Add a functionarity to handle Subtype
Change-Id: Ic6055ba218b64f4276e3db99a435f546c3990ee5main
parent
279da1da91
commit
4ab730dbd3
|
@ -37,7 +37,7 @@ public class InputLanguageSelection extends PreferenceActivity {
|
||||||
private String mSelectedLanguages;
|
private String mSelectedLanguages;
|
||||||
private ArrayList<Loc> mAvailableLanguages = new ArrayList<Loc>();
|
private ArrayList<Loc> mAvailableLanguages = new ArrayList<Loc>();
|
||||||
private static final String[] BLACKLIST_LANGUAGES = {
|
private static final String[] BLACKLIST_LANGUAGES = {
|
||||||
"ko", "ja", "zh", "el"
|
"ko", "ja", "zh", "el", "zz"
|
||||||
};
|
};
|
||||||
|
|
||||||
private static class Loc implements Comparable<Object> {
|
private static class Loc implements Comparable<Object> {
|
||||||
|
@ -74,7 +74,7 @@ public class InputLanguageSelection extends PreferenceActivity {
|
||||||
for (int i = 0; i < mAvailableLanguages.size(); i++) {
|
for (int i = 0; i < mAvailableLanguages.size(); i++) {
|
||||||
CheckBoxPreference pref = new CheckBoxPreference(this);
|
CheckBoxPreference pref = new CheckBoxPreference(this);
|
||||||
Locale locale = mAvailableLanguages.get(i).locale;
|
Locale locale = mAvailableLanguages.get(i).locale;
|
||||||
pref.setTitle(SubtypeSwitcher.getLanguageName(locale));
|
pref.setTitle(SubtypeSwitcher.getFullDisplayName(locale, true));
|
||||||
boolean checked = isLocaleIn(locale, languageList);
|
boolean checked = isLocaleIn(locale, languageList);
|
||||||
pref.setChecked(checked);
|
pref.setChecked(checked);
|
||||||
if (hasDictionary(locale)) {
|
if (hasDictionary(locale)) {
|
||||||
|
@ -167,7 +167,7 @@ public class InputLanguageSelection extends PreferenceActivity {
|
||||||
|
|
||||||
if (finalSize == 0) {
|
if (finalSize == 0) {
|
||||||
preprocess[finalSize++] =
|
preprocess[finalSize++] =
|
||||||
new Loc(SubtypeSwitcher.getLanguageName(l), l);
|
new Loc(SubtypeSwitcher.getFullDisplayName(l, true), l);
|
||||||
} else {
|
} else {
|
||||||
// check previous entry:
|
// check previous entry:
|
||||||
// same lang and a country -> upgrade to full name and
|
// same lang and a country -> upgrade to full name and
|
||||||
|
@ -175,15 +175,15 @@ public class InputLanguageSelection extends PreferenceActivity {
|
||||||
// diff lang -> insert ours with lang-only name
|
// diff lang -> insert ours with lang-only name
|
||||||
if (preprocess[finalSize-1].locale.getLanguage().equals(
|
if (preprocess[finalSize-1].locale.getLanguage().equals(
|
||||||
language)) {
|
language)) {
|
||||||
preprocess[finalSize-1].label = SubtypeSwitcher.getLanguageName(
|
preprocess[finalSize-1].label = SubtypeSwitcher.getFullDisplayName(
|
||||||
preprocess[finalSize-1].locale);
|
preprocess[finalSize-1].locale, false);
|
||||||
preprocess[finalSize++] =
|
preprocess[finalSize++] =
|
||||||
new Loc(SubtypeSwitcher.getLanguageName(l), l);
|
new Loc(SubtypeSwitcher.getFullDisplayName(l, false), l);
|
||||||
} else {
|
} else {
|
||||||
String displayName;
|
String displayName;
|
||||||
if (s.equals("zz_ZZ")) {
|
if (s.equals("zz_ZZ")) {
|
||||||
} else {
|
} else {
|
||||||
displayName = SubtypeSwitcher.getLanguageName(l);
|
displayName = SubtypeSwitcher.getFullDisplayName(l, true);
|
||||||
preprocess[finalSize++] = new Loc(displayName, l);
|
preprocess[finalSize++] = new Loc(displayName, l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -462,7 +462,7 @@ public class LatinIME extends InputMethodService
|
||||||
|
|
||||||
private void initSuggest() {
|
private void initSuggest() {
|
||||||
updateAutoTextEnabled();
|
updateAutoTextEnabled();
|
||||||
String locale = mSubtypeSwitcher.getInputLanguage();
|
String locale = mSubtypeSwitcher.getInputLocaleStr();
|
||||||
|
|
||||||
Resources orig = getResources();
|
Resources orig = getResources();
|
||||||
Locale savedLocale = mSubtypeSwitcher.changeSystemLocale(new Locale(locale));
|
Locale savedLocale = mSubtypeSwitcher.changeSystemLocale(new Locale(locale));
|
||||||
|
@ -519,6 +519,7 @@ public class LatinIME extends InputMethodService
|
||||||
@Override
|
@Override
|
||||||
public void onConfigurationChanged(Configuration conf) {
|
public void onConfigurationChanged(Configuration conf) {
|
||||||
mSubtypeSwitcher.onConfigurationChanged(conf);
|
mSubtypeSwitcher.onConfigurationChanged(conf);
|
||||||
|
onLanguageChanged();
|
||||||
updateAutoTextEnabled();
|
updateAutoTextEnabled();
|
||||||
|
|
||||||
// If orientation changed while predicting, commit the change
|
// If orientation changed while predicting, commit the change
|
||||||
|
@ -577,9 +578,11 @@ public class LatinIME extends InputMethodService
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SubtypeSwitcher.getInstance().updateParametersOnStartInputView();
|
||||||
|
|
||||||
if (mRefreshKeyboardRequired) {
|
if (mRefreshKeyboardRequired) {
|
||||||
mRefreshKeyboardRequired = false;
|
mRefreshKeyboardRequired = false;
|
||||||
toggleLanguage(true, true);
|
onLanguageChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
TextEntryState.newSession(this);
|
TextEntryState.newSession(this);
|
||||||
|
@ -2176,8 +2179,18 @@ public class LatinIME extends InputMethodService
|
||||||
return mWord.isFirstCharCapitalized();
|
return mWord.isFirstCharCapitalized();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Notify that Language has been changed and toggleLanguage will update KeyboaredID according
|
||||||
|
// to new Language.
|
||||||
|
private void onLanguageChanged() {
|
||||||
|
toggleLanguage(true, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// "reset" and "next" are used only for USE_SPACEBAR_LANGUAGE_SWITCHER.
|
||||||
private void toggleLanguage(boolean reset, boolean next) {
|
private void toggleLanguage(boolean reset, boolean next) {
|
||||||
mSubtypeSwitcher.toggleLanguage(reset, next);
|
if (SubtypeSwitcher.USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||||
|
mSubtypeSwitcher.toggleLanguage(reset, next);
|
||||||
|
}
|
||||||
|
// Reload keyboard because the current language has been changed.
|
||||||
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
||||||
final int mode = switcher.getKeyboardMode();
|
final int mode = switcher.getKeyboardMode();
|
||||||
final EditorInfo attribute = getCurrentInputEditorInfo();
|
final EditorInfo attribute = getCurrentInputEditorInfo();
|
||||||
|
@ -2249,7 +2262,7 @@ public class LatinIME extends InputMethodService
|
||||||
return new FieldContext(
|
return new FieldContext(
|
||||||
getCurrentInputConnection(),
|
getCurrentInputConnection(),
|
||||||
getCurrentInputEditorInfo(),
|
getCurrentInputEditorInfo(),
|
||||||
mSubtypeSwitcher.getInputLanguage(),
|
mSubtypeSwitcher.getInputLocaleStr(),
|
||||||
mSubtypeSwitcher.getEnabledLanguages());
|
mSubtypeSwitcher.getEnabledLanguages());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2372,7 +2385,7 @@ public class LatinIME extends InputMethodService
|
||||||
private void updateAutoTextEnabled() {
|
private void updateAutoTextEnabled() {
|
||||||
if (mSuggest == null) return;
|
if (mSuggest == null) return;
|
||||||
mSuggest.setAutoTextEnabled(mQuickFixes
|
mSuggest.setAutoTextEnabled(mQuickFixes
|
||||||
&& SubtypeSwitcher.getInstance().isSystemLocaleSameAsInputLocale());
|
&& SubtypeSwitcher.getInstance().isSystemLanguageSameAsInputLanguage());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSuggestionVisibility(SharedPreferences prefs) {
|
private void updateSuggestionVisibility(SharedPreferences prefs) {
|
||||||
|
@ -2419,7 +2432,7 @@ public class LatinIME extends InputMethodService
|
||||||
sp.getBoolean(PREF_HAS_USED_VOICE_INPUT_UNSUPPORTED_LOCALE, false);
|
sp.getBoolean(PREF_HAS_USED_VOICE_INPUT_UNSUPPORTED_LOCALE, false);
|
||||||
|
|
||||||
mLocaleSupportedForVoiceInput = SubtypeSwitcher.getInstance().isVoiceSupported(
|
mLocaleSupportedForVoiceInput = SubtypeSwitcher.getInstance().isVoiceSupported(
|
||||||
SubtypeSwitcher.getInstance().getInputLanguage());
|
SubtypeSwitcher.getInstance().getInputLocaleStr());
|
||||||
|
|
||||||
mAutoCorrectEnabled = isAutoCorrectEnabled(sp);
|
mAutoCorrectEnabled = isAutoCorrectEnabled(sp);
|
||||||
mBigramSuggestionEnabled = mAutoCorrectEnabled && isBigramSuggestionEnabled(sp);
|
mBigramSuggestionEnabled = mAutoCorrectEnabled && isBigramSuggestionEnabled(sp);
|
||||||
|
@ -2580,6 +2593,7 @@ public class LatinIME extends InputMethodService
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype) {
|
public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype) {
|
||||||
SubtypeSwitcher.getInstance().onCurrentInputMethodSubtypeChanged(subtype);
|
SubtypeSwitcher.getInstance().updateSubtype(subtype);
|
||||||
|
onLanguageChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
package com.android.inputmethod.latin;
|
package com.android.inputmethod.latin;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
@ -34,7 +33,6 @@ import android.speech.SpeechRecognizer;
|
||||||
import android.text.AutoText;
|
import android.text.AutoText;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.inputmethod.voice.SettingsUtil;
|
|
||||||
import com.android.inputmethod.voice.VoiceInputLogger;
|
import com.android.inputmethod.voice.VoiceInputLogger;
|
||||||
|
|
||||||
public class LatinIMESettings extends PreferenceActivity
|
public class LatinIMESettings extends PreferenceActivity
|
||||||
|
|
|
@ -419,7 +419,7 @@ public class LatinKeyboard extends BaseKeyboard {
|
||||||
final Rect bounds = new Rect();
|
final Rect bounds = new Rect();
|
||||||
|
|
||||||
// Estimate appropriate language name text size to fit in maxTextWidth.
|
// Estimate appropriate language name text size to fit in maxTextWidth.
|
||||||
String language = SubtypeSwitcher.getLanguageName(locale);
|
String language = SubtypeSwitcher.getDisplayLanguage(locale);
|
||||||
int textWidth = getTextWidth(paint, language, origTextSize, bounds);
|
int textWidth = getTextWidth(paint, language, origTextSize, bounds);
|
||||||
// Assuming text width and text size are proportional to each other.
|
// Assuming text width and text size are proportional to each other.
|
||||||
float textSize = origTextSize * Math.min(maxTextWidth / textWidth, 1.0f);
|
float textSize = origTextSize * Math.min(maxTextWidth / textWidth, 1.0f);
|
||||||
|
@ -435,7 +435,7 @@ public class LatinKeyboard extends BaseKeyboard {
|
||||||
textSize = origTextSize;
|
textSize = origTextSize;
|
||||||
}
|
}
|
||||||
if (useShortName) {
|
if (useShortName) {
|
||||||
language = SubtypeSwitcher.getShortLanguageName(locale);
|
language = SubtypeSwitcher.getShortDisplayLanguage(locale);
|
||||||
textWidth = getTextWidth(paint, language, origTextSize, bounds);
|
textWidth = getTextWidth(paint, language, origTextSize, bounds);
|
||||||
textSize = origTextSize * Math.min(maxTextWidth / textWidth, 1.0f);
|
textSize = origTextSize * Math.min(maxTextWidth / textWidth, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,14 +18,18 @@ package com.android.inputmethod.latin;
|
||||||
|
|
||||||
import com.android.inputmethod.voice.SettingsUtil;
|
import com.android.inputmethod.voice.SettingsUtil;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.inputmethodservice.InputMethodService;
|
import android.inputmethodservice.InputMethodService;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.view.inputmethod.InputMethodSubtype;
|
import android.view.inputmethod.InputMethodSubtype;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
@ -33,12 +37,34 @@ import java.util.Locale;
|
||||||
public class SubtypeSwitcher {
|
public class SubtypeSwitcher {
|
||||||
// This flag indicates if we support language switching by swipe on space bar.
|
// This flag indicates if we support language switching by swipe on space bar.
|
||||||
// We may or may not draw the current language on space bar regardless of this flag.
|
// We may or may not draw the current language on space bar regardless of this flag.
|
||||||
public static final boolean USE_SPACEBAR_LANGUAGE_SWITCHER = true;
|
public static final boolean USE_SPACEBAR_LANGUAGE_SWITCHER = false;
|
||||||
|
private static final boolean DBG = false;
|
||||||
private static final String TAG = "SubtypeSwitcher";
|
private static final String TAG = "SubtypeSwitcher";
|
||||||
|
|
||||||
|
private static final char LOCALE_SEPARATER = '_';
|
||||||
|
private static final String KEYBOARD_MODE = "keyboard";
|
||||||
|
private static final String VOICE_MODE = "voice";
|
||||||
|
private final TextUtils.SimpleStringSplitter mLocaleSplitter =
|
||||||
|
new TextUtils.SimpleStringSplitter(LOCALE_SEPARATER);
|
||||||
|
|
||||||
private static final SubtypeSwitcher sInstance = new SubtypeSwitcher();
|
private static final SubtypeSwitcher sInstance = new SubtypeSwitcher();
|
||||||
private InputMethodService mService;
|
private /* final */ InputMethodService mService;
|
||||||
private Resources mResources;
|
private /* final */ InputMethodManager mImm;
|
||||||
|
private /* final */ Resources mResources;
|
||||||
|
private final ArrayList<InputMethodSubtype> mEnabledKeyboardSubtypesOfCurrentInputMethod =
|
||||||
|
new ArrayList<InputMethodSubtype>();
|
||||||
|
private final ArrayList<String> mEnabledLanguagesOfCurrentInputMethod = new ArrayList<String>();
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
// Variants which should be changed only by reload functions.
|
||||||
private Locale mSystemLocale;
|
private Locale mSystemLocale;
|
||||||
|
private Locale mInputLocale;
|
||||||
|
private String mInputLocaleStr;
|
||||||
|
private String mMode;
|
||||||
|
private List<InputMethodSubtype> mAllEnabledSubtypesOfCurrentInputMethod;
|
||||||
|
private boolean mNeedsToDisplayLanguage;
|
||||||
|
private boolean mIsSystemLanguageSameAsInputLanguage;
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
public static SubtypeSwitcher getInstance() {
|
public static SubtypeSwitcher getInstance() {
|
||||||
return sInstance;
|
return sInstance;
|
||||||
|
@ -47,16 +73,97 @@ public class SubtypeSwitcher {
|
||||||
public static void init(LatinIME service) {
|
public static void init(LatinIME service) {
|
||||||
sInstance.mService = service;
|
sInstance.mService = service;
|
||||||
sInstance.mResources = service.getResources();
|
sInstance.mResources = service.getResources();
|
||||||
sInstance.mSystemLocale = sInstance.mResources.getConfiguration().locale;
|
sInstance.mImm = (InputMethodManager) service.getSystemService(
|
||||||
|
Context.INPUT_METHOD_SERVICE);
|
||||||
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||||
sInstance.initLanguageSwitcher(service);
|
sInstance.initLanguageSwitcher(service);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sInstance.updateAllParameters();
|
||||||
}
|
}
|
||||||
|
|
||||||
private SubtypeSwitcher() {
|
private SubtypeSwitcher() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype) {
|
// Update all parameters stored in SubtypeSwitcher.
|
||||||
|
// Only configuration changed event is allowed to call this because this is heavy.
|
||||||
|
private void updateAllParameters() {
|
||||||
|
mSystemLocale = mResources.getConfiguration().locale;
|
||||||
|
updateSubtype(mImm.getCurrentInputMethodSubtype());
|
||||||
|
updateParametersOnStartInputView();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update parameters which are changed outside LatinIME. This parameters affect UI so they
|
||||||
|
// should be updated every time onStartInputview.
|
||||||
|
public void updateParametersOnStartInputView() {
|
||||||
|
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||||
|
updateForSpaceBarLanguageSwitch();
|
||||||
|
} else {
|
||||||
|
updateEnabledSubtypes();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reload enabledSubtypes from the framework.
|
||||||
|
private void updateEnabledSubtypes() {
|
||||||
|
boolean foundCurrentSubtypeBecameDisabled = true;
|
||||||
|
mAllEnabledSubtypesOfCurrentInputMethod = mImm.getEnabledInputMethodSubtypeList(null);
|
||||||
|
mEnabledLanguagesOfCurrentInputMethod.clear();
|
||||||
|
mEnabledKeyboardSubtypesOfCurrentInputMethod.clear();
|
||||||
|
for (InputMethodSubtype ims: mAllEnabledSubtypesOfCurrentInputMethod) {
|
||||||
|
final String locale = ims.getLocale();
|
||||||
|
final String mode = ims.getMode();
|
||||||
|
mLocaleSplitter.setString(locale);
|
||||||
|
if (mLocaleSplitter.hasNext()) {
|
||||||
|
mEnabledLanguagesOfCurrentInputMethod.add(mLocaleSplitter.next());
|
||||||
|
}
|
||||||
|
if (locale.equals(mInputLocaleStr) && mode.equals(mMode)) {
|
||||||
|
foundCurrentSubtypeBecameDisabled = false;
|
||||||
|
}
|
||||||
|
if (KEYBOARD_MODE.equals(ims.getMode())) {
|
||||||
|
mEnabledKeyboardSubtypesOfCurrentInputMethod.add(ims);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mNeedsToDisplayLanguage = !(getEnabledKeyboardLocaleCount() <= 1
|
||||||
|
&& mIsSystemLanguageSameAsInputLanguage);
|
||||||
|
if (foundCurrentSubtypeBecameDisabled) {
|
||||||
|
updateSubtype(mImm.getCurrentInputMethodSubtype());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the current subtype. LatinIME.onCurrentInputMethodSubtypeChanged calls this function.
|
||||||
|
public void updateSubtype(InputMethodSubtype newSubtype) {
|
||||||
|
if (DBG) {
|
||||||
|
Log.w(TAG, "Update subtype to:" + newSubtype.getLocale() + "," + newSubtype.getMode());
|
||||||
|
}
|
||||||
|
updateInputLocale(newSubtype.getLocale());
|
||||||
|
mMode = newSubtype.getMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the current input locale from Locale string.
|
||||||
|
private void updateInputLocale(String inputLocaleStr) {
|
||||||
|
// example: inputLocaleStr = "en_US" "en" ""
|
||||||
|
// "en_US" --> language: en & country: US
|
||||||
|
// "en" --> language: en
|
||||||
|
// "" --> the system locale
|
||||||
|
mLocaleSplitter.setString(inputLocaleStr);
|
||||||
|
if (mLocaleSplitter.hasNext()) {
|
||||||
|
String language = mLocaleSplitter.next();
|
||||||
|
if (mLocaleSplitter.hasNext()) {
|
||||||
|
mInputLocale = new Locale(language, mLocaleSplitter.next());
|
||||||
|
} else {
|
||||||
|
mInputLocale = new Locale(language);
|
||||||
|
}
|
||||||
|
mInputLocaleStr = inputLocaleStr;
|
||||||
|
} else {
|
||||||
|
mInputLocale = mSystemLocale;
|
||||||
|
String country = mSystemLocale.getCountry();
|
||||||
|
mInputLocaleStr = mSystemLocale.getLanguage()
|
||||||
|
+ (TextUtils.isEmpty(country) ? "" : "_" + mSystemLocale.getLanguage());
|
||||||
|
}
|
||||||
|
mIsSystemLanguageSameAsInputLanguage = getSystemLocale().getLanguage().equalsIgnoreCase(
|
||||||
|
getInputLocale().getLanguage());
|
||||||
|
mNeedsToDisplayLanguage = !(getEnabledKeyboardLocaleCount() <= 1
|
||||||
|
&& mIsSystemLanguageSameAsInputLanguage);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////
|
//////////////////////////////////
|
||||||
|
@ -66,82 +173,94 @@ public class SubtypeSwitcher {
|
||||||
public int getEnabledKeyboardLocaleCount() {
|
public int getEnabledKeyboardLocaleCount() {
|
||||||
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||||
return mLanguageSwitcher.getLocaleCount();
|
return mLanguageSwitcher.getLocaleCount();
|
||||||
|
} else {
|
||||||
|
return mEnabledKeyboardSubtypesOfCurrentInputMethod.size();
|
||||||
}
|
}
|
||||||
// TODO: Implement for no legacy mode
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Cache the value
|
|
||||||
public boolean needsToDisplayLanguage() {
|
public boolean needsToDisplayLanguage() {
|
||||||
// TODO: Takes care of two-char locale such as "en" in addition to "en_US"
|
return mNeedsToDisplayLanguage;
|
||||||
return !(getEnabledKeyboardLocaleCount() <= 1 && getSystemLocale().getLanguage(
|
|
||||||
).equalsIgnoreCase(getInputLocale().getLanguage()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Locale getInputLocale() {
|
public Locale getInputLocale() {
|
||||||
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||||
return mLanguageSwitcher.getInputLocale();
|
return mLanguageSwitcher.getInputLocale();
|
||||||
|
} else {
|
||||||
|
return mInputLocale;
|
||||||
}
|
}
|
||||||
// TODO: Implement for no legacy mode
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getInputLanguage() {
|
public String getInputLocaleStr() {
|
||||||
String inputLanguage = null;
|
|
||||||
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||||
|
String inputLanguage = null;
|
||||||
inputLanguage = mLanguageSwitcher.getInputLanguage();
|
inputLanguage = mLanguageSwitcher.getInputLanguage();
|
||||||
|
// Should return system locale if there is no Language available.
|
||||||
|
if (inputLanguage == null) {
|
||||||
|
inputLanguage = getSystemLocale().getLanguage();
|
||||||
|
}
|
||||||
|
return inputLanguage;
|
||||||
|
} else {
|
||||||
|
return mInputLocaleStr;
|
||||||
}
|
}
|
||||||
// Should return system locale if there is no Language available.
|
|
||||||
if (inputLanguage == null) {
|
|
||||||
inputLanguage = getSystemLocale().getLanguage();
|
|
||||||
}
|
|
||||||
return inputLanguage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getEnabledLanguages() {
|
public String[] getEnabledLanguages() {
|
||||||
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||||
return mLanguageSwitcher.getEnabledLanguages();
|
return mLanguageSwitcher.getEnabledLanguages();
|
||||||
|
} else {
|
||||||
|
return mEnabledLanguagesOfCurrentInputMethod.toArray(
|
||||||
|
new String[mEnabledLanguagesOfCurrentInputMethod.size()]);
|
||||||
}
|
}
|
||||||
// TODO: Implement for no legacy mode
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Locale getSystemLocale() {
|
public Locale getSystemLocale() {
|
||||||
return mSystemLocale;
|
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||||
|
return mLanguageSwitcher.getSystemLocale();
|
||||||
|
} else {
|
||||||
|
return mSystemLocale;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Cache the value for faster processing.
|
public boolean isSystemLanguageSameAsInputLanguage() {
|
||||||
public boolean isSystemLocaleSameAsInputLocale() {
|
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||||
// TODO: Takes care of two-char locale such as "en" in addition to "en_US"
|
return getSystemLocale().getLanguage().equalsIgnoreCase(
|
||||||
return getSystemLocale().getLanguage().equalsIgnoreCase(
|
getInputLocaleStr().substring(0, 2));
|
||||||
getInputLanguage().substring(0, 2));
|
} else {
|
||||||
|
return mIsSystemLanguageSameAsInputLanguage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onConfigurationChanged(Configuration conf) {
|
public void onConfigurationChanged(Configuration conf) {
|
||||||
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
final Locale systemLocale = conf.locale;
|
||||||
// If the system locale changes and is different from the saved
|
// If system configuration was changed, update all parameters.
|
||||||
// locale (mSystemLocale), then reload the input locale list from the
|
if (!TextUtils.equals(systemLocale.toString(), mSystemLocale.toString())) {
|
||||||
// latin ime settings (shared prefs) and reset the input locale
|
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||||
// to the first one.
|
// If the system locale changes and is different from the saved
|
||||||
final Locale systemLocale = conf.locale;
|
// locale (mSystemLocale), then reload the input locale list from the
|
||||||
if (!TextUtils.equals(systemLocale.toString(), mSystemLocale.toString())) {
|
// latin ime settings (shared prefs) and reset the input locale
|
||||||
mSystemLocale = systemLocale;
|
// to the first one.
|
||||||
mLanguageSwitcher.loadLocales(
|
mLanguageSwitcher.loadLocales(PreferenceManager
|
||||||
PreferenceManager.getDefaultSharedPreferences(mService));
|
.getDefaultSharedPreferences(mService));
|
||||||
mLanguageSwitcher.setSystemLocale(systemLocale);
|
mLanguageSwitcher.setSystemLocale(systemLocale);
|
||||||
toggleLanguage(true, true);
|
} else {
|
||||||
|
updateAllParameters();
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||||
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||||
mLanguageSwitcher.loadLocales(sharedPreferences);
|
if (LatinIME.PREF_SELECTED_LANGUAGES.equals(key)) {
|
||||||
return;
|
mLanguageSwitcher.loadLocales(sharedPreferences);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change system locale for this application
|
||||||
|
* @param newLocale
|
||||||
|
* @return oldLocale
|
||||||
|
*/
|
||||||
public Locale changeSystemLocale(Locale newLocale) {
|
public Locale changeSystemLocale(Locale newLocale) {
|
||||||
Configuration conf = mResources.getConfiguration();
|
Configuration conf = mResources.getConfiguration();
|
||||||
Locale oldLocale = conf.locale;
|
Locale oldLocale = conf.locale;
|
||||||
|
@ -150,16 +269,25 @@ public class SubtypeSwitcher {
|
||||||
return oldLocale;
|
return oldLocale;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////
|
//////////////////////////////////////
|
||||||
// Legacy Language Switch support //
|
// SpaceBar Language Switch support //
|
||||||
////////////////////////////////////////////
|
//////////////////////////////////////
|
||||||
|
|
||||||
private LanguageSwitcher mLanguageSwitcher;
|
private LanguageSwitcher mLanguageSwitcher;
|
||||||
|
|
||||||
public static String getLanguageName(Locale locale) {
|
public static String getFullDisplayName(Locale locale, boolean returnsNameInThisLocale) {
|
||||||
|
if (returnsNameInThisLocale) {
|
||||||
|
return toTitleCase(locale.getDisplayName(locale));
|
||||||
|
} else {
|
||||||
|
return toTitleCase(locale.getDisplayName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getDisplayLanguage(Locale locale) {
|
||||||
return toTitleCase(locale.getDisplayLanguage(locale));
|
return toTitleCase(locale.getDisplayLanguage(locale));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getShortLanguageName(Locale locale) {
|
public static String getShortDisplayLanguage(Locale locale) {
|
||||||
return toTitleCase(locale.getLanguage());
|
return toTitleCase(locale.getLanguage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,25 +298,34 @@ public class SubtypeSwitcher {
|
||||||
return Character.toUpperCase(s.charAt(0)) + s.substring(1);
|
return Character.toUpperCase(s.charAt(0)) + s.substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateForSpaceBarLanguageSwitch() {
|
||||||
|
// We need to update mNeedsToDisplayLanguage in onStartInputView because
|
||||||
|
// getEnabledKeyboardLocaleCount could have been changed.
|
||||||
|
mNeedsToDisplayLanguage = !(getEnabledKeyboardLocaleCount() <= 1
|
||||||
|
&& getSystemLocale().getLanguage().equalsIgnoreCase(
|
||||||
|
getInputLocale().getLanguage()));
|
||||||
|
}
|
||||||
|
|
||||||
public String getInputLanguageName() {
|
public String getInputLanguageName() {
|
||||||
return getLanguageName(getInputLocale());
|
return getDisplayLanguage(getInputLocale());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNextInputLanguageName() {
|
public String getNextInputLanguageName() {
|
||||||
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||||
return getLanguageName(mLanguageSwitcher.getNextInputLocale());
|
return getDisplayLanguage(mLanguageSwitcher.getNextInputLocale());
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPreviousInputLanguageName() {
|
public String getPreviousInputLanguageName() {
|
||||||
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||||
return getLanguageName(mLanguageSwitcher.getPrevInputLocale());
|
return getDisplayLanguage(mLanguageSwitcher.getPrevInputLocale());
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This can be an array of String
|
|
||||||
// A list of locales which are supported by default for voice input, unless we get a
|
// A list of locales which are supported by default for voice input, unless we get a
|
||||||
// different list from Gservices.
|
// different list from Gservices.
|
||||||
private static final String DEFAULT_VOICE_INPUT_SUPPORTED_LOCALES =
|
private static final String DEFAULT_VOICE_INPUT_SUPPORTED_LOCALES =
|
||||||
|
@ -225,16 +362,18 @@ public class SubtypeSwitcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toggleLanguage(boolean reset, boolean next) {
|
public void toggleLanguage(boolean reset, boolean next) {
|
||||||
if (reset) {
|
if (USE_SPACEBAR_LANGUAGE_SWITCHER) {
|
||||||
mLanguageSwitcher.reset();
|
if (reset) {
|
||||||
} else {
|
mLanguageSwitcher.reset();
|
||||||
if (next) {
|
|
||||||
mLanguageSwitcher.next();
|
|
||||||
} else {
|
} else {
|
||||||
mLanguageSwitcher.prev();
|
if (next) {
|
||||||
|
mLanguageSwitcher.next();
|
||||||
|
} else {
|
||||||
|
mLanguageSwitcher.prev();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
mLanguageSwitcher.persist();
|
||||||
}
|
}
|
||||||
mLanguageSwitcher.persist();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initLanguageSwitcher(LatinIME service) {
|
private void initLanguageSwitcher(LatinIME service) {
|
||||||
|
|
Loading…
Reference in New Issue