Merge pull request #269 from alek3y/master

Fix abrupt multitouch movement
This commit is contained in:
Tibor Kaputa 2023-03-12 12:27:50 +01:00 committed by GitHub
commit 9e01762794
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -60,6 +60,7 @@ class MyCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) {
private var mIsBucketFillOn = false
private var mWasMultitouch = false
private var mIgnoreTouches = false
private var mIgnoreMultitouchChanges = false
private var mWasScalingInGesture = false
private var mWasMovingCanvasInGesture = false
private var mBackgroundColor = 0
@ -160,7 +161,7 @@ class MyCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) {
actionMove(newValueX, newValueY)
}
if (mAllowMovingZooming && mWasMultitouch) {
if (mAllowMovingZooming && mWasMultitouch && !mIgnoreMultitouchChanges) {
mPosX += x - mLastTouchX
mPosY += y - mLastTouchY
mWasMovingCanvasInGesture = true
@ -169,6 +170,7 @@ class MyCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) {
mLastTouchX = x
mLastTouchY = y
mIgnoreMultitouchChanges = false
}
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
mActivePointerId = INVALID_POINTER_ID
@ -179,12 +181,14 @@ class MyCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) {
MotionEvent.ACTION_POINTER_DOWN -> {
if (mAllowMovingZooming) {
mWasMultitouch = true
mIgnoreMultitouchChanges = true
mTouchSloppedBeforeMultitouch = mLastMotionEvent.isTouchSlop(pointerIndex, mStartX, mStartY)
}
}
MotionEvent.ACTION_POINTER_UP -> {
if (mAllowMovingZooming) {
mIgnoreTouches = true
mIgnoreMultitouchChanges = true
actionUp(!mWasScalingInGesture && !mWasMovingCanvasInGesture)
}
}