Refactor SubtypeLocaleUtils a bit
Change-Id: If8b7fd5ef0b4ff3791deeacc12abb256a10176bfmain
parent
9eec53a2c2
commit
58e830ec19
|
@ -365,18 +365,12 @@
|
||||||
(Compact) can be an abbreviation to fit in the CHAR LIMIT.
|
(Compact) can be an abbreviation to fit in the CHAR LIMIT.
|
||||||
TODO: Remove translatable=false once we are settled down with the naming. -->
|
TODO: Remove translatable=false once we are settled down with the naming. -->
|
||||||
<string name="subtype_generic_compact" translatable="false"><xliff:g id="LANGUAGE_NAME" example="Hindi">%s</xliff:g> (Compact)</string>
|
<string name="subtype_generic_compact" translatable="false"><xliff:g id="LANGUAGE_NAME" example="Hindi">%s</xliff:g> (Compact)</string>
|
||||||
<!-- TODO: Uncomment once we can handle IETF language tag with script name specified.
|
<!-- Description for "LANGUAGE_NAME" (Cyrillic) keyboard subtype [CHAR LIMIT=25]
|
||||||
Description for Serbian Cyrillic keyboard subtype [CHAR LIMIT=25]
|
(Cyrillic) can be an abbreviation to fit in the CHAR LIMIT. -->
|
||||||
(Cyrillic) can be an abbreviation to fit in the CHAR LIMIT.
|
<string name="subtype_generic_cyrillic"><xliff:g id="LANGUAGE_NAME" example="Serbian">%s</xliff:g> (Cyrillic)</string>
|
||||||
<string name="subtype_serbian_cyrillic">Serbian (Cyrillic)</string>
|
<!-- Description for "LANGUAGE_NAME" (Latin) keyboard subtype [CHAR LIMIT=25]
|
||||||
Description for Serbian Latin keyboard subtype [CHAR LIMIT=25]
|
(Latin) can be an abbreviation to fit in the CHAR LIMIT. -->
|
||||||
(Latin) can be an abbreviation to fit in the CHAR LIMIT.
|
<string name="subtype_generic_latin"><xliff:g id="LANGUAGE_NAME" example="Serbian">%s</xliff:g> (Latin)</string>
|
||||||
<string name="subtype_serbian_latin">Serbian (Latin)</string>
|
|
||||||
Description for Serbian Latin keyboard subtype with explicit keyboard layout [CHAR LIMIT=25]
|
|
||||||
(Latin) can be an abbreviation to fit in the CHAR LIMIT.
|
|
||||||
This should be identical to subtype_serbian_latin aside from the trailing (%s).
|
|
||||||
<string name="subtype_with_layout_sr-Latn">Serbian (Latin) (<xliff:g id="KEYBOARD_LAYOUT" example="QWERTY">%s</xliff:g>)</string>
|
|
||||||
-->
|
|
||||||
<!-- This string is displayed in a language list that allows to choose a language for
|
<!-- This string is displayed in a language list that allows to choose a language for
|
||||||
suggestions in a software keyboard. This setting won't give suggestions in any particular
|
suggestions in a software keyboard. This setting won't give suggestions in any particular
|
||||||
language, hence "No language".
|
language, hence "No language".
|
||||||
|
|
|
@ -18,8 +18,6 @@ package com.android.inputmethod.latin.utils;
|
||||||
|
|
||||||
import android.view.inputmethod.InputMethodSubtype;
|
import android.view.inputmethod.InputMethodSubtype;
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
public final class SpacebarLanguageUtils {
|
public final class SpacebarLanguageUtils {
|
||||||
private SpacebarLanguageUtils() {
|
private SpacebarLanguageUtils() {
|
||||||
// Intentional empty constructor for utility class.
|
// Intentional empty constructor for utility class.
|
||||||
|
@ -55,7 +53,6 @@ public final class SpacebarLanguageUtils {
|
||||||
if (SubtypeLocaleUtils.isNoLanguage(subtype)) {
|
if (SubtypeLocaleUtils.isNoLanguage(subtype)) {
|
||||||
return SubtypeLocaleUtils.getKeyboardLayoutSetDisplayName(subtype);
|
return SubtypeLocaleUtils.getKeyboardLayoutSetDisplayName(subtype);
|
||||||
}
|
}
|
||||||
final Locale locale = SubtypeLocaleUtils.getSubtypeLocale(subtype);
|
return SubtypeLocaleUtils.getSubtypeLanguageDisplayName(subtype.getLocale());
|
||||||
return SubtypeLocaleUtils.getSubtypeLocaleDisplayName(locale.getLanguage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ import android.os.Build;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.inputmethod.InputMethodSubtype;
|
import android.view.inputmethod.InputMethodSubtype;
|
||||||
|
|
||||||
import com.android.inputmethod.latin.DictionaryFactory;
|
import com.android.inputmethod.latin.Constants;
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -33,10 +33,10 @@ import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
public final class SubtypeLocaleUtils {
|
public final class SubtypeLocaleUtils {
|
||||||
static final String TAG = SubtypeLocaleUtils.class.getSimpleName();
|
private static final String TAG = SubtypeLocaleUtils.class.getSimpleName();
|
||||||
// This class must be located in the same package as LatinIME.java.
|
|
||||||
private static final String RESOURCE_PACKAGE_NAME =
|
// This reference class {@link Constants} must be located in the same package as LatinIME.java.
|
||||||
DictionaryFactory.class.getPackage().getName();
|
private static final String RESOURCE_PACKAGE_NAME = Constants.class.getPackage().getName();
|
||||||
|
|
||||||
// Special language code to represent "no language".
|
// Special language code to represent "no language".
|
||||||
public static final String NO_LANGUAGE = "zz";
|
public static final String NO_LANGUAGE = "zz";
|
||||||
|
@ -44,7 +44,8 @@ public final class SubtypeLocaleUtils {
|
||||||
public static final String EMOJI = "emoji";
|
public static final String EMOJI = "emoji";
|
||||||
public static final int UNKNOWN_KEYBOARD_LAYOUT = R.string.subtype_generic;
|
public static final int UNKNOWN_KEYBOARD_LAYOUT = R.string.subtype_generic;
|
||||||
|
|
||||||
private static boolean sInitialized = false;
|
private static volatile boolean sInitialized = false;
|
||||||
|
private static final Object sInitializeLock = new Object();
|
||||||
private static Resources sResources;
|
private static Resources sResources;
|
||||||
private static String[] sPredefinedKeyboardLayoutSet;
|
private static String[] sPredefinedKeyboardLayoutSet;
|
||||||
// Keyboard layout to its display name map.
|
// Keyboard layout to its display name map.
|
||||||
|
@ -77,9 +78,16 @@ public final class SubtypeLocaleUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note that this initialization method can be called multiple times.
|
// Note that this initialization method can be called multiple times.
|
||||||
public static synchronized void init(final Context context) {
|
public static void init(final Context context) {
|
||||||
if (sInitialized) return;
|
synchronized (sInitializeLock) {
|
||||||
|
if (sInitialized == false) {
|
||||||
|
initLocked(context);
|
||||||
|
sInitialized = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void initLocked(final Context context) {
|
||||||
final Resources res = context.getResources();
|
final Resources res = context.getResources();
|
||||||
sResources = res;
|
sResources = res;
|
||||||
|
|
||||||
|
@ -122,8 +130,6 @@ public final class SubtypeLocaleUtils {
|
||||||
final String keyboardLayoutSet = keyboardLayoutSetMap[i + 1];
|
final String keyboardLayoutSet = keyboardLayoutSetMap[i + 1];
|
||||||
sLocaleAndExtraValueToKeyboardLayoutSetMap.put(key, keyboardLayoutSet);
|
sLocaleAndExtraValueToKeyboardLayoutSetMap.put(key, keyboardLayoutSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
sInitialized = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String[] getPredefinedKeyboardLayoutSet() {
|
public static String[] getPredefinedKeyboardLayoutSet() {
|
||||||
|
@ -167,8 +173,18 @@ public final class SubtypeLocaleUtils {
|
||||||
return getSubtypeLocaleDisplayNameInternal(localeString, displayLocale);
|
return getSubtypeLocaleDisplayNameInternal(localeString, displayLocale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getSubtypeLanguageDisplayName(final String localeString) {
|
||||||
|
final Locale locale = LocaleUtils.constructLocaleFromString(localeString);
|
||||||
|
final Locale displayLocale = getDisplayLocaleOfSubtypeLocale(localeString);
|
||||||
|
return getSubtypeLocaleDisplayNameInternal(locale.getLanguage(), displayLocale);
|
||||||
|
}
|
||||||
|
|
||||||
private static String getSubtypeLocaleDisplayNameInternal(final String localeString,
|
private static String getSubtypeLocaleDisplayNameInternal(final String localeString,
|
||||||
final Locale displayLocale) {
|
final Locale displayLocale) {
|
||||||
|
if (NO_LANGUAGE.equals(localeString)) {
|
||||||
|
// No language subtype should be displayed in system locale.
|
||||||
|
return sResources.getString(R.string.subtype_no_language);
|
||||||
|
}
|
||||||
final Integer exceptionalNameResId = sExceptionalLocaleToNameIdsMap.get(localeString);
|
final Integer exceptionalNameResId = sExceptionalLocaleToNameIdsMap.get(localeString);
|
||||||
final String displayName;
|
final String displayName;
|
||||||
if (exceptionalNameResId != null) {
|
if (exceptionalNameResId != null) {
|
||||||
|
@ -179,9 +195,6 @@ public final class SubtypeLocaleUtils {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
displayName = getExceptionalName.runInLocale(sResources, displayLocale);
|
displayName = getExceptionalName.runInLocale(sResources, displayLocale);
|
||||||
} else if (NO_LANGUAGE.equals(localeString)) {
|
|
||||||
// No language subtype should be displayed in system locale.
|
|
||||||
return sResources.getString(R.string.subtype_no_language);
|
|
||||||
} else {
|
} else {
|
||||||
final Locale locale = LocaleUtils.constructLocaleFromString(localeString);
|
final Locale locale = LocaleUtils.constructLocaleFromString(localeString);
|
||||||
displayName = locale.getDisplayName(displayLocale);
|
displayName = locale.getDisplayName(displayLocale);
|
||||||
|
|
Loading…
Reference in New Issue