Skip to content
Open
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
23 changes: 16 additions & 7 deletions app/src/main/java/dev/arkbuilders/arkmemo/ui/views/NotesCanvas.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class NotesCanvas(context: Context, attrs: AttributeSet) : View(context, attrs)
return false
}

var finishDrawing = false
when (event.action) {
MotionEvent.ACTION_DOWN -> {
path.moveTo(x, y)
Expand All @@ -56,7 +55,10 @@ class NotesCanvas(context: Context, attrs: AttributeSet) : View(context, attrs)
}
currentX = x
currentY = y
val drawPath = DrawPath(path, viewModel.paint)
viewModel.onDrawPath(drawPath)
}

MotionEvent.ACTION_MOVE -> {
val x2 = (currentX + x) / 2
val y2 = (currentY + y) / 2
Expand All @@ -72,17 +74,24 @@ class NotesCanvas(context: Context, attrs: AttributeSet) : View(context, attrs)
currentX = x
currentY = y
}

MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
if (x == currentX && y == currentY) {
path.lineTo(x, y)
viewModel.svg().apply {
addCommand(
SVGCommand.AbsLineTo(x, y).apply {
paintColor = viewModel.paint.color.getStrokeColor()
brushSizeId = viewModel.paint.strokeWidth.getBrushSizeId()
},
)
}
Comment on lines +79 to +88
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Dot detection needs touch-jitter tolerance.

ACTION_UP coordinates often drift by a few pixels even on a stationary tap, so this strict equality rarely fires. When it doesn’t, we skip the lineTo/SVG command and the dot still vanishes after reload—undercutting the PR goal. Please gate this branch with a small tolerance (e.g., a few px or scaledTouchSlop) instead of raw equality.

-                if (x == currentX && y == currentY) {
+                if (
+                    kotlin.math.abs(x - currentX) <= DOT_TOLERANCE_PX &&
+                    kotlin.math.abs(y - currentY) <= DOT_TOLERANCE_PX
+                ) {

Add an appropriate constant (tuned for density/touch slop) near the class definition, for example:

private companion object {
    private const val DOT_TOLERANCE_PX = 4f
}
🤖 Prompt for AI Agents
In app/src/main/java/dev/arkbuilders/arkmemo/ui/views/NotesCanvas.kt around
lines 79-88, the current dot-detection uses strict x == currentX && y ==
currentY which fails due to touch jitter; add a small tolerance constant near
the class definition (e.g., in a private companion object, either a fixed
DOT_TOLERANCE_PX or obtain ViewConfiguration.get(context).scaledTouchSlop
converted to pixels) and replace the equality check with a distance/tolerance
check (e.g., if (abs(x - currentX) <= DOT_TOLERANCE_PX && abs(y - currentY) <=
DOT_TOLERANCE_PX) or squared-distance comparison) so the touch-up branch fires
for near-identical coordinates and the SVG dot command is preserved.

}
path = Path()
finishDrawing = true
}
}

if (!finishDrawing) {
val drawPath = DrawPath(path, viewModel.paint)
viewModel.onDrawPath(drawPath)
invalidate()
}
invalidate()

return true
}
Expand Down