am c2e2b394: Merge "Add SubtypeLocaleUtils.isRtlLanguage method"
* commit 'c2e2b3949b159d6412e0e5815c1503d94b2b5ce7': Add SubtypeLocaleUtils.isRtlLanguage methodmain
commit
a4d04eb863
|
@ -25,9 +25,11 @@ import android.os.Build;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.inputmethod.InputMethodSubtype;
|
import android.view.inputmethod.InputMethodSubtype;
|
||||||
|
|
||||||
|
import com.android.inputmethod.annotations.UsedForTesting;
|
||||||
import com.android.inputmethod.latin.DictionaryFactory;
|
import com.android.inputmethod.latin.DictionaryFactory;
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
@ -334,4 +336,23 @@ public final class SubtypeLocaleUtils {
|
||||||
final Locale locale = getSubtypeLocale(subtype);
|
final Locale locale = getSubtypeLocale(subtype);
|
||||||
return StringUtils.capitalizeFirstCodePoint(locale.getLanguage(), locale);
|
return StringUtils.capitalizeFirstCodePoint(locale.getLanguage(), locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 = {
|
||||||
|
"ar", // Arabic
|
||||||
|
"fa", // Persian
|
||||||
|
"iw", // Hebrew
|
||||||
|
};
|
||||||
|
static {
|
||||||
|
Arrays.sort(SORTED_RTL_LANGUAGES);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Remove @UsedForTesting annotation.
|
||||||
|
@UsedForTesting
|
||||||
|
public static boolean isRtlLanguage(final InputMethodSubtype subtype) {
|
||||||
|
final Locale locale = getSubtypeLocale(subtype);
|
||||||
|
final String language = locale.getLanguage();
|
||||||
|
return Arrays.binarySearch(SORTED_RTL_LANGUAGES, language) >= 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,7 +101,6 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase {
|
||||||
SubtypeLocaleUtils.NO_LANGUAGE, "azerty", null);
|
SubtypeLocaleUtils.NO_LANGUAGE, "azerty", null);
|
||||||
ZZ_PC = AdditionalSubtypeUtils.createAdditionalSubtype(
|
ZZ_PC = AdditionalSubtypeUtils.createAdditionalSubtype(
|
||||||
SubtypeLocaleUtils.NO_LANGUAGE, "pcqwerty", null);
|
SubtypeLocaleUtils.NO_LANGUAGE, "pcqwerty", null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAllFullDisplayName() {
|
public void testAllFullDisplayName() {
|
||||||
|
@ -423,4 +422,27 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase {
|
||||||
public void testAdditionalSubtypeForSpacebarInFrench() {
|
public void testAdditionalSubtypeForSpacebarInFrench() {
|
||||||
testsAdditionalSubtypesForSpacebar.runInLocale(mRes, Locale.FRENCH);
|
testsAdditionalSubtypesForSpacebar.runInLocale(mRes, Locale.FRENCH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testIsRtlLanguage() {
|
||||||
|
// Known Right-to-Left language subtypes.
|
||||||
|
final InputMethodSubtype ARABIC = mRichImm
|
||||||
|
.findSubtypeByLocaleAndKeyboardLayoutSet("ar", "arabic");
|
||||||
|
assertNotNull("Arabic", ARABIC);
|
||||||
|
final InputMethodSubtype FARSI = mRichImm
|
||||||
|
.findSubtypeByLocaleAndKeyboardLayoutSet("fa", "farsi");
|
||||||
|
assertNotNull("Farsi", FARSI);
|
||||||
|
final InputMethodSubtype HEBREW = mRichImm
|
||||||
|
.findSubtypeByLocaleAndKeyboardLayoutSet("iw", "hebrew");
|
||||||
|
assertNotNull("Hebrew", HEBREW);
|
||||||
|
|
||||||
|
for (final InputMethodSubtype subtype : mSubtypesList) {
|
||||||
|
final String subtypeName = SubtypeLocaleUtils
|
||||||
|
.getSubtypeDisplayNameInSystemLocale(subtype);
|
||||||
|
if (subtype.equals(ARABIC) || subtype.equals(FARSI) || subtype.equals(HEBREW)) {
|
||||||
|
assertTrue(subtypeName, SubtypeLocaleUtils.isRtlLanguage(subtype));
|
||||||
|
} else {
|
||||||
|
assertFalse(subtypeName, SubtypeLocaleUtils.isRtlLanguage(subtype));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue