2011-01-14 07:12:36 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011 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.
|
|
|
|
*/
|
|
|
|
|
2013-07-24 01:37:07 +00:00
|
|
|
package com.android.inputmethod.latin.utils;
|
2011-01-14 07:12:36 +00:00
|
|
|
|
2014-10-23 09:37:32 +00:00
|
|
|
import static com.android.inputmethod.latin.common.Constants.Subtype.ExtraValue.COMBINING_RULES;
|
|
|
|
import static com.android.inputmethod.latin.common.Constants.Subtype.ExtraValue.KEYBOARD_LAYOUT_SET;
|
|
|
|
import static com.android.inputmethod.latin.common.Constants.Subtype.ExtraValue.UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME;
|
2012-04-19 03:42:13 +00:00
|
|
|
|
2011-01-14 07:12:36 +00:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.res.Resources;
|
2012-05-06 16:47:14 +00:00
|
|
|
import android.os.Build;
|
2012-05-05 07:33:51 +00:00
|
|
|
import android.util.Log;
|
2012-04-13 04:07:28 +00:00
|
|
|
import android.view.inputmethod.InputMethodSubtype;
|
|
|
|
|
2013-07-24 01:37:07 +00:00
|
|
|
import com.android.inputmethod.latin.R;
|
2014-11-06 11:29:29 +00:00
|
|
|
import com.android.inputmethod.latin.common.LocaleUtils;
|
2014-10-28 12:31:09 +00:00
|
|
|
import com.android.inputmethod.latin.common.StringUtils;
|
2012-05-05 07:14:04 +00:00
|
|
|
|
2012-04-11 09:21:10 +00:00
|
|
|
import java.util.HashMap;
|
2011-01-14 07:12:36 +00:00
|
|
|
import java.util.Locale;
|
|
|
|
|
2014-11-06 04:16:20 +00:00
|
|
|
import javax.annotation.Nonnull;
|
2014-11-19 02:57:49 +00:00
|
|
|
import javax.annotation.Nullable;
|
2014-11-06 04:16:20 +00:00
|
|
|
|
2014-08-25 04:42:15 +00:00
|
|
|
/**
|
|
|
|
* A helper class to deal with subtype locales.
|
|
|
|
*/
|
|
|
|
// TODO: consolidate this into RichInputMethodSubtype
|
2013-07-24 01:37:07 +00:00
|
|
|
public final class SubtypeLocaleUtils {
|
2014-10-20 05:48:56 +00:00
|
|
|
static final String TAG = SubtypeLocaleUtils.class.getSimpleName();
|
2014-04-10 08:00:37 +00:00
|
|
|
|
2014-10-23 09:37:32 +00:00
|
|
|
// This reference class {@link R} must be located in the same package as LatinIME.java.
|
|
|
|
private static final String RESOURCE_PACKAGE_NAME = R.class.getPackage().getName();
|
2012-04-13 07:41:24 +00:00
|
|
|
|
2012-04-03 03:50:28 +00:00
|
|
|
// Special language code to represent "no language".
|
2012-04-18 06:44:34 +00:00
|
|
|
public static final String NO_LANGUAGE = "zz";
|
2012-04-20 09:25:05 +00:00
|
|
|
public static final String QWERTY = "qwerty";
|
2013-08-28 00:01:52 +00:00
|
|
|
public static final String EMOJI = "emoji";
|
2012-04-25 04:10:21 +00:00
|
|
|
public static final int UNKNOWN_KEYBOARD_LAYOUT = R.string.subtype_generic;
|
|
|
|
|
2014-04-10 08:00:37 +00:00
|
|
|
private static volatile boolean sInitialized = false;
|
|
|
|
private static final Object sInitializeLock = new Object();
|
2013-01-23 07:23:11 +00:00
|
|
|
private static Resources sResources;
|
2012-04-20 09:25:05 +00:00
|
|
|
// Keyboard layout to its display name map.
|
2014-05-23 11:18:17 +00:00
|
|
|
private static final HashMap<String, String> sKeyboardLayoutToDisplayNameMap = new HashMap<>();
|
2012-04-20 09:25:05 +00:00
|
|
|
// Keyboard layout to subtype name resource id map.
|
2014-05-23 11:18:17 +00:00
|
|
|
private static final HashMap<String, Integer> sKeyboardLayoutToNameIdsMap = new HashMap<>();
|
2014-08-21 05:58:41 +00:00
|
|
|
// Exceptional locale whose name should be displayed in Locale.ROOT.
|
2014-10-06 03:18:45 +00:00
|
|
|
private static final HashMap<String, Integer> sExceptionalLocaleDisplayedInRootLocale =
|
|
|
|
new HashMap<>();
|
2012-05-06 16:47:14 +00:00
|
|
|
// Exceptional locale to subtype name resource id map.
|
2014-05-23 11:18:17 +00:00
|
|
|
private static final HashMap<String, Integer> sExceptionalLocaleToNameIdsMap = new HashMap<>();
|
2013-01-23 06:41:43 +00:00
|
|
|
// Exceptional locale to subtype name with layout resource id map.
|
2012-05-06 16:47:14 +00:00
|
|
|
private static final HashMap<String, Integer> sExceptionalLocaleToWithLayoutNameIdsMap =
|
2014-05-23 11:18:17 +00:00
|
|
|
new HashMap<>();
|
2013-01-23 06:41:43 +00:00
|
|
|
private static final String SUBTYPE_NAME_RESOURCE_PREFIX =
|
|
|
|
"string/subtype_";
|
2012-04-25 05:17:49 +00:00
|
|
|
private static final String SUBTYPE_NAME_RESOURCE_GENERIC_PREFIX =
|
|
|
|
"string/subtype_generic_";
|
2012-05-06 16:47:14 +00:00
|
|
|
private static final String SUBTYPE_NAME_RESOURCE_WITH_LAYOUT_PREFIX =
|
|
|
|
"string/subtype_with_layout_";
|
2012-04-25 05:17:49 +00:00
|
|
|
private static final String SUBTYPE_NAME_RESOURCE_NO_LANGUAGE_PREFIX =
|
|
|
|
"string/subtype_no_language_";
|
2014-10-06 03:18:45 +00:00
|
|
|
private static final String SUBTYPE_NAME_RESOURCE_IN_ROOT_LOCALE_PREFIX =
|
|
|
|
"string/subtype_in_root_locale_";
|
2012-06-28 03:03:11 +00:00
|
|
|
// Keyboard layout set name for the subtypes that don't have a keyboardLayoutSet extra value.
|
|
|
|
// This is for compatibility to keep the same subtype ids as pre-JellyBean.
|
2013-01-23 06:41:43 +00:00
|
|
|
private static final HashMap<String, String> sLocaleAndExtraValueToKeyboardLayoutSetMap =
|
2014-05-23 11:18:17 +00:00
|
|
|
new HashMap<>();
|
2012-04-13 04:07:28 +00:00
|
|
|
|
2013-07-24 01:37:07 +00:00
|
|
|
private SubtypeLocaleUtils() {
|
2011-01-14 07:12:36 +00:00
|
|
|
// Intentional empty constructor for utility class.
|
|
|
|
}
|
|
|
|
|
2012-07-04 09:22:40 +00:00
|
|
|
// Note that this initialization method can be called multiple times.
|
2014-04-10 08:00:37 +00:00
|
|
|
public static void init(final Context context) {
|
|
|
|
synchronized (sInitializeLock) {
|
|
|
|
if (sInitialized == false) {
|
|
|
|
initLocked(context);
|
|
|
|
sInitialized = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-04 09:22:40 +00:00
|
|
|
|
2014-04-10 08:00:37 +00:00
|
|
|
private static void initLocked(final Context context) {
|
2011-01-14 07:12:36 +00:00
|
|
|
final Resources res = context.getResources();
|
2013-01-23 07:23:11 +00:00
|
|
|
sResources = res;
|
2012-04-20 09:25:05 +00:00
|
|
|
|
|
|
|
final String[] predefinedLayoutSet = res.getStringArray(R.array.predefined_layouts);
|
|
|
|
final String[] layoutDisplayNames = res.getStringArray(
|
|
|
|
R.array.predefined_layout_display_names);
|
|
|
|
for (int i = 0; i < predefinedLayoutSet.length; i++) {
|
|
|
|
final String layoutName = predefinedLayoutSet[i];
|
2012-05-06 16:47:14 +00:00
|
|
|
sKeyboardLayoutToDisplayNameMap.put(layoutName, layoutDisplayNames[i]);
|
2012-04-25 05:17:49 +00:00
|
|
|
final String resourceName = SUBTYPE_NAME_RESOURCE_GENERIC_PREFIX + layoutName;
|
2012-04-20 09:25:05 +00:00
|
|
|
final int resId = res.getIdentifier(resourceName, null, RESOURCE_PACKAGE_NAME);
|
|
|
|
sKeyboardLayoutToNameIdsMap.put(layoutName, resId);
|
2012-04-25 05:17:49 +00:00
|
|
|
// Register subtype name resource id of "No language" with key "zz_<layout>"
|
|
|
|
final String noLanguageResName = SUBTYPE_NAME_RESOURCE_NO_LANGUAGE_PREFIX + layoutName;
|
|
|
|
final int noLanguageResId = res.getIdentifier(
|
|
|
|
noLanguageResName, null, RESOURCE_PACKAGE_NAME);
|
|
|
|
final String key = getNoLanguageLayoutKey(layoutName);
|
|
|
|
sKeyboardLayoutToNameIdsMap.put(key, noLanguageResId);
|
2012-04-20 09:25:05 +00:00
|
|
|
}
|
|
|
|
|
2014-08-25 04:42:15 +00:00
|
|
|
final String[] exceptionalLocaleInRootLocale = res.getStringArray(
|
2014-08-21 05:58:41 +00:00
|
|
|
R.array.subtype_locale_displayed_in_root_locale);
|
2014-08-25 04:42:15 +00:00
|
|
|
for (int i = 0; i < exceptionalLocaleInRootLocale.length; i++) {
|
2014-10-06 03:18:45 +00:00
|
|
|
final String localeString = exceptionalLocaleInRootLocale[i];
|
|
|
|
final String resourceName = SUBTYPE_NAME_RESOURCE_IN_ROOT_LOCALE_PREFIX + localeString;
|
|
|
|
final int resId = res.getIdentifier(resourceName, null, RESOURCE_PACKAGE_NAME);
|
|
|
|
sExceptionalLocaleDisplayedInRootLocale.put(localeString, resId);
|
2014-08-21 05:58:41 +00:00
|
|
|
}
|
|
|
|
|
2012-04-20 09:25:05 +00:00
|
|
|
final String[] exceptionalLocales = res.getStringArray(
|
|
|
|
R.array.subtype_locale_exception_keys);
|
|
|
|
for (int i = 0; i < exceptionalLocales.length; i++) {
|
2012-05-06 16:47:14 +00:00
|
|
|
final String localeString = exceptionalLocales[i];
|
2013-01-23 06:41:43 +00:00
|
|
|
final String resourceName = SUBTYPE_NAME_RESOURCE_PREFIX + localeString;
|
2012-05-06 16:47:14 +00:00
|
|
|
final int resId = res.getIdentifier(resourceName, null, RESOURCE_PACKAGE_NAME);
|
2013-01-23 06:41:43 +00:00
|
|
|
sExceptionalLocaleToNameIdsMap.put(localeString, resId);
|
|
|
|
final String resourceNameWithLayout =
|
|
|
|
SUBTYPE_NAME_RESOURCE_WITH_LAYOUT_PREFIX + localeString;
|
|
|
|
final int resIdWithLayout = res.getIdentifier(
|
|
|
|
resourceNameWithLayout, null, RESOURCE_PACKAGE_NAME);
|
|
|
|
sExceptionalLocaleToWithLayoutNameIdsMap.put(localeString, resIdWithLayout);
|
2011-01-14 07:12:36 +00:00
|
|
|
}
|
2012-06-28 03:03:11 +00:00
|
|
|
|
|
|
|
final String[] keyboardLayoutSetMap = res.getStringArray(
|
|
|
|
R.array.locale_and_extra_value_to_keyboard_layout_set_map);
|
2013-03-25 03:37:04 +00:00
|
|
|
for (int i = 0; i + 1 < keyboardLayoutSetMap.length; i += 2) {
|
2012-06-28 03:03:11 +00:00
|
|
|
final String key = keyboardLayoutSetMap[i];
|
|
|
|
final String keyboardLayoutSet = keyboardLayoutSetMap[i + 1];
|
|
|
|
sLocaleAndExtraValueToKeyboardLayoutSetMap.put(key, keyboardLayoutSet);
|
|
|
|
}
|
2012-04-03 03:50:28 +00:00
|
|
|
}
|
|
|
|
|
2013-01-23 07:23:11 +00:00
|
|
|
public static boolean isExceptionalLocale(final String localeString) {
|
2013-01-23 06:41:43 +00:00
|
|
|
return sExceptionalLocaleToNameIdsMap.containsKey(localeString);
|
2012-05-06 16:47:14 +00:00
|
|
|
}
|
|
|
|
|
2013-01-23 07:23:11 +00:00
|
|
|
private static final String getNoLanguageLayoutKey(final String keyboardLayoutName) {
|
2012-04-25 05:17:49 +00:00
|
|
|
return NO_LANGUAGE + "_" + keyboardLayoutName;
|
2012-04-20 09:25:05 +00:00
|
|
|
}
|
|
|
|
|
2013-01-23 07:23:11 +00:00
|
|
|
public static int getSubtypeNameId(final String localeString, final String keyboardLayoutName) {
|
2013-01-06 02:10:27 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN
|
|
|
|
&& isExceptionalLocale(localeString)) {
|
2012-05-06 16:47:14 +00:00
|
|
|
return sExceptionalLocaleToWithLayoutNameIdsMap.get(localeString);
|
|
|
|
}
|
2013-01-25 04:11:51 +00:00
|
|
|
final String key = NO_LANGUAGE.equals(localeString)
|
2012-04-25 05:17:49 +00:00
|
|
|
? getNoLanguageLayoutKey(keyboardLayoutName)
|
|
|
|
: keyboardLayoutName;
|
|
|
|
final Integer nameId = sKeyboardLayoutToNameIdsMap.get(key);
|
|
|
|
return nameId == null ? UNKNOWN_KEYBOARD_LAYOUT : nameId;
|
|
|
|
}
|
2012-04-13 07:41:24 +00:00
|
|
|
|
2014-11-06 04:16:20 +00:00
|
|
|
@Nonnull
|
|
|
|
public static Locale getDisplayLocaleOfSubtypeLocale(@Nonnull final String localeString) {
|
2013-01-25 04:11:51 +00:00
|
|
|
if (NO_LANGUAGE.equals(localeString)) {
|
|
|
|
return sResources.getConfiguration().locale;
|
|
|
|
}
|
2014-10-06 03:18:45 +00:00
|
|
|
if (sExceptionalLocaleDisplayedInRootLocale.containsKey(localeString)) {
|
2014-08-21 05:58:41 +00:00
|
|
|
return Locale.ROOT;
|
|
|
|
}
|
2013-01-25 04:11:51 +00:00
|
|
|
return LocaleUtils.constructLocaleFromString(localeString);
|
|
|
|
}
|
|
|
|
|
2014-11-06 04:16:20 +00:00
|
|
|
public static String getSubtypeLocaleDisplayNameInSystemLocale(
|
|
|
|
@Nonnull final String localeString) {
|
2013-01-23 06:41:43 +00:00
|
|
|
final Locale displayLocale = sResources.getConfiguration().locale;
|
|
|
|
return getSubtypeLocaleDisplayNameInternal(localeString, displayLocale);
|
|
|
|
}
|
|
|
|
|
2014-11-06 04:16:20 +00:00
|
|
|
@Nonnull
|
|
|
|
public static String getSubtypeLocaleDisplayName(@Nonnull final String localeString) {
|
2013-01-25 04:11:51 +00:00
|
|
|
final Locale displayLocale = getDisplayLocaleOfSubtypeLocale(localeString);
|
2013-01-23 06:41:43 +00:00
|
|
|
return getSubtypeLocaleDisplayNameInternal(localeString, displayLocale);
|
|
|
|
}
|
|
|
|
|
2014-11-06 04:16:20 +00:00
|
|
|
@Nonnull
|
|
|
|
public static String getSubtypeLanguageDisplayName(@Nonnull final String localeString) {
|
2014-04-10 08:00:37 +00:00
|
|
|
final Locale displayLocale = getDisplayLocaleOfSubtypeLocale(localeString);
|
2014-08-21 05:58:41 +00:00
|
|
|
final String languageString;
|
2014-10-06 03:18:45 +00:00
|
|
|
if (sExceptionalLocaleDisplayedInRootLocale.containsKey(localeString)) {
|
2014-08-21 05:58:41 +00:00
|
|
|
languageString = localeString;
|
|
|
|
} else {
|
2014-11-17 09:07:35 +00:00
|
|
|
languageString = LocaleUtils.constructLocaleFromString(localeString).getLanguage();
|
2014-08-21 05:58:41 +00:00
|
|
|
}
|
|
|
|
return getSubtypeLocaleDisplayNameInternal(languageString, displayLocale);
|
2014-04-10 08:00:37 +00:00
|
|
|
}
|
|
|
|
|
2014-11-06 04:16:20 +00:00
|
|
|
@Nonnull
|
|
|
|
private static String getSubtypeLocaleDisplayNameInternal(@Nonnull final String localeString,
|
|
|
|
@Nonnull final Locale displayLocale) {
|
2014-04-10 08:00:37 +00:00
|
|
|
if (NO_LANGUAGE.equals(localeString)) {
|
|
|
|
// No language subtype should be displayed in system locale.
|
|
|
|
return sResources.getString(R.string.subtype_no_language);
|
|
|
|
}
|
2014-10-06 03:18:45 +00:00
|
|
|
final Integer exceptionalNameResId;
|
|
|
|
if (displayLocale.equals(Locale.ROOT)
|
|
|
|
&& sExceptionalLocaleDisplayedInRootLocale.containsKey(localeString)) {
|
|
|
|
exceptionalNameResId = sExceptionalLocaleDisplayedInRootLocale.get(localeString);
|
|
|
|
} else if (sExceptionalLocaleToNameIdsMap.containsKey(localeString)) {
|
|
|
|
exceptionalNameResId = sExceptionalLocaleToNameIdsMap.get(localeString);
|
|
|
|
} else {
|
|
|
|
exceptionalNameResId = null;
|
|
|
|
}
|
|
|
|
|
2013-01-23 06:41:43 +00:00
|
|
|
final String displayName;
|
|
|
|
if (exceptionalNameResId != null) {
|
|
|
|
final RunInLocale<String> getExceptionalName = new RunInLocale<String>() {
|
|
|
|
@Override
|
|
|
|
protected String job(final Resources res) {
|
|
|
|
return res.getString(exceptionalNameResId);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
displayName = getExceptionalName.runInLocale(sResources, displayLocale);
|
|
|
|
} else {
|
2014-11-17 09:07:35 +00:00
|
|
|
displayName = LocaleUtils.constructLocaleFromString(localeString)
|
|
|
|
.getDisplayName(displayLocale);
|
2013-01-23 06:41:43 +00:00
|
|
|
}
|
2013-04-10 08:13:26 +00:00
|
|
|
return StringUtils.capitalizeFirstCodePoint(displayName, displayLocale);
|
2012-04-03 03:50:28 +00:00
|
|
|
}
|
|
|
|
|
2012-04-25 05:17:49 +00:00
|
|
|
// InputMethodSubtype's display name in its locale.
|
|
|
|
// isAdditionalSubtype (T=true, F=false)
|
2012-11-19 02:25:30 +00:00
|
|
|
// locale layout | display name
|
|
|
|
// ------ ------- - ----------------------
|
|
|
|
// en_US qwerty F English (US) exception
|
|
|
|
// en_GB qwerty F English (UK) exception
|
|
|
|
// es_US spanish F Español (EE.UU.) exception
|
|
|
|
// fr azerty F Français
|
|
|
|
// fr_CA qwerty F Français (Canada)
|
2013-12-13 08:09:16 +00:00
|
|
|
// fr_CH swiss F Français (Suisse)
|
2012-11-19 02:25:30 +00:00
|
|
|
// de qwertz F Deutsch
|
2013-12-13 08:09:16 +00:00
|
|
|
// de_CH swiss T Deutsch (Schweiz)
|
2014-03-28 02:09:44 +00:00
|
|
|
// zz qwerty F Alphabet (QWERTY) in system locale
|
2012-11-19 02:25:30 +00:00
|
|
|
// fr qwertz T Français (QWERTZ)
|
|
|
|
// de qwerty T Deutsch (QWERTY)
|
2013-01-23 06:41:43 +00:00
|
|
|
// en_US azerty T English (US) (AZERTY) exception
|
2014-03-28 02:09:44 +00:00
|
|
|
// zz azerty T Alphabet (AZERTY) in system locale
|
2012-04-25 05:17:49 +00:00
|
|
|
|
2014-11-06 04:16:20 +00:00
|
|
|
@Nonnull
|
|
|
|
private static String getReplacementString(@Nonnull final InputMethodSubtype subtype,
|
|
|
|
@Nonnull final Locale displayLocale) {
|
2013-01-23 07:23:11 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN
|
|
|
|
&& subtype.containsExtraValueKey(UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME)) {
|
|
|
|
return subtype.getExtraValueOf(UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME);
|
|
|
|
}
|
2014-10-20 05:48:56 +00:00
|
|
|
return getSubtypeLocaleDisplayNameInternal(subtype.getLocale(), displayLocale);
|
2013-01-23 07:23:11 +00:00
|
|
|
}
|
|
|
|
|
2014-11-06 04:16:20 +00:00
|
|
|
@Nonnull
|
|
|
|
public static String getSubtypeDisplayNameInSystemLocale(
|
|
|
|
@Nonnull final InputMethodSubtype subtype) {
|
2013-01-25 04:11:51 +00:00
|
|
|
final Locale displayLocale = sResources.getConfiguration().locale;
|
|
|
|
return getSubtypeDisplayNameInternal(subtype, displayLocale);
|
2013-01-23 06:41:43 +00:00
|
|
|
}
|
|
|
|
|
2014-11-06 04:16:20 +00:00
|
|
|
@Nonnull
|
2014-11-19 02:57:49 +00:00
|
|
|
public static String getSubtypeNameForLogging(@Nullable final InputMethodSubtype subtype) {
|
2013-07-23 02:03:18 +00:00
|
|
|
if (subtype == null) {
|
|
|
|
return "<null subtype>";
|
|
|
|
}
|
|
|
|
return getSubtypeLocale(subtype) + "/" + getKeyboardLayoutSetName(subtype);
|
2013-01-23 06:41:43 +00:00
|
|
|
}
|
|
|
|
|
2014-11-06 04:16:20 +00:00
|
|
|
@Nonnull
|
|
|
|
private static String getSubtypeDisplayNameInternal(@Nonnull final InputMethodSubtype subtype,
|
|
|
|
@Nonnull final Locale displayLocale) {
|
2013-01-23 06:41:43 +00:00
|
|
|
final String replacementString = getReplacementString(subtype, displayLocale);
|
2014-08-25 04:42:15 +00:00
|
|
|
// TODO: rework this for multi-lingual subtypes
|
2012-05-05 07:14:04 +00:00
|
|
|
final int nameResId = subtype.getNameResId();
|
|
|
|
final RunInLocale<String> getSubtypeName = new RunInLocale<String>() {
|
|
|
|
@Override
|
2013-01-23 06:41:43 +00:00
|
|
|
protected String job(final Resources res) {
|
2012-05-05 07:33:51 +00:00
|
|
|
try {
|
2012-05-06 16:47:14 +00:00
|
|
|
return res.getString(nameResId, replacementString);
|
2012-05-05 07:33:51 +00:00
|
|
|
} catch (Resources.NotFoundException e) {
|
|
|
|
// TODO: Remove this catch when InputMethodManager.getCurrentInputMethodSubtype
|
|
|
|
// is fixed.
|
|
|
|
Log.w(TAG, "Unknown subtype: mode=" + subtype.getMode()
|
2013-01-25 04:11:51 +00:00
|
|
|
+ " nameResId=" + subtype.getNameResId()
|
2012-05-05 07:33:51 +00:00
|
|
|
+ " locale=" + subtype.getLocale()
|
|
|
|
+ " extra=" + subtype.getExtraValue()
|
2013-06-25 08:03:05 +00:00
|
|
|
+ "\n" + DebugLogUtils.getStackTrace());
|
2012-05-05 07:33:51 +00:00
|
|
|
return "";
|
|
|
|
}
|
2012-05-05 07:14:04 +00:00
|
|
|
}
|
|
|
|
};
|
2013-04-10 08:13:26 +00:00
|
|
|
return StringUtils.capitalizeFirstCodePoint(
|
2013-01-25 04:11:51 +00:00
|
|
|
getSubtypeName.runInLocale(sResources, displayLocale), displayLocale);
|
2012-04-04 09:18:56 +00:00
|
|
|
}
|
2012-04-13 04:07:28 +00:00
|
|
|
|
2014-11-06 04:16:20 +00:00
|
|
|
@Nonnull
|
|
|
|
public static Locale getSubtypeLocale(@Nonnull final InputMethodSubtype subtype) {
|
2012-04-11 09:21:10 +00:00
|
|
|
final String localeString = subtype.getLocale();
|
2014-08-25 04:42:15 +00:00
|
|
|
return LocaleUtils.constructLocaleFromString(localeString);
|
2012-04-13 04:07:28 +00:00
|
|
|
}
|
|
|
|
|
2014-11-06 04:16:20 +00:00
|
|
|
@Nonnull
|
|
|
|
public static String getKeyboardLayoutSetDisplayName(
|
|
|
|
@Nonnull final InputMethodSubtype subtype) {
|
2012-04-19 11:16:35 +00:00
|
|
|
final String layoutName = getKeyboardLayoutSetName(subtype);
|
2012-05-06 16:47:14 +00:00
|
|
|
return getKeyboardLayoutSetDisplayName(layoutName);
|
|
|
|
}
|
|
|
|
|
2014-11-06 04:16:20 +00:00
|
|
|
@Nonnull
|
|
|
|
public static String getKeyboardLayoutSetDisplayName(@Nonnull final String layoutName) {
|
2012-05-06 16:47:14 +00:00
|
|
|
return sKeyboardLayoutToDisplayNameMap.get(layoutName);
|
2012-04-17 09:55:51 +00:00
|
|
|
}
|
|
|
|
|
2014-11-06 04:16:20 +00:00
|
|
|
@Nonnull
|
2013-01-23 07:23:11 +00:00
|
|
|
public static String getKeyboardLayoutSetName(final InputMethodSubtype subtype) {
|
2012-06-28 03:03:11 +00:00
|
|
|
String keyboardLayoutSet = subtype.getExtraValueOf(KEYBOARD_LAYOUT_SET);
|
|
|
|
if (keyboardLayoutSet == null) {
|
|
|
|
// This subtype doesn't have a keyboardLayoutSet extra value, so lookup its keyboard
|
|
|
|
// layout set in sLocaleAndExtraValueToKeyboardLayoutSetMap to keep it compatible with
|
|
|
|
// pre-JellyBean.
|
|
|
|
final String key = subtype.getLocale() + ":" + subtype.getExtraValue();
|
|
|
|
keyboardLayoutSet = sLocaleAndExtraValueToKeyboardLayoutSetMap.get(key);
|
|
|
|
}
|
2012-04-13 04:07:28 +00:00
|
|
|
// TODO: Remove this null check when InputMethodManager.getCurrentInputMethodSubtype is
|
|
|
|
// fixed.
|
2012-04-13 07:41:24 +00:00
|
|
|
if (keyboardLayoutSet == null) {
|
|
|
|
android.util.Log.w(TAG, "KeyboardLayoutSet not found, use QWERTY: " +
|
2012-04-19 11:21:02 +00:00
|
|
|
"locale=" + subtype.getLocale() + " extraValue=" + subtype.getExtraValue());
|
2012-04-20 09:25:05 +00:00
|
|
|
return QWERTY;
|
2012-04-13 07:41:24 +00:00
|
|
|
}
|
2012-04-11 09:21:10 +00:00
|
|
|
return keyboardLayoutSet;
|
2012-04-13 04:07:28 +00:00
|
|
|
}
|
2013-07-23 02:03:18 +00:00
|
|
|
|
2014-05-08 05:53:56 +00:00
|
|
|
public static String getCombiningRulesExtraValue(final InputMethodSubtype subtype) {
|
2014-10-23 09:37:32 +00:00
|
|
|
return subtype.getExtraValueOf(COMBINING_RULES);
|
2014-05-08 05:53:56 +00:00
|
|
|
}
|
2011-01-14 07:12:36 +00:00
|
|
|
}
|