InputMethodSubtype.java revision 92a6f3018ace5aa2d5ea74e7d378b6960b5e053e
1ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok/* 2ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok * Copyright (C) 2010 The Android Open Source Project 3ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok * 4ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok * Licensed under the Apache License, Version 2.0 (the "License"); 5ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok * you may not use this file except in compliance with the License. 6ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok * You may obtain a copy of the License at 7ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok * 8ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok * http://www.apache.org/licenses/LICENSE-2.0 9ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok * 10ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok * Unless required by applicable law or agreed to in writing, software 11ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok * distributed under the License is distributed on an "AS IS" BASIS, 12ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok * See the License for the specific language governing permissions and 14ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok * limitations under the License. 15ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok */ 16ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok 17ab751aa085433e9f735d2e7603459c6c7e9d2fb0satokpackage android.view.inputmethod; 18ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok 197265d9bd6d80c5bedaa6de2b80f6619a301a07c8satokimport android.content.Context; 204f31353cb3b00c77c9420ef27ec949fd570ede3bsatokimport android.content.pm.ApplicationInfo; 21ab751aa085433e9f735d2e7603459c6c7e9d2fb0satokimport android.os.Parcel; 22ab751aa085433e9f735d2e7603459c6c7e9d2fb0satokimport android.os.Parcelable; 234f31353cb3b00c77c9420ef27ec949fd570ede3bsatokimport android.text.TextUtils; 249c4cc03a354922df08efacfc486ef0e80144d3easatokimport android.util.Slog; 25ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok 267265d9bd6d80c5bedaa6de2b80f6619a301a07c8satokimport java.util.ArrayList; 27ab751aa085433e9f735d2e7603459c6c7e9d2fb0satokimport java.util.Arrays; 289c4cc03a354922df08efacfc486ef0e80144d3easatokimport java.util.HashMap; 297265d9bd6d80c5bedaa6de2b80f6619a301a07c8satokimport java.util.HashSet; 3083e675f5ecf9f5615f3179ac102176faa3ae2596satokimport java.util.IllegalFormatException; 317265d9bd6d80c5bedaa6de2b80f6619a301a07c8satokimport java.util.List; 32a9778d4d442db65344e32318b1fd43ab54898389satokimport java.util.Locale; 33ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok 34ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok/** 359a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * This class is used to specify meta information of a subtype contained in an input method editor 369a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * (IME). Subtype can describe locale (e.g. en_US, fr_FR...) and mode (e.g. voice, keyboard...), 379a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * and is used for IME switch and settings. The input method subtype allows the system to bring up 389a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * the specified subtype of the designated IME directly. 3944b75030931d9c65c9e495a86d11d71da59b4429satok * 409a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * <p>It should be defined in an XML resource file of the input method with the 419a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * <code><subtype></code> element. For more information, see the guide to 4244b75030931d9c65c9e495a86d11d71da59b4429satok * <a href="{@docRoot}resources/articles/creating-input-method.html"> 4344b75030931d9c65c9e495a86d11d71da59b4429satok * Creating an Input Method</a>.</p> 44ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok */ 45ab751aa085433e9f735d2e7603459c6c7e9d2fb0satokpublic final class InputMethodSubtype implements Parcelable { 469c4cc03a354922df08efacfc486ef0e80144d3easatok private static final String TAG = InputMethodSubtype.class.getSimpleName(); 479c4cc03a354922df08efacfc486ef0e80144d3easatok private static final String EXTRA_VALUE_PAIR_SEPARATOR = ","; 489c4cc03a354922df08efacfc486ef0e80144d3easatok private static final String EXTRA_VALUE_KEY_VALUE_SEPARATOR = "="; 4983e675f5ecf9f5615f3179ac102176faa3ae2596satok // TODO: remove this 5083e675f5ecf9f5615f3179ac102176faa3ae2596satok private static final String EXTRA_KEY_UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME = 5183e675f5ecf9f5615f3179ac102176faa3ae2596satok "UntranslatableReplacementStringInSubtypeName"; 529c4cc03a354922df08efacfc486ef0e80144d3easatok 539aabb95781bee6a44684a6f6feb155e115d24983satok private final boolean mIsAuxiliary; 54a86f5e448cd6d29340ca6cbe509bc6384bc0d711satok private final boolean mOverridesImplicitlyEnabledSubtype; 55dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka private final boolean mIsAsciiCapable; 569aabb95781bee6a44684a6f6feb155e115d24983satok private final int mSubtypeHashCode; 57ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok private final int mSubtypeIconResId; 589aabb95781bee6a44684a6f6feb155e115d24983satok private final int mSubtypeNameResId; 59e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka private final int mSubtypeId; 60ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok private final String mSubtypeLocale; 619ef0283bdcd9534cc09ae37eb2b78771b95247b5satok private final String mSubtypeMode; 62ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok private final String mSubtypeExtraValue; 63e52eb4e289bf8d7b04582803b0d0f9ab7399c1afsatok private volatile HashMap<String, String> mExtraValueHashMapCache; 64ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok 65ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok /** 66dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * InputMethodSubtypeBuilder is a builder class of InputMethodSubtype. 67dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * This class is designed to be used with 68dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * {@link android.view.inputmethod.InputMethodManager#setAdditionalInputMethodSubtypes}. 69dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * The developer needs to be aware of what each parameter means. 70dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka */ 71dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka public static class InputMethodSubtypeBuilder { 72dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka /** 73dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * @param isAuxiliary should true when this subtype is auxiliary, false otherwise. 74dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * An auxiliary subtype has the following differences with a regular subtype: 75dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * - An auxiliary subtype cannot be chosen as the default IME in Settings. 76dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * - The framework will never switch to this subtype through 77dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * {@link android.view.inputmethod.InputMethodManager#switchToLastInputMethod}. 78dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * Note that the subtype will still be available in the IME switcher. 79dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * The intent is to allow for IMEs to specify they are meant to be invoked temporarily 80dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * in a one-shot way, and to return to the previous IME once finished (e.g. voice input). 81dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka */ 82dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka public InputMethodSubtypeBuilder setIsAuxiliary(boolean isAuxiliary) { 83dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka mIsAuxiliary = isAuxiliary; 84dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka return this; 85dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka } 86dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka private boolean mIsAuxiliary = false; 87dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka 88dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka /** 89dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * @param overridesImplicitlyEnabledSubtype should be true if this subtype should be 90dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * enabled by default if no other subtypes in the IME are enabled explicitly. Note that a 91dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * subtype with this parameter set will not be shown in the list of subtypes in each IME's 92dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * subtype enabler. A canonical use of this would be for an IME to supply an "automatic" 93dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * subtype that adapts to the current system language. 94dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka */ 95dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka public InputMethodSubtypeBuilder setOverridesImplicitlyEnabledSubtype( 96dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka boolean overridesImplicitlyEnabledSubtype) { 97dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka mOverridesImplicitlyEnabledSubtype = overridesImplicitlyEnabledSubtype; 98dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka return this; 99dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka } 100dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka private boolean mOverridesImplicitlyEnabledSubtype = false; 101dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka 102dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka /** 103dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * @param isAsciiCapable should be true if this subtype is ASCII capable. If the subtype 104dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * is ASCII capable, it should guarantee that the user can input ASCII characters with 105dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * this subtype. This is important because many password fields only allow 106dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * ASCII-characters. 107dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka */ 108dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka public InputMethodSubtypeBuilder setIsAsciiCapable(boolean isAsciiCapable) { 109dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka mIsAsciiCapable = isAsciiCapable; 110dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka return this; 111dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka } 112dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka private boolean mIsAsciiCapable = false; 113dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka 114dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka /** 115dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * @param subtypeIconResId is a resource ID of the subtype icon drawable. 116dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka */ 117dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka public InputMethodSubtypeBuilder setSubtypeIconResId(int subtypeIconResId) { 118dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka mSubtypeIconResId = subtypeIconResId; 119dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka return this; 120dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka } 121dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka private int mSubtypeIconResId = 0; 122dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka 123dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka /** 124dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * @param subtypeNameResId is the resource ID of the subtype name string. 125dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * The string resource may have exactly one %s in it. If present, 126dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * the %s part will be replaced with the locale's display name by 127dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * the formatter. Please refer to {@link #getDisplayName} for details. 128dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka */ 129dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka public InputMethodSubtypeBuilder setSubtypeNameResId(int subtypeNameResId) { 130dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka mSubtypeNameResId = subtypeNameResId; 131dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka return this; 132dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka } 133dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka private int mSubtypeNameResId = 0; 134dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka 135dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka /** 136dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * @param subtypeId is the unique ID for this subtype. The input method framework keeps 137dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * track of enabled subtypes by ID. When the IME package gets upgraded, enabled IDs will 138dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * stay enabled even if other attributes are different. If the ID is unspecified or 0, 139dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * Arrays.hashCode(new Object[] {locale, mode, extraValue, 140dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * isAuxiliary, overridesImplicitlyEnabledSubtype}) will be used instead. 141dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka */ 142dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka public InputMethodSubtypeBuilder setSubtypeId(int subtypeId) { 143dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka mSubtypeId = subtypeId; 144dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka return this; 145dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka } 146dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka private int mSubtypeId = 0; 147dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka 148dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka /** 149dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * @param subtypeLocale is the locale supported by this subtype. 150dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka */ 151dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka public InputMethodSubtypeBuilder setSubtypeLocale(String subtypeLocale) { 152dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka mSubtypeLocale = subtypeLocale == null ? "" : subtypeLocale; 153dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka return this; 154dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka } 155dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka private String mSubtypeLocale = ""; 156dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka 157dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka /** 158dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * @param subtypeMode is the mode supported by this subtype. 159dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka */ 160dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka public InputMethodSubtypeBuilder setSubtypeMode(String subtypeMode) { 161dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka mSubtypeMode = subtypeMode == null ? "" : subtypeMode; 162dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka return this; 163dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka } 164dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka private String mSubtypeMode = ""; 165dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka /** 166dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * @param subtypeExtraValue is the extra value of the subtype. This string is free-form, 167dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * but the API supplies tools to deal with a key-value comma-separated list; see 168dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * {@link #containsExtraValueKey} and {@link #getExtraValueOf}. 169dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka */ 170dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka public InputMethodSubtypeBuilder setSubtypeExtraValue(String subtypeExtraValue) { 171dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka mSubtypeExtraValue = subtypeExtraValue == null ? "" : subtypeExtraValue; 172dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka return this; 173dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka } 174dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka private String mSubtypeExtraValue = ""; 175dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka 176dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka /** 177dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * @return InputMethodSubtype using parameters in this InputMethodSubtypeBuilder. 178dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka */ 179dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka public InputMethodSubtype build() { 180dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka return new InputMethodSubtype(this); 181dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka } 182dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka } 183dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka 184dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka private static InputMethodSubtypeBuilder getBuilder(int nameId, int iconId, String locale, 185dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka String mode, String extraValue, boolean isAuxiliary, 186dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka boolean overridesImplicitlyEnabledSubtype, int id, boolean isAsciiCapable) { 187dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka final InputMethodSubtypeBuilder builder = new InputMethodSubtypeBuilder(); 188dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka builder.mSubtypeNameResId = nameId; 189dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka builder.mSubtypeIconResId = iconId; 190dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka builder.mSubtypeLocale = locale; 191dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka builder.mSubtypeMode = mode; 192dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka builder.mSubtypeExtraValue = extraValue; 193dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka builder.mIsAuxiliary = isAuxiliary; 194dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka builder.mOverridesImplicitlyEnabledSubtype = overridesImplicitlyEnabledSubtype; 195dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka builder.mSubtypeId = id; 196dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka builder.mIsAsciiCapable = isAsciiCapable; 197dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka return builder; 198dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka } 199dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka 200dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka /** 201e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka * Constructor with no subtype ID specified, overridesImplicitlyEnabledSubtype not specified. 202dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * Arguments for this constructor have the same meanings as 203dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * {@link InputMethodSubtype#InputMethodSubtype(int, int, String, String, String, boolean, 204dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * boolean, int)} except "id" and "overridesImplicitlyEnabledSubtype". 2053889e492bcad3c6f565d30da4e02d0dcde09d084satok * @hide 206ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok */ 207a86f5e448cd6d29340ca6cbe509bc6384bc0d711satok public InputMethodSubtype(int nameId, int iconId, String locale, String mode, String extraValue, 208a86f5e448cd6d29340ca6cbe509bc6384bc0d711satok boolean isAuxiliary) { 2098b83a7297680911d666546ee0b3a464514dc2c27Ken Wakasa this(nameId, iconId, locale, mode, extraValue, isAuxiliary, false); 2109aabb95781bee6a44684a6f6feb155e115d24983satok } 2119aabb95781bee6a44684a6f6feb155e115d24983satok 2129aabb95781bee6a44684a6f6feb155e115d24983satok /** 213e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka * Constructor with no subtype ID specified. 214dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * @deprecated use {@link InputMethodSubtypeBuilder} instead. 215dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * Arguments for this constructor have the same meanings as 216dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * {@link InputMethodSubtype#InputMethodSubtype(int, int, String, String, String, boolean, 217dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * boolean, int)} except "id". 2189aabb95781bee6a44684a6f6feb155e115d24983satok */ 219a9778d4d442db65344e32318b1fd43ab54898389satok public InputMethodSubtype(int nameId, int iconId, String locale, String mode, String extraValue, 220a86f5e448cd6d29340ca6cbe509bc6384bc0d711satok boolean isAuxiliary, boolean overridesImplicitlyEnabledSubtype) { 221e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka this(nameId, iconId, locale, mode, extraValue, isAuxiliary, 222e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka overridesImplicitlyEnabledSubtype, 0); 223e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka } 224e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka 225e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka /** 226e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka * Constructor. 227dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * @deprecated use {@link InputMethodSubtypeBuilder} instead. 228dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * "isAsciiCapable" is "false" in this constructor. 229e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka * @param nameId Resource ID of the subtype name string. The string resource may have exactly 230e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka * one %s in it. If there is, the %s part will be replaced with the locale's display name by 231e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka * the formatter. Please refer to {@link #getDisplayName} for details. 232e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka * @param iconId Resource ID of the subtype icon drawable. 233e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka * @param locale The locale supported by the subtype 234e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka * @param mode The mode supported by the subtype 235e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka * @param extraValue The extra value of the subtype. This string is free-form, but the API 236e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka * supplies tools to deal with a key-value comma-separated list; see 237e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka * {@link #containsExtraValueKey} and {@link #getExtraValueOf}. 238e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka * @param isAuxiliary true when this subtype is auxiliary, false otherwise. An auxiliary 239e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka * subtype will not be shown in the list of enabled IMEs for choosing the current IME in 240e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka * the Settings even when this subtype is enabled. Please note that this subtype will still 241e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka * be shown in the list of IMEs in the IME switcher to allow the user to tentatively switch 242e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka * to this subtype while an IME is shown. The framework will never switch the current IME to 243e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka * this subtype by {@link android.view.inputmethod.InputMethodManager#switchToLastInputMethod}. 244e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka * The intent of having this flag is to allow for IMEs that are invoked in a one-shot way as 245e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka * auxiliary input mode, and return to the previous IME once it is finished (e.g. voice input). 246e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka * @param overridesImplicitlyEnabledSubtype true when this subtype should be enabled by default 247e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka * if no other subtypes in the IME are enabled explicitly. Note that a subtype with this 248e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka * parameter being true will not be shown in the list of subtypes in each IME's subtype enabler. 249e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka * Having an "automatic" subtype is an example use of this flag. 250e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka * @param id The unique ID for the subtype. The input method framework keeps track of enabled 251e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka * subtypes by ID. When the IME package gets upgraded, enabled IDs will stay enabled even if 252e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka * other attributes are different. If the ID is unspecified or 0, 253e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka * Arrays.hashCode(new Object[] {locale, mode, extraValue, 254e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka * isAuxiliary, overridesImplicitlyEnabledSubtype}) will be used instead. 255e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka */ 256e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka public InputMethodSubtype(int nameId, int iconId, String locale, String mode, String extraValue, 257e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka boolean isAuxiliary, boolean overridesImplicitlyEnabledSubtype, int id) { 258dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka this(getBuilder(nameId, iconId, locale, mode, extraValue, isAuxiliary, 259dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka overridesImplicitlyEnabledSubtype, id, false)); 260dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka } 261dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka 262dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka /** 263dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * Constructor. 264dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * @param builder Builder for InputMethodSubtype 265dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka */ 266dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka private InputMethodSubtype(InputMethodSubtypeBuilder builder) { 267dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka mSubtypeNameResId = builder.mSubtypeNameResId; 268dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka mSubtypeIconResId = builder.mSubtypeIconResId; 269dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka mSubtypeLocale = builder.mSubtypeLocale; 270dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka mSubtypeMode = builder.mSubtypeMode; 271dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka mSubtypeExtraValue = builder.mSubtypeExtraValue; 272dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka mIsAuxiliary = builder.mIsAuxiliary; 273dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka mOverridesImplicitlyEnabledSubtype = builder.mOverridesImplicitlyEnabledSubtype; 274dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka mSubtypeId = builder.mSubtypeId; 275dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka mIsAsciiCapable = builder.mIsAsciiCapable; 276e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka // If hashCode() of this subtype is 0 and you want to specify it as an id of this subtype, 277e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka // just specify 0 as this subtype's id. Then, this subtype's id is treated as 0. 278dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka mSubtypeHashCode = mSubtypeId != 0 ? mSubtypeId : hashCodeInternal(mSubtypeLocale, 279dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka mSubtypeMode, mSubtypeExtraValue, mIsAuxiliary, mOverridesImplicitlyEnabledSubtype, 280dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka mIsAsciiCapable); 281ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok } 282ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok 283ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok InputMethodSubtype(Parcel source) { 284af4bf400abab86baee44dacbcdf13444d06ee46esatok String s; 285ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok mSubtypeNameResId = source.readInt(); 286ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok mSubtypeIconResId = source.readInt(); 287af4bf400abab86baee44dacbcdf13444d06ee46esatok s = source.readString(); 288af4bf400abab86baee44dacbcdf13444d06ee46esatok mSubtypeLocale = s != null ? s : ""; 289af4bf400abab86baee44dacbcdf13444d06ee46esatok s = source.readString(); 290af4bf400abab86baee44dacbcdf13444d06ee46esatok mSubtypeMode = s != null ? s : ""; 291af4bf400abab86baee44dacbcdf13444d06ee46esatok s = source.readString(); 292af4bf400abab86baee44dacbcdf13444d06ee46esatok mSubtypeExtraValue = s != null ? s : ""; 2939aabb95781bee6a44684a6f6feb155e115d24983satok mIsAuxiliary = (source.readInt() == 1); 294a86f5e448cd6d29340ca6cbe509bc6384bc0d711satok mOverridesImplicitlyEnabledSubtype = (source.readInt() == 1); 295e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka mSubtypeHashCode = source.readInt(); 296e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka mSubtypeId = source.readInt(); 297dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka mIsAsciiCapable = (source.readInt() == 1); 298ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok } 299ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok 300ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok /** 3019a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * @return Resource ID of the subtype name string. 302ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok */ 303ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok public int getNameResId() { 304ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok return mSubtypeNameResId; 305ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok } 306ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok 307ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok /** 3089a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * @return Resource ID of the subtype icon drawable. 309ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok */ 310ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok public int getIconResId() { 311ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok return mSubtypeIconResId; 312ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok } 313ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok 314ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok /** 3159a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * @return The locale of the subtype. This method returns the "locale" string parameter passed 3169a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * to the constructor. 317ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok */ 318ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok public String getLocale() { 319ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok return mSubtypeLocale; 320ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok } 321ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok 322ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok /** 3239a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * @return The mode of the subtype. 324ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok */ 3259ef0283bdcd9534cc09ae37eb2b78771b95247b5satok public String getMode() { 3269ef0283bdcd9534cc09ae37eb2b78771b95247b5satok return mSubtypeMode; 327ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok } 328ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok 329ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok /** 3309a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * @return The extra value of the subtype. 331ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok */ 332ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok public String getExtraValue() { 333ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok return mSubtypeExtraValue; 334ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok } 335ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok 3369aabb95781bee6a44684a6f6feb155e115d24983satok /** 3379a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * @return true if this subtype is auxiliary, false otherwise. An auxiliary subtype will not be 3389a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * shown in the list of enabled IMEs for choosing the current IME in the Settings even when this 3399a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * subtype is enabled. Please note that this subtype will still be shown in the list of IMEs in 3409a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * the IME switcher to allow the user to tentatively switch to this subtype while an IME is 3419a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * shown. The framework will never switch the current IME to this subtype by 3429a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * {@link android.view.inputmethod.InputMethodManager#switchToLastInputMethod}. 3439a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * The intent of having this flag is to allow for IMEs that are invoked in a one-shot way as 3449a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * auxiliary input mode, and return to the previous IME once it is finished (e.g. voice input). 3459aabb95781bee6a44684a6f6feb155e115d24983satok */ 3469aabb95781bee6a44684a6f6feb155e115d24983satok public boolean isAuxiliary() { 3479aabb95781bee6a44684a6f6feb155e115d24983satok return mIsAuxiliary; 3489aabb95781bee6a44684a6f6feb155e115d24983satok } 3499aabb95781bee6a44684a6f6feb155e115d24983satok 3504f31353cb3b00c77c9420ef27ec949fd570ede3bsatok /** 3519a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * @return true when this subtype will be enabled by default if no other subtypes in the IME 3529a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * are enabled explicitly, false otherwise. Note that a subtype with this method returning true 3539a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * will not be shown in the list of subtypes in each IME's subtype enabler. Having an 3549a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * "automatic" subtype is an example use of this flag. 355a86f5e448cd6d29340ca6cbe509bc6384bc0d711satok */ 356a86f5e448cd6d29340ca6cbe509bc6384bc0d711satok public boolean overridesImplicitlyEnabledSubtype() { 357a86f5e448cd6d29340ca6cbe509bc6384bc0d711satok return mOverridesImplicitlyEnabledSubtype; 358a86f5e448cd6d29340ca6cbe509bc6384bc0d711satok } 359a86f5e448cd6d29340ca6cbe509bc6384bc0d711satok 360a86f5e448cd6d29340ca6cbe509bc6384bc0d711satok /** 361dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * @return true if this subtype is Ascii capable, false otherwise. If the subtype is ASCII 362dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * capable, it should guarantee that the user can input ASCII characters with this subtype. 363dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka * This is important because many password fields only allow ASCII-characters. 364dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka */ 365dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka public boolean isAsciiCapable() { 366dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka return mIsAsciiCapable; 367dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka } 368dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka 369dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka /** 3704f31353cb3b00c77c9420ef27ec949fd570ede3bsatok * @param context Context will be used for getting Locale and PackageManager. 3714f31353cb3b00c77c9420ef27ec949fd570ede3bsatok * @param packageName The package name of the IME 3724f31353cb3b00c77c9420ef27ec949fd570ede3bsatok * @param appInfo The application info of the IME 3734f31353cb3b00c77c9420ef27ec949fd570ede3bsatok * @return a display name for this subtype. The string resource of the label (mSubtypeNameResId) 3749a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * may have exactly one %s in it. If there is, the %s part will be replaced with the locale's 3759a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * display name by the formatter. If there is not, this method returns the string specified by 3769a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * mSubtypeNameResId. If mSubtypeNameResId is not specified (== 0), it's up to the framework to 3779a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * generate an appropriate display name. 3784f31353cb3b00c77c9420ef27ec949fd570ede3bsatok */ 3794f31353cb3b00c77c9420ef27ec949fd570ede3bsatok public CharSequence getDisplayName( 3804f31353cb3b00c77c9420ef27ec949fd570ede3bsatok Context context, String packageName, ApplicationInfo appInfo) { 381a9778d4d442db65344e32318b1fd43ab54898389satok final Locale locale = constructLocaleFromString(mSubtypeLocale); 382a9778d4d442db65344e32318b1fd43ab54898389satok final String localeStr = locale != null ? locale.getDisplayName() : mSubtypeLocale; 3834f31353cb3b00c77c9420ef27ec949fd570ede3bsatok if (mSubtypeNameResId == 0) { 384a9778d4d442db65344e32318b1fd43ab54898389satok return localeStr; 3854f31353cb3b00c77c9420ef27ec949fd570ede3bsatok } 38635412d63ee59b99a43725e466c5deef52b2324dfsatok final CharSequence subtypeName = context.getPackageManager().getText( 38735412d63ee59b99a43725e466c5deef52b2324dfsatok packageName, mSubtypeNameResId, appInfo); 3884f31353cb3b00c77c9420ef27ec949fd570ede3bsatok if (!TextUtils.isEmpty(subtypeName)) { 38983e675f5ecf9f5615f3179ac102176faa3ae2596satok final String replacementString = 39083e675f5ecf9f5615f3179ac102176faa3ae2596satok containsExtraValueKey(EXTRA_KEY_UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME) 39183e675f5ecf9f5615f3179ac102176faa3ae2596satok ? getExtraValueOf(EXTRA_KEY_UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME) 39283e675f5ecf9f5615f3179ac102176faa3ae2596satok : localeStr; 39383e675f5ecf9f5615f3179ac102176faa3ae2596satok try { 39483e675f5ecf9f5615f3179ac102176faa3ae2596satok return String.format( 39583e675f5ecf9f5615f3179ac102176faa3ae2596satok subtypeName.toString(), replacementString != null ? replacementString : ""); 39683e675f5ecf9f5615f3179ac102176faa3ae2596satok } catch (IllegalFormatException e) { 39783e675f5ecf9f5615f3179ac102176faa3ae2596satok Slog.w(TAG, "Found illegal format in subtype name("+ subtypeName + "): " + e); 39883e675f5ecf9f5615f3179ac102176faa3ae2596satok return ""; 39983e675f5ecf9f5615f3179ac102176faa3ae2596satok } 4004f31353cb3b00c77c9420ef27ec949fd570ede3bsatok } else { 401a9778d4d442db65344e32318b1fd43ab54898389satok return localeStr; 4024f31353cb3b00c77c9420ef27ec949fd570ede3bsatok } 4034f31353cb3b00c77c9420ef27ec949fd570ede3bsatok } 4044f31353cb3b00c77c9420ef27ec949fd570ede3bsatok 4059c4cc03a354922df08efacfc486ef0e80144d3easatok private HashMap<String, String> getExtraValueHashMap() { 4069c4cc03a354922df08efacfc486ef0e80144d3easatok if (mExtraValueHashMapCache == null) { 407e52eb4e289bf8d7b04582803b0d0f9ab7399c1afsatok synchronized(this) { 408e52eb4e289bf8d7b04582803b0d0f9ab7399c1afsatok if (mExtraValueHashMapCache == null) { 409e52eb4e289bf8d7b04582803b0d0f9ab7399c1afsatok mExtraValueHashMapCache = new HashMap<String, String>(); 410e52eb4e289bf8d7b04582803b0d0f9ab7399c1afsatok final String[] pairs = mSubtypeExtraValue.split(EXTRA_VALUE_PAIR_SEPARATOR); 411e52eb4e289bf8d7b04582803b0d0f9ab7399c1afsatok final int N = pairs.length; 412e52eb4e289bf8d7b04582803b0d0f9ab7399c1afsatok for (int i = 0; i < N; ++i) { 413e52eb4e289bf8d7b04582803b0d0f9ab7399c1afsatok final String[] pair = pairs[i].split(EXTRA_VALUE_KEY_VALUE_SEPARATOR); 414e52eb4e289bf8d7b04582803b0d0f9ab7399c1afsatok if (pair.length == 1) { 415e52eb4e289bf8d7b04582803b0d0f9ab7399c1afsatok mExtraValueHashMapCache.put(pair[0], null); 416e52eb4e289bf8d7b04582803b0d0f9ab7399c1afsatok } else if (pair.length > 1) { 417e52eb4e289bf8d7b04582803b0d0f9ab7399c1afsatok if (pair.length > 2) { 418e52eb4e289bf8d7b04582803b0d0f9ab7399c1afsatok Slog.w(TAG, "ExtraValue has two or more '='s"); 419e52eb4e289bf8d7b04582803b0d0f9ab7399c1afsatok } 420e52eb4e289bf8d7b04582803b0d0f9ab7399c1afsatok mExtraValueHashMapCache.put(pair[0], pair[1]); 421e52eb4e289bf8d7b04582803b0d0f9ab7399c1afsatok } 4229c4cc03a354922df08efacfc486ef0e80144d3easatok } 4239c4cc03a354922df08efacfc486ef0e80144d3easatok } 4249c4cc03a354922df08efacfc486ef0e80144d3easatok } 4259c4cc03a354922df08efacfc486ef0e80144d3easatok } 4269c4cc03a354922df08efacfc486ef0e80144d3easatok return mExtraValueHashMapCache; 4279c4cc03a354922df08efacfc486ef0e80144d3easatok } 4289c4cc03a354922df08efacfc486ef0e80144d3easatok 4299c4cc03a354922df08efacfc486ef0e80144d3easatok /** 4309c4cc03a354922df08efacfc486ef0e80144d3easatok * The string of ExtraValue in subtype should be defined as follows: 4319c4cc03a354922df08efacfc486ef0e80144d3easatok * example: key0,key1=value1,key2,key3,key4=value4 4329a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * @param key The key of extra value 4339a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * @return The subtype contains specified the extra value 4349c4cc03a354922df08efacfc486ef0e80144d3easatok */ 4359c4cc03a354922df08efacfc486ef0e80144d3easatok public boolean containsExtraValueKey(String key) { 4369c4cc03a354922df08efacfc486ef0e80144d3easatok return getExtraValueHashMap().containsKey(key); 4379c4cc03a354922df08efacfc486ef0e80144d3easatok } 4389c4cc03a354922df08efacfc486ef0e80144d3easatok 4399c4cc03a354922df08efacfc486ef0e80144d3easatok /** 4409c4cc03a354922df08efacfc486ef0e80144d3easatok * The string of ExtraValue in subtype should be defined as follows: 4419c4cc03a354922df08efacfc486ef0e80144d3easatok * example: key0,key1=value1,key2,key3,key4=value4 4429a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * @param key The key of extra value 4439a74476c0ab1aaa59e9aed6ecdeba43d5b4d3495Ken Wakasa * @return The value of the specified key 4449c4cc03a354922df08efacfc486ef0e80144d3easatok */ 4459c4cc03a354922df08efacfc486ef0e80144d3easatok public String getExtraValueOf(String key) { 4469c4cc03a354922df08efacfc486ef0e80144d3easatok return getExtraValueHashMap().get(key); 4479c4cc03a354922df08efacfc486ef0e80144d3easatok } 4489c4cc03a354922df08efacfc486ef0e80144d3easatok 449ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok @Override 450ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok public int hashCode() { 451ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok return mSubtypeHashCode; 452ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok } 453ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok 454ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok @Override 455ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok public boolean equals(Object o) { 456ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok if (o instanceof InputMethodSubtype) { 457ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok InputMethodSubtype subtype = (InputMethodSubtype) o; 458e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka if (subtype.mSubtypeId != 0 || mSubtypeId != 0) { 459e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka return (subtype.hashCode() == hashCode()); 460e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka } 461af4bf400abab86baee44dacbcdf13444d06ee46esatok return (subtype.hashCode() == hashCode()) 462ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok && (subtype.getLocale().equals(getLocale())) 46392a6f3018ace5aa2d5ea74e7d378b6960b5e053eSatoshi Kataoka && (subtype.getMode().equals(getMode())) 464a9778d4d442db65344e32318b1fd43ab54898389satok && (subtype.getExtraValue().equals(getExtraValue())) 465dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka && (subtype.isAuxiliary() == isAuxiliary()) 46692a6f3018ace5aa2d5ea74e7d378b6960b5e053eSatoshi Kataoka && (subtype.overridesImplicitlyEnabledSubtype() 46792a6f3018ace5aa2d5ea74e7d378b6960b5e053eSatoshi Kataoka == overridesImplicitlyEnabledSubtype()) 468dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka && (subtype.isAsciiCapable() == isAsciiCapable()); 469ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok } 470ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok return false; 471ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok } 472ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok 4739aabb95781bee6a44684a6f6feb155e115d24983satok @Override 474ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok public int describeContents() { 475ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok return 0; 476ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok } 477ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok 4789aabb95781bee6a44684a6f6feb155e115d24983satok @Override 479ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok public void writeToParcel(Parcel dest, int parcelableFlags) { 480ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok dest.writeInt(mSubtypeNameResId); 481ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok dest.writeInt(mSubtypeIconResId); 482ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok dest.writeString(mSubtypeLocale); 4839ef0283bdcd9534cc09ae37eb2b78771b95247b5satok dest.writeString(mSubtypeMode); 484ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok dest.writeString(mSubtypeExtraValue); 4859aabb95781bee6a44684a6f6feb155e115d24983satok dest.writeInt(mIsAuxiliary ? 1 : 0); 486a86f5e448cd6d29340ca6cbe509bc6384bc0d711satok dest.writeInt(mOverridesImplicitlyEnabledSubtype ? 1 : 0); 487e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka dest.writeInt(mSubtypeHashCode); 488e62e6d8731ab1e02c1632ebc011792d07b902af8Satoshi Kataoka dest.writeInt(mSubtypeId); 489dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka dest.writeInt(mIsAsciiCapable ? 1 : 0); 490ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok } 491ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok 492ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok public static final Parcelable.Creator<InputMethodSubtype> CREATOR 493ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok = new Parcelable.Creator<InputMethodSubtype>() { 4949aabb95781bee6a44684a6f6feb155e115d24983satok @Override 495ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok public InputMethodSubtype createFromParcel(Parcel source) { 496ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok return new InputMethodSubtype(source); 497ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok } 498ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok 4999aabb95781bee6a44684a6f6feb155e115d24983satok @Override 500ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok public InputMethodSubtype[] newArray(int size) { 501ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok return new InputMethodSubtype[size]; 502ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok } 503ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok }; 504ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok 505a9778d4d442db65344e32318b1fd43ab54898389satok private static Locale constructLocaleFromString(String localeStr) { 506a9778d4d442db65344e32318b1fd43ab54898389satok if (TextUtils.isEmpty(localeStr)) 507a9778d4d442db65344e32318b1fd43ab54898389satok return null; 508a9778d4d442db65344e32318b1fd43ab54898389satok String[] localeParams = localeStr.split("_", 3); 509a9778d4d442db65344e32318b1fd43ab54898389satok // The length of localeStr is guaranteed to always return a 1 <= value <= 3 510a9778d4d442db65344e32318b1fd43ab54898389satok // because localeStr is not empty. 511a9778d4d442db65344e32318b1fd43ab54898389satok if (localeParams.length == 1) { 512a9778d4d442db65344e32318b1fd43ab54898389satok return new Locale(localeParams[0]); 513a9778d4d442db65344e32318b1fd43ab54898389satok } else if (localeParams.length == 2) { 514a9778d4d442db65344e32318b1fd43ab54898389satok return new Locale(localeParams[0], localeParams[1]); 515a9778d4d442db65344e32318b1fd43ab54898389satok } else if (localeParams.length == 3) { 516a9778d4d442db65344e32318b1fd43ab54898389satok return new Locale(localeParams[0], localeParams[1], localeParams[2]); 517a9778d4d442db65344e32318b1fd43ab54898389satok } 518a9778d4d442db65344e32318b1fd43ab54898389satok return null; 519a9778d4d442db65344e32318b1fd43ab54898389satok } 520a9778d4d442db65344e32318b1fd43ab54898389satok 521a9778d4d442db65344e32318b1fd43ab54898389satok private static int hashCodeInternal(String locale, String mode, String extraValue, 522dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka boolean isAuxiliary, boolean overridesImplicitlyEnabledSubtype, 523dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka boolean isAsciiCapable) { 524a86f5e448cd6d29340ca6cbe509bc6384bc0d711satok return Arrays.hashCode(new Object[] {locale, mode, extraValue, isAuxiliary, 525dc8abf6cee0bcf44e2cad8155f0c151105d46471Satoshi Kataoka overridesImplicitlyEnabledSubtype, isAsciiCapable}); 526ab751aa085433e9f735d2e7603459c6c7e9d2fb0satok } 5277265d9bd6d80c5bedaa6de2b80f6619a301a07c8satok 5287265d9bd6d80c5bedaa6de2b80f6619a301a07c8satok /** 5297265d9bd6d80c5bedaa6de2b80f6619a301a07c8satok * Sort the list of InputMethodSubtype 5307265d9bd6d80c5bedaa6de2b80f6619a301a07c8satok * @param context Context will be used for getting localized strings from IME 5317265d9bd6d80c5bedaa6de2b80f6619a301a07c8satok * @param flags Flags for the sort order 5327265d9bd6d80c5bedaa6de2b80f6619a301a07c8satok * @param imi InputMethodInfo of which subtypes are subject to be sorted 5337265d9bd6d80c5bedaa6de2b80f6619a301a07c8satok * @param subtypeList List of InputMethodSubtype which will be sorted 5347265d9bd6d80c5bedaa6de2b80f6619a301a07c8satok * @return Sorted list of subtypes 5357265d9bd6d80c5bedaa6de2b80f6619a301a07c8satok * @hide 5367265d9bd6d80c5bedaa6de2b80f6619a301a07c8satok */ 5377265d9bd6d80c5bedaa6de2b80f6619a301a07c8satok public static List<InputMethodSubtype> sort(Context context, int flags, InputMethodInfo imi, 5387265d9bd6d80c5bedaa6de2b80f6619a301a07c8satok List<InputMethodSubtype> subtypeList) { 5397265d9bd6d80c5bedaa6de2b80f6619a301a07c8satok if (imi == null) return subtypeList; 5407265d9bd6d80c5bedaa6de2b80f6619a301a07c8satok final HashSet<InputMethodSubtype> inputSubtypesSet = new HashSet<InputMethodSubtype>( 5417265d9bd6d80c5bedaa6de2b80f6619a301a07c8satok subtypeList); 5427265d9bd6d80c5bedaa6de2b80f6619a301a07c8satok final ArrayList<InputMethodSubtype> sortedList = new ArrayList<InputMethodSubtype>(); 5437265d9bd6d80c5bedaa6de2b80f6619a301a07c8satok int N = imi.getSubtypeCount(); 5447265d9bd6d80c5bedaa6de2b80f6619a301a07c8satok for (int i = 0; i < N; ++i) { 5457265d9bd6d80c5bedaa6de2b80f6619a301a07c8satok InputMethodSubtype subtype = imi.getSubtypeAt(i); 5467265d9bd6d80c5bedaa6de2b80f6619a301a07c8satok if (inputSubtypesSet.contains(subtype)) { 5477265d9bd6d80c5bedaa6de2b80f6619a301a07c8satok sortedList.add(subtype); 5487265d9bd6d80c5bedaa6de2b80f6619a301a07c8satok inputSubtypesSet.remove(subtype); 5497265d9bd6d80c5bedaa6de2b80f6619a301a07c8satok } 5507265d9bd6d80c5bedaa6de2b80f6619a301a07c8satok } 5517265d9bd6d80c5bedaa6de2b80f6619a301a07c8satok // If subtypes in inputSubtypesSet remain, that means these subtypes are not 5527265d9bd6d80c5bedaa6de2b80f6619a301a07c8satok // contained in imi, so the remaining subtypes will be appended. 5537265d9bd6d80c5bedaa6de2b80f6619a301a07c8satok for (InputMethodSubtype subtype: inputSubtypesSet) { 5547265d9bd6d80c5bedaa6de2b80f6619a301a07c8satok sortedList.add(subtype); 5557265d9bd6d80c5bedaa6de2b80f6619a301a07c8satok } 5567265d9bd6d80c5bedaa6de2b80f6619a301a07c8satok return sortedList; 5577265d9bd6d80c5bedaa6de2b80f6619a301a07c8satok } 558af4bf400abab86baee44dacbcdf13444d06ee46esatok} 559