Implement "forceAscii" private IME option
This change also introduces "AsciiCapable" extra value for subtype that indicates the subtype can input any ASCII code point from its keyboard layout. Only if the input field has "forceAscii" private IME option and the current subtype doesn't have "AsciiCapable" extra value, the en_US keyboard layout will be used for the input field. Bug: 3384942 Change-Id: I25e2553e37ecb5002df1164e45f6273845fe463bmain
parent
f77009ac3a
commit
af52c0ea04
|
@ -31,13 +31,13 @@
|
||||||
android:label="@string/subtype_en_US"
|
android:label="@string/subtype_en_US"
|
||||||
android:imeSubtypeLocale="en_US"
|
android:imeSubtypeLocale="en_US"
|
||||||
android:imeSubtypeMode="keyboard"
|
android:imeSubtypeMode="keyboard"
|
||||||
android:imeSubtypeExtraValue="TrySuppressingImeSwitcher"
|
android:imeSubtypeExtraValue="TrySuppressingImeSwitcher,AsciiCapable"
|
||||||
/>
|
/>
|
||||||
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
||||||
android:label="@string/subtype_en_GB"
|
android:label="@string/subtype_en_GB"
|
||||||
android:imeSubtypeLocale="en_GB"
|
android:imeSubtypeLocale="en_GB"
|
||||||
android:imeSubtypeMode="keyboard"
|
android:imeSubtypeMode="keyboard"
|
||||||
android:imeSubtypeExtraValue="TrySuppressingImeSwitcher"
|
android:imeSubtypeExtraValue="TrySuppressingImeSwitcher,AsciiCapable"
|
||||||
/>
|
/>
|
||||||
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
||||||
android:label="@string/subtype_generic"
|
android:label="@string/subtype_generic"
|
||||||
|
@ -48,61 +48,73 @@
|
||||||
android:label="@string/subtype_generic"
|
android:label="@string/subtype_generic"
|
||||||
android:imeSubtypeLocale="cs"
|
android:imeSubtypeLocale="cs"
|
||||||
android:imeSubtypeMode="keyboard"
|
android:imeSubtypeMode="keyboard"
|
||||||
|
android:imeSubtypeExtraValue="AsciiCapable"
|
||||||
/>
|
/>
|
||||||
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
||||||
android:label="@string/subtype_generic"
|
android:label="@string/subtype_generic"
|
||||||
android:imeSubtypeLocale="da"
|
android:imeSubtypeLocale="da"
|
||||||
android:imeSubtypeMode="keyboard"
|
android:imeSubtypeMode="keyboard"
|
||||||
|
android:imeSubtypeExtraValue="AsciiCapable"
|
||||||
/>
|
/>
|
||||||
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
||||||
android:label="@string/subtype_generic"
|
android:label="@string/subtype_generic"
|
||||||
android:imeSubtypeLocale="de"
|
android:imeSubtypeLocale="de"
|
||||||
android:imeSubtypeMode="keyboard"
|
android:imeSubtypeMode="keyboard"
|
||||||
|
android:imeSubtypeExtraValue="AsciiCapable"
|
||||||
/>
|
/>
|
||||||
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
||||||
android:label="@string/subtype_de_qwerty"
|
android:label="@string/subtype_de_qwerty"
|
||||||
android:imeSubtypeLocale="de_ZZ"
|
android:imeSubtypeLocale="de_ZZ"
|
||||||
android:imeSubtypeMode="keyboard"
|
android:imeSubtypeMode="keyboard"
|
||||||
|
android:imeSubtypeExtraValue="AsciiCapable"
|
||||||
/>
|
/>
|
||||||
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
||||||
android:label="@string/subtype_generic"
|
android:label="@string/subtype_generic"
|
||||||
android:imeSubtypeLocale="es"
|
android:imeSubtypeLocale="es"
|
||||||
android:imeSubtypeMode="keyboard"
|
android:imeSubtypeMode="keyboard"
|
||||||
|
android:imeSubtypeExtraValue="AsciiCapable"
|
||||||
/>
|
/>
|
||||||
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
||||||
android:label="@string/subtype_generic"
|
android:label="@string/subtype_generic"
|
||||||
android:imeSubtypeLocale="fi"
|
android:imeSubtypeLocale="fi"
|
||||||
android:imeSubtypeMode="keyboard"
|
android:imeSubtypeMode="keyboard"
|
||||||
|
android:imeSubtypeExtraValue="AsciiCapable"
|
||||||
/>
|
/>
|
||||||
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
||||||
android:label="@string/subtype_generic"
|
android:label="@string/subtype_generic"
|
||||||
android:imeSubtypeLocale="fr"
|
android:imeSubtypeLocale="fr"
|
||||||
android:imeSubtypeMode="keyboard"
|
android:imeSubtypeMode="keyboard"
|
||||||
|
android:imeSubtypeExtraValue="AsciiCapable"
|
||||||
/>
|
/>
|
||||||
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
||||||
android:label="@string/subtype_generic"
|
android:label="@string/subtype_generic"
|
||||||
android:imeSubtypeLocale="fr_CA"
|
android:imeSubtypeLocale="fr_CA"
|
||||||
android:imeSubtypeMode="keyboard"
|
android:imeSubtypeMode="keyboard"
|
||||||
|
android:imeSubtypeExtraValue="AsciiCapable"
|
||||||
/>
|
/>
|
||||||
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
||||||
android:label="@string/subtype_generic"
|
android:label="@string/subtype_generic"
|
||||||
android:imeSubtypeLocale="fr_CH"
|
android:imeSubtypeLocale="fr_CH"
|
||||||
android:imeSubtypeMode="keyboard"
|
android:imeSubtypeMode="keyboard"
|
||||||
|
android:imeSubtypeExtraValue="AsciiCapable"
|
||||||
/>
|
/>
|
||||||
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
||||||
android:label="@string/subtype_generic"
|
android:label="@string/subtype_generic"
|
||||||
android:imeSubtypeLocale="hr"
|
android:imeSubtypeLocale="hr"
|
||||||
android:imeSubtypeMode="keyboard"
|
android:imeSubtypeMode="keyboard"
|
||||||
|
android:imeSubtypeExtraValue="AsciiCapable"
|
||||||
/>
|
/>
|
||||||
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
||||||
android:label="@string/subtype_generic"
|
android:label="@string/subtype_generic"
|
||||||
android:imeSubtypeLocale="hu"
|
android:imeSubtypeLocale="hu"
|
||||||
android:imeSubtypeMode="keyboard"
|
android:imeSubtypeMode="keyboard"
|
||||||
|
android:imeSubtypeExtraValue="AsciiCapable"
|
||||||
/>
|
/>
|
||||||
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
||||||
android:label="@string/subtype_generic"
|
android:label="@string/subtype_generic"
|
||||||
android:imeSubtypeLocale="it"
|
android:imeSubtypeLocale="it"
|
||||||
android:imeSubtypeMode="keyboard"
|
android:imeSubtypeMode="keyboard"
|
||||||
|
android:imeSubtypeExtraValue="AsciiCapable"
|
||||||
/>
|
/>
|
||||||
<!-- Java uses the deprecated "iw" code instead of the standard "he" code for Hebrew. -->
|
<!-- Java uses the deprecated "iw" code instead of the standard "he" code for Hebrew. -->
|
||||||
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
||||||
|
@ -114,21 +126,25 @@
|
||||||
android:label="@string/subtype_generic"
|
android:label="@string/subtype_generic"
|
||||||
android:imeSubtypeLocale="nb"
|
android:imeSubtypeLocale="nb"
|
||||||
android:imeSubtypeMode="keyboard"
|
android:imeSubtypeMode="keyboard"
|
||||||
|
android:imeSubtypeExtraValue="AsciiCapable"
|
||||||
/>
|
/>
|
||||||
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
||||||
android:label="@string/subtype_generic"
|
android:label="@string/subtype_generic"
|
||||||
android:imeSubtypeLocale="nl"
|
android:imeSubtypeLocale="nl"
|
||||||
android:imeSubtypeMode="keyboard"
|
android:imeSubtypeMode="keyboard"
|
||||||
|
android:imeSubtypeExtraValue="AsciiCapable"
|
||||||
/>
|
/>
|
||||||
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
||||||
android:label="@string/subtype_generic"
|
android:label="@string/subtype_generic"
|
||||||
android:imeSubtypeLocale="pl"
|
android:imeSubtypeLocale="pl"
|
||||||
android:imeSubtypeMode="keyboard"
|
android:imeSubtypeMode="keyboard"
|
||||||
|
android:imeSubtypeExtraValue="AsciiCapable"
|
||||||
/>
|
/>
|
||||||
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
||||||
android:label="@string/subtype_generic"
|
android:label="@string/subtype_generic"
|
||||||
android:imeSubtypeLocale="pt"
|
android:imeSubtypeLocale="pt"
|
||||||
android:imeSubtypeMode="keyboard"
|
android:imeSubtypeMode="keyboard"
|
||||||
|
android:imeSubtypeExtraValue="AsciiCapable"
|
||||||
/>
|
/>
|
||||||
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
||||||
android:label="@string/subtype_generic"
|
android:label="@string/subtype_generic"
|
||||||
|
@ -144,10 +160,12 @@
|
||||||
android:label="@string/subtype_generic"
|
android:label="@string/subtype_generic"
|
||||||
android:imeSubtypeLocale="sv"
|
android:imeSubtypeLocale="sv"
|
||||||
android:imeSubtypeMode="keyboard"
|
android:imeSubtypeMode="keyboard"
|
||||||
|
android:imeSubtypeExtraValue="AsciiCapable"
|
||||||
/>
|
/>
|
||||||
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
<subtype android:icon="@drawable/ic_subtype_keyboard"
|
||||||
android:label="@string/subtype_generic"
|
android:label="@string/subtype_generic"
|
||||||
android:imeSubtypeLocale="tr"
|
android:imeSubtypeLocale="tr"
|
||||||
android:imeSubtypeMode="keyboard"
|
android:imeSubtypeMode="keyboard"
|
||||||
|
android:imeSubtypeExtraValue="AsciiCapable"
|
||||||
/>
|
/>
|
||||||
</input-method>
|
</input-method>
|
||||||
|
|
|
@ -258,8 +258,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
final SoftReference<LatinKeyboard> ref = mKeyboardCache.get(id);
|
final SoftReference<LatinKeyboard> ref = mKeyboardCache.get(id);
|
||||||
LatinKeyboard keyboard = (ref == null) ? null : ref.get();
|
LatinKeyboard keyboard = (ref == null) ? null : ref.get();
|
||||||
if (keyboard == null) {
|
if (keyboard == null) {
|
||||||
final Locale savedLocale = Utils.setSystemLocale(
|
final Locale savedLocale = Utils.setSystemLocale(mResources, id.mLocale);
|
||||||
mResources, mSubtypeSwitcher.getInputLocale());
|
|
||||||
try {
|
try {
|
||||||
keyboard = new LatinKeyboard.Builder(mThemeContext).load(id).build();
|
keyboard = new LatinKeyboard.Builder(mThemeContext).load(id).build();
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -319,13 +318,19 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
final boolean hasSettingsKey = settingsKeyEnabled && !noSettingsKey;
|
final boolean hasSettingsKey = settingsKeyEnabled && !noSettingsKey;
|
||||||
final int f2KeyMode = getF2KeyMode(settingsKeyEnabled, noSettingsKey);
|
final int f2KeyMode = getF2KeyMode(settingsKeyEnabled, noSettingsKey);
|
||||||
final boolean hasShortcutKey = voiceKeyEnabled && (isSymbols != voiceKeyOnMain);
|
final boolean hasShortcutKey = voiceKeyEnabled && (isSymbols != voiceKeyOnMain);
|
||||||
|
final boolean forceAscii = Utils.inPrivateImeOptions(
|
||||||
|
mPackageName, LatinIME.IME_OPTION_FORCE_ASCII, editorInfo);
|
||||||
|
final boolean asciiCapable = mSubtypeSwitcher.currentSubtypeContainsExtraValueKey(
|
||||||
|
LatinIME.SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE);
|
||||||
|
final Locale locale = (forceAscii && !asciiCapable)
|
||||||
|
? Locale.US : mSubtypeSwitcher.getInputLocale();
|
||||||
final Configuration conf = mResources.getConfiguration();
|
final Configuration conf = mResources.getConfiguration();
|
||||||
final DisplayMetrics dm = mResources.getDisplayMetrics();
|
final DisplayMetrics dm = mResources.getDisplayMetrics();
|
||||||
|
|
||||||
return new KeyboardId(
|
return new KeyboardId(
|
||||||
mResources.getResourceEntryName(xmlId), xmlId, mSubtypeSwitcher.getInputLocale(),
|
mResources.getResourceEntryName(xmlId), xmlId, locale, conf.orientation,
|
||||||
conf.orientation, dm.widthPixels, mode, editorInfo,
|
dm.widthPixels, mode, editorInfo, hasSettingsKey, f2KeyMode, noSettingsKey,
|
||||||
hasSettingsKey, f2KeyMode, noSettingsKey, voiceKeyEnabled, hasShortcutKey);
|
voiceKeyEnabled, hasShortcutKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getKeyboardMode() {
|
public int getKeyboardMode() {
|
||||||
|
|
|
@ -141,7 +141,7 @@ public class LatinKeyboard extends Keyboard {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSpacebarTextFadeFactor(float fadeFactor, LatinKeyboardView view) {
|
public void setSpacebarTextFadeFactor(float fadeFactor, KeyboardView view) {
|
||||||
mSpacebarTextFadeFactor = fadeFactor;
|
mSpacebarTextFadeFactor = fadeFactor;
|
||||||
updateSpacebarForLocale(false);
|
updateSpacebarForLocale(false);
|
||||||
if (view != null)
|
if (view != null)
|
||||||
|
@ -154,7 +154,7 @@ public class LatinKeyboard extends Keyboard {
|
||||||
return newColor;
|
return newColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateShortcutKey(boolean available, LatinKeyboardView view) {
|
public void updateShortcutKey(boolean available, KeyboardView view) {
|
||||||
if (mShortcutKey == null)
|
if (mShortcutKey == null)
|
||||||
return;
|
return;
|
||||||
mShortcutKey.setEnabled(available);
|
mShortcutKey.setEnabled(available);
|
||||||
|
@ -193,9 +193,8 @@ public class LatinKeyboard extends Keyboard {
|
||||||
&& Utils.hasMultipleEnabledIMEsOrSubtypes(imm, true /* include aux subtypes */);
|
&& Utils.hasMultipleEnabledIMEsOrSubtypes(imm, true /* include aux subtypes */);
|
||||||
mSpaceKey.setNeedsSpecialPopupHint(shouldShowInputMethodPicker);
|
mSpaceKey.setNeedsSpecialPopupHint(shouldShowInputMethodPicker);
|
||||||
// If application locales are explicitly selected.
|
// If application locales are explicitly selected.
|
||||||
if (mSubtypeSwitcher.needsToDisplayLanguage()) {
|
if (mSubtypeSwitcher.needsToDisplayLanguage(mId.mLocale)) {
|
||||||
mSpaceKey.setIcon(getSpaceDrawable(
|
mSpaceKey.setIcon(getSpaceDrawable(mId.mLocale, isAutoCorrection));
|
||||||
mSubtypeSwitcher.getInputLocale(), isAutoCorrection));
|
|
||||||
} else if (isAutoCorrection) {
|
} else if (isAutoCorrection) {
|
||||||
mSpaceKey.setIcon(getSpaceDrawable(null, true));
|
mSpaceKey.setIcon(getSpaceDrawable(null, true));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -106,6 +106,18 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
*/
|
*/
|
||||||
public static final String IME_OPTION_NO_SETTINGS_KEY = "noSettingsKey";
|
public static final String IME_OPTION_NO_SETTINGS_KEY = "noSettingsKey";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The private IME option used to indicate that the given text field needs
|
||||||
|
* ASCII code points input.
|
||||||
|
*/
|
||||||
|
public static final String IME_OPTION_FORCE_ASCII = "forceAscii";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The subtype extra value used to indicate that the subtype keyboard layout is capable for
|
||||||
|
* typing ASCII characters.
|
||||||
|
*/
|
||||||
|
public static final String SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE = "AsciiCapable";
|
||||||
|
|
||||||
private static final int EXTENDED_TOUCHABLE_REGION_HEIGHT = 100;
|
private static final int EXTENDED_TOUCHABLE_REGION_HEIGHT = 100;
|
||||||
|
|
||||||
// How many continuous deletes at which to start deleting at a higher speed.
|
// How many continuous deletes at which to start deleting at a higher speed.
|
||||||
|
|
|
@ -415,7 +415,10 @@ public class SubtypeSwitcher {
|
||||||
return mEnabledKeyboardSubtypesOfCurrentInputMethod.size();
|
return mEnabledKeyboardSubtypesOfCurrentInputMethod.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean needsToDisplayLanguage() {
|
public boolean needsToDisplayLanguage(Locale keyboardLocale) {
|
||||||
|
if (!keyboardLocale.equals(mInputLocale)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return mNeedsToDisplayLanguage;
|
return mNeedsToDisplayLanguage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue