Skip to content

Fix: Implements go back twice to exit in the whiteboard for gesture navigation - #20792

Merged
BrayanDSO merged 2 commits into
ankidroid:mainfrom
ShaanNarendran:double-back-whiteboard
Apr 23, 2026
Merged

Fix: Implements go back twice to exit in the whiteboard for gesture navigation#20792
BrayanDSO merged 2 commits into
ankidroid:mainfrom
ShaanNarendran:double-back-whiteboard

Conversation

@ShaanNarendran

@ShaanNarendran ShaanNarendran commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Note

Tested out Opus 4.6 with code generation, still wrote all the code manually and tested everything physically

Purpose / Description

Currently, the double tap/swipe to back option doesn't work properly in the whiteboard and a single gesture/back press exits. This was a pain point for users who were using the whiteboard for language like Japanese.
Currently, this doesn't detect gestures since it involved an external API and I wasn't very sure of how that worked so didn't want to include it here.

Fixes

Approach

Implements a new doubleBackPressCallback function which intercepts back presses when the whiteboard is enabled. If the user presses back once, a snackbar is shown. If they press back again within 2 seconds, the activity finishes. If they don't, shouldReEnable checks whether the whiteboard is still active.

How Has This Been Tested?

Screen_recording_20260420_121417.webm

Checklist

Please, go through these checks before submitting the PR.

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

@david-allison david-allison left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't feel this handles Brayan's comment:

If we can also check whether the system is using gestures instead of buttons for navigation, it would be even better.

I skimmed the discussion, as far as I understand it, requiring a confirmation should only occur if the Android back gesture is enabled, rather than buttons.


In addition, implementer's choice

Consider a commit to change the string:

- Press back again to exit
+ Go back again to exit

@david-allison david-allison added the Needs Author Reply Waiting for a reply from the original author label Apr 20, 2026
@ShaanNarendran

ShaanNarendran commented Apr 20, 2026

Copy link
Copy Markdown
Contributor Author

I don't feel this handles Brayan's comment:

If we can also check whether the system is using gestures instead of buttons for navigation, it would be even better.

I skimmed the discussion, as far as I understand it, requiring a confirmation should only occur if the Android back gesture is enabled, rather than buttons.

I had wanted to do this initially (https://stackoverflow.com/questions/74848618/how-to-detect-whether-gesture-navigation-or-button-navigation-is-active). But I was wondering why we wouldn't want to have the same thing for both navigation modes? I can make the change to using insets to detect gestures though, should just involve an extra function to detect gestures and then pass that to the ReEnable.
Edit: Since, Brayan designed reviewer I think it's best I follow his comments with the same, I'll push out a commit soon with both fixes ^^
Will change the string since then it would be nav agnostic, thanks for the find there!

@ShaanNarendran

Copy link
Copy Markdown
Contributor Author

For future reference, using insets to detect navigation isn't reliable so using settings.secure is better
see: https://www.b4x.com/android/forum/threads/solved-how-to-determine-users-system-navigation-mode-back-button-or-side-swipe.159347/

@ShaanNarendran
ShaanNarendran force-pushed the double-back-whiteboard branch from 9eac988 to 3f8fa87 Compare April 20, 2026 08:34

@david-allison david-allison left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

squash commits 1 and 2

Comment thread AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerFragment.kt Outdated
@ShaanNarendran ShaanNarendran changed the title Fix: Implements double tap back in the whiteboard Fix: Implements go back twice to exit in the whiteboard for gesture navigation Apr 20, 2026
@ShaanNarendran
ShaanNarendran force-pushed the double-back-whiteboard branch 2 times, most recently from 80c8dbd to 7096f8e Compare April 20, 2026 08:59

@david-allison david-allison left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Almost!

Comment thread AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerFragment.kt Outdated
Comment thread compat/src/main/java/com/ichi2/anki/compat/NavigationCompat.kt Outdated
@ShaanNarendran

ShaanNarendran commented Apr 20, 2026

Copy link
Copy Markdown
Contributor Author

hopefully I implemented the compat part correctly, please let me know if there's any issues

edit: failing tests will figure it out shortly

@ShaanNarendran
ShaanNarendran force-pushed the double-back-whiteboard branch from b7ad7ce to aa24043 Compare April 20, 2026 11:28

@david-allison david-allison left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Almost!!

Comment thread compat/src/main/java/com/ichi2/anki/compat/CompatV29.kt Outdated
@ShaanNarendran
ShaanNarendran force-pushed the double-back-whiteboard branch from aa24043 to 1406576 Compare April 22, 2026 06:57

@BrayanDSO BrayanDSO left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great to me. Thanks

@BrayanDSO BrayanDSO added Needs Second Approval Has one approval, one more approval to merge and removed Needs Review labels Apr 22, 2026
*/
fun isUsingSystemGestureNavigation(
context: Context,
default: Int = 0,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be better to have the default as a Boolean

@ShaanNarendran
ShaanNarendran force-pushed the double-back-whiteboard branch from 1406576 to 2616670 Compare April 22, 2026 17:09
@ShaanNarendran

ShaanNarendran commented Apr 22, 2026

Copy link
Copy Markdown
Contributor Author

flaky test I'm pretty sure

@david-allison david-allison left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Index: compat/src/main/java/com/ichi2/anki/compat/BaseCompat.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/compat/src/main/java/com/ichi2/anki/compat/BaseCompat.kt b/compat/src/main/java/com/ichi2/anki/compat/BaseCompat.kt
--- a/compat/src/main/java/com/ichi2/anki/compat/BaseCompat.kt	(revision e911b16a595b247cf9f7842df36658270c0ae0db)
+++ b/compat/src/main/java/com/ichi2/anki/compat/BaseCompat.kt	(date 1776886772578)
@@ -289,8 +289,7 @@
     // Until API 29, gesture navigation does not exist
     override fun isUsingSystemGestureNavigation(
         context: Context,
-        default: Boolean,
-        gestureMode: Int,
+        defaultValue: Boolean,
     ): Boolean = false
 }
 
Index: compat/src/main/java/com/ichi2/anki/compat/CompatV29.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/compat/src/main/java/com/ichi2/anki/compat/CompatV29.kt b/compat/src/main/java/com/ichi2/anki/compat/CompatV29.kt
--- a/compat/src/main/java/com/ichi2/anki/compat/CompatV29.kt	(revision e911b16a595b247cf9f7842df36658270c0ae0db)
+++ b/compat/src/main/java/com/ichi2/anki/compat/CompatV29.kt	(date 1776886686118)
@@ -87,11 +87,10 @@
 
     override fun isUsingSystemGestureNavigation(
         context: Context,
-        default: Boolean,
-        gestureMode: Int,
+        defaultValue: Boolean,
     ): Boolean {
-        val defaultMode = if (default) gestureMode else 0
-        return Settings.Secure.getInt(context.contentResolver, "navigation_mode", defaultMode) == gestureMode
+        val defaultMode = if (defaultValue) 2 else 0
+        return Settings.Secure.getInt(context.contentResolver, "navigation_mode", defaultMode) == 2
     }
 
     companion object {
Index: compat/src/main/java/com/ichi2/anki/compat/Compat.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/compat/src/main/java/com/ichi2/anki/compat/Compat.kt b/compat/src/main/java/com/ichi2/anki/compat/Compat.kt
--- a/compat/src/main/java/com/ichi2/anki/compat/Compat.kt	(revision e911b16a595b247cf9f7842df36658270c0ae0db)
+++ b/compat/src/main/java/com/ichi2/anki/compat/Compat.kt	(date 1776886772584)
@@ -282,12 +282,10 @@
      * Note: this reads a `Settings.Secure` key that is not part of the public API.
      * It will not throw, but the result is manufacturer dependent.
      *
-     * @param default value returned when the `navigation_mode` key is unset
-     * @param gestureMode the value of `navigation_mode` representing gesture navigation
+     * @param defaultValue value returned when the `navigation_mode` key is unset
      */
     fun isUsingSystemGestureNavigation(
         context: Context,
-        default: Boolean = false,
-        gestureMode: Int = 2,
+        defaultValue: Boolean = false,
     ): Boolean
 }

Does this work (untested)

@ShaanNarendran
ShaanNarendran force-pushed the double-back-whiteboard branch from 2616670 to b13c20a Compare April 22, 2026 20:24
@david-allison
david-allison enabled auto-merge April 22, 2026 20:41
@david-allison
david-allison disabled auto-merge April 22, 2026 20:41
@BrayanDSO BrayanDSO added Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) and removed Needs Author Reply Waiting for a reply from the original author Needs Second Approval Has one approval, one more approval to merge labels Apr 22, 2026
@BrayanDSO
BrayanDSO added this pull request to the merge queue Apr 22, 2026
Merged via the queue into ankidroid:main with commit c7d8078 Apr 23, 2026
15 checks passed
@github-actions github-actions Bot added this to the 2.24 release milestone Apr 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Maintainers: Please Sync Translations to produce a commit with only the automated changes from this PR.

Read more about updating strings on the wiki,

@github-actions github-actions Bot removed the Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) label Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Press back twice" doesn't work on new study screen

4 participants