Add emoji key to bottom row and option to disable it

This commit is contained in:
Aleksandras Kostarevas 2024-04-10 19:44:59 -05:00
parent e7ec9c3d78
commit 2531a74b71
18 changed files with 79 additions and 96 deletions

View File

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

View File

@ -30,10 +30,11 @@
te: Telugu -->
<case
latin:languageCode="fa|kn|ne|te"
latin:languageSwitchKeyEnabled="true"
latin:bottomEmojiKeyEnabled="true"
latin:mode="text|im"
>
<Key
latin:keyStyle="languageSwitchKeyStyle" />
latin:keyStyle="bottomEmojiKeyStyle" />
<Key
latin:keyStyle="spaceKeyStyle"
latin:keyWidth="7.0%p" />
@ -42,7 +43,7 @@
</case>
<case
latin:languageCode="fa|kn|ne|te"
latin:languageSwitchKeyEnabled="false"
latin:bottomEmojiKeyEnabled="false"
>
<Key
latin:keyStyle="spaceKeyStyle"
@ -51,15 +52,16 @@
latin:keyStyle="zwnjKeyStyle" />
</case>
<case
latin:languageSwitchKeyEnabled="true"
latin:bottomEmojiKeyEnabled="true"
latin:mode="text|im"
>
<Key
latin:keyStyle="languageSwitchKeyStyle" />
latin:keyStyle="bottomEmojiKeyStyle" />
<Key
latin:keyStyle="spaceKeyStyle"
latin:keyWidth="14.0%p" />
</case>
<!-- languageSwitchKeyEnabled="false" -->
<!-- bottomEmojiKeyEnabled="false" -->
<default>
<Key
latin:keyStyle="spaceKeyStyle"

View File

@ -24,10 +24,11 @@
<switch>
<case
latin:keyboardLayoutSet="bengali_akkhor|farsi|kannada|nepali_romanized|nepali_traditional|telugu"
latin:languageSwitchKeyEnabled="true"
latin:bottomEmojiKeyEnabled="true"
latin:mode="text|im"
>
<Key
latin:keyStyle="languageSwitchKeyStyle" />
latin:keyStyle="bottomEmojiKeyStyle" />
<Key
latin:keyStyle="spaceKeyStyle"
latin:keyWidth="8.0%p" />
@ -36,7 +37,7 @@
</case>
<case
latin:keyboardLayoutSet="bengali_akkhor|farsi|kannada|nepali_romanized|nepali_traditional|telugu"
latin:languageSwitchKeyEnabled="false"
latin:bottomEmojiKeyEnabled="false"
>
<Key
latin:keyStyle="spaceKeyStyle"
@ -45,15 +46,16 @@
latin:keyStyle="zwnjKeyStyle" />
</case>
<case
latin:languageSwitchKeyEnabled="true"
latin:bottomEmojiKeyEnabled="true"
latin:mode="text|im"
>
<Key
latin:keyStyle="languageSwitchKeyStyle" />
latin:keyStyle="bottomEmojiKeyStyle" />
<Key
latin:keyStyle="spaceKeyStyle"
latin:keyWidth="16.0%p" />
</case>
<!-- languageSwitchKeyEnabled="false" -->
<!-- bottomEmojiKeyEnabled="false" -->
<default>
<Key
latin:keyStyle="spaceKeyStyle"

View File

@ -24,10 +24,11 @@
<switch>
<case
latin:keyboardLayoutSet="bengali_akkhor|farsi|kannada|nepali_romanized|nepali_traditional|telugu"
latin:languageSwitchKeyEnabled="true"
latin:bottomEmojiKeyEnabled="true"
latin:mode="text|im"
>
<Key
latin:keyStyle="languageSwitchKeyStyle" />
latin:keyStyle="bottomEmojiKeyStyle" />
<Key
latin:keyStyle="spaceKeyStyle"
latin:keyWidth="45.0%p" />
@ -36,7 +37,7 @@
</case>
<case
latin:keyboardLayoutSet="bengali_akkhor|farsi|kannada|nepali_romanized|nepali_traditional|telugu"
latin:languageSwitchKeyEnabled="false"
latin:bottomEmojiKeyEnabled="false"
>
<Key
latin:keyStyle="spaceKeyStyle"
@ -45,15 +46,16 @@
latin:keyStyle="zwnjKeyStyle" />
</case>
<case
latin:languageSwitchKeyEnabled="true"
latin:bottomEmojiKeyEnabled="true"
latin:mode="text|im"
>
<Key
latin:keyStyle="languageSwitchKeyStyle" />
latin:keyStyle="bottomEmojiKeyStyle" />
<Key
latin:keyStyle="spaceKeyStyle"
latin:keyWidth="54.0%p" />
</case>
<!-- languageSwitchKeyEnabled="false" -->
<!-- bottomEmojiKeyEnabled="false" -->
<default>
<Key
latin:keyStyle="spaceKeyStyle"

View File

@ -99,10 +99,9 @@
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="functional" />
<key-style
latin:styleName="languageSwitchKeyStyle"
latin:keySpec="!icon/language_switch_key|!code/key_language_switch"
latin:keyActionFlags="noKeyPreview|altCodeWhileTyping|enableLongPress"
latin:altCode="!code/key_space" />
latin:styleName="bottomEmojiKeyStyle"
latin:keySpec="!icon/emoji_action_key|!code/key_emoji"
latin:keyActionFlags="noKeyPreview" />
<key-style
latin:styleName="emojiKeyStyle"
latin:keySpec="!icon/emoji_normal_key|!code/key_emoji"

View File

@ -29,10 +29,11 @@
latin:keyboardLayout="@xml/key_settings" />
<switch>
<case
latin:languageSwitchKeyEnabled="true"
latin:bottomEmojiKeyEnabled="true"
latin:mode="text|im"
>
<Key
latin:keyStyle="languageSwitchKeyStyle"
latin:keyStyle="bottomEmojiKeyStyle"
latin:keyXPos="22.0%p"
latin:keyWidth="9.0%p" />
<Key

View File

@ -24,10 +24,11 @@
<switch>
<case
latin:keyboardLayoutSet="bengali_akkhor|farsi|kannada|nepali_romanized|nepali_traditional|telugu"
latin:languageSwitchKeyEnabled="true"
latin:bottomEmojiKeyEnabled="true"
latin:mode="text|im"
>
<Key
latin:keyStyle="languageSwitchKeyStyle" />
latin:keyStyle="bottomEmojiKeyStyle" />
<Key
latin:keyStyle="spaceKeyStyle"
latin:keyWidth="30%p" />
@ -36,7 +37,7 @@
</case>
<case
latin:keyboardLayoutSet="bengali_akkhor|farsi|kannada|nepali_romanized|nepali_traditional|telugu"
latin:languageSwitchKeyEnabled="false"
latin:bottomEmojiKeyEnabled="false"
>
<Key
latin:keyStyle="spaceKeyStyle"
@ -45,15 +46,16 @@
latin:keyStyle="zwnjKeyStyle" />
</case>
<case
latin:languageSwitchKeyEnabled="true"
latin:bottomEmojiKeyEnabled="true"
latin:mode="text|im"
>
<Key
latin:keyStyle="languageSwitchKeyStyle" />
latin:keyStyle="bottomEmojiKeyStyle" />
<Key
latin:keyStyle="spaceKeyStyle"
latin:keyWidth="40%p" />
</case>
<!-- languageSwitchKeyEnabled="false" -->
<!-- bottomEmojiKeyEnabled="false" -->
<default>
<Key
latin:keyStyle="spaceKeyStyle"

View File

@ -125,10 +125,9 @@
latin:altCode="!code/key_space"
latin:backgroundType="functional" />
<key-style
latin:styleName="languageSwitchKeyStyle"
latin:keySpec="!icon/language_switch_key|!code/key_language_switch"
latin:keyActionFlags="noKeyPreview|altCodeWhileTyping|enableLongPress"
latin:altCode="!code/key_space" />
latin:styleName="bottomEmojiKeyStyle"
latin:keySpec="!icon/emoji_action_key|!code/key_emoji"
latin:keyActionFlags="noKeyPreview" />
<key-style
latin:styleName="tabKeyStyle"
latin:keySpec="!icon/tab_key|!code/key_tab"

View File

@ -35,17 +35,18 @@
</switch>
<switch>
<case
latin:languageSwitchKeyEnabled="true"
latin:bottomEmojiKeyEnabled="true"
latin:mode="text|im"
>
<Key
latin:keyStyle="languageSwitchKeyStyle"
latin:keyStyle="bottomEmojiKeyStyle"
latin:keyXPos="19.231%p"
latin:keyWidth="11.538%p" />
<Key
latin:keyStyle="spaceKeyStyle"
latin:keyWidth="42.308%p" />
</case>
<!-- languageSwitchKeyEnabled="false" -->
<!-- bottomEmojiKeyEnabled="false" -->
<default>
<Key
latin:keyStyle="spaceKeyStyle"

View File

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

View File

@ -118,7 +118,7 @@ public final class KeyboardLayoutSet {
boolean mIsPasswordField;
boolean mVoiceInputKeyEnabled;
boolean mNoSettingsKey;
boolean mLanguageSwitchKeyEnabled;
boolean mBottomEmojiKeyEnabled;
RichInputMethodSubtype mSubtype;
boolean mIsSpellChecker;
int mKeyboardWidth;
@ -322,8 +322,8 @@ public final class KeyboardLayoutSet {
return this;
}
public Builder setLanguageSwitchKeyEnabled(final boolean enabled) {
mParams.mLanguageSwitchKeyEnabled = enabled;
public Builder setBottomEmojiKeyEnabled(final boolean enabled) {
mParams.mBottomEmojiKeyEnabled = enabled;
return this;
}

View File

@ -125,7 +125,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
builder.setKeyboardGeometry(keyboardWidth, keyboardHeight);
builder.setSubtype(mRichImm.getCurrentSubtype());
builder.setVoiceInputKeyEnabled(settingsValues.mShowsVoiceInputKey);
builder.setLanguageSwitchKeyEnabled(mLatinIMELegacy.shouldShowLanguageSwitchKey());
builder.setBottomEmojiKeyEnabled(mLatinIMELegacy.shouldShowEmojiKey());
builder.setSplitLayoutEnabledByUser(ProductionFlags.IS_SPLIT_KEYBOARD_SUPPORTED
&& settingsValues.mIsSplitKeyboardEnabled);
mKeyboardLayoutSet = builder.build();

View File

@ -678,8 +678,8 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
final boolean hasShortcutKeyMatched = matchBoolean(caseAttr,
R.styleable.Keyboard_Case_hasShortcutKey, id.mHasShortcutKey);
final boolean languageSwitchKeyEnabledMatched = matchBoolean(caseAttr,
R.styleable.Keyboard_Case_languageSwitchKeyEnabled,
id.mLanguageSwitchKeyEnabled);
R.styleable.Keyboard_Case_bottomEmojiKeyEnabled,
id.mBottomEmojiKeyEnabled);
final boolean isMultiLineMatched = matchBoolean(caseAttr,
R.styleable.Keyboard_Case_isMultiLine, id.isMultiLine());
final boolean imeActionMatched = matchInteger(caseAttr,
@ -722,8 +722,8 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
"passwordInput"),
booleanAttr(caseAttr, R.styleable.Keyboard_Case_hasShortcutKey,
"hasShortcutKey"),
booleanAttr(caseAttr, R.styleable.Keyboard_Case_languageSwitchKeyEnabled,
"languageSwitchKeyEnabled"),
booleanAttr(caseAttr, R.styleable.Keyboard_Case_bottomEmojiKeyEnabled,
"bottomEmojiKeyEnabled"),
booleanAttr(caseAttr, R.styleable.Keyboard_Case_isMultiLine,
"isMultiLine"),
booleanAttr(caseAttr, R.styleable.Keyboard_Case_isSplitLayout,

View File

@ -2025,16 +2025,11 @@ public class LatinIMELegacy implements KeyboardActionListener,
return mRichImm.shouldOfferSwitchingToNextInputMethod(token, fallbackValue);
}
public boolean shouldShowLanguageSwitchKey() {
public boolean shouldShowEmojiKey() {
// TODO: Revisit here to reorganize the settings. Probably we can/should use different
// strategy once the implementation of
// {@link InputMethodManager#shouldOfferSwitchingToNextInputMethod} is defined well.
final boolean fallbackValue = mSettings.getCurrent().isLanguageSwitchKeyEnabled();
final IBinder token = mInputMethodService.getWindow().getWindow().getAttributes().token;
if (token == null) {
return fallbackValue;
}
return mRichImm.shouldOfferSwitchingToNextInputMethod(token, fallbackValue);
return mSettings.getCurrent().isEmojiKeyEnabled();
}
private void setNavigationBarVisibility(final boolean visible) {

View File

@ -76,8 +76,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
BuildCompatUtils.EFFECTIVE_SDK_INT <= Build.VERSION_CODES.KITKAT;
public static final boolean SHOULD_SHOW_LXX_SUGGESTION_UI =
BuildCompatUtils.EFFECTIVE_SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
public static final String PREF_SHOW_LANGUAGE_SWITCH_KEY =
"pref_show_language_switch_key";
public static final String PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST =
"pref_include_other_imes_in_language_switch_list";
public static final String PREF_CUSTOM_INPUT_STYLES = "custom_input_styles";
@ -101,11 +100,9 @@ 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";
// 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 =
"pref_suppress_language_switch_key";
public static final String PREF_SHOW_EMOJI_KEY =
"pref_show_emoji_key";
private static final String PREF_LAST_USED_PERSONALIZATION_TOKEN =
"pref_last_used_personalization_token";
private static final String PREF_LAST_PERSONALIZATION_DICT_WIPED_TIME =
@ -261,16 +258,8 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
R.integer.config_key_preview_linger_timeout))));
}
public static boolean readShowsLanguageSwitchKey(final SharedPreferences prefs) {
if (prefs.contains(PREF_SUPPRESS_LANGUAGE_SWITCH_KEY)) {
final boolean suppressLanguageSwitchKey = prefs.getBoolean(
PREF_SUPPRESS_LANGUAGE_SWITCH_KEY, true);
final SharedPreferences.Editor editor = prefs.edit();
editor.remove(PREF_SUPPRESS_LANGUAGE_SWITCH_KEY);
editor.putBoolean(PREF_SHOW_LANGUAGE_SWITCH_KEY, !suppressLanguageSwitchKey);
editor.apply();
}
return prefs.getBoolean(PREF_SHOW_LANGUAGE_SWITCH_KEY, false);
public static boolean readShowsEmojiKey(final SharedPreferences prefs) {
return prefs.getBoolean(PREF_SHOW_EMOJI_KEY, true);
}
public static String readPrefAdditionalSubtypes(final SharedPreferences prefs,

View File

@ -67,7 +67,7 @@ public class SettingsValues {
public final boolean mKeyPreviewPopupOn;
public final boolean mShowsVoiceInputKey;
public final boolean mIncludesOtherImesInLanguageSwitchList;
public final boolean mShowsLanguageSwitchKey;
public final boolean mShowsEmojiKey;
public final boolean mUseContactsDict;
public final boolean mUsePersonalizedDicts;
public final boolean mUseDoubleSpacePeriod;
@ -141,8 +141,7 @@ public class SettingsValues {
mIncludesOtherImesInLanguageSwitchList = Settings.ENABLE_SHOW_LANGUAGE_SWITCH_KEY_SETTINGS
? prefs.getBoolean(Settings.PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST, false)
: true /* forcibly */;
mShowsLanguageSwitchKey = Settings.ENABLE_SHOW_LANGUAGE_SWITCH_KEY_SETTINGS
? Settings.readShowsLanguageSwitchKey(prefs) : false /* forcibly */;
mShowsEmojiKey = Settings.readShowsEmojiKey(prefs);
mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true);
mUsePersonalizedDicts = prefs.getBoolean(Settings.PREF_KEY_USE_PERSONALIZED_DICTS, true);
mUseDoubleSpacePeriod = prefs.getBoolean(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true)
@ -269,15 +268,8 @@ public class SettingsValues {
return mInputAttributes.mShouldInsertSpacesAutomatically;
}
public boolean isLanguageSwitchKeyEnabled() {
if (!mShowsLanguageSwitchKey) {
return false;
}
final RichInputMethodManager imm = RichInputMethodManager.getInstance();
if (mIncludesOtherImesInLanguageSwitchList) {
return imm.hasMultipleEnabledIMEsOrSubtypes(false /* include aux subtypes */);
}
return imm.hasMultipleEnabledSubtypesInThisIme(false /* include aux subtypes */);
public boolean isEmojiKeyEnabled() {
return mShowsEmojiKey;
}
public boolean isSameInputType(final EditorInfo editorInfo) {
@ -390,8 +382,8 @@ public class SettingsValues {
sb.append("" + mShowsVoiceInputKey);
sb.append("\n mIncludesOtherImesInLanguageSwitchList = ");
sb.append("" + mIncludesOtherImesInLanguageSwitchList);
sb.append("\n mShowsLanguageSwitchKey = ");
sb.append("" + mShowsLanguageSwitchKey);
sb.append("\n mShowsEmojiKey = ");
sb.append("" + mShowsEmojiKey);
sb.append("\n mUseContactsDict = ");
sb.append("" + mUseContactsDict);
sb.append("\n mUsePersonalizedDicts = ");

View File

@ -56,6 +56,12 @@ fun TypingScreen(navController: NavHostController = rememberNavController()) {
subtitle = "Suggest emojis while you're typing",
setting = SHOW_EMOJI_SUGGESTIONS
)
SettingToggleSharedPrefs(
title = "Emoji key",
subtitle = "Show the emoji key on the bottom row",
key = Settings.PREF_SHOW_EMOJI_KEY,
default = true
)
SettingToggleSharedPrefs(
title = stringResource(R.string.auto_cap),
subtitle = stringResource(R.string.auto_cap_summary),
@ -84,13 +90,6 @@ fun TypingScreen(navController: NavHostController = rememberNavController()) {
default = booleanResource(R.bool.config_default_key_preview_popup)
)
SettingToggleSharedPrefs(
title = stringResource(R.string.show_language_switch_key),
subtitle = stringResource(R.string.show_language_switch_key_summary),
key = Settings.PREF_SHOW_LANGUAGE_SWITCH_KEY,
default = false
)
SettingRadio(title = "Vibration Duration", options = listOf(-1, 5, 10, 20, 40), optionNames = listOf("Default", "Low", "Medium", "High", "Higher"), setting = vibrationDurationSetting)
}
}

View File

@ -161,7 +161,7 @@ public abstract class KeyboardLayoutSetTestsBase extends AndroidTestCase {
builder.setKeyboardGeometry(keyboardWidth, keyboardHeight)
.setSubtype(RichInputMethodSubtype.getRichInputMethodSubtype(subtype))
.setVoiceInputKeyEnabled(voiceInputKeyEnabled)
.setLanguageSwitchKeyEnabled(languageSwitchKeyEnabled)
.setBottomEmojiKeyEnabled(languageSwitchKeyEnabled)
.setSplitLayoutEnabledByUser(splitLayoutEnabled);
return builder.build();
}