Skip to content
Snippets Groups Projects
Commit 6c2f9f5b authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Fix bug: 2512075 : Current input language resets to first in list on orientation change

Have separate variables for system locale and input locale.
parent 3656fb79
No related branches found
No related tags found
No related merge requests found
...@@ -164,7 +164,8 @@ public class LatinIME extends InputMethodService ...@@ -164,7 +164,8 @@ public class LatinIME extends InputMethodService
Resources mResources; Resources mResources;
private String mLocale; private String mInputLocale;
private String mSystemLocale;
private LanguageSwitcher mLanguageSwitcher; private LanguageSwitcher mLanguageSwitcher;
private StringBuilder mComposing = new StringBuilder(); private StringBuilder mComposing = new StringBuilder();
...@@ -277,7 +278,7 @@ public class LatinIME extends InputMethodService ...@@ -277,7 +278,7 @@ public class LatinIME extends InputMethodService
mLanguageSwitcher.loadLocales(prefs); mLanguageSwitcher.loadLocales(prefs);
mKeyboardSwitcher = new KeyboardSwitcher(this, this); mKeyboardSwitcher = new KeyboardSwitcher(this, this);
mKeyboardSwitcher.setLanguageSwitcher(mLanguageSwitcher); mKeyboardSwitcher.setLanguageSwitcher(mLanguageSwitcher);
boolean enableMultipleLanguages = mLanguageSwitcher.getLocaleCount() > 0; mSystemLocale = conf.locale.toString();
String inputLanguage = mLanguageSwitcher.getInputLanguage(); String inputLanguage = mLanguageSwitcher.getInputLanguage();
if (inputLanguage == null) { if (inputLanguage == null) {
inputLanguage = conf.locale.toString(); inputLanguage = conf.locale.toString();
...@@ -306,7 +307,7 @@ public class LatinIME extends InputMethodService ...@@ -306,7 +307,7 @@ public class LatinIME extends InputMethodService
} }
private void initSuggest(String locale) { private void initSuggest(String locale) {
mLocale = locale; mInputLocale = locale;
Resources orig = getResources(); Resources orig = getResources();
Configuration conf = orig.getConfiguration(); Configuration conf = orig.getConfiguration();
...@@ -321,14 +322,14 @@ public class LatinIME extends InputMethodService ...@@ -321,14 +322,14 @@ public class LatinIME extends InputMethodService
mSuggest = new Suggest(this, R.raw.main); mSuggest = new Suggest(this, R.raw.main);
updateAutoTextEnabled(saveLocale); updateAutoTextEnabled(saveLocale);
if (mUserDictionary != null) mUserDictionary.close(); if (mUserDictionary != null) mUserDictionary.close();
mUserDictionary = new UserDictionary(this, mLocale); mUserDictionary = new UserDictionary(this, mInputLocale);
if (mContactsDictionary == null) { if (mContactsDictionary == null) {
mContactsDictionary = new ContactsDictionary(this); mContactsDictionary = new ContactsDictionary(this);
} }
if (mAutoDictionary != null) { if (mAutoDictionary != null) {
mAutoDictionary.close(); mAutoDictionary.close();
} }
mAutoDictionary = new AutoDictionary(this, this, mLocale); mAutoDictionary = new AutoDictionary(this, this, mInputLocale);
mSuggest.setUserDictionary(mUserDictionary); mSuggest.setUserDictionary(mUserDictionary);
mSuggest.setContactsDictionary(mContactsDictionary); mSuggest.setContactsDictionary(mContactsDictionary);
mSuggest.setAutoDictionary(mAutoDictionary); mSuggest.setAutoDictionary(mAutoDictionary);
...@@ -354,10 +355,12 @@ public class LatinIME extends InputMethodService ...@@ -354,10 +355,12 @@ public class LatinIME extends InputMethodService
@Override @Override
public void onConfigurationChanged(Configuration conf) { public void onConfigurationChanged(Configuration conf) {
// If the system locale changes and is different from the saved // If the system locale changes and is different from the saved
// locale (mLocale), then reload the input locale list from the // locale (mSystemLocale), then reload the input locale list from the
// latin ime settings (shared prefs) and reset the input locale // latin ime settings (shared prefs) and reset the input locale
// to the first one. // to the first one.
if (!TextUtils.equals(conf.locale.toString(), mLocale)) { final String systemLocale = conf.locale.toString();
if (!TextUtils.equals(systemLocale, mSystemLocale)) {
mSystemLocale = systemLocale;
if (mLanguageSwitcher != null) { if (mLanguageSwitcher != null) {
mLanguageSwitcher.loadLocales( mLanguageSwitcher.loadLocales(
PreferenceManager.getDefaultSharedPreferences(this)); PreferenceManager.getDefaultSharedPreferences(this));
...@@ -1783,7 +1786,8 @@ public class LatinIME extends InputMethodService ...@@ -1783,7 +1786,8 @@ public class LatinIME extends InputMethodService
private void updateAutoTextEnabled(Locale systemLocale) { private void updateAutoTextEnabled(Locale systemLocale) {
if (mSuggest == null) return; if (mSuggest == null) return;
boolean different = !systemLocale.getLanguage().equalsIgnoreCase(mLocale.substring(0, 2)); boolean different =
!systemLocale.getLanguage().equalsIgnoreCase(mInputLocale.substring(0, 2));
mSuggest.setAutoTextEnabled(!different && mQuickFixes); mSuggest.setAutoTextEnabled(!different && mQuickFixes);
} }
...@@ -1822,7 +1826,7 @@ public class LatinIME extends InputMethodService ...@@ -1822,7 +1826,7 @@ public class LatinIME extends InputMethodService
ArrayList<String> voiceInputSupportedLocales = ArrayList<String> voiceInputSupportedLocales =
newArrayList(supportedLocalesString.split("\\s+")); newArrayList(supportedLocalesString.split("\\s+"));
mLocaleSupportedForVoiceInput = voiceInputSupportedLocales.contains(mLocale); mLocaleSupportedForVoiceInput = voiceInputSupportedLocales.contains(mInputLocale);
mShowSuggestions = sp.getBoolean(PREF_SHOW_SUGGESTIONS, true); mShowSuggestions = sp.getBoolean(PREF_SHOW_SUGGESTIONS, true);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment