Skip to content

Commit

Permalink
feat: Show keyboard shortcuts preference
Browse files Browse the repository at this point in the history
it shows up the system dialog with the available shortcuts if the user has a physical keyboard attached. It helps the discoverability of keyboard shortcuts along the app.

After the user knows that the app has keyboard shortcuts, they can use the system shortcut (which can be seen in the dialog itself) in any other screen to see the available shortcuts there
  • Loading branch information
BrayanDSO authored and lukstbit committed Feb 9, 2025
1 parent e5f9af1 commit baf31be
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/
package com.ichi2.anki.preferences

import android.content.res.Configuration
import androidx.annotation.StringRes
import androidx.preference.Preference
import com.ichi2.anki.CollectionManager.TR
import com.ichi2.anki.R
import com.ichi2.anki.cardviewer.ViewerCommand
Expand All @@ -41,6 +43,16 @@ class ControlsSettingsFragment : SettingsFragment() {
.forEach { pref -> pref.value = commands[pref.key]?.defaultValue?.toPreferenceString() }

setDynamicTitle()

// TODO replace the preference with something dismissible. This is meant only to improve
// the discoverability of the system shortcut for the shortcuts dialog.
requirePreference<Preference>(R.string.pref_keyboard_shortcuts_key).apply {
isVisible = resources.configuration.keyboard == Configuration.KEYBOARD_QWERTY
setOnPreferenceClickListener {
requireActivity().requestShowKeyboardShortcuts()
true
}
}
}

private fun setDynamicTitle() {
Expand Down
5 changes: 5 additions & 0 deletions AnkiDroid/src/main/res/drawable/ic_keyboard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="?attr/colorControlNormal" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M20,5L4,5c-1.1,0 -1.99,0.9 -1.99,2L2,17c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,7c0,-1.1 -0.9,-2 -2,-2zM11,8h2v2h-2L11,8zM11,11h2v2h-2v-2zM8,8h2v2L8,10L8,8zM8,11h2v2L8,13v-2zM7,13L5,13v-2h2v2zM7,10L5,10L5,8h2v2zM16,17L8,17v-2h8v2zM16,13h-2v-2h2v2zM16,10h-2L14,8h2v2zM19,13h-2v-2h2v2zM19,10h-2L17,8h2v2z"/>

</vector>
1 change: 1 addition & 0 deletions AnkiDroid/src/main/res/values/10-preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<string name="gestures_summ">Assign gestures to actions such as answering and editing cards.</string>
<string name="gestures_corner_touch" maxLength="41">9-point touch</string>
<string name="gestures_corner_touch_summary">Allow touch gestures in screen corners</string>
<string name="show_keyboard_shortcuts" maxLength="41">Show keyboard shortcuts</string>
<string name="gestures_full_screen_nav_drawer" maxLength="41">Full screen navigation drawer</string>
<string name="gestures_fullscreen_nav_drawer_summary">Open navigation drawer when swiped right from anywhere on the screen</string>
<string name="gestures_none" maxLength="41" comment="No gestures">None</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 @@ -84,6 +84,7 @@
<string name="gestures_preference">gestures</string>
<string name="gestures_corner_touch_preference">gestureCornerTouch</string>
<string name="nav_drawer_gesture_key">gestureFullScreenNavigationDrawer</string>
<string name="pref_keyboard_shortcuts_key">showKeyboardShortcuts</string>
<string name="pref_swipe_sensitivity_key">swipeSensitivity</string>
<string name="show_answer_command_key">binding_SHOW_ANSWER</string>
<string name="answer_again_command_key">binding_FLIP_OR_ANSWER_EASE1</string>
Expand Down
11 changes: 9 additions & 2 deletions AnkiDroid/src/main/res/xml/preferences_controls.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:title="@string/pref_cat_controls"
android:key="@string/pref_controls_screen_key">
android:key="@string/pref_controls_screen_key"
tools:context=".preferences.ControlsSettingsFragment">

<SwitchPreferenceCompat
android:defaultValue="false"
Expand Down Expand Up @@ -48,7 +49,13 @@
android:defaultValue="100"
android:valueFrom="20"
android:valueTo="180"
app:displayValue="true"/>
app:displayValue="true" />

<Preference
android:key="@string/pref_keyboard_shortcuts_key"
android:title="@string/show_keyboard_shortcuts"
android:icon="@drawable/ic_keyboard"
/>

<PreferenceCategory android:title="@string/answer_buttons">
<com.ichi2.preferences.ControlPreference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class PreferencesAnalyticsTest : RobolectricTest() {
// Preferences that only click: don't have a value
R.string.tts_key, // tts
R.string.pref_reset_languages_key, // resetLanguages
R.string.pref_keyboard_shortcuts_key, // showKeyboardShortcuts
// Opens App Bar buttons fragment
R.string.custom_buttons_link_preference, // custom_buttons_link
// Opens Custom sync server fragment
Expand Down

0 comments on commit baf31be

Please sign in to comment.