add setting for localized number row (if applicable for enabled subtypes)

This commit is contained in:
Helium314 2023-11-27 15:50:06 +01:00
parent 2b8c62cb02
commit 4d015d0c83
7 changed files with 82 additions and 29 deletions

View file

@ -63,17 +63,33 @@ open class KeyboardBuilder<KP : KeyboardParams>(protected val mContext: Context,
return this return this
// todo: further plan // todo: further plan
// add option for number row (latin first vs locale numbers first // release next version before continuing, testing current state for a while is likely necessary
// show only if number row enabled // migrate other languages/layouts to this style
// release next version before continuing
// migrate other languages to this style
// may be tricky in some cases, like additional row, or no shift key, or pc qwerty layout // may be tricky in some cases, like additional row, or no shift key, or pc qwerty layout
// also the integrated number row might cause issues, and should be removed / ignored // also the integrated number row might cause issues, and should be removed / ignored
// at least some of these layouts will need more complicated definition // at least some of these layouts will need more complicated definition
// test the zwnj key // test the zwnj key
// label flags: some should be set by keyboard, not by row/letter
// e.g. arabic looks weird with number row in holo being bold, but all other letters normal
// migrate keypad layouts to this style // migrate keypad layouts to this style
// will need more configurable layout definition -> another parser, or do it with compatible jsons // will need more configurable layout definition -> another parser, or do it with compatible jsons
// allow users to define their own layouts (maybe migrate other layouts first?) // make the remove duplicate moreKey thing an option?
// why is it on for serbian (latin), but not for german (german)?
// only nordic and serbian_qwertz layouts have it disabled, default is enabled
// -> add the option, but disable it by default for all layouts
// migrate emoji layouts to this style
// emojis are defined in that string array, should be simple to handle
// parsing could be done into a single row, which is then split as needed
// this might help with split layout (no change in key size, but in number of rows)
// write another parser, it should already consider split
// migrate moreKeys and moreSuggestions to this style?
// at least they should not make use of the KeyTextsSet/Table (and of the XmlKeyboardParser?)
// remove the old parser
// then finally the spanish/german/swiss/nordic layouts can be removed and replaced by some hasExtraKeys parameter
// also the eo check could then be removed
// and maybe the language -> layout thing could be moved to assets? and maybe even here the extra keys could be defined...
// should be either both in method.xml, or both in assets (actually method might be more suitable)
// allow users to define their own layouts (maybe do everything else first?)
// need to solve the scaling issue with number row and 5 row keyboards // need to solve the scaling issue with number row and 5 row keyboards
// write up how things work for users, also regarding language more keys // write up how things work for users, also regarding language more keys
// readme, maybe also some "help" button in a dialog // readme, maybe also some "help" button in a dialog
@ -96,24 +112,7 @@ open class KeyboardBuilder<KP : KeyboardParams>(protected val mContext: Context,
// popup and (single key) long press preview rescale the label on x only, which may deform emojis // popup and (single key) long press preview rescale the label on x only, which may deform emojis
// does glide typing work with multiple letters on one key? if not, users should be notified // does glide typing work with multiple letters on one key? if not, users should be notified
// maybe allow users to define their own symbol and shift-symbol layouts // maybe allow users to define their own symbol and shift-symbol layouts
// allow users to import layouts, which essentially just fills the text from a file // allow users to import layouts, which essentially just fills the text from a file
// can be json too, but need to have a (close to) final definition first
// make the remove duplicate moreKey thing an option?
// why is it on for serbian (latin), but not for german (german)?
// only nordic and serbian_qwertz layouts have it disabled, default is enabled
// -> add the option, but disable it by default for all layouts
// migrate emoji layouts to this style
// emojis are defined in that string array, should be simple to handle
// parsing could be done into a single row, which is then split as needed
// this might help with split layout (no change in key size, but in number of rows)
// write another parser, it should already consider split
// migrate moreKeys and moreSuggestions to this style?
// at least they should not make use of the KeyTextsSet/Table (and of the XmlKeyboardParser?)
// remove the old parser
// then finally the spanish/german/swiss/nordic layouts can be removed and replaced by some hasExtraKeys parameter
// also the eo check could then be removed
// and maybe the language -> layout thing could be moved to assets? and maybe even here the extra keys could be defined...
// should be either both in method.xml, or both in assets (actually method might be more suitable)
// labelFlags should be set correctly // labelFlags should be set correctly
// alignHintLabelToBottom: on lxx and rounded themes, but did not find what it actually does... // alignHintLabelToBottom: on lxx and rounded themes, but did not find what it actually does...

View file

@ -7,6 +7,7 @@ import org.dslul.openboard.inputmethod.keyboard.internal.KeyboardParams
import org.dslul.openboard.inputmethod.keyboard.internal.keyboard_parser.floris.KeyData import org.dslul.openboard.inputmethod.keyboard.internal.keyboard_parser.floris.KeyData
import org.dslul.openboard.inputmethod.keyboard.internal.keyboard_parser.floris.toTextKey import org.dslul.openboard.inputmethod.keyboard.internal.keyboard_parser.floris.toTextKey
import org.dslul.openboard.inputmethod.latin.common.splitOnWhitespace import org.dslul.openboard.inputmethod.latin.common.splitOnWhitespace
import org.dslul.openboard.inputmethod.latin.settings.Settings
import java.io.InputStream import java.io.InputStream
import java.util.Locale import java.util.Locale
import kotlin.math.round import kotlin.math.round
@ -70,7 +71,7 @@ class LocaleKeyTexts(dataStream: InputStream?, locale: Locale) {
READER_MODE_MORE_KEYS -> addMoreKeys(line.splitOnWhitespace()) READER_MODE_MORE_KEYS -> addMoreKeys(line.splitOnWhitespace())
READER_MODE_EXTRA_KEYS -> if (!onlyMoreKeys) addExtraKey(line.split(colonSpaceRegex, 2)) READER_MODE_EXTRA_KEYS -> if (!onlyMoreKeys) addExtraKey(line.split(colonSpaceRegex, 2))
READER_MODE_LABELS -> if (!onlyMoreKeys) addLabel(line.split(colonSpaceRegex, 2)) READER_MODE_LABELS -> if (!onlyMoreKeys) addLabel(line.split(colonSpaceRegex, 2))
READER_MODE_NUMBER_ROW -> if (!onlyMoreKeys) setNumberRow(line.splitOnWhitespace()) READER_MODE_NUMBER_ROW -> setNumberRow(line.splitOnWhitespace(), onlyMoreKeys)
} }
} }
} }
@ -119,10 +120,21 @@ class LocaleKeyTexts(dataStream: InputStream?, locale: Locale) {
// set number row only, does not affect moreKeys // set number row only, does not affect moreKeys
// setting more than 10 number keys will cause crashes, but could actually be implemented at some point // setting more than 10 number keys will cause crashes, but could actually be implemented at some point
private fun setNumberRow(split: List<String>) { private fun setNumberRow(split: List<String>, onlyAddToMoreKeys: Boolean) {
if (numberKeys == split) return if (onlyAddToMoreKeys) {
numberKeys.forEachIndexed { i, n -> numbersMoreKeys[i].add(0, n) } // as of now this should never be used, but better have it
numberKeys = split numberKeys.forEachIndexed { i, n ->
if (numberKeys[i] != n && n !in numbersMoreKeys[i])
numbersMoreKeys[i].add(0, n)
}
return
}
if (Settings.getInstance().current.mLocalizedNumberRow) {
numberKeys.forEachIndexed { i, n -> numbersMoreKeys[i].add(0, n) }
numberKeys = split
} else {
split.forEachIndexed { i, n -> numbersMoreKeys[i].add(0, n) }
}
} }
// get number row including moreKeys // get number row including moreKeys

View file

@ -14,15 +14,19 @@ import android.graphics.drawable.Drawable;
import android.media.AudioManager; import android.media.AudioManager;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.inputmethod.InputMethodSubtype;
import androidx.core.graphics.drawable.DrawableCompat; import androidx.core.graphics.drawable.DrawableCompat;
import androidx.preference.Preference; import androidx.preference.Preference;
import org.dslul.openboard.inputmethod.keyboard.KeyboardLayoutSet;
import org.dslul.openboard.inputmethod.keyboard.KeyboardSwitcher; import org.dslul.openboard.inputmethod.keyboard.KeyboardSwitcher;
import org.dslul.openboard.inputmethod.latin.AudioAndHapticFeedbackManager; import org.dslul.openboard.inputmethod.latin.AudioAndHapticFeedbackManager;
import org.dslul.openboard.inputmethod.latin.R; import org.dslul.openboard.inputmethod.latin.R;
import org.dslul.openboard.inputmethod.latin.RichInputMethodManager; import org.dslul.openboard.inputmethod.latin.RichInputMethodManager;
import kotlin.collections.ArraysKt;
public final class PreferencesSettingsFragment extends SubScreenFragment { public final class PreferencesSettingsFragment extends SubScreenFragment {
private boolean mReloadKeyboard = false; private boolean mReloadKeyboard = false;
@ -62,6 +66,7 @@ public final class PreferencesSettingsFragment extends SubScreenFragment {
setupKeypressSoundVolumeSettings(); setupKeypressSoundVolumeSettings();
setupHistoryRetentionTimeSettings(); setupHistoryRetentionTimeSettings();
refreshEnablingsOfKeypressSoundAndVibrationAndHistRetentionSettings(); refreshEnablingsOfKeypressSoundAndVibrationAndHistRetentionSettings();
setLocalizedNumberRowVisibility();
} }
@Override @Override
@ -74,6 +79,10 @@ public final class PreferencesSettingsFragment extends SubScreenFragment {
refreshEnablingsOfKeypressSoundAndVibrationAndHistRetentionSettings(); refreshEnablingsOfKeypressSoundAndVibrationAndHistRetentionSettings();
if (Settings.PREF_SHOW_POPUP_HINTS.equals(key)) if (Settings.PREF_SHOW_POPUP_HINTS.equals(key))
mReloadKeyboard = true; mReloadKeyboard = true;
if (key.equals(Settings.PREF_SHOW_NUMBER_ROW))
setLocalizedNumberRowVisibility();
if (key.equals(Settings.PREF_LOCALIZED_NUMBER_ROW))
KeyboardLayoutSet.onSystemLocaleChanged();
} }
@Override @Override
@ -84,6 +93,25 @@ public final class PreferencesSettingsFragment extends SubScreenFragment {
mReloadKeyboard = false; mReloadKeyboard = false;
} }
private void setLocalizedNumberRowVisibility() {
final Preference pref = findPreference(Settings.PREF_LOCALIZED_NUMBER_ROW);
if (pref == null) return;
if (!getSharedPreferences().getBoolean(Settings.PREF_SHOW_NUMBER_ROW, false)) {
pref.setVisible(false);
return;
}
// locales that have a number row defined (not good to have it hardcoded, but reading a bunch of files isn't great either)
final String[] numberRowLocales = new String[] { "ar", "bn", "fa", "hi", "mr", "ne", "ur" };
for (final InputMethodSubtype subtype : SubtypeSettingsKt.getEnabledSubtypes(getSharedPreferences(), true)) {
if (ArraysKt.any(numberRowLocales, (l) -> l.equals(subtype.getLocale().substring(0, 2)))) {
pref.setVisible(true);
return;
}
}
pref.setVisible(false);
}
private void refreshEnablingsOfKeypressSoundAndVibrationAndHistRetentionSettings() { private void refreshEnablingsOfKeypressSoundAndVibrationAndHistRetentionSettings() {
final SharedPreferences prefs = getSharedPreferences(); final SharedPreferences prefs = getSharedPreferences();
final Resources res = getResources(); final Resources res = getResources();

View file

@ -103,12 +103,13 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static final String PREF_GESTURE_FLOATING_PREVIEW_TEXT = "pref_gesture_floating_preview_text"; public static final String PREF_GESTURE_FLOATING_PREVIEW_TEXT = "pref_gesture_floating_preview_text";
public static final String PREF_GESTURE_SPACE_AWARE = "pref_gesture_space_aware"; public static final String PREF_GESTURE_SPACE_AWARE = "pref_gesture_space_aware";
public static final String PREF_SHOW_SETUP_WIZARD_ICON = "pref_show_setup_wizard_icon"; public static final String PREF_SHOW_SETUP_WIZARD_ICON = "pref_show_setup_wizard_icon";
public static final String PREF_USE_NEW_KEYBOARD_PARSING = "pref_use_new_keyboard_parsing"; // todo: remove later public static final String PREF_USE_NEW_KEYBOARD_PARSING = "pref_use_new_keyboard_parsing1"; // todo: remove later
public static final String PREF_ONE_HANDED_MODE = "pref_one_handed_mode_enabled"; public static final String PREF_ONE_HANDED_MODE = "pref_one_handed_mode_enabled";
public static final String PREF_ONE_HANDED_GRAVITY = "pref_one_handed_mode_gravity"; public static final String PREF_ONE_HANDED_GRAVITY = "pref_one_handed_mode_gravity";
public static final String PREF_SHOW_NUMBER_ROW = "pref_show_number_row"; public static final String PREF_SHOW_NUMBER_ROW = "pref_show_number_row";
public static final String PREF_LOCALIZED_NUMBER_ROW = "pref_localized_number_row";
public static final String PREF_SHOW_HINTS = "pref_show_hints"; public static final String PREF_SHOW_HINTS = "pref_show_hints";
public static final String PREF_SHOW_POPUP_HINTS = "pref_show_popup_hints"; public static final String PREF_SHOW_POPUP_HINTS = "pref_show_popup_hints";

View file

@ -64,6 +64,7 @@ public class SettingsValues {
public final boolean mLanguageSwitchKeyToOtherImes; public final boolean mLanguageSwitchKeyToOtherImes;
public final boolean mLanguageSwitchKeyToOtherSubtypes; public final boolean mLanguageSwitchKeyToOtherSubtypes;
public final boolean mShowsNumberRow; public final boolean mShowsNumberRow;
public final boolean mLocalizedNumberRow;
public final boolean mShowsHints; public final boolean mShowsHints;
public final boolean mShowsPopupHints; public final boolean mShowsPopupHints;
public final boolean mSpaceForLangChange; public final boolean mSpaceForLangChange;
@ -148,6 +149,7 @@ public class SettingsValues {
mLanguageSwitchKeyToOtherImes = languagePref.equals("input_method") || languagePref.equals("both"); mLanguageSwitchKeyToOtherImes = languagePref.equals("input_method") || languagePref.equals("both");
mLanguageSwitchKeyToOtherSubtypes = languagePref.equals("internal") || languagePref.equals("both"); mLanguageSwitchKeyToOtherSubtypes = languagePref.equals("internal") || languagePref.equals("both");
mShowsNumberRow = prefs.getBoolean(Settings.PREF_SHOW_NUMBER_ROW, false); mShowsNumberRow = prefs.getBoolean(Settings.PREF_SHOW_NUMBER_ROW, false);
mLocalizedNumberRow = mShowsNumberRow && prefs.getBoolean(Settings.PREF_LOCALIZED_NUMBER_ROW, true);
mShowsHints = prefs.getBoolean(Settings.PREF_SHOW_HINTS, true); mShowsHints = prefs.getBoolean(Settings.PREF_SHOW_HINTS, true);
mShowsPopupHints = prefs.getBoolean(Settings.PREF_SHOW_POPUP_HINTS, false); mShowsPopupHints = prefs.getBoolean(Settings.PREF_SHOW_POPUP_HINTS, false);
mSpaceForLangChange = prefs.getBoolean(Settings.PREF_SPACE_TO_CHANGE_LANG, true); mSpaceForLangChange = prefs.getBoolean(Settings.PREF_SPACE_TO_CHANGE_LANG, true);

View file

@ -230,6 +230,10 @@
<string name="number_row">Number row</string> <string name="number_row">Number row</string>
<!-- Description of the settings to enable number row --> <!-- Description of the settings to enable number row -->
<string name="number_row_summary">Always show number row</string> <string name="number_row_summary">Always show number row</string>
<!-- Title of the settings to localize number row -->
<string name="localized_number_row">Localize number row</string>
<!-- Description of the settings to localize number row -->
<string name="localized_number_row_summary">Prefer localized over latin numbers</string>
<!-- Title of the settings to show key hints --> <!-- Title of the settings to show key hints -->
<string name="show_hints">Show key hints</string> <string name="show_hints">Show key hints</string>
<!-- Description of the settings to show hints --> <!-- Description of the settings to show hints -->

View file

@ -64,6 +64,13 @@
android:defaultValue="false" android:defaultValue="false"
android:persistent="true" /> android:persistent="true" />
<SwitchPreferenceCompat
android:key="pref_localized_number_row"
android:title="@string/localized_number_row"
android:summary="@string/localized_number_row_summary"
android:defaultValue="true"
android:persistent="true" />
<ListPreference <ListPreference
android:key="pref_language_switch_key" android:key="pref_language_switch_key"
android:title="@string/show_language_switch_key" android:title="@string/show_language_switch_key"