diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/Whiteboard.kt b/AnkiDroid/src/main/java/com/ichi2/anki/Whiteboard.kt index e33f71337668..ec725a71d7cd 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/Whiteboard.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/Whiteboard.kt @@ -110,7 +110,11 @@ class Whiteboard(activity: AnkiActivity, handleMultiTouch: Boolean, inverted: Bo private fun handleDrawEvent(event: MotionEvent): Boolean { val x = event.x val y = event.y - if (event.getToolType(event.actionIndex) != MotionEvent.TOOL_TYPE_STYLUS && toggleStylus == true) { + if (event.getToolType(event.actionIndex) == MotionEvent.TOOL_TYPE_ERASER) { + stylusErase(event) + return true + } + if (event.getToolType(event.actionIndex) != MotionEvent.TOOL_TYPE_STYLUS && toggleStylus) { return false } return when (event.actionMasked) { @@ -145,14 +149,8 @@ class Whiteboard(activity: AnkiActivity, handleMultiTouch: Boolean, inverted: Bo false } 211, 213 -> { - if (event.buttonState == MotionEvent.BUTTON_STYLUS_PRIMARY && !undoEmpty()) { - val didErase = mUndo.erase(event.x.toInt(), event.y.toInt()) - if (didErase) { - mUndo.apply() - if (undoEmpty()) { - mAnkiActivity.invalidateOptionsMenu() - } - } + if (event.buttonState == MotionEvent.BUTTON_STYLUS_PRIMARY) { + stylusErase(event) } true } @@ -177,6 +175,21 @@ class Whiteboard(activity: AnkiActivity, handleMultiTouch: Boolean, inverted: Bo } } + /** + * Erase with stylus pen.(By using the eraser button on the stylus pen or by using the digital eraser) + */ + private fun stylusErase(event: MotionEvent) { + if (!undoEmpty()) { + val didErase = mUndo.erase(event.x.toInt(), event.y.toInt()) + if (didErase) { + mUndo.apply() + if (undoEmpty()) { + mAnkiActivity.invalidateOptionsMenu() + } + } + } + } + /** * Clear the whiteboard. */