Skip to content

Commit

Permalink
feat: configurable minimal screen touch time to reveal answer
Browse files Browse the repository at this point in the history
Defaults to 0ms so no long touch required, but may be configured
to require a long-press, which may reduce accidental show answer
presses in bumpy environments / with accessibility needs for tremor
  • Loading branch information
criticalAY authored and lukstbit committed Sep 13, 2023
1 parent 52b511b commit c7f0b05
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
26 changes: 24 additions & 2 deletions AnkiDroid/src/main/java/com/ichi2/anki/AbstractFlashcardViewer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ abstract class AbstractFlashcardViewer :
protected var fullscreenMode = DEFAULT
private set
private var mRelativeButtonSize = 0
private var minimalClickSpeed = 0
private var mDoubleScrolling = false
private var mGesturesEnabled = false
private var mLargeAnswerButtons = false
Expand Down Expand Up @@ -894,8 +895,28 @@ abstract class AbstractFlashcardViewer :
easeButton4!!.hideNextReviewTime()
}
val flipCard = findViewById<Button>(R.id.flip_card)
flipCardLayout = findViewById<LinearLayout>(R.id.flashcard_layout_flip).apply {
setOnClickListener(mFlipCardListener)
flipCardLayout = findViewById<LinearLayout>(R.id.flashcard_layout_flip)
flipCardLayout?.let { layout ->
if (minimalClickSpeed == 0) {
layout.setOnClickListener(mFlipCardListener)
} else {
val handler = Handler(Looper.getMainLooper())
layout.setOnTouchListener { _, event ->
when (event.action) {
MotionEvent.ACTION_DOWN -> {
handler.postDelayed({
mFlipCardListener.onClick(layout)
}, minimalClickSpeed.toLong())
false
}
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL, MotionEvent.ACTION_HOVER_ENTER -> {
handler.removeCallbacksAndMessages(null)
false
}
else -> false
}
}
}
}
if (animationEnabled()) {
flipCard.setBackgroundResource(getResFromAttr(this, R.attr.hardButtonRippleRef))
Expand Down Expand Up @@ -1150,6 +1171,7 @@ abstract class AbstractFlashcardViewer :
val preferences = baseContext.sharedPrefs()
typeAnswer = createInstance(preferences)
// mDeckFilename = preferences.getString("deckFilename", "");
minimalClickSpeed = preferences.getInt("showCardAnswerButtonTime", 0)
fullscreenMode = fromPreference(preferences)
mRelativeButtonSize = preferences.getInt("answerButtonSize", 100)
mTTS.enabled = preferences.getBoolean("tts", false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ object UsageAnalytics {
"answerButtonSize",
"showLargeAnswerButtons",
"relativeCardBrowserFontSize",
"showCardAnswerButtonTime",
// Advanced
"deckPath", // AnkiDroid directory
"backupMax", // Max number of backups
Expand Down
2 changes: 2 additions & 0 deletions AnkiDroid/src/main/res/values/10-preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@
<string name="pref_backup_max" maxLength="41">Max number of backups</string>
<string name="pref_double_tap_time_interval" maxLength="41">Double tap time interval (milliseconds)</string>
<string name="pref_double_tap_time_interval_summary">A second tap of the answer buttons will be ignored if this time has not elapsed. This prevents accidental double taps</string>
<string name="pref_show_answer_long_press" maxLength="41">Show answer long-press time (ms)</string>
<string name="pref_show_answer_long_press_summary">Minimum long-press time before the show answer button will register a touch. May reduce the chance of accidental extra button presses. Default is 0ms</string>
<string name="show_estimates" maxLength="41">Show button time</string>
<string name="show_estimates_summ">Show next review time on answer buttons</string>
<string name="show_large_answer_buttons" maxLength="41">Show large answer buttons</string>
Expand Down
1 change: 1 addition & 0 deletions AnkiDroid/src/main/res/values/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
<string name="image_zoom_preference">imageZoom</string>
<string name="answer_button_size_preference">answerButtonSize</string>
<string name="show_large_answer_buttons_preference">showLargeAnswerButtons</string>
<string name="pref_card_minimal_click_time">showCardAnswerButtonTime</string>
<!-- Custom sync server -->
<string name="pref_custom_sync_server_screen_key">customSyncServerScreen</string>
<string name="custom_sync_server_collection_url_key">syncBaseUrl</string>
Expand Down
7 changes: 7 additions & 0 deletions AnkiDroid/src/main/res/xml/preferences_accessibility.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,11 @@
android:valueTo="200"
android:stepSize="10"
app:displayFormat="@string/pref_summary_percentage"/>
<com.ichi2.preferences.NumberRangePreferenceCompat
android:defaultValue="0"
android:key="@string/pref_card_minimal_click_time"
android:summary="@string/pref_show_answer_long_press_summary"
android:title="@string/pref_show_answer_long_press"
app:min="0"
android:max="2000" />
</PreferenceScreen>

0 comments on commit c7f0b05

Please sign in to comment.