Add Spanish United States keyboard

The subtype locale name on the spacebar will be suppressed when only
one subtype is enabled and
 - Subtype locale is equal to the system locale.
or
 - Subtype language is equal to the system language but the subtype is
   implicitly enabled.

Thus the "es_ES" system locale chooses "es" subtype keyboard
implicitly but the keyboard doesn't have the subtype name on its
spacebar.

This change also removes Spanish Latin America keyboard.

Bug: 7531804
Change-Id: Ib929e8235d643c0ba039eb010e18ab721a734e15
main
Tadashi G. Takaoka 2012-11-19 11:25:30 +09:00
parent 9904c9ebbd
commit 76d4ffeebf
8 changed files with 100 additions and 49 deletions

View File

@ -140,10 +140,12 @@
<string-array name="subtype_locale_exception_keys"> <string-array name="subtype_locale_exception_keys">
<item>en_US</item> <item>en_US</item>
<item>en_GB</item> <item>en_GB</item>
<item>es_US</item>
</string-array> </string-array>
<string-array name="subtype_locale_exception_values"> <string-array name="subtype_locale_exception_values">
<item>English (US)</item> <item>English (US)</item>
<item>English (UK)</item> <item>English (UK)</item>
<item>Español (EE.UU.)</item>
</string-array> </string-array>
<!-- Generic subtype label --> <!-- Generic subtype label -->

View File

@ -36,7 +36,8 @@
en_GB: English Great Britain/qwerty en_GB: English Great Britain/qwerty
eo: Esperanto/spanish eo: Esperanto/spanish
es: Spanish/spanish es: Spanish/spanish
es_419: Spanish Latin America/qwerty es_US: Spanish United States/spanish
(es_419: Spanish Latin America/qwerty)
et: Estonian/nordic et: Estonian/nordic
fa: Persian/arabic fa: Persian/arabic
fi: Finnish/nordic fi: Finnish/nordic
@ -184,13 +185,22 @@
android:imeSubtypeMode="keyboard" android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection" android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection"
/> />
<subtype android:icon="@drawable/ic_subtype_keyboard"
android:label="@string/subtype_generic"
android:subtypeId="0x84d2efc6"
android:imeSubtypeLocale="es_US"
android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=spanish,AsciiCapable"
/>
<!--
<subtype android:icon="@drawable/ic_subtype_keyboard" <subtype android:icon="@drawable/ic_subtype_keyboard"
android:label="@string/subtype_generic" android:label="@string/subtype_generic"
android:subtypeId="0x623f9286" android:subtypeId="0x623f9286"
android:imeSubtypeLocale="es_419" android:imeSubtypeLocale="es_419"
android:imeSubtypeMode="keyboard" android:imeSubtypeMode="keyboard"
android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable" android:imeSubtypeExtraValue="KeyboardLayoutSet=spanish,AsciiCapable"
/> />
-->
<subtype android:icon="@drawable/ic_subtype_keyboard" <subtype android:icon="@drawable/ic_subtype_keyboard"
android:label="@string/subtype_generic" android:label="@string/subtype_generic"
android:subtypeId="0xec2d3955" android:subtypeId="0xec2d3955"

View File

@ -1029,18 +1029,19 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
// 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 (QWERTZ)
// en_US azerty T En English English (US) (AZERTY) // de qwerty T De Deutsch Deutsch (QWERTY)
// zz azerty T AZERTY AZERTY // en_US azerty T En English English (US) (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, final Resources res) {

View File

@ -87,6 +87,9 @@ public final class AdditionalSubtypeSettings extends PreferenceFragment {
} }
static final class SubtypeLocaleAdapter extends ArrayAdapter<SubtypeLocaleItem> { static final class SubtypeLocaleAdapter extends ArrayAdapter<SubtypeLocaleItem> {
private static final String TAG = SubtypeLocaleAdapter.class.getSimpleName();
private static final boolean DEBUG_SUBTYPE_ID = false;
public SubtypeLocaleAdapter(final Context context) { public SubtypeLocaleAdapter(final Context context) {
super(context, android.R.layout.simple_spinner_item); super(context, android.R.layout.simple_spinner_item);
setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
@ -97,6 +100,11 @@ public final class AdditionalSubtypeSettings extends PreferenceFragment {
final int count = imi.getSubtypeCount(); final int count = imi.getSubtypeCount();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
final InputMethodSubtype subtype = imi.getSubtypeAt(i); final InputMethodSubtype subtype = imi.getSubtypeAt(i);
if (DEBUG_SUBTYPE_ID) {
android.util.Log.d(TAG, String.format("%-6s 0x%08x %11d %s",
subtype.getLocale(), subtype.hashCode(), subtype.hashCode(),
SubtypeLocale.getSubtypeDisplayName(subtype, context.getResources())));
}
if (subtype.containsExtraValueKey(ASCII_CAPABLE)) { if (subtype.containsExtraValueKey(ASCII_CAPABLE)) {
items.add(createItem(context, subtype.getLocale())); items.add(createItem(context, subtype.getLocale()));
} }

View File

@ -96,28 +96,42 @@ public final class RichInputMethodManager {
return mInputMethodInfoOfThisIme.getId(); return mInputMethodInfoOfThisIme.getId();
} }
public boolean checkIfSubtypeBelongsToThisImeAndEnabled(final InputMethodSubtype ims) { public boolean checkIfSubtypeBelongsToThisImeAndEnabled(final InputMethodSubtype subtype) {
return checkIfSubtypeBelongsToImeAndEnabled(mInputMethodInfoOfThisIme, ims); return checkIfSubtypeBelongsToImeAndEnabled(mInputMethodInfoOfThisIme, subtype);
}
public boolean checkIfSubtypeBelongsToThisImeAndImplicitlyEnabled(
final InputMethodSubtype subtype) {
final boolean subtypeEnabled = checkIfSubtypeBelongsToThisImeAndEnabled(subtype);
final boolean subtypeExplicitlyEnabled = checkIfSubtypeBelongsToList(
subtype, mImmWrapper.mImm.getEnabledInputMethodSubtypeList(
mInputMethodInfoOfThisIme, false /* allowsImplicitlySelectedSubtypes */));
return subtypeEnabled && !subtypeExplicitlyEnabled;
} }
public boolean checkIfSubtypeBelongsToImeAndEnabled(final InputMethodInfo imi, public boolean checkIfSubtypeBelongsToImeAndEnabled(final InputMethodInfo imi,
final InputMethodSubtype ims) { final InputMethodSubtype subtype) {
final List<InputMethodSubtype> subtypes = mImmWrapper.mImm.getEnabledInputMethodSubtypeList( return checkIfSubtypeBelongsToList(
imi, true /* allowsImplicitlySelectedSubtypes */); subtype, mImmWrapper.mImm.getEnabledInputMethodSubtypeList(
for (final InputMethodSubtype subtype : subtypes) { imi, true /* allowsImplicitlySelectedSubtypes */));
if (subtype.equals(ims)) { }
private static boolean checkIfSubtypeBelongsToList(final InputMethodSubtype subtype,
final List<InputMethodSubtype> subtypes) {
for (final InputMethodSubtype ims : subtypes) {
if (ims.equals(subtype)) {
return true; return true;
} }
} }
return false; return false;
} }
public boolean checkIfSubtypeBelongsToThisIme(final InputMethodSubtype ims) { public boolean checkIfSubtypeBelongsToThisIme(final InputMethodSubtype subtype) {
final InputMethodInfo myImi = mInputMethodInfoOfThisIme; final InputMethodInfo myImi = mInputMethodInfoOfThisIme;
final int count = myImi.getSubtypeCount(); final int count = myImi.getSubtypeCount();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
final InputMethodSubtype subtype = myImi.getSubtypeAt(i); final InputMethodSubtype ims = myImi.getSubtypeAt(i);
if (subtype.equals(ims)) { if (ims.equals(subtype)) {
return true; return true;
} }
} }

View File

@ -151,18 +151,19 @@ public final class SubtypeLocale {
// InputMethodSubtype's display name in its locale. // InputMethodSubtype's display name in its locale.
// isAdditionalSubtype (T=true, F=false) // isAdditionalSubtype (T=true, F=false)
// locale layout | display name // locale layout | display name
// ------ ------ - ---------------------- // ------ ------- - ----------------------
// en_US qwerty F English (US) exception // en_US qwerty F English (US) exception
// en_GB qwerty F English (UK) exception // en_GB qwerty F English (UK) exception
// fr azerty F Français // es_US spanish F Español (EE.UU.) exception
// fr_CA qwerty F Français (Canada) // fr azerty F Français
// de qwertz F Deutsch // fr_CA qwerty F Français (Canada)
// zz qwerty F No language (QWERTY) in system locale // de qwertz F Deutsch
// fr qwertz T Français (QWERTZ) // zz qwerty F No language (QWERTY) in system locale
// de qwerty T Deutsch (QWERTY) // fr qwertz T Français (QWERTZ)
// en_US azerty T English (US) (AZERTY) // de qwerty T Deutsch (QWERTY)
// zz azerty T No language (AZERTY) in system locale // en_US azerty T English (US) (AZERTY)
// zz azerty T No language (AZERTY) in system locale
public static String getSubtypeDisplayName(final InputMethodSubtype subtype, Resources res) { public static String getSubtypeDisplayName(final InputMethodSubtype subtype, Resources res) {
final String replacementString = (Build.VERSION.SDK_INT >= /* JELLY_BEAN */ 15 final String replacementString = (Build.VERSION.SDK_INT >= /* JELLY_BEAN */ 15

View File

@ -193,8 +193,13 @@ public final class SubtypeSwitcher {
} }
final Locale newLocale = SubtypeLocale.getSubtypeLocale(newSubtype); final Locale newLocale = SubtypeLocale.getSubtypeLocale(newSubtype);
final boolean sameLocale = mCurrentSystemLocale.equals(newLocale);
final boolean sameLanguage = mCurrentSystemLocale.getLanguage().equals(
newLocale.getLanguage());
final boolean implicitlyEnabled =
mRichImm.checkIfSubtypeBelongsToThisImeAndImplicitlyEnabled(newSubtype);
mNeedsToDisplayLanguage.updateIsSystemLanguageSameAsInputLanguage( mNeedsToDisplayLanguage.updateIsSystemLanguageSameAsInputLanguage(
mCurrentSystemLocale.equals(newLocale)); sameLocale || (sameLanguage && implicitlyEnabled));
if (newSubtype.equals(mCurrentSubtype)) return; if (newSubtype.equals(mCurrentSubtype)) return;

View File

@ -59,24 +59,27 @@ public class SubtypeLocaleTests extends AndroidTestCase {
// InputMethodSubtype's display name in its locale. // InputMethodSubtype's display name in its locale.
// isAdditionalSubtype (T=true, F=false) // isAdditionalSubtype (T=true, F=false)
// locale layout | display name // locale layout | display name
// ------ ------ - ---------------------- // ------ ------- - ----------------------
// en_US qwerty F English (US) exception // en_US qwerty F English (US) exception
// en_GB qwerty F English (UK) exception // en_GB qwerty F English (UK) exception
// fr azerty F Français // es_US spanish F Español (EE.UU.) exception
// fr_CA qwerty F Français (Canada) // fr azerty F Français
// de qwertz F Deutsch // fr_CA qwerty F Français (Canada)
// zz qwerty F No language (QWERTY) in system locale // de qwertz F Deutsch
// fr qwertz T Français (QWERTZ) // zz qwerty F No language (QWERTY) in system locale
// de qwerty T Deutsch (QWERTY) // fr qwertz T Français (QWERTZ)
// en_US azerty T English (US) (AZERTY) // de qwerty T Deutsch (QWERTY)
// zz azerty T No language (AZERTY) in system locale // en_US azerty T English (US) (AZERTY)
// zz azerty T No language (AZERTY) in system locale
public void testPredefinedSubtypesInEnglish() { public void testPredefinedSubtypesInEnglish() {
final InputMethodSubtype EN_US = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( final InputMethodSubtype EN_US = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
Locale.US.toString(), "qwerty"); Locale.US.toString(), "qwerty");
final InputMethodSubtype EN_GB = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( final InputMethodSubtype EN_GB = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
Locale.UK.toString(), "qwerty"); Locale.UK.toString(), "qwerty");
final InputMethodSubtype ES_US = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
"es_US", "spanish");
final InputMethodSubtype FR = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( final InputMethodSubtype FR = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
Locale.FRENCH.toString(), "azerty"); Locale.FRENCH.toString(), "azerty");
final InputMethodSubtype FR_CA = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( final InputMethodSubtype FR_CA = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
@ -88,6 +91,7 @@ public class SubtypeLocaleTests extends AndroidTestCase {
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("fr ", "azerty", SubtypeLocale.getKeyboardLayoutSetName(FR)); assertEquals("fr ", "azerty", SubtypeLocale.getKeyboardLayoutSetName(FR));
assertEquals("fr_CA", "qwerty", SubtypeLocale.getKeyboardLayoutSetName(FR_CA)); assertEquals("fr_CA", "qwerty", SubtypeLocale.getKeyboardLayoutSetName(FR_CA));
assertEquals("de ", "qwertz", SubtypeLocale.getKeyboardLayoutSetName(DE)); assertEquals("de ", "qwertz", SubtypeLocale.getKeyboardLayoutSetName(DE));
@ -100,6 +104,8 @@ public class SubtypeLocaleTests extends AndroidTestCase {
SubtypeLocale.getSubtypeDisplayName(EN_US, res)); SubtypeLocale.getSubtypeDisplayName(EN_US, res));
assertEquals("en_GB", "English (UK)", assertEquals("en_GB", "English (UK)",
SubtypeLocale.getSubtypeDisplayName(EN_GB, res)); SubtypeLocale.getSubtypeDisplayName(EN_GB, res));
assertEquals("es_US", "Español (EE.UU.)",
SubtypeLocale.getSubtypeDisplayName(ES_US, res));
assertEquals("fr ", "Français", assertEquals("fr ", "Français",
SubtypeLocale.getSubtypeDisplayName(FR, res)); SubtypeLocale.getSubtypeDisplayName(FR, res));
assertEquals("fr_CA", "Français (Canada)", assertEquals("fr_CA", "Français (Canada)",
@ -146,6 +152,8 @@ public class SubtypeLocaleTests extends AndroidTestCase {
Locale.US.toString(), "qwerty"); Locale.US.toString(), "qwerty");
final InputMethodSubtype EN_GB = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( final InputMethodSubtype EN_GB = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
Locale.UK.toString(), "qwerty"); Locale.UK.toString(), "qwerty");
final InputMethodSubtype ES_US = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
"es_US", "spanish");
final InputMethodSubtype FR = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( final InputMethodSubtype FR = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
Locale.FRENCH.toString(), "azerty"); Locale.FRENCH.toString(), "azerty");
final InputMethodSubtype FR_CA = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet( final InputMethodSubtype FR_CA = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
@ -162,6 +170,8 @@ public class SubtypeLocaleTests extends AndroidTestCase {
SubtypeLocale.getSubtypeDisplayName(EN_US, res)); SubtypeLocale.getSubtypeDisplayName(EN_US, res));
assertEquals("en_GB", "English (UK)", assertEquals("en_GB", "English (UK)",
SubtypeLocale.getSubtypeDisplayName(EN_GB, res)); SubtypeLocale.getSubtypeDisplayName(EN_GB, res));
assertEquals("es_US", "Español (EE.UU.)",
SubtypeLocale.getSubtypeDisplayName(ES_US, res));
assertEquals("fr ", "Français", assertEquals("fr ", "Français",
SubtypeLocale.getSubtypeDisplayName(FR, res)); SubtypeLocale.getSubtypeDisplayName(FR, res));
assertEquals("fr_CA", "Français (Canada)", assertEquals("fr_CA", "Français (Canada)",