Merge "Set additional subtypes before getting current subtype"

main
Tadashi G. Takaoka 2012-11-27 22:22:31 -08:00 committed by Android (Google) Code Review
commit 2200dbbf09
6 changed files with 37 additions and 31 deletions

View File

@ -386,12 +386,11 @@ public final class AdditionalSubtypeSettings extends PreferenceFragment {
public void onCreate(final Bundle savedInstanceState) { public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
RichInputMethodManager.init(getActivity()); mPrefs = getPreferenceManager().getSharedPreferences();
RichInputMethodManager.init(getActivity(), mPrefs);
mRichImm = RichInputMethodManager.getInstance(); mRichImm = RichInputMethodManager.getInstance();
addPreferencesFromResource(R.xml.additional_subtype_settings); addPreferencesFromResource(R.xml.additional_subtype_settings);
setHasOptionsMenu(true); setHasOptionsMenu(true);
mPrefs = getPreferenceManager().getSharedPreferences();
} }
@Override @Override

View File

@ -403,33 +403,28 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
@Override @Override
public void onCreate() { public void onCreate() {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
mPrefs = prefs; mResources = getResources();
LatinImeLogger.init(this, prefs);
LatinImeLogger.init(this, mPrefs);
if (ProductionFlag.IS_EXPERIMENTAL) { if (ProductionFlag.IS_EXPERIMENTAL) {
ResearchLogger.getInstance().init(this, prefs); ResearchLogger.getInstance().init(this, mPrefs);
} }
RichInputMethodManager.init(this); RichInputMethodManager.init(this, mPrefs);
mRichImm = RichInputMethodManager.getInstance();
SubtypeSwitcher.init(this); SubtypeSwitcher.init(this);
KeyboardSwitcher.init(this, prefs); KeyboardSwitcher.init(this, mPrefs);
AccessibilityUtils.init(this); AccessibilityUtils.init(this);
super.onCreate(); super.onCreate();
mRichImm = RichInputMethodManager.getInstance();
mHandler.onCreate(); mHandler.onCreate();
DEBUG = LatinImeLogger.sDBG; DEBUG = LatinImeLogger.sDBG;
final Resources res = getResources();
mResources = res;
loadSettings(); loadSettings();
mRichImm.setAdditionalInputMethodSubtypes(mCurrentSettings.getAdditionalSubtypes());
initSuggest(); initSuggest();
mDisplayOrientation = res.getConfiguration().orientation; mDisplayOrientation = mResources.getConfiguration().orientation;
// Register to receive ringer mode change and network state change. // Register to receive ringer mode change and network state change.
// Also receive installation and removal of a dictionary pack. // Also receive installation and removal of a dictionary pack.

View File

@ -19,6 +19,7 @@ package com.android.inputmethod.latin;
import static com.android.inputmethod.latin.Constants.Subtype.KEYBOARD_MODE; import static com.android.inputmethod.latin.Constants.Subtype.KEYBOARD_MODE;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.os.IBinder; import android.os.IBinder;
import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
@ -49,19 +50,34 @@ public final class RichInputMethodManager {
return sInstance; return sInstance;
} }
public static void init(final Context context) { public static void init(final Context context, final SharedPreferences prefs) {
sInstance.initInternal(context); sInstance.initInternal(context, prefs);
}
private boolean isInitialized() {
return mImmWrapper != null;
} }
private void checkInitialized() { private void checkInitialized() {
if (mImmWrapper == null) { if (!isInitialized()) {
throw new RuntimeException(TAG + " is used before initialization"); throw new RuntimeException(TAG + " is used before initialization");
} }
} }
private void initInternal(final Context context) { private void initInternal(final Context context, final SharedPreferences prefs) {
if (isInitialized()) {
return;
}
mImmWrapper = new InputMethodManagerCompatWrapper(context); mImmWrapper = new InputMethodManagerCompatWrapper(context);
mInputMethodInfoOfThisIme = getInputMethodInfoOfThisIme(context); mInputMethodInfoOfThisIme = getInputMethodInfoOfThisIme(context);
// Initialize additional subtypes.
SubtypeLocale.init(context);
final String prefAdditionalSubtypes = SettingsValues.getPrefAdditionalSubtypes(
prefs, context.getResources());
final InputMethodSubtype[] additionalSubtypes =
AdditionalSubtype.createAdditionalSubtypesArray(prefAdditionalSubtypes);
setAdditionalInputMethodSubtypes(additionalSubtypes);
} }
public InputMethodManager getInputMethodManager() { public InputMethodManager getInputMethodManager() {

View File

@ -22,7 +22,6 @@ import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
import android.util.Log; import android.util.Log;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.keyboard.internal.KeySpecParser; import com.android.inputmethod.keyboard.internal.KeySpecParser;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
@ -82,7 +81,6 @@ public final class SettingsValues {
private final int mVibrationDurationSettingsRawValue; private final int mVibrationDurationSettingsRawValue;
@SuppressWarnings("unused") // TODO: Use this @SuppressWarnings("unused") // TODO: Use this
private final float mKeypressSoundVolumeRawValue; private final float mKeypressSoundVolumeRawValue;
private final InputMethodSubtype[] mAdditionalSubtypes;
public final boolean mGestureInputEnabled; public final boolean mGestureInputEnabled;
public final boolean mGesturePreviewTrailEnabled; public final boolean mGesturePreviewTrailEnabled;
public final boolean mGestureFloatingPreviewTextEnabled; public final boolean mGestureFloatingPreviewTextEnabled;
@ -170,8 +168,6 @@ public final class SettingsValues {
mAutoCorrectionThresholdRawValue); mAutoCorrectionThresholdRawValue);
mVoiceKeyEnabled = mVoiceMode != null && !mVoiceMode.equals(voiceModeOff); mVoiceKeyEnabled = mVoiceMode != null && !mVoiceMode.equals(voiceModeOff);
mVoiceKeyOnMain = mVoiceMode != null && mVoiceMode.equals(voiceModeMain); mVoiceKeyOnMain = mVoiceMode != null && mVoiceMode.equals(voiceModeMain);
mAdditionalSubtypes = AdditionalSubtype.createAdditionalSubtypesArray(
getPrefAdditionalSubtypes(prefs, res));
final boolean gestureInputEnabledByBuildConfig = res.getBoolean( final boolean gestureInputEnabledByBuildConfig = res.getBoolean(
R.bool.config_gesture_input_enabled_by_build_config); R.bool.config_gesture_input_enabled_by_build_config);
mGestureInputEnabled = gestureInputEnabledByBuildConfig mGestureInputEnabled = gestureInputEnabledByBuildConfig
@ -375,10 +371,6 @@ public final class SettingsValues {
return res.getBoolean(R.bool.config_use_fullscreen_mode); return res.getBoolean(R.bool.config_use_fullscreen_mode);
} }
public InputMethodSubtype[] getAdditionalSubtypes() {
return mAdditionalSubtypes;
}
public static String getPrefAdditionalSubtypes(final SharedPreferences prefs, public static String getPrefAdditionalSubtypes(final SharedPreferences prefs,
final Resources res) { final Resources res) {
final String predefinedPrefSubtypes = AdditionalSubtype.createPrefSubtypes( final String predefinedPrefSubtypes = AdditionalSubtype.createPrefSubtypes(

View File

@ -18,6 +18,7 @@ package com.android.inputmethod.keyboard;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.preference.PreferenceManager;
import android.test.AndroidTestCase; import android.test.AndroidTestCase;
import android.view.inputmethod.InputMethodSubtype; import android.view.inputmethod.InputMethodSubtype;
@ -41,7 +42,8 @@ public class SpacebarTextTests extends AndroidTestCase {
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
final Context context = getContext(); final Context context = getContext();
RichInputMethodManager.init(context); RichInputMethodManager.init(
context, PreferenceManager.getDefaultSharedPreferences(context));
mRichImm = RichInputMethodManager.getInstance(); mRichImm = RichInputMethodManager.getInstance();
mRes = context.getResources(); mRes = context.getResources();
SubtypeLocale.init(context); SubtypeLocale.init(context);

View File

@ -18,6 +18,7 @@ package com.android.inputmethod.latin;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.preference.PreferenceManager;
import android.test.AndroidTestCase; import android.test.AndroidTestCase;
import android.view.inputmethod.InputMethodSubtype; import android.view.inputmethod.InputMethodSubtype;
@ -37,7 +38,8 @@ public class SubtypeLocaleTests extends AndroidTestCase {
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
final Context context = getContext(); final Context context = getContext();
RichInputMethodManager.init(context); RichInputMethodManager.init(
context, PreferenceManager.getDefaultSharedPreferences(context));
mRichImm = RichInputMethodManager.getInstance(); mRichImm = RichInputMethodManager.getInstance();
mRes = context.getResources(); mRes = context.getResources();
SubtypeLocale.init(context); SubtypeLocale.init(context);