Use SubtypeLocaleUtils.isRtlLanguage

Change-Id: Ic0208412cd9c02975641cb5c448d092f28786746
main
Tadashi G. Takaoka 2014-02-06 15:43:00 +09:00
parent 48ea52800a
commit 3bbd50c36b
6 changed files with 26 additions and 40 deletions

View File

@ -276,9 +276,9 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
params.mThemeId = keyboardAttr.getInt(R.styleable.Keyboard_themeId, 0);
params.mIconsSet.loadIcons(keyboardAttr);
final String language = params.mId.mLocale.getLanguage();
params.mCodesSet.setLanguage(language);
params.mTextsSet.setLanguage(language);
final Locale locale = params.mId.mLocale;
params.mCodesSet.setLocale(locale);
params.mTextsSet.setLocale(locale);
final RunInLocale<Void> job = new RunInLocale<Void>() {
@Override
protected Void job(final Resources res) {
@ -287,9 +287,8 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
}
};
// Null means the current system locale.
final Locale locale = SubtypeLocaleUtils.isNoLanguage(params.mId.mSubtype)
? null : params.mId.mLocale;
job.runInLocale(mResources, locale);
job.runInLocale(mResources,
SubtypeLocaleUtils.isNoLanguage(params.mId.mSubtype) ? null : locale);
final int resourceId = keyboardAttr.getResourceId(
R.styleable.Keyboard_touchPositionCorrectionData, 0);

View File

@ -18,20 +18,20 @@ package com.android.inputmethod.keyboard.internal;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.utils.CollectionUtils;
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
import java.util.HashMap;
import java.util.Locale;
public final class KeyboardCodesSet {
public static final String PREFIX_CODE = "!code/";
private static final HashMap<String, int[]> sLanguageToCodesMap = CollectionUtils.newHashMap();
private static final HashMap<String, Integer> sNameToIdMap = CollectionUtils.newHashMap();
private int[] mCodes = DEFAULT;
public void setLanguage(final String language) {
final int[] codes = sLanguageToCodesMap.get(language);
mCodes = (codes != null) ? codes : DEFAULT;
public void setLocale(final Locale locale) {
mCodes = SubtypeLocaleUtils.isRtlLanguage(locale) ? RTL : DEFAULT;
}
public int getCode(final String name) {
@ -134,18 +134,6 @@ public final class KeyboardCodesSet {
CODE_LEFT_CURLY_BRACKET,
};
private static final String LANGUAGE_DEFAULT = "DEFAULT";
private static final String LANGUAGE_ARABIC = "ar";
private static final String LANGUAGE_PERSIAN = "fa";
private static final String LANGUAGE_HEBREW = "iw";
private static final Object[] LANGUAGE_AND_CODES = {
LANGUAGE_DEFAULT, DEFAULT,
LANGUAGE_ARABIC, RTL,
LANGUAGE_PERSIAN, RTL,
LANGUAGE_HEBREW, RTL,
};
static {
if (DEFAULT.length != RTL.length || DEFAULT.length != ID_TO_NAME.length) {
throw new RuntimeException("Internal inconsistency");
@ -153,11 +141,5 @@ public final class KeyboardCodesSet {
for (int i = 0; i < ID_TO_NAME.length; i++) {
sNameToIdMap.put(ID_TO_NAME[i], i);
}
for (int i = 0; i < LANGUAGE_AND_CODES.length; i += 2) {
final String language = (String)LANGUAGE_AND_CODES[i];
final int[] codes = (int[])LANGUAGE_AND_CODES[i + 1];
sLanguageToCodesMap.put(language, codes);
}
}
}

View File

@ -25,6 +25,7 @@ import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.utils.CollectionUtils;
import java.util.HashMap;
import java.util.Locale;
/**
* !!!!! DO NOT EDIT THIS FILE !!!!!
@ -52,15 +53,17 @@ public final class KeyboardTextsSet {
private static final int MAX_STRING_REFERENCE_INDIRECTION = 10;
// Language to texts map.
private static final HashMap<String, String[]> sLocaleToTextsMap = CollectionUtils.newHashMap();
private static final HashMap<String, String[]> sLanguageToTextsMap =
CollectionUtils.newHashMap();
private static final HashMap<String, Integer> sNameToIdsMap = CollectionUtils.newHashMap();
private String[] mTexts;
// Resource name to text map.
private HashMap<String, String> mResourceNameToTextsMap = CollectionUtils.newHashMap();
public void setLanguage(final String language) {
mTexts = sLocaleToTextsMap.get(language);
public void setLocale(final Locale locale) {
final String language = locale.getLanguage();
mTexts = sLanguageToTextsMap.get(language);
if (mTexts == null) {
mTexts = LANGUAGE_DEFAULT;
}
@ -3647,7 +3650,7 @@ public final class KeyboardTextsSet {
for (int i = 0; i < LANGUAGES_AND_TEXTS.length; i += 2) {
final String language = (String)LANGUAGES_AND_TEXTS[i];
final String[] texts = (String[])LANGUAGES_AND_TEXTS[i + 1];
sLocaleToTextsMap.put(language, texts);
sLanguageToTextsMap.put(language, texts);
}
}
}

View File

@ -52,9 +52,8 @@ abstract class KeySpecParserTestsBase extends AndroidTestCase {
protected void setUp() throws Exception {
super.setUp();
final String language = TEST_LOCALE.getLanguage();
mCodesSet.setLanguage(language);
mTextsSet.setLanguage(language);
mCodesSet.setLocale(TEST_LOCALE);
mTextsSet.setLocale(TEST_LOCALE);
final Context context = getContext();
new RunInLocale<Void>() {
@Override

View File

@ -41,7 +41,7 @@ public class MoreKeySpecSplitTests extends InstrumentationTestCase {
final Instrumentation instrumentation = getInstrumentation();
final Context targetContext = instrumentation.getTargetContext();
mTextsSet.setLanguage(TEST_LOCALE.getLanguage());
mTextsSet.setLocale(TEST_LOCALE);
new RunInLocale<Void>() {
@Override
protected Void job(final Resources res) {

View File

@ -25,6 +25,7 @@ import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.utils.CollectionUtils;
import java.util.HashMap;
import java.util.Locale;
/**
* !!!!! DO NOT EDIT THIS FILE !!!!!
@ -52,15 +53,17 @@ public final class KeyboardTextsSet {
private static final int MAX_STRING_REFERENCE_INDIRECTION = 10;
// Language to texts map.
private static final HashMap<String, String[]> sLocaleToTextsMap = CollectionUtils.newHashMap();
private static final HashMap<String, String[]> sLanguageToTextsMap =
CollectionUtils.newHashMap();
private static final HashMap<String, Integer> sNameToIdsMap = CollectionUtils.newHashMap();
private String[] mTexts;
// Resource name to text map.
private HashMap<String, String> mResourceNameToTextsMap = CollectionUtils.newHashMap();
public void setLanguage(final String language) {
mTexts = sLocaleToTextsMap.get(language);
public void setLocale(final Locale locale) {
final String language = locale.getLanguage();
mTexts = sLanguageToTextsMap.get(language);
if (mTexts == null) {
mTexts = LANGUAGE_DEFAULT;
}
@ -195,7 +198,7 @@ public final class KeyboardTextsSet {
for (int i = 0; i < LANGUAGES_AND_TEXTS.length; i += 2) {
final String language = (String)LANGUAGES_AND_TEXTS[i];
final String[] texts = (String[])LANGUAGES_AND_TEXTS[i + 1];
sLocaleToTextsMap.put(language, texts);
sLanguageToTextsMap.put(language, texts);
}
}
}