From ccc923251f2e56089018f8998ddb56da0cfc7f80 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 26 Aug 2018 16:43:51 +0200 Subject: [PATCH] fixing some multitouch glitches --- .../simplemobiletools/draw/views/MyCanvas.kt | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/draw/views/MyCanvas.kt b/app/src/main/kotlin/com/simplemobiletools/draw/views/MyCanvas.kt index 3b4d14e..69da4c3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/draw/views/MyCanvas.kt +++ b/app/src/main/kotlin/com/simplemobiletools/draw/views/MyCanvas.kt @@ -44,6 +44,7 @@ class MyCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) { private var mIsStrokeWidthBarEnabled = false private var mAllowZooming = true private var mIsEraserOn = false + private var mWasMultitouch = false private var mBackgroundColor = 0 private var mCenter: PointF? = null @@ -261,13 +262,15 @@ class MyCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) { } private fun actionUp() { - mPath.lineTo(mCurX, mCurY) + if (!mWasMultitouch) { + mPath.lineTo(mCurX, mCurY) - // draw a dot on click - if (mStartX == mCurX && mStartY == mCurY) { - mPath.lineTo(mCurX, mCurY + 2) - mPath.lineTo(mCurX + 1, mCurY + 2) - mPath.lineTo(mCurX + 1, mCurY) + // draw a dot on click + if (mStartX == mCurX && mStartY == mCurY) { + mPath.lineTo(mCurX, mCurY + 2) + mPath.lineTo(mCurX + 1, mCurY + 2) + mPath.lineTo(mCurX + 1, mCurY) + } } mPaths[mPath] = mPaintOptions @@ -288,21 +291,24 @@ class MyCanvas(context: Context, attrs: AttributeSet) : View(context, attrs) { val x = event.x val y = event.y - when (event.action) { + when (event.action and MotionEvent.ACTION_MASK) { MotionEvent.ACTION_DOWN -> { + mWasMultitouch = false mStartX = x mStartY = y actionDown(x, y) mUndonePaths.clear() mListener?.toggleRedoVisibility(false) + } MotionEvent.ACTION_MOVE -> { - if (!mAllowZooming || (!mScaleDetector!!.isInProgress && event.pointerCount == 1)) { + if (!mAllowZooming || (!mScaleDetector!!.isInProgress && event.pointerCount == 1 && !mWasMultitouch)) { actionMove(x, y) } } MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> actionUp() + MotionEvent.ACTION_POINTER_DOWN -> mWasMultitouch = true } invalidate()