diff --git a/module/build.gradle b/module/build.gradle index cd72f55..5022e7c 100644 --- a/module/build.gradle +++ b/module/build.gradle @@ -9,8 +9,8 @@ android { defaultConfig { minSdkVersion 16 targetSdkVersion 30 - versionCode 4 - versionName "1.3" + versionCode 5 + versionName "1.4" } buildTypes { } diff --git a/module/src/main/java/org/nuclearfog/textviewtool/LinkAndScrollMovement.java b/module/src/main/java/org/nuclearfog/textviewtool/LinkAndScrollMovement.java index 4e652af..0d40773 100644 --- a/module/src/main/java/org/nuclearfog/textviewtool/LinkAndScrollMovement.java +++ b/module/src/main/java/org/nuclearfog/textviewtool/LinkAndScrollMovement.java @@ -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 { @@ -32,6 +32,9 @@ 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; @@ -39,7 +42,6 @@ private LinkAndScrollMovement() { super(); } - @Override public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) { switch(event.getAction()) { @@ -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(); @@ -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; } /** @@ -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; + } } \ No newline at end of file