From 7ff88006b7be2a283c294d7460b339cd10225c24 Mon Sep 17 00:00:00 2001 From: KP2A Developer Date: Sat, 4 Apr 2026 12:12:30 +0530 Subject: [PATCH] Add Dvorak keyboard layout option (#1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implements a user-selectable Dvorak keyboard layout alongside the existing QWERTY layout. Users can switch between layouts via a new "Key layout" preference in the keyboard settings screen. Changes: - res/xml/kbd_dvorak.xml: Dvorak alpha layout (light theme) Row 1: , . p y f g c r l ⌫ Row 2: a o e u i d h t n s Row 3: ⇧ z q j k x b m w v Bottom row: ' [space] ; (replacing f1 and period flanking keys) - res/xml/kbd_dvorak_black.xml: Same layout, dark theme icons - res/values/donottranslate-altchars.xml: Add alternates_for_apostrophe and alternates_for_semicolon for long-press popups on bottom-row keys - res/values/strings.xml: Add pref_key_layout_title, pref_key_layout_qwerty, pref_key_layout_dvorak strings and key_layout_entries/key_layout_entry_values arrays for the ListPreference - res/xml/prefs.xml: Add ListPreference for key layout selection near the language selection preference - KeyboardSwitcher.java: Add PREF_KEY_LAYOUT, KEY_LAYOUT_QWERTY, KEY_LAYOUT_DVORAK constants; KBD_DVORAK resource table; mKeyLayout field; read preference in init(); select Dvorak vs QWERTY resources in getKeyboardId(); handle preference change in onSharedPreferenceChanged() - LatinKeyboard.java: Extend mIsAlphaKeyboard check to include Dvorak resource IDs so shift/space bar behaviour works correctly on Dvorak Co-Authored-By: Claude Sonnet 4.6 --- .../softkeyboard/KeyboardSwitcher.java | 12 +- .../softkeyboard/LatinKeyboard.java | 4 +- .../res/values/donottranslate-altchars.xml | 2 + .../app/src/main/res/values/strings.xml | 13 + .../app/src/main/res/xml/kbd_dvorak.xml | 540 ++++++++++++++++++ .../app/src/main/res/xml/kbd_dvorak_black.xml | 480 ++++++++++++++++ .../app/src/main/res/xml/prefs.xml | 8 + 7 files changed, 1057 insertions(+), 2 deletions(-) create mode 100644 src/java/KP2ASoftkeyboard_AS/app/src/main/res/xml/kbd_dvorak.xml create mode 100644 src/java/KP2ASoftkeyboard_AS/app/src/main/res/xml/kbd_dvorak_black.xml diff --git a/src/java/KP2ASoftkeyboard_AS/app/src/main/java/keepass2android/softkeyboard/KeyboardSwitcher.java b/src/java/KP2ASoftkeyboard_AS/app/src/main/java/keepass2android/softkeyboard/KeyboardSwitcher.java index e6847814a..506cc493e 100644 --- a/src/java/KP2ASoftkeyboard_AS/app/src/main/java/keepass2android/softkeyboard/KeyboardSwitcher.java +++ b/src/java/KP2ASoftkeyboard_AS/app/src/main/java/keepass2android/softkeyboard/KeyboardSwitcher.java @@ -69,6 +69,9 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha public static final String DEFAULT_LAYOUT_ID = "4"; public static final String PREF_KEYBOARD_LAYOUT = "pref_keyboard_layout_20100902"; + public static final String PREF_KEY_LAYOUT = "pref_key_layout"; + public static final String KEY_LAYOUT_QWERTY = "qwerty"; + public static final String KEY_LAYOUT_DVORAK = "dvorak"; private static final int[] THEMES = new int [] { R.layout.input_basic, R.layout.input_basic_highcontrast, R.layout.input_stone_normal, R.layout.input_stone_bold, R.layout.input_gingerbread}; @@ -86,6 +89,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha private static final int[] KBD_SYMBOLS_SHIFT = new int[] { R.xml.kbd_symbols_shift, R.xml.kbd_symbols_shift_black}; private static final int[] KBD_QWERTY = new int[] {R.xml.kbd_qwerty, R.xml.kbd_qwerty_black}; + private static final int[] KBD_DVORAK = new int[] {R.xml.kbd_dvorak, R.xml.kbd_dvorak_black}; private static final int[] KBD_KP2A = new int[] {R.xml.kbd_kp2a, R.xml.kbd_kp2a_black}; @@ -141,6 +145,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha private Locale mInputLocale; private int mLayoutId; + private String mKeyLayout; private static final KeyboardSwitcher sInstance = new KeyboardSwitcher(); @@ -158,6 +163,7 @@ public static void init(KP2AKeyboard ims) { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ims); sInstance.mLayoutId = Integer.valueOf( prefs.getString(PREF_KEYBOARD_LAYOUT, DEFAULT_LAYOUT_ID)); + sInstance.mKeyLayout = prefs.getString(PREF_KEY_LAYOUT, KEY_LAYOUT_QWERTY); sInstance.updateSettingsKeyState(prefs); prefs.registerOnSharedPreferenceChangeListener(sInstance); @@ -321,7 +327,8 @@ private KeyboardId getKeyboardId(int mode, int imeOptions, boolean isSymbols) { } } // TODO: generalize for any KeyboardId - int keyboardRowsResId = KBD_QWERTY[charColorId]; + int[] alphaKbd = KEY_LAYOUT_DVORAK.equals(mKeyLayout) ? KBD_DVORAK : KBD_QWERTY; + int keyboardRowsResId = alphaKbd[charColorId]; switch (mode) { case MODE_KP2A: @@ -569,6 +576,9 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin if (PREF_KEYBOARD_LAYOUT.equals(key)) { changeLatinKeyboardView( Integer.valueOf(sharedPreferences.getString(key, DEFAULT_LAYOUT_ID)), false); + } else if (PREF_KEY_LAYOUT.equals(key)) { + mKeyLayout = sharedPreferences.getString(key, KEY_LAYOUT_QWERTY); + setKeyboardMode(mMode, mImeOptions, mPreferSymbols); } else if (LatinIMESettings.PREF_SETTINGS_KEY.equals(key)) { updateSettingsKeyState(sharedPreferences); recreateInputView(); diff --git a/src/java/KP2ASoftkeyboard_AS/app/src/main/java/keepass2android/softkeyboard/LatinKeyboard.java b/src/java/KP2ASoftkeyboard_AS/app/src/main/java/keepass2android/softkeyboard/LatinKeyboard.java index 45bc65d90..21396c02d 100644 --- a/src/java/KP2ASoftkeyboard_AS/app/src/main/java/keepass2android/softkeyboard/LatinKeyboard.java +++ b/src/java/KP2ASoftkeyboard_AS/app/src/main/java/keepass2android/softkeyboard/LatinKeyboard.java @@ -144,7 +144,9 @@ public LatinKeyboard(Context context, int xmlLayoutResId, int mode) { sSpacebarVerticalCorrection = res.getDimensionPixelOffset( R.dimen.spacebar_vertical_correction); mIsAlphaKeyboard = xmlLayoutResId == R.xml.kbd_qwerty - || xmlLayoutResId == R.xml.kbd_qwerty_black; + || xmlLayoutResId == R.xml.kbd_qwerty_black + || xmlLayoutResId == R.xml.kbd_dvorak + || xmlLayoutResId == R.xml.kbd_dvorak_black; // The index of space key is available only after Keyboard constructor has finished. mSpaceKeyIndexArray = new int[] { indexOf(KP2AKeyboard.KEYCODE_SPACE) }; initializeNumberHintResources(context); diff --git a/src/java/KP2ASoftkeyboard_AS/app/src/main/res/values/donottranslate-altchars.xml b/src/java/KP2ASoftkeyboard_AS/app/src/main/res/values/donottranslate-altchars.xml index bba7282c9..d56fe5447 100644 --- a/src/java/KP2ASoftkeyboard_AS/app/src/main/res/values/donottranslate-altchars.xml +++ b/src/java/KP2ASoftkeyboard_AS/app/src/main/res/values/donottranslate-altchars.xml @@ -43,4 +43,6 @@ + \u2018\u2019\u201C\u201D\u0060\u00B4" + : diff --git a/src/java/KP2ASoftkeyboard_AS/app/src/main/res/values/strings.xml b/src/java/KP2ASoftkeyboard_AS/app/src/main/res/values/strings.xml index f4c674f20..b24489791 100644 --- a/src/java/KP2ASoftkeyboard_AS/app/src/main/res/values/strings.xml +++ b/src/java/KP2ASoftkeyboard_AS/app/src/main/res/values/strings.xml @@ -373,6 +373,19 @@ keyboard voice + + Key layout + QWERTY + Dvorak + + @string/pref_key_layout_qwerty + @string/pref_key_layout_dvorak + + + qwerty + dvorak + + Android keyboard Debug settings Debug Mode diff --git a/src/java/KP2ASoftkeyboard_AS/app/src/main/res/xml/kbd_dvorak.xml b/src/java/KP2ASoftkeyboard_AS/app/src/main/res/xml/kbd_dvorak.xml new file mode 100644 index 000000000..77599a31f --- /dev/null +++ b/src/java/KP2ASoftkeyboard_AS/app/src/main/res/xml/kbd_dvorak.xml @@ -0,0 +1,540 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/java/KP2ASoftkeyboard_AS/app/src/main/res/xml/kbd_dvorak_black.xml b/src/java/KP2ASoftkeyboard_AS/app/src/main/res/xml/kbd_dvorak_black.xml new file mode 100644 index 000000000..60c05d555 --- /dev/null +++ b/src/java/KP2ASoftkeyboard_AS/app/src/main/res/xml/kbd_dvorak_black.xml @@ -0,0 +1,480 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/java/KP2ASoftkeyboard_AS/app/src/main/res/xml/prefs.xml b/src/java/KP2ASoftkeyboard_AS/app/src/main/res/xml/prefs.xml index d748765e7..0bf54229e 100644 --- a/src/java/KP2ASoftkeyboard_AS/app/src/main/res/xml/prefs.xml +++ b/src/java/KP2ASoftkeyboard_AS/app/src/main/res/xml/prefs.xml @@ -61,6 +61,14 @@ android:action="keepass2android.softkeyboard.INPUT_LANGUAGE_SELECTION"/> + +