From ce022748c7acd738b0762dc2c578998cd74ef6ca Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 9 Mar 2012 10:15:24 +0900 Subject: [PATCH 1/2] Fix a crash Bug: 6137076 Change-Id: I05f9f72a2678d10d3400dab5fc71544276739dcf --- .../com/android/inputmethod/latin/LatinIME.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 273593dfb..ca38cdeec 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -535,10 +535,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar registerReceiver(mReceiver, filter); mVoiceProxy = VoiceProxy.init(this, prefs, mHandler); - final IntentFilter ringerModeFilter = new IntentFilter(); - ringerModeFilter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); - registerReceiver(mFeedbackManager, ringerModeFilter); - final IntentFilter packageFilter = new IntentFilter(); packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED); packageFilter.addAction(Intent.ACTION_PACKAGE_REMOVED); @@ -551,11 +547,19 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar registerReceiver(mDictionaryPackInstallReceiver, newDictFilter); } + private void renewFeedbackReceiver() { + if (null != mFeedbackManager) unregisterReceiver(mFeedbackManager); + mFeedbackManager = new AudioAndHapticFeedbackManager(this, mSettingsValues); + final IntentFilter ringerModeFilter = new IntentFilter(); + ringerModeFilter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); + registerReceiver(mFeedbackManager, ringerModeFilter); + } + // Has to be package-visible for unit tests /* package */ void loadSettings() { if (null == mPrefs) mPrefs = PreferenceManager.getDefaultSharedPreferences(this); mSettingsValues = new SettingsValues(mPrefs, this, mSubtypeSwitcher.getInputLocaleStr()); - mFeedbackManager = new AudioAndHapticFeedbackManager(this, mSettingsValues); + renewFeedbackReceiver(); resetContactsDictionary(null == mSuggest ? null : mSuggest.getContactsDictionary()); } From 05d60e52a348c0b42a815118655344525fba8c4a Mon Sep 17 00:00:00 2001 From: Ken Wakasa Date: Sat, 28 Apr 2012 03:24:05 +0900 Subject: [PATCH 2/2] Avoid Resources$NotFoundException bug: 6410653 Change-Id: I4263632e76b44abf8ecd9114a9eb185ad39201fd --- java/src/com/android/inputmethod/latin/ImfUtils.java | 1 + java/src/com/android/inputmethod/latin/SubtypeLocale.java | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/ImfUtils.java b/java/src/com/android/inputmethod/latin/ImfUtils.java index 4633b82f5..af46a02c0 100644 --- a/java/src/com/android/inputmethod/latin/ImfUtils.java +++ b/java/src/com/android/inputmethod/latin/ImfUtils.java @@ -66,6 +66,7 @@ public class ImfUtils { public static boolean checkIfSubtypeBelongsToThisIme(Context context, InputMethodSubtype ims) { final InputMethodInfo myImi = getInputMethodInfoOfThisIme(context); final InputMethodManager imm = getInputMethodManager(context); + // TODO: Cache all subtypes of this IME for optimization final List subtypes = imm.getEnabledInputMethodSubtypeList(myImi, true); for (final InputMethodSubtype subtype : subtypes) { if (subtype.equals(ims)) { diff --git a/java/src/com/android/inputmethod/latin/SubtypeLocale.java b/java/src/com/android/inputmethod/latin/SubtypeLocale.java index d10c42ccd..9f89f9ee1 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeLocale.java +++ b/java/src/com/android/inputmethod/latin/SubtypeLocale.java @@ -33,11 +33,10 @@ public class SubtypeLocale { // Special language code to represent "no language". public static final String NO_LANGUAGE = "zz"; - public static final String QWERTY = "qwerty"; - public static final int UNKNOWN_KEYBOARD_LAYOUT = R.string.subtype_generic; + private static Context sContext; private static String[] sPredefinedKeyboardLayoutSet; // Keyboard layout to its display name map. private static final HashMap sKeyboardKayoutToDisplayNameMap = @@ -58,6 +57,7 @@ public class SubtypeLocale { } public static void init(Context context) { + sContext = context; final Resources res = context.getResources(); final String[] predefinedLayoutSet = res.getStringArray(R.array.predefined_layouts); @@ -128,6 +128,9 @@ public class SubtypeLocale { // zz azerty T No language (AZERTY) public static String getSubtypeDisplayName(InputMethodSubtype subtype, Resources res) { + // TODO: Remove this check when InputMethodManager.getLastInputMethodSubtype is + // fixed. + if (!ImfUtils.checkIfSubtypeBelongsToThisIme(sContext, subtype)) return ""; final String language = getSubtypeLocaleDisplayName(subtype.getLocale()); return res.getString(subtype.getNameResId(), language); }