am 65a199ca: Merge "Add SpacebarLanguageUtils class"

* commit '65a199ca8eeab16ff80fd48f1d783c82e4fb55b1':
  Add SpacebarLanguageUtils class
main
Tadashi G. Takaoka 2014-04-01 03:29:14 +00:00 committed by Android Git Automerger
commit 78835a8da3
5 changed files with 348 additions and 177 deletions

View File

@ -60,7 +60,7 @@ import com.android.inputmethod.latin.define.ProductionFlag;
import com.android.inputmethod.latin.settings.DebugSettings;
import com.android.inputmethod.latin.utils.CollectionUtils;
import com.android.inputmethod.latin.utils.CoordinateUtils;
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
import com.android.inputmethod.latin.utils.SpacebarLanguageUtils;
import com.android.inputmethod.latin.utils.TypefaceUtils;
import com.android.inputmethod.latin.utils.UsabilityStudyLogUtils;
import com.android.inputmethod.research.ResearchLogger;
@ -918,14 +918,13 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
// Layout language name on spacebar.
private String layoutLanguageOnSpacebar(final Paint paint,
final InputMethodSubtype subtype, final int width) {
// Choose appropriate language name to fit into the width.
final String fullText = SubtypeLocaleUtils.getFullDisplayName(subtype);
final String fullText = SpacebarLanguageUtils.getFullDisplayName(subtype);
if (fitsTextIntoWidth(width, fullText, paint)) {
return fullText;
}
final String middleText = SubtypeLocaleUtils.getMiddleDisplayName(subtype);
final String middleText = SpacebarLanguageUtils.getMiddleDisplayName(subtype);
if (fitsTextIntoWidth(width, middleText, paint)) {
return middleText;
}

View File

@ -0,0 +1,61 @@
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.inputmethod.latin.utils;
import android.view.inputmethod.InputMethodSubtype;
import java.util.Locale;
public final class SpacebarLanguageUtils {
private SpacebarLanguageUtils() {
// Intentional empty constructor for utility class.
}
// InputMethodSubtype's display name for spacebar text in its locale.
// isAdditionalSubtype (T=true, F=false)
// locale layout | Middle Full
// ------ ------- - --------- ----------------------
// en_US qwerty F English English (US) exception
// en_GB qwerty F English English (UK) exception
// es_US spanish F Español Español (EE.UU.) exception
// fr azerty F Français Français
// fr_CA qwerty F Français Français (Canada)
// fr_CH swiss F Français Français (Suisse)
// de qwertz F Deutsch Deutsch
// de_CH swiss T Deutsch Deutsch (Schweiz)
// zz qwerty F QWERTY QWERTY
// fr qwertz T Français Français
// de qwerty T Deutsch Deutsch
// en_US azerty T English English (US)
// zz azerty T AZERTY AZERTY
// Get InputMethodSubtype's full display name in its locale.
public static String getFullDisplayName(final InputMethodSubtype subtype) {
if (SubtypeLocaleUtils.isNoLanguage(subtype)) {
return SubtypeLocaleUtils.getKeyboardLayoutSetDisplayName(subtype);
}
return SubtypeLocaleUtils.getSubtypeLocaleDisplayName(subtype.getLocale());
}
// Get InputMethodSubtype's middle display name in its locale.
public static String getMiddleDisplayName(final InputMethodSubtype subtype) {
if (SubtypeLocaleUtils.isNoLanguage(subtype)) {
return SubtypeLocaleUtils.getKeyboardLayoutSetDisplayName(subtype);
}
final Locale locale = SubtypeLocaleUtils.getSubtypeLocale(subtype);
return SubtypeLocaleUtils.getSubtypeLocaleDisplayName(locale.getLanguage());
}
}

View File

@ -292,41 +292,6 @@ public final class SubtypeLocaleUtils {
return keyboardLayoutSet;
}
// InputMethodSubtype's display name for spacebar text in its locale.
// isAdditionalSubtype (T=true, F=false)
// locale layout | Middle Full
// ------ ------- - --------- ----------------------
// en_US qwerty F English English (US) exception
// en_GB qwerty F English English (UK) exception
// es_US spanish F Español Español (EE.UU.) exception
// fr azerty F Français Français
// fr_CA qwerty F Français Français (Canada)
// fr_CH swiss F Français Français (Suisse)
// de qwertz F Deutsch Deutsch
// de_CH swiss T Deutsch Deutsch (Schweiz)
// zz qwerty F QWERTY QWERTY
// fr qwertz T Français Français
// de qwerty T Deutsch Deutsch
// en_US azerty T English English (US)
// zz azerty T AZERTY AZERTY
// Get InputMethodSubtype's full display name in its locale.
public static String getFullDisplayName(final InputMethodSubtype subtype) {
if (isNoLanguage(subtype)) {
return getKeyboardLayoutSetDisplayName(subtype);
}
return getSubtypeLocaleDisplayName(subtype.getLocale());
}
// Get InputMethodSubtype's middle display name in its locale.
public static String getMiddleDisplayName(final InputMethodSubtype subtype) {
if (isNoLanguage(subtype)) {
return getKeyboardLayoutSetDisplayName(subtype);
}
final Locale locale = getSubtypeLocale(subtype);
return getSubtypeLocaleDisplayName(locale.getLanguage());
}
// TODO: Get this information from the framework instead of maintaining here by ourselves.
// Sorted list of known Right-To-Left language codes.
private static final String[] SORTED_RTL_LANGUAGES = {

View File

@ -0,0 +1,251 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.inputmethod.latin.utils;
import android.content.Context;
import android.content.res.Resources;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.latin.RichInputMethodManager;
import java.util.ArrayList;
import java.util.Locale;
@SmallTest
public class SpacebarLanguagetUtilsTests extends AndroidTestCase {
// All input method subtypes of LatinIME.
private final ArrayList<InputMethodSubtype> mSubtypesList = CollectionUtils.newArrayList();
private RichInputMethodManager mRichImm;
private Resources mRes;
InputMethodSubtype EN_US;
InputMethodSubtype EN_GB;
InputMethodSubtype ES_US;
InputMethodSubtype FR;
InputMethodSubtype FR_CA;
InputMethodSubtype FR_CH;
InputMethodSubtype DE;
InputMethodSubtype DE_CH;
InputMethodSubtype ZZ;
InputMethodSubtype DE_QWERTY;
InputMethodSubtype FR_QWERTZ;
InputMethodSubtype EN_US_AZERTY;
InputMethodSubtype EN_UK_DVORAK;
InputMethodSubtype ES_US_COLEMAK;
InputMethodSubtype ZZ_AZERTY;
InputMethodSubtype ZZ_PC;
@Override
protected void setUp() throws Exception {
super.setUp();
final Context context = getContext();
RichInputMethodManager.init(context);
mRichImm = RichInputMethodManager.getInstance();
mRes = context.getResources();
SubtypeLocaleUtils.init(context);
final InputMethodInfo imi = mRichImm.getInputMethodInfoOfThisIme();
final int subtypeCount = imi.getSubtypeCount();
for (int index = 0; index < subtypeCount; index++) {
final InputMethodSubtype subtype = imi.getSubtypeAt(index);
mSubtypesList.add(subtype);
}
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");
FR_CH = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
"fr_CH", "swiss");
DE = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
Locale.GERMAN.toString(), "qwertz");
DE_CH = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
"de_CH", "swiss");
ZZ = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet(
SubtypeLocaleUtils.NO_LANGUAGE, "qwerty");
DE_QWERTY = AdditionalSubtypeUtils.createAdditionalSubtype(
Locale.GERMAN.toString(), "qwerty", null);
FR_QWERTZ = AdditionalSubtypeUtils.createAdditionalSubtype(
Locale.FRENCH.toString(), "qwertz", null);
EN_US_AZERTY = AdditionalSubtypeUtils.createAdditionalSubtype(
Locale.US.toString(), "azerty", null);
EN_UK_DVORAK = AdditionalSubtypeUtils.createAdditionalSubtype(
Locale.UK.toString(), "dvorak", null);
ES_US_COLEMAK = AdditionalSubtypeUtils.createAdditionalSubtype(
"es_US", "colemak", null);
ZZ_AZERTY = AdditionalSubtypeUtils.createAdditionalSubtype(
SubtypeLocaleUtils.NO_LANGUAGE, "azerty", null);
ZZ_PC = AdditionalSubtypeUtils.createAdditionalSubtype(
SubtypeLocaleUtils.NO_LANGUAGE, "pcqwerty", null);
}
public void testAllFullDisplayNameForSpacebar() {
for (final InputMethodSubtype subtype : mSubtypesList) {
final String subtypeName = SubtypeLocaleUtils
.getSubtypeDisplayNameInSystemLocale(subtype);
final String spacebarText = SpacebarLanguageUtils.getFullDisplayName(subtype);
final String languageName = SubtypeLocaleUtils
.getSubtypeLocaleDisplayName(subtype.getLocale());
if (SubtypeLocaleUtils.isNoLanguage(subtype)) {
assertFalse(subtypeName, spacebarText.contains(languageName));
} else {
assertTrue(subtypeName, spacebarText.contains(languageName));
}
}
}
public void testAllMiddleDisplayNameForSpacebar() {
for (final InputMethodSubtype subtype : mSubtypesList) {
final String subtypeName = SubtypeLocaleUtils
.getSubtypeDisplayNameInSystemLocale(subtype);
final String spacebarText = SpacebarLanguageUtils.getMiddleDisplayName(subtype);
if (SubtypeLocaleUtils.isNoLanguage(subtype)) {
assertEquals(subtypeName,
SubtypeLocaleUtils.getKeyboardLayoutSetDisplayName(subtype), spacebarText);
} else {
final Locale locale = SubtypeLocaleUtils.getSubtypeLocale(subtype);
assertEquals(subtypeName,
SubtypeLocaleUtils.getSubtypeLocaleDisplayName(locale.getLanguage()),
spacebarText);
}
}
}
// InputMethodSubtype's display name for spacebar text in its locale.
// isAdditionalSubtype (T=true, F=false)
// locale layout | Middle Full
// ------ ------- - --------- ----------------------
// en_US qwerty F English English (US) exception
// en_GB qwerty F English English (UK) exception
// es_US spanish F Español Español (EE.UU.) exception
// fr azerty F Français Français
// fr_CA qwerty F Français Français (Canada)
// fr_CH swiss F Français Français (Suisse)
// de qwertz F Deutsch Deutsch
// de_CH swiss F Deutsch Deutsch (Schweiz)
// zz qwerty F QWERTY QWERTY
// fr qwertz T Français Français
// de qwerty T Deutsch Deutsch
// en_US azerty T English English (US)
// zz azerty T AZERTY AZERTY
private final RunInLocale<Void> testsPredefinedSubtypesForSpacebar = new RunInLocale<Void>() {
@Override
protected Void job(final Resources res) {
assertEquals("en_US", "English (US)",
SpacebarLanguageUtils.getFullDisplayName(EN_US));
assertEquals("en_GB", "English (UK)",
SpacebarLanguageUtils.getFullDisplayName(EN_GB));
assertEquals("es_US", "Español (EE.UU.)",
SpacebarLanguageUtils.getFullDisplayName(ES_US));
assertEquals("fr", "Français",
SpacebarLanguageUtils.getFullDisplayName(FR));
assertEquals("fr_CA", "Français (Canada)",
SpacebarLanguageUtils.getFullDisplayName(FR_CA));
assertEquals("fr_CH", "Français (Suisse)",
SpacebarLanguageUtils.getFullDisplayName(FR_CH));
assertEquals("de", "Deutsch",
SpacebarLanguageUtils.getFullDisplayName(DE));
assertEquals("de_CH", "Deutsch (Schweiz)",
SpacebarLanguageUtils.getFullDisplayName(DE_CH));
assertEquals("zz", "QWERTY",
SpacebarLanguageUtils.getFullDisplayName(ZZ));
assertEquals("en_US", "English",
SpacebarLanguageUtils.getMiddleDisplayName(EN_US));
assertEquals("en_GB", "English",
SpacebarLanguageUtils.getMiddleDisplayName(EN_GB));
assertEquals("es_US", "Español",
SpacebarLanguageUtils.getMiddleDisplayName(ES_US));
assertEquals("fr", "Français",
SpacebarLanguageUtils.getMiddleDisplayName(FR));
assertEquals("fr_CA", "Français",
SpacebarLanguageUtils.getMiddleDisplayName(FR_CA));
assertEquals("fr_CH", "Français",
SpacebarLanguageUtils.getMiddleDisplayName(FR_CH));
assertEquals("de", "Deutsch",
SpacebarLanguageUtils.getMiddleDisplayName(DE));
assertEquals("de_CH", "Deutsch",
SpacebarLanguageUtils.getMiddleDisplayName(DE_CH));
assertEquals("zz", "QWERTY",
SpacebarLanguageUtils.getMiddleDisplayName(ZZ));
return null;
}
};
private final RunInLocale<Void> testsAdditionalSubtypesForSpacebar = new RunInLocale<Void>() {
@Override
protected Void job(final Resources res) {
assertEquals("fr qwertz", "Français",
SpacebarLanguageUtils.getFullDisplayName(FR_QWERTZ));
assertEquals("de qwerty", "Deutsch",
SpacebarLanguageUtils.getFullDisplayName(DE_QWERTY));
assertEquals("en_US azerty", "English (US)",
SpacebarLanguageUtils.getFullDisplayName(EN_US_AZERTY));
assertEquals("en_UK dvorak", "English (UK)",
SpacebarLanguageUtils.getFullDisplayName(EN_UK_DVORAK));
assertEquals("es_US colemak", "Español (EE.UU.)",
SpacebarLanguageUtils.getFullDisplayName(ES_US_COLEMAK));
assertEquals("zz azerty", "AZERTY",
SpacebarLanguageUtils.getFullDisplayName(ZZ_AZERTY));
assertEquals("zz pc", "PC",
SpacebarLanguageUtils.getFullDisplayName(ZZ_PC));
assertEquals("fr qwertz", "Français",
SpacebarLanguageUtils.getMiddleDisplayName(FR_QWERTZ));
assertEquals("de qwerty", "Deutsch",
SpacebarLanguageUtils.getMiddleDisplayName(DE_QWERTY));
assertEquals("en_US azerty", "English",
SpacebarLanguageUtils.getMiddleDisplayName(EN_US_AZERTY));
assertEquals("en_UK dvorak", "English",
SpacebarLanguageUtils.getMiddleDisplayName(EN_UK_DVORAK));
assertEquals("es_US colemak", "Español",
SpacebarLanguageUtils.getMiddleDisplayName(ES_US_COLEMAK));
assertEquals("zz azerty", "AZERTY",
SpacebarLanguageUtils.getMiddleDisplayName(ZZ_AZERTY));
assertEquals("zz pc", "PC",
SpacebarLanguageUtils.getMiddleDisplayName(ZZ_PC));
return null;
}
};
public void testPredefinedSubtypesForSpacebarInEnglish() {
testsPredefinedSubtypesForSpacebar.runInLocale(mRes, Locale.ENGLISH);
}
public void testAdditionalSubtypeForSpacebarInEnglish() {
testsAdditionalSubtypesForSpacebar.runInLocale(mRes, Locale.ENGLISH);
}
public void testPredefinedSubtypesForSpacebarInFrench() {
testsPredefinedSubtypesForSpacebar.runInLocale(mRes, Locale.FRENCH);
}
public void testAdditionalSubtypeForSpacebarInFrench() {
testsAdditionalSubtypesForSpacebar.runInLocale(mRes, Locale.FRENCH);
}
}

View File

@ -123,12 +123,23 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase {
assertEquals("en_US", "qwerty", SubtypeLocaleUtils.getKeyboardLayoutSetName(EN_US));
assertEquals("en_GB", "qwerty", SubtypeLocaleUtils.getKeyboardLayoutSetName(EN_GB));
assertEquals("es_US", "spanish", SubtypeLocaleUtils.getKeyboardLayoutSetName(ES_US));
assertEquals("fr ", "azerty", SubtypeLocaleUtils.getKeyboardLayoutSetName(FR));
assertEquals("fr", "azerty", SubtypeLocaleUtils.getKeyboardLayoutSetName(FR));
assertEquals("fr_CA", "qwerty", SubtypeLocaleUtils.getKeyboardLayoutSetName(FR_CA));
assertEquals("fr_CH", "swiss", SubtypeLocaleUtils.getKeyboardLayoutSetName(FR_CH));
assertEquals("de ", "qwertz", SubtypeLocaleUtils.getKeyboardLayoutSetName(DE));
assertEquals("de", "qwertz", SubtypeLocaleUtils.getKeyboardLayoutSetName(DE));
assertEquals("de_CH", "swiss", SubtypeLocaleUtils.getKeyboardLayoutSetName(DE_CH));
assertEquals("zz ", "qwerty", SubtypeLocaleUtils.getKeyboardLayoutSetName(ZZ));
assertEquals("zz", "qwerty", SubtypeLocaleUtils.getKeyboardLayoutSetName(ZZ));
assertEquals("de qwerty", "qwerty", SubtypeLocaleUtils.getKeyboardLayoutSetName(DE_QWERTY));
assertEquals("fr qwertz", "qwertz", SubtypeLocaleUtils.getKeyboardLayoutSetName(FR_QWERTZ));
assertEquals("en_US azerty", "azerty",
SubtypeLocaleUtils.getKeyboardLayoutSetName(EN_US_AZERTY));
assertEquals("en_UK dvorak", "dvorak",
SubtypeLocaleUtils.getKeyboardLayoutSetName(EN_UK_DVORAK));
assertEquals("es_US colemak", "colemak",
SubtypeLocaleUtils.getKeyboardLayoutSetName(ES_US_COLEMAK));
assertEquals("zz azerty", "azerty",
SubtypeLocaleUtils.getKeyboardLayoutSetName(ZZ_AZERTY));
}
// InputMethodSubtype's display name in system locale (en_US).
@ -161,17 +172,17 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase {
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(EN_GB));
assertEquals("es_US", "Spanish (US)",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(ES_US));
assertEquals("fr ", "French",
assertEquals("fr", "French",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(FR));
assertEquals("fr_CA", "French (Canada)",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(FR_CA));
assertEquals("fr_CH", "French (Switzerland)",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(FR_CH));
assertEquals("de ", "German",
assertEquals("de", "German",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(DE));
assertEquals("de_CH", "German (Switzerland)",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(DE_CH));
assertEquals("zz ", "Alphabet (QWERTY)",
assertEquals("zz", "Alphabet (QWERTY)",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(ZZ));
return null;
}
@ -183,17 +194,19 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase {
final RunInLocale<Void> tests = new RunInLocale<Void>() {
@Override
protected Void job(final Resources res) {
assertEquals("fr qwertz", "French (QWERTZ)",
assertEquals("fr qwertz", "French (QWERTZ)",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(FR_QWERTZ));
assertEquals("de qwerty", "German (QWERTY)",
assertEquals("de qwerty", "German (QWERTY)",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(DE_QWERTY));
assertEquals("en_US azerty", "English (US) (AZERTY)",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(EN_US_AZERTY));
assertEquals("en_UK dvorak", "English (UK) (Dvorak)",
assertEquals("en_UK dvorak","English (UK) (Dvorak)",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(EN_UK_DVORAK));
assertEquals("es_US colemak","Spanish (US) (Colemak)",
assertEquals("es_US colemak", "Spanish (US) (Colemak)",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(ES_US_COLEMAK));
assertEquals("zz pc", "Alphabet (PC)",
assertEquals("zz azerty", "Alphabet (AZERTY)",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(ZZ_AZERTY));
assertEquals("zz pc", "Alphabet (PC)",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(ZZ_PC));
return null;
}
@ -231,17 +244,17 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase {
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(EN_GB));
assertEquals("es_US", "Espagnol (États-Unis)",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(ES_US));
assertEquals("fr ", "Français",
assertEquals("fr", "Français",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(FR));
assertEquals("fr_CA", "Français (Canada)",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(FR_CA));
assertEquals("fr_CH", "Français (Suisse)",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(FR_CH));
assertEquals("de ", "Allemand",
assertEquals("de", "Allemand",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(DE));
assertEquals("de_CH", "Allemand (Suisse)",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(DE_CH));
assertEquals("zz ", "Alphabet latin (QWERTY)",
assertEquals("zz", "Alphabet latin (QWERTY)",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(ZZ));
return null;
}
@ -253,17 +266,19 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase {
final RunInLocale<Void> tests = new RunInLocale<Void>() {
@Override
protected Void job(final Resources res) {
assertEquals("fr qwertz", "Français (QWERTZ)",
assertEquals("fr qwertz", "Français (QWERTZ)",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(FR_QWERTZ));
assertEquals("de qwerty", "Allemand (QWERTY)",
assertEquals("de qwerty", "Allemand (QWERTY)",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(DE_QWERTY));
assertEquals("en_US azerty", "Anglais (États-Unis) (AZERTY)",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(EN_US_AZERTY));
assertEquals("en_UK dvorak", "Anglais (Royaume-Uni) (Dvorak)",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(EN_UK_DVORAK));
assertEquals("es_US colemak","Espagnol (États-Unis) (Colemak)",
assertEquals("es_US colemak", "Espagnol (États-Unis) (Colemak)",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(ES_US_COLEMAK));
assertEquals("zz pc", "Alphabet latin (PC)",
assertEquals("zz azerty", "Alphabet latin (AZERTY)",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(ZZ_AZERTY));
assertEquals("zz pc", "Alphabet latin (PC)",
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(ZZ_PC));
return null;
}
@ -271,126 +286,6 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase {
tests.runInLocale(mRes, Locale.FRENCH);
}
public void testAllFullDisplayNameForSpacebar() {
for (final InputMethodSubtype subtype : mSubtypesList) {
final String subtypeName = SubtypeLocaleUtils
.getSubtypeDisplayNameInSystemLocale(subtype);
final String spacebarText = SubtypeLocaleUtils.getFullDisplayName(subtype);
final String languageName = SubtypeLocaleUtils
.getSubtypeLocaleDisplayName(subtype.getLocale());
if (SubtypeLocaleUtils.isNoLanguage(subtype)) {
assertFalse(subtypeName, spacebarText.contains(languageName));
} else {
assertTrue(subtypeName, spacebarText.contains(languageName));
}
}
}
public void testAllMiddleDisplayNameForSpacebar() {
for (final InputMethodSubtype subtype : mSubtypesList) {
final String subtypeName = SubtypeLocaleUtils
.getSubtypeDisplayNameInSystemLocale(subtype);
final String spacebarText = SubtypeLocaleUtils.getMiddleDisplayName(subtype);
if (SubtypeLocaleUtils.isNoLanguage(subtype)) {
assertEquals(subtypeName,
SubtypeLocaleUtils.getKeyboardLayoutSetDisplayName(subtype), spacebarText);
} else {
final Locale locale = SubtypeLocaleUtils.getSubtypeLocale(subtype);
assertEquals(subtypeName,
SubtypeLocaleUtils.getSubtypeLocaleDisplayName(locale.getLanguage()),
spacebarText);
}
}
}
// InputMethodSubtype's display name for spacebar text in its locale.
// isAdditionalSubtype (T=true, F=false)
// locale layout | Middle Full
// ------ ------- - --------- ----------------------
// en_US qwerty F English English (US) exception
// en_GB qwerty F English English (UK) exception
// es_US spanish F Español Español (EE.UU.) exception
// fr azerty F Français Français
// fr_CA qwerty F Français Français (Canada)
// fr_CH swiss F Français Français (Suisse)
// de qwertz F Deutsch Deutsch
// de_CH swiss F Deutsch Deutsch (Schweiz)
// zz qwerty F QWERTY QWERTY
// fr qwertz T Français Français
// de qwerty T Deutsch Deutsch
// en_US azerty T English English (US)
// zz azerty T AZERTY AZERTY
private final RunInLocale<Void> testsPredefinedSubtypesForSpacebar = new RunInLocale<Void>() {
@Override
protected Void job(final Resources res) {
assertEquals("en_US", "English (US)", SubtypeLocaleUtils.getFullDisplayName(EN_US));
assertEquals("en_GB", "English (UK)", SubtypeLocaleUtils.getFullDisplayName(EN_GB));
assertEquals("es_US", "Español (EE.UU.)",
SubtypeLocaleUtils.getFullDisplayName(ES_US));
assertEquals("fr ", "Français", SubtypeLocaleUtils.getFullDisplayName(FR));
assertEquals("fr_CA", "Français (Canada)",
SubtypeLocaleUtils.getFullDisplayName(FR_CA));
assertEquals("fr_CH", "Français (Suisse)",
SubtypeLocaleUtils.getFullDisplayName(FR_CH));
assertEquals("de ", "Deutsch", SubtypeLocaleUtils.getFullDisplayName(DE));
assertEquals("de_CH", "Deutsch (Schweiz)",
SubtypeLocaleUtils.getFullDisplayName(DE_CH));
assertEquals("zz ", "QWERTY", SubtypeLocaleUtils.getFullDisplayName(ZZ));
assertEquals("en_US", "English", SubtypeLocaleUtils.getMiddleDisplayName(EN_US));
assertEquals("en_GB", "English", SubtypeLocaleUtils.getMiddleDisplayName(EN_GB));
assertEquals("es_US", "Español", SubtypeLocaleUtils.getMiddleDisplayName(ES_US));
assertEquals("fr ", "Français", SubtypeLocaleUtils.getMiddleDisplayName(FR));
assertEquals("fr_CA", "Français", SubtypeLocaleUtils.getMiddleDisplayName(FR_CA));
assertEquals("fr_CH", "Français", SubtypeLocaleUtils.getMiddleDisplayName(FR_CH));
assertEquals("de ", "Deutsch", SubtypeLocaleUtils.getMiddleDisplayName(DE));
assertEquals("de_CH", "Deutsch", SubtypeLocaleUtils.getMiddleDisplayName(DE_CH));
assertEquals("zz ", "QWERTY", SubtypeLocaleUtils.getMiddleDisplayName(ZZ));
return null;
}
};
private final RunInLocale<Void> testsAdditionalSubtypesForSpacebar = new RunInLocale<Void>() {
@Override
protected Void job(final Resources res) {
assertEquals("fr qwertz", "Français",
SubtypeLocaleUtils.getFullDisplayName(FR_QWERTZ));
assertEquals("de qwerty", "Deutsch",
SubtypeLocaleUtils.getFullDisplayName(DE_QWERTY));
assertEquals("en_US azerty", "English (US)",
SubtypeLocaleUtils.getFullDisplayName(EN_US_AZERTY));
assertEquals("zz azerty", "AZERTY",
SubtypeLocaleUtils.getFullDisplayName(ZZ_AZERTY));
assertEquals("fr qwertz", "Français",
SubtypeLocaleUtils.getMiddleDisplayName(FR_QWERTZ));
assertEquals("de qwerty", "Deutsch",
SubtypeLocaleUtils.getMiddleDisplayName(DE_QWERTY));
assertEquals("en_US azerty", "English",
SubtypeLocaleUtils.getMiddleDisplayName(EN_US_AZERTY));
assertEquals("zz azerty", "AZERTY",
SubtypeLocaleUtils.getMiddleDisplayName(ZZ_AZERTY));
return null;
}
};
public void testPredefinedSubtypesForSpacebarInEnglish() {
testsPredefinedSubtypesForSpacebar.runInLocale(mRes, Locale.ENGLISH);
}
public void testAdditionalSubtypeForSpacebarInEnglish() {
testsAdditionalSubtypesForSpacebar.runInLocale(mRes, Locale.ENGLISH);
}
public void testPredefinedSubtypesForSpacebarInFrench() {
testsPredefinedSubtypesForSpacebar.runInLocale(mRes, Locale.FRENCH);
}
public void testAdditionalSubtypeForSpacebarInFrench() {
testsAdditionalSubtypesForSpacebar.runInLocale(mRes, Locale.FRENCH);
}
public void testIsRtlLanguage() {
// Known Right-to-Left language subtypes.
final InputMethodSubtype ARABIC = mRichImm