add separate number row

This code is adapted from Indic Keyboard, and doesn't resize the buttons when switching from/to symbols; instead, an additional row is always shown. Fixes #21.
This commit is contained in:
dslul 2020-09-11 16:59:15 +02:00
parent 98b9a8fdf1
commit 3377df1e9d
14 changed files with 100 additions and 1 deletions

View file

@ -78,6 +78,7 @@ public final class KeyboardId {
public final int mElementId;
public final EditorInfo mEditorInfo;
public final boolean mClobberSettingsKey;
public final boolean mNumberRowEnabled;
public final boolean mLanguageSwitchKeyEnabled;
public final String mCustomActionLabel;
public final boolean mHasShortcutKey;
@ -93,6 +94,7 @@ public final class KeyboardId {
mElementId = elementId;
mEditorInfo = params.mEditorInfo;
mClobberSettingsKey = params.mNoSettingsKey;
mNumberRowEnabled = params.mNumberRowEnabled;
mLanguageSwitchKeyEnabled = params.mLanguageSwitchKeyEnabled;
mCustomActionLabel = (mEditorInfo.actionLabel != null)
? mEditorInfo.actionLabel.toString() : null;
@ -111,6 +113,7 @@ public final class KeyboardId {
id.passwordInput(),
id.mClobberSettingsKey,
id.mHasShortcutKey,
id.mNumberRowEnabled,
id.mLanguageSwitchKeyEnabled,
id.isMultiLine(),
id.imeAction(),
@ -132,6 +135,7 @@ public final class KeyboardId {
&& other.passwordInput() == passwordInput()
&& other.mClobberSettingsKey == mClobberSettingsKey
&& other.mHasShortcutKey == mHasShortcutKey
&& other.mNumberRowEnabled == mNumberRowEnabled
&& other.mLanguageSwitchKeyEnabled == mLanguageSwitchKeyEnabled
&& other.isMultiLine() == isMultiLine()
&& other.imeAction() == imeAction()
@ -202,6 +206,7 @@ public final class KeyboardId {
(mClobberSettingsKey ? " clobberSettingsKey" : ""),
(passwordInput() ? " passwordInput" : ""),
(mHasShortcutKey ? " hasShortcutKey" : ""),
(mNumberRowEnabled ? " numberRowEnabled" : ""),
(mLanguageSwitchKeyEnabled ? " languageSwitchKeyEnabled" : ""),
(isMultiLine() ? " isMultiLine" : ""),
(mIsSplitLayout ? " isSplitLayout" : "")

View file

@ -119,6 +119,7 @@ public final class KeyboardLayoutSet {
boolean mIsPasswordField;
boolean mVoiceInputKeyEnabled;
boolean mNoSettingsKey;
boolean mNumberRowEnabled;
boolean mLanguageSwitchKeyEnabled;
RichInputMethodSubtype mSubtype;
boolean mIsSpellChecker;
@ -324,6 +325,11 @@ public final class KeyboardLayoutSet {
return this;
}
public Builder setNumberRowEnabled(final boolean enabled) {
mParams.mNumberRowEnabled = enabled;
return this;
}
public Builder setLanguageSwitchKeyEnabled(final boolean enabled) {
mParams.mLanguageSwitchKeyEnabled = enabled;
return this;

View file

@ -115,6 +115,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
builder.setKeyboardGeometry(keyboardWidth, keyboardHeight);
builder.setSubtype(mRichImm.getCurrentSubtype());
builder.setVoiceInputKeyEnabled(settingsValues.mShowsVoiceInputKey);
builder.setNumberRowEnabled(settingsValues.mShowsNumberRow);
builder.setLanguageSwitchKeyEnabled(mLatinIME.shouldShowLanguageSwitchKey());
builder.setSplitLayoutEnabledByUser(ProductionFlags.IS_SPLIT_KEYBOARD_SUPPORTED
&& settingsValues.mIsSplitKeyboardEnabled);

View file

@ -662,6 +662,9 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
R.styleable.Keyboard_Case_clobberSettingsKey, id.mClobberSettingsKey);
final boolean hasShortcutKeyMatched = matchBoolean(caseAttr,
R.styleable.Keyboard_Case_hasShortcutKey, id.mHasShortcutKey);
final boolean numberRowEnabledMatched = matchBoolean(caseAttr,
R.styleable.Keyboard_Case_numberRowEnabled,
id.mNumberRowEnabled);
final boolean languageSwitchKeyEnabledMatched = matchBoolean(caseAttr,
R.styleable.Keyboard_Case_languageSwitchKeyEnabled,
id.mLanguageSwitchKeyEnabled);
@ -680,7 +683,7 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
final boolean selected = keyboardLayoutSetMatched && keyboardLayoutSetElementMatched
&& keyboardThemeMacthed && modeMatched && navigateNextMatched
&& navigatePreviousMatched && passwordInputMatched && clobberSettingsKeyMatched
&& hasShortcutKeyMatched && languageSwitchKeyEnabledMatched
&& hasShortcutKeyMatched && languageSwitchKeyEnabledMatched && numberRowEnabledMatched
&& isMultiLineMatched && imeActionMatched && isIconDefinedMatched
&& localeCodeMatched && languageCodeMatched && countryCodeMatched
&& splitLayoutMatched;
@ -707,6 +710,8 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
"passwordInput"),
booleanAttr(caseAttr, R.styleable.Keyboard_Case_hasShortcutKey,
"hasShortcutKey"),
booleanAttr(caseAttr, R.styleable.Keyboard_Case_numberRowEnabled,
"numberRowEnabled"),
booleanAttr(caseAttr, R.styleable.Keyboard_Case_languageSwitchKeyEnabled,
"languageSwitchKeyEnabled"),
booleanAttr(caseAttr, R.styleable.Keyboard_Case_isMultiLine,

View file

@ -102,6 +102,10 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static final String PREF_KEY_IS_INTERNAL = "pref_key_is_internal";
public static final String PREF_ENABLE_METRICS_LOGGING = "pref_enable_metrics_logging";
public static final String PREF_SHOW_NUMBER_ROW =
"pref_show_number_row";
// This preference key is deprecated. Use {@link #PREF_SHOW_LANGUAGE_SWITCH_KEY} instead.
// This is being used only for the backward compatibility.
private static final String PREF_SUPPRESS_LANGUAGE_SWITCH_KEY =
@ -335,6 +339,10 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
return (milliseconds != UNDEFINED_PREFERENCE_VALUE_INT) ? milliseconds : defaultValue;
}
public static boolean readShowsNumberRow(final SharedPreferences prefs) {
return prefs.getBoolean(PREF_SHOW_NUMBER_ROW, false);
}
public static float readKeyboardHeight(final SharedPreferences prefs,
final float defaultValue) {
final float percentage = prefs.getFloat(

View file

@ -69,6 +69,7 @@ public class SettingsValues {
public final boolean mKeyPreviewPopupOn;
public final boolean mShowsVoiceInputKey;
public final boolean mIncludesOtherImesInLanguageSwitchList;
public final boolean mShowsNumberRow;
public final boolean mShowsLanguageSwitchKey;
public final boolean mUseContactsDict;
public final boolean mUsePersonalizedDicts;
@ -144,6 +145,7 @@ public class SettingsValues {
DebugSettings.PREF_SLIDING_KEY_INPUT_PREVIEW, true);
mShowsVoiceInputKey = needsToShowVoiceInputKey(prefs, res) && mInputAttributes.mShouldShowVoiceInputKey;
mIncludesOtherImesInLanguageSwitchList = !Settings.ENABLE_SHOW_LANGUAGE_SWITCH_KEY_SETTINGS || prefs.getBoolean(Settings.PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST, false) /* forcibly */;
mShowsNumberRow = prefs.getBoolean(Settings.PREF_SHOW_NUMBER_ROW, false);
mShowsLanguageSwitchKey = prefs.getBoolean(Settings.PREF_SHOW_LANGUAGE_SWITCH_KEY, false);
mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true);
mUsePersonalizedDicts = prefs.getBoolean(Settings.PREF_KEY_USE_PERSONALIZED_DICTS, true);

View file

@ -501,6 +501,7 @@
<attr name="clobberSettingsKey" format="boolean" />
<attr name="hasShortcutKey" format="boolean" />
<attr name="languageSwitchKeyEnabled" format="boolean" />
<attr name="numberRowEnabled" format="boolean" />
<attr name="isMultiLine" format="boolean" />
<attr name="imeAction" format="enum">
<!-- This should be aligned with

View file

@ -223,6 +223,11 @@
<!-- Title of the item to change the keyboard theme [CHAR LIMIT=20]-->
<string name="keyboard_layout">Keyboard theme</string>
<!-- Title of the settings to enable number row -->
<string name="number_row">Number row</string>
<!-- Description of the settings to enable number row -->
<string name="number_row_summary">Always show number row</string>
<!-- Title of the settings to enable keyboard resizing -->
<string name="prefs_resize_keyboard">Enable keyboard resizing</string>
<!-- Title of the settings for setting keyboard height -->

View file

@ -22,6 +22,12 @@
android:summary="@string/auto_cap_summary"
android:defaultValue="true"
android:persistent="true" />
<CheckBoxPreference
android:key="pref_show_number_row"
android:title="@string/number_row"
android:summary="@string/number_row_summary"
android:defaultValue="false"
android:persistent="true" />
<CheckBoxPreference
android:key="pref_key_use_double_space_period"
android:title="@string/use_double_space_period"

View file

@ -23,6 +23,18 @@
>
<include
latin:keyboardLayout="@xml/key_styles_common" />
<switch>
<case
latin:numberRowEnabled="true"
>
<Row
latin:keyWidth="10%p"
>
<include
latin:keyboardLayout="@xml/rowkeys_symbols1" />
</Row>
</case>
</switch>
<Row
latin:keyWidth="10%p"
>

View file

@ -23,6 +23,18 @@
>
<include
latin:keyboardLayout="@xml/key_styles_common" />
<switch>
<case
latin:numberRowEnabled="true"
>
<Row
latin:keyWidth="10%p"
>
<include
latin:keyboardLayout="@xml/rowkeys_symbols1" />
</Row>
</case>
</switch>
<Row
latin:keyWidth="10%p"
>

View file

@ -23,6 +23,18 @@
>
<include
latin:keyboardLayout="@xml/key_styles_common" />
<switch>
<case
latin:numberRowEnabled="true"
>
<Row
latin:keyWidth="10%p"
>
<include
latin:keyboardLayout="@xml/rowkeys_symbols1" />
</Row>
</case>
</switch>
<Row
latin:keyWidth="10%p"
>

View file

@ -31,6 +31,18 @@
<include
latin:keyboardLayout="@xml/rowkeys_symbols1" />
</Row>
<switch>
<case
latin:numberRowEnabled="true"
>
<Row
latin:keyWidth="10%p"
>
<include
latin:keyboardLayout="@xml/rowkeys_symbols_shift1" />
</Row>
</case>
</switch>
<Row
latin:keyWidth="10%p"
>

View file

@ -25,6 +25,18 @@
latin:keyboardLayout="@xml/key_styles_common" />
<include
latin:keyboardLayout="@xml/key_styles_currency" />
<switch>
<case
latin:numberRowEnabled="true"
>
<Row
latin:keyWidth="10%p"
>
<include
latin:keyboardLayout="@xml/rowkeys_symbols1" />
</Row>
</case>
</switch>
<Row
latin:keyWidth="10%p"
>