code cleanup, added comments

This commit is contained in:
nuclearfog 2023-11-21 23:20:03 +01:00
parent 3bd42fb2c6
commit 6098e1fd63
No known key found for this signature in database
GPG Key ID: 43E45B82006BC9D5
2 changed files with 28 additions and 27 deletions

View File

@ -9,6 +9,8 @@ import android.view.ViewParent;
import android.widget.TextView;
/**
* {@link ScrollingMovementMethod} implementation fixing TextView scrolling issues
*
* @author nuclearfog
*/
public class LinkAndScrollMovement extends ScrollingMovementMethod {
@ -29,6 +31,7 @@ public class LinkAndScrollMovement extends ScrollingMovementMethod {
private int yScroll = 0;
/**
*
*/
private LinkAndScrollMovement() {
super();
@ -36,7 +39,7 @@ public class LinkAndScrollMovement extends ScrollingMovementMethod {
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
switch(event.getAction()) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
lockParentScrolling(widget, true);
xScroll = widget.getScrollX();
@ -68,21 +71,6 @@ public class LinkAndScrollMovement extends ScrollingMovementMethod {
return super.onTouchEvent(widget, buffer, event);
}
/**
* lock parent view scrolling
*
* @param widget interacting TextView
* @param lock true if parent views scrolling should be locked
*/
private void lockParentScrolling(TextView widget, boolean lock) {
ViewParent parent = widget.getParent();
int lineCount = widget.getLineCount();
int maxLines = widget.getMaxLines();
if ( parent != null && maxLines > 0 && lineCount > maxLines ) {
parent.requestDisallowInterceptTouchEvent(lock);
}
}
/**
* Get singleton instance of the movement method
*
@ -91,4 +79,19 @@ public class LinkAndScrollMovement extends ScrollingMovementMethod {
public static LinkAndScrollMovement getInstance() {
return instance;
}
/**
* lock parent view scrolling
*
* @param widget interacting TextView
* @param lock true if parent views scrolling should be locked
*/
private void lockParentScrolling(TextView widget, boolean lock) {
ViewParent parent = widget.getParent();
int lineCount = widget.getLineCount();
int maxLines = widget.getMaxLines();
if (parent != null && maxLines > 0 && lineCount > maxLines) {
parent.requestDisallowInterceptTouchEvent(lock);
}
}
}

View File

@ -12,8 +12,6 @@ import android.widget.RemoteViews.RemoteView;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageView;
import static android.view.MotionEvent.*;
import org.nuclearfog.twidda.R;
/**
@ -76,18 +74,17 @@ public class ZoomView extends AppCompatImageView {
if (getScaleType() != ScaleType.MATRIX)
setScaleType(ScaleType.MATRIX);
if (event.getPointerCount() == 1) {
switch (event.getAction()) {
case ACTION_UP:
switch (event.getActionMasked()) {
case MotionEvent.ACTION_UP:
pos.set(event.getX(), event.getY());
moveLock = false;
break;
case ACTION_DOWN:
case MotionEvent.ACTION_DOWN:
pos.set(event.getX(), event.getY());
break;
case ACTION_MOVE:
case MotionEvent.ACTION_MOVE:
if (moveLock || !enableMove)
return super.performClick();
float posX = event.getX() - pos.x;
@ -101,15 +98,15 @@ public class ZoomView extends AppCompatImageView {
} else if (event.getPointerCount() == 2) {
float distX, distY, scale;
switch (event.getActionMasked()) {
case ACTION_POINTER_UP:
case ACTION_POINTER_DOWN:
case MotionEvent.ACTION_POINTER_UP:
case MotionEvent.ACTION_POINTER_DOWN:
distX = event.getX(0) - event.getX(1);
distY = event.getY(0) - event.getY(1);
dist.set(distX, distY); // Distance vector
moveLock = true;
break;
case ACTION_MOVE:
case MotionEvent.ACTION_MOVE:
distX = event.getX(0) - event.getX(1);
distY = event.getY(0) - event.getY(1);
PointF current = new PointF(distX, distY);
@ -167,7 +164,8 @@ public class ZoomView extends AppCompatImageView {
*/
private void apply(Matrix m) {
Drawable d = getDrawable();
if (d == null) return;
if (d == null)
return;
float[] val = new float[9];
m.getValues(val);