aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/deprecated
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/deprecated')
-rw-r--r--java/src/com/android/inputmethod/deprecated/LanguageSwitcherProxy.java18
-rw-r--r--java/src/com/android/inputmethod/deprecated/languageswitcher/LanguageSwitcher.java24
2 files changed, 32 insertions, 10 deletions
diff --git a/java/src/com/android/inputmethod/deprecated/LanguageSwitcherProxy.java b/java/src/com/android/inputmethod/deprecated/LanguageSwitcherProxy.java
index 5d165cda9..73f0b7a2d 100644
--- a/java/src/com/android/inputmethod/deprecated/LanguageSwitcherProxy.java
+++ b/java/src/com/android/inputmethod/deprecated/LanguageSwitcherProxy.java
@@ -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);
+ }
+ }
}
diff --git a/java/src/com/android/inputmethod/deprecated/languageswitcher/LanguageSwitcher.java b/java/src/com/android/inputmethod/deprecated/languageswitcher/LanguageSwitcher.java
index 639b7cdd0..e4b2e035c 100644
--- a/java/src/com/android/inputmethod/deprecated/languageswitcher/LanguageSwitcher.java
+++ b/java/src/com/android/inputmethod/deprecated/languageswitcher/LanguageSwitcher.java
@@ -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, ""));
}
}