Skip to content

Commit

Permalink
Add toolbar option to toggle Split Keyboard Setting - Enhancement #1218
Browse files Browse the repository at this point in the history
… (#1263)


---------

Co-authored-by: Josh <[email protected]>
Co-authored-by: Helium314 <[email protected]>
  • Loading branch information
3 people authored Feb 9, 2025
1 parent c0b3e76 commit 679754b
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,16 @@ public void switchOneHandedMode() {
Settings.getInstance().writeOneHandedModeGravity(mKeyboardViewWrapper.getOneHandedGravity());
}

public void toggleSplitKeyboardMode() {
final Settings settings = Settings.getInstance();
settings.writeSplitKeyboardEnabled(
!settings.getCurrent().mIsSplitKeyboardEnabled,
mCurrentOrientation == Configuration.ORIENTATION_LANDSCAPE
);
loadKeyboard(mLatinIME.getCurrentInputEditorInfo(), settings.getCurrent(),
mLatinIME.getCurrentAutoCapsState(), mLatinIME.getCurrentRecapitalizeState());
}

/**
* Displays a toast message.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class KeyboardIconsSet private constructor() {
ToolbarKey.FULL_RIGHT -> R.drawable.ic_to_end
ToolbarKey.PAGE_START -> R.drawable.ic_page_start
ToolbarKey.PAGE_END -> R.drawable.ic_page_end
ToolbarKey.SPLIT -> R.drawable.ic_ime_switcher
})
}
} }
Expand Down Expand Up @@ -212,6 +213,7 @@ class KeyboardIconsSet private constructor() {
ToolbarKey.FULL_RIGHT -> R.drawable.ic_to_end
ToolbarKey.PAGE_START -> R.drawable.ic_page_start
ToolbarKey.PAGE_END -> R.drawable.ic_page_end
ToolbarKey.SPLIT -> R.drawable.ic_ime_switcher
})
}
} }
Expand Down Expand Up @@ -272,6 +274,7 @@ class KeyboardIconsSet private constructor() {
ToolbarKey.FULL_RIGHT -> R.drawable.ic_to_end_rounded
ToolbarKey.PAGE_START -> R.drawable.ic_page_start_rounded
ToolbarKey.PAGE_END -> R.drawable.ic_page_end_rounded
ToolbarKey.SPLIT -> R.drawable.ic_ime_switcher
})
}
} }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ object KeyCode {
FN, CLIPBOARD_CLEAR_HISTORY, NUMPAD,

// heliboard only
SYMBOL_ALPHA, TOGGLE_ONE_HANDED_MODE, SWITCH_ONE_HANDED_MODE, SHIFT_ENTER,
SYMBOL_ALPHA, TOGGLE_ONE_HANDED_MODE, SWITCH_ONE_HANDED_MODE, SPLIT_LAYOUT, SHIFT_ENTER,
ACTION_NEXT, ACTION_PREVIOUS, NOT_SPECIFIED, CLIPBOARD_COPY_ALL, WORD_LEFT, WORD_RIGHT, PAGE_UP,
PAGE_DOWN, META, TAB, ESCAPE, INSERT, SLEEP, MEDIA_PLAY, MEDIA_PAUSE, MEDIA_PLAY_PAUSE, MEDIA_NEXT,
MEDIA_PREVIOUS, VOL_UP, VOL_DOWN, MUTE, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, BACK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ public static String printableCode(final int code) {
case CODE_SPACE: return "space";
case KeyCode.TOGGLE_ONE_HANDED_MODE: return "toggleOneHandedMode";
case KeyCode.SWITCH_ONE_HANDED_MODE: return "switchOneHandedMode";
case KeyCode.SPLIT_LAYOUT: return "splitLayout";
case KeyCode.NUMPAD: return "numpad";
default:
if (code < CODE_SPACE) return String.format("\\u%02X", code);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,9 @@ private void handleFunctionalEvent(final Event event, final InputTransaction inp
case KeyCode.REDO:
sendDownUpKeyEventWithMetaState(KeyEvent.KEYCODE_Z, KeyEvent.META_CTRL_ON | KeyEvent.META_SHIFT_ON);
break;
case KeyCode.SPLIT_LAYOUT:
KeyboardSwitcher.getInstance().toggleSplitKeyboardMode();
break;
case KeyCode.VOICE_INPUT:
// switching to shortcut IME, shift state, keyboard,... is handled by LatinIME,
// {@link KeyboardSwitcher#onEvent(Event)}, or {@link #onPressKey(int,int,boolean)} and {@link #onReleaseKey(int,boolean)}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ class AppearanceSettingsFragment : SubScreenFragment() {
private val dayNightPref: TwoStatePreference? by lazy { preferenceScreen.findPreference(Settings.PREF_THEME_DAY_NIGHT) }
private val userColorsPref: Preference by lazy { preferenceScreen.findPreference("theme_select_colors")!! }
private val userColorsPrefNight: Preference? by lazy { preferenceScreen.findPreference("theme_select_colors_night") }
private val splitPref: TwoStatePreference? by lazy { preferenceScreen.findPreference(Settings.PREF_ENABLE_SPLIT_KEYBOARD) }
private val splitLandscapePref: TwoStatePreference? by lazy { preferenceScreen.findPreference(Settings.PREF_ENABLE_SPLIT_KEYBOARD_LANDSCAPE) }
private val splitPortraitPref: TwoStatePreference? by lazy { preferenceScreen.findPreference(Settings.PREF_ENABLE_SPLIT_KEYBOARD) }
private val splitScalePref: Preference? by lazy { preferenceScreen.findPreference(Settings.PREF_SPLIT_SPACER_SCALE) }
private val splitScaleLandscapePref: Preference? by lazy { preferenceScreen.findPreference(Settings.PREF_SPLIT_SPACER_SCALE_LANDSCAPE) }

private val dayImageFilePicker = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
if (it.resultCode != Activity.RESULT_OK) return@registerForActivityResult
Expand Down Expand Up @@ -112,12 +114,20 @@ class AppearanceSettingsFragment : SubScreenFragment() {
setupScalePrefs(Settings.PREF_SIDE_PADDING_SCALE_LANDSCAPE, 0f)
if (splitScalePref != null) {
setupScalePrefs(Settings.PREF_SPLIT_SPACER_SCALE, SettingsValues.DEFAULT_SIZE_SCALE)
splitScalePref?.isVisible = splitPref?.isChecked == true
splitPref?.setOnPreferenceChangeListener { _, value ->
splitScalePref?.isVisible = splitPortraitPref?.isChecked == true
splitPortraitPref?.setOnPreferenceChangeListener { _, value ->
splitScalePref?.isVisible = value as Boolean
true
}
}
if (splitScaleLandscapePref != null) {
setupScalePrefs(Settings.PREF_SPLIT_SPACER_SCALE_LANDSCAPE, SettingsValues.DEFAULT_SIZE_SCALE)
splitScaleLandscapePref?.isVisible = splitLandscapePref?.isChecked == true
splitLandscapePref?.setOnPreferenceChangeListener { _, value ->
splitScaleLandscapePref?.isVisible = value as Boolean
true
}
}
findPreference<Preference>("custom_background_image")?.setOnPreferenceClickListener { onClickLoadImage(false) }
findPreference<Preference>("custom_background_image_landscape")?.setOnPreferenceClickListener { onClickLoadImage(true) }
findPreference<Preference>("custom_font")?.setOnPreferenceClickListener { onClickCustomFont() }
Expand Down Expand Up @@ -155,13 +165,6 @@ class AppearanceSettingsFragment : SubScreenFragment() {
removePreference("theme_select_colors_night")
}
}
val metrics = requireContext().resources.displayMetrics
val widthDp = TypedValueCompat.pxToDp(metrics.widthPixels.toFloat(), metrics)
val heightDp = TypedValueCompat.pxToDp(metrics.heightPixels.toFloat(), metrics)
if ((min(widthDp, heightDp) < 600 && max(widthDp, heightDp) < 720)) {
removePreference(Settings.PREF_ENABLE_SPLIT_KEYBOARD)
removePreference(Settings.PREF_SPLIT_SPACER_SCALE)
}
}

private fun setColorPrefs(style: String) {
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/java/helium314/keyboard/latin/settings/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static final String PREF_VARIABLE_TOOLBAR_DIRECTION = "var_toolbar_direction";
public static final String PREF_ADDITIONAL_SUBTYPES = "additional_subtypes";
public static final String PREF_ENABLE_SPLIT_KEYBOARD = "split_keyboard";
public static final String PREF_ENABLE_SPLIT_KEYBOARD_LANDSCAPE = "split_keyboard_landscape";
public static final String PREF_SPLIT_SPACER_SCALE = "split_spacer_scale";
public static final String PREF_SPLIT_SPACER_SCALE_LANDSCAPE = "split_spacer_scale_landscape";
public static final String PREF_KEYBOARD_HEIGHT_SCALE = "keyboard_height_scale";
public static final String PREF_BOTTOM_PADDING_SCALE = "bottom_padding_scale";
public static final String PREF_BOTTOM_PADDING_SCALE_LANDSCAPE = "bottom_padding_scale_landscape";
Expand Down Expand Up @@ -518,6 +520,21 @@ public void writeOneHandedModeGravity(final int gravity) {
(getCurrent().mDisplayOrientation == Configuration.ORIENTATION_PORTRAIT), gravity).apply();
}

public void writeSplitKeyboardEnabled(final boolean enabled, final boolean isLandscape) {
final String pref = isLandscape ? PREF_ENABLE_SPLIT_KEYBOARD_LANDSCAPE : PREF_ENABLE_SPLIT_KEYBOARD;
mPrefs.edit().putBoolean(pref, enabled).apply();
}

public static boolean readSplitKeyboardEnabled(final SharedPreferences prefs, final boolean isLandscape) {
final String pref = isLandscape ? PREF_ENABLE_SPLIT_KEYBOARD_LANDSCAPE : PREF_ENABLE_SPLIT_KEYBOARD;
return prefs.getBoolean(pref, false);
}

public static float readSplitSpacerScale(final SharedPreferences prefs, final boolean isLandscape) {
final String pref = isLandscape ? PREF_SPLIT_SPACER_SCALE_LANDSCAPE : PREF_SPLIT_SPACER_SCALE;
return prefs.getFloat(pref, SettingsValues.DEFAULT_SIZE_SCALE);
}

public static float readBottomPaddingScale(final SharedPreferences prefs, final boolean landscape) {
if (landscape)
return prefs.getFloat(PREF_BOTTOM_PADDING_SCALE_LANDSCAPE, 0f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public class SettingsValues {
public SettingsValues(final Context context, final SharedPreferences prefs, final Resources res,
@NonNull final InputAttributes inputAttributes) {
mLocale = ConfigurationCompatKt.locale(res.getConfiguration());
mDisplayOrientation = res.getConfiguration().orientation;

// Store the input attributes
mInputAttributes = inputAttributes;
Expand Down Expand Up @@ -202,11 +203,12 @@ public SettingsValues(final Context context, final SharedPreferences prefs, fina
mSuggestClipboardContent = readSuggestClipboardContent(prefs, res);
mDoubleSpacePeriodTimeout = res.getInteger(R.integer.config_double_space_period_timeout);
mHasHardwareKeyboard = Settings.readHasHardwareKeyboard(res.getConfiguration());
final boolean isLandscape = mDisplayOrientation == Configuration.ORIENTATION_LANDSCAPE;
final float displayWidthDp = TypedValueCompat.pxToDp(res.getDisplayMetrics().widthPixels, res.getDisplayMetrics());
mIsSplitKeyboardEnabled = prefs.getBoolean(Settings.PREF_ENABLE_SPLIT_KEYBOARD, false) && displayWidthDp > 600; // require display width of 600 dp for split
mIsSplitKeyboardEnabled = Settings.readSplitKeyboardEnabled(prefs, isLandscape);
// determine spacerWidth from display width and scale setting
mSplitKeyboardSpacerRelativeWidth = mIsSplitKeyboardEnabled
? Math.min(Math.max((displayWidthDp - 600) / 600f + 0.15f, 0.15f), 0.35f) * prefs.getFloat(Settings.PREF_SPLIT_SPACER_SCALE, DEFAULT_SIZE_SCALE)
? Math.min(Math.max((displayWidthDp - 600) / 600f + 0.15f, 0.15f), 0.35f) * Settings.readSplitSpacerScale(prefs, isLandscape)
: 0f;
mQuickPinToolbarKeys = prefs.getBoolean(Settings.PREF_QUICK_PIN_TOOLBAR_KEYS, false);
mScreenMetrics = Settings.readScreenMetrics(res);
Expand All @@ -230,7 +232,6 @@ public SettingsValues(final Context context, final SharedPreferences prefs, fina
mIncognitoModeEnabled = Settings.readAlwaysIncognitoMode(prefs) || mInputAttributes.mNoLearning
|| mInputAttributes.mIsPasswordField;
mKeyboardHeightScale = prefs.getFloat(Settings.PREF_KEYBOARD_HEIGHT_SCALE, DEFAULT_SIZE_SCALE);
mDisplayOrientation = res.getConfiguration().orientation;
mSpaceSwipeHorizontal = Settings.readHorizontalSpaceSwipe(prefs);
mSpaceSwipeVertical = Settings.readVerticalSpaceSwipe(prefs);
mLanguageSwipeDistance = Settings.readLanguageSwipeDistance(prefs, res);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ private fun setToolbarButtonActivatedState(button: ImageButton) {
button.isActivated = when (button.tag) {
INCOGNITO -> Settings.readAlwaysIncognitoMode(DeviceProtectedUtils.getSharedPreferences(button.context))
ONE_HANDED -> Settings.getInstance().current.mOneHandedModeEnabled
SPLIT -> Settings.getInstance().current.mIsSplitKeyboardEnabled
AUTOCORRECT -> Settings.getInstance().current.mAutoCorrectionEnabledPerUserSettings
else -> true
}
Expand Down Expand Up @@ -99,6 +100,7 @@ fun getCodeForToolbarKey(key: ToolbarKey) = Settings.getInstance().getCustomTool
FULL_RIGHT -> KeyCode.MOVE_END_OF_LINE
PAGE_START -> KeyCode.MOVE_START_OF_PAGE
PAGE_END -> KeyCode.MOVE_END_OF_PAGE
SPLIT -> KeyCode.SPLIT_LAYOUT
}

fun getCodeForToolbarKeyLongClick(key: ToolbarKey) = Settings.getInstance().getCustomToolbarLongpressCode(key) ?: when (key) {
Expand All @@ -122,7 +124,7 @@ fun getCodeForToolbarKeyLongClick(key: ToolbarKey) = Settings.getInstance().getC

// names need to be aligned with resources strings (using lowercase of key.name)
enum class ToolbarKey {
VOICE, CLIPBOARD, NUMPAD, UNDO, REDO, SETTINGS, SELECT_ALL, SELECT_WORD, COPY, CUT, PASTE, ONE_HANDED,
VOICE, CLIPBOARD, NUMPAD, UNDO, REDO, SETTINGS, SELECT_ALL, SELECT_WORD, COPY, CUT, PASTE, ONE_HANDED, SPLIT,
INCOGNITO, AUTOCORRECT, CLEAR_CLIPBOARD, CLOSE_HISTORY, EMOJI, LEFT, RIGHT, UP, DOWN, WORD_LEFT, WORD_RIGHT,
PAGE_UP, PAGE_DOWN, FULL_LEFT, FULL_RIGHT, PAGE_START, PAGE_END
}
Expand Down
9 changes: 7 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,14 @@
<string name="settings_category_experimental">Experimental</string>
<!-- Settings category title for Appearance & Layout/Misc [CHAR LIMIT=33] -->
<string name="settings_category_miscellaneous">Miscellaneous</string>
<!-- Option for enabling or disabling the split keyboard layout. [CHAR LIMIT=65]-->
<!-- Option for enabling or disabling the split keyboard layout in portrait mode. [CHAR LIMIT=65]-->
<string name="enable_split_keyboard">Enable split keyboard</string>
<!-- Option for setting distance for split keyboard -->
<!-- Option for enabling or disabling the split keyboard layout in landscape mode. [CHAR LIMIT=65]-->
<string name="enable_split_keyboard_landscape">Enable split keyboard (landscape)</string>
<!-- Option for setting distance for split keyboard in portrait mode -->
<string name="split_spacer_scale">Split distance</string>
<!-- Option for setting distance for split keyboard in landscape mode -->
<string name="split_spacer_scale_landscape">Split distance (landscape)</string>
<!-- Option name for including other IMEs in the language key switch list [CHAR LIMIT=30] -->
<string name="language_switch_key_switch_input_method">Switch to other input methods</string>
<!-- Option name for switching language / subtype only [CHAR LIMIT=30] -->
Expand Down Expand Up @@ -269,6 +273,7 @@
<string name="select_all" tools:keep="@string/select_all" translatable="false">@android:string/selectAll</string>
<string name="select_word" tools:keep="@string/select_word">Select word</string>
<string name="one_handed" tools:keep="@string/one_handed">One-handed mode</string>
<string name="split" tools:keep="@string/split">Split keyboard</string>
<string name="full_left" tools:keep="@string/full_left">Full left</string>
<string name="full_right" tools:keep="@string/full_right">Full right</string>
<string name="page_start" tools:keep="@string/page_start">Page start</string>
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/xml/prefs_screen_appearance.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@
latin:minValue="50"
latin:maxValue="200" /> <!-- percentage -->

<SwitchPreference
android:key="split_keyboard_landscape"
android:title="@string/enable_split_keyboard_landscape"
android:persistent="true"
android:defaultValue="false" />

<helium314.keyboard.latin.settings.SeekBarDialogPreference
android:key="split_spacer_scale_landscape"
android:title="@string/split_spacer_scale_landscape"
latin:minValue="50"
latin:maxValue="200" /> <!-- percentage -->

<SwitchPreference
android:key="narrow_key_gaps"
android:title="@string/prefs_narrow_key_gaps"
Expand Down

0 comments on commit 679754b

Please sign in to comment.