Made keyboard layout aware of one-handed mode (e.g. hides one-handed key when one-handed mode is enabled)

This commit is contained in:
pdroidandroid@gmail.com 2022-02-21 13:19:47 +01:00
parent d27659de4f
commit 1b1dc96a3d
10 changed files with 81 additions and 22 deletions

View file

@ -85,6 +85,7 @@ public final class KeyboardId {
public final String mCustomActionLabel; public final String mCustomActionLabel;
public final boolean mHasShortcutKey; public final boolean mHasShortcutKey;
public final boolean mIsSplitLayout; public final boolean mIsSplitLayout;
public final boolean mOneHandedModeEnabled;
private final int mHashCode; private final int mHashCode;
@ -103,6 +104,7 @@ public final class KeyboardId {
? mEditorInfo.actionLabel.toString() : null; ? mEditorInfo.actionLabel.toString() : null;
mHasShortcutKey = params.mVoiceInputKeyEnabled; mHasShortcutKey = params.mVoiceInputKeyEnabled;
mIsSplitLayout = params.mIsSplitLayoutEnabled; mIsSplitLayout = params.mIsSplitLayoutEnabled;
mOneHandedModeEnabled = params.mOneHandedModeEnabled;
mHashCode = computeHashCode(this); mHashCode = computeHashCode(this);
} }

View file

@ -122,6 +122,7 @@ public final class KeyboardLayoutSet {
boolean mNumberRowEnabled; boolean mNumberRowEnabled;
boolean mLanguageSwitchKeyEnabled; boolean mLanguageSwitchKeyEnabled;
boolean mEmojiKeyEnabled; boolean mEmojiKeyEnabled;
boolean mOneHandedModeEnabled;
RichInputMethodSubtype mSubtype; RichInputMethodSubtype mSubtype;
boolean mIsSpellChecker; boolean mIsSpellChecker;
int mKeyboardWidth; int mKeyboardWidth;
@ -351,6 +352,11 @@ public final class KeyboardLayoutSet {
return this; return this;
} }
public Builder setOneHandedModeEnabled(boolean enabled) {
mParams.mOneHandedModeEnabled = enabled;
return this;
}
// Super redux version of reading the script ID for some subtype from Xml. // Super redux version of reading the script ID for some subtype from Xml.
static int readScriptId(final Resources resources, final InputMethodSubtype subtype) { static int readScriptId(final Resources resources, final InputMethodSubtype subtype) {
final String layoutSetName = KEYBOARD_LAYOUT_SET_RESOURCE_PREFIX final String layoutSetName = KEYBOARD_LAYOUT_SET_RESOURCE_PREFIX

View file

@ -129,10 +129,12 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
builder.setEmojiKeyEnabled(settingsValues.mShowsEmojiKey); builder.setEmojiKeyEnabled(settingsValues.mShowsEmojiKey);
builder.setSplitLayoutEnabledByUser(ProductionFlags.IS_SPLIT_KEYBOARD_SUPPORTED builder.setSplitLayoutEnabledByUser(ProductionFlags.IS_SPLIT_KEYBOARD_SUPPORTED
&& settingsValues.mIsSplitKeyboardEnabled); && settingsValues.mIsSplitKeyboardEnabled);
final boolean oneHandedModeEnabled = settingsValues.mOneHandedModeEnabled;
builder.setOneHandedModeEnabled(oneHandedModeEnabled);
mKeyboardLayoutSet = builder.build(); mKeyboardLayoutSet = builder.build();
try { try {
mState.onLoadKeyboard(currentAutoCapsState, currentRecapitalizeState, mState.onLoadKeyboard(currentAutoCapsState, currentRecapitalizeState,
settingsValues.mOneHandedModeEnabled); oneHandedModeEnabled);
mKeyboardTextsSet.setLocale(mRichImm.getCurrentSubtypeLocale(), mThemeContext); mKeyboardTextsSet.setLocale(mRichImm.getCurrentSubtypeLocale(), mThemeContext);
} catch (KeyboardLayoutSetException e) { } catch (KeyboardLayoutSetException e) {
Log.w(TAG, "loading keyboard failed: " + e.mKeyboardId, e.getCause()); Log.w(TAG, "loading keyboard failed: " + e.mKeyboardId, e.getCause());

View file

@ -700,13 +700,16 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
final boolean countryCodeMatched = matchCountryCodes(caseAttr, locale); final boolean countryCodeMatched = matchCountryCodes(caseAttr, locale);
final boolean splitLayoutMatched = matchBoolean(caseAttr, final boolean splitLayoutMatched = matchBoolean(caseAttr,
R.styleable.Keyboard_Case_isSplitLayout, id.mIsSplitLayout); R.styleable.Keyboard_Case_isSplitLayout, id.mIsSplitLayout);
final boolean oneHandedModeEnabledMatched = matchBoolean(caseAttr,
R.styleable.Keyboard_Case_oneHandedModeEnabled,
id.mOneHandedModeEnabled);
final boolean selected = keyboardLayoutSetMatched && keyboardLayoutSetElementMatched final boolean selected = keyboardLayoutSetMatched && keyboardLayoutSetElementMatched
&& keyboardThemeMacthed && modeMatched && navigateNextMatched && keyboardThemeMacthed && modeMatched && navigateNextMatched
&& navigatePreviousMatched && passwordInputMatched && clobberSettingsKeyMatched && navigatePreviousMatched && passwordInputMatched && clobberSettingsKeyMatched
&& hasShortcutKeyMatched && numberRowEnabledMatched && languageSwitchKeyEnabledMatched && hasShortcutKeyMatched && numberRowEnabledMatched && languageSwitchKeyEnabledMatched
&& emojiKeyEnabledMatched && isMultiLineMatched && imeActionMatched && isIconDefinedMatched && emojiKeyEnabledMatched && isMultiLineMatched && imeActionMatched && isIconDefinedMatched
&& localeCodeMatched && languageCodeMatched && countryCodeMatched && localeCodeMatched && languageCodeMatched && countryCodeMatched
&& splitLayoutMatched; && splitLayoutMatched && oneHandedModeEnabledMatched;
if (DEBUG) { if (DEBUG) {
startTag("<%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s>%s", TAG_CASE, startTag("<%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s>%s", TAG_CASE,
@ -748,6 +751,8 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
"languageCode"), "languageCode"),
textAttr(caseAttr.getString(R.styleable.Keyboard_Case_countryCode), textAttr(caseAttr.getString(R.styleable.Keyboard_Case_countryCode),
"countryCode"), "countryCode"),
booleanAttr(caseAttr, R.styleable.Keyboard_Case_oneHandedModeEnabled,
"oneHandedModeEnabled"),
selected ? "" : " skipped"); selected ? "" : " skipped");
} }

View file

@ -261,6 +261,7 @@ public final class KeyboardTextsTable {
/* 177: 0 */ "keyspec_clipboard_action_key", /* 177: 0 */ "keyspec_clipboard_action_key",
/* 178: 0 */ "keyspec_clipboard_normal_key", /* 178: 0 */ "keyspec_clipboard_normal_key",
/* 179: 0 */ "keyspec_start_onehanded_mode", /* 179: 0 */ "keyspec_start_onehanded_mode",
/* 180: 0 */ "keyspec_language_switch",
}; };
private static final String EMPTY = ""; private static final String EMPTY = "";
@ -489,6 +490,7 @@ public final class KeyboardTextsTable {
/* keyspec_clipboard_action_key */ "!icon/clipboard_action_key|!code/key_clipboard", /* keyspec_clipboard_action_key */ "!icon/clipboard_action_key|!code/key_clipboard",
/* keyspec_clipboard_normal_key */ "!icon/clipboard_normal_key|!code/key_clipboard", /* keyspec_clipboard_normal_key */ "!icon/clipboard_normal_key|!code/key_clipboard",
/* keyspec_start_onehanded_mode */ "!icon/start_onehanded_mode_key|!code/key_start_onehanded", /* keyspec_start_onehanded_mode */ "!icon/start_onehanded_mode_key|!code/key_start_onehanded",
/* keyspec_language_switch */ "!icon/language_switch_key|!code/key_language_switch",
}; };
/* Locale af: Afrikaans */ /* Locale af: Afrikaans */
@ -4251,7 +4253,7 @@ public final class KeyboardTextsTable {
private static final Object[] LOCALES_AND_TEXTS = { private static final Object[] LOCALES_AND_TEXTS = {
// "locale", TEXT_ARRAY, /* numberOfNonNullText/lengthOf_TEXT_ARRAY localeName */ // "locale", TEXT_ARRAY, /* numberOfNonNullText/lengthOf_TEXT_ARRAY localeName */
"DEFAULT", TEXTS_DEFAULT, /* 180/180 DEFAULT */ "DEFAULT", TEXTS_DEFAULT, /* 181/181 DEFAULT */
"af" , TEXTS_af, /* 7/ 13 Afrikaans */ "af" , TEXTS_af, /* 7/ 13 Afrikaans */
"ar" , TEXTS_ar, /* 55/110 Arabic */ "ar" , TEXTS_ar, /* 55/110 Arabic */
"az" , TEXTS_az, /* 11/ 18 Azerbaijani */ "az" , TEXTS_az, /* 11/ 18 Azerbaijani */

View file

@ -515,6 +515,7 @@
<attr name="hasShortcutKey" format="boolean" /> <attr name="hasShortcutKey" format="boolean" />
<attr name="languageSwitchKeyEnabled" format="boolean" /> <attr name="languageSwitchKeyEnabled" format="boolean" />
<attr name="emojiKeyEnabled" format="boolean" /> <attr name="emojiKeyEnabled" format="boolean" />
<attr name="oneHandedModeEnabled" format="boolean" />
<attr name="numberRowEnabled" format="boolean" /> <attr name="numberRowEnabled" format="boolean" />
<attr name="isMultiLine" format="boolean" /> <attr name="isMultiLine" format="boolean" />
<attr name="imeAction" format="enum"> <attr name="imeAction" format="enum">

View file

@ -100,7 +100,7 @@
latin:backgroundType="functional" /> latin:backgroundType="functional" />
<key-style <key-style
latin:styleName="languageSwitchKeyStyle" latin:styleName="languageSwitchKeyStyle"
latin:keySpec="!icon/language_switch_key|!code/key_language_switch" latin:keySpec="!text/keyspec_language_switch"
latin:keyActionFlags="noKeyPreview|altCodeWhileTyping|enableLongPress" latin:keyActionFlags="noKeyPreview|altCodeWhileTyping|enableLongPress"
latin:altCode="!code/key_space" latin:altCode="!code/key_space"
latin:backgroundType="functional" /> latin:backgroundType="functional" />

View file

@ -126,7 +126,7 @@
latin:backgroundType="functional" /> latin:backgroundType="functional" />
<key-style <key-style
latin:styleName="languageSwitchKeyStyle" latin:styleName="languageSwitchKeyStyle"
latin:keySpec="!icon/language_switch_key|!code/key_language_switch" latin:keySpec="!text/keyspec_language_switch"
latin:keyActionFlags="noKeyPreview|altCodeWhileTyping|enableLongPress" latin:keyActionFlags="noKeyPreview|altCodeWhileTyping|enableLongPress"
latin:altCode="!code/key_space" latin:altCode="!code/key_space"
latin:backgroundType="functional" /> latin:backgroundType="functional" />

View file

@ -20,52 +20,92 @@
<merge <merge
xmlns:latin="http://schemas.android.com/apk/res-auto" xmlns:latin="http://schemas.android.com/apk/res-auto"
> >
<!-- Key style for the key which may have settings key as more keys. --> <!-- Key style for the key which may have settings key as more keys. -->
<switch> <switch>
<case <case
latin:clobberSettingsKey="true" latin:clobberSettingsKey="true"
> >
<key-style <key-style
latin:styleName="settingsMoreKeysStyle" latin:styleName="settingsMoreKeysStyle"
latin:backgroundType="functional" /> latin:backgroundType="functional"/>
</case> </case>
<case <case
latin:emojiKeyEnabled="true" latin:oneHandedModeEnabled="true"
latin:languageSwitchKeyEnabled="true" latin:languageSwitchKeyEnabled="true"
> latin:emojiKeyEnabled="true">
<key-style <key-style
latin:styleName="settingsMoreKeysStyle" latin:styleName="settingsMoreKeysStyle"
latin:keyLabelFlags="hasPopupHint" latin:keyLabelFlags="hasPopupHint"
latin:additionalMoreKeys="!text/keyspec_settings,!text/keyspec_clipboard_normal_key,!text/keyspec_start_onehanded_mode" latin:backgroundType="functional"
latin:backgroundType="functional" /> latin:additionalMoreKeys="!text/keyspec_settings,!text/keyspec_clipboard_normal_key"/>
</case> </case>
<case <case
latin:emojiKeyEnabled="false" latin:oneHandedModeEnabled="true"
latin:languageSwitchKeyEnabled="true" latin:languageSwitchKeyEnabled="true"
> latin:emojiKeyEnabled="false">
<key-style <key-style
latin:styleName="settingsMoreKeysStyle" latin:styleName="settingsMoreKeysStyle"
latin:keyLabelFlags="hasPopupHint" latin:keyLabelFlags="hasPopupHint"
latin:additionalMoreKeys="!text/keyspec_settings,!text/keyspec_clipboard_normal_key,!text/keyspec_emoji_normal_key,!text/keyspec_start_onehanded_mode" latin:backgroundType="functional"
latin:backgroundType="functional" /> latin:additionalMoreKeys="!text/keyspec_settings,!text/keyspec_clipboard_normal_key,!text/keyspec_emoji_normal_key"/>
</case> </case>
<case <case
latin:emojiKeyEnabled="true" latin:oneHandedModeEnabled="true"
latin:languageSwitchKeyEnabled="false" latin:languageSwitchKeyEnabled="false"
> latin:emojiKeyEnabled="true">
<key-style <key-style
latin:styleName="settingsMoreKeysStyle" latin:styleName="settingsMoreKeysStyle"
latin:keyLabelFlags="hasPopupHint" latin:keyLabelFlags="hasPopupHint"
latin:additionalMoreKeys="!text/keyspec_settings,!icon/language_switch_key|!code/key_language_switch,!text/keyspec_clipboard_normal_key,!text/keyspec_start_onehanded_mode" latin:backgroundType="functional"
latin:backgroundType="functional" /> latin:additionalMoreKeys="!text/keyspec_settings,!text/keyspec_clipboard_normal_key,!text/keyspec_language_switch"/>
</case>
<case
latin:oneHandedModeEnabled="true"
latin:languageSwitchKeyEnabled="false"
latin:emojiKeyEnabled="false">
<key-style
latin:styleName="settingsMoreKeysStyle"
latin:keyLabelFlags="hasPopupHint"
latin:backgroundType="functional"
latin:additionalMoreKeys="!text/keyspec_settings,!text/keyspec_clipboard_normal_key,!text/keyspec_language_switch,!text/keyspec_emoji_normal_key"/>
</case>
<case
latin:oneHandedModeEnabled="false"
latin:languageSwitchKeyEnabled="true"
latin:emojiKeyEnabled="true">
<key-style
latin:styleName="settingsMoreKeysStyle"
latin:keyLabelFlags="hasPopupHint"
latin:backgroundType="functional"
latin:additionalMoreKeys="!text/keyspec_settings,!text/keyspec_clipboard_normal_key,!text/keyspec_start_onehanded_mode"/>
</case>
<case
latin:oneHandedModeEnabled="false"
latin:languageSwitchKeyEnabled="true"
latin:emojiKeyEnabled="false">
<key-style
latin:styleName="settingsMoreKeysStyle"
latin:keyLabelFlags="hasPopupHint"
latin:backgroundType="functional"
latin:additionalMoreKeys="!text/keyspec_settings,!text/keyspec_clipboard_normal_key,!text/keyspec_start_onehanded_mode,!text/keyspec_emoji_normal_key"/>
</case>
<case
latin:oneHandedModeEnabled="false"
latin:languageSwitchKeyEnabled="false"
latin:emojiKeyEnabled="true">
<key-style
latin:styleName="settingsMoreKeysStyle"
latin:keyLabelFlags="hasPopupHint"
latin:backgroundType="functional"
latin:additionalMoreKeys="!text/keyspec_settings,!text/keyspec_clipboard_normal_key,!text/keyspec_start_onehanded_mode,!text/keyspec_language_switch"/>
</case> </case>
<default> <default>
<key-style <key-style
latin:styleName="settingsMoreKeysStyle" latin:styleName="settingsMoreKeysStyle"
latin:keyLabelFlags="hasPopupHint" latin:keyLabelFlags="hasPopupHint"
latin:additionalMoreKeys="!text/keyspec_settings,!icon/language_switch_key|!code/key_language_switch,!text/keyspec_clipboard_normal_key,!text/keyspec_emoji_normal_key,!text/keyspec_start_onehanded_mode" latin:backgroundType="functional"
latin:backgroundType="functional" /> latin:additionalMoreKeys="!text/keyspec_settings,!text/keyspec_clipboard_normal_key,!text/keyspec_start_onehanded_mode,!text/keyspec_language_switch,!text/keyspec_emoji_normal_key"/>
</default> </default>
</switch> </switch>
</merge> </merge>

View file

@ -263,6 +263,7 @@
<string name="keyspec_clipboard_action_key">!icon/clipboard_action_key|!code/key_clipboard</string> <string name="keyspec_clipboard_action_key">!icon/clipboard_action_key|!code/key_clipboard</string>
<string name="keyspec_clipboard_normal_key">!icon/clipboard_normal_key|!code/key_clipboard</string> <string name="keyspec_clipboard_normal_key">!icon/clipboard_normal_key|!code/key_clipboard</string>
<string name="keyspec_start_onehanded_mode">!icon/start_onehanded_mode_key|!code/key_start_onehanded</string> <string name="keyspec_start_onehanded_mode">!icon/start_onehanded_mode_key|!code/key_start_onehanded</string>
<string name="keyspec_language_switch">!icon/language_switch_key|!code/key_language_switch</string>
<string name="label_go_key">!string/label_go_key</string> <string name="label_go_key">!string/label_go_key</string>
<string name="label_send_key">!string/label_send_key</string> <string name="label_send_key">!string/label_send_key</string>
<string name="label_next_key">!string/label_next_key</string> <string name="label_next_key">!string/label_next_key</string>