am bb84fdd1: am bb5deb82: Fix singleton/utility classes initialization in SettingsFragment

* commit 'bb84fdd134e0a5aff268d5d475091e023778655d':
  Fix singleton/utility classes initialization in SettingsFragment
main
Tadashi G. Takaoka 2013-05-15 10:36:14 -07:00 committed by Android Git Automerger
commit 1626830701
2 changed files with 12 additions and 7 deletions

View File

@ -77,12 +77,13 @@ public final class SettingsFragment extends InputMethodSettingsFragment
final Resources res = getResources(); final Resources res = getResources();
final Context context = getActivity(); final Context context = getActivity();
// When we are called from the Settings application but we are not already running, the // When we are called from the Settings application but we are not already running, some
// {@link SubtypeLocale} class may not have been initialized. It is safe to call // singleton and utility classes may not have been initialized. We have to call
// {@link SubtypeLocale#init(Context)} multiple times. // initialization method of these classes here. See {@link LatinIME#onCreate()}.
SubtypeSwitcher.init(context);
SubtypeLocale.init(context); SubtypeLocale.init(context);
// Ditto for {@link AudioAndHapticFeedbackManager} class.
AudioAndHapticFeedbackManager.init(context); AudioAndHapticFeedbackManager.init(context);
mVoicePreference = (ListPreference) findPreference(Settings.PREF_VOICE_MODE); mVoicePreference = (ListPreference) findPreference(Settings.PREF_VOICE_MODE);
mShowCorrectionSuggestionsPreference = mShowCorrectionSuggestionsPreference =
(ListPreference) findPreference(Settings.PREF_SHOW_SUGGESTIONS_SETTING); (ListPreference) findPreference(Settings.PREF_SHOW_SUGGESTIONS_SETTING);

View File

@ -80,6 +80,7 @@ public final class SubtypeSwitcher {
public static void init(final Context context) { public static void init(final Context context) {
SubtypeLocale.init(context); SubtypeLocale.init(context);
RichInputMethodManager.init(context);
sInstance.initialize(context); sInstance.initialize(context);
} }
@ -87,10 +88,13 @@ public final class SubtypeSwitcher {
// Intentional empty constructor for singleton. // Intentional empty constructor for singleton.
} }
private void initialize(final Context service) { private void initialize(final Context context) {
mResources = service.getResources(); if (mResources != null) {
return;
}
mResources = context.getResources();
mRichImm = RichInputMethodManager.getInstance(); mRichImm = RichInputMethodManager.getInstance();
mConnectivityManager = (ConnectivityManager) service.getSystemService( mConnectivityManager = (ConnectivityManager) context.getSystemService(
Context.CONNECTIVITY_SERVICE); Context.CONNECTIVITY_SERVICE);
mNoLanguageSubtype = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( mNoLanguageSubtype = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
SubtypeLocale.NO_LANGUAGE, SubtypeLocale.QWERTY); SubtypeLocale.NO_LANGUAGE, SubtypeLocale.QWERTY);