diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardId.java b/java/src/com/android/inputmethod/keyboard/KeyboardId.java index b7eb8f69c15bed53205193f9c77c9bb5e890951d..233716acf6ac2b403f62ee8ec22ceba6aa0cb32f 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 07f71ee17bd33c924659b1df38d51e69f1172a5a..8c7246855b6cb8fb1a074f2cacd82df5501d3876 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 9bbd3a280c0724a01399f2676878ecb9dbad3fef..8261400b2e54af30e74c7129dac49b7a109d5795 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 777dab443f2518a6e6d1caf115e784c7f4a0e387..28cec56e6ea414c2837a926ecd6a8954b7452919 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<String, Integer> sKeyboardLayoutToNameIdsMap = new HashMap<String, Integer>(); @@ -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 6ff8aa2f55906ea0198bad186f988e4013eb502a..7a22c974246a30ba0eed02bb0bdb18c7dbb31934 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 0000000000000000000000000000000000000000..b205cc0042e26655f6278c7c331d951d5ec554eb --- /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 bd7d89fe7b348a7e95f425448ab0d375b5747db4..4633b82f5cdbb561fa2b763ac302696a5ee7fbcf 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 9cfde8b77a8beead6ace63ddf487f042ff74ea49..31c832c31a4b558729eba673a7a1f39425fbd0d6 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 787e86a79551aa895185eaaa03fd6b8726d162e4..772777f196bbed43d7a75a7432a70fb64c6188f3 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 cf95a7e1a8eb784575c369768b125159c90b005c..1a9f373a1fcdec0a0d32556abc9ff849d98def5c 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;