Fix for language bar switching
Change-Id: Id3974642b62b012968c537eff7c1a7ee37e2def2
This commit is contained in:
parent
0851abf999
commit
6d9021527a
5 changed files with 39 additions and 16 deletions
|
@ -107,7 +107,8 @@ public class InputMethodManagerCompatWrapper {
|
|||
public List<InputMethodSubtypeCompatWrapper> getEnabledInputMethodSubtypeList(
|
||||
InputMethodInfoCompatWrapper imi, boolean allowsImplicitlySelectedSubtypes) {
|
||||
if (!SUBTYPE_SUPPORTED) {
|
||||
String[] languages = mLanguageSwitcherProxy.getEnabledLanguages();
|
||||
String[] languages = mLanguageSwitcherProxy.getEnabledLanguages(
|
||||
allowsImplicitlySelectedSubtypes);
|
||||
List<InputMethodSubtypeCompatWrapper> subtypeList =
|
||||
new ArrayList<InputMethodSubtypeCompatWrapper>();
|
||||
for (String lang: languages) {
|
||||
|
@ -195,10 +196,6 @@ public class InputMethodManagerCompatWrapper {
|
|||
|
||||
public void setInputMethodAndSubtype(
|
||||
IBinder token, String id, InputMethodSubtypeCompatWrapper subtype) {
|
||||
if (!SUBTYPE_SUPPORTED) {
|
||||
mLanguageSwitcherProxy.setLocale(subtype.getLocale());
|
||||
return;
|
||||
}
|
||||
CompatUtils.invoke(mImm, null, METHOD_setInputMethodAndSubtype,
|
||||
token, id, subtype.getOriginalObject());
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package com.android.inputmethod.compat;
|
||||
|
||||
import com.android.inputmethod.deprecated.LanguageSwitcherProxy;
|
||||
import com.android.inputmethod.latin.SubtypeSwitcher;
|
||||
|
||||
import android.inputmethodservice.InputMethodService;
|
||||
|
@ -51,6 +52,9 @@ public class InputMethodServiceCompatWrapper extends InputMethodService {
|
|||
subtype = mImm.getCurrentInputMethodSubtype();
|
||||
}
|
||||
if (subtype != null) {
|
||||
if (!InputMethodManagerCompatWrapper.SUBTYPE_SUPPORTED) {
|
||||
LanguageSwitcherProxy.getInstance().setLocale(subtype.getLocale());
|
||||
}
|
||||
SubtypeSwitcher.getInstance().updateSubtype(subtype);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ package com.android.inputmethod.deprecated;
|
|||
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
|
||||
import com.android.inputmethod.deprecated.languageswitcher.LanguageSwitcher;
|
||||
import com.android.inputmethod.latin.LatinIME;
|
||||
import com.android.inputmethod.latin.Settings;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
|
@ -26,7 +27,7 @@ import android.content.res.Configuration;
|
|||
import java.util.Locale;
|
||||
|
||||
// This class is used only when the IME doesn't use method.xml for language switching.
|
||||
public class LanguageSwitcherProxy {
|
||||
public class LanguageSwitcherProxy implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
private static final LanguageSwitcherProxy sInstance = new LanguageSwitcherProxy();
|
||||
private LanguageSwitcher mLanguageSwitcher;
|
||||
private SharedPreferences mPrefs;
|
||||
|
@ -42,6 +43,7 @@ public class LanguageSwitcherProxy {
|
|||
sInstance.mLanguageSwitcher = new LanguageSwitcher(service);
|
||||
sInstance.mLanguageSwitcher.loadLocales(prefs, conf.locale);
|
||||
sInstance.mPrefs = prefs;
|
||||
prefs.registerOnSharedPreferenceChangeListener(sInstance);
|
||||
}
|
||||
|
||||
public static void onConfigurationChanged(Configuration conf) {
|
||||
|
@ -58,8 +60,8 @@ public class LanguageSwitcherProxy {
|
|||
return mLanguageSwitcher.getLocaleCount();
|
||||
}
|
||||
|
||||
public String[] getEnabledLanguages() {
|
||||
return mLanguageSwitcher.getEnabledLanguages();
|
||||
public String[] getEnabledLanguages(boolean allowImplicitlySelectedLanguages) {
|
||||
return mLanguageSwitcher.getEnabledLanguages(allowImplicitlySelectedLanguages);
|
||||
}
|
||||
|
||||
public Locale getInputLocale() {
|
||||
|
@ -70,4 +72,14 @@ public class LanguageSwitcherProxy {
|
|||
mLanguageSwitcher.setLocale(localeStr);
|
||||
mLanguageSwitcher.persist(mPrefs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
|
||||
// PREF_SELECTED_LANGUAGES: enabled input subtypes
|
||||
// PREF_INPUT_LANGUAGE: current input subtype
|
||||
if (key.equals(Settings.PREF_SELECTED_LANGUAGES)
|
||||
|| key.equals(Settings.PREF_INPUT_LANGUAGE)) {
|
||||
mLanguageSwitcher.loadLocales(prefs, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ package com.android.inputmethod.deprecated.languageswitcher;
|
|||
|
||||
import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper;
|
||||
import com.android.inputmethod.latin.LatinIME;
|
||||
import com.android.inputmethod.latin.LatinImeLogger;
|
||||
import com.android.inputmethod.latin.Settings;
|
||||
import com.android.inputmethod.latin.SharedPreferencesCompat;
|
||||
|
||||
|
@ -25,6 +26,7 @@ import android.content.SharedPreferences;
|
|||
import android.content.SharedPreferences.Editor;
|
||||
import android.content.res.Configuration;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
|
@ -34,12 +36,14 @@ import java.util.Locale;
|
|||
* input language that the user has selected.
|
||||
*/
|
||||
public class LanguageSwitcher {
|
||||
private static final String TAG = LanguageSwitcher.class.getSimpleName();
|
||||
|
||||
private static final String KEYBOARD_MODE = "keyboard";
|
||||
private static final String[] EMPTY_STIRNG_ARRAY = new String[0];
|
||||
|
||||
private final ArrayList<Locale> mLocales = new ArrayList<Locale>();
|
||||
private final LatinIME mIme;
|
||||
private String[] mSelectedLanguageArray;
|
||||
private String[] mSelectedLanguageArray = EMPTY_STIRNG_ARRAY;
|
||||
private String mSelectedLanguages;
|
||||
private int mCurrentIndex = 0;
|
||||
private String mDefaultInputLanguage;
|
||||
|
@ -69,12 +73,16 @@ public class LanguageSwitcher {
|
|||
* @return whether there was any change
|
||||
*/
|
||||
public boolean loadLocales(SharedPreferences sp, Locale systemLocale) {
|
||||
if (LatinImeLogger.sDBG) {
|
||||
Log.d(TAG, "load locales");
|
||||
}
|
||||
if (systemLocale != null) {
|
||||
setSystemLocale(systemLocale);
|
||||
}
|
||||
String selectedLanguages = sp.getString(Settings.PREF_SELECTED_LANGUAGES, null);
|
||||
String currentLanguage = sp.getString(Settings.PREF_INPUT_LANGUAGE, null);
|
||||
if (selectedLanguages == null || selectedLanguages.length() < 1) {
|
||||
if (TextUtils.isEmpty(selectedLanguages)) {
|
||||
mSelectedLanguageArray = EMPTY_STIRNG_ARRAY;
|
||||
loadDefaults();
|
||||
if (mLocales.size() == 0) {
|
||||
return false;
|
||||
|
@ -104,6 +112,9 @@ public class LanguageSwitcher {
|
|||
}
|
||||
|
||||
private void loadDefaults() {
|
||||
if (LatinImeLogger.sDBG) {
|
||||
Log.d(TAG, "load default locales:");
|
||||
}
|
||||
mDefaultInputLocale = mIme.getResources().getConfiguration().locale;
|
||||
String country = mDefaultInputLocale.getCountry();
|
||||
mDefaultInputLanguage = mDefaultInputLocale.getLanguage() +
|
||||
|
@ -132,7 +143,10 @@ public class LanguageSwitcher {
|
|||
/**
|
||||
* Returns the list of enabled language codes.
|
||||
*/
|
||||
public String[] getEnabledLanguages() {
|
||||
public String[] getEnabledLanguages(boolean allowImplicitlySelectedLanguages) {
|
||||
if (mSelectedLanguageArray.length == 0 && allowImplicitlySelectedLanguages) {
|
||||
return new String[] { mDefaultInputLanguage };
|
||||
}
|
||||
return mSelectedLanguageArray;
|
||||
}
|
||||
|
||||
|
@ -218,9 +232,5 @@ public class LanguageSwitcher {
|
|||
Editor editor = prefs.edit();
|
||||
editor.putString(Settings.PREF_INPUT_LANGUAGE, getInputLanguage());
|
||||
SharedPreferencesCompat.apply(editor);
|
||||
// When the current language is changed, the event for this change should be handled
|
||||
// internally as a subtype switching.
|
||||
mIme.notifyOnCurrentInputMethodSubtypeChanged(new InputMethodSubtypeCompatWrapper(
|
||||
0, 0, getInputLocale().toString(), KEYBOARD_MODE, ""));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -375,10 +375,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
|||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
mPrefs = prefs;
|
||||
LatinImeLogger.init(this, prefs);
|
||||
LanguageSwitcherProxy.init(this, prefs);
|
||||
SubtypeSwitcher.init(this, prefs);
|
||||
KeyboardSwitcher.init(this, prefs);
|
||||
AccessibilityUtils.init(this, prefs);
|
||||
LanguageSwitcherProxy.init(this, prefs);
|
||||
|
||||
super.onCreate();
|
||||
|
||||
|
|
Loading…
Reference in a new issue