From ab6e6ee64f421769b31b5946f508d3beeb49e683 Mon Sep 17 00:00:00 2001 From: tuancoltech Date: Fri, 18 Oct 2024 21:47:46 +0700 Subject: [PATCH] Back gesture is recognized as drawing intent: https://app.asana.com/0/1207819682524134/1208536199909620 --- .../dev/arkbuilders/arkmemo/ui/views/NotesCanvas.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/src/main/java/dev/arkbuilders/arkmemo/ui/views/NotesCanvas.kt b/app/src/main/java/dev/arkbuilders/arkmemo/ui/views/NotesCanvas.kt index 99f44ae7..00533937 100644 --- a/app/src/main/java/dev/arkbuilders/arkmemo/ui/views/NotesCanvas.kt +++ b/app/src/main/java/dev/arkbuilders/arkmemo/ui/views/NotesCanvas.kt @@ -1,6 +1,7 @@ package dev.arkbuilders.arkmemo.ui.views import android.content.Context +import android.content.res.Resources import android.graphics.Canvas import android.graphics.Path import android.util.AttributeSet @@ -19,6 +20,8 @@ class NotesCanvas(context: Context, attrs: AttributeSet): View(context, attrs) { private lateinit var viewModel: GraphicNotesViewModel private var path = Path() + private val screenWidth by lazy { Resources.getSystem().displayMetrics.widthPixels } + override fun onDraw(canvas: Canvas) { val paths = viewModel.paths() if (paths.isNotEmpty()) { @@ -32,6 +35,14 @@ class NotesCanvas(context: Context, attrs: AttributeSet): View(context, attrs) { val x = event.x val y = event.y + val edgeThreshold = 50 + + // When touch point starts from either of the left or right side of the screen, + // that's probably a back gesture. Do not draw in this case + if (x < edgeThreshold || x > screenWidth - edgeThreshold) { + return false + } + var finishDrawing = false when(event.action) { MotionEvent.ACTION_DOWN -> {