Refactor SubtypeLocale to hold Resources
Change-Id: Ia667bc2d406d66c87215dd3b9569f36f4642cfe0main
parent
40651c8cf7
commit
4b3cae9b0c
|
@ -1371,7 +1371,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
||||||
private String layoutLanguageOnSpacebar(final Paint paint, final InputMethodSubtype subtype,
|
private String layoutLanguageOnSpacebar(final Paint paint, final InputMethodSubtype subtype,
|
||||||
final int width) {
|
final int width) {
|
||||||
// Choose appropriate language name to fit into the width.
|
// Choose appropriate language name to fit into the width.
|
||||||
final String fullText = getFullDisplayName(subtype, getResources());
|
final String fullText = getFullDisplayName(subtype);
|
||||||
if (fitsTextIntoWidth(width, fullText, paint)) {
|
if (fitsTextIntoWidth(width, fullText, paint)) {
|
||||||
return fullText;
|
return fullText;
|
||||||
}
|
}
|
||||||
|
@ -1445,12 +1445,12 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
||||||
// zz azerty T AZERTY AZERTY
|
// zz azerty T AZERTY AZERTY
|
||||||
|
|
||||||
// Get InputMethodSubtype's full display name in its locale.
|
// Get InputMethodSubtype's full display name in its locale.
|
||||||
static String getFullDisplayName(final InputMethodSubtype subtype, final Resources res) {
|
static String getFullDisplayName(final InputMethodSubtype subtype) {
|
||||||
if (SubtypeLocale.isNoLanguage(subtype)) {
|
if (SubtypeLocale.isNoLanguage(subtype)) {
|
||||||
return SubtypeLocale.getKeyboardLayoutSetDisplayName(subtype);
|
return SubtypeLocale.getKeyboardLayoutSetDisplayName(subtype);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SubtypeLocale.getSubtypeDisplayName(subtype, res);
|
return SubtypeLocale.getSubtypeDisplayName(subtype);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get InputMethodSubtype's short display name in its locale.
|
// Get InputMethodSubtype's short display name in its locale.
|
||||||
|
|
|
@ -103,7 +103,7 @@ public final class AdditionalSubtypeSettings extends PreferenceFragment {
|
||||||
if (DEBUG_SUBTYPE_ID) {
|
if (DEBUG_SUBTYPE_ID) {
|
||||||
android.util.Log.d(TAG, String.format("%-6s 0x%08x %11d %s",
|
android.util.Log.d(TAG, String.format("%-6s 0x%08x %11d %s",
|
||||||
subtype.getLocale(), subtype.hashCode(), subtype.hashCode(),
|
subtype.getLocale(), subtype.hashCode(), subtype.hashCode(),
|
||||||
SubtypeLocale.getSubtypeDisplayName(subtype, context.getResources())));
|
SubtypeLocale.getSubtypeDisplayName(subtype)));
|
||||||
}
|
}
|
||||||
if (subtype.containsExtraValueKey(ASCII_CAPABLE)) {
|
if (subtype.containsExtraValueKey(ASCII_CAPABLE)) {
|
||||||
items.add(createItem(context, subtype.getLocale()));
|
items.add(createItem(context, subtype.getLocale()));
|
||||||
|
@ -205,8 +205,7 @@ public final class AdditionalSubtypeSettings extends PreferenceFragment {
|
||||||
setDialogTitle(R.string.add_style);
|
setDialogTitle(R.string.add_style);
|
||||||
setKey(KEY_NEW_SUBTYPE);
|
setKey(KEY_NEW_SUBTYPE);
|
||||||
} else {
|
} else {
|
||||||
final String displayName = SubtypeLocale.getSubtypeDisplayName(
|
final String displayName = SubtypeLocale.getSubtypeDisplayName(subtype);
|
||||||
subtype, getContext().getResources());
|
|
||||||
setTitle(displayName);
|
setTitle(displayName);
|
||||||
setDialogTitle(displayName);
|
setDialogTitle(displayName);
|
||||||
setKey(KEY_PREFIX + subtype.getLocale() + "_"
|
setKey(KEY_PREFIX + subtype.getLocale() + "_"
|
||||||
|
@ -498,7 +497,7 @@ public final class AdditionalSubtypeSettings extends PreferenceFragment {
|
||||||
final Context context = getActivity();
|
final Context context = getActivity();
|
||||||
final Resources res = context.getResources();
|
final Resources res = context.getResources();
|
||||||
final String message = res.getString(R.string.custom_input_style_already_exists,
|
final String message = res.getString(R.string.custom_input_style_already_exists,
|
||||||
SubtypeLocale.getSubtypeDisplayName(subtype, res));
|
SubtypeLocale.getSubtypeDisplayName(subtype));
|
||||||
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -236,7 +236,7 @@ public final class SettingsFragment extends InputMethodSettingsFragment
|
||||||
final StringBuilder styles = new StringBuilder();
|
final StringBuilder styles = new StringBuilder();
|
||||||
for (final InputMethodSubtype subtype : subtypes) {
|
for (final InputMethodSubtype subtype : subtypes) {
|
||||||
if (styles.length() > 0) styles.append(", ");
|
if (styles.length() > 0) styles.append(", ");
|
||||||
styles.append(SubtypeLocale.getSubtypeDisplayName(subtype, res));
|
styles.append(SubtypeLocale.getSubtypeDisplayName(subtype));
|
||||||
}
|
}
|
||||||
customInputStyles.setSummary(styles);
|
customInputStyles.setSummary(styles);
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ public final class SubtypeLocale {
|
||||||
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 boolean sInitialized = false;
|
||||||
|
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.
|
||||||
private static final HashMap<String, String> sKeyboardLayoutToDisplayNameMap =
|
private static final HashMap<String, String> sKeyboardLayoutToDisplayNameMap =
|
||||||
|
@ -71,10 +72,11 @@ public final class SubtypeLocale {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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(Context context) {
|
public static synchronized void init(final Context context) {
|
||||||
if (sInitialized) return;
|
if (sInitialized) return;
|
||||||
|
|
||||||
final Resources res = context.getResources();
|
final Resources res = context.getResources();
|
||||||
|
sResources = res;
|
||||||
|
|
||||||
final String[] predefinedLayoutSet = res.getStringArray(R.array.predefined_layouts);
|
final String[] predefinedLayoutSet = res.getStringArray(R.array.predefined_layouts);
|
||||||
sPredefinedKeyboardLayoutSet = predefinedLayoutSet;
|
sPredefinedKeyboardLayoutSet = predefinedLayoutSet;
|
||||||
|
@ -121,15 +123,15 @@ public final class SubtypeLocale {
|
||||||
return sPredefinedKeyboardLayoutSet;
|
return sPredefinedKeyboardLayoutSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isExceptionalLocale(String localeString) {
|
public static boolean isExceptionalLocale(final String localeString) {
|
||||||
return sExceptionalLocaleToWithLayoutNameIdsMap.containsKey(localeString);
|
return sExceptionalLocaleToWithLayoutNameIdsMap.containsKey(localeString);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String getNoLanguageLayoutKey(String keyboardLayoutName) {
|
private static final String getNoLanguageLayoutKey(final String keyboardLayoutName) {
|
||||||
return NO_LANGUAGE + "_" + keyboardLayoutName;
|
return NO_LANGUAGE + "_" + keyboardLayoutName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getSubtypeNameId(String localeString, String keyboardLayoutName) {
|
public static int getSubtypeNameId(final String localeString, final String keyboardLayoutName) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN
|
||||||
&& isExceptionalLocale(localeString)) {
|
&& isExceptionalLocale(localeString)) {
|
||||||
return sExceptionalLocaleToWithLayoutNameIdsMap.get(localeString);
|
return sExceptionalLocaleToWithLayoutNameIdsMap.get(localeString);
|
||||||
|
@ -141,7 +143,7 @@ public final class SubtypeLocale {
|
||||||
return nameId == null ? UNKNOWN_KEYBOARD_LAYOUT : nameId;
|
return nameId == null ? UNKNOWN_KEYBOARD_LAYOUT : nameId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getSubtypeLocaleDisplayName(String localeString) {
|
public static String getSubtypeLocaleDisplayName(final String localeString) {
|
||||||
final String exceptionalValue = sExceptionalDisplayNamesMap.get(localeString);
|
final String exceptionalValue = sExceptionalDisplayNamesMap.get(localeString);
|
||||||
if (exceptionalValue != null) {
|
if (exceptionalValue != null) {
|
||||||
return exceptionalValue;
|
return exceptionalValue;
|
||||||
|
@ -166,12 +168,17 @@ public final class SubtypeLocale {
|
||||||
// en_US azerty T English (US) (AZERTY)
|
// en_US azerty T English (US) (AZERTY)
|
||||||
// zz azerty T No language (AZERTY) in system locale
|
// zz azerty T No language (AZERTY) in system locale
|
||||||
|
|
||||||
public static String getSubtypeDisplayName(final InputMethodSubtype subtype, Resources res) {
|
private static String getReplacementString(final InputMethodSubtype subtype) {
|
||||||
final String replacementString =
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN
|
||||||
(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN
|
&& subtype.containsExtraValueKey(UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME)) {
|
||||||
&& subtype.containsExtraValueKey(UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME))
|
return subtype.getExtraValueOf(UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME);
|
||||||
? subtype.getExtraValueOf(UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME)
|
} else {
|
||||||
: getSubtypeLocaleDisplayName(subtype.getLocale());
|
return getSubtypeLocaleDisplayName(subtype.getLocale());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getSubtypeDisplayName(final InputMethodSubtype subtype) {
|
||||||
|
final String replacementString = getReplacementString(subtype);
|
||||||
final int nameResId = subtype.getNameResId();
|
final int nameResId = subtype.getNameResId();
|
||||||
final RunInLocale<String> getSubtypeName = new RunInLocale<String>() {
|
final RunInLocale<String> getSubtypeName = new RunInLocale<String>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -190,30 +197,30 @@ public final class SubtypeLocale {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
final Locale locale = isNoLanguage(subtype)
|
final Locale locale = isNoLanguage(subtype)
|
||||||
? res.getConfiguration().locale : getSubtypeLocale(subtype);
|
? sResources.getConfiguration().locale : getSubtypeLocale(subtype);
|
||||||
return getSubtypeName.runInLocale(res, locale);
|
return getSubtypeName.runInLocale(sResources, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isNoLanguage(InputMethodSubtype subtype) {
|
public static boolean isNoLanguage(final InputMethodSubtype subtype) {
|
||||||
final String localeString = subtype.getLocale();
|
final String localeString = subtype.getLocale();
|
||||||
return localeString.equals(NO_LANGUAGE);
|
return localeString.equals(NO_LANGUAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Locale getSubtypeLocale(InputMethodSubtype subtype) {
|
public static Locale getSubtypeLocale(final InputMethodSubtype subtype) {
|
||||||
final String localeString = subtype.getLocale();
|
final String localeString = subtype.getLocale();
|
||||||
return LocaleUtils.constructLocaleFromString(localeString);
|
return LocaleUtils.constructLocaleFromString(localeString);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getKeyboardLayoutSetDisplayName(InputMethodSubtype subtype) {
|
public static String getKeyboardLayoutSetDisplayName(final InputMethodSubtype subtype) {
|
||||||
final String layoutName = getKeyboardLayoutSetName(subtype);
|
final String layoutName = getKeyboardLayoutSetName(subtype);
|
||||||
return getKeyboardLayoutSetDisplayName(layoutName);
|
return getKeyboardLayoutSetDisplayName(layoutName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getKeyboardLayoutSetDisplayName(String layoutName) {
|
public static String getKeyboardLayoutSetDisplayName(final String layoutName) {
|
||||||
return sKeyboardLayoutToDisplayNameMap.get(layoutName);
|
return sKeyboardLayoutToDisplayNameMap.get(layoutName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getKeyboardLayoutSetName(InputMethodSubtype subtype) {
|
public static String getKeyboardLayoutSetName(final InputMethodSubtype subtype) {
|
||||||
String keyboardLayoutSet = subtype.getExtraValueOf(KEYBOARD_LAYOUT_SET);
|
String keyboardLayoutSet = subtype.getExtraValueOf(KEYBOARD_LAYOUT_SET);
|
||||||
if (keyboardLayoutSet == null) {
|
if (keyboardLayoutSet == null) {
|
||||||
// This subtype doesn't have a keyboardLayoutSet extra value, so lookup its keyboard
|
// This subtype doesn't have a keyboardLayoutSet extra value, so lookup its keyboard
|
||||||
|
|
|
@ -151,8 +151,7 @@ public final class SubtypeSwitcher {
|
||||||
// Update the current subtype. LatinIME.onCurrentInputMethodSubtypeChanged calls this function.
|
// Update the current subtype. LatinIME.onCurrentInputMethodSubtypeChanged calls this function.
|
||||||
public void onSubtypeChanged(final InputMethodSubtype newSubtype) {
|
public void onSubtypeChanged(final InputMethodSubtype newSubtype) {
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
Log.w(TAG, "onSubtypeChanged: " + SubtypeLocale.getSubtypeDisplayName(
|
Log.w(TAG, "onSubtypeChanged: " + SubtypeLocale.getSubtypeDisplayName(newSubtype));
|
||||||
newSubtype, mResources));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final Locale newLocale = SubtypeLocale.getSubtypeLocale(newSubtype);
|
final Locale newLocale = SubtypeLocale.getSubtypeLocale(newSubtype);
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
package com.android.inputmethod.keyboard;
|
package com.android.inputmethod.keyboard;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.test.AndroidTestCase;
|
import android.test.AndroidTestCase;
|
||||||
import android.view.inputmethod.InputMethodSubtype;
|
import android.view.inputmethod.InputMethodSubtype;
|
||||||
|
|
||||||
|
@ -35,7 +34,6 @@ public class SpacebarTextTests extends AndroidTestCase {
|
||||||
private final ArrayList<InputMethodSubtype> mSubtypesList = CollectionUtils.newArrayList();
|
private final ArrayList<InputMethodSubtype> mSubtypesList = CollectionUtils.newArrayList();
|
||||||
|
|
||||||
private RichInputMethodManager mRichImm;
|
private RichInputMethodManager mRichImm;
|
||||||
private Resources mRes;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
|
@ -43,14 +41,13 @@ public class SpacebarTextTests extends AndroidTestCase {
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
RichInputMethodManager.init(context);
|
RichInputMethodManager.init(context);
|
||||||
mRichImm = RichInputMethodManager.getInstance();
|
mRichImm = RichInputMethodManager.getInstance();
|
||||||
mRes = context.getResources();
|
|
||||||
SubtypeLocale.init(context);
|
SubtypeLocale.init(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAllFullDisplayName() {
|
public void testAllFullDisplayName() {
|
||||||
for (final InputMethodSubtype subtype : mSubtypesList) {
|
for (final InputMethodSubtype subtype : mSubtypesList) {
|
||||||
final String subtypeName = SubtypeLocale.getSubtypeDisplayName(subtype, mRes);
|
final String subtypeName = SubtypeLocale.getSubtypeDisplayName(subtype);
|
||||||
final String spacebarText = MainKeyboardView.getFullDisplayName(subtype, mRes);
|
final String spacebarText = MainKeyboardView.getFullDisplayName(subtype);
|
||||||
final String languageName =
|
final String languageName =
|
||||||
SubtypeLocale.getSubtypeLocaleDisplayName(subtype.getLocale());
|
SubtypeLocale.getSubtypeLocaleDisplayName(subtype.getLocale());
|
||||||
if (SubtypeLocale.isNoLanguage(subtype)) {
|
if (SubtypeLocale.isNoLanguage(subtype)) {
|
||||||
|
@ -63,7 +60,7 @@ public class SpacebarTextTests extends AndroidTestCase {
|
||||||
|
|
||||||
public void testAllMiddleDisplayName() {
|
public void testAllMiddleDisplayName() {
|
||||||
for (final InputMethodSubtype subtype : mSubtypesList) {
|
for (final InputMethodSubtype subtype : mSubtypesList) {
|
||||||
final String subtypeName = SubtypeLocale.getSubtypeDisplayName(subtype, mRes);
|
final String subtypeName = SubtypeLocale.getSubtypeDisplayName(subtype);
|
||||||
final String spacebarText = MainKeyboardView.getMiddleDisplayName(subtype);
|
final String spacebarText = MainKeyboardView.getMiddleDisplayName(subtype);
|
||||||
if (SubtypeLocale.isNoLanguage(subtype)) {
|
if (SubtypeLocale.isNoLanguage(subtype)) {
|
||||||
assertEquals(subtypeName,
|
assertEquals(subtypeName,
|
||||||
|
@ -78,7 +75,7 @@ public class SpacebarTextTests extends AndroidTestCase {
|
||||||
|
|
||||||
public void testAllShortDisplayName() {
|
public void testAllShortDisplayName() {
|
||||||
for (final InputMethodSubtype subtype : mSubtypesList) {
|
for (final InputMethodSubtype subtype : mSubtypesList) {
|
||||||
final String subtypeName = SubtypeLocale.getSubtypeDisplayName(subtype, mRes);
|
final String subtypeName = SubtypeLocale.getSubtypeDisplayName(subtype);
|
||||||
final Locale locale = SubtypeLocale.getSubtypeLocale(subtype);
|
final Locale locale = SubtypeLocale.getSubtypeLocale(subtype);
|
||||||
final String spacebarText = MainKeyboardView.getShortDisplayName(subtype);
|
final String spacebarText = MainKeyboardView.getShortDisplayName(subtype);
|
||||||
final String languageCode = StringUtils.toTitleCase(locale.getLanguage(), locale);
|
final String languageCode = StringUtils.toTitleCase(locale.getLanguage(), locale);
|
||||||
|
@ -120,17 +117,17 @@ public class SpacebarTextTests extends AndroidTestCase {
|
||||||
SubtypeLocale.NO_LANGUAGE, "qwerty");
|
SubtypeLocale.NO_LANGUAGE, "qwerty");
|
||||||
|
|
||||||
assertEquals("en_US", "English (US)",
|
assertEquals("en_US", "English (US)",
|
||||||
MainKeyboardView.getFullDisplayName(EN_US, mRes));
|
MainKeyboardView.getFullDisplayName(EN_US));
|
||||||
assertEquals("en_GB", "English (UK)",
|
assertEquals("en_GB", "English (UK)",
|
||||||
MainKeyboardView.getFullDisplayName(EN_GB, mRes));
|
MainKeyboardView.getFullDisplayName(EN_GB));
|
||||||
assertEquals("fr ", "Français",
|
assertEquals("fr ", "Français",
|
||||||
MainKeyboardView.getFullDisplayName(FR, mRes));
|
MainKeyboardView.getFullDisplayName(FR));
|
||||||
assertEquals("fr_CA", "Français (Canada)",
|
assertEquals("fr_CA", "Français (Canada)",
|
||||||
MainKeyboardView.getFullDisplayName(FR_CA, mRes));
|
MainKeyboardView.getFullDisplayName(FR_CA));
|
||||||
assertEquals("de ", "Deutsch",
|
assertEquals("de ", "Deutsch",
|
||||||
MainKeyboardView.getFullDisplayName(DE, mRes));
|
MainKeyboardView.getFullDisplayName(DE));
|
||||||
assertEquals("zz ", "QWERTY",
|
assertEquals("zz ", "QWERTY",
|
||||||
MainKeyboardView.getFullDisplayName(ZZ, mRes));
|
MainKeyboardView.getFullDisplayName(ZZ));
|
||||||
|
|
||||||
assertEquals("en_US", "English", MainKeyboardView.getMiddleDisplayName(EN_US));
|
assertEquals("en_US", "English", MainKeyboardView.getMiddleDisplayName(EN_US));
|
||||||
assertEquals("en_GB", "English", MainKeyboardView.getMiddleDisplayName(EN_GB));
|
assertEquals("en_GB", "English", MainKeyboardView.getMiddleDisplayName(EN_GB));
|
||||||
|
@ -158,13 +155,13 @@ public class SpacebarTextTests extends AndroidTestCase {
|
||||||
SubtypeLocale.NO_LANGUAGE, "azerty", null);
|
SubtypeLocale.NO_LANGUAGE, "azerty", null);
|
||||||
|
|
||||||
assertEquals("fr qwertz", "Français (QWERTZ)",
|
assertEquals("fr qwertz", "Français (QWERTZ)",
|
||||||
MainKeyboardView.getFullDisplayName(FR_QWERTZ, mRes));
|
MainKeyboardView.getFullDisplayName(FR_QWERTZ));
|
||||||
assertEquals("de qwerty", "Deutsch (QWERTY)",
|
assertEquals("de qwerty", "Deutsch (QWERTY)",
|
||||||
MainKeyboardView.getFullDisplayName(DE_QWERTY, mRes));
|
MainKeyboardView.getFullDisplayName(DE_QWERTY));
|
||||||
assertEquals("en_US azerty", "English (US) (AZERTY)",
|
assertEquals("en_US azerty", "English (US) (AZERTY)",
|
||||||
MainKeyboardView.getFullDisplayName(US_AZERTY, mRes));
|
MainKeyboardView.getFullDisplayName(US_AZERTY));
|
||||||
assertEquals("zz azerty", "AZERTY",
|
assertEquals("zz azerty", "AZERTY",
|
||||||
MainKeyboardView.getFullDisplayName(ZZ_AZERTY, mRes));
|
MainKeyboardView.getFullDisplayName(ZZ_AZERTY));
|
||||||
|
|
||||||
assertEquals("fr qwertz", "Français", MainKeyboardView.getMiddleDisplayName(FR_QWERTZ));
|
assertEquals("fr qwertz", "Français", MainKeyboardView.getMiddleDisplayName(FR_QWERTZ));
|
||||||
assertEquals("de qwerty", "Deutsch", MainKeyboardView.getMiddleDisplayName(DE_QWERTY));
|
assertEquals("de qwerty", "Deutsch", MainKeyboardView.getMiddleDisplayName(DE_QWERTY));
|
||||||
|
|
|
@ -33,6 +33,18 @@ public class SubtypeLocaleTests extends AndroidTestCase {
|
||||||
private RichInputMethodManager mRichImm;
|
private RichInputMethodManager mRichImm;
|
||||||
private Resources mRes;
|
private Resources mRes;
|
||||||
|
|
||||||
|
InputMethodSubtype EN_US;
|
||||||
|
InputMethodSubtype EN_GB;
|
||||||
|
InputMethodSubtype ES_US;
|
||||||
|
InputMethodSubtype FR;
|
||||||
|
InputMethodSubtype FR_CA;
|
||||||
|
InputMethodSubtype DE;
|
||||||
|
InputMethodSubtype ZZ;
|
||||||
|
InputMethodSubtype DE_QWERTY;
|
||||||
|
InputMethodSubtype FR_QWERTZ;
|
||||||
|
InputMethodSubtype US_AZERTY;
|
||||||
|
InputMethodSubtype ZZ_AZERTY;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
@ -41,11 +53,35 @@ public class SubtypeLocaleTests extends AndroidTestCase {
|
||||||
mRichImm = RichInputMethodManager.getInstance();
|
mRichImm = RichInputMethodManager.getInstance();
|
||||||
mRes = context.getResources();
|
mRes = context.getResources();
|
||||||
SubtypeLocale.init(context);
|
SubtypeLocale.init(context);
|
||||||
|
|
||||||
|
EN_US = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
||||||
|
Locale.US.toString(), "qwerty");
|
||||||
|
EN_GB = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
||||||
|
Locale.UK.toString(), "qwerty");
|
||||||
|
ES_US = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
||||||
|
"es_US", "spanish");
|
||||||
|
FR = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
||||||
|
Locale.FRENCH.toString(), "azerty");
|
||||||
|
FR_CA = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
||||||
|
Locale.CANADA_FRENCH.toString(), "qwerty");
|
||||||
|
DE = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
||||||
|
Locale.GERMAN.toString(), "qwertz");
|
||||||
|
ZZ = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
||||||
|
SubtypeLocale.NO_LANGUAGE, "qwerty");
|
||||||
|
DE_QWERTY = AdditionalSubtype.createAdditionalSubtype(
|
||||||
|
Locale.GERMAN.toString(), "qwerty", null);
|
||||||
|
FR_QWERTZ = AdditionalSubtype.createAdditionalSubtype(
|
||||||
|
Locale.FRENCH.toString(), "qwertz", null);
|
||||||
|
US_AZERTY = AdditionalSubtype.createAdditionalSubtype(
|
||||||
|
Locale.US.toString(), "azerty", null);
|
||||||
|
ZZ_AZERTY = AdditionalSubtype.createAdditionalSubtype(
|
||||||
|
SubtypeLocale.NO_LANGUAGE, "azerty", null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAllFullDisplayName() {
|
public void testAllFullDisplayName() {
|
||||||
for (final InputMethodSubtype subtype : mSubtypesList) {
|
for (final InputMethodSubtype subtype : mSubtypesList) {
|
||||||
final String subtypeName = SubtypeLocale.getSubtypeDisplayName(subtype, mRes);
|
final String subtypeName = SubtypeLocale.getSubtypeDisplayName(subtype);
|
||||||
if (SubtypeLocale.isNoLanguage(subtype)) {
|
if (SubtypeLocale.isNoLanguage(subtype)) {
|
||||||
final String noLanguage = mRes.getString(R.string.subtype_no_language);
|
final String noLanguage = mRes.getString(R.string.subtype_no_language);
|
||||||
assertTrue(subtypeName, subtypeName.contains(noLanguage));
|
assertTrue(subtypeName, subtypeName.contains(noLanguage));
|
||||||
|
@ -74,21 +110,6 @@ public class SubtypeLocaleTests extends AndroidTestCase {
|
||||||
// zz azerty T No language (AZERTY) in system locale
|
// zz azerty T No language (AZERTY) in system locale
|
||||||
|
|
||||||
public void testPredefinedSubtypesInEnglish() {
|
public void testPredefinedSubtypesInEnglish() {
|
||||||
final InputMethodSubtype EN_US = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
|
||||||
Locale.US.toString(), "qwerty");
|
|
||||||
final InputMethodSubtype EN_GB = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
|
||||||
Locale.UK.toString(), "qwerty");
|
|
||||||
final InputMethodSubtype ES_US = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
|
||||||
"es_US", "spanish");
|
|
||||||
final InputMethodSubtype FR = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
|
||||||
Locale.FRENCH.toString(), "azerty");
|
|
||||||
final InputMethodSubtype FR_CA = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
|
||||||
Locale.CANADA_FRENCH.toString(), "qwerty");
|
|
||||||
final InputMethodSubtype DE = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
|
||||||
Locale.GERMAN.toString(), "qwertz");
|
|
||||||
final InputMethodSubtype ZZ = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
|
||||||
SubtypeLocale.NO_LANGUAGE, "qwerty");
|
|
||||||
|
|
||||||
assertEquals("en_US", "qwerty", SubtypeLocale.getKeyboardLayoutSetName(EN_US));
|
assertEquals("en_US", "qwerty", SubtypeLocale.getKeyboardLayoutSetName(EN_US));
|
||||||
assertEquals("en_GB", "qwerty", SubtypeLocale.getKeyboardLayoutSetName(EN_GB));
|
assertEquals("en_GB", "qwerty", SubtypeLocale.getKeyboardLayoutSetName(EN_GB));
|
||||||
assertEquals("es_US", "spanish", SubtypeLocale.getKeyboardLayoutSetName(ES_US));
|
assertEquals("es_US", "spanish", SubtypeLocale.getKeyboardLayoutSetName(ES_US));
|
||||||
|
@ -101,19 +122,19 @@ public class SubtypeLocaleTests extends AndroidTestCase {
|
||||||
@Override
|
@Override
|
||||||
protected Void job(Resources res) {
|
protected Void job(Resources res) {
|
||||||
assertEquals("en_US", "English (US)",
|
assertEquals("en_US", "English (US)",
|
||||||
SubtypeLocale.getSubtypeDisplayName(EN_US, res));
|
SubtypeLocale.getSubtypeDisplayName(EN_US));
|
||||||
assertEquals("en_GB", "English (UK)",
|
assertEquals("en_GB", "English (UK)",
|
||||||
SubtypeLocale.getSubtypeDisplayName(EN_GB, res));
|
SubtypeLocale.getSubtypeDisplayName(EN_GB));
|
||||||
assertEquals("es_US", "Español (EE.UU.)",
|
assertEquals("es_US", "Español (EE.UU.)",
|
||||||
SubtypeLocale.getSubtypeDisplayName(ES_US, res));
|
SubtypeLocale.getSubtypeDisplayName(ES_US));
|
||||||
assertEquals("fr ", "Français",
|
assertEquals("fr ", "Français",
|
||||||
SubtypeLocale.getSubtypeDisplayName(FR, res));
|
SubtypeLocale.getSubtypeDisplayName(FR));
|
||||||
assertEquals("fr_CA", "Français (Canada)",
|
assertEquals("fr_CA", "Français (Canada)",
|
||||||
SubtypeLocale.getSubtypeDisplayName(FR_CA, res));
|
SubtypeLocale.getSubtypeDisplayName(FR_CA));
|
||||||
assertEquals("de ", "Deutsch",
|
assertEquals("de ", "Deutsch",
|
||||||
SubtypeLocale.getSubtypeDisplayName(DE, res));
|
SubtypeLocale.getSubtypeDisplayName(DE));
|
||||||
assertEquals("zz ", "No language (QWERTY)",
|
assertEquals("zz ", "No language (QWERTY)",
|
||||||
SubtypeLocale.getSubtypeDisplayName(ZZ, res));
|
SubtypeLocale.getSubtypeDisplayName(ZZ));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -121,26 +142,17 @@ public class SubtypeLocaleTests extends AndroidTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAdditionalSubtypesInEnglish() {
|
public void testAdditionalSubtypesInEnglish() {
|
||||||
final InputMethodSubtype DE_QWERTY = AdditionalSubtype.createAdditionalSubtype(
|
|
||||||
Locale.GERMAN.toString(), "qwerty", null);
|
|
||||||
final InputMethodSubtype FR_QWERTZ = AdditionalSubtype.createAdditionalSubtype(
|
|
||||||
Locale.FRENCH.toString(), "qwertz", null);
|
|
||||||
final InputMethodSubtype US_AZERTY = AdditionalSubtype.createAdditionalSubtype(
|
|
||||||
Locale.US.toString(), "azerty", null);
|
|
||||||
final InputMethodSubtype ZZ_AZERTY = AdditionalSubtype.createAdditionalSubtype(
|
|
||||||
SubtypeLocale.NO_LANGUAGE, "azerty", null);
|
|
||||||
|
|
||||||
final RunInLocale<Void> tests = new RunInLocale<Void>() {
|
final RunInLocale<Void> tests = new RunInLocale<Void>() {
|
||||||
@Override
|
@Override
|
||||||
protected Void job(Resources res) {
|
protected Void job(Resources res) {
|
||||||
assertEquals("fr qwertz", "Français (QWERTZ)",
|
assertEquals("fr qwertz", "Français (QWERTZ)",
|
||||||
SubtypeLocale.getSubtypeDisplayName(FR_QWERTZ, res));
|
SubtypeLocale.getSubtypeDisplayName(FR_QWERTZ));
|
||||||
assertEquals("de qwerty", "Deutsch (QWERTY)",
|
assertEquals("de qwerty", "Deutsch (QWERTY)",
|
||||||
SubtypeLocale.getSubtypeDisplayName(DE_QWERTY, res));
|
SubtypeLocale.getSubtypeDisplayName(DE_QWERTY));
|
||||||
assertEquals("en_US azerty", "English (US) (AZERTY)",
|
assertEquals("en_US azerty", "English (US) (AZERTY)",
|
||||||
SubtypeLocale.getSubtypeDisplayName(US_AZERTY, res));
|
SubtypeLocale.getSubtypeDisplayName(US_AZERTY));
|
||||||
assertEquals("zz azerty", "No language (AZERTY)",
|
assertEquals("zz azerty", "No language (AZERTY)",
|
||||||
SubtypeLocale.getSubtypeDisplayName(ZZ_AZERTY, res));
|
SubtypeLocale.getSubtypeDisplayName(ZZ_AZERTY));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -148,38 +160,23 @@ public class SubtypeLocaleTests extends AndroidTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPredefinedSubtypesInFrench() {
|
public void testPredefinedSubtypesInFrench() {
|
||||||
final InputMethodSubtype EN_US = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
|
||||||
Locale.US.toString(), "qwerty");
|
|
||||||
final InputMethodSubtype EN_GB = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
|
||||||
Locale.UK.toString(), "qwerty");
|
|
||||||
final InputMethodSubtype ES_US = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
|
||||||
"es_US", "spanish");
|
|
||||||
final InputMethodSubtype FR = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
|
||||||
Locale.FRENCH.toString(), "azerty");
|
|
||||||
final InputMethodSubtype FR_CA = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
|
||||||
Locale.CANADA_FRENCH.toString(), "qwerty");
|
|
||||||
final InputMethodSubtype DE = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
|
||||||
Locale.GERMAN.toString(), "qwertz");
|
|
||||||
final InputMethodSubtype ZZ = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
|
|
||||||
SubtypeLocale.NO_LANGUAGE, "qwerty");
|
|
||||||
|
|
||||||
final RunInLocale<Void> tests = new RunInLocale<Void>() {
|
final RunInLocale<Void> tests = new RunInLocale<Void>() {
|
||||||
@Override
|
@Override
|
||||||
protected Void job(Resources res) {
|
protected Void job(Resources res) {
|
||||||
assertEquals("en_US", "English (US)",
|
assertEquals("en_US", "English (US)",
|
||||||
SubtypeLocale.getSubtypeDisplayName(EN_US, res));
|
SubtypeLocale.getSubtypeDisplayName(EN_US));
|
||||||
assertEquals("en_GB", "English (UK)",
|
assertEquals("en_GB", "English (UK)",
|
||||||
SubtypeLocale.getSubtypeDisplayName(EN_GB, res));
|
SubtypeLocale.getSubtypeDisplayName(EN_GB));
|
||||||
assertEquals("es_US", "Español (EE.UU.)",
|
assertEquals("es_US", "Español (EE.UU.)",
|
||||||
SubtypeLocale.getSubtypeDisplayName(ES_US, res));
|
SubtypeLocale.getSubtypeDisplayName(ES_US));
|
||||||
assertEquals("fr ", "Français",
|
assertEquals("fr ", "Français",
|
||||||
SubtypeLocale.getSubtypeDisplayName(FR, res));
|
SubtypeLocale.getSubtypeDisplayName(FR));
|
||||||
assertEquals("fr_CA", "Français (Canada)",
|
assertEquals("fr_CA", "Français (Canada)",
|
||||||
SubtypeLocale.getSubtypeDisplayName(FR_CA, res));
|
SubtypeLocale.getSubtypeDisplayName(FR_CA));
|
||||||
assertEquals("de ", "Deutsch",
|
assertEquals("de ", "Deutsch",
|
||||||
SubtypeLocale.getSubtypeDisplayName(DE, res));
|
SubtypeLocale.getSubtypeDisplayName(DE));
|
||||||
assertEquals("zz ", "Pas de langue (QWERTY)",
|
assertEquals("zz ", "Pas de langue (QWERTY)",
|
||||||
SubtypeLocale.getSubtypeDisplayName(ZZ, res));
|
SubtypeLocale.getSubtypeDisplayName(ZZ));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -187,26 +184,17 @@ public class SubtypeLocaleTests extends AndroidTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAdditionalSubtypesInFrench() {
|
public void testAdditionalSubtypesInFrench() {
|
||||||
final InputMethodSubtype DE_QWERTY = AdditionalSubtype.createAdditionalSubtype(
|
|
||||||
Locale.GERMAN.toString(), "qwerty", null);
|
|
||||||
final InputMethodSubtype FR_QWERTZ = AdditionalSubtype.createAdditionalSubtype(
|
|
||||||
Locale.FRENCH.toString(), "qwertz", null);
|
|
||||||
final InputMethodSubtype US_AZERTY = AdditionalSubtype.createAdditionalSubtype(
|
|
||||||
Locale.US.toString(), "azerty", null);
|
|
||||||
final InputMethodSubtype ZZ_AZERTY = AdditionalSubtype.createAdditionalSubtype(
|
|
||||||
SubtypeLocale.NO_LANGUAGE, "azerty", null);
|
|
||||||
|
|
||||||
final RunInLocale<Void> tests = new RunInLocale<Void>() {
|
final RunInLocale<Void> tests = new RunInLocale<Void>() {
|
||||||
@Override
|
@Override
|
||||||
protected Void job(Resources res) {
|
protected Void job(Resources res) {
|
||||||
assertEquals("fr qwertz", "Français (QWERTZ)",
|
assertEquals("fr qwertz", "Français (QWERTZ)",
|
||||||
SubtypeLocale.getSubtypeDisplayName(FR_QWERTZ, res));
|
SubtypeLocale.getSubtypeDisplayName(FR_QWERTZ));
|
||||||
assertEquals("de qwerty", "Deutsch (QWERTY)",
|
assertEquals("de qwerty", "Deutsch (QWERTY)",
|
||||||
SubtypeLocale.getSubtypeDisplayName(DE_QWERTY, res));
|
SubtypeLocale.getSubtypeDisplayName(DE_QWERTY));
|
||||||
assertEquals("en_US azerty", "English (US) (AZERTY)",
|
assertEquals("en_US azerty", "English (US) (AZERTY)",
|
||||||
SubtypeLocale.getSubtypeDisplayName(US_AZERTY, res));
|
SubtypeLocale.getSubtypeDisplayName(US_AZERTY));
|
||||||
assertEquals("zz azerty", "Aucune langue (AZERTY)",
|
assertEquals("zz azerty", "Aucune langue (AZERTY)",
|
||||||
SubtypeLocale.getSubtypeDisplayName(ZZ_AZERTY, res));
|
SubtypeLocale.getSubtypeDisplayName(ZZ_AZERTY));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue