Loading java/src/com/android/inputmethod/latin/SubtypeLocale.java +14 −3 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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) { Loading tests/src/com/android/inputmethod/keyboard/SpacebarTextTests.java +0 −2 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -41,7 +40,6 @@ public class SpacebarTextTests extends AndroidTestCase { super.setUp(); final Context context = getContext(); mRes = context.getResources(); InputMethodManagerCompatWrapper.init(context); SubtypeLocale.init(context); } Loading tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java +95 −33 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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); } Loading @@ -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"); Loading @@ -93,21 +93,28 @@ public class SubtypeLocaleTests extends AndroidTestCase { assertEquals("de ", "qwertz", SubtypeLocale.getKeyboardLayoutSetName(DE)); assertEquals("zz ", "qwerty", SubtypeLocale.getKeyboardLayoutSetName(ZZ)); final RunInLocale<Void> tests = new RunInLocale<Void>() { @Override protected Void job(Resources res) { assertEquals("en_US", "English (US)", SubtypeLocale.getSubtypeDisplayName(EN_US, mRes)); SubtypeLocale.getSubtypeDisplayName(EN_US, res)); assertEquals("en_GB", "English (UK)", SubtypeLocale.getSubtypeDisplayName(EN_GB, mRes)); SubtypeLocale.getSubtypeDisplayName(EN_GB, res)); assertEquals("fr ", "Français", SubtypeLocale.getSubtypeDisplayName(FR, mRes)); SubtypeLocale.getSubtypeDisplayName(FR, res)); assertEquals("fr_CA", "Français (Canada)", SubtypeLocale.getSubtypeDisplayName(FR_CA, mRes)); SubtypeLocale.getSubtypeDisplayName(FR_CA, res)); assertEquals("de ", "Deutsch", SubtypeLocale.getSubtypeDisplayName(DE, mRes)); SubtypeLocale.getSubtypeDisplayName(DE, res)); assertEquals("zz ", "No language (QWERTY)", SubtypeLocale.getSubtypeDisplayName(ZZ, mRes)); 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( Loading @@ -117,32 +124,87 @@ public class SubtypeLocaleTests extends AndroidTestCase { 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("fr qwertz", "Français (QWERTZ)", SubtypeLocale.getSubtypeDisplayName(FR_QWERTZ, mRes)); SubtypeLocale.getSubtypeDisplayName(FR_QWERTZ, res)); assertEquals("de qwerty", "Deutsch (QWERTY)", SubtypeLocale.getSubtypeDisplayName(DE_QWERTY, mRes)); SubtypeLocale.getSubtypeDisplayName(DE_QWERTY, res)); assertEquals("en_US azerty", "English (US) (AZERTY)", SubtypeLocale.getSubtypeDisplayName(US_AZERTY, mRes)); SubtypeLocale.getSubtypeDisplayName(US_AZERTY, res)); assertEquals("zz azerty", "No language (AZERTY)", SubtypeLocale.getSubtypeDisplayName(ZZ_AZERTY, mRes)); 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 InputMethodSubtype ZZ_AZERTY = AdditionalSubtype.createAdditionalSubtype( SubtypeLocale.NO_LANGUAGE, "azerty", null); 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("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)); assertEquals("zz azerty", "Pas de langue (AZERTY)", 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("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; } Loading Loading
java/src/com/android/inputmethod/latin/SubtypeLocale.java +14 −3 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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) { Loading
tests/src/com/android/inputmethod/keyboard/SpacebarTextTests.java +0 −2 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -41,7 +40,6 @@ public class SpacebarTextTests extends AndroidTestCase { super.setUp(); final Context context = getContext(); mRes = context.getResources(); InputMethodManagerCompatWrapper.init(context); SubtypeLocale.init(context); } Loading
tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java +95 −33 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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); } Loading @@ -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"); Loading @@ -93,21 +93,28 @@ public class SubtypeLocaleTests extends AndroidTestCase { assertEquals("de ", "qwertz", SubtypeLocale.getKeyboardLayoutSetName(DE)); assertEquals("zz ", "qwerty", SubtypeLocale.getKeyboardLayoutSetName(ZZ)); final RunInLocale<Void> tests = new RunInLocale<Void>() { @Override protected Void job(Resources res) { assertEquals("en_US", "English (US)", SubtypeLocale.getSubtypeDisplayName(EN_US, mRes)); SubtypeLocale.getSubtypeDisplayName(EN_US, res)); assertEquals("en_GB", "English (UK)", SubtypeLocale.getSubtypeDisplayName(EN_GB, mRes)); SubtypeLocale.getSubtypeDisplayName(EN_GB, res)); assertEquals("fr ", "Français", SubtypeLocale.getSubtypeDisplayName(FR, mRes)); SubtypeLocale.getSubtypeDisplayName(FR, res)); assertEquals("fr_CA", "Français (Canada)", SubtypeLocale.getSubtypeDisplayName(FR_CA, mRes)); SubtypeLocale.getSubtypeDisplayName(FR_CA, res)); assertEquals("de ", "Deutsch", SubtypeLocale.getSubtypeDisplayName(DE, mRes)); SubtypeLocale.getSubtypeDisplayName(DE, res)); assertEquals("zz ", "No language (QWERTY)", SubtypeLocale.getSubtypeDisplayName(ZZ, mRes)); 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( Loading @@ -117,32 +124,87 @@ public class SubtypeLocaleTests extends AndroidTestCase { 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("fr qwertz", "Français (QWERTZ)", SubtypeLocale.getSubtypeDisplayName(FR_QWERTZ, mRes)); SubtypeLocale.getSubtypeDisplayName(FR_QWERTZ, res)); assertEquals("de qwerty", "Deutsch (QWERTY)", SubtypeLocale.getSubtypeDisplayName(DE_QWERTY, mRes)); SubtypeLocale.getSubtypeDisplayName(DE_QWERTY, res)); assertEquals("en_US azerty", "English (US) (AZERTY)", SubtypeLocale.getSubtypeDisplayName(US_AZERTY, mRes)); SubtypeLocale.getSubtypeDisplayName(US_AZERTY, res)); assertEquals("zz azerty", "No language (AZERTY)", SubtypeLocale.getSubtypeDisplayName(ZZ_AZERTY, mRes)); 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 InputMethodSubtype ZZ_AZERTY = AdditionalSubtype.createAdditionalSubtype( SubtypeLocale.NO_LANGUAGE, "azerty", null); 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("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)); assertEquals("zz azerty", "Pas de langue (AZERTY)", 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("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; } Loading