Skip to content

Commit

Permalink
version 1.4 bug fix, added method to set threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearfog committed Jan 23, 2021
1 parent 8ac1b02 commit 4bf3e16
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
4 changes: 2 additions & 2 deletions module/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 30
versionCode 4
versionName "1.3"
versionCode 5
versionName "1.4"
}

buildTypes { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* While scrolling a TextView, the spans stay locked until the next tap event.
*
* @author nuclearfog
* @version 1.3
* @version 1.4
*/
public class LinkAndScrollMovement extends ScrollingMovementMethod {

Expand All @@ -32,14 +32,16 @@ public class LinkAndScrollMovement extends ScrollingMovementMethod {
*/
private static final int THRESHOLD_HEIGHT_DIVIDER = 3;

private int thresholdX = THRESHOLD_WIDTH_DIVIDER;
private int thresholdY = THRESHOLD_HEIGHT_DIVIDER;

private int xScroll = 0;
private int yScroll = 0;

private LinkAndScrollMovement() {
super();
}


@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
switch(event.getAction()) {
Expand All @@ -51,10 +53,9 @@ public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event

case ACTION_UP:
lockParentScrolling(widget, false);
int deltaX = Math.abs(widget.getScrollY() - xScroll);
int deltaX = Math.abs(widget.getScrollX() - xScroll);
int deltaY = Math.abs(widget.getScrollY() - yScroll);
if (deltaY <= widget.getTextSize() / THRESHOLD_HEIGHT_DIVIDER &&
deltaX <= widget.getWidth() / THRESHOLD_WIDTH_DIVIDER) {
if (deltaY <= widget.getTextSize() / thresholdY && deltaX <= widget.getWidth() / thresholdX) {
int x = (int) event.getX();
int y = (int) event.getY();
x -= widget.getTotalPaddingLeft();
Expand All @@ -76,12 +77,14 @@ public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event
}

/**
* Get singleton instance of the movement method
*
* @return LinkAndScrollingMovementMethod object
* sets maximum threshold to lock link clicks
* @param thrX threshold for x axis
* @param thrY threshold for y axis
*/
public static LinkAndScrollMovement getInstance() {
return instance;
public LinkAndScrollMovement setThreshold(int thrX, int thrY) {
thresholdX = thrX;
thresholdY = thrY;
return this;
}

/**
Expand All @@ -98,4 +101,13 @@ private void lockParentScrolling(TextView widget, boolean lock) {
parent.requestDisallowInterceptTouchEvent(lock);
}
}

/**
* Get singleton instance of the movement method
*
* @return LinkAndScrollingMovementMethod object
*/
public static LinkAndScrollMovement getInstance() {
return instance;
}
}

0 comments on commit 4bf3e16

Please sign in to comment.