Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Back gesture is recognized as drawing intent #80

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/src/main/java/dev/arkbuilders/arkmemo/ui/views/NotesCanvas.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,6 +19,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()) {
Expand All @@ -31,6 +34,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 -> {
Expand Down