From 55d28fd1b2631a63542a647f693d8a8ed749bcf7 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 18 Apr 2012 17:39:57 +0900 Subject: Cleanup InputMethodManagerCompatWrapper Change-Id: Id3b84ee19bb504ed8fbb398e260cc663a5b5ae0d --- .../com/android/inputmethod/latin/ImfUtils.java | 163 +++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 java/src/com/android/inputmethod/latin/ImfUtils.java (limited to 'java/src/com/android/inputmethod/latin/ImfUtils.java') diff --git a/java/src/com/android/inputmethod/latin/ImfUtils.java b/java/src/com/android/inputmethod/latin/ImfUtils.java new file mode 100644 index 000000000..bd7d89fe7 --- /dev/null +++ b/java/src/com/android/inputmethod/latin/ImfUtils.java @@ -0,0 +1,163 @@ +/* + * 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 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 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 checkIfSubtypeBelongsToThisIme(Context context, InputMethodSubtype ims) { + final InputMethodInfo myImi = getInputMethodInfoOfThisIme(context); + final InputMethodManager imm = getInputMethodManager(context); + final List subtypes = imm.getEnabledInputMethodSubtypeList(myImi, true); + for (final InputMethodSubtype subtype : subtypes) { + if (subtype.equals(ims)) { + return true; + } + } + return false; + } + + public static boolean hasMultipleEnabledIMEsOrSubtypes(Context context, + final boolean shouldIncludeAuxiliarySubtypes) { + final InputMethodManager imm = getInputMethodManager(context); + final List enabledImis = imm.getEnabledInputMethodList(); + return hasMultipleEnabledSubtypes(context, shouldIncludeAuxiliarySubtypes, enabledImis); + } + + public static boolean hasMultipleEnabledSubtypesInThisIme(Context context, + final boolean shouldIncludeAuxiliarySubtypes) { + final InputMethodInfo myImi = getInputMethodInfoOfThisIme(context); + final List imiList = Collections.singletonList(myImi); + return hasMultipleEnabledSubtypes(context, shouldIncludeAuxiliarySubtypes, imiList); + } + + private static boolean hasMultipleEnabledSubtypes(Context context, + final boolean shouldIncludeAuxiliarySubtypes, List 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 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 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 (SubtypeSwitcher.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; + } + } + throw new RuntimeException("Can't find subtype for locale " + localeString + + " and keyboard layout " + keyboardLayoutSetName); + } + + public static void setAdditionalInputMethodSubtypes(Context context, + InputMethodSubtype[] subtypes) { + final InputMethodManager imm = getInputMethodManager(context); + final String imiId = getInputMethodIdOfThisIme(context); + imm.setAdditionalInputMethodSubtypes(imiId, subtypes); + } +} -- cgit v1.2.3-83-g751a From 1cb08acaf3b4d58cbf4cb65f9fc3990b39e33f00 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Thu, 19 Apr 2012 12:42:13 +0900 Subject: Add Constants class to hold public constants This change also gets rid of compiler warnings about "deprecations". Change-Id: Id9b83483c453a81ebac34b684656db05e3599657 --- .../android/inputmethod/keyboard/KeyboardId.java | 5 +- .../inputmethod/keyboard/KeyboardLayoutSet.java | 19 ++-- .../keyboard/internal/KeySpecParser.java | 6 +- .../inputmethod/latin/AdditionalSubtype.java | 22 ++--- .../latin/AdditionalSubtypeSettings.java | 6 +- .../com/android/inputmethod/latin/Constants.java | 103 +++++++++++++++++++++ .../com/android/inputmethod/latin/ImfUtils.java | 4 +- .../com/android/inputmethod/latin/LatinIME.java | 56 ++--------- .../android/inputmethod/latin/SubtypeLocale.java | 5 +- .../android/inputmethod/latin/SubtypeSwitcher.java | 10 +- 10 files changed, 153 insertions(+), 83 deletions(-) create mode 100644 java/src/com/android/inputmethod/latin/Constants.java (limited to 'java/src/com/android/inputmethod/latin/ImfUtils.java') diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardId.java b/java/src/com/android/inputmethod/keyboard/KeyboardId.java index b7eb8f69c..233716acf 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardId.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardId.java @@ -16,6 +16,8 @@ package com.android.inputmethod.keyboard; +import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.KEYBOARD_LAYOUT_SET; + import android.text.InputType; import android.text.TextUtils; import android.view.inputmethod.EditorInfo; @@ -23,7 +25,6 @@ import android.view.inputmethod.InputMethodSubtype; import com.android.inputmethod.compat.EditorInfoCompatUtils; import com.android.inputmethod.latin.InputTypeUtils; -import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.SubtypeLocale; import java.util.Arrays; @@ -184,7 +185,7 @@ public class KeyboardId { return String.format("[%s %s:%s %s%d %s %s %s%s%s%s%s%s%s%s]", elementIdToName(mElementId), mLocale, - mSubtype.getExtraValueOf(LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LAYOUT_SET), + mSubtype.getExtraValueOf(KEYBOARD_LAYOUT_SET), (mOrientation == 1 ? "port" : "land"), mWidth, modeName(mMode), imeAction(), diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java index 07f71ee17..8c7246855 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java @@ -16,6 +16,12 @@ package com.android.inputmethod.keyboard; +import static com.android.inputmethod.latin.Constants.ImeOption.FORCE_ASCII; +import static com.android.inputmethod.latin.Constants.ImeOption.NO_MICROPHONE; +import static com.android.inputmethod.latin.Constants.ImeOption.NO_MICROPHONE_COMPAT; +import static com.android.inputmethod.latin.Constants.ImeOption.NO_SETTINGS_KEY; +import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.ASCII_CAPABLE; + import android.content.Context; import android.content.res.Configuration; import android.content.res.Resources; @@ -31,7 +37,6 @@ import com.android.inputmethod.compat.EditorInfoCompatUtils; import com.android.inputmethod.keyboard.KeyboardLayoutSet.Params.ElementParams; import com.android.inputmethod.latin.InputAttributes; import com.android.inputmethod.latin.InputTypeUtils; -import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.SubtypeLocale; @@ -230,7 +235,7 @@ public class KeyboardLayoutSet { params.mMode = getKeyboardMode(editorInfo); params.mEditorInfo = (editorInfo != null) ? editorInfo : EMPTY_EDITOR_INFO; params.mNoSettingsKey = InputAttributes.inPrivateImeOptions( - mPackageName, LatinIME.IME_OPTION_NO_SETTINGS_KEY, mEditorInfo); + mPackageName, NO_SETTINGS_KEY, mEditorInfo); } public Builder setScreenGeometry(int orientation, int widthPixels) { @@ -240,10 +245,10 @@ public class KeyboardLayoutSet { } public Builder setSubtype(InputMethodSubtype subtype) { - final boolean asciiCapable = subtype.containsExtraValueKey( - LatinIME.SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE); + final boolean asciiCapable = subtype.containsExtraValueKey(ASCII_CAPABLE); + @SuppressWarnings("deprecation") final boolean deprecatedForceAscii = InputAttributes.inPrivateImeOptions( - mPackageName, LatinIME.IME_OPTION_FORCE_ASCII, mEditorInfo); + mPackageName, FORCE_ASCII, mEditorInfo); final boolean forceAscii = EditorInfoCompatUtils.hasFlagForceAscii( mParams.mEditorInfo.imeOptions) || deprecatedForceAscii; @@ -260,9 +265,9 @@ public class KeyboardLayoutSet { boolean languageSwitchKeyEnabled) { @SuppressWarnings("deprecation") final boolean deprecatedNoMicrophone = InputAttributes.inPrivateImeOptions( - null, LatinIME.IME_OPTION_NO_MICROPHONE_COMPAT, mEditorInfo); + null, NO_MICROPHONE_COMPAT, mEditorInfo); final boolean noMicrophone = InputAttributes.inPrivateImeOptions( - mPackageName, LatinIME.IME_OPTION_NO_MICROPHONE, mEditorInfo) + mPackageName, NO_MICROPHONE, mEditorInfo) || deprecatedNoMicrophone; mParams.mVoiceKeyEnabled = voiceKeyEnabled && !noMicrophone; mParams.mVoiceKeyOnMain = voiceKeyOnMain; diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java index 9bbd3a280..8261400b2 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java @@ -159,7 +159,7 @@ public class KeySpecParser { return parseEscape(moreKeySpec.substring(end + /* LABEL_END */1)); } - private static String getOutputText(String moreKeySpec) { + static String getOutputText(String moreKeySpec) { if (hasCode(moreKeySpec)) { return null; } @@ -183,7 +183,7 @@ public class KeySpecParser { return (StringUtils.codePointCount(label) == 1) ? null : label; } - private static int getCode(String moreKeySpec, KeyboardCodesSet codesSet) { + static int getCode(String moreKeySpec, KeyboardCodesSet codesSet) { if (hasCode(moreKeySpec)) { final int end = indexOfLabelEnd(moreKeySpec, 0); if (indexOfLabelEnd(moreKeySpec, end + 1) >= 0) { @@ -219,7 +219,7 @@ public class KeySpecParser { } } - private static int getIconId(String moreKeySpec) { + static int getIconId(String moreKeySpec) { if (hasIcon(moreKeySpec)) { final int end = moreKeySpec.indexOf(LABEL_END, PREFIX_ICON.length()); final String name = moreKeySpec.substring(PREFIX_ICON.length(), end); diff --git a/java/src/com/android/inputmethod/latin/AdditionalSubtype.java b/java/src/com/android/inputmethod/latin/AdditionalSubtype.java index 777dab443..28cec56e6 100644 --- a/java/src/com/android/inputmethod/latin/AdditionalSubtype.java +++ b/java/src/com/android/inputmethod/latin/AdditionalSubtype.java @@ -16,6 +16,10 @@ package com.android.inputmethod.latin; +import static com.android.inputmethod.latin.Constants.Subtype.KEYBOARD_MODE; +import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.IS_ADDITIONAL_SUBTYPE; +import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.KEYBOARD_LAYOUT_SET; + import android.view.inputmethod.InputMethodSubtype; import java.util.HashMap; @@ -30,9 +34,6 @@ public class AdditionalSubtype { AZERTY }; - private static final String SUBTYPE_MODE_KEYBOARD = "keyboard"; - private static final String SUBTYPE_EXTRA_VALUE_IS_ADDITIONAL_SUBTYPE = "isAdditionalSubtype"; - // Keyboard layout to subtype name resource id map. private static final HashMap sKeyboardLayoutToNameIdsMap = new HashMap(); @@ -48,7 +49,7 @@ public class AdditionalSubtype { } public static boolean isAdditionalSubtype(InputMethodSubtype subtype) { - return subtype.containsExtraValueKey(SUBTYPE_EXTRA_VALUE_IS_ADDITIONAL_SUBTYPE); + return subtype.containsExtraValueKey(IS_ADDITIONAL_SUBTYPE); } private static final String LOCALE_AND_LAYOUT_SEPARATOR = ":"; @@ -56,25 +57,22 @@ public class AdditionalSubtype { public static InputMethodSubtype createAdditionalSubtype( String localeString, String keyboardLayoutSetName, String extraValue) { - final String layoutExtraValue = LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LAYOUT_SET + "=" - + keyboardLayoutSetName; + final String layoutExtraValue = KEYBOARD_LAYOUT_SET + "=" + keyboardLayoutSetName; final String filteredExtraValue = StringUtils.appendToCsvIfNotExists( - SUBTYPE_EXTRA_VALUE_IS_ADDITIONAL_SUBTYPE, extraValue); + IS_ADDITIONAL_SUBTYPE, extraValue); Integer nameId = sKeyboardLayoutToNameIdsMap.get(keyboardLayoutSetName); if (nameId == null) nameId = R.string.subtype_generic; return new InputMethodSubtype(nameId, R.drawable.ic_subtype_keyboard, - localeString, SUBTYPE_MODE_KEYBOARD, + localeString, KEYBOARD_MODE, layoutExtraValue + "," + filteredExtraValue, false, false); } public static String getPrefSubtype(InputMethodSubtype subtype) { final String localeString = subtype.getLocale(); final String keyboardLayoutSetName = SubtypeLocale.getKeyboardLayoutSetName(subtype); - final String layoutExtraValue = LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LAYOUT_SET + "=" - + keyboardLayoutSetName; + final String layoutExtraValue = KEYBOARD_LAYOUT_SET + "=" + keyboardLayoutSetName; final String extraValue = StringUtils.removeFromCsvIfExists(layoutExtraValue, - StringUtils.removeFromCsvIfExists(SUBTYPE_EXTRA_VALUE_IS_ADDITIONAL_SUBTYPE, - subtype.getExtraValue())); + StringUtils.removeFromCsvIfExists(IS_ADDITIONAL_SUBTYPE, subtype.getExtraValue())); final String basePrefSubtype = localeString + LOCALE_AND_LAYOUT_SEPARATOR + keyboardLayoutSetName; return extraValue.isEmpty() ? basePrefSubtype diff --git a/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java b/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java index 6ff8aa2f5..7a22c9742 100644 --- a/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java +++ b/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java @@ -16,6 +16,8 @@ package com.android.inputmethod.latin; +import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.ASCII_CAPABLE; + import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; @@ -88,7 +90,7 @@ public class AdditionalSubtypeSettings extends PreferenceFragment { final int count = imi.getSubtypeCount(); for (int i = 0; i < count; i++) { final InputMethodSubtype subtype = imi.getSubtypeAt(i); - if (subtype.containsExtraValueKey(LatinIME.SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE)) { + if (subtype.containsExtraValueKey(ASCII_CAPABLE)) { items.add(createItem(context, subtype.getLocale())); } } @@ -223,7 +225,7 @@ public class AdditionalSubtypeSettings extends PreferenceFragment { final KeyboardLayoutSetItem layout = (KeyboardLayoutSetItem) mKeyboardLayoutSetSpinner.getSelectedItem(); final InputMethodSubtype subtype = AdditionalSubtype.createAdditionalSubtype( - locale.first, layout.first, LatinIME.SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE); + locale.first, layout.first, ASCII_CAPABLE); setSubtype(subtype); notifyChanged(); break; diff --git a/java/src/com/android/inputmethod/latin/Constants.java b/java/src/com/android/inputmethod/latin/Constants.java new file mode 100644 index 000000000..b205cc004 --- /dev/null +++ b/java/src/com/android/inputmethod/latin/Constants.java @@ -0,0 +1,103 @@ +/* + * 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 android.view.inputmethod.EditorInfo; + +public final class Constants { + public static final class ImeOption { + /** + * The private IME option used to indicate that no microphone should be shown for a given + * text field. For instance, this is specified by the search dialog when the dialog is + * already showing a voice search button. + * + * @deprecated Use {@link ImeOption#NO_MICROPHONE} with package name prefixed. + */ + @SuppressWarnings("dep-ann") + public static final String NO_MICROPHONE_COMPAT = "nm"; + + /** + * The private IME option used to indicate that no microphone should be shown for a given + * text field. For instance, this is specified by the search dialog when the dialog is + * already showing a voice search button. + */ + public static final String NO_MICROPHONE = "noMicrophoneKey"; + + /** + * The private IME option used to indicate that no settings key should be shown for a given + * text field. + */ + public static final String NO_SETTINGS_KEY = "noSettingsKey"; + + /** + * The private IME option used to indicate that the given text field needs ASCII code points + * input. + * + * @deprecated Use {@link EditorInfo#IME_FLAG_FORCE_ASCII}. + */ + @SuppressWarnings("dep-ann") + public static final String FORCE_ASCII = "forceAscii"; + + private ImeOption() { + // This utility class is not publicly instantiable. + } + } + + public static final class Subtype { + /** + * The subtype mode used to indicate that the subtype is a keyboard. + */ + public static final String KEYBOARD_MODE = "keyboard"; + + public static final class ExtraValue { + /** + * The subtype extra value used to indicate that the subtype keyboard layout set name. + */ + public static final String KEYBOARD_LAYOUT_SET = "KeyboardLayoutSet"; + + /** + * The subtype extra value used to indicate that the subtype keyboard layout is capable + * for typing ASCII characters. + */ + public static final String ASCII_CAPABLE = "AsciiCapable"; + + /** + * The subtype extra value used to indicate that the subtype require network connection + * to work. + */ + public static final String REQ_NETWORK_CONNECTIVITY = "requireNetworkConnectivity"; + + /** + * The subtype extra value used to indicate that the subtype is additional subtype + * that the user defined. This extra value is private to LatinIME. + */ + public static final String IS_ADDITIONAL_SUBTYPE = "isAdditionalSubtype"; + + private ExtraValue() { + // This utility class is not publicly instantiable. + } + } + + private Subtype() { + // This utility class is not publicly instantiable. + } + } + + private Constants() { + // This utility class is not publicly instantiable. + } +} diff --git a/java/src/com/android/inputmethod/latin/ImfUtils.java b/java/src/com/android/inputmethod/latin/ImfUtils.java index bd7d89fe7..4633b82f5 100644 --- a/java/src/com/android/inputmethod/latin/ImfUtils.java +++ b/java/src/com/android/inputmethod/latin/ImfUtils.java @@ -16,6 +16,8 @@ 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; @@ -131,7 +133,7 @@ public class ImfUtils { // both explicitly and implicitly enabled input method subtype. // (The current IME should be LatinIME.) for (InputMethodSubtype subtype : subtypes) { - if (SubtypeSwitcher.KEYBOARD_MODE.equals(subtype.getMode())) { + if (KEYBOARD_MODE.equals(subtype.getMode())) { ++keyboardCount; } } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 9cfde8b77..31c832c31 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -16,6 +16,10 @@ package com.android.inputmethod.latin; +import static com.android.inputmethod.latin.Constants.ImeOption.FORCE_ASCII; +import static com.android.inputmethod.latin.Constants.ImeOption.NO_MICROPHONE; +import static com.android.inputmethod.latin.Constants.ImeOption.NO_MICROPHONE_COMPAT; + import android.app.AlertDialog; import android.content.BroadcastReceiver; import android.content.Context; @@ -81,49 +85,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private static final boolean TRACE = false; private static boolean DEBUG; - /** - * The private IME option used to indicate that no microphone should be - * shown for a given text field. For instance, this is specified by the - * search dialog when the dialog is already showing a voice search button. - * - * @deprecated Use {@link LatinIME#IME_OPTION_NO_MICROPHONE} with package name prefixed. - */ - @SuppressWarnings("dep-ann") - public static final String IME_OPTION_NO_MICROPHONE_COMPAT = "nm"; - - /** - * The private IME option used to indicate that no microphone should be - * shown for a given text field. For instance, this is specified by the - * search dialog when the dialog is already showing a voice search button. - */ - public static final String IME_OPTION_NO_MICROPHONE = "noMicrophoneKey"; - - /** - * The private IME option used to indicate that no settings key should be - * shown for a given text field. - */ - public static final String IME_OPTION_NO_SETTINGS_KEY = "noSettingsKey"; - - /** - * The private IME option used to indicate that the given text field needs - * ASCII code points input. - * - * @deprecated Use {@link EditorInfo#IME_FLAG_FORCE_ASCII}. - */ - @SuppressWarnings("dep-ann") - public static final String IME_OPTION_FORCE_ASCII = "forceAscii"; - - /** - * The subtype extra value used to indicate that the subtype keyboard layout set name. - */ - public static final String SUBTYPE_EXTRA_VALUE_KEYBOARD_LAYOUT_SET = "KeyboardLayoutSet"; - - /** - * The subtype extra value used to indicate that the subtype keyboard layout is capable for - * typing ASCII characters. - */ - public static final String SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE = "AsciiCapable"; - private static final int EXTENDED_TOUCHABLE_REGION_HEIGHT = 100; // How many continuous deletes at which to start deleting at a higher speed. @@ -649,6 +610,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen super.onStartInput(editorInfo, restarting); } + @SuppressWarnings("deprecation") private void onStartInputViewInternal(EditorInfo editorInfo, boolean restarting) { super.onStartInputView(editorInfo, restarting); final KeyboardSwitcher switcher = mKeyboardSwitcher; @@ -669,14 +631,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen if (ProductionFlag.IS_EXPERIMENTAL) { ResearchLogger.latinIME_onStartInputViewInternal(editorInfo); } - if (InputAttributes.inPrivateImeOptions( - null, IME_OPTION_NO_MICROPHONE_COMPAT, editorInfo)) { + if (InputAttributes.inPrivateImeOptions(null, NO_MICROPHONE_COMPAT, editorInfo)) { Log.w(TAG, "Deprecated private IME option specified: " + editorInfo.privateImeOptions); - Log.w(TAG, "Use " + getPackageName() + "." + IME_OPTION_NO_MICROPHONE + " instead"); + Log.w(TAG, "Use " + getPackageName() + "." + NO_MICROPHONE + " instead"); } - if (InputAttributes.inPrivateImeOptions( - getPackageName(), IME_OPTION_FORCE_ASCII, editorInfo)) { + if (InputAttributes.inPrivateImeOptions(getPackageName(), FORCE_ASCII, editorInfo)) { Log.w(TAG, "Deprecated private IME option specified: " + editorInfo.privateImeOptions); Log.w(TAG, "Use EditorInfo.IME_FLAG_FORCE_ASCII flag instead"); diff --git a/java/src/com/android/inputmethod/latin/SubtypeLocale.java b/java/src/com/android/inputmethod/latin/SubtypeLocale.java index 787e86a79..772777f19 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeLocale.java +++ b/java/src/com/android/inputmethod/latin/SubtypeLocale.java @@ -16,6 +16,8 @@ package com.android.inputmethod.latin; +import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.KEYBOARD_LAYOUT_SET; + import android.content.Context; import android.content.res.Resources; import android.view.inputmethod.InputMethodSubtype; @@ -117,8 +119,7 @@ public class SubtypeLocale { } public static String getKeyboardLayoutSetName(InputMethodSubtype subtype) { - final String keyboardLayoutSet = subtype.getExtraValueOf( - LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LAYOUT_SET); + final String keyboardLayoutSet = subtype.getExtraValueOf(KEYBOARD_LAYOUT_SET); // TODO: Remove this null check when InputMethodManager.getCurrentInputMethodSubtype is // fixed. if (keyboardLayoutSet == null) { diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index cf95a7e1a..1a9f373a1 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -16,6 +16,9 @@ package com.android.inputmethod.latin; +import static com.android.inputmethod.latin.Constants.Subtype.KEYBOARD_MODE; +import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.REQ_NETWORK_CONNECTIVITY; + import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager.NameNotFoundException; @@ -42,11 +45,7 @@ public class SubtypeSwitcher { private static boolean DBG = LatinImeLogger.sDBG; private static final String TAG = SubtypeSwitcher.class.getSimpleName(); - public static final String KEYBOARD_MODE = "keyboard"; private static final char LOCALE_SEPARATOR = '_'; - private static final String SUBTYPE_EXTRAVALUE_REQUIRE_NETWORK_CONNECTIVITY = - "requireNetworkConnectivity"; - private final TextUtils.SimpleStringSplitter mLocaleSplitter = new TextUtils.SimpleStringSplitter(LOCALE_SEPARATOR); @@ -309,8 +308,7 @@ public class SubtypeSwitcher { return false; if (mShortcutSubtype == null) return true; - if (mShortcutSubtype.containsExtraValueKey( - SUBTYPE_EXTRAVALUE_REQUIRE_NETWORK_CONNECTIVITY)) { + if (mShortcutSubtype.containsExtraValueKey(REQ_NETWORK_CONNECTIVITY)) { return mIsNetworkConnected; } return true; -- cgit v1.2.3-83-g751a From 0ab1c664c138b3bc10730c89b2d8efdacee6b15b Mon Sep 17 00:00:00 2001 From: Ken Wakasa Date: Sat, 28 Apr 2012 03:24:05 +0900 Subject: 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(-) (limited to 'java/src/com/android/inputmethod/latin/ImfUtils.java') 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); } -- cgit v1.2.3-83-g751a From ae2388c7f799ab565f63d3ba83abaf3300475fd0 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 1 May 2012 20:06:38 +0900 Subject: Fix checking if subtype belongs to this ime Bug: 6422318 Change-Id: I5779c0e277444315191fa964a976dcb4316cc24a --- java/src/com/android/inputmethod/latin/ImfUtils.java | 16 +++++++++++++++- java/src/com/android/inputmethod/latin/LatinIME.java | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/ImfUtils.java') diff --git a/java/src/com/android/inputmethod/latin/ImfUtils.java b/java/src/com/android/inputmethod/latin/ImfUtils.java index af46a02c0..36f6d8ba0 100644 --- a/java/src/com/android/inputmethod/latin/ImfUtils.java +++ b/java/src/com/android/inputmethod/latin/ImfUtils.java @@ -63,7 +63,8 @@ public class ImfUtils { return getInputMethodInfoOfThisIme(context).getId(); } - public static boolean checkIfSubtypeBelongsToThisIme(Context context, InputMethodSubtype ims) { + 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 @@ -76,6 +77,19 @@ public class ImfUtils { 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 boolean hasMultipleEnabledIMEsOrSubtypes(Context context, final boolean shouldIncludeAuxiliarySubtypes) { final InputMethodManager imm = getInputMethodManager(context); diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index c6381180c..7efdef987 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1148,8 +1148,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen final IBinder token = getWindow().getWindow().getAttributes().token; if (mShouldSwitchToLastSubtype) { final InputMethodSubtype lastSubtype = mImm.getLastInputMethodSubtype(); - final boolean lastSubtypeBelongsToThisIme = ImfUtils.checkIfSubtypeBelongsToThisIme( - this, lastSubtype); + final boolean lastSubtypeBelongsToThisIme = + ImfUtils.checkIfSubtypeBelongsToThisImeAndEnabled(this, lastSubtype); if ((includesOtherImes || lastSubtypeBelongsToThisIme) && mImm.switchToLastInputMethod(token)) { mShouldSwitchToLastSubtype = false; -- cgit v1.2.3-83-g751a From 749b2a388edc3e86e4af1208740caccb7e39b7cd Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 16 May 2012 16:14:17 +0900 Subject: Check duplicated entry of "custom input style" Bug: 6495488 Change-Id: Ia6c2421cb0e7c1793d4dfe18acd07fd6f8c5d797 --- java/res/values/strings.xml | 2 + .../latin/AdditionalSubtypeSettings.java | 105 ++++++++++++++++----- .../com/android/inputmethod/latin/ImfUtils.java | 3 +- .../android/inputmethod/latin/SubtypeSwitcher.java | 3 + 4 files changed, 88 insertions(+), 25 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/ImfUtils.java') diff --git a/java/res/values/strings.xml b/java/res/values/strings.xml index 8b03379ca..b9bec9896 100644 --- a/java/res/values/strings.xml +++ b/java/res/values/strings.xml @@ -293,6 +293,8 @@ Enable Not now + + "The same input style already exists: %s" Usability study mode diff --git a/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java b/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java index a8115fb82..779a38823 100644 --- a/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java +++ b/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java @@ -24,6 +24,7 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; +import android.content.res.Resources; import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; @@ -41,9 +42,11 @@ import android.view.inputmethod.InputMethodSubtype; import android.widget.ArrayAdapter; import android.widget.Spinner; import android.widget.SpinnerAdapter; +import android.widget.Toast; import com.android.inputmethod.compat.CompatUtils; +import java.util.ArrayList; import java.util.TreeSet; public class AdditionalSubtypeSettings extends PreferenceFragment { @@ -60,7 +63,6 @@ public class AdditionalSubtypeSettings extends PreferenceFragment { private static final String KEY_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"; - static class SubtypeLocaleItem extends Pair implements Comparable { public SubtypeLocaleItem(String localeString, String displayName) { @@ -139,6 +141,7 @@ public class AdditionalSubtypeSettings extends PreferenceFragment { private interface SubtypeDialogProxy { public void onRemovePressed(SubtypePreference subtypePref); + public void onSavePressed(SubtypePreference subtypePref); public void onAddPressed(SubtypePreference subtypePref); public SubtypeLocaleAdapter getSubtypeLocaleAdapter(); public KeyboardLayoutSetAdapter getKeyboardLayoutSetAdapter(); @@ -150,6 +153,7 @@ public class AdditionalSubtypeSettings extends PreferenceFragment { private static final String KEY_NEW_SUBTYPE = KEY_PREFIX + "new"; private InputMethodSubtype mSubtype; + private InputMethodSubtype mPreviousSubtype; private final SubtypeDialogProxy mProxy; private Spinner mSubtypeLocaleSpinner; @@ -182,6 +186,7 @@ public class AdditionalSubtypeSettings extends PreferenceFragment { } public void setSubtype(InputMethodSubtype subtype) { + mPreviousSubtype = mSubtype; mSubtype = subtype; if (isIncomplete()) { setTitle(null); @@ -197,6 +202,14 @@ public class AdditionalSubtypeSettings extends PreferenceFragment { } } + public void revert() { + setSubtype(mPreviousSubtype); + } + + public boolean hasBeenModified() { + return mSubtype != null && !mSubtype.equals(mPreviousSubtype); + } + @Override protected View onCreateDialogView() { final View v = super.onCreateDialogView(); @@ -250,7 +263,7 @@ public class AdditionalSubtypeSettings extends PreferenceFragment { super.onClick(dialog, which); switch (which) { case DialogInterface.BUTTON_POSITIVE: - final boolean addPressed = isIncomplete(); + final boolean isEditing = !isIncomplete(); final SubtypeLocaleItem locale = (SubtypeLocaleItem) mSubtypeLocaleSpinner.getSelectedItem(); final KeyboardLayoutSetItem layout = @@ -259,7 +272,9 @@ public class AdditionalSubtypeSettings extends PreferenceFragment { locale.first, layout.first, ASCII_CAPABLE); setSubtype(subtype); notifyChanged(); - if (addPressed) { + if (isEditing) { + mProxy.onSavePressed(this); + } else { mProxy.onAddPressed(this); } break; @@ -414,18 +429,45 @@ public class AdditionalSubtypeSettings extends PreferenceFragment { public void onRemovePressed(SubtypePreference subtypePref) { mIsAddingNewSubtype = false; final PreferenceGroup group = getPreferenceScreen(); - if (group != null) { - group.removePreference(subtypePref); + group.removePreference(subtypePref); + ImfUtils.setAdditionalInputMethodSubtypes(getActivity(), getSubtypes()); + } + + @Override + public void onSavePressed(SubtypePreference subtypePref) { + final InputMethodSubtype subtype = subtypePref.getSubtype(); + if (!subtypePref.hasBeenModified()) { + return; } + if (findDuplicatedSubtype(subtype) == null) { + ImfUtils.setAdditionalInputMethodSubtypes(getActivity(), getSubtypes()); + return; + } + + // Saved subtype is duplicated. + final PreferenceGroup group = getPreferenceScreen(); + group.removePreference(subtypePref); + subtypePref.revert(); + group.addPreference(subtypePref); + showSubtypeAlreadyExistsToast(subtype); } @Override public void onAddPressed(SubtypePreference subtypePref) { mIsAddingNewSubtype = false; - setAdditionalInputMethodSubtypes(getPrefSubtypes()); - mSubtypePreferenceKeyForSubtypeEnabler = subtypePref.getKey(); - mSubtypeEnablerNotificationDialog = createDialog(subtypePref); - mSubtypeEnablerNotificationDialog.show(); + final InputMethodSubtype subtype = subtypePref.getSubtype(); + if (findDuplicatedSubtype(subtype) == null) { + ImfUtils.setAdditionalInputMethodSubtypes(getActivity(), getSubtypes()); + mSubtypePreferenceKeyForSubtypeEnabler = subtypePref.getKey(); + mSubtypeEnablerNotificationDialog = createDialog(subtypePref); + mSubtypeEnablerNotificationDialog.show(); + return; + } + + // Newly added subtype is duplicated. + final PreferenceGroup group = getPreferenceScreen(); + group.removePreference(subtypePref); + showSubtypeAlreadyExistsToast(subtype); } @Override @@ -439,6 +481,21 @@ public class AdditionalSubtypeSettings extends PreferenceFragment { } }; + private void showSubtypeAlreadyExistsToast(InputMethodSubtype subtype) { + final Context context = getActivity(); + final Resources res = context.getResources(); + final String message = res.getString(R.string.custom_input_style_already_exists, + SubtypeLocale.getSubtypeDisplayName(subtype, res)); + Toast.makeText(context, message, Toast.LENGTH_SHORT).show(); + } + + private InputMethodSubtype findDuplicatedSubtype(InputMethodSubtype subtype) { + final String localeString = subtype.getLocale(); + final String keyboardLayoutSetName = SubtypeLocale.getKeyboardLayoutSetName(subtype); + return ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet( + getActivity(), localeString, keyboardLayoutSetName); + } + private AlertDialog createDialog(SubtypePreference subtypePref) { final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.custom_input_styles_title) @@ -474,9 +531,9 @@ public class AdditionalSubtypeSettings extends PreferenceFragment { } } - private String getPrefSubtypes() { + private InputMethodSubtype[] getSubtypes() { final PreferenceGroup group = getPreferenceScreen(); - final StringBuilder sb = new StringBuilder(); + final ArrayList subtypes = new ArrayList(); final int count = group.getPreferenceCount(); for (int i = 0; i < count; i++) { final Preference pref = group.getPreference(i); @@ -484,13 +541,20 @@ public class AdditionalSubtypeSettings extends PreferenceFragment { final SubtypePreference subtypePref = (SubtypePreference)pref; // We should not save newly adding subtype to preference because it is incomplete. if (subtypePref.isIncomplete()) continue; - final InputMethodSubtype subtype = subtypePref.getSubtype(); - if (sb.length() > 0) { - sb.append(AdditionalSubtype.PREF_SUBTYPE_SEPARATOR); - } - sb.append(AdditionalSubtype.getPrefSubtype(subtype)); + subtypes.add(subtypePref.getSubtype()); } } + return subtypes.toArray(new InputMethodSubtype[subtypes.size()]); + } + + private String getPrefSubtypes(InputMethodSubtype[] subtypes) { + final StringBuilder sb = new StringBuilder(); + for (final InputMethodSubtype subtype : subtypes) { + if (sb.length() > 0) { + sb.append(AdditionalSubtype.PREF_SUBTYPE_SEPARATOR); + } + sb.append(AdditionalSubtype.getPrefSubtype(subtype)); + } return sb.toString(); } @@ -498,7 +562,8 @@ public class AdditionalSubtypeSettings extends PreferenceFragment { public void onPause() { super.onPause(); final String oldSubtypes = SettingsValues.getPrefAdditionalSubtypes(mPrefs, getResources()); - final String prefSubtypes = getPrefSubtypes(); + final InputMethodSubtype[] subtypes = getSubtypes(); + final String prefSubtypes = getPrefSubtypes(subtypes); if (prefSubtypes.equals(oldSubtypes)) { return; } @@ -509,12 +574,6 @@ public class AdditionalSubtypeSettings extends PreferenceFragment { } finally { editor.apply(); } - setAdditionalInputMethodSubtypes(prefSubtypes); - } - - private void setAdditionalInputMethodSubtypes(final String prefSubtypes) { - final InputMethodSubtype[] subtypes = - AdditionalSubtype.createAdditionalSubtypesArray(prefSubtypes); ImfUtils.setAdditionalInputMethodSubtypes(getActivity(), subtypes); } diff --git a/java/src/com/android/inputmethod/latin/ImfUtils.java b/java/src/com/android/inputmethod/latin/ImfUtils.java index 36f6d8ba0..b882a4860 100644 --- a/java/src/com/android/inputmethod/latin/ImfUtils.java +++ b/java/src/com/android/inputmethod/latin/ImfUtils.java @@ -167,8 +167,7 @@ public class ImfUtils { return subtype; } } - throw new RuntimeException("Can't find subtype for locale " + localeString - + " and keyboard layout " + keyboardLayoutSetName); + return null; } public static void setAdditionalInputMethodSubtypes(Context context, diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index f2d971ca4..664de6774 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -101,6 +101,9 @@ public class SubtypeSwitcher { mCurrentSubtype = mImm.getCurrentInputMethodSubtype(); mNoLanguageSubtype = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet( service, SubtypeLocale.NO_LANGUAGE, SubtypeLocale.QWERTY); + if (mNoLanguageSubtype == null) { + throw new RuntimeException("Can't find no lanugage with QWERTY subtype"); + } final NetworkInfo info = mConnectivityManager.getActiveNetworkInfo(); mIsNetworkConnected = (info != null && info.isConnected()); -- cgit v1.2.3-83-g751a