diff options
Diffstat (limited to 'java/src/com/android/inputmethod')
7 files changed, 66 insertions, 47 deletions
diff --git a/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java b/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java index e75559e62..7eb5acda8 100644 --- a/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java +++ b/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java @@ -21,7 +21,6 @@ import com.android.inputmethod.latin.DictionaryFactory; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.Settings; import com.android.inputmethod.latin.SharedPreferencesCompat; -import com.android.inputmethod.latin.SubtypeSwitcher; import com.android.inputmethod.latin.Utils; import org.xmlpull.v1.XmlPullParserException; @@ -237,12 +236,12 @@ public class InputLanguageSelection extends PreferenceActivity { if (finalSize == 0) { preprocess[finalSize++] = - new LocaleEntry(SubtypeSwitcher.getFullDisplayName(l, false), l); + new LocaleEntry(Utils.getFullDisplayName(l, false), l); } else { if (s.equals("zz_ZZ")) { // ignore this locale } else { - final String displayName = SubtypeSwitcher.getFullDisplayName(l, false); + final String displayName = Utils.getFullDisplayName(l, false); preprocess[finalSize++] = new LocaleEntry(displayName, l); } } diff --git a/java/src/com/android/inputmethod/deprecated/voice/RecognitionView.java b/java/src/com/android/inputmethod/deprecated/voice/RecognitionView.java index dcb826e8f..71d15dc3d 100644 --- a/java/src/com/android/inputmethod/deprecated/voice/RecognitionView.java +++ b/java/src/com/android/inputmethod/deprecated/voice/RecognitionView.java @@ -18,6 +18,7 @@ package com.android.inputmethod.deprecated.voice; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.SubtypeSwitcher; +import com.android.inputmethod.latin.Utils; import android.content.Context; import android.content.res.Resources; @@ -221,7 +222,7 @@ public class RecognitionView { Locale locale = SubtypeSwitcher.getInstance().getInputLocale(); mLanguage.setVisibility(View.VISIBLE); - mLanguage.setText(SubtypeSwitcher.getFullDisplayName(locale, true)); + mLanguage.setText(Utils.getFullDisplayName(locale, true)); mPopupLayout.setBackgroundDrawable(mListeningBorder); break; diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 8bf82807a..b1212f424 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -258,8 +258,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha final SoftReference<LatinKeyboard> ref = mKeyboardCache.get(id); LatinKeyboard keyboard = (ref == null) ? null : ref.get(); if (keyboard == null) { - final Locale savedLocale = Utils.setSystemLocale( - mResources, mSubtypeSwitcher.getInputLocale()); + final Locale savedLocale = Utils.setSystemLocale(mResources, id.mLocale); try { keyboard = new LatinKeyboard.Builder(mThemeContext).load(id).build(); } finally { @@ -319,13 +318,19 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha final boolean hasSettingsKey = settingsKeyEnabled && !noSettingsKey; final int f2KeyMode = getF2KeyMode(settingsKeyEnabled, noSettingsKey); 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 DisplayMetrics dm = mResources.getDisplayMetrics(); return new KeyboardId( - mResources.getResourceEntryName(xmlId), xmlId, mSubtypeSwitcher.getInputLocale(), - conf.orientation, dm.widthPixels, mode, editorInfo, - hasSettingsKey, f2KeyMode, noSettingsKey, voiceKeyEnabled, hasShortcutKey); + mResources.getResourceEntryName(xmlId), xmlId, locale, conf.orientation, + dm.widthPixels, mode, editorInfo, hasSettingsKey, f2KeyMode, noSettingsKey, + voiceKeyEnabled, hasShortcutKey); } public int getKeyboardMode() { diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java index 1b6f57b92..345272044 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java @@ -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; updateSpacebarForLocale(false); if (view != null) @@ -154,7 +154,7 @@ public class LatinKeyboard extends Keyboard { return newColor; } - public void updateShortcutKey(boolean available, LatinKeyboardView view) { + public void updateShortcutKey(boolean available, KeyboardView view) { if (mShortcutKey == null) return; mShortcutKey.setEnabled(available); @@ -193,9 +193,8 @@ public class LatinKeyboard extends Keyboard { && Utils.hasMultipleEnabledIMEsOrSubtypes(imm, true /* include aux subtypes */); mSpaceKey.setNeedsSpecialPopupHint(shouldShowInputMethodPicker); // If application locales are explicitly selected. - if (mSubtypeSwitcher.needsToDisplayLanguage()) { - mSpaceKey.setIcon(getSpaceDrawable( - mSubtypeSwitcher.getInputLocale(), isAutoCorrection)); + if (mSubtypeSwitcher.needsToDisplayLanguage(mId.mLocale)) { + mSpaceKey.setIcon(getSpaceDrawable(mId.mLocale, isAutoCorrection)); } else if (isAutoCorrection) { mSpaceKey.setIcon(getSpaceDrawable(null, true)); } else { @@ -216,7 +215,7 @@ public class LatinKeyboard extends Keyboard { final Rect bounds = new Rect(); // Estimate appropriate language name text size to fit in maxTextWidth. - String language = SubtypeSwitcher.getFullDisplayName(locale, true); + String language = Utils.getFullDisplayName(locale, true); int textWidth = getTextWidth(paint, language, origTextSize, bounds); // Assuming text width and text size are proportional to each other. float textSize = origTextSize * Math.min(width / textWidth, 1.0f); @@ -228,7 +227,7 @@ public class LatinKeyboard extends Keyboard { final boolean useShortName; if (useMiddleName) { - language = SubtypeSwitcher.getMiddleDisplayLanguage(locale); + language = Utils.getMiddleDisplayLanguage(locale); textWidth = getTextWidth(paint, language, origTextSize, bounds); textSize = origTextSize * Math.min(width / textWidth, 1.0f); useShortName = (textSize / origTextSize < MINIMUM_SCALE_OF_LANGUAGE_NAME) @@ -238,7 +237,7 @@ public class LatinKeyboard extends Keyboard { } if (useShortName) { - language = SubtypeSwitcher.getShortDisplayLanguage(locale); + language = Utils.getShortDisplayLanguage(locale); textWidth = getTextWidth(paint, language, origTextSize, bounds); textSize = origTextSize * Math.min(width / textWidth, 1.0f); } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 394414d03..552517bc8 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -106,6 +106,18 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar */ 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; // How many continuous deletes at which to start deleting at a higher speed. diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index 0a391a77e..d969e39eb 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -415,7 +415,10 @@ public class SubtypeSwitcher { return mEnabledKeyboardSubtypesOfCurrentInputMethod.size(); } - public boolean needsToDisplayLanguage() { + public boolean needsToDisplayLanguage(Locale keyboardLocale) { + if (!keyboardLocale.equals(mInputLocale)) { + return false; + } return mNeedsToDisplayLanguage; } @@ -492,36 +495,8 @@ public class SubtypeSwitcher { KeyboardSwitcher.getInstance().getKeyboardView().getWindowToken()); } - public static String getFullDisplayName(Locale locale, boolean returnsNameInThisLocale) { - if (returnsNameInThisLocale) { - return toTitleCase(SubtypeLocale.getFullDisplayName(locale), locale); - } else { - return toTitleCase(locale.getDisplayName(), locale); - } - } - - public static String getDisplayLanguage(Locale locale) { - return toTitleCase(SubtypeLocale.getFullDisplayName(locale), locale); - } - - public static String getMiddleDisplayLanguage(Locale locale) { - return toTitleCase((Utils.constructLocaleFromString( - locale.getLanguage()).getDisplayLanguage(locale)), locale); - } - - public static String getShortDisplayLanguage(Locale locale) { - return toTitleCase(locale.getLanguage(), locale); - } - - private static String toTitleCase(String s, Locale locale) { - if (s.length() == 0) { - return s; - } - return s.toUpperCase(locale).charAt(0) + s.substring(1); - } - public String getInputLanguageName() { - return getDisplayLanguage(getInputLocale()); + return Utils.getDisplayLanguage(getInputLocale()); } ///////////////////////////// diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java index 36fbfd951..ff051dcbb 100644 --- a/java/src/com/android/inputmethod/latin/Utils.java +++ b/java/src/com/android/inputmethod/latin/Utils.java @@ -769,4 +769,32 @@ public class Utils { StringBuilderPool.recycle((StringBuilder)garbage); } } + + public static String getFullDisplayName(Locale locale, boolean returnsNameInThisLocale) { + if (returnsNameInThisLocale) { + return toTitleCase(SubtypeLocale.getFullDisplayName(locale), locale); + } else { + return toTitleCase(locale.getDisplayName(), locale); + } + } + + public static String getDisplayLanguage(Locale locale) { + return toTitleCase(SubtypeLocale.getFullDisplayName(locale), locale); + } + + public static String getMiddleDisplayLanguage(Locale locale) { + return toTitleCase((constructLocaleFromString( + locale.getLanguage()).getDisplayLanguage(locale)), locale); + } + + public static String getShortDisplayLanguage(Locale locale) { + return toTitleCase(locale.getLanguage(), locale); + } + + private static String toTitleCase(String s, Locale locale) { + if (s.length() <= 1) { + return s; + } + return s.toUpperCase(locale).charAt(0) + s.substring(1); + } } |