Merge remote-tracking branch 'goog/master' into mergescriptpackage

main
Ken Wakasa 2012-11-12 15:47:29 +09:00
commit 6d05505bbf
11 changed files with 313 additions and 319 deletions

View File

@ -27,7 +27,6 @@
<application android:label="@string/aosp_android_keyboard_ime_name" <application android:label="@string/aosp_android_keyboard_ime_name"
android:icon="@mipmap/ic_ime_settings" android:icon="@mipmap/ic_ime_settings"
android:backupAgent="BackupAgent"
android:killAfterRestore="false" android:killAfterRestore="false"
android:supportsRtl="true"> android:supportsRtl="true">

View File

@ -19,53 +19,21 @@ package com.android.inputmethod.compat;
import android.content.Context; import android.content.Context;
import android.os.IBinder; import android.os.IBinder;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.latin.ImfUtils;
import java.lang.reflect.Method; import java.lang.reflect.Method;
// TODO: Override this class with the concrete implementation if we need to take care of the
// performance.
public final class InputMethodManagerCompatWrapper { public final class InputMethodManagerCompatWrapper {
private static final String TAG = InputMethodManagerCompatWrapper.class.getSimpleName();
private static final Method METHOD_switchToNextInputMethod = CompatUtils.getMethod( private static final Method METHOD_switchToNextInputMethod = CompatUtils.getMethod(
InputMethodManager.class, "switchToNextInputMethod", IBinder.class, Boolean.TYPE); InputMethodManager.class, "switchToNextInputMethod", IBinder.class, Boolean.TYPE);
private static final InputMethodManagerCompatWrapper sInstance = public final InputMethodManager mImm;
new InputMethodManagerCompatWrapper();
private InputMethodManager mImm; public InputMethodManagerCompatWrapper(final Context context) {
mImm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
private InputMethodManagerCompatWrapper() {
// This wrapper class is not publicly instantiable.
} }
public static InputMethodManagerCompatWrapper getInstance() { public boolean switchToNextInputMethod(final IBinder token, final boolean onlyCurrentIme) {
if (sInstance.mImm == null) {
throw new RuntimeException(TAG + ".getInstance() is called before initialization");
}
return sInstance;
}
public static void init(Context context) {
sInstance.mImm = ImfUtils.getInputMethodManager(context);
}
public InputMethodSubtype getLastInputMethodSubtype() {
return mImm.getLastInputMethodSubtype();
}
public boolean switchToLastInputMethod(IBinder token) {
return mImm.switchToLastInputMethod(token);
}
public boolean switchToNextInputMethod(IBinder token, boolean onlyCurrentIme) {
return (Boolean)CompatUtils.invoke(mImm, false, METHOD_switchToNextInputMethod, token, return (Boolean)CompatUtils.invoke(mImm, false, METHOD_switchToNextInputMethod, token,
onlyCurrentIme); onlyCurrentIme);
} }
public void showInputMethodPicker() {
mImm.showInputMethodPicker();
}
} }

View File

@ -30,11 +30,11 @@ import com.android.inputmethod.keyboard.KeyboardLayoutSet.KeyboardLayoutSetExcep
import com.android.inputmethod.keyboard.PointerTracker.TimerProxy; import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
import com.android.inputmethod.keyboard.internal.KeyboardState; import com.android.inputmethod.keyboard.internal.KeyboardState;
import com.android.inputmethod.latin.AudioAndHapticFeedbackManager; import com.android.inputmethod.latin.AudioAndHapticFeedbackManager;
import com.android.inputmethod.latin.ImfUtils;
import com.android.inputmethod.latin.InputView; import com.android.inputmethod.latin.InputView;
import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinIME;
import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.RichInputMethodManager;
import com.android.inputmethod.latin.SettingsValues; import com.android.inputmethod.latin.SettingsValues;
import com.android.inputmethod.latin.SubtypeSwitcher; import com.android.inputmethod.latin.SubtypeSwitcher;
import com.android.inputmethod.latin.WordComposer; import com.android.inputmethod.latin.WordComposer;
@ -142,7 +142,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
builder.setOptions( builder.setOptions(
settingsValues.isVoiceKeyEnabled(editorInfo), settingsValues.isVoiceKeyEnabled(editorInfo),
settingsValues.isVoiceKeyOnMain(), settingsValues.isVoiceKeyOnMain(),
settingsValues.isLanguageSwitchKeyEnabled(mThemeContext)); settingsValues.isLanguageSwitchKeyEnabled());
mKeyboardLayoutSet = builder.build(); mKeyboardLayoutSet = builder.build();
try { try {
mState.onLoadKeyboard(mResources.getString(R.string.layout_switch_back_symbols)); mState.onLoadKeyboard(mResources.getString(R.string.layout_switch_back_symbols));
@ -187,7 +187,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
final boolean needsToDisplayLanguage = mSubtypeSwitcher.needsToDisplayLanguage( final boolean needsToDisplayLanguage = mSubtypeSwitcher.needsToDisplayLanguage(
keyboard.mId.mLocale); keyboard.mId.mLocale);
keyboardView.startDisplayLanguageOnSpacebar(subtypeChanged, needsToDisplayLanguage, keyboardView.startDisplayLanguageOnSpacebar(subtypeChanged, needsToDisplayLanguage,
ImfUtils.hasMultipleEnabledIMEsOrSubtypes(mLatinIME, true)); RichInputMethodManager.getInstance().hasMultipleEnabledIMEsOrSubtypes(true));
} }
public Keyboard getKeyboard() { public Keyboard getKeyboard() {

View File

@ -50,6 +50,7 @@ import java.util.ArrayList;
import java.util.TreeSet; import java.util.TreeSet;
public final class AdditionalSubtypeSettings extends PreferenceFragment { public final class AdditionalSubtypeSettings extends PreferenceFragment {
private RichInputMethodManager mRichImm;
private SharedPreferences mPrefs; private SharedPreferences mPrefs;
private SubtypeLocaleAdapter mSubtypeLocaleAdapter; private SubtypeLocaleAdapter mSubtypeLocaleAdapter;
private KeyboardLayoutSetAdapter mKeyboardLayoutSetAdapter; private KeyboardLayoutSetAdapter mKeyboardLayoutSetAdapter;
@ -63,6 +64,7 @@ public final class AdditionalSubtypeSettings extends PreferenceFragment {
private static final String KEY_IS_SUBTYPE_ENABLER_NOTIFICATION_DIALOG_OPEN = private static final String KEY_IS_SUBTYPE_ENABLER_NOTIFICATION_DIALOG_OPEN =
"is_subtype_enabler_notification_dialog_open"; "is_subtype_enabler_notification_dialog_open";
private static final String KEY_SUBTYPE_FOR_SUBTYPE_ENABLER = "subtype_for_subtype_enabler"; private static final String KEY_SUBTYPE_FOR_SUBTYPE_ENABLER = "subtype_for_subtype_enabler";
static final class SubtypeLocaleItem extends Pair<String, String> static final class SubtypeLocaleItem extends Pair<String, String>
implements Comparable<SubtypeLocaleItem> { implements Comparable<SubtypeLocaleItem> {
public SubtypeLocaleItem(final String localeString, final String displayName) { public SubtypeLocaleItem(final String localeString, final String displayName) {
@ -90,7 +92,8 @@ public final class AdditionalSubtypeSettings extends PreferenceFragment {
setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
final TreeSet<SubtypeLocaleItem> items = CollectionUtils.newTreeSet(); final TreeSet<SubtypeLocaleItem> items = CollectionUtils.newTreeSet();
final InputMethodInfo imi = ImfUtils.getInputMethodInfoOfThisIme(context); final InputMethodInfo imi = RichInputMethodManager.getInstance()
.getInputMethodInfoOfThisIme();
final int count = imi.getSubtypeCount(); final int count = imi.getSubtypeCount();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
final InputMethodSubtype subtype = imi.getSubtypeAt(i); final InputMethodSubtype subtype = imi.getSubtypeAt(i);
@ -375,6 +378,8 @@ 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());
mRichImm = RichInputMethodManager.getInstance();
addPreferencesFromResource(R.xml.additional_subtype_settings); addPreferencesFromResource(R.xml.additional_subtype_settings);
setHasOptionsMenu(true); setHasOptionsMenu(true);
@ -431,7 +436,7 @@ public final class AdditionalSubtypeSettings extends PreferenceFragment {
mIsAddingNewSubtype = false; mIsAddingNewSubtype = false;
final PreferenceGroup group = getPreferenceScreen(); final PreferenceGroup group = getPreferenceScreen();
group.removePreference(subtypePref); group.removePreference(subtypePref);
ImfUtils.setAdditionalInputMethodSubtypes(getActivity(), getSubtypes()); mRichImm.setAdditionalInputMethodSubtypes(getSubtypes());
} }
@Override @Override
@ -441,7 +446,7 @@ public final class AdditionalSubtypeSettings extends PreferenceFragment {
return; return;
} }
if (findDuplicatedSubtype(subtype) == null) { if (findDuplicatedSubtype(subtype) == null) {
ImfUtils.setAdditionalInputMethodSubtypes(getActivity(), getSubtypes()); mRichImm.setAdditionalInputMethodSubtypes(getSubtypes());
return; return;
} }
@ -458,7 +463,7 @@ public final class AdditionalSubtypeSettings extends PreferenceFragment {
mIsAddingNewSubtype = false; mIsAddingNewSubtype = false;
final InputMethodSubtype subtype = subtypePref.getSubtype(); final InputMethodSubtype subtype = subtypePref.getSubtype();
if (findDuplicatedSubtype(subtype) == null) { if (findDuplicatedSubtype(subtype) == null) {
ImfUtils.setAdditionalInputMethodSubtypes(getActivity(), getSubtypes()); mRichImm.setAdditionalInputMethodSubtypes(getSubtypes());
mSubtypePreferenceKeyForSubtypeEnabler = subtypePref.getKey(); mSubtypePreferenceKeyForSubtypeEnabler = subtypePref.getKey();
mSubtypeEnablerNotificationDialog = createDialog(subtypePref); mSubtypeEnablerNotificationDialog = createDialog(subtypePref);
mSubtypeEnablerNotificationDialog.show(); mSubtypeEnablerNotificationDialog.show();
@ -493,8 +498,8 @@ public final class AdditionalSubtypeSettings extends PreferenceFragment {
private InputMethodSubtype findDuplicatedSubtype(final InputMethodSubtype subtype) { private InputMethodSubtype findDuplicatedSubtype(final InputMethodSubtype subtype) {
final String localeString = subtype.getLocale(); final String localeString = subtype.getLocale();
final String keyboardLayoutSetName = SubtypeLocale.getKeyboardLayoutSetName(subtype); final String keyboardLayoutSetName = SubtypeLocale.getKeyboardLayoutSetName(subtype);
return ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet( return mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
getActivity(), localeString, keyboardLayoutSetName); localeString, keyboardLayoutSetName);
} }
private AlertDialog createDialog( private AlertDialog createDialog(
@ -507,7 +512,7 @@ public final class AdditionalSubtypeSettings extends PreferenceFragment {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
final Intent intent = CompatUtils.getInputLanguageSelectionIntent( final Intent intent = CompatUtils.getInputLanguageSelectionIntent(
ImfUtils.getInputMethodIdOfThisIme(getActivity()), mRichImm.getInputMethodIdOfThisIme(),
Intent.FLAG_ACTIVITY_NEW_TASK Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
| Intent.FLAG_ACTIVITY_CLEAR_TOP); | Intent.FLAG_ACTIVITY_CLEAR_TOP);
@ -565,7 +570,7 @@ public final class AdditionalSubtypeSettings extends PreferenceFragment {
} finally { } finally {
editor.apply(); editor.apply();
} }
ImfUtils.setAdditionalInputMethodSubtypes(getActivity(), subtypes); mRichImm.setAdditionalInputMethodSubtypes(subtypes);
} }
@Override @Override

View File

@ -1,186 +0,0 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.inputmethod.latin;
import static com.android.inputmethod.latin.Constants.Subtype.KEYBOARD_MODE;
import android.content.Context;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.InputMethodSubtype;
import java.util.Collections;
import java.util.List;
/**
* Utility class for Input Method Framework
*/
public final class ImfUtils {
private ImfUtils() {
// This utility class is not publicly instantiable.
}
private static InputMethodManager sInputMethodManager;
public static InputMethodManager getInputMethodManager(Context context) {
if (sInputMethodManager == null) {
sInputMethodManager = (InputMethodManager)context.getSystemService(
Context.INPUT_METHOD_SERVICE);
}
return sInputMethodManager;
}
private static InputMethodInfo sInputMethodInfoOfThisIme;
public static InputMethodInfo getInputMethodInfoOfThisIme(Context context) {
if (sInputMethodInfoOfThisIme == null) {
final InputMethodManager imm = getInputMethodManager(context);
final String packageName = context.getPackageName();
for (final InputMethodInfo imi : imm.getInputMethodList()) {
if (imi.getPackageName().equals(packageName))
return imi;
}
throw new RuntimeException("Can not find input method id for " + packageName);
}
return sInputMethodInfoOfThisIme;
}
public static String getInputMethodIdOfThisIme(Context context) {
return getInputMethodInfoOfThisIme(context).getId();
}
public static boolean checkIfSubtypeBelongsToThisImeAndEnabled(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<InputMethodSubtype> subtypes = imm.getEnabledInputMethodSubtypeList(myImi, true);
for (final InputMethodSubtype subtype : subtypes) {
if (subtype.equals(ims)) {
return true;
}
}
return false;
}
public static boolean checkIfSubtypeBelongsToThisIme(Context context,
InputMethodSubtype ims) {
final InputMethodInfo myImi = getInputMethodInfoOfThisIme(context);
final int count = myImi.getSubtypeCount();
for (int i = 0; i < count; i++) {
final InputMethodSubtype subtype = myImi.getSubtypeAt(i);
if (subtype.equals(ims)) {
return true;
}
}
return false;
}
public static InputMethodSubtype getCurrentInputMethodSubtype(Context context,
InputMethodSubtype defaultSubtype) {
final InputMethodManager imm = getInputMethodManager(context);
final InputMethodSubtype currentSubtype = imm.getCurrentInputMethodSubtype();
return (currentSubtype != null) ? currentSubtype : defaultSubtype;
}
public static boolean hasMultipleEnabledIMEsOrSubtypes(Context context,
final boolean shouldIncludeAuxiliarySubtypes) {
final InputMethodManager imm = getInputMethodManager(context);
final List<InputMethodInfo> enabledImis = imm.getEnabledInputMethodList();
return hasMultipleEnabledSubtypes(context, shouldIncludeAuxiliarySubtypes, enabledImis);
}
public static boolean hasMultipleEnabledSubtypesInThisIme(Context context,
final boolean shouldIncludeAuxiliarySubtypes) {
final InputMethodInfo myImi = getInputMethodInfoOfThisIme(context);
final List<InputMethodInfo> imiList = Collections.singletonList(myImi);
return hasMultipleEnabledSubtypes(context, shouldIncludeAuxiliarySubtypes, imiList);
}
private static boolean hasMultipleEnabledSubtypes(Context context,
final boolean shouldIncludeAuxiliarySubtypes, List<InputMethodInfo> imiList) {
final InputMethodManager imm = getInputMethodManager(context);
// Number of the filtered IMEs
int filteredImisCount = 0;
for (InputMethodInfo imi : imiList) {
// We can return true immediately after we find two or more filtered IMEs.
if (filteredImisCount > 1) return true;
final List<InputMethodSubtype> subtypes =
imm.getEnabledInputMethodSubtypeList(imi, true);
// IMEs that have no subtypes should be counted.
if (subtypes.isEmpty()) {
++filteredImisCount;
continue;
}
int auxCount = 0;
for (InputMethodSubtype subtype : subtypes) {
if (subtype.isAuxiliary()) {
++auxCount;
}
}
final int nonAuxCount = subtypes.size() - auxCount;
// IMEs that have one or more non-auxiliary subtypes should be counted.
// If shouldIncludeAuxiliarySubtypes is true, IMEs that have two or more auxiliary
// subtypes should be counted as well.
if (nonAuxCount > 0 || (shouldIncludeAuxiliarySubtypes && auxCount > 1)) {
++filteredImisCount;
continue;
}
}
if (filteredImisCount > 1) {
return true;
}
final List<InputMethodSubtype> subtypes = imm.getEnabledInputMethodSubtypeList(null, true);
int keyboardCount = 0;
// imm.getEnabledInputMethodSubtypeList(null, true) will return the current IME's
// both explicitly and implicitly enabled input method subtype.
// (The current IME should be LatinIME.)
for (InputMethodSubtype subtype : subtypes) {
if (KEYBOARD_MODE.equals(subtype.getMode())) {
++keyboardCount;
}
}
return keyboardCount > 1;
}
public static InputMethodSubtype findSubtypeByLocaleAndKeyboardLayoutSet(
Context context, String localeString, String keyboardLayoutSetName) {
final InputMethodInfo imi = getInputMethodInfoOfThisIme(context);
final int count = imi.getSubtypeCount();
for (int i = 0; i < count; i++) {
final InputMethodSubtype subtype = imi.getSubtypeAt(i);
final String layoutName = SubtypeLocale.getKeyboardLayoutSetName(subtype);
if (localeString.equals(subtype.getLocale())
&& keyboardLayoutSetName.equals(layoutName)) {
return subtype;
}
}
return null;
}
public static void setAdditionalInputMethodSubtypes(Context context,
InputMethodSubtype[] subtypes) {
final InputMethodManager imm = getInputMethodManager(context);
final String imiId = getInputMethodIdOfThisIme(context);
imm.setAdditionalInputMethodSubtypes(imiId, subtypes);
}
}

View File

@ -56,13 +56,13 @@ import android.view.WindowManager;
import android.view.inputmethod.CompletionInfo; import android.view.inputmethod.CompletionInfo;
import android.view.inputmethod.CorrectionInfo; import android.view.inputmethod.CorrectionInfo;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.InputMethodSubtype; import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.accessibility.AccessibilityUtils; import com.android.inputmethod.accessibility.AccessibilityUtils;
import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy; import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.compat.CompatUtils; import com.android.inputmethod.compat.CompatUtils;
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
import com.android.inputmethod.compat.InputMethodServiceCompatUtils; import com.android.inputmethod.compat.InputMethodServiceCompatUtils;
import com.android.inputmethod.compat.SuggestionSpanUtils; import com.android.inputmethod.compat.SuggestionSpanUtils;
import com.android.inputmethod.keyboard.KeyDetector; import com.android.inputmethod.keyboard.KeyDetector;
@ -137,7 +137,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
private CompletionInfo[] mApplicationSpecifiedCompletions; private CompletionInfo[] mApplicationSpecifiedCompletions;
private ApplicationInfo mTargetApplicationInfo; private ApplicationInfo mTargetApplicationInfo;
private InputMethodManagerCompatWrapper mImm; private RichInputMethodManager mRichImm;
private Resources mResources; private Resources mResources;
private SharedPreferences mPrefs; private SharedPreferences mPrefs;
@UsedForTesting final KeyboardSwitcher mKeyboardSwitcher; @UsedForTesting final KeyboardSwitcher mKeyboardSwitcher;
@ -383,14 +383,14 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
if (ProductionFlag.IS_EXPERIMENTAL) { if (ProductionFlag.IS_EXPERIMENTAL) {
ResearchLogger.getInstance().init(this, prefs); ResearchLogger.getInstance().init(this, prefs);
} }
InputMethodManagerCompatWrapper.init(this); RichInputMethodManager.init(this);
SubtypeSwitcher.init(this); SubtypeSwitcher.init(this);
KeyboardSwitcher.init(this, prefs); KeyboardSwitcher.init(this, prefs);
AccessibilityUtils.init(this); AccessibilityUtils.init(this);
super.onCreate(); super.onCreate();
mImm = InputMethodManagerCompatWrapper.getInstance(); mRichImm = RichInputMethodManager.getInstance();
mHandler.onCreate(); mHandler.onCreate();
DEBUG = LatinImeLogger.sDBG; DEBUG = LatinImeLogger.sDBG;
@ -399,7 +399,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
loadSettings(); loadSettings();
ImfUtils.setAdditionalInputMethodSubtypes(this, mCurrentSettings.getAdditionalSubtypes()); mRichImm.setAdditionalInputMethodSubtypes(mCurrentSettings.getAdditionalSubtypes());
initSuggest(); initSuggest();
@ -556,7 +556,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
@Override @Override
public void onConfigurationChanged(final Configuration conf) { public void onConfigurationChanged(final Configuration conf) {
// System locale has been changed. Needs to reload keyboard. // System locale has been changed. Needs to reload keyboard.
if (mSubtypeSwitcher.onConfigurationChanged(conf, this)) { if (mSubtypeSwitcher.onConfigurationChanged(conf)) {
loadKeyboard(); loadKeyboard();
} }
// If orientation changed while predicting, commit the change // If orientation changed while predicting, commit the change
@ -698,8 +698,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
.updateParametersOnStartInputViewAndReturnIfCurrentSubtypeEnabled(); .updateParametersOnStartInputViewAndReturnIfCurrentSubtypeEnabled();
if (!currentSubtypeEnabled) { if (!currentSubtypeEnabled) {
// Current subtype is disabled. Needs to update subtype and keyboard. // Current subtype is disabled. Needs to update subtype and keyboard.
final InputMethodSubtype newSubtype = ImfUtils.getCurrentInputMethodSubtype( final InputMethodSubtype newSubtype = mRichImm.getCurrentInputMethodSubtype(
this, mSubtypeSwitcher.getNoLanguageSubtype()); mSubtypeSwitcher.getNoLanguageSubtype());
mSubtypeSwitcher.updateSubtype(newSubtype); mSubtypeSwitcher.updateSubtype(newSubtype);
loadKeyboard(); loadKeyboard();
} }
@ -1216,9 +1216,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
if (isShowingOptionDialog()) return false; if (isShowingOptionDialog()) return false;
switch (requestCode) { switch (requestCode) {
case CODE_SHOW_INPUT_METHOD_PICKER: case CODE_SHOW_INPUT_METHOD_PICKER:
if (ImfUtils.hasMultipleEnabledIMEsOrSubtypes( if (mRichImm.hasMultipleEnabledIMEsOrSubtypes(true /* include aux subtypes */)) {
this, true /* include aux subtypes */)) { mRichImm.getInputMethodManager().showInputMethodPicker();
mImm.showInputMethodPicker();
return true; return true;
} }
return false; return false;
@ -1242,21 +1241,22 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
private void handleLanguageSwitchKey() { private void handleLanguageSwitchKey() {
final IBinder token = getWindow().getWindow().getAttributes().token; final IBinder token = getWindow().getWindow().getAttributes().token;
if (mCurrentSettings.mIncludesOtherImesInLanguageSwitchList) { if (mCurrentSettings.mIncludesOtherImesInLanguageSwitchList) {
mImm.switchToNextInputMethod(token, false /* onlyCurrentIme */); mRichImm.switchToNextInputMethod(token, false /* onlyCurrentIme */);
return; return;
} }
if (mShouldSwitchToLastSubtype) { if (mShouldSwitchToLastSubtype) {
final InputMethodSubtype lastSubtype = mImm.getLastInputMethodSubtype(); final InputMethodManager imm = mRichImm.getInputMethodManager();
final InputMethodSubtype lastSubtype = imm.getLastInputMethodSubtype();
final boolean lastSubtypeBelongsToThisIme = final boolean lastSubtypeBelongsToThisIme =
ImfUtils.checkIfSubtypeBelongsToThisImeAndEnabled(this, lastSubtype); mRichImm.checkIfSubtypeBelongsToThisImeAndEnabled(lastSubtype);
if (lastSubtypeBelongsToThisIme && mImm.switchToLastInputMethod(token)) { if (lastSubtypeBelongsToThisIme && imm.switchToLastInputMethod(token)) {
mShouldSwitchToLastSubtype = false; mShouldSwitchToLastSubtype = false;
} else { } else {
mImm.switchToNextInputMethod(token, true /* onlyCurrentIme */); mRichImm.switchToNextInputMethod(token, true /* onlyCurrentIme */);
mShouldSwitchToLastSubtype = true; mShouldSwitchToLastSubtype = true;
} }
} else { } else {
mImm.switchToNextInputMethod(token, true /* onlyCurrentIme */); mRichImm.switchToNextInputMethod(token, true /* onlyCurrentIme */);
} }
} }
@ -2352,7 +2352,6 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
getString(R.string.language_selection_title), getString(R.string.language_selection_title),
getString(R.string.english_ime_settings), getString(R.string.english_ime_settings),
}; };
final Context context = this;
final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface di, int position) { public void onClick(DialogInterface di, int position) {
@ -2360,7 +2359,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
switch (position) { switch (position) {
case 0: case 0:
Intent intent = CompatUtils.getInputLanguageSelectionIntent( Intent intent = CompatUtils.getInputLanguageSelectionIntent(
ImfUtils.getInputMethodIdOfThisIme(context), mRichImm.getInputMethodIdOfThisIme(),
Intent.FLAG_ACTIVITY_NEW_TASK Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
| Intent.FLAG_ACTIVITY_CLEAR_TOP); | Intent.FLAG_ACTIVITY_CLEAR_TOP);

View File

@ -0,0 +1,213 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.inputmethod.latin;
import static com.android.inputmethod.latin.Constants.Subtype.KEYBOARD_MODE;
import android.content.Context;
import android.os.IBinder;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
import java.util.Collections;
import java.util.List;
/**
* Enrichment class for InputMethodManager to simplify interaction and add functionality.
*/
public final class RichInputMethodManager {
private static final String TAG = RichInputMethodManager.class.getSimpleName();
private RichInputMethodManager() {
// This utility class is not publicly instantiable.
}
private static final RichInputMethodManager sInstance = new RichInputMethodManager();
private InputMethodManagerCompatWrapper mImmWrapper;
private InputMethodInfo mInputMethodInfoOfThisIme;
public static RichInputMethodManager getInstance() {
sInstance.checkInitialized();
return sInstance;
}
public static void init(final Context context) {
sInstance.initInternal(context);
}
private void checkInitialized() {
if (mImmWrapper == null) {
throw new RuntimeException(TAG + " is used before initialization");
}
}
private void initInternal(final Context context) {
mImmWrapper = new InputMethodManagerCompatWrapper(context);
mInputMethodInfoOfThisIme = getInputMethodInfoOfThisIme(context);
}
public InputMethodManager getInputMethodManager() {
checkInitialized();
return mImmWrapper.mImm;
}
private InputMethodInfo getInputMethodInfoOfThisIme(final Context context) {
final String packageName = context.getPackageName();
for (final InputMethodInfo imi : mImmWrapper.mImm.getInputMethodList()) {
if (imi.getPackageName().equals(packageName)) {
return imi;
}
}
throw new RuntimeException("Input method id for " + packageName + " not found.");
}
public boolean switchToNextInputMethod(final IBinder token, final boolean onlyCurrentIme) {
final boolean result = mImmWrapper.switchToNextInputMethod(token, onlyCurrentIme);
if (!result) {
mImmWrapper.mImm.switchToLastInputMethod(token);
return false;
}
return true;
}
public InputMethodInfo getInputMethodInfoOfThisIme() {
return mInputMethodInfoOfThisIme;
}
public String getInputMethodIdOfThisIme() {
return mInputMethodInfoOfThisIme.getId();
}
public boolean checkIfSubtypeBelongsToThisImeAndEnabled(final InputMethodSubtype ims) {
return checkIfSubtypeBelongsToImeAndEnabled(mInputMethodInfoOfThisIme, ims);
}
public boolean checkIfSubtypeBelongsToImeAndEnabled(final InputMethodInfo imi,
final InputMethodSubtype ims) {
final List<InputMethodSubtype> subtypes = mImmWrapper.mImm.getEnabledInputMethodSubtypeList(
imi, true /* allowsImplicitlySelectedSubtypes */);
for (final InputMethodSubtype subtype : subtypes) {
if (subtype.equals(ims)) {
return true;
}
}
return false;
}
public boolean checkIfSubtypeBelongsToThisIme(final InputMethodSubtype ims) {
final InputMethodInfo myImi = mInputMethodInfoOfThisIme;
final int count = myImi.getSubtypeCount();
for (int i = 0; i < count; i++) {
final InputMethodSubtype subtype = myImi.getSubtypeAt(i);
if (subtype.equals(ims)) {
return true;
}
}
return false;
}
public InputMethodSubtype getCurrentInputMethodSubtype(
final InputMethodSubtype defaultSubtype) {
final InputMethodSubtype currentSubtype = mImmWrapper.mImm.getCurrentInputMethodSubtype();
return (currentSubtype != null) ? currentSubtype : defaultSubtype;
}
public boolean hasMultipleEnabledIMEsOrSubtypes(final boolean shouldIncludeAuxiliarySubtypes) {
final List<InputMethodInfo> enabledImis = mImmWrapper.mImm.getEnabledInputMethodList();
return hasMultipleEnabledSubtypes(shouldIncludeAuxiliarySubtypes, enabledImis);
}
public boolean hasMultipleEnabledSubtypesInThisIme(
final boolean shouldIncludeAuxiliarySubtypes) {
final List<InputMethodInfo> imiList = Collections.singletonList(mInputMethodInfoOfThisIme);
return hasMultipleEnabledSubtypes(shouldIncludeAuxiliarySubtypes, imiList);
}
private boolean hasMultipleEnabledSubtypes(final boolean shouldIncludeAuxiliarySubtypes,
final List<InputMethodInfo> imiList) {
// Number of the filtered IMEs
int filteredImisCount = 0;
for (InputMethodInfo imi : imiList) {
// We can return true immediately after we find two or more filtered IMEs.
if (filteredImisCount > 1) return true;
final List<InputMethodSubtype> subtypes =
mImmWrapper.mImm.getEnabledInputMethodSubtypeList(imi, true);
// IMEs that have no subtypes should be counted.
if (subtypes.isEmpty()) {
++filteredImisCount;
continue;
}
int auxCount = 0;
for (InputMethodSubtype subtype : subtypes) {
if (subtype.isAuxiliary()) {
++auxCount;
}
}
final int nonAuxCount = subtypes.size() - auxCount;
// IMEs that have one or more non-auxiliary subtypes should be counted.
// If shouldIncludeAuxiliarySubtypes is true, IMEs that have two or more auxiliary
// subtypes should be counted as well.
if (nonAuxCount > 0 || (shouldIncludeAuxiliarySubtypes && auxCount > 1)) {
++filteredImisCount;
continue;
}
}
if (filteredImisCount > 1) {
return true;
}
final List<InputMethodSubtype> subtypes =
mImmWrapper.mImm.getEnabledInputMethodSubtypeList(null, true);
int keyboardCount = 0;
// imm.getEnabledInputMethodSubtypeList(null, true) will return the current IME's
// both explicitly and implicitly enabled input method subtype.
// (The current IME should be LatinIME.)
for (InputMethodSubtype subtype : subtypes) {
if (KEYBOARD_MODE.equals(subtype.getMode())) {
++keyboardCount;
}
}
return keyboardCount > 1;
}
public InputMethodSubtype findSubtypeByLocaleAndKeyboardLayoutSet(final String localeString,
final String keyboardLayoutSetName) {
final InputMethodInfo myImi = mInputMethodInfoOfThisIme;
final int count = myImi.getSubtypeCount();
for (int i = 0; i < count; i++) {
final InputMethodSubtype subtype = myImi.getSubtypeAt(i);
final String layoutName = SubtypeLocale.getKeyboardLayoutSetName(subtype);
if (localeString.equals(subtype.getLocale())
&& keyboardLayoutSetName.equals(layoutName)) {
return subtype;
}
}
return null;
}
public void setAdditionalInputMethodSubtypes(final InputMethodSubtype[] subtypes) {
mImmWrapper.mImm.setAdditionalInputMethodSubtypes(
mInputMethodInfoOfThisIme.getId(), subtypes);
}
}

View File

@ -355,16 +355,15 @@ public final class SettingsValues {
return prefs.getBoolean(Settings.PREF_SHOW_LANGUAGE_SWITCH_KEY, true); return prefs.getBoolean(Settings.PREF_SHOW_LANGUAGE_SWITCH_KEY, true);
} }
public boolean isLanguageSwitchKeyEnabled(final Context context) { public boolean isLanguageSwitchKeyEnabled() {
if (!mShowsLanguageSwitchKey) { if (!mShowsLanguageSwitchKey) {
return false; return false;
} }
final RichInputMethodManager imm = RichInputMethodManager.getInstance();
if (mIncludesOtherImesInLanguageSwitchList) { if (mIncludesOtherImesInLanguageSwitchList) {
return ImfUtils.hasMultipleEnabledIMEsOrSubtypes( return imm.hasMultipleEnabledIMEsOrSubtypes(false /* include aux subtypes */);
context, /* include aux subtypes */false);
} else { } else {
return ImfUtils.hasMultipleEnabledSubtypesInThisIme( return imm.hasMultipleEnabledSubtypesInThisIme(false /* include aux subtypes */);
context, /* include aux subtypes */false);
} }
} }

View File

@ -43,7 +43,7 @@ public final class SubtypeSwitcher {
private static final String TAG = SubtypeSwitcher.class.getSimpleName(); private static final String TAG = SubtypeSwitcher.class.getSimpleName();
private static final SubtypeSwitcher sInstance = new SubtypeSwitcher(); private static final SubtypeSwitcher sInstance = new SubtypeSwitcher();
private /* final */ InputMethodManager mImm; private /* final */ RichInputMethodManager mRichImm;
private /* final */ Resources mResources; private /* final */ Resources mResources;
private /* final */ ConnectivityManager mConnectivityManager; private /* final */ ConnectivityManager mConnectivityManager;
@ -84,7 +84,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);
sInstance.initialize(context); sInstance.initialize(context);
sInstance.updateAllParameters(context); sInstance.updateAllParameters();
} }
private SubtypeSwitcher() { private SubtypeSwitcher() {
@ -93,13 +93,13 @@ public final class SubtypeSwitcher {
private void initialize(final Context service) { private void initialize(final Context service) {
mResources = service.getResources(); mResources = service.getResources();
mImm = ImfUtils.getInputMethodManager(service); mRichImm = RichInputMethodManager.getInstance();
mConnectivityManager = (ConnectivityManager) service.getSystemService( mConnectivityManager = (ConnectivityManager) service.getSystemService(
Context.CONNECTIVITY_SERVICE); Context.CONNECTIVITY_SERVICE);
mCurrentSystemLocale = mResources.getConfiguration().locale; mCurrentSystemLocale = mResources.getConfiguration().locale;
mNoLanguageSubtype = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet( mNoLanguageSubtype = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
service, SubtypeLocale.NO_LANGUAGE, SubtypeLocale.QWERTY); SubtypeLocale.NO_LANGUAGE, SubtypeLocale.QWERTY);
mCurrentSubtype = ImfUtils.getCurrentInputMethodSubtype(service, mNoLanguageSubtype); mCurrentSubtype = mRichImm.getCurrentInputMethodSubtype(mNoLanguageSubtype);
if (mNoLanguageSubtype == null) { if (mNoLanguageSubtype == null) {
throw new RuntimeException("Can't find no lanugage with QWERTY subtype"); throw new RuntimeException("Can't find no lanugage with QWERTY subtype");
} }
@ -110,9 +110,9 @@ public final class SubtypeSwitcher {
// Update all parameters stored in SubtypeSwitcher. // Update all parameters stored in SubtypeSwitcher.
// Only configuration changed event is allowed to call this because this is heavy. // Only configuration changed event is allowed to call this because this is heavy.
private void updateAllParameters(final Context context) { private void updateAllParameters() {
mCurrentSystemLocale = mResources.getConfiguration().locale; mCurrentSystemLocale = mResources.getConfiguration().locale;
updateSubtype(ImfUtils.getCurrentInputMethodSubtype(context, mNoLanguageSubtype)); updateSubtype(mRichImm.getCurrentInputMethodSubtype(mNoLanguageSubtype));
updateParametersOnStartInputViewAndReturnIfCurrentSubtypeEnabled(); updateParametersOnStartInputViewAndReturnIfCurrentSubtypeEnabled();
} }
@ -137,7 +137,7 @@ public final class SubtypeSwitcher {
*/ */
private boolean updateEnabledSubtypesAndReturnIfEnabled(final InputMethodSubtype subtype) { private boolean updateEnabledSubtypesAndReturnIfEnabled(final InputMethodSubtype subtype) {
final List<InputMethodSubtype> enabledSubtypesOfThisIme = final List<InputMethodSubtype> enabledSubtypesOfThisIme =
mImm.getEnabledInputMethodSubtypeList(null, true); mRichImm.getInputMethodManager().getEnabledInputMethodSubtypeList(null, true);
mNeedsToDisplayLanguage.updateEnabledSubtypeCount(enabledSubtypesOfThisIme.size()); mNeedsToDisplayLanguage.updateEnabledSubtypeCount(enabledSubtypesOfThisIme.size());
for (final InputMethodSubtype ims : enabledSubtypesOfThisIme) { for (final InputMethodSubtype ims : enabledSubtypesOfThisIme) {
@ -162,7 +162,7 @@ public final class SubtypeSwitcher {
} }
// TODO: Update an icon for shortcut IME // TODO: Update an icon for shortcut IME
final Map<InputMethodInfo, List<InputMethodSubtype>> shortcuts = final Map<InputMethodInfo, List<InputMethodSubtype>> shortcuts =
mImm.getShortcutInputMethodsAndSubtypes(); mRichImm.getInputMethodManager().getShortcutInputMethodsAndSubtypes();
mShortcutInputMethodInfo = null; mShortcutInputMethodInfo = null;
mShortcutSubtype = null; mShortcutSubtype = null;
for (final InputMethodInfo imi : shortcuts.keySet()) { for (final InputMethodInfo imi : shortcuts.keySet()) {
@ -221,7 +221,7 @@ public final class SubtypeSwitcher {
if (token == null) { if (token == null) {
return; return;
} }
final InputMethodManager imm = mImm; final InputMethodManager imm = mRichImm.getInputMethodManager();
new AsyncTask<Void, Void, Void>() { new AsyncTask<Void, Void, Void>() {
@Override @Override
protected Void doInBackground(Void... params) { protected Void doInBackground(Void... params) {
@ -238,14 +238,8 @@ public final class SubtypeSwitcher {
if (mShortcutSubtype == null) { if (mShortcutSubtype == null) {
return true; return true;
} }
final boolean allowsImplicitlySelectedSubtypes = true; return mRichImm.checkIfSubtypeBelongsToImeAndEnabled(
for (final InputMethodSubtype enabledSubtype : mImm.getEnabledInputMethodSubtypeList( mShortcutInputMethodInfo, mShortcutSubtype);
mShortcutInputMethodInfo, allowsImplicitlySelectedSubtypes)) {
if (enabledSubtype.equals(mShortcutSubtype)) {
return true;
}
}
return false;
} }
public boolean isShortcutImeReady() { public boolean isShortcutImeReady() {
@ -285,12 +279,12 @@ public final class SubtypeSwitcher {
return SubtypeLocale.getSubtypeLocale(mCurrentSubtype); return SubtypeLocale.getSubtypeLocale(mCurrentSubtype);
} }
public boolean onConfigurationChanged(final Configuration conf, final Context context) { public boolean onConfigurationChanged(final Configuration conf) {
final Locale systemLocale = conf.locale; final Locale systemLocale = conf.locale;
final boolean systemLocaleChanged = !systemLocale.equals(mCurrentSystemLocale); final boolean systemLocaleChanged = !systemLocale.equals(mCurrentSystemLocale);
// If system configuration was changed, update all parameters. // If system configuration was changed, update all parameters.
if (systemLocaleChanged) { if (systemLocaleChanged) {
updateAllParameters(context); updateAllParameters();
} }
return systemLocaleChanged; return systemLocaleChanged;
} }

View File

@ -23,7 +23,7 @@ import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.latin.AdditionalSubtype; import com.android.inputmethod.latin.AdditionalSubtype;
import com.android.inputmethod.latin.CollectionUtils; import com.android.inputmethod.latin.CollectionUtils;
import com.android.inputmethod.latin.ImfUtils; import com.android.inputmethod.latin.RichInputMethodManager;
import com.android.inputmethod.latin.StringUtils; import com.android.inputmethod.latin.StringUtils;
import com.android.inputmethod.latin.SubtypeLocale; import com.android.inputmethod.latin.SubtypeLocale;
@ -34,12 +34,15 @@ public class SpacebarTextTests extends AndroidTestCase {
// Locale to subtypes list. // Locale to subtypes list.
private final ArrayList<InputMethodSubtype> mSubtypesList = CollectionUtils.newArrayList(); private final ArrayList<InputMethodSubtype> mSubtypesList = CollectionUtils.newArrayList();
private RichInputMethodManager mRichImm;
private Resources mRes; private Resources mRes;
@Override @Override
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);
mRichImm = RichInputMethodManager.getInstance();
mRes = context.getResources(); mRes = context.getResources();
SubtypeLocale.init(context); SubtypeLocale.init(context);
} }
@ -103,19 +106,18 @@ public class SpacebarTextTests extends AndroidTestCase {
// zz azerty T AZERTY AZERTY // zz azerty T AZERTY AZERTY
public void testPredefinedSubtypes() { public void testPredefinedSubtypes() {
final Context context = getContext(); final InputMethodSubtype EN_US = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
final InputMethodSubtype EN_US = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet( Locale.US.toString(), "qwerty");
context, Locale.US.toString(), "qwerty"); final InputMethodSubtype EN_GB = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
final InputMethodSubtype EN_GB = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet( Locale.UK.toString(), "qwerty");
context, Locale.UK.toString(), "qwerty"); final InputMethodSubtype FR = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
final InputMethodSubtype FR = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet( Locale.FRENCH.toString(), "azerty");
context, Locale.FRENCH.toString(), "azerty"); final InputMethodSubtype FR_CA = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
final InputMethodSubtype FR_CA = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet( Locale.CANADA_FRENCH.toString(), "qwerty");
context, Locale.CANADA_FRENCH.toString(), "qwerty"); final InputMethodSubtype DE = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
final InputMethodSubtype DE = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet( Locale.GERMAN.toString(), "qwertz");
context, Locale.GERMAN.toString(), "qwertz"); final InputMethodSubtype ZZ = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
final InputMethodSubtype ZZ = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet( SubtypeLocale.NO_LANGUAGE, "qwerty");
context, SubtypeLocale.NO_LANGUAGE, "qwerty");
assertEquals("en_US", "English (US)", assertEquals("en_US", "English (US)",
MainKeyboardView.getFullDisplayName(EN_US, mRes)); MainKeyboardView.getFullDisplayName(EN_US, mRes));

View File

@ -30,12 +30,15 @@ public class SubtypeLocaleTests extends AndroidTestCase {
// Locale to subtypes list. // Locale to subtypes list.
private final ArrayList<InputMethodSubtype> mSubtypesList = CollectionUtils.newArrayList(); private final ArrayList<InputMethodSubtype> mSubtypesList = CollectionUtils.newArrayList();
private RichInputMethodManager mRichImm;
private Resources mRes; private Resources mRes;
@Override @Override
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);
mRichImm = RichInputMethodManager.getInstance();
mRes = context.getResources(); mRes = context.getResources();
SubtypeLocale.init(context); SubtypeLocale.init(context);
} }
@ -70,19 +73,18 @@ public class SubtypeLocaleTests extends AndroidTestCase {
// zz azerty T No language (AZERTY) in system locale // zz azerty T No language (AZERTY) in system locale
public void testPredefinedSubtypesInEnglish() { public void testPredefinedSubtypesInEnglish() {
final Context context = getContext(); final InputMethodSubtype EN_US = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
final InputMethodSubtype EN_US = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet( Locale.US.toString(), "qwerty");
context, Locale.US.toString(), "qwerty"); final InputMethodSubtype EN_GB = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
final InputMethodSubtype EN_GB = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet( Locale.UK.toString(), "qwerty");
context, Locale.UK.toString(), "qwerty"); final InputMethodSubtype FR = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
final InputMethodSubtype FR = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet( Locale.FRENCH.toString(), "azerty");
context, Locale.FRENCH.toString(), "azerty"); final InputMethodSubtype FR_CA = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
final InputMethodSubtype FR_CA = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet( Locale.CANADA_FRENCH.toString(), "qwerty");
context, Locale.CANADA_FRENCH.toString(), "qwerty"); final InputMethodSubtype DE = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
final InputMethodSubtype DE = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet( Locale.GERMAN.toString(), "qwertz");
context, Locale.GERMAN.toString(), "qwertz"); final InputMethodSubtype ZZ = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
final InputMethodSubtype ZZ = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet( SubtypeLocale.NO_LANGUAGE, "qwerty");
context, SubtypeLocale.NO_LANGUAGE, "qwerty");
assertEquals("en_US", "qwerty", SubtypeLocale.getKeyboardLayoutSetName(EN_US)); assertEquals("en_US", "qwerty", SubtypeLocale.getKeyboardLayoutSetName(EN_US));
assertEquals("en_GB", "qwerty", SubtypeLocale.getKeyboardLayoutSetName(EN_GB)); assertEquals("en_GB", "qwerty", SubtypeLocale.getKeyboardLayoutSetName(EN_GB));
@ -140,19 +142,18 @@ public class SubtypeLocaleTests extends AndroidTestCase {
} }
public void testPredefinedSubtypesInFrench() { public void testPredefinedSubtypesInFrench() {
final Context context = getContext(); final InputMethodSubtype EN_US = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
final InputMethodSubtype EN_US = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet( Locale.US.toString(), "qwerty");
context, Locale.US.toString(), "qwerty"); final InputMethodSubtype EN_GB = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
final InputMethodSubtype EN_GB = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet( Locale.UK.toString(), "qwerty");
context, Locale.UK.toString(), "qwerty"); final InputMethodSubtype FR = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
final InputMethodSubtype FR = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet( Locale.FRENCH.toString(), "azerty");
context, Locale.FRENCH.toString(), "azerty"); final InputMethodSubtype FR_CA = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
final InputMethodSubtype FR_CA = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet( Locale.CANADA_FRENCH.toString(), "qwerty");
context, Locale.CANADA_FRENCH.toString(), "qwerty"); final InputMethodSubtype DE = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
final InputMethodSubtype DE = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet( Locale.GERMAN.toString(), "qwertz");
context, Locale.GERMAN.toString(), "qwertz"); final InputMethodSubtype ZZ = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
final InputMethodSubtype ZZ = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet( SubtypeLocale.NO_LANGUAGE, "qwerty");
context, SubtypeLocale.NO_LANGUAGE, "qwerty");
final RunInLocale<Void> tests = new RunInLocale<Void>() { final RunInLocale<Void> tests = new RunInLocale<Void>() {
@Override @Override