am 8630cd9d: Remove keyboard layout description on the spacebar

# Via Tadashi G. Takaoka
* commit '8630cd9d1708d42b3ed5d07d89ade2f3c1f85e47':
  Remove keyboard layout description on the spacebar
This commit is contained in:
Tadashi G. Takaoka 2013-01-27 19:45:16 -08:00 committed by Android Git Automerger
commit 5e24367cbc
3 changed files with 137 additions and 92 deletions

View file

@ -1443,9 +1443,9 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
// fr_CA qwerty F Fr Français Français (Canada) // fr_CA qwerty F Fr Français Français (Canada)
// de qwertz F De Deutsch Deutsch // de qwertz F De Deutsch Deutsch
// zz qwerty F QWERTY QWERTY // zz qwerty F QWERTY QWERTY
// fr qwertz T Fr Français Français (QWERTZ) // fr qwertz T Fr Français Français
// de qwerty T De Deutsch Deutsch (QWERTY) // de qwerty T De Deutsch Deutsch
// en_US azerty T En English English (US) (AZERTY) // en_US azerty T En English English (US)
// 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.
@ -1453,8 +1453,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
if (SubtypeLocale.isNoLanguage(subtype)) { if (SubtypeLocale.isNoLanguage(subtype)) {
return SubtypeLocale.getKeyboardLayoutSetDisplayName(subtype); return SubtypeLocale.getKeyboardLayoutSetDisplayName(subtype);
} }
return SubtypeLocale.getSubtypeLocaleDisplayName(subtype.getLocale());
return SubtypeLocale.getSubtypeDisplayName(subtype);
} }
// Get InputMethodSubtype's short display name in its locale. // Get InputMethodSubtype's short display name in its locale.
@ -1472,6 +1471,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
return SubtypeLocale.getKeyboardLayoutSetDisplayName(subtype); return SubtypeLocale.getKeyboardLayoutSetDisplayName(subtype);
} }
final Locale locale = SubtypeLocale.getSubtypeLocale(subtype); final Locale locale = SubtypeLocale.getSubtypeLocale(subtype);
return StringUtils.toTitleCase(locale.getDisplayLanguage(locale), locale); return SubtypeLocale.getSubtypeLocaleDisplayName(locale.getLanguage());
} }
} }

View file

@ -140,26 +140,32 @@ public final class SubtypeLocale {
&& isExceptionalLocale(localeString)) { && isExceptionalLocale(localeString)) {
return sExceptionalLocaleToWithLayoutNameIdsMap.get(localeString); return sExceptionalLocaleToWithLayoutNameIdsMap.get(localeString);
} }
final String key = localeString.equals(NO_LANGUAGE) final String key = NO_LANGUAGE.equals(localeString)
? getNoLanguageLayoutKey(keyboardLayoutName) ? getNoLanguageLayoutKey(keyboardLayoutName)
: keyboardLayoutName; : keyboardLayoutName;
final Integer nameId = sKeyboardLayoutToNameIdsMap.get(key); final Integer nameId = sKeyboardLayoutToNameIdsMap.get(key);
return nameId == null ? UNKNOWN_KEYBOARD_LAYOUT : nameId; return nameId == null ? UNKNOWN_KEYBOARD_LAYOUT : nameId;
} }
private static Locale getDisplayLocaleOfSubtypeLocale(final String localeString) {
if (NO_LANGUAGE.equals(localeString)) {
return sResources.getConfiguration().locale;
}
return LocaleUtils.constructLocaleFromString(localeString);
}
public static String getSubtypeLocaleDisplayNameInSystemLocale(final String localeString) { public static String getSubtypeLocaleDisplayNameInSystemLocale(final String localeString) {
final Locale displayLocale = sResources.getConfiguration().locale; final Locale displayLocale = sResources.getConfiguration().locale;
return getSubtypeLocaleDisplayNameInternal(localeString, displayLocale); return getSubtypeLocaleDisplayNameInternal(localeString, displayLocale);
} }
public static String getSubtypeLocaleDisplayName(final String localeString) { public static String getSubtypeLocaleDisplayName(final String localeString) {
final Locale displayLocale = LocaleUtils.constructLocaleFromString(localeString); final Locale displayLocale = getDisplayLocaleOfSubtypeLocale(localeString);
return getSubtypeLocaleDisplayNameInternal(localeString, displayLocale); return getSubtypeLocaleDisplayNameInternal(localeString, displayLocale);
} }
private static String getSubtypeLocaleDisplayNameInternal(final String localeString, private static String getSubtypeLocaleDisplayNameInternal(final String localeString,
final Locale displayLocale) { final Locale displayLocale) {
final Locale locale = LocaleUtils.constructLocaleFromString(localeString);
final Integer exceptionalNameResId = sExceptionalLocaleToNameIdsMap.get(localeString); final Integer exceptionalNameResId = sExceptionalLocaleToNameIdsMap.get(localeString);
final String displayName; final String displayName;
if (exceptionalNameResId != null) { if (exceptionalNameResId != null) {
@ -170,7 +176,11 @@ public final class SubtypeLocale {
} }
}; };
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);
displayName = locale.getDisplayName(displayLocale); displayName = locale.getDisplayName(displayLocale);
} }
return StringUtils.toTitleCase(displayName, displayLocale); return StringUtils.toTitleCase(displayName, displayLocale);
@ -203,13 +213,13 @@ public final class SubtypeLocale {
} }
public static String getSubtypeDisplayNameInSystemLocale(final InputMethodSubtype subtype) { public static String getSubtypeDisplayNameInSystemLocale(final InputMethodSubtype subtype) {
final Locale subtypeLocale = sResources.getConfiguration().locale; final Locale displayLocale = sResources.getConfiguration().locale;
return getSubtypeDisplayNameInternal(subtype, subtypeLocale); return getSubtypeDisplayNameInternal(subtype, displayLocale);
} }
public static String getSubtypeDisplayName(final InputMethodSubtype subtype) { public static String getSubtypeDisplayName(final InputMethodSubtype subtype) {
final Locale subtypeLocale = LocaleUtils.constructLocaleFromString(subtype.getLocale()); final Locale displayLocale = getDisplayLocaleOfSubtypeLocale(subtype.getLocale());
return getSubtypeDisplayNameInternal(subtype, subtypeLocale); return getSubtypeDisplayNameInternal(subtype, displayLocale);
} }
private static String getSubtypeDisplayNameInternal(final InputMethodSubtype subtype, private static String getSubtypeDisplayNameInternal(final InputMethodSubtype subtype,
@ -225,6 +235,7 @@ public final class SubtypeLocale {
// TODO: Remove this catch when InputMethodManager.getCurrentInputMethodSubtype // TODO: Remove this catch when InputMethodManager.getCurrentInputMethodSubtype
// is fixed. // is fixed.
Log.w(TAG, "Unknown subtype: mode=" + subtype.getMode() Log.w(TAG, "Unknown subtype: mode=" + subtype.getMode()
+ " nameResId=" + subtype.getNameResId()
+ " locale=" + subtype.getLocale() + " locale=" + subtype.getLocale()
+ " extra=" + subtype.getExtraValue() + " extra=" + subtype.getExtraValue()
+ "\n" + Utils.getStackTrace()); + "\n" + Utils.getStackTrace());
@ -232,15 +243,13 @@ public final class SubtypeLocale {
} }
} }
}; };
final Locale locale = isNoLanguage(subtype)
? sResources.getConfiguration().locale : displayLocale;
return StringUtils.toTitleCase( return StringUtils.toTitleCase(
getSubtypeName.runInLocale(sResources, locale), locale); getSubtypeName.runInLocale(sResources, displayLocale), displayLocale);
} }
public static boolean isNoLanguage(final 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 NO_LANGUAGE.equals(localeString);
} }
public static Locale getSubtypeLocale(final InputMethodSubtype subtype) { public static Locale getSubtypeLocale(final InputMethodSubtype subtype) {

View file

@ -17,6 +17,7 @@
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;
@ -25,6 +26,7 @@ import com.android.inputmethod.latin.CollectionUtils;
import com.android.inputmethod.latin.RichInputMethodManager; import com.android.inputmethod.latin.RichInputMethodManager;
import com.android.inputmethod.latin.StringUtils; import com.android.inputmethod.latin.StringUtils;
import com.android.inputmethod.latin.SubtypeLocale; import com.android.inputmethod.latin.SubtypeLocale;
import com.android.inputmethod.latin.LocaleUtils.RunInLocale;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Locale; import java.util.Locale;
@ -34,6 +36,19 @@ 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;
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 {
@ -41,7 +56,25 @@ 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);
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() {
@ -89,88 +122,92 @@ public class SpacebarTextTests extends AndroidTestCase {
// InputMethodSubtype's display name for spacebar text in its locale. // InputMethodSubtype's display name for spacebar text in its locale.
// isAdditionalSubtype (T=true, F=false) // isAdditionalSubtype (T=true, F=false)
// locale layout | Short Middle Full // locale layout | Short Middle Full
// ------ ------ - ---- --------- ---------------------- // ------ ------- - ---- --------- ----------------------
// en_US qwerty F En English English (US) exception // en_US qwerty F En English English (US) exception
// en_GB qwerty F En English English (UK) exception // en_GB qwerty F En English English (UK) exception
// fr azerty F Fr Français Français // es_US spanish F Es Español Español (EE.UU.) exception
// fr_CA qwerty F Fr Français Français (Canada) // fr azerty F Fr Français Français
// de qwertz F De Deutsch Deutsch // fr_CA qwerty F Fr Français Français (Canada)
// zz qwerty F QWERTY QWERTY // de qwertz F De Deutsch Deutsch
// fr qwertz T Fr Français Français (QWERTZ) // zz qwerty F QWERTY QWERTY
// de qwerty T De Deutsch Deutsch (QWERTY) // fr qwertz T Fr Français Français
// en_US azerty T En English English (US) (AZERTY) // de qwerty T De Deutsch Deutsch
// zz azerty T AZERTY AZERTY // en_US azerty T En English English (US)
// zz azerty T AZERTY AZERTY
public void testPredefinedSubtypes() { private final RunInLocale<Void> testsPredefinedSubtypes = new RunInLocale<Void>() {
final InputMethodSubtype EN_US = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( @Override
Locale.US.toString(), "qwerty"); protected Void job(Resources res) {
final InputMethodSubtype EN_GB = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( assertEquals("en_US", "English (US)", MainKeyboardView.getFullDisplayName(EN_US));
Locale.UK.toString(), "qwerty"); assertEquals("en_GB", "English (UK)", MainKeyboardView.getFullDisplayName(EN_GB));
final InputMethodSubtype FR = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( assertEquals("es_US", "Español (EE.UU.)", MainKeyboardView.getFullDisplayName(ES_US));
Locale.FRENCH.toString(), "azerty"); assertEquals("fr ", "Français", MainKeyboardView.getFullDisplayName(FR));
final InputMethodSubtype FR_CA = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( assertEquals("fr_CA", "Français (Canada)", MainKeyboardView.getFullDisplayName(FR_CA));
Locale.CANADA_FRENCH.toString(), "qwerty"); assertEquals("de ", "Deutsch", MainKeyboardView.getFullDisplayName(DE));
final InputMethodSubtype DE = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( assertEquals("zz ", "QWERTY", MainKeyboardView.getFullDisplayName(ZZ));
Locale.GERMAN.toString(), "qwertz");
final InputMethodSubtype ZZ = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
SubtypeLocale.NO_LANGUAGE, "qwerty");
assertEquals("en_US", "English (US)", assertEquals("en_US", "English", MainKeyboardView.getMiddleDisplayName(EN_US));
MainKeyboardView.getFullDisplayName(EN_US)); assertEquals("en_GB", "English", MainKeyboardView.getMiddleDisplayName(EN_GB));
assertEquals("en_GB", "English (UK)", assertEquals("es_US", "Español", MainKeyboardView.getMiddleDisplayName(ES_US));
MainKeyboardView.getFullDisplayName(EN_GB)); assertEquals("fr ", "Français", MainKeyboardView.getMiddleDisplayName(FR));
assertEquals("fr ", "Français", assertEquals("fr_CA", "Français", MainKeyboardView.getMiddleDisplayName(FR_CA));
MainKeyboardView.getFullDisplayName(FR)); assertEquals("de ", "Deutsch", MainKeyboardView.getMiddleDisplayName(DE));
assertEquals("fr_CA", "Français (Canada)", assertEquals("zz ", "QWERTY", MainKeyboardView.getMiddleDisplayName(ZZ));
MainKeyboardView.getFullDisplayName(FR_CA));
assertEquals("de ", "Deutsch",
MainKeyboardView.getFullDisplayName(DE));
assertEquals("zz ", "QWERTY",
MainKeyboardView.getFullDisplayName(ZZ));
assertEquals("en_US", "English", MainKeyboardView.getMiddleDisplayName(EN_US)); assertEquals("en_US", "En", MainKeyboardView.getShortDisplayName(EN_US));
assertEquals("en_GB", "English", MainKeyboardView.getMiddleDisplayName(EN_GB)); assertEquals("en_GB", "En", MainKeyboardView.getShortDisplayName(EN_GB));
assertEquals("fr ", "Français", MainKeyboardView.getMiddleDisplayName(FR)); assertEquals("es_US", "Es", MainKeyboardView.getShortDisplayName(ES_US));
assertEquals("fr_CA", "Français", MainKeyboardView.getMiddleDisplayName(FR_CA)); assertEquals("fr ", "Fr", MainKeyboardView.getShortDisplayName(FR));
assertEquals("de ", "Deutsch", MainKeyboardView.getMiddleDisplayName(DE)); assertEquals("fr_CA", "Fr", MainKeyboardView.getShortDisplayName(FR_CA));
assertEquals("zz ", "QWERTY", MainKeyboardView.getMiddleDisplayName(ZZ)); assertEquals("de ", "De", MainKeyboardView.getShortDisplayName(DE));
assertEquals("zz ", "", MainKeyboardView.getShortDisplayName(ZZ));
return null;
}
};
assertEquals("en_US", "En", MainKeyboardView.getShortDisplayName(EN_US)); private final RunInLocale<Void> testsAdditionalSubtypes = new RunInLocale<Void>() {
assertEquals("en_GB", "En", MainKeyboardView.getShortDisplayName(EN_GB)); @Override
assertEquals("fr ", "Fr", MainKeyboardView.getShortDisplayName(FR)); protected Void job(Resources res) {
assertEquals("fr_CA", "Fr", MainKeyboardView.getShortDisplayName(FR_CA)); assertEquals("fr qwertz", "Français",
assertEquals("de ", "De", MainKeyboardView.getShortDisplayName(DE)); MainKeyboardView.getFullDisplayName(FR_QWERTZ));
assertEquals("zz ", "", MainKeyboardView.getShortDisplayName(ZZ)); assertEquals("de qwerty", "Deutsch",
MainKeyboardView.getFullDisplayName(DE_QWERTY));
assertEquals("en_US azerty", "English (US)",
MainKeyboardView.getFullDisplayName(US_AZERTY));
assertEquals("zz azerty", "AZERTY",
MainKeyboardView.getFullDisplayName(ZZ_AZERTY));
assertEquals("fr qwertz", "Français",
MainKeyboardView.getMiddleDisplayName(FR_QWERTZ));
assertEquals("de qwerty", "Deutsch",
MainKeyboardView.getMiddleDisplayName(DE_QWERTY));
assertEquals("en_US azerty", "English",
MainKeyboardView.getMiddleDisplayName(US_AZERTY));
assertEquals("zz azerty", "AZERTY",
MainKeyboardView.getMiddleDisplayName(ZZ_AZERTY));
assertEquals("fr qwertz", "Fr", MainKeyboardView.getShortDisplayName(FR_QWERTZ));
assertEquals("de qwerty", "De", MainKeyboardView.getShortDisplayName(DE_QWERTY));
assertEquals("en_US azerty", "En", MainKeyboardView.getShortDisplayName(US_AZERTY));
assertEquals("zz azerty", "", MainKeyboardView.getShortDisplayName(ZZ_AZERTY));
return null;
}
};
public void testPredefinedSubtypesInEnglish() {
testsPredefinedSubtypes.runInLocale(mRes, Locale.ENGLISH);
} }
public void testAdditionalSubtype() { public void testAdditionalSubtypeInEnglish() {
final InputMethodSubtype DE_QWERTY = AdditionalSubtype.createAdditionalSubtype( testsAdditionalSubtypes.runInLocale(mRes, Locale.ENGLISH);
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);
assertEquals("fr qwertz", "Français (QWERTZ)", public void testPredefinedSubtypesInFrench() {
MainKeyboardView.getFullDisplayName(FR_QWERTZ)); testsPredefinedSubtypes.runInLocale(mRes, Locale.FRENCH);
assertEquals("de qwerty", "Deutsch (QWERTY)", }
MainKeyboardView.getFullDisplayName(DE_QWERTY));
assertEquals("en_US azerty", "English (US) (AZERTY)",
MainKeyboardView.getFullDisplayName(US_AZERTY));
assertEquals("zz azerty", "AZERTY",
MainKeyboardView.getFullDisplayName(ZZ_AZERTY));
assertEquals("fr qwertz", "Français", MainKeyboardView.getMiddleDisplayName(FR_QWERTZ)); public void testAdditionalSubtypeInFrench() {
assertEquals("de qwerty", "Deutsch", MainKeyboardView.getMiddleDisplayName(DE_QWERTY)); testsAdditionalSubtypes.runInLocale(mRes, Locale.FRENCH);
assertEquals("en_US azerty", "English", MainKeyboardView.getMiddleDisplayName(US_AZERTY));
assertEquals("zz azerty", "AZERTY", MainKeyboardView.getMiddleDisplayName(ZZ_AZERTY));
assertEquals("fr qwertz", "Fr", MainKeyboardView.getShortDisplayName(FR_QWERTZ));
assertEquals("de qwerty", "De", MainKeyboardView.getShortDisplayName(DE_QWERTY));
assertEquals("en_US azerty", "En", MainKeyboardView.getShortDisplayName(US_AZERTY));
assertEquals("zz azerty", "", MainKeyboardView.getShortDisplayName(ZZ_AZERTY));
} }
} }