diff options
Diffstat (limited to 'java')
-rw-r--r-- | java/res/values/attrs.xml | 25 | ||||
-rw-r--r-- | java/res/xml/keyboard_layout_set_bengali.xml | 2 | ||||
-rw-r--r-- | java/res/xml/keyboard_layout_set_hindi.xml | 2 | ||||
-rw-r--r-- | java/res/xml/keyboard_layout_set_hindi_compact.xml | 2 | ||||
-rw-r--r-- | java/res/xml/keyboard_layout_set_kannada.xml | 2 | ||||
-rw-r--r-- | java/res/xml/keyboard_layout_set_khmer.xml | 2 | ||||
-rw-r--r-- | java/res/xml/keyboard_layout_set_lao.xml | 2 | ||||
-rw-r--r-- | java/res/xml/keyboard_layout_set_malayalam.xml | 2 | ||||
-rw-r--r-- | java/res/xml/keyboard_layout_set_marathi.xml | 2 | ||||
-rw-r--r-- | java/res/xml/keyboard_layout_set_myanmar.xml | 2 | ||||
-rw-r--r-- | java/res/xml/keyboard_layout_set_nepali_romanized.xml | 2 | ||||
-rw-r--r-- | java/res/xml/keyboard_layout_set_nepali_traditional.xml | 2 | ||||
-rw-r--r-- | java/res/xml/keyboard_layout_set_sinhala.xml | 2 | ||||
-rw-r--r-- | java/res/xml/keyboard_layout_set_tamil.xml | 2 | ||||
-rw-r--r-- | java/res/xml/keyboard_layout_set_telugu.xml | 2 | ||||
-rw-r--r-- | java/res/xml/keyboard_layout_set_thai.xml | 2 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/latin/utils/ScriptUtils.java | 123 |
17 files changed, 135 insertions, 43 deletions
diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index 5434106c5..003b011f3 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -481,13 +481,24 @@ <declare-styleable name="KeyboardLayoutSet_Feature"> <!-- This should be aligned with ScriptUtils.SCRIPT_* --> <attr name="supportedScript" format="enum"> - <enum name="latin" value="0" /> - <enum name="cyrillic" value="1" /> - <enum name="greek" value="2" /> - <enum name="arabic" value="3" /> - <enum name="hebrew" value="4" /> - <enum name="armenian" value="5" /> - <enum name="georgian" value="6" /> + <enum name="arabic" value="0" /> + <enum name="armenian" value="1" /> + <enum name="bengali" value="2" /> + <enum name="cyrillic" value="3" /> + <enum name="devanagari" value="4" /> + <enum name="georgian" value="5" /> + <enum name="greek" value="6" /> + <enum name="hebrew" value="7" /> + <enum name="kannada" value="8" /> + <enum name="khmer" value="9" /> + <enum name="lao" value="10" /> + <enum name="latin" value="11" /> + <enum name="malayalam" value="12" /> + <enum name="myanmar" value="13" /> + <enum name="sinhala" value="14" /> + <enum name="tamil" value="15" /> + <enum name="telugu" value="16" /> + <enum name="thai" value="17" /> </attr> </declare-styleable> diff --git a/java/res/xml/keyboard_layout_set_bengali.xml b/java/res/xml/keyboard_layout_set_bengali.xml index 6e40e6de4..de48a0ceb 100644 --- a/java/res/xml/keyboard_layout_set_bengali.xml +++ b/java/res/xml/keyboard_layout_set_bengali.xml @@ -20,6 +20,8 @@ <KeyboardLayoutSet xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + <Feature + latin:supportedScript="bengali" /> <Element latin:elementName="alphabet" latin:elementKeyboard="@xml/kbd_bengali" diff --git a/java/res/xml/keyboard_layout_set_hindi.xml b/java/res/xml/keyboard_layout_set_hindi.xml index e850c7ebc..ee41b2ae7 100644 --- a/java/res/xml/keyboard_layout_set_hindi.xml +++ b/java/res/xml/keyboard_layout_set_hindi.xml @@ -20,6 +20,8 @@ <KeyboardLayoutSet xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + <Feature + latin:supportedScript="devanagari" /> <Element latin:elementName="alphabet" latin:elementKeyboard="@xml/kbd_hindi" diff --git a/java/res/xml/keyboard_layout_set_hindi_compact.xml b/java/res/xml/keyboard_layout_set_hindi_compact.xml index 77d02fbbc..147b2993f 100644 --- a/java/res/xml/keyboard_layout_set_hindi_compact.xml +++ b/java/res/xml/keyboard_layout_set_hindi_compact.xml @@ -20,6 +20,8 @@ <KeyboardLayoutSet xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + <Feature + latin:supportedScript="devanagari" /> <Element latin:elementName="alphabet" latin:elementKeyboard="@xml/kbd_hindi_compact" diff --git a/java/res/xml/keyboard_layout_set_kannada.xml b/java/res/xml/keyboard_layout_set_kannada.xml index 8dcf99657..14323e7ef 100644 --- a/java/res/xml/keyboard_layout_set_kannada.xml +++ b/java/res/xml/keyboard_layout_set_kannada.xml @@ -20,6 +20,8 @@ <KeyboardLayoutSet xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + <Feature + latin:supportedScript="kannada" /> <Element latin:elementName="alphabet" latin:elementKeyboard="@xml/kbd_kannada" diff --git a/java/res/xml/keyboard_layout_set_khmer.xml b/java/res/xml/keyboard_layout_set_khmer.xml index 181f98b3d..752c8520a 100644 --- a/java/res/xml/keyboard_layout_set_khmer.xml +++ b/java/res/xml/keyboard_layout_set_khmer.xml @@ -20,6 +20,8 @@ <KeyboardLayoutSet xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + <Feature + latin:supportedScript="khmer" /> <Element latin:elementName="alphabet" latin:elementKeyboard="@xml/kbd_khmer" diff --git a/java/res/xml/keyboard_layout_set_lao.xml b/java/res/xml/keyboard_layout_set_lao.xml index 2ffde45db..6285f87f9 100644 --- a/java/res/xml/keyboard_layout_set_lao.xml +++ b/java/res/xml/keyboard_layout_set_lao.xml @@ -20,6 +20,8 @@ <KeyboardLayoutSet xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + <Feature + latin:supportedScript="lao" /> <Element latin:elementName="alphabet" latin:elementKeyboard="@xml/kbd_lao" diff --git a/java/res/xml/keyboard_layout_set_malayalam.xml b/java/res/xml/keyboard_layout_set_malayalam.xml index 14c76baf0..f6086f6cb 100644 --- a/java/res/xml/keyboard_layout_set_malayalam.xml +++ b/java/res/xml/keyboard_layout_set_malayalam.xml @@ -20,6 +20,8 @@ <KeyboardLayoutSet xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + <Feature + latin:supportedScript="malayalam" /> <Element latin:elementName="alphabet" latin:elementKeyboard="@xml/kbd_malayalam" diff --git a/java/res/xml/keyboard_layout_set_marathi.xml b/java/res/xml/keyboard_layout_set_marathi.xml index e5c68e7ce..6aea17546 100644 --- a/java/res/xml/keyboard_layout_set_marathi.xml +++ b/java/res/xml/keyboard_layout_set_marathi.xml @@ -20,6 +20,8 @@ <KeyboardLayoutSet xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + <Feature + latin:supportedScript="devanagari" /> <Element latin:elementName="alphabet" latin:elementKeyboard="@xml/kbd_marathi" diff --git a/java/res/xml/keyboard_layout_set_myanmar.xml b/java/res/xml/keyboard_layout_set_myanmar.xml index 5c823b263..5af8c064e 100644 --- a/java/res/xml/keyboard_layout_set_myanmar.xml +++ b/java/res/xml/keyboard_layout_set_myanmar.xml @@ -20,6 +20,8 @@ <KeyboardLayoutSet xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + <Feature + latin:supportedScript="myanmar" /> <Element latin:elementName="alphabet" latin:elementKeyboard="@xml/kbd_myanmar" diff --git a/java/res/xml/keyboard_layout_set_nepali_romanized.xml b/java/res/xml/keyboard_layout_set_nepali_romanized.xml index fbbc6a5a0..5bad83537 100644 --- a/java/res/xml/keyboard_layout_set_nepali_romanized.xml +++ b/java/res/xml/keyboard_layout_set_nepali_romanized.xml @@ -20,6 +20,8 @@ <KeyboardLayoutSet xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + <Feature + latin:supportedScript="devanagari" /> <Element latin:elementName="alphabet" latin:elementKeyboard="@xml/kbd_nepali_romanized" diff --git a/java/res/xml/keyboard_layout_set_nepali_traditional.xml b/java/res/xml/keyboard_layout_set_nepali_traditional.xml index 4a3b60153..6f11dee58 100644 --- a/java/res/xml/keyboard_layout_set_nepali_traditional.xml +++ b/java/res/xml/keyboard_layout_set_nepali_traditional.xml @@ -20,6 +20,8 @@ <KeyboardLayoutSet xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + <Feature + latin:supportedScript="devanagari" /> <Element latin:elementName="alphabet" latin:elementKeyboard="@xml/kbd_nepali_traditional" diff --git a/java/res/xml/keyboard_layout_set_sinhala.xml b/java/res/xml/keyboard_layout_set_sinhala.xml index 8e6e619d2..1955d218f 100644 --- a/java/res/xml/keyboard_layout_set_sinhala.xml +++ b/java/res/xml/keyboard_layout_set_sinhala.xml @@ -20,6 +20,8 @@ <KeyboardLayoutSet xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + <Feature + latin:supportedScript="sinhala" /> <Element latin:elementName="alphabet" latin:elementKeyboard="@xml/kbd_sinhala" diff --git a/java/res/xml/keyboard_layout_set_tamil.xml b/java/res/xml/keyboard_layout_set_tamil.xml index 5c0491505..27f4a3266 100644 --- a/java/res/xml/keyboard_layout_set_tamil.xml +++ b/java/res/xml/keyboard_layout_set_tamil.xml @@ -20,6 +20,8 @@ <KeyboardLayoutSet xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + <Feature + latin:supportedScript="tamil" /> <Element latin:elementName="alphabet" latin:elementKeyboard="@xml/kbd_tamil" diff --git a/java/res/xml/keyboard_layout_set_telugu.xml b/java/res/xml/keyboard_layout_set_telugu.xml index aca47b9d9..2bf65bcbd 100644 --- a/java/res/xml/keyboard_layout_set_telugu.xml +++ b/java/res/xml/keyboard_layout_set_telugu.xml @@ -20,6 +20,8 @@ <KeyboardLayoutSet xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + <Feature + latin:supportedScript="telugu" /> <Element latin:elementName="alphabet" latin:elementKeyboard="@xml/kbd_telugu" diff --git a/java/res/xml/keyboard_layout_set_thai.xml b/java/res/xml/keyboard_layout_set_thai.xml index b8f99971b..f69dfa6bd 100644 --- a/java/res/xml/keyboard_layout_set_thai.xml +++ b/java/res/xml/keyboard_layout_set_thai.xml @@ -20,6 +20,8 @@ <KeyboardLayoutSet xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + <Feature + latin:supportedScript="thai" /> <Element latin:elementName="alphabet" latin:elementKeyboard="@xml/kbd_thai" diff --git a/java/src/com/android/inputmethod/latin/utils/ScriptUtils.java b/java/src/com/android/inputmethod/latin/utils/ScriptUtils.java index a76a6dfd7..0e244666d 100644 --- a/java/src/com/android/inputmethod/latin/utils/ScriptUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/ScriptUtils.java @@ -26,13 +26,24 @@ public class ScriptUtils { // Used for hardware keyboards public static final int SCRIPT_UNKNOWN = -1; // TODO: should we use ISO 15924 identifiers instead? - public static final int SCRIPT_LATIN = 0; - public static final int SCRIPT_CYRILLIC = 1; - public static final int SCRIPT_GREEK = 2; - public static final int SCRIPT_ARABIC = 3; - public static final int SCRIPT_HEBREW = 4; - public static final int SCRIPT_ARMENIAN = 5; - public static final int SCRIPT_GEORGIAN = 6; + public static final int SCRIPT_ARABIC = 0; + public static final int SCRIPT_ARMENIAN = 1; + public static final int SCRIPT_BENGALI = 2; + public static final int SCRIPT_CYRILLIC = 3; + public static final int SCRIPT_DEVANAGARI = 4; + public static final int SCRIPT_GEORGIAN = 5; + public static final int SCRIPT_GREEK = 6; + public static final int SCRIPT_HEBREW = 7; + public static final int SCRIPT_KANNADA = 8; + public static final int SCRIPT_KHMER = 9; + public static final int SCRIPT_LAO = 10; + public static final int SCRIPT_LATIN = 11; + public static final int SCRIPT_MALAYALAM = 12; + public static final int SCRIPT_MYANMAR = 13; + public static final int SCRIPT_SINHALA = 14; + public static final int SCRIPT_TAMIL = 15; + public static final int SCRIPT_TELUGU = 16; + public static final int SCRIPT_THAI = 17; public static final TreeMap<String, Integer> mSpellCheckerLanguageToScript; static { // List of the supported languages and their associated script. We won't check @@ -72,56 +83,96 @@ public class ScriptUtils { */ public static boolean isLetterPartOfScript(final int codePoint, final int scriptId) { switch (scriptId) { - case SCRIPT_LATIN: - // Our supported latin script dictionaries (EFIGS) at the moment only include - // characters in the C0, C1, Latin Extended A and B, IPA extensions unicode - // blocks. As it happens, those are back-to-back in the code range 0x40 to 0x2AF, - // so the below is a very efficient way to test for it. As for the 0-0x3F, it's - // excluded from isLetter anyway. - return codePoint <= 0x2AF && Character.isLetter(codePoint); - case SCRIPT_CYRILLIC: - // All Cyrillic characters are in the 400~52F block. There are some in the upper - // Unicode range, but they are archaic characters that are not used in modern - // Russian and are not used by our dictionary. - return codePoint >= 0x400 && codePoint <= 0x52F && Character.isLetter(codePoint); - case SCRIPT_GREEK: - // Greek letters are either in the 370~3FF range (Greek & Coptic), or in the - // 1F00~1FFF range (Greek extended). Our dictionary contains both sort of characters. - // Our dictionary also contains a few words with 0xF2; it would be best to check - // if that's correct, but a web search does return results for these words so - // they are probably okay. - return (codePoint >= 0x370 && codePoint <= 0x3FF) - || (codePoint >= 0x1F00 && codePoint <= 0x1FFF) - || codePoint == 0xF2; case SCRIPT_ARABIC: // Arabic letters can be in any of the following blocks: // Arabic U+0600..U+06FF - // Arabic Supplement U+0750..U+077F + // Arabic Supplement, Thaana U+0750..U+077F, U+0780..U+07BF // Arabic Extended-A U+08A0..U+08FF // Arabic Presentation Forms-A U+FB50..U+FDFF // Arabic Presentation Forms-B U+FE70..U+FEFF return (codePoint >= 0x600 && codePoint <= 0x6FF) - || (codePoint >= 0x750 && codePoint <= 0x77F) + || (codePoint >= 0x750 && codePoint <= 0x7BF) || (codePoint >= 0x8A0 && codePoint <= 0x8FF) || (codePoint >= 0xFB50 && codePoint <= 0xFDFF) || (codePoint >= 0xFE70 && codePoint <= 0xFEFF); - case SCRIPT_HEBREW: - // Hebrew letters are in the Hebrew unicode block, which spans from U+0590 to U+05FF, - // or in the Alphabetic Presentation Forms block, U+FB00..U+FB4F, but only in the - // Hebrew part of that block, which is U+FB1D..U+FB4F. - return (codePoint >= 0x590 && codePoint <= 0x5FF - || codePoint >= 0xFB1D && codePoint <= 0xFB4F); case SCRIPT_ARMENIAN: // Armenian letters are in the Armenian unicode block, U+0530..U+058F and // Alphabetic Presentation Forms block, U+FB00..U+FB4F, but only in the Armenian part // of that block, which is U+FB13..U+FB17. return (codePoint >= 0x530 && codePoint <= 0x58F || codePoint >= 0xFB13 && codePoint <= 0xFB17); + case SCRIPT_BENGALI: + // Bengali unicode block is U+0980..U+09FF + return (codePoint >= 0x980 && codePoint <= 0x9FF); + case SCRIPT_CYRILLIC: + // All Cyrillic characters are in the 400~52F block. There are some in the upper + // Unicode range, but they are archaic characters that are not used in modern + // Russian and are not used by our dictionary. + return codePoint >= 0x400 && codePoint <= 0x52F && Character.isLetter(codePoint); + case SCRIPT_DEVANAGARI: + // Devanagari unicode block is +0900..U+097F + return (codePoint >= 0x900 && codePoint <= 0x97F); case SCRIPT_GEORGIAN: // Georgian letters are in the Georgian unicode block, U+10A0..U+10FF, // or Georgian supplement block, U+2D00..U+2D2F return (codePoint >= 0x10A0 && codePoint <= 0x10FF || codePoint >= 0x2D00 && codePoint <= 0x2D2F); + case SCRIPT_GREEK: + // Greek letters are either in the 370~3FF range (Greek & Coptic), or in the + // 1F00~1FFF range (Greek extended). Our dictionary contains both sort of characters. + // Our dictionary also contains a few words with 0xF2; it would be best to check + // if that's correct, but a web search does return results for these words so + // they are probably okay. + return (codePoint >= 0x370 && codePoint <= 0x3FF) + || (codePoint >= 0x1F00 && codePoint <= 0x1FFF) + || codePoint == 0xF2; + case SCRIPT_HEBREW: + // Hebrew letters are in the Hebrew unicode block, which spans from U+0590 to U+05FF, + // or in the Alphabetic Presentation Forms block, U+FB00..U+FB4F, but only in the + // Hebrew part of that block, which is U+FB1D..U+FB4F. + return (codePoint >= 0x590 && codePoint <= 0x5FF + || codePoint >= 0xFB1D && codePoint <= 0xFB4F); + case SCRIPT_KANNADA: + // Kannada unicode block is U+0C80..U+0CFF + return (codePoint >= 0xC80 && codePoint <= 0xCFF); + case SCRIPT_KHMER: + // Khmer letters are in unicode block U+1780..U+17FF, and the Khmer symbols block + // is U+19E0..U+19FF + return (codePoint >= 0x1780 && codePoint <= 0x17FF + || codePoint >= 0x19E0 && codePoint <= 0x19FF); + case SCRIPT_LAO: + // The Lao block is U+0E80..U+0EFF + return (codePoint >= 0xE80 && codePoint <= 0xEFF); + case SCRIPT_LATIN: + // Our supported latin script dictionaries (EFIGS) at the moment only include + // characters in the C0, C1, Latin Extended A and B, IPA extensions unicode + // blocks. As it happens, those are back-to-back in the code range 0x40 to 0x2AF, + // so the below is a very efficient way to test for it. As for the 0-0x3F, it's + // excluded from isLetter anyway. + return codePoint <= 0x2AF && Character.isLetter(codePoint); + case SCRIPT_MALAYALAM: + // Malayalam unicode block is U+0D00..U+0D7F + return (codePoint >= 0xD00 && codePoint <= 0xD7F); + case SCRIPT_MYANMAR: + // Myanmar has three unicode blocks : + // Myanmar U+1000..U+109F + // Myanmar extended-A U+AA60..U+AA7F + // Myanmar extended-B U+A9E0..U+A9FF + return (codePoint >= 0x1000 && codePoint <= 0x109F + || codePoint >= 0xAA60 && codePoint <= 0xAA7F + || codePoint >= 0xA9E0 && codePoint <= 0xA9FF); + case SCRIPT_SINHALA: + // Sinhala unicode block is U+0D80..U+0DFF + return (codePoint >= 0xD80 && codePoint <= 0xDFF); + case SCRIPT_TAMIL: + // Tamil unicode block is U+0B80..U+0BFF + return (codePoint >= 0xB80 && codePoint <= 0xBFF); + case SCRIPT_TELUGU: + // Telugu unicode block is U+0C00..U+0C7F + return (codePoint >= 0xC00 && codePoint <= 0xC7F); + case SCRIPT_THAI: + // Thai unicode block is U+0E00..U+0E7F + return (codePoint >= 0xE00 && codePoint <= 0xE7F); case SCRIPT_UNKNOWN: return true; default: |