aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--java/src/com/android/inputmethod/latin/SubtypeLocale.java17
-rw-r--r--tests/src/com/android/inputmethod/keyboard/SpacebarTextTests.java2
-rw-r--r--tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java128
3 files changed, 109 insertions, 38 deletions
diff --git a/java/src/com/android/inputmethod/latin/SubtypeLocale.java b/java/src/com/android/inputmethod/latin/SubtypeLocale.java
index 9f89f9ee1..7694b56fc 100644
--- a/java/src/com/android/inputmethod/latin/SubtypeLocale.java
+++ b/java/src/com/android/inputmethod/latin/SubtypeLocale.java
@@ -22,6 +22,8 @@ import android.content.Context;
import android.content.res.Resources;
import android.view.inputmethod.InputMethodSubtype;
+import com.android.inputmethod.latin.LocaleUtils.RunInLocale;
+
import java.util.HashMap;
import java.util.Locale;
@@ -121,18 +123,27 @@ public class SubtypeLocale {
// fr azerty F Français
// fr_CA qwerty F Français (Canada)
// de qwertz F Deutsch
- // zz qwerty F No language (QWERTY)
+ // zz qwerty F No language (QWERTY) in system locale
// fr qwertz T Français (QWERTZ)
// de qwerty T Deutsch (QWERTY)
// en_US azerty T English (US) (AZERTY)
- // zz azerty T No language (AZERTY)
+ // zz azerty T No language (AZERTY) in system locale
public static String getSubtypeDisplayName(InputMethodSubtype subtype, Resources res) {
// TODO: Remove this check when InputMethodManager.getLastInputMethodSubtype is
// fixed.
if (!ImfUtils.checkIfSubtypeBelongsToThisIme(sContext, subtype)) return "";
final String language = getSubtypeLocaleDisplayName(subtype.getLocale());
- return res.getString(subtype.getNameResId(), language);
+ final int nameResId = subtype.getNameResId();
+ final RunInLocale<String> getSubtypeName = new RunInLocale<String>() {
+ @Override
+ protected String job(Resources res) {
+ return res.getString(nameResId, language);
+ }
+ };
+ final Locale locale = isNoLanguage(subtype)
+ ? res.getConfiguration().locale : getSubtypeLocale(subtype);
+ return getSubtypeName.runInLocale(res, locale);
}
public static boolean isNoLanguage(InputMethodSubtype subtype) {
diff --git a/tests/src/com/android/inputmethod/keyboard/SpacebarTextTests.java b/tests/src/com/android/inputmethod/keyboard/SpacebarTextTests.java
index 663f7087d..a34e0ef8b 100644
--- a/tests/src/com/android/inputmethod/keyboard/SpacebarTextTests.java
+++ b/tests/src/com/android/inputmethod/keyboard/SpacebarTextTests.java
@@ -21,7 +21,6 @@ import android.content.res.Resources;
import android.test.AndroidTestCase;
import android.view.inputmethod.InputMethodSubtype;
-import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
import com.android.inputmethod.latin.AdditionalSubtype;
import com.android.inputmethod.latin.ImfUtils;
import com.android.inputmethod.latin.StringUtils;
@@ -41,7 +40,6 @@ public class SpacebarTextTests extends AndroidTestCase {
super.setUp();
final Context context = getContext();
mRes = context.getResources();
- InputMethodManagerCompatWrapper.init(context);
SubtypeLocale.init(context);
}
diff --git a/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java b/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java
index 5393b23ac..8863bcf47 100644
--- a/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java
+++ b/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java
@@ -21,7 +21,6 @@ import android.content.res.Resources;
import android.test.AndroidTestCase;
import android.view.inputmethod.InputMethodSubtype;
-import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
import com.android.inputmethod.latin.LocaleUtils.RunInLocale;
import java.util.ArrayList;
@@ -31,14 +30,15 @@ public class SubtypeLocaleTests extends AndroidTestCase {
// Locale to subtypes list.
private final ArrayList<InputMethodSubtype> mSubtypesList = new ArrayList<InputMethodSubtype>();
+ private Context mContext;
private Resources mRes;
@Override
protected void setUp() throws Exception {
super.setUp();
final Context context = getContext();
+ mContext = context;
mRes = context.getResources();
- InputMethodManagerCompatWrapper.init(context);
SubtypeLocale.init(context);
}
@@ -65,13 +65,13 @@ public class SubtypeLocaleTests extends AndroidTestCase {
// fr azerty F Français
// fr_CA qwerty F Français (Canada)
// de qwertz F Deutsch
- // zz qwerty F No language (QWERTY)
+ // zz qwerty F No language (QWERTY) in system locale
// fr qwertz T Français (QWERTZ)
// de qwerty T Deutsch (QWERTY)
// en_US azerty T English (US) (AZERTY)
- // zz azerty T No language (AZERTY)
+ // zz azerty T No language (AZERTY) in system locale
- public void testPredefinedSubtypes() {
+ public void testPredefinedSubtypesInEnglish() {
final Context context = getContext();
final InputMethodSubtype EN_US = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet(
context, Locale.US.toString(), "qwerty");
@@ -93,21 +93,28 @@ public class SubtypeLocaleTests extends AndroidTestCase {
assertEquals("de ", "qwertz", SubtypeLocale.getKeyboardLayoutSetName(DE));
assertEquals("zz ", "qwerty", SubtypeLocale.getKeyboardLayoutSetName(ZZ));
- assertEquals("en_US", "English (US)",
- SubtypeLocale.getSubtypeDisplayName(EN_US, mRes));
- assertEquals("en_GB", "English (UK)",
- SubtypeLocale.getSubtypeDisplayName(EN_GB, mRes));
- assertEquals("fr ", "Français",
- SubtypeLocale.getSubtypeDisplayName(FR, mRes));
- assertEquals("fr_CA", "Français (Canada)",
- SubtypeLocale.getSubtypeDisplayName(FR_CA, mRes));
- assertEquals("de ", "Deutsch",
- SubtypeLocale.getSubtypeDisplayName(DE, mRes));
- assertEquals("zz ", "No language (QWERTY)",
- SubtypeLocale.getSubtypeDisplayName(ZZ, mRes));
+ final RunInLocale<Void> tests = new RunInLocale<Void>() {
+ @Override
+ protected Void job(Resources res) {
+ assertEquals("en_US", "English (US)",
+ SubtypeLocale.getSubtypeDisplayName(EN_US, res));
+ assertEquals("en_GB", "English (UK)",
+ SubtypeLocale.getSubtypeDisplayName(EN_GB, res));
+ assertEquals("fr ", "Français",
+ SubtypeLocale.getSubtypeDisplayName(FR, res));
+ assertEquals("fr_CA", "Français (Canada)",
+ SubtypeLocale.getSubtypeDisplayName(FR_CA, res));
+ assertEquals("de ", "Deutsch",
+ SubtypeLocale.getSubtypeDisplayName(DE, res));
+ assertEquals("zz ", "No language (QWERTY)",
+ SubtypeLocale.getSubtypeDisplayName(ZZ, res));
+ return null;
+ }
+ };
+ tests.runInLocale(mRes, Locale.ENGLISH);
}
- public void testAdditionalSubtype() {
+ public void testAdditionalSubtypesInEnglish() {
final InputMethodSubtype DE_QWERTY = AdditionalSubtype.createAdditionalSubtype(
Locale.GERMAN.toString(), "qwerty", null);
final InputMethodSubtype FR_QWERTZ = AdditionalSubtype.createAdditionalSubtype(
@@ -117,32 +124,87 @@ public class SubtypeLocaleTests extends AndroidTestCase {
final InputMethodSubtype ZZ_AZERTY = AdditionalSubtype.createAdditionalSubtype(
SubtypeLocale.NO_LANGUAGE, "azerty", null);
- assertEquals("fr qwertz", "Français (QWERTZ)",
- SubtypeLocale.getSubtypeDisplayName(FR_QWERTZ, mRes));
- assertEquals("de qwerty", "Deutsch (QWERTY)",
- SubtypeLocale.getSubtypeDisplayName(DE_QWERTY, mRes));
- assertEquals("en_US azerty", "English (US) (AZERTY)",
- SubtypeLocale.getSubtypeDisplayName(US_AZERTY, mRes));
- assertEquals("zz azerty", "No language (AZERTY)",
- SubtypeLocale.getSubtypeDisplayName(ZZ_AZERTY, mRes));
+ ImfUtils.setAdditionalInputMethodSubtypes(mContext, new InputMethodSubtype[] {
+ DE_QWERTY, FR_QWERTZ, US_AZERTY, ZZ_AZERTY
+ });
+
+ final RunInLocale<Void> tests = new RunInLocale<Void>() {
+ @Override
+ protected Void job(Resources res) {
+ assertEquals("fr qwertz", "Français (QWERTZ)",
+ SubtypeLocale.getSubtypeDisplayName(FR_QWERTZ, res));
+ assertEquals("de qwerty", "Deutsch (QWERTY)",
+ SubtypeLocale.getSubtypeDisplayName(DE_QWERTY, res));
+ assertEquals("en_US azerty", "English (US) (AZERTY)",
+ SubtypeLocale.getSubtypeDisplayName(US_AZERTY, res));
+ assertEquals("zz azerty", "No language (AZERTY)",
+ SubtypeLocale.getSubtypeDisplayName(ZZ_AZERTY, res));
+ return null;
+ }
+ };
+ tests.runInLocale(mRes, Locale.ENGLISH);
}
- public void testNoLanguageInFrench() {
+ public void testPredefinedSubtypesInFrench() {
final Context context = getContext();
+ final InputMethodSubtype EN_US = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet(
+ context, Locale.US.toString(), "qwerty");
+ final InputMethodSubtype EN_GB = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet(
+ context, Locale.UK.toString(), "qwerty");
+ final InputMethodSubtype FR = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet(
+ context, Locale.FRENCH.toString(), "azerty");
+ final InputMethodSubtype FR_CA = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet(
+ context, Locale.CANADA_FRENCH.toString(), "qwerty");
+ final InputMethodSubtype DE = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet(
+ context, Locale.GERMAN.toString(), "qwertz");
final InputMethodSubtype ZZ = ImfUtils.findSubtypeByLocaleAndKeyboardLayoutSet(
context, SubtypeLocale.NO_LANGUAGE, "qwerty");
+
+ final RunInLocale<Void> tests = new RunInLocale<Void>() {
+ @Override
+ protected Void job(Resources res) {
+ assertEquals("en_US", "English (US)",
+ SubtypeLocale.getSubtypeDisplayName(EN_US, res));
+ assertEquals("en_GB", "English (UK)",
+ SubtypeLocale.getSubtypeDisplayName(EN_GB, res));
+ assertEquals("fr ", "Français",
+ SubtypeLocale.getSubtypeDisplayName(FR, res));
+ assertEquals("fr_CA", "Français (Canada)",
+ SubtypeLocale.getSubtypeDisplayName(FR_CA, res));
+ assertEquals("de ", "Deutsch",
+ SubtypeLocale.getSubtypeDisplayName(DE, res));
+ assertEquals("zz ", "Pas de langue (QWERTY)",
+ SubtypeLocale.getSubtypeDisplayName(ZZ, res));
+ return null;
+ }
+ };
+ tests.runInLocale(mRes, Locale.FRENCH);
+ }
+
+ 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);
+ ImfUtils.setAdditionalInputMethodSubtypes(mContext, new InputMethodSubtype[] {
+ DE_QWERTY, FR_QWERTZ, US_AZERTY, ZZ_AZERTY
+ });
+
final RunInLocale<Void> tests = new RunInLocale<Void>() {
@Override
protected Void job(Resources res) {
- assertEquals("zz ", "qwerty", SubtypeLocale.getKeyboardLayoutSetName(ZZ));
- assertEquals("zz ", "azerty", SubtypeLocale.getKeyboardLayoutSetName(ZZ_AZERTY));
-
- assertEquals("zz ", "Pas de langue (QWERTY)",
- SubtypeLocale.getSubtypeDisplayName(ZZ, res));
- assertEquals("zz azerty", "Pas de langue (AZERTY)",
+ assertEquals("fr qwertz", "Français (QWERTZ)",
+ SubtypeLocale.getSubtypeDisplayName(FR_QWERTZ, res));
+ assertEquals("de qwerty", "Deutsch (QWERTY)",
+ SubtypeLocale.getSubtypeDisplayName(DE_QWERTY, res));
+ assertEquals("en_US azerty", "English (US) (AZERTY)",
+ SubtypeLocale.getSubtypeDisplayName(US_AZERTY, res));
+ assertEquals("zz azerty", "Aucune langue (AZERTY)",
SubtypeLocale.getSubtypeDisplayName(ZZ_AZERTY, res));
return null;
}