Fix double tap scale

This commit is contained in:
Alexey Kulish 2016-07-03 15:16:06 +03:00
parent f6f25e6c9f
commit e48e32440a

View file

@ -32,8 +32,10 @@ public class DoubleTapScaleDetector {
private MotionEvent firstDown; private MotionEvent firstDown;
private MotionEvent firstUp; private MotionEvent firstUp;
private MotionEvent secondDown; private MotionEvent secondDown;
private int mTouchSlopSquare;
private int mDoubleTapSlopSquare; private int mDoubleTapSlopSquare;
private boolean mIsDoubleTapping; private boolean mIsDoubleTapping;
private boolean mScrolling;
public DoubleTapScaleDetector(Activity ctx, DoubleTapZoomListener listener) { public DoubleTapScaleDetector(Activity ctx, DoubleTapZoomListener listener) {
this.ctx = ctx; this.ctx = ctx;
@ -49,6 +51,8 @@ public class DoubleTapScaleDetector {
centerScreen = new PointF(defaultDisplay.getWidth() / 2, defaultDisplay.getHeight() / 2); centerScreen = new PointF(defaultDisplay.getWidth() / 2, defaultDisplay.getHeight() / 2);
} }
final ViewConfiguration configuration = ViewConfiguration.get(ctx); final ViewConfiguration configuration = ViewConfiguration.get(ctx);
int touchSlop = configuration.getScaledTouchSlop();
mTouchSlopSquare = touchSlop * touchSlop;
int doubleTapSlop = (int) (configuration.getScaledDoubleTapSlop() * 0.5); int doubleTapSlop = (int) (configuration.getScaledDoubleTapSlop() * 0.5);
mDoubleTapSlopSquare = doubleTapSlop * doubleTapSlop; mDoubleTapSlopSquare = doubleTapSlop * doubleTapSlop;
} }
@ -57,6 +61,7 @@ public class DoubleTapScaleDetector {
if (event.getPointerCount() != 1) { if (event.getPointerCount() != 1) {
resetEvents(); resetEvents();
mIsDoubleTapping = false; mIsDoubleTapping = false;
mScrolling = false;
return false; return false;
} }
if (event.getAction() == MotionEvent.ACTION_UP) { if (event.getAction() == MotionEvent.ACTION_UP) {
@ -71,14 +76,17 @@ public class DoubleTapScaleDetector {
listener.onDoubleTap(event); listener.onDoubleTap(event);
} }
handled = true; handled = true;
} else { } else if (!mScrolling) {
firstUp = MotionEvent.obtain(event); firstUp = MotionEvent.obtain(event);
} else {
resetEvents();
} }
if (handled) { if (handled) {
resetEvents(); resetEvents();
} }
mIsDoubleTapping = false; mIsDoubleTapping = false;
mScrolling = false;
return handled; return handled;
} else { } else {
if (event.getAction() == MotionEvent.ACTION_DOWN && !mIsInZoomMode) { if (event.getAction() == MotionEvent.ACTION_DOWN && !mIsInZoomMode) {
@ -94,6 +102,9 @@ public class DoubleTapScaleDetector {
firstDown = MotionEvent.obtain(event); firstDown = MotionEvent.obtain(event);
} }
} else if (event.getAction() == MotionEvent.ACTION_MOVE) { } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
if (!mScrolling && secondDown == null && firstDown != null) {
mScrolling = calculateSqaredDistance(firstDown, event) > mTouchSlopSquare;
}
if (isConfirmedScale(secondDown, event)) { if (isConfirmedScale(secondDown, event)) {
mIsInZoomMode = true; mIsInZoomMode = true;
} }