Add SubtypeLocaleUtils.isRtlLanguage method
Change-Id: I2e399ae9ca111638b583c5681de08b0e6db86e3a
This commit is contained in:
parent
1e4b1300e6
commit
c0c74d22a0
2 changed files with 44 additions and 1 deletions
|
@ -25,9 +25,11 @@ import android.os.Build;
|
|||
import android.util.Log;
|
||||
import android.view.inputmethod.InputMethodSubtype;
|
||||
|
||||
import com.android.inputmethod.annotations.UsedForTesting;
|
||||
import com.android.inputmethod.latin.DictionaryFactory;
|
||||
import com.android.inputmethod.latin.R;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
|
||||
|
@ -334,4 +336,23 @@ public final class SubtypeLocaleUtils {
|
|||
final Locale locale = getSubtypeLocale(subtype);
|
||||
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);
|
||||
ZZ_PC = AdditionalSubtypeUtils.createAdditionalSubtype(
|
||||
SubtypeLocaleUtils.NO_LANGUAGE, "pcqwerty", null);
|
||||
|
||||
}
|
||||
|
||||
public void testAllFullDisplayName() {
|
||||
|
@ -423,4 +422,27 @@ public class SubtypeLocaleUtilsTests extends AndroidTestCase {
|
|||
public void testAdditionalSubtypeForSpacebarInFrench() {
|
||||
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 a new issue