aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--java/res/xml/key_styles_currency.xml26
-rw-r--r--java/res/xml/method.xml9
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java3
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsTable.java386
-rw-r--r--java/src/com/android/inputmethod/latin/BinaryDictionary.java24
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java4
-rw-r--r--java/src/com/android/inputmethod/latin/utils/StatsUtils.java53
-rw-r--r--native/jni/NativeFileList.mk3
-rw-r--r--native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp2
-rw-r--r--native/jni/src/defines.h8
-rw-r--r--native/jni/src/suggest/core/dictionary/dictionary.h2
-rw-r--r--native/jni/src/suggest/core/dictionary/property/bigram_property.h65
-rw-r--r--native/jni/src/suggest/core/dictionary/property/unigram_property.h107
-rw-r--r--native/jni/src/suggest/core/dictionary/property/word_property.cpp (renamed from native/jni/src/suggest/core/dictionary/word_property.cpp)32
-rw-r--r--native/jni/src/suggest/core/dictionary/property/word_property.h54
-rw-r--r--native/jni/src/suggest/core/dictionary/word_property.h121
-rw-r--r--native/jni/src/suggest/core/policy/dictionary_structure_with_buffer_policy.h2
-rw-r--r--native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.cpp13
-rw-r--r--native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.cpp16
-rw-r--r--native/jni/tests/defines_test.cpp34
-rw-r--r--tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetSubtypesCountTests.java4
-rw-r--r--tests/src/com/android/inputmethod/keyboard/layout/Hindi.java4
-rw-r--r--tests/src/com/android/inputmethod/keyboard/layout/tests/TestsEnglishIN.java55
-rw-r--r--tests/src/com/android/inputmethod/latin/ShiftModeTests.java56
-rw-r--r--tools/make-keyboard-text/res/src/com/android/inputmethod/keyboard/internal/KeyboardTextsTable.tmpl50
-rw-r--r--tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/JarUtils.java37
-rw-r--r--tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/LocaleUtils.java15
-rw-r--r--tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/MoreKeysResources.java122
-rw-r--r--tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/StringResourceMap.java18
29 files changed, 846 insertions, 479 deletions
diff --git a/java/res/xml/key_styles_currency.xml b/java/res/xml/key_styles_currency.xml
index 29e2eae3d..0bb2bb408 100644
--- a/java/res/xml/key_styles_currency.xml
+++ b/java/res/xml/key_styles_currency.xml
@@ -129,6 +129,32 @@
latin:styleName="moreCurrency4KeyStyle"
latin:keySpec="¢" />
</case>
+ <!-- IN: India (Rupee) -->
+ <case
+ latin:countryCode="IN"
+ >
+ <!-- U+20B9: "₹" INDIAN RUPEE SIGN
+ U+00A3: "£" POUND SIGN
+ U+20AC: "€" EURO SIGN
+ U+00A2: "¢" CENT SIGN -->
+ <key-style
+ latin:styleName="currencyKeyStyle"
+ latin:keySpec="&#x20B9;"
+ latin:moreKeys="!text/morekeys_currency" />
+ <key-style
+ latin:styleName="moreCurrency1KeyStyle"
+ latin:keySpec="&#x00A3;" />
+ <key-style
+ latin:styleName="moreCurrency2KeyStyle"
+ latin:keySpec="&#x20AC;" />
+ <key-style
+ latin:styleName="moreCurrency3KeyStyle"
+ latin:keySpec="$"
+ latin:moreKeys="&#x00A2;" />
+ <key-style
+ latin:styleName="moreCurrency4KeyStyle"
+ latin:keySpec="&#x00A2;" />
+ </case>
<!-- GB: United Kingdom (Pound) -->
<case
latin:countryCode="GB"
diff --git a/java/res/xml/method.xml b/java/res/xml/method.xml
index 6db80b857..1bef3c254 100644
--- a/java/res/xml/method.xml
+++ b/java/res/xml/method.xml
@@ -34,6 +34,7 @@
de: German/qwertz
de_CH: German (Switzerland)/swiss
el: Greek/greek
+ en_IN: English (India)/qwerty
en_US: English (United States)/qwerty
en_GB: English (Great Britain)/qwerty
eo: Esperanto/spanish
@@ -217,6 +218,14 @@
/>
<subtype android:icon="@drawable/ic_ime_switcher_dark"
android:label="@string/subtype_generic"
+ android:subtypeId="0x8d58fc2d"
+ android:imeSubtypeLocale="en_IN"
+ android:imeSubtypeMode="keyboard"
+ android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable,EmojiCapable"
+ android:isAsciiCapable="true"
+ />
+ <subtype android:icon="@drawable/ic_ime_switcher_dark"
+ android:label="@string/subtype_generic"
android:subtypeId="0x4090554a"
android:imeSubtypeLocale="eo"
android:imeSubtypeMode="keyboard"
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java
index 56acdde8d..0047aa4a1 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java
@@ -41,8 +41,7 @@ public final class KeyboardTextsSet {
private HashMap<String, String> mResourceNameToTextsMap = CollectionUtils.newHashMap();
public void setLocale(final Locale locale, final Context context) {
- final String language = locale.getLanguage();
- mTextsTable = KeyboardTextsTable.getTextsTable(language);
+ mTextsTable = KeyboardTextsTable.getTextsTable(locale);
final Resources res = context.getResources();
final int referenceId = context.getApplicationInfo().labelRes;
final String resourcePackageName = res.getResourcePackageName(referenceId);
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsTable.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsTable.java
index 17611c6cc..1bd98332f 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsTable.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsTable.java
@@ -19,6 +19,7 @@ package com.android.inputmethod.keyboard.internal;
import com.android.inputmethod.latin.utils.CollectionUtils;
import java.util.HashMap;
+import java.util.Locale;
/**
* !!!!! DO NOT EDIT THIS FILE !!!!!
@@ -44,19 +45,19 @@ import java.util.HashMap;
public final class KeyboardTextsTable {
// Name to index map.
private static final HashMap<String, Integer> sNameToIndexesMap = CollectionUtils.newHashMap();
- // Language to texts table map.
- private static final HashMap<String, String[]> sLanguageToTextsTableMap =
+ // Locale to texts table map.
+ private static final HashMap<String, String[]> sLocaleToTextsTableMap =
CollectionUtils.newHashMap();
// TODO: Remove this variable after debugging.
- // Texts table to language maps.
- private static final HashMap<String[], String> sTextsTableToLanguageMap =
+ // Texts table to locale maps.
+ private static final HashMap<String[], String> sTextsTableToLocaleMap =
CollectionUtils.newHashMap();
public static String getText(final String name, final String[] textsTable) {
final Integer indexObj = sNameToIndexesMap.get(name);
if (indexObj == null) {
- throw new RuntimeException("Unknown text name=" + name + " language="
- + sTextsTableToLanguageMap.get(textsTable));
+ throw new RuntimeException("Unknown text name=" + name + " locale="
+ + sTextsTableToLocaleMap.get(textsTable));
}
final int index = indexObj;
final String text = (index < textsTable.length) ? textsTable[index] : null;
@@ -64,17 +65,24 @@ public final class KeyboardTextsTable {
return text;
}
// Sanity check.
- if (index >= 0 && index < LANGUAGE_DEFAULT.length) {
- return LANGUAGE_DEFAULT[index];
+ if (index >= 0 && index < TEXTS_DEFAULT.length) {
+ return TEXTS_DEFAULT[index];
}
// Throw exception for debugging purpose.
throw new RuntimeException("Illegal index=" + index + " for name=" + name
- + " language=" + sTextsTableToLanguageMap.get(textsTable));
+ + " locale=" + sTextsTableToLocaleMap.get(textsTable));
}
- public static String[] getTextsTable(final String language) {
- final String[] textsTable = sLanguageToTextsTableMap.get(language);
- return textsTable != null ? textsTable : LANGUAGE_DEFAULT;
+ public static String[] getTextsTable(final Locale locale) {
+ final String localeKey = locale.toString();
+ if (sLocaleToTextsTableMap.containsKey(localeKey)) {
+ return sLocaleToTextsTableMap.get(localeKey);
+ }
+ final String languageKey = locale.getLanguage();
+ if (sLocaleToTextsTableMap.containsKey(languageKey)) {
+ return sLocaleToTextsTableMap.get(languageKey);
+ }
+ return TEXTS_DEFAULT;
}
private static final String[] NAMES = {
@@ -252,7 +260,7 @@ public final class KeyboardTextsTable {
private static final String EMPTY = "";
/* Default texts */
- private static final String[] LANGUAGE_DEFAULT = {
+ private static final String[] TEXTS_DEFAULT = {
/* morekeys_a ~ */
EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY,
/* ~ morekeys_c */
@@ -457,8 +465,8 @@ public final class KeyboardTextsTable {
/* keyspec_emoji_key */ "!icon/emoji_key|!code/key_emoji",
};
- /* Language af: Afrikaans */
- private static final String[] LANGUAGE_af = {
+ /* Locale af: Afrikaans */
+ private static final String[] TEXTS_af = {
// This is the same as Dutch except more keys of y and demoting vowels with diaeresis.
// U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE
// U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX
@@ -513,8 +521,8 @@ public final class KeyboardTextsTable {
/* morekeys_y */ "\u00FD,\u0133",
};
- /* Language ar: Arabic */
- private static final String[] LANGUAGE_ar = {
+ /* Locale ar: Arabic */
+ private static final String[] TEXTS_ar = {
/* morekeys_a ~ */
null, null, null, null, null, null, null, null, null,
/* ~ single_quotes */
@@ -640,8 +648,8 @@ public final class KeyboardTextsTable {
/* morekeys_symbols_percent */ "\\%,\u2030",
};
- /* Language az_AZ: Azerbaijani (Azerbaijan) */
- private static final String[] LANGUAGE_az_AZ = {
+ /* Locale az_AZ: Azerbaijani (Azerbaijan) */
+ private static final String[] TEXTS_az_AZ = {
// U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX
/* morekeys_a */ "\u00E2",
// U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS
@@ -688,8 +696,8 @@ public final class KeyboardTextsTable {
/* morekeys_g */ "\u011F",
};
- /* Language be_BY: Belarusian (Belarus) */
- private static final String[] LANGUAGE_be_BY = {
+ /* Locale be_BY: Belarusian (Belarus) */
+ private static final String[] TEXTS_be_BY = {
/* morekeys_a ~ */
null, null, null, null, null, null,
/* ~ morekeys_c */
@@ -721,8 +729,8 @@ public final class KeyboardTextsTable {
/* morekeys_cyrillic_soft_sign */ "\u044A",
};
- /* Language bg: Bulgarian */
- private static final String[] LANGUAGE_bg = {
+ /* Locale bg: Bulgarian */
+ private static final String[] TEXTS_bg = {
/* morekeys_a ~ */
null, null, null, null, null, null,
/* ~ morekeys_c */
@@ -737,8 +745,8 @@ public final class KeyboardTextsTable {
/* keylabel_to_alpha */ "\u0410\u0411\u0412",
};
- /* Language ca: Catalan */
- private static final String[] LANGUAGE_ca = {
+ /* Locale ca: Catalan */
+ private static final String[] TEXTS_ca = {
// U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE
// U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE
// U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS
@@ -816,8 +824,8 @@ public final class KeyboardTextsTable {
/* morekeys_tablet_punctuation */ "!autoColumnOrder!8,\\,,',\u00B7,#,),(,/,;,@,:,-,\",+,\\%,&",
};
- /* Language cs: Czech */
- private static final String[] LANGUAGE_cs = {
+ /* Locale cs: Czech */
+ private static final String[] TEXTS_cs = {
// U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE
// U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE
// U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX
@@ -894,8 +902,8 @@ public final class KeyboardTextsTable {
/* morekeys_r */ "\u0159",
};
- /* Language da: Danish */
- private static final String[] LANGUAGE_da = {
+ /* Locale da: Danish */
+ private static final String[] TEXTS_da = {
// U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE
// U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS
// U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE
@@ -963,8 +971,8 @@ public final class KeyboardTextsTable {
/* morekeys_nordic_row2_11 */ "\u00F6",
};
- /* Language de: German */
- private static final String[] LANGUAGE_de = {
+ /* Locale de: German */
+ private static final String[] TEXTS_de = {
// U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS
// U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX
// U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE
@@ -1033,8 +1041,8 @@ public final class KeyboardTextsTable {
/* morekeys_swiss_row2_11 */ "\u00E0",
};
- /* Language el: Greek */
- private static final String[] LANGUAGE_el = {
+ /* Locale el: Greek */
+ private static final String[] TEXTS_el = {
/* morekeys_a ~ */
null, null, null, null, null, null, null, null, null,
/* ~ single_quotes */
@@ -1045,8 +1053,8 @@ public final class KeyboardTextsTable {
/* keylabel_to_alpha */ "\u0391\u0392\u0393",
};
- /* Language en: English */
- private static final String[] LANGUAGE_en = {
+ /* Locale en: English */
+ private static final String[] TEXTS_en = {
// U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE
// U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE
// U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX
@@ -1094,8 +1102,8 @@ public final class KeyboardTextsTable {
/* morekeys_s */ "\u00DF",
};
- /* Language eo: Esperanto */
- private static final String[] LANGUAGE_eo = {
+ /* Locale eo: Esperanto */
+ private static final String[] TEXTS_eo = {
// U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE
// U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE
// U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX
@@ -1243,8 +1251,8 @@ public final class KeyboardTextsTable {
/* keyspec_x */ "\u0109",
};
- /* Language es: Spanish */
- private static final String[] LANGUAGE_es = {
+ /* Locale es: Spanish */
+ private static final String[] TEXTS_es = {
// U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE
// U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE
// U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS
@@ -1306,8 +1314,8 @@ public final class KeyboardTextsTable {
/* morekeys_punctuation */ "!autoColumnOrder!9,\\,,?,!,#,),(,/,;,\u00A1,',@,:,-,\",+,\\%,&,\u00BF",
};
- /* Language et_EE: Estonian (Estonia) */
- private static final String[] LANGUAGE_et_EE = {
+ /* Locale et_EE: Estonian (Estonia) */
+ private static final String[] TEXTS_et_EE = {
// U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS
// U+0101: "ā" LATIN SMALL LETTER A WITH MACRON
// U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE
@@ -1409,8 +1417,8 @@ public final class KeyboardTextsTable {
/* morekeys_nordic_row2_10 */ "\u00F5",
};
- /* Language eu_ES: Basque (Spain) */
- private static final String[] LANGUAGE_eu_ES = {
+ /* Locale eu_ES: Basque (Spain) */
+ private static final String[] TEXTS_eu_ES = {
// U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE
// U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE
// U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS
@@ -1463,8 +1471,8 @@ public final class KeyboardTextsTable {
/* morekeys_n */ "\u00F1,\u0144",
};
- /* Language fa: Persian */
- private static final String[] LANGUAGE_fa = {
+ /* Locale fa: Persian */
+ private static final String[] TEXTS_fa = {
/* morekeys_a ~ */
null, null, null, null, null, null, null, null, null,
/* ~ single_quotes */
@@ -1601,8 +1609,8 @@ public final class KeyboardTextsTable {
/* morekeys_greater_than */ "!fixedColumnOrder!3,!text/keyspec_right_single_angle_quote,!text/keyspec_greater_than_equal,!text/keyspec_greater_than",
};
- /* Language fi: Finnish */
- private static final String[] LANGUAGE_fi = {
+ /* Locale fi: Finnish */
+ private static final String[] TEXTS_fi = {
// U+00E6: "æ" LATIN SMALL LETTER AE
// U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE
// U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE
@@ -1651,8 +1659,8 @@ public final class KeyboardTextsTable {
/* morekeys_nordic_row2_11 */ "\u00E6",
};
- /* Language fr: French */
- private static final String[] LANGUAGE_fr = {
+ /* Locale fr: French */
+ private static final String[] TEXTS_fr = {
// U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE
// U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX
// U+00E6: "æ" LATIN SMALL LETTER AE
@@ -1724,8 +1732,8 @@ public final class KeyboardTextsTable {
/* morekeys_swiss_row2_11 */ "\u00E4",
};
- /* Language gl_ES: Gallegan (Spain) */
- private static final String[] LANGUAGE_gl_ES = {
+ /* Locale gl_ES: Gallegan (Spain) */
+ private static final String[] TEXTS_gl_ES = {
// U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE
// U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE
// U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS
@@ -1778,8 +1786,8 @@ public final class KeyboardTextsTable {
/* morekeys_n */ "\u00F1,\u0144",
};
- /* Language hi: Hindi */
- private static final String[] LANGUAGE_hi = {
+ /* Locale hi: Hindi */
+ private static final String[] TEXTS_hi = {
/* morekeys_a ~ */
null, null, null, null, null, null, null, null, null,
/* ~ single_quotes */
@@ -1830,8 +1838,8 @@ public final class KeyboardTextsTable {
/* additional_morekeys_symbols_0 */ "0",
};
- /* Language hr: Croatian */
- private static final String[] LANGUAGE_hr = {
+ /* Locale hr: Croatian */
+ private static final String[] TEXTS_hr = {
/* morekeys_a ~ */
null, null, null, null, null,
/* ~ morekeys_i */
@@ -1863,8 +1871,8 @@ public final class KeyboardTextsTable {
/* double_angle_quotes */ "!text/double_raqm_laqm",
};
- /* Language hu: Hungarian */
- private static final String[] LANGUAGE_hu = {
+ /* Locale hu: Hungarian */
+ private static final String[] TEXTS_hu = {
// U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE
// U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE
// U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX
@@ -1917,8 +1925,8 @@ public final class KeyboardTextsTable {
/* double_angle_quotes */ "!text/double_raqm_laqm",
};
- /* Language hy_AM: Armenian (Armenia) */
- private static final String[] LANGUAGE_hy_AM = {
+ /* Locale hy_AM: Armenian (Armenia) */
+ private static final String[] TEXTS_hy_AM = {
/* morekeys_a ~ */
null, null, null, null, null, null, null, null, null,
/* ~ single_quotes */
@@ -1970,8 +1978,8 @@ public final class KeyboardTextsTable {
/* morekeys_exclamation */ "\u055C,\u00A1",
};
- /* Language is: Icelandic */
- private static final String[] LANGUAGE_is = {
+ /* Locale is: Icelandic */
+ private static final String[] TEXTS_is = {
// U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE
// U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS
// U+00E6: "æ" LATIN SMALL LETTER AE
@@ -2027,8 +2035,8 @@ public final class KeyboardTextsTable {
/* morekeys_t */ "\u00FE",
};
- /* Language it: Italian */
- private static final String[] LANGUAGE_it = {
+ /* Locale it: Italian */
+ private static final String[] TEXTS_it = {
// U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE
// U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE
// U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX
@@ -2072,8 +2080,8 @@ public final class KeyboardTextsTable {
/* morekeys_i */ "\u00EC,\u00ED,\u00EE,\u00EF,\u012F,\u012B",
};
- /* Language iw: Hebrew */
- private static final String[] LANGUAGE_iw = {
+ /* Locale iw: Hebrew */
+ private static final String[] TEXTS_iw = {
/* morekeys_a ~ */
null, null, null, null, null, null,
/* ~ morekeys_c */
@@ -2130,8 +2138,8 @@ public final class KeyboardTextsTable {
/* morekeys_plus */ "\u00B1,\uFB29",
};
- /* Language ka_GE: Georgian (Georgia) */
- private static final String[] LANGUAGE_ka_GE = {
+ /* Locale ka_GE: Georgian (Georgia) */
+ private static final String[] TEXTS_ka_GE = {
/* morekeys_a ~ */
null, null, null, null, null, null,
/* ~ morekeys_c */
@@ -2145,8 +2153,8 @@ public final class KeyboardTextsTable {
/* keylabel_to_alpha */ "\u10D0\u10D1\u10D2",
};
- /* Language kk: Kazakh */
- private static final String[] LANGUAGE_kk = {
+ /* Locale kk: Kazakh */
+ private static final String[] TEXTS_kk = {
/* morekeys_a ~ */
null, null, null, null, null, null, null, null, null,
/* ~ single_quotes */
@@ -2202,8 +2210,8 @@ public final class KeyboardTextsTable {
/* morekeys_cyrillic_a */ "\u04D9",
};
- /* Language km_KH: Khmer (Cambodia) */
- private static final String[] LANGUAGE_km_KH = {
+ /* Locale km_KH: Khmer (Cambodia) */
+ private static final String[] TEXTS_km_KH = {
/* morekeys_a ~ */
null, null, null, null, null, null, null, null, null,
/* ~ single_quotes */
@@ -2226,8 +2234,8 @@ public final class KeyboardTextsTable {
/* morekeys_currency_dollar */ "\u17DB,\u00A2,\u00A3,\u20AC,\u00A5,\u20B1",
};
- /* Language ky: Kirghiz */
- private static final String[] LANGUAGE_ky = {
+ /* Locale ky: Kirghiz */
+ private static final String[] TEXTS_ky = {
/* morekeys_a ~ */
null, null, null, null, null, null, null, null, null,
/* ~ single_quotes */
@@ -2268,8 +2276,8 @@ public final class KeyboardTextsTable {
/* morekeys_cyrillic_o */ "\u04E9",
};
- /* Language lo_LA: Lao (Laos) */
- private static final String[] LANGUAGE_lo_LA = {
+ /* Locale lo_LA: Lao (Laos) */
+ private static final String[] TEXTS_lo_LA = {
/* morekeys_a ~ */
null, null, null, null, null, null, null, null, null,
/* ~ single_quotes */
@@ -2285,8 +2293,8 @@ public final class KeyboardTextsTable {
/* keyspec_currency */ "\u20AD",
};
- /* Language lt: Lithuanian */
- private static final String[] LANGUAGE_lt = {
+ /* Locale lt: Lithuanian */
+ private static final String[] TEXTS_lt = {
// U+0105: "ą" LATIN SMALL LETTER A WITH OGONEK
// U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS
// U+0101: "ā" LATIN SMALL LETTER A WITH MACRON
@@ -2380,8 +2388,8 @@ public final class KeyboardTextsTable {
/* morekeys_k */ "\u0137",
};
- /* Language lv: Latvian */
- private static final String[] LANGUAGE_lv = {
+ /* Locale lv: Latvian */
+ private static final String[] TEXTS_lv = {
// U+0101: "ā" LATIN SMALL LETTER A WITH MACRON
// U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE
// U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE
@@ -2474,8 +2482,8 @@ public final class KeyboardTextsTable {
/* morekeys_k */ "\u0137",
};
- /* Language mk: Macedonian */
- private static final String[] LANGUAGE_mk = {
+ /* Locale mk: Macedonian */
+ private static final String[] TEXTS_mk = {
/* morekeys_a ~ */
null, null, null, null, null, null,
/* ~ morekeys_c */
@@ -2510,8 +2518,8 @@ public final class KeyboardTextsTable {
/* keyspec_south_slavic_row3_8 */ "\u0453",
};
- /* Language mn_MN: Mongolian (Mongolia) */
- private static final String[] LANGUAGE_mn_MN = {
+ /* Locale mn_MN: Mongolian (Mongolia) */
+ private static final String[] TEXTS_mn_MN = {
/* morekeys_a ~ */
null, null, null, null, null, null, null, null, null,
/* ~ single_quotes */
@@ -2527,8 +2535,8 @@ public final class KeyboardTextsTable {
/* keyspec_currency */ "\u20AE",
};
- /* Language my_MM: Burmese (Myanmar) */
- private static final String[] LANGUAGE_my_MM = {
+ /* Locale my_MM: Burmese (Myanmar) */
+ private static final String[] TEXTS_my_MM = {
/* morekeys_a ~ */
null, null, null, null, null, null, null, null, null,
/* ~ single_quotes */
@@ -2539,8 +2547,8 @@ public final class KeyboardTextsTable {
/* keylabel_to_alpha */ "\u1000\u1001\u1002",
};
- /* Language nb: Norwegian Bokmål */
- private static final String[] LANGUAGE_nb = {
+ /* Locale nb: Norwegian Bokmål */
+ private static final String[] TEXTS_nb = {
// U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE
// U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS
// U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE
@@ -2593,8 +2601,8 @@ public final class KeyboardTextsTable {
/* morekeys_nordic_row2_11 */ "\u00E4",
};
- /* Language ne_NP: Nepali (Nepal) */
- private static final String[] LANGUAGE_ne_NP = {
+ /* Locale ne_NP: Nepali (Nepal) */
+ private static final String[] TEXTS_ne_NP = {
/* morekeys_a ~ */
null, null, null, null, null, null, null, null, null,
/* ~ single_quotes */
@@ -2645,8 +2653,8 @@ public final class KeyboardTextsTable {
/* additional_morekeys_symbols_0 */ "0",
};
- /* Language nl: Dutch */
- private static final String[] LANGUAGE_nl = {
+ /* Locale nl: Dutch */
+ private static final String[] TEXTS_nl = {
// U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE
// U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS
// U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX
@@ -2699,8 +2707,8 @@ public final class KeyboardTextsTable {
/* morekeys_y */ "\u0133",
};
- /* Language pl: Polish */
- private static final String[] LANGUAGE_pl = {
+ /* Locale pl: Polish */
+ private static final String[] TEXTS_pl = {
// U+0105: "ą" LATIN SMALL LETTER A WITH OGONEK
// U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE
// U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE
@@ -2755,8 +2763,8 @@ public final class KeyboardTextsTable {
/* morekeys_l */ "\u0142",
};
- /* Language pt: Portuguese */
- private static final String[] LANGUAGE_pt = {
+ /* Locale pt: Portuguese */
+ private static final String[] TEXTS_pt = {
// U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE
// U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE
// U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE
@@ -2803,8 +2811,8 @@ public final class KeyboardTextsTable {
/* morekeys_c */ "\u00E7,\u010D,\u0107",
};
- /* Language rm: Raeto-Romance */
- private static final String[] LANGUAGE_rm = {
+ /* Locale rm: Raeto-Romance */
+ private static final String[] TEXTS_rm = {
/* morekeys_a */ null,
// U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE
// U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE
@@ -2816,8 +2824,8 @@ public final class KeyboardTextsTable {
/* morekeys_o */ "\u00F2,\u00F3,\u00F6,\u00F4,\u00F5,\u0153,\u00F8",
};
- /* Language ro: Romanian */
- private static final String[] LANGUAGE_ro = {
+ /* Locale ro: Romanian */
+ private static final String[] TEXTS_ro = {
// U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX
// U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE
// U+0103: "ă" LATIN SMALL LETTER A WITH BREVE
@@ -2855,8 +2863,8 @@ public final class KeyboardTextsTable {
/* morekeys_t */ "\u021B",
};
- /* Language ru: Russian */
- private static final String[] LANGUAGE_ru = {
+ /* Locale ru: Russian */
+ private static final String[] TEXTS_ru = {
/* morekeys_a ~ */
null, null, null, null, null, null,
/* ~ morekeys_c */
@@ -2888,8 +2896,8 @@ public final class KeyboardTextsTable {
/* morekeys_cyrillic_soft_sign */ "\u044A",
};
- /* Language sk: Slovak */
- private static final String[] LANGUAGE_sk = {
+ /* Locale sk: Slovak */
+ private static final String[] TEXTS_sk = {
// U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE
// U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS
// U+0101: "ā" LATIN SMALL LETTER A WITH MACRON
@@ -2983,8 +2991,8 @@ public final class KeyboardTextsTable {
/* morekeys_k */ "\u0137",
};
- /* Language sl: Slovenian */
- private static final String[] LANGUAGE_sl = {
+ /* Locale sl: Slovenian */
+ private static final String[] TEXTS_sl = {
/* morekeys_a ~ */
null, null, null, null, null,
/* ~ morekeys_i */
@@ -3009,8 +3017,8 @@ public final class KeyboardTextsTable {
/* double_angle_quotes */ "!text/double_raqm_laqm",
};
- /* Language sr: Serbian */
- private static final String[] LANGUAGE_sr = {
+ /* Locale sr: Serbian */
+ private static final String[] TEXTS_sr = {
/* morekeys_a ~ */
null, null, null, null, null, null,
/* ~ morekeys_c */
@@ -3069,8 +3077,8 @@ public final class KeyboardTextsTable {
/* keyspec_south_slavic_row3_8 */ "\u0452",
};
- /* Language sv: Swedish */
- private static final String[] LANGUAGE_sv = {
+ /* Locale sv: Swedish */
+ private static final String[] TEXTS_sv = {
// U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE
// U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE
// U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX
@@ -3155,8 +3163,8 @@ public final class KeyboardTextsTable {
/* morekeys_nordic_row2_11 */ "\u00E6",
};
- /* Language sw: Swahili */
- private static final String[] LANGUAGE_sw = {
+ /* Locale sw: Swahili */
+ private static final String[] TEXTS_sw = {
// This is the same as English except morekeys_g.
// U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE
// U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE
@@ -3209,8 +3217,8 @@ public final class KeyboardTextsTable {
/* morekeys_g */ "g\'",
};
- /* Language th: Thai */
- private static final String[] LANGUAGE_th = {
+ /* Locale th: Thai */
+ private static final String[] TEXTS_th = {
/* morekeys_a ~ */
null, null, null, null, null, null, null, null, null,
/* ~ single_quotes */
@@ -3226,8 +3234,8 @@ public final class KeyboardTextsTable {
/* keyspec_currency */ "\u0E3F",
};
- /* Language tl: Tagalog */
- private static final String[] LANGUAGE_tl = {
+ /* Locale tl: Tagalog */
+ private static final String[] TEXTS_tl = {
// U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE
// U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE
// U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS
@@ -3280,8 +3288,8 @@ public final class KeyboardTextsTable {
/* morekeys_n */ "\u00F1,\u0144",
};
- /* Language tr: Turkish */
- private static final String[] LANGUAGE_tr = {
+ /* Locale tr: Turkish */
+ private static final String[] TEXTS_tr = {
// U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX
/* morekeys_a */ "\u00E2",
// U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS
@@ -3327,8 +3335,8 @@ public final class KeyboardTextsTable {
/* morekeys_g */ "\u011F",
};
- /* Language uk: Ukrainian */
- private static final String[] LANGUAGE_uk = {
+ /* Locale uk: Ukrainian */
+ private static final String[] TEXTS_uk = {
/* morekeys_a ~ */
null, null, null, null, null, null,
/* ~ morekeys_c */
@@ -3371,8 +3379,8 @@ public final class KeyboardTextsTable {
/* morekeys_cyrillic_ghe */ "\u0491",
};
- /* Language vi: Vietnamese */
- private static final String[] LANGUAGE_vi = {
+ /* Locale vi: Vietnamese */
+ private static final String[] TEXTS_vi = {
// U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE
// U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE
// U+1EA3: "ả" LATIN SMALL LETTER A WITH HOOK ABOVE
@@ -3457,8 +3465,8 @@ public final class KeyboardTextsTable {
/* keyspec_currency */ "\u20AB",
};
- /* Language zu: Zulu */
- private static final String[] LANGUAGE_zu = {
+ /* Locale zu: Zulu */
+ private static final String[] TEXTS_zu = {
// This is the same as English
// U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE
// U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE
@@ -3507,8 +3515,8 @@ public final class KeyboardTextsTable {
/* morekeys_s */ "\u00DF",
};
- /* Language zz: Alphabet */
- private static final String[] LANGUAGE_zz = {
+ /* Locale zz: Alphabet */
+ private static final String[] TEXTS_zz = {
// U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE
// U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE
// U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX
@@ -3646,67 +3654,65 @@ public final class KeyboardTextsTable {
/* morekeys_j */ "\u0135",
};
- // TODO: Use the language + "_" + region representation for the locale string key.
- // Currently we are dropping the region from the key.
- private static final Object[] LANGUAGES_AND_TEXTS = {
+ private static final Object[] LOCALES_AND_TEXTS = {
// "locale", TEXT_ARRAY, /* numberOfNonNullText/lengthOf_TEXT_ARRAY localeName */
- "DEFAULT", LANGUAGE_DEFAULT, /* 168/168 default */
- "af", LANGUAGE_af, /* 7/ 12 Afrikaans */
- "ar", LANGUAGE_ar, /* 55/107 Arabic */
- "az", LANGUAGE_az_AZ, /* 8/ 17 Azerbaijani (Azerbaijan) */
- "be", LANGUAGE_be_BY, /* 9/ 32 Belarusian (Belarus) */
- "bg", LANGUAGE_bg, /* 2/ 10 Bulgarian */
- "ca", LANGUAGE_ca, /* 11/120 Catalan */
- "cs", LANGUAGE_cs, /* 17/ 21 Czech */
- "da", LANGUAGE_da, /* 19/ 33 Danish */
- "de", LANGUAGE_de, /* 16/ 91 German */
- "el", LANGUAGE_el, /* 1/ 10 Greek */
- "en", LANGUAGE_en, /* 8/ 11 English */
- "eo", LANGUAGE_eo, /* 26/115 Esperanto */
- "es", LANGUAGE_es, /* 8/ 55 Spanish */
- "et", LANGUAGE_et_EE, /* 22/ 27 Estonian (Estonia) */
- "eu", LANGUAGE_eu_ES, /* 7/ 8 Basque (Spain) */
- "fa", LANGUAGE_fa, /* 58/123 Persian */
- "fi", LANGUAGE_fi, /* 10/ 33 Finnish */
- "fr", LANGUAGE_fr, /* 13/ 91 French */
- "gl", LANGUAGE_gl_ES, /* 7/ 8 Gallegan (Spain) */
- "hi", LANGUAGE_hi, /* 23/ 54 Hindi */
- "hr", LANGUAGE_hr, /* 9/ 19 Croatian */
- "hu", LANGUAGE_hu, /* 9/ 19 Hungarian */
- "hy", LANGUAGE_hy_AM, /* 8/126 Armenian (Armenia) */
- "is", LANGUAGE_is, /* 10/ 15 Icelandic */
- "it", LANGUAGE_it, /* 5/ 5 Italian */
- "iw", LANGUAGE_iw, /* 20/121 Hebrew */
- "ka", LANGUAGE_ka_GE, /* 3/ 10 Georgian (Georgia) */
- "kk", LANGUAGE_kk, /* 15/118 Kazakh */
- "km", LANGUAGE_km_KH, /* 2/119 Khmer (Cambodia) */
- "ky", LANGUAGE_ky, /* 10/ 80 Kirghiz */
- "lo", LANGUAGE_lo_LA, /* 2/ 20 Lao (Laos) */
- "lt", LANGUAGE_lt, /* 18/ 22 Lithuanian */
- "lv", LANGUAGE_lv, /* 18/ 22 Latvian */
- "mk", LANGUAGE_mk, /* 9/ 85 Macedonian */
- "mn", LANGUAGE_mn_MN, /* 2/ 20 Mongolian (Mongolia) */
- "my", LANGUAGE_my_MM, /* 1/ 10 Burmese (Myanmar) */
- "nb", LANGUAGE_nb, /* 11/ 33 Norwegian Bokmål */
- "ne", LANGUAGE_ne_NP, /* 23/ 54 Nepali (Nepal) */
- "nl", LANGUAGE_nl, /* 9/ 12 Dutch */
- "pl", LANGUAGE_pl, /* 10/ 16 Polish */
- "pt", LANGUAGE_pt, /* 6/ 6 Portuguese */
- "rm", LANGUAGE_rm, /* 1/ 2 Raeto-Romance */
- "ro", LANGUAGE_ro, /* 6/ 15 Romanian */
- "ru", LANGUAGE_ru, /* 9/ 32 Russian */
- "sk", LANGUAGE_sk, /* 20/ 22 Slovak */
- "sl", LANGUAGE_sl, /* 8/ 19 Slovenian */
- "sr", LANGUAGE_sr, /* 11/ 85 Serbian */
- "sv", LANGUAGE_sv, /* 21/ 33 Swedish */
- "sw", LANGUAGE_sw, /* 9/ 17 Swahili */
- "th", LANGUAGE_th, /* 2/ 20 Thai */
- "tl", LANGUAGE_tl, /* 7/ 8 Tagalog */
- "tr", LANGUAGE_tr, /* 7/ 17 Turkish */
- "uk", LANGUAGE_uk, /* 11/ 79 Ukrainian */
- "vi", LANGUAGE_vi, /* 8/ 20 Vietnamese */
- "zu", LANGUAGE_zu, /* 8/ 11 Zulu */
- "zz", LANGUAGE_zz, /* 19/109 Alphabet */
+ "DEFAULT", TEXTS_DEFAULT, /* 168/168 default */
+ "af" , TEXTS_af, /* 7/ 12 Afrikaans */
+ "ar" , TEXTS_ar, /* 55/107 Arabic */
+ "az_AZ" , TEXTS_az_AZ, /* 8/ 17 Azerbaijani (Azerbaijan) */
+ "be_BY" , TEXTS_be_BY, /* 9/ 32 Belarusian (Belarus) */
+ "bg" , TEXTS_bg, /* 2/ 10 Bulgarian */
+ "ca" , TEXTS_ca, /* 11/120 Catalan */
+ "cs" , TEXTS_cs, /* 17/ 21 Czech */
+ "da" , TEXTS_da, /* 19/ 33 Danish */
+ "de" , TEXTS_de, /* 16/ 91 German */
+ "el" , TEXTS_el, /* 1/ 10 Greek */
+ "en" , TEXTS_en, /* 8/ 11 English */
+ "eo" , TEXTS_eo, /* 26/115 Esperanto */
+ "es" , TEXTS_es, /* 8/ 55 Spanish */
+ "et_EE" , TEXTS_et_EE, /* 22/ 27 Estonian (Estonia) */
+ "eu_ES" , TEXTS_eu_ES, /* 7/ 8 Basque (Spain) */
+ "fa" , TEXTS_fa, /* 58/123 Persian */
+ "fi" , TEXTS_fi, /* 10/ 33 Finnish */
+ "fr" , TEXTS_fr, /* 13/ 91 French */
+ "gl_ES" , TEXTS_gl_ES, /* 7/ 8 Gallegan (Spain) */
+ "hi" , TEXTS_hi, /* 23/ 54 Hindi */
+ "hr" , TEXTS_hr, /* 9/ 19 Croatian */
+ "hu" , TEXTS_hu, /* 9/ 19 Hungarian */
+ "hy_AM" , TEXTS_hy_AM, /* 8/126 Armenian (Armenia) */
+ "is" , TEXTS_is, /* 10/ 15 Icelandic */
+ "it" , TEXTS_it, /* 5/ 5 Italian */
+ "iw" , TEXTS_iw, /* 20/121 Hebrew */
+ "ka_GE" , TEXTS_ka_GE, /* 3/ 10 Georgian (Georgia) */
+ "kk" , TEXTS_kk, /* 15/118 Kazakh */
+ "km_KH" , TEXTS_km_KH, /* 2/119 Khmer (Cambodia) */
+ "ky" , TEXTS_ky, /* 10/ 80 Kirghiz */
+ "lo_LA" , TEXTS_lo_LA, /* 2/ 20 Lao (Laos) */
+ "lt" , TEXTS_lt, /* 18/ 22 Lithuanian */
+ "lv" , TEXTS_lv, /* 18/ 22 Latvian */
+ "mk" , TEXTS_mk, /* 9/ 85 Macedonian */
+ "mn_MN" , TEXTS_mn_MN, /* 2/ 20 Mongolian (Mongolia) */
+ "my_MM" , TEXTS_my_MM, /* 1/ 10 Burmese (Myanmar) */
+ "nb" , TEXTS_nb, /* 11/ 33 Norwegian Bokmål */
+ "ne_NP" , TEXTS_ne_NP, /* 23/ 54 Nepali (Nepal) */
+ "nl" , TEXTS_nl, /* 9/ 12 Dutch */
+ "pl" , TEXTS_pl, /* 10/ 16 Polish */
+ "pt" , TEXTS_pt, /* 6/ 6 Portuguese */
+ "rm" , TEXTS_rm, /* 1/ 2 Raeto-Romance */
+ "ro" , TEXTS_ro, /* 6/ 15 Romanian */
+ "ru" , TEXTS_ru, /* 9/ 32 Russian */
+ "sk" , TEXTS_sk, /* 20/ 22 Slovak */
+ "sl" , TEXTS_sl, /* 8/ 19 Slovenian */
+ "sr" , TEXTS_sr, /* 11/ 85 Serbian */
+ "sv" , TEXTS_sv, /* 21/ 33 Swedish */
+ "sw" , TEXTS_sw, /* 9/ 17 Swahili */
+ "th" , TEXTS_th, /* 2/ 20 Thai */
+ "tl" , TEXTS_tl, /* 7/ 8 Tagalog */
+ "tr" , TEXTS_tr, /* 7/ 17 Turkish */
+ "uk" , TEXTS_uk, /* 11/ 79 Ukrainian */
+ "vi" , TEXTS_vi, /* 8/ 20 Vietnamese */
+ "zu" , TEXTS_zu, /* 8/ 11 Zulu */
+ "zz" , TEXTS_zz, /* 19/109 Alphabet */
};
static {
@@ -3714,11 +3720,11 @@ public final class KeyboardTextsTable {
sNameToIndexesMap.put(NAMES[index], index);
}
- for (int i = 0; i < LANGUAGES_AND_TEXTS.length; i += 2) {
- final String language = (String)LANGUAGES_AND_TEXTS[i];
- final String[] textsTable = (String[])LANGUAGES_AND_TEXTS[i + 1];
- sLanguageToTextsTableMap.put(language, textsTable);
- sTextsTableToLanguageMap.put(textsTable, language);
+ for (int i = 0; i < LOCALES_AND_TEXTS.length; i += 2) {
+ final String locale = (String)LOCALES_AND_TEXTS[i];
+ final String[] textsTable = (String[])LOCALES_AND_TEXTS[i + 1];
+ sLocaleToTextsTableMap.put(locale, textsTable);
+ sTextsTableToLocaleMap.put(textsTable, locale);
}
}
}
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
index 30c2dfedb..7b37777f5 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
@@ -253,18 +253,20 @@ public final class BinaryDictionary extends Dictionary {
// TODO: toLowerCase in the native code
final int[] prevWordCodePointArray = (null == prevWord)
? null : StringUtils.toCodePointArray(prevWord);
- final int composerSize = composer.sizeWithoutTrailingSingleQuotes();
-
+ final InputPointers inputPointers = composer.getInputPointers();
final boolean isGesture = composer.isBatchMode();
- if (composerSize <= 1 || !isGesture) {
+ final int inputSize;
+ if (!isGesture) {
+ final int composerSize = composer.sizeWithoutTrailingSingleQuotes();
if (composerSize > MAX_WORD_LENGTH - 1) return null;
for (int i = 0; i < composerSize; i++) {
mInputCodePoints[i] = composer.getCodeAt(i);
}
+ inputSize = composerSize;
+ } else {
+ inputSize = inputPointers.getPointerSize();
}
- final InputPointers ips = composer.getInputPointers();
- final int inputSize = isGesture ? ips.getPointerSize() : composerSize;
mNativeSuggestOptions.setIsGesture(isGesture);
mNativeSuggestOptions.setAdditionalFeaturesOptions(additionalFeaturesOptions);
if (inOutLanguageWeight != null) {
@@ -274,12 +276,12 @@ public final class BinaryDictionary extends Dictionary {
}
// proximityInfo and/or prevWordForBigrams may not be null.
getSuggestionsNative(mNativeDict, proximityInfo.getNativeProximityInfo(),
- getTraverseSession(sessionId).getSession(), ips.getXCoordinates(),
- ips.getYCoordinates(), ips.getTimes(), ips.getPointerIds(), mInputCodePoints,
- inputSize, mNativeSuggestOptions.getOptions(),
- prevWordCodePointArray, mOutputSuggestionCount, mOutputCodePoints, mOutputScores,
- mSpaceIndices, mOutputTypes, mOutputAutoCommitFirstWordConfidence,
- mInputOutputLanguageWeight);
+ getTraverseSession(sessionId).getSession(), inputPointers.getXCoordinates(),
+ inputPointers.getYCoordinates(), inputPointers.getTimes(),
+ inputPointers.getPointerIds(), mInputCodePoints, inputSize,
+ mNativeSuggestOptions.getOptions(), prevWordCodePointArray, mOutputSuggestionCount,
+ mOutputCodePoints, mOutputScores, mSpaceIndices, mOutputTypes,
+ mOutputAutoCommitFirstWordConfidence, mInputOutputLanguageWeight);
if (inOutLanguageWeight != null) {
inOutLanguageWeight[0] = mInputOutputLanguageWeight[0];
}
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index ca99998e0..6d36af77a 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -88,6 +88,7 @@ import com.android.inputmethod.latin.utils.ImportantNoticeUtils;
import com.android.inputmethod.latin.utils.IntentUtils;
import com.android.inputmethod.latin.utils.JniUtils;
import com.android.inputmethod.latin.utils.LeakGuardHandlerWrapper;
+import com.android.inputmethod.latin.utils.StatsUtils;
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
import com.android.inputmethod.research.ResearchLogger;
@@ -509,6 +510,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
registerReceiver(mDictionaryDumpBroadcastReceiver, dictDumpFilter);
DictionaryDecayBroadcastReciever.setUpIntervalAlarmForDictionaryDecaying(this);
+
+ StatsUtils.onCreateCompleted(this);
}
// Has to be package-visible for unit tests
@@ -628,6 +631,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
PersonalizationDictionarySessionRegistrar.close(this);
LatinImeLogger.commit();
LatinImeLogger.onDestroy();
+ StatsUtils.onDestroy();
super.onDestroy();
}
diff --git a/java/src/com/android/inputmethod/latin/utils/StatsUtils.java b/java/src/com/android/inputmethod/latin/utils/StatsUtils.java
new file mode 100644
index 000000000..a059f877b
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/utils/StatsUtils.java
@@ -0,0 +1,53 @@
+/*
+ * 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.content.Context;
+import android.content.SharedPreferences;
+import android.preference.PreferenceManager;
+import android.util.Log;
+
+import com.android.inputmethod.latin.settings.Settings;
+
+public final class StatsUtils {
+ private static final String TAG = StatsUtils.class.getSimpleName();
+ private static final StatsUtils sInstance = new StatsUtils();
+
+ public static void onCreateCompleted(final Context context) {
+ sInstance.onCreateCompletedInternal(context);
+ }
+
+ private void onCreateCompletedInternal(final Context context) {
+ mContext = context;
+ final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
+ final Boolean usePersonalizedDict =
+ prefs.getBoolean(Settings.PREF_KEY_USE_PERSONALIZED_DICTS, true);
+ Log.d(TAG, "onCreateCompleted. context: " + context.toString() + "usePersonalizedDict: "
+ + usePersonalizedDict);
+ }
+
+ public static void onDestroy() {
+ sInstance.onDestroyInternal();
+ }
+
+ private void onDestroyInternal() {
+ Log.d(TAG, "onDestroy. context: " + mContext.toString());
+ mContext = null;
+ }
+
+ private Context mContext;
+}
diff --git a/native/jni/NativeFileList.mk b/native/jni/NativeFileList.mk
index 23b037701..a22497fd9 100644
--- a/native/jni/NativeFileList.mk
+++ b/native/jni/NativeFileList.mk
@@ -31,7 +31,7 @@ LATIN_IME_CORE_SRC_FILES := \
digraph_utils.cpp \
error_type_utils.cpp \
multi_bigram_map.cpp \
- word_property.cpp) \
+ property/word_property.cpp) \
$(addprefix suggest/core/layout/, \
additional_proximity_chars.cpp \
proximity_info.cpp \
@@ -100,4 +100,5 @@ LATIN_IME_CORE_SRC_FILES := \
time_keeper.cpp)
LATIN_IME_CORE_TEST_FILES := \
+ defines_test.cpp \
utils/autocorrection_threshold_utils_test.cpp
diff --git a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp
index bf03fdf5c..a10234423 100644
--- a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp
+++ b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp
@@ -24,7 +24,7 @@
#include "jni.h"
#include "jni_common.h"
#include "suggest/core/dictionary/dictionary.h"
-#include "suggest/core/dictionary/word_property.h"
+#include "suggest/core/dictionary/property/word_property.h"
#include "suggest/core/result/suggestion_results.h"
#include "suggest/core/suggest_options.h"
#include "suggest/policyimpl/dictionary/structure/dictionary_structure_with_buffer_policy_factory.h"
diff --git a/native/jni/src/defines.h b/native/jni/src/defines.h
index 1719b1c60..3becc79e8 100644
--- a/native/jni/src/defines.h
+++ b/native/jni/src/defines.h
@@ -35,7 +35,13 @@
// Must be equal to ProximityInfo.MAX_PROXIMITY_CHARS_SIZE in Java
#define MAX_PROXIMITY_CHARS_SIZE 16
#define ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE 2
-#define NELEMS(x) (sizeof(x) / sizeof((x)[0]))
+
+// TODO: Use size_t instead of int.
+// Disclaimer: You will see a compile error if you use this macro against a variable-length array.
+// Sorry for the inconvenience. It isn't supported.
+template <typename T, int N>
+char (&ArraySizeHelper(T (&array)[N]))[N];
+#define NELEMS(x) (sizeof(ArraySizeHelper(x)))
AK_FORCE_INLINE static int intArrayToCharArray(const int *const source, const int sourceSize,
char *dest, const int destSize) {
diff --git a/native/jni/src/suggest/core/dictionary/dictionary.h b/native/jni/src/suggest/core/dictionary/dictionary.h
index a134516e1..6b7756565 100644
--- a/native/jni/src/suggest/core/dictionary/dictionary.h
+++ b/native/jni/src/suggest/core/dictionary/dictionary.h
@@ -22,7 +22,7 @@
#include "defines.h"
#include "jni.h"
#include "suggest/core/dictionary/bigram_dictionary.h"
-#include "suggest/core/dictionary/word_property.h"
+#include "suggest/core/dictionary/property/word_property.h"
#include "suggest/core/policy/dictionary_header_structure_policy.h"
#include "suggest/core/policy/dictionary_structure_with_buffer_policy.h"
#include "suggest/core/suggest_interface.h"
diff --git a/native/jni/src/suggest/core/dictionary/property/bigram_property.h b/native/jni/src/suggest/core/dictionary/property/bigram_property.h
new file mode 100644
index 000000000..8d3429b5b
--- /dev/null
+++ b/native/jni/src/suggest/core/dictionary/property/bigram_property.h
@@ -0,0 +1,65 @@
+/*
+ * 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.
+ */
+
+#ifndef LATINIME_BIGRAM_PROPERTY_H
+#define LATINIME_BIGRAM_PROPERTY_H
+
+#include <vector>
+
+#include "defines.h"
+
+namespace latinime {
+
+class BigramProperty {
+ public:
+ BigramProperty(const std::vector<int> *const targetCodePoints,
+ const int probability, const int timestamp, const int level, const int count)
+ : mTargetCodePoints(*targetCodePoints), mProbability(probability),
+ mTimestamp(timestamp), mLevel(level), mCount(count) {}
+
+ const std::vector<int> *getTargetCodePoints() const {
+ return &mTargetCodePoints;
+ }
+
+ int getProbability() const {
+ return mProbability;
+ }
+
+ int getTimestamp() const {
+ return mTimestamp;
+ }
+
+ int getLevel() const {
+ return mLevel;
+ }
+
+ int getCount() const {
+ return mCount;
+ }
+
+ private:
+ // Default copy constructor and assign operator are used for using in std::vector.
+ DISALLOW_DEFAULT_CONSTRUCTOR(BigramProperty);
+
+ // TODO: Make members const.
+ std::vector<int> mTargetCodePoints;
+ int mProbability;
+ int mTimestamp;
+ int mLevel;
+ int mCount;
+};
+} // namespace latinime
+#endif // LATINIME_WORD_PROPERTY_H
diff --git a/native/jni/src/suggest/core/dictionary/property/unigram_property.h b/native/jni/src/suggest/core/dictionary/property/unigram_property.h
new file mode 100644
index 000000000..d2551057b
--- /dev/null
+++ b/native/jni/src/suggest/core/dictionary/property/unigram_property.h
@@ -0,0 +1,107 @@
+/*
+ * 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.
+ */
+
+#ifndef LATINIME_UNIGRAM_PROPERTY_H
+#define LATINIME_UNIGRAM_PROPERTY_H
+
+#include <vector>
+
+#include "defines.h"
+
+namespace latinime {
+
+class UnigramProperty {
+ public:
+ class ShortcutProperty {
+ public:
+ ShortcutProperty(const std::vector<int> *const targetCodePoints, const int probability)
+ : mTargetCodePoints(*targetCodePoints), mProbability(probability) {}
+
+ const std::vector<int> *getTargetCodePoints() const {
+ return &mTargetCodePoints;
+ }
+
+ int getProbability() const {
+ return mProbability;
+ }
+
+ private:
+ // Default copy constructor and assign operator are used for using in std::vector.
+ DISALLOW_DEFAULT_CONSTRUCTOR(ShortcutProperty);
+
+ // TODO: Make members const.
+ std::vector<int> mTargetCodePoints;
+ int mProbability;
+ };
+
+ UnigramProperty()
+ : mIsNotAWord(false), mIsBlacklisted(false), mProbability(NOT_A_PROBABILITY),
+ mTimestamp(NOT_A_TIMESTAMP), mLevel(0), mCount(0), mShortcuts() {}
+
+ UnigramProperty(const bool isNotAWord, const bool isBlacklisted, const int probability,
+ const int timestamp, const int level, const int count,
+ const std::vector<ShortcutProperty> *const shortcuts)
+ : mIsNotAWord(isNotAWord), mIsBlacklisted(isBlacklisted), mProbability(probability),
+ mTimestamp(timestamp), mLevel(level), mCount(count), mShortcuts(*shortcuts) {}
+
+ bool isNotAWord() const {
+ return mIsNotAWord;
+ }
+
+ bool isBlacklisted() const {
+ return mIsBlacklisted;
+ }
+
+ bool hasShortcuts() const {
+ return !mShortcuts.empty();
+ }
+
+ int getProbability() const {
+ return mProbability;
+ }
+
+ int getTimestamp() const {
+ return mTimestamp;
+ }
+
+ int getLevel() const {
+ return mLevel;
+ }
+
+ int getCount() const {
+ return mCount;
+ }
+
+ const std::vector<ShortcutProperty> &getShortcuts() const {
+ return mShortcuts;
+ }
+
+ private:
+ // Default copy constructor is used for using as a return value.
+ DISALLOW_ASSIGNMENT_OPERATOR(UnigramProperty);
+
+ // TODO: Make members const.
+ bool mIsNotAWord;
+ bool mIsBlacklisted;
+ int mProbability;
+ // Historical information
+ int mTimestamp;
+ int mLevel;
+ int mCount;
+ std::vector<ShortcutProperty> mShortcuts;
+};
+} // namespace latinime
+#endif // LATINIME_UNIGRAM_PROPERTY_H
diff --git a/native/jni/src/suggest/core/dictionary/word_property.cpp b/native/jni/src/suggest/core/dictionary/property/word_property.cpp
index 473311842..95608dcf8 100644
--- a/native/jni/src/suggest/core/dictionary/word_property.cpp
+++ b/native/jni/src/suggest/core/dictionary/property/word_property.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include "suggest/core/dictionary/word_property.h"
+#include "suggest/core/dictionary/property/word_property.h"
namespace latinime {
@@ -23,9 +23,12 @@ void WordProperty::outputProperties(JNIEnv *const env, jintArray outCodePoints,
jobject outBigramProbabilities, jobject outShortcutTargets,
jobject outShortcutProbabilities) const {
env->SetIntArrayRegion(outCodePoints, 0 /* start */, mCodePoints.size(), &mCodePoints[0]);
- jboolean flags[] = {mIsNotAWord, mIsBlacklisted, mHasBigrams, mHasShortcuts};
+
+ jboolean flags[] = {mUnigramProperty.isNotAWord(), mUnigramProperty.isBlacklisted(),
+ !mBigrams.empty(), mUnigramProperty.hasShortcuts()};
env->SetBooleanArrayRegion(outFlags, 0 /* start */, NELEMS(flags), flags);
- int probabilityInfo[] = {mProbability, mTimestamp, mLevel, mCount};
+ int probabilityInfo[] = {mUnigramProperty.getProbability(), mUnigramProperty.getTimestamp(),
+ mUnigramProperty.getLevel(), mUnigramProperty.getCount()};
env->SetIntArrayRegion(outProbabilityInfo, 0 /* start */, NELEMS(probabilityInfo),
probabilityInfo);
@@ -35,19 +38,17 @@ void WordProperty::outputProperties(JNIEnv *const env, jintArray outCodePoints,
jmethodID addMethodId = env->GetMethodID(arrayListClass, "add", "(Ljava/lang/Object;)Z");
// Output bigrams.
- const int bigramCount = mBigrams.size();
- for (int i = 0; i < bigramCount; ++i) {
- const BigramProperty *const bigramProperty = &mBigrams[i];
- const std::vector<int> *const word1CodePoints = bigramProperty->getTargetCodePoints();
+ for (const auto &bigramProperty : mBigrams) {
+ const std::vector<int> *const word1CodePoints = bigramProperty.getTargetCodePoints();
jintArray bigramWord1CodePointArray = env->NewIntArray(word1CodePoints->size());
env->SetIntArrayRegion(bigramWord1CodePointArray, 0 /* start */,
- word1CodePoints->size(), &word1CodePoints->at(0));
+ word1CodePoints->size(), word1CodePoints->data());
env->CallBooleanMethod(outBigramTargets, addMethodId, bigramWord1CodePointArray);
env->DeleteLocalRef(bigramWord1CodePointArray);
- int bigramProbabilityInfo[] = {bigramProperty->getProbability(),
- bigramProperty->getTimestamp(), bigramProperty->getLevel(),
- bigramProperty->getCount()};
+ int bigramProbabilityInfo[] = {bigramProperty.getProbability(),
+ bigramProperty.getTimestamp(), bigramProperty.getLevel(),
+ bigramProperty.getCount()};
jintArray bigramProbabilityInfoArray = env->NewIntArray(NELEMS(bigramProbabilityInfo));
env->SetIntArrayRegion(bigramProbabilityInfoArray, 0 /* start */,
NELEMS(bigramProbabilityInfo), bigramProbabilityInfo);
@@ -56,16 +57,15 @@ void WordProperty::outputProperties(JNIEnv *const env, jintArray outCodePoints,
}
// Output shortcuts.
- const int shortcutTargetCount = mShortcuts.size();
- for (int i = 0; i < shortcutTargetCount; ++i) {
- const std::vector<int> *const targetCodePoints = mShortcuts[i].getTargetCodePoints();
+ for (const auto &shortcut : mUnigramProperty.getShortcuts()) {
+ const std::vector<int> *const targetCodePoints = shortcut.getTargetCodePoints();
jintArray shortcutTargetCodePointArray = env->NewIntArray(targetCodePoints->size());
env->SetIntArrayRegion(shortcutTargetCodePointArray, 0 /* start */,
- targetCodePoints->size(), &targetCodePoints->at(0));
+ targetCodePoints->size(), targetCodePoints->data());
env->CallBooleanMethod(outShortcutTargets, addMethodId, shortcutTargetCodePointArray);
env->DeleteLocalRef(shortcutTargetCodePointArray);
jobject integerProbability = env->NewObject(integerClass, intToIntegerConstructorId,
- mShortcuts[i].getProbability());
+ shortcut.getProbability());
env->CallBooleanMethod(outShortcutProbabilities, addMethodId, integerProbability);
env->DeleteLocalRef(integerProbability);
}
diff --git a/native/jni/src/suggest/core/dictionary/property/word_property.h b/native/jni/src/suggest/core/dictionary/property/word_property.h
new file mode 100644
index 000000000..5519a917c
--- /dev/null
+++ b/native/jni/src/suggest/core/dictionary/property/word_property.h
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+
+#ifndef LATINIME_WORD_PROPERTY_H
+#define LATINIME_WORD_PROPERTY_H
+
+#include <vector>
+
+#include "defines.h"
+#include "jni.h"
+#include "suggest/core/dictionary/property/bigram_property.h"
+#include "suggest/core/dictionary/property/unigram_property.h"
+
+namespace latinime {
+
+// This class is used for returning information belonging to a word to java side.
+class WordProperty {
+ public:
+ // Default constructor is used to create an instance that indicates an invalid word.
+ WordProperty()
+ : mCodePoints(), mUnigramProperty(), mBigrams() {}
+
+ WordProperty(const std::vector<int> *const codePoints,
+ const UnigramProperty *const unigramProperty,
+ const std::vector<BigramProperty> *const bigrams)
+ : mCodePoints(*codePoints), mUnigramProperty(*unigramProperty), mBigrams(*bigrams) {}
+
+ void outputProperties(JNIEnv *const env, jintArray outCodePoints, jbooleanArray outFlags,
+ jintArray outProbabilityInfo, jobject outBigramTargets, jobject outBigramProbabilities,
+ jobject outShortcutTargets, jobject outShortcutProbabilities) const;
+
+ private:
+ // Default copy constructor is used for using as a return value.
+ DISALLOW_ASSIGNMENT_OPERATOR(WordProperty);
+
+ const std::vector<int> mCodePoints;
+ const UnigramProperty mUnigramProperty;
+ const std::vector<BigramProperty> mBigrams;
+};
+} // namespace latinime
+#endif // LATINIME_WORD_PROPERTY_H
diff --git a/native/jni/src/suggest/core/dictionary/word_property.h b/native/jni/src/suggest/core/dictionary/word_property.h
deleted file mode 100644
index 40b1a91a4..000000000
--- a/native/jni/src/suggest/core/dictionary/word_property.h
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright (C) 2013 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.
- */
-
-#ifndef LATINIME_WORD_PROPERTY_H
-#define LATINIME_WORD_PROPERTY_H
-
-#include <cstring>
-#include <vector>
-
-#include "defines.h"
-#include "jni.h"
-
-namespace latinime {
-
-// This class is used for returning information belonging to a word to java side.
-class WordProperty {
- public:
- class BigramProperty {
- public:
- BigramProperty(const std::vector<int> *const targetCodePoints,
- const int probability, const int timestamp, const int level, const int count)
- : mTargetCodePoints(*targetCodePoints), mProbability(probability),
- mTimestamp(timestamp), mLevel(level), mCount(count) {}
-
- const std::vector<int> *getTargetCodePoints() const {
- return &mTargetCodePoints;
- }
-
- int getProbability() const {
- return mProbability;
- }
-
- int getTimestamp() const {
- return mTimestamp;
- }
-
- int getLevel() const {
- return mLevel;
- }
-
- int getCount() const {
- return mCount;
- }
-
- private:
- std::vector<int> mTargetCodePoints;
- int mProbability;
- int mTimestamp;
- int mLevel;
- int mCount;
- };
-
- class ShortcutProperty {
- public:
- ShortcutProperty(const std::vector<int> *const targetCodePoints, const int probability)
- : mTargetCodePoints(*targetCodePoints), mProbability(probability) {}
-
- const std::vector<int> *getTargetCodePoints() const {
- return &mTargetCodePoints;
- }
-
- int getProbability() const {
- return mProbability;
- }
-
- private:
- std::vector<int> mTargetCodePoints;
- int mProbability;
- };
-
- // Invalid word.
- WordProperty()
- : mCodePoints(), mIsNotAWord(false), mIsBlacklisted(false),
- mHasBigrams(false), mHasShortcuts(false), mProbability(NOT_A_PROBABILITY),
- mTimestamp(0), mLevel(0), mCount(0), mBigrams(), mShortcuts() {}
-
- WordProperty(const std::vector<int> *const codePoints,
- const bool isNotAWord, const bool isBlacklisted, const bool hasBigrams,
- const bool hasShortcuts, const int probability, const int timestamp,
- const int level, const int count, const std::vector<BigramProperty> *const bigrams,
- const std::vector<ShortcutProperty> *const shortcuts)
- : mCodePoints(*codePoints), mIsNotAWord(isNotAWord), mIsBlacklisted(isBlacklisted),
- mHasBigrams(hasBigrams), mHasShortcuts(hasShortcuts), mProbability(probability),
- mTimestamp(timestamp), mLevel(level), mCount(count), mBigrams(*bigrams),
- mShortcuts(*shortcuts) {}
-
- void outputProperties(JNIEnv *const env, jintArray outCodePoints, jbooleanArray outFlags,
- jintArray outProbabilityInfo, jobject outBigramTargets, jobject outBigramProbabilities,
- jobject outShortcutTargets, jobject outShortcutProbabilities) const;
-
- private:
- DISALLOW_ASSIGNMENT_OPERATOR(WordProperty);
-
- std::vector<int> mCodePoints;
- bool mIsNotAWord;
- bool mIsBlacklisted;
- bool mHasBigrams;
- bool mHasShortcuts;
- int mProbability;
- // Historical information
- int mTimestamp;
- int mLevel;
- int mCount;
- std::vector<BigramProperty> mBigrams;
- std::vector<ShortcutProperty> mShortcuts;
-};
-} // namespace latinime
-#endif // LATINIME_WORD_PROPERTY_H
diff --git a/native/jni/src/suggest/core/policy/dictionary_structure_with_buffer_policy.h b/native/jni/src/suggest/core/policy/dictionary_structure_with_buffer_policy.h
index b6dc7d006..ae2e7a8fe 100644
--- a/native/jni/src/suggest/core/policy/dictionary_structure_with_buffer_policy.h
+++ b/native/jni/src/suggest/core/policy/dictionary_structure_with_buffer_policy.h
@@ -20,7 +20,7 @@
#include <memory>
#include "defines.h"
-#include "suggest/core/dictionary/word_property.h"
+#include "suggest/core/dictionary/property/word_property.h"
namespace latinime {
diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.cpp b/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.cpp
index 4e795f82c..b426dbf28 100644
--- a/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.cpp
+++ b/native/jni/src/suggest/policyimpl/dictionary/structure/v2/patricia_trie_policy.cpp
@@ -339,7 +339,7 @@ const WordProperty PatriciaTriePolicy::getWordProperty(const int *const codePoin
std::vector<int> codePointVector(ptNodeParams.getCodePoints(),
ptNodeParams.getCodePoints() + ptNodeParams.getCodePointCount());
// Fetch bigram information.
- std::vector<WordProperty::BigramProperty> bigrams;
+ std::vector<BigramProperty> bigrams;
const int bigramListPos = getBigramsPositionOfPtNode(ptNodePos);
int bigramWord1CodePoints[MAX_WORD_LENGTH];
BinaryDictionaryBigramsIterator bigramsIt(getBigramsStructurePolicy(), bigramListPos);
@@ -360,7 +360,7 @@ const WordProperty PatriciaTriePolicy::getWordProperty(const int *const codePoin
}
}
// Fetch shortcut information.
- std::vector<WordProperty::ShortcutProperty> shortcuts;
+ std::vector<UnigramProperty::ShortcutProperty> shortcuts;
int shortcutPos = getShortcutPositionOfPtNode(ptNodePos);
if (shortcutPos != NOT_A_DICT_POS) {
int shortcutTargetCodePoints[MAX_WORD_LENGTH];
@@ -379,11 +379,10 @@ const WordProperty PatriciaTriePolicy::getWordProperty(const int *const codePoin
shortcuts.emplace_back(&shortcutTarget, shortcutProbability);
}
}
- return WordProperty(&codePointVector, ptNodeParams.isNotAWord(),
- ptNodeParams.isBlacklisted(), ptNodeParams.hasBigrams(),
- ptNodeParams.hasShortcutTargets(), ptNodeParams.getProbability(),
- NOT_A_TIMESTAMP /* timestamp */, 0 /* level */, 0 /* count */,
- &bigrams, &shortcuts);
+ const UnigramProperty unigramProperty(ptNodeParams.isNotAWord(),
+ ptNodeParams.isBlacklisted(), ptNodeParams.getProbability(),
+ NOT_A_TIMESTAMP /* timestamp */, 0 /* level */, 0 /* count */, &shortcuts);
+ return WordProperty(&codePointVector, &unigramProperty, &bigrams);
}
int PatriciaTriePolicy::getNextWordAndNextToken(const int token, int *const outCodePoints) {
diff --git a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.cpp b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.cpp
index 107ddab2c..6cf8409dc 100644
--- a/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.cpp
+++ b/native/jni/src/suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_policy.cpp
@@ -20,7 +20,9 @@
#include "suggest/core/dicnode/dic_node.h"
#include "suggest/core/dicnode/dic_node_vector.h"
-#include "suggest/core/dictionary/word_property.h"
+#include "suggest/core/dictionary/property/bigram_property.h"
+#include "suggest/core/dictionary/property/unigram_property.h"
+#include "suggest/core/dictionary/property/word_property.h"
#include "suggest/policyimpl/dictionary/structure/pt_common/dynamic_pt_reading_helper.h"
#include "suggest/policyimpl/dictionary/structure/v4/ver4_patricia_trie_node_reader.h"
#include "suggest/policyimpl/dictionary/utils/forgetting_curve_utils.h"
@@ -358,7 +360,7 @@ const WordProperty Ver4PatriciaTriePolicy::getWordProperty(const int *const code
ptNodeParams.getTerminalId());
const HistoricalInfo *const historicalInfo = probabilityEntry.getHistoricalInfo();
// Fetch bigram information.
- std::vector<WordProperty::BigramProperty> bigrams;
+ std::vector<BigramProperty> bigrams;
const int bigramListPos = getBigramsPositionOfPtNode(ptNodePos);
if (bigramListPos != NOT_A_DICT_POS) {
int bigramWord1CodePoints[MAX_WORD_LENGTH];
@@ -395,7 +397,7 @@ const WordProperty Ver4PatriciaTriePolicy::getWordProperty(const int *const code
}
}
// Fetch shortcut information.
- std::vector<WordProperty::ShortcutProperty> shortcuts;
+ std::vector<UnigramProperty::ShortcutProperty> shortcuts;
int shortcutPos = getShortcutPositionOfPtNode(ptNodePos);
if (shortcutPos != NOT_A_DICT_POS) {
int shortcutTarget[MAX_WORD_LENGTH];
@@ -411,11 +413,11 @@ const WordProperty Ver4PatriciaTriePolicy::getWordProperty(const int *const code
shortcuts.emplace_back(&target, shortcutProbability);
}
}
- return WordProperty(&codePointVector, ptNodeParams.isNotAWord(),
- ptNodeParams.isBlacklisted(), ptNodeParams.hasBigrams(),
- ptNodeParams.hasShortcutTargets(), ptNodeParams.getProbability(),
+ const UnigramProperty unigramProperty(ptNodeParams.isNotAWord(),
+ ptNodeParams.isBlacklisted(), ptNodeParams.getProbability(),
historicalInfo->getTimeStamp(), historicalInfo->getLevel(),
- historicalInfo->getCount(), &bigrams, &shortcuts);
+ historicalInfo->getCount(), &shortcuts);
+ return WordProperty(&codePointVector, &unigramProperty, &bigrams);
}
int Ver4PatriciaTriePolicy::getNextWordAndNextToken(const int token, int *const outCodePoints) {
diff --git a/native/jni/tests/defines_test.cpp b/native/jni/tests/defines_test.cpp
new file mode 100644
index 000000000..f7b80b2b5
--- /dev/null
+++ b/native/jni/tests/defines_test.cpp
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+
+#include "defines.h"
+
+#include <gtest/gtest.h>
+
+namespace latinime {
+namespace {
+
+TEST(DefinesTest, NELEMSForFixedLengthArray) {
+ const size_t SMALL_ARRAY_SIZE = 1;
+ const size_t LARGE_ARRAY_SIZE = 100;
+ int smallArray[SMALL_ARRAY_SIZE];
+ int largeArray[LARGE_ARRAY_SIZE];
+ EXPECT_EQ(SMALL_ARRAY_SIZE, NELEMS(smallArray));
+ EXPECT_EQ(LARGE_ARRAY_SIZE, NELEMS(largeArray));
+}
+
+} // namespace
+} // namespace latinime
diff --git a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetSubtypesCountTests.java b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetSubtypesCountTests.java
index d6d12ea56..57d295058 100644
--- a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetSubtypesCountTests.java
+++ b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetSubtypesCountTests.java
@@ -25,8 +25,8 @@ import java.util.ArrayList;
@SmallTest
public class KeyboardLayoutSetSubtypesCountTests extends KeyboardLayoutSetTestsBase {
- private static final int NUMBER_OF_SUBTYPES = 67;
- private static final int NUMBER_OF_ASCII_CAPABLE_SUBTYPES = 42;
+ private static final int NUMBER_OF_SUBTYPES = 68;
+ private static final int NUMBER_OF_ASCII_CAPABLE_SUBTYPES = 43;
private static final int NUMBER_OF_PREDEFINED_ADDITIONAL_SUBTYPES = 2;
private static String toString(final ArrayList<InputMethodSubtype> subtypeList) {
diff --git a/tests/src/com/android/inputmethod/keyboard/layout/Hindi.java b/tests/src/com/android/inputmethod/keyboard/layout/Hindi.java
index c3f45313f..b12b8be64 100644
--- a/tests/src/com/android/inputmethod/keyboard/layout/Hindi.java
+++ b/tests/src/com/android/inputmethod/keyboard/layout/Hindi.java
@@ -51,7 +51,7 @@ public final class Hindi extends LayoutBase {
public ExpectedKey getBackToSymbolsKey() { return HINDI_BACK_TO_SYMBOLS_KEY; }
@Override
- public ExpectedKey getCurrencyKey() { return CURRENCY_HINDI; }
+ public ExpectedKey getCurrencyKey() { return CURRENCY_RUPEE; }
@Override
public ExpectedKey[] getOtherCurrencyKeys() {
@@ -78,7 +78,7 @@ public final class Hindi extends LayoutBase {
Constants.CODE_SHIFT);
// U+20B9: "₹" INDIAN RUPEE SIGN
- private static final ExpectedKey CURRENCY_HINDI = key("\u20B9",
+ private static final ExpectedKey CURRENCY_RUPEE = key("\u20B9",
Symbols.CURRENCY_GENERIC_MORE_KEYS);
}
diff --git a/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsEnglishIN.java b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsEnglishIN.java
new file mode 100644
index 000000000..c80b25024
--- /dev/null
+++ b/tests/src/com/android/inputmethod/keyboard/layout/tests/TestsEnglishIN.java
@@ -0,0 +1,55 @@
+/*
+ * 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.keyboard.layout.tests;
+
+import android.test.suitebuilder.annotation.SmallTest;
+
+import com.android.inputmethod.keyboard.layout.LayoutBase;
+import com.android.inputmethod.keyboard.layout.Qwerty;
+import com.android.inputmethod.keyboard.layout.Symbols;
+import com.android.inputmethod.keyboard.layout.SymbolsShifted;
+import com.android.inputmethod.keyboard.layout.expected.ExpectedKey;
+
+import java.util.Locale;
+
+/*
+ * en_IN: English (India)/qwerty
+ */
+@SmallTest
+public final class TestsEnglishIN extends TestsEnglishUS {
+ private static final Locale LOCALE = new Locale("en", "IN");
+ private static final LayoutBase LAYOUT = new Qwerty(new EnglishINCustomizer(LOCALE));
+
+ @Override
+ LayoutBase getLayout() { return LAYOUT; }
+
+ private static class EnglishINCustomizer extends EnglishCustomizer {
+ public EnglishINCustomizer(final Locale locale) { super(locale); }
+
+ @Override
+ public ExpectedKey getCurrencyKey() { return CURRENCY_RUPEE; }
+
+ @Override
+ public ExpectedKey[] getOtherCurrencyKeys() {
+ return SymbolsShifted.CURRENCIES_OTHER_GENERIC;
+ }
+
+ // U+20B9: "₹" INDIAN RUPEE SIGN
+ private static final ExpectedKey CURRENCY_RUPEE = key("\u20B9",
+ Symbols.CURRENCY_GENERIC_MORE_KEYS);
+ }
+}
diff --git a/tests/src/com/android/inputmethod/latin/ShiftModeTests.java b/tests/src/com/android/inputmethod/latin/ShiftModeTests.java
new file mode 100644
index 000000000..806fad060
--- /dev/null
+++ b/tests/src/com/android/inputmethod/latin/ShiftModeTests.java
@@ -0,0 +1,56 @@
+/*
+ * 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;
+
+import android.test.suitebuilder.annotation.LargeTest;
+import android.text.TextUtils;
+import android.view.inputmethod.EditorInfo;
+
+import com.android.inputmethod.latin.Constants;
+import com.android.inputmethod.latin.WordComposer;
+
+@LargeTest
+public class ShiftModeTests extends InputTestsBase {
+
+ @Override
+ protected EditorInfo enrichEditorInfo(final EditorInfo ei) {
+ ei.inputType |= TextUtils.CAP_MODE_SENTENCES;
+ ei.initialCapsMode = TextUtils.CAP_MODE_SENTENCES;
+ return ei;
+ }
+
+ private boolean isCapsModeAutoShifted() {
+ return mLatinIME.mKeyboardSwitcher.getKeyboardShiftMode()
+ == WordComposer.CAPS_MODE_AUTO_SHIFTED;
+ }
+
+ public void testTypicalSentence() {
+ assertTrue("Initial auto caps state", isCapsModeAutoShifted());
+ type("Test");
+ assertFalse("Caps after letter", isCapsModeAutoShifted());
+ type(" ");
+ assertFalse("Caps after space", isCapsModeAutoShifted());
+ type("some,");
+ assertFalse("Caps after comma", isCapsModeAutoShifted());
+ type(" ");
+ assertFalse("Caps after comma space", isCapsModeAutoShifted());
+ type("words.");
+ assertFalse("Caps directly after period", isCapsModeAutoShifted());
+ type(" ");
+ assertTrue("Caps after period space", isCapsModeAutoShifted());
+ }
+}
diff --git a/tools/make-keyboard-text/res/src/com/android/inputmethod/keyboard/internal/KeyboardTextsTable.tmpl b/tools/make-keyboard-text/res/src/com/android/inputmethod/keyboard/internal/KeyboardTextsTable.tmpl
index b25bfb204..2b5494fa5 100644
--- a/tools/make-keyboard-text/res/src/com/android/inputmethod/keyboard/internal/KeyboardTextsTable.tmpl
+++ b/tools/make-keyboard-text/res/src/com/android/inputmethod/keyboard/internal/KeyboardTextsTable.tmpl
@@ -19,6 +19,7 @@ package com.android.inputmethod.keyboard.internal;
import com.android.inputmethod.latin.utils.CollectionUtils;
import java.util.HashMap;
+import java.util.Locale;
/**
* !!!!! DO NOT EDIT THIS FILE !!!!!
@@ -44,19 +45,19 @@ import java.util.HashMap;
public final class KeyboardTextsTable {
// Name to index map.
private static final HashMap<String, Integer> sNameToIndexesMap = CollectionUtils.newHashMap();
- // Language to texts table map.
- private static final HashMap<String, String[]> sLanguageToTextsTableMap =
+ // Locale to texts table map.
+ private static final HashMap<String, String[]> sLocaleToTextsTableMap =
CollectionUtils.newHashMap();
// TODO: Remove this variable after debugging.
- // Texts table to language maps.
- private static final HashMap<String[], String> sTextsTableToLanguageMap =
+ // Texts table to locale maps.
+ private static final HashMap<String[], String> sTextsTableToLocaleMap =
CollectionUtils.newHashMap();
public static String getText(final String name, final String[] textsTable) {
final Integer indexObj = sNameToIndexesMap.get(name);
if (indexObj == null) {
- throw new RuntimeException("Unknown text name=" + name + " language="
- + sTextsTableToLanguageMap.get(textsTable));
+ throw new RuntimeException("Unknown text name=" + name + " locale="
+ + sTextsTableToLocaleMap.get(textsTable));
}
final int index = indexObj;
final String text = (index < textsTable.length) ? textsTable[index] : null;
@@ -64,17 +65,24 @@ public final class KeyboardTextsTable {
return text;
}
// Sanity check.
- if (index >= 0 && index < LANGUAGE_DEFAULT.length) {
- return LANGUAGE_DEFAULT[index];
+ if (index >= 0 && index < TEXTS_DEFAULT.length) {
+ return TEXTS_DEFAULT[index];
}
// Throw exception for debugging purpose.
throw new RuntimeException("Illegal index=" + index + " for name=" + name
- + " language=" + sTextsTableToLanguageMap.get(textsTable));
+ + " locale=" + sTextsTableToLocaleMap.get(textsTable));
}
- public static String[] getTextsTable(final String language) {
- final String[] textsTable = sLanguageToTextsTableMap.get(language);
- return textsTable != null ? textsTable : LANGUAGE_DEFAULT;
+ public static String[] getTextsTable(final Locale locale) {
+ final String localeKey = locale.toString();
+ if (sLocaleToTextsTableMap.containsKey(localeKey)) {
+ return sLocaleToTextsTableMap.get(localeKey);
+ }
+ final String languageKey = locale.getLanguage();
+ if (sLocaleToTextsTableMap.containsKey(languageKey)) {
+ return sLocaleToTextsTableMap.get(languageKey);
+ }
+ return TEXTS_DEFAULT;
}
private static final String[] NAMES = {
@@ -85,16 +93,14 @@ public final class KeyboardTextsTable {
private static final String EMPTY = "";
/* Default texts */
- private static final String[] LANGUAGE_DEFAULT = {
+ private static final String[] TEXTS_DEFAULT = {
/* @DEFAULT_TEXTS@ */
};
/* @TEXTS@ */
- // TODO: Use the language + "_" + region representation for the locale string key.
- // Currently we are dropping the region from the key.
- private static final Object[] LANGUAGES_AND_TEXTS = {
+ private static final Object[] LOCALES_AND_TEXTS = {
// "locale", TEXT_ARRAY, /* numberOfNonNullText/lengthOf_TEXT_ARRAY localeName */
- /* @LANGUAGES_AND_TEXTS@ */
+ /* @LOCALES_AND_TEXTS@ */
};
static {
@@ -102,11 +108,11 @@ public final class KeyboardTextsTable {
sNameToIndexesMap.put(NAMES[index], index);
}
- for (int i = 0; i < LANGUAGES_AND_TEXTS.length; i += 2) {
- final String language = (String)LANGUAGES_AND_TEXTS[i];
- final String[] textsTable = (String[])LANGUAGES_AND_TEXTS[i + 1];
- sLanguageToTextsTableMap.put(language, textsTable);
- sTextsTableToLanguageMap.put(textsTable, language);
+ for (int i = 0; i < LOCALES_AND_TEXTS.length; i += 2) {
+ final String locale = (String)LOCALES_AND_TEXTS[i];
+ final String[] textsTable = (String[])LOCALES_AND_TEXTS[i + 1];
+ sLocaleToTextsTableMap.put(locale, textsTable);
+ sTextsTableToLocaleMap.put(textsTable, locale);
}
}
}
diff --git a/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/JarUtils.java b/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/JarUtils.java
index a74096e79..b892df236 100644
--- a/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/JarUtils.java
+++ b/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/JarUtils.java
@@ -16,6 +16,7 @@
package com.android.inputmethod.keyboard.tools;
+import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
@@ -58,7 +59,7 @@ public final class JarUtils {
public boolean accept(String dirName, String name);
}
- public static ArrayList<String> getNameListing(final JarFile jar, final JarFilter filter) {
+ public static ArrayList<String> getEntryNameListing(final JarFile jar, final JarFilter filter) {
final ArrayList<String> result = new ArrayList<String>();
final Enumeration<JarEntry> entries = jar.entries();
while (entries.hasMoreElements()) {
@@ -74,12 +75,42 @@ public final class JarUtils {
return result;
}
- public static ArrayList<String> getNameListing(final JarFile jar, final String filterName) {
- return getNameListing(jar, new JarFilter() {
+ public static ArrayList<String> getEntryNameListing(final JarFile jar,
+ final String filterName) {
+ return getEntryNameListing(jar, new JarFilter() {
@Override
public boolean accept(final String dirName, final String name) {
return name.equals(filterName);
}
});
}
+
+ // The locale is taken from string resource jar entry name (values-<locale>/)
+ // or {@link LocaleUtils#DEFAULT_LOCALE_KEY} for the default string resource
+ // directory (values/).
+ public static String getLocaleFromEntryName(final String jarEntryName) {
+ final String dirName = jarEntryName.substring(0, jarEntryName.lastIndexOf('/'));
+ final int pos = dirName.lastIndexOf('/');
+ final String parentName = (pos >= 0) ? dirName.substring(pos + 1) : dirName;
+ final int localePos = parentName.indexOf('-');
+ if (localePos < 0) {
+ // Default resource name.
+ return LocaleUtils.DEFAULT_LOCALE_KEY;
+ }
+ final String locale = parentName.substring(localePos + 1);
+ final int regionPos = locale.indexOf("-r");
+ if (regionPos < 0) {
+ return locale;
+ }
+ return locale.replace("-r", "_");
+ }
+
+ public static void close(final Closeable stream) {
+ try {
+ if (stream != null) {
+ stream.close();
+ }
+ } catch (IOException e) {
+ }
+ }
}
diff --git a/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/LocaleUtils.java b/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/LocaleUtils.java
index 9fdc1f607..d0f8b4292 100644
--- a/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/LocaleUtils.java
+++ b/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/LocaleUtils.java
@@ -26,6 +26,10 @@ import java.util.Locale;
* for the make-keyboard-text tool.
*/
public final class LocaleUtils {
+ public static final String DEFAULT_LOCALE_KEY = "DEFAULT";
+ public static final String NO_LANGUAGE_LOCALE_CODE = "zz";
+ public static final String NO_LANGUAGE_LOCALE_DISPLAY_NAME = "Alphabet";
+
private LocaleUtils() {
// Intentional empty constructor for utility class.
}
@@ -44,7 +48,8 @@ public final class LocaleUtils {
if (retval != null) {
return retval;
}
- String[] localeParams = localeStr.split("_", 3);
+ final String[] localeParams = localeStr.split("_", 3);
+ // TODO: Use JDK 7 Locale.Builder to handle a script name.
if (localeParams.length == 1) {
retval = new Locale(localeParams[0]);
} else if (localeParams.length == 2) {
@@ -58,4 +63,12 @@ public final class LocaleUtils {
return retval;
}
}
+
+ public static String getLocaleDisplayName(final String localeString) {
+ if (localeString.equals(NO_LANGUAGE_LOCALE_CODE)) {
+ return NO_LANGUAGE_LOCALE_DISPLAY_NAME;
+ }
+ final Locale locale = constructLocaleFromString(localeString);
+ return locale.getDisplayName(Locale.ENGLISH);
+ }
}
diff --git a/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/MoreKeysResources.java b/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/MoreKeysResources.java
index 9bb2b38dd..c1a9753cc 100644
--- a/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/MoreKeysResources.java
+++ b/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/MoreKeysResources.java
@@ -16,10 +16,8 @@
package com.android.inputmethod.keyboard.tools;
-import java.io.Closeable;
import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.PrintStream;
@@ -27,7 +25,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
-import java.util.Locale;
+import java.util.TreeMap;
import java.util.jar.JarFile;
public class MoreKeysResources {
@@ -37,21 +35,15 @@ public class MoreKeysResources {
private static final String MARK_NAMES = "@NAMES@";
private static final String MARK_DEFAULT_TEXTS = "@DEFAULT_TEXTS@";
private static final String MARK_TEXTS = "@TEXTS@";
- private static final String MARK_LANGUAGES_AND_TEXTS = "@LANGUAGES_AND_TEXTS@";
- private static final String DEFAULT_LANGUAGE_NAME = "DEFAULT";
+ private static final String TEXTS_ARRAY_NAME_PREFIX = "TEXTS_";
+ private static final String MARK_LOCALES_AND_TEXTS = "@LOCALES_AND_TEXTS@";
private static final String EMPTY_STRING_VAR = "EMPTY";
- private static final String NO_LANGUAGE_CODE = "zz";
- private static final String NO_LANGUAGE_DISPLAY_NAME = "Alphabet";
-
private final JarFile mJar;
- // Language to string resources map.
- private final HashMap<String, StringResourceMap> mResourcesMap =
- new HashMap<String, StringResourceMap>();
- // Sorted languages list. The language is taken from string resource directories
- // (values-<language>/) or {@link #DEFAULT_LANGUAGE_NAME} for the default string resource
- // directory (values/).
- private final ArrayList<String> mSortedLanguagesList = new ArrayList<String>();
+ // String resources maps sorted by its language. The language is determined from the jar entry
+ // name by calling {@link JarUtils#getLocaleFromEntryName(String)}.
+ private final TreeMap<String, StringResourceMap> mResourcesMap =
+ new TreeMap<String, StringResourceMap>();
// Default string resources map.
private final StringResourceMap mDefaultResourceMap;
// Histogram of string resource names. This is used to sort {@link #mSortedResourceNames}.
@@ -64,22 +56,13 @@ public class MoreKeysResources {
public MoreKeysResources(final JarFile jar) {
mJar = jar;
- final ArrayList<String> resources = JarUtils.getNameListing(jar, TEXT_RESOURCE_NAME);
- for (final String name : resources) {
- final String dirName = name.substring(0, name.lastIndexOf('/'));
- final int pos = dirName.lastIndexOf('/');
- final String parentName = (pos >= 0) ? dirName.substring(pos + 1) : dirName;
- final String language = getLanguageFromResDir(parentName);
- final InputStream stream = JarUtils.openResource(name);
- try {
- mResourcesMap.put(language, new StringResourceMap(stream));
- } finally {
- close(stream);
- }
+ final ArrayList<String> resourceEntryNames = JarUtils.getEntryNameListing(
+ jar, TEXT_RESOURCE_NAME);
+ for (final String entryName : resourceEntryNames) {
+ final StringResourceMap resMap = new StringResourceMap(entryName);
+ mResourcesMap.put(resMap.mLocale, resMap);
}
- mDefaultResourceMap = mResourcesMap.get(DEFAULT_LANGUAGE_NAME);
- mSortedLanguagesList.addAll(mResourcesMap.keySet());
- Collections.sort(mSortedLanguagesList);
+ mDefaultResourceMap = mResourcesMap.get(LocaleUtils.DEFAULT_LOCALE_KEY);
// Initialize name histogram and names list.
final HashMap<String, Integer> nameHistogram = mNameHistogram;
@@ -89,12 +72,12 @@ public class MoreKeysResources {
resourceNamesList.add(res.mName);
}
// Make name histogram.
- for (final String language : mResourcesMap.keySet()) {
- final StringResourceMap resMap = mResourcesMap.get(language);
+ for (final String locale : mResourcesMap.keySet()) {
+ final StringResourceMap resMap = mResourcesMap.get(locale);
if (resMap == mDefaultResourceMap) continue;
for (final StringResource res : resMap.getResources()) {
if (!mDefaultResourceMap.contains(res.mName)) {
- throw new RuntimeException(res.mName + " in " + language
+ throw new RuntimeException(res.mName + " in " + locale
+ " doesn't have default resource");
}
final int histogramValue = nameHistogram.get(res.mName);
@@ -118,22 +101,8 @@ public class MoreKeysResources {
mSortedResourceNames = resourceNamesList.toArray(new String[resourceNamesList.size()]);
}
- private static String getLanguageFromResDir(final String dirName) {
- final int languagePos = dirName.indexOf('-');
- if (languagePos < 0) {
- // Default resource.
- return DEFAULT_LANGUAGE_NAME;
- }
- final String language = dirName.substring(languagePos + 1);
- final int countryPos = language.indexOf("-r");
- if (countryPos < 0) {
- return language;
- }
- return language.replace("-r", "_");
- }
-
public void writeToJava(final String outDir) {
- final ArrayList<String> list = JarUtils.getNameListing(mJar, JAVA_TEMPLATE);
+ final ArrayList<String> list = JarUtils.getEntryNameListing(mJar, JAVA_TEMPLATE);
if (list.isEmpty()) {
throw new RuntimeException("Can't find java template " + JAVA_TEMPLATE);
}
@@ -159,8 +128,8 @@ public class MoreKeysResources {
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
- close(lnr);
- close(ps);
+ JarUtils.close(lnr);
+ JarUtils.close(ps);
}
}
@@ -174,8 +143,8 @@ public class MoreKeysResources {
dumpDefaultTexts(out);
} else if (line.contains(MARK_TEXTS)) {
dumpTexts(out);
- } else if (line.contains(MARK_LANGUAGES_AND_TEXTS)) {
- dumpLanguageMap(out);
+ } else if (line.contains(MARK_LOCALES_AND_TEXTS)) {
+ dumpLocalesMap(out);
} else {
out.println(line);
}
@@ -196,16 +165,17 @@ public class MoreKeysResources {
mDefaultResourceMap.setOutputArraySize(outputArraySize);
}
- private static String getArrayNameForLanguage(final String language) {
- return "LANGUAGE_" + language;
+ private static String getArrayNameForLocale(final String locale) {
+ return TEXTS_ARRAY_NAME_PREFIX + locale;
}
private void dumpTexts(final PrintStream out) {
- for (final String language : mSortedLanguagesList) {
- final StringResourceMap resMap = mResourcesMap.get(language);
+ for (final StringResourceMap resMap : mResourcesMap.values()) {
+ final String locale = resMap.mLocale;
if (resMap == mDefaultResourceMap) continue;
- out.format(" /* Language %s: %s */\n", language, getLanguageDisplayName(language));
- out.format(" private static final String[] " + getArrayNameForLanguage(language)
+ out.format(" /* Locale %s: %s */\n",
+ locale, LocaleUtils.getLocaleDisplayName(locale));
+ out.format(" private static final String[] " + getArrayNameForLocale(locale)
+ " = {\n");
final int outputArraySize = dumpTextsInternal(out, resMap);
resMap.setOutputArraySize(outputArraySize);
@@ -213,28 +183,19 @@ public class MoreKeysResources {
}
}
- private void dumpLanguageMap(final PrintStream out) {
- for (final String language : mSortedLanguagesList) {
- final StringResourceMap resMap = mResourcesMap.get(language);
- final Locale locale = LocaleUtils.constructLocaleFromString(language);
- final String languageKeyToDump = locale.getCountry().isEmpty()
- ? String.format("\"%s\"", language)
- : String.format("\"%s\"", locale.getLanguage());
- out.format(" %s, %-15s /* %3d/%3d %s */\n",
- languageKeyToDump, getArrayNameForLanguage(language) + ",",
+ private void dumpLocalesMap(final PrintStream out) {
+ for (final StringResourceMap resMap : mResourcesMap.values()) {
+ final String locale = resMap.mLocale;
+ final String localeToDump = locale.equals(LocaleUtils.DEFAULT_LOCALE_KEY)
+ ? String.format("\"%s\"", locale)
+ : String.format("\"%s\"%s", locale, " ".substring(locale.length()));
+ out.format(" %s, %-12s /* %3d/%3d %s */\n",
+ localeToDump, getArrayNameForLocale(locale) + ",",
resMap.getResources().size(), resMap.getOutputArraySize(),
- getLanguageDisplayName(language));
+ LocaleUtils.getLocaleDisplayName(locale));
}
}
- private static String getLanguageDisplayName(final String language) {
- final Locale locale = LocaleUtils.constructLocaleFromString(language);
- if (locale.getLanguage().equals(NO_LANGUAGE_CODE)) {
- return NO_LANGUAGE_DISPLAY_NAME;
- }
- return locale.getDisplayName(Locale.ENGLISH);
- }
-
private int dumpTextsInternal(final PrintStream out, final StringResourceMap resMap) {
final ArrayInitializerFormatter formatter =
new ArrayInitializerFormatter(out, 100, " ", mSortedResourceNames);
@@ -289,13 +250,4 @@ public class MoreKeysResources {
}
return sb.toString();
}
-
- private static void close(final Closeable stream) {
- try {
- if (stream != null) {
- stream.close();
- }
- } catch (IOException e) {
- }
- }
}
diff --git a/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/StringResourceMap.java b/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/StringResourceMap.java
index 4eff8a24b..d7e76ad77 100644
--- a/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/StringResourceMap.java
+++ b/tools/make-keyboard-text/src/com/android/inputmethod/keyboard/tools/StringResourceMap.java
@@ -34,6 +34,8 @@ import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
public class StringResourceMap {
+ // Locale name.
+ public final String mLocale;
// String resource list.
private final List<StringResource> mResources;
// Name to string resource map.
@@ -42,25 +44,31 @@ public class StringResourceMap {
// The length of String[] that is created from this {@link StringResourceMap}. The length is
// calculated in {@link MoreKeysResources#dumpTexts(OutputStream)} and recorded by
// {@link #setOutputArraySize(int)}. The recorded length is used as a part of comment by
- // {@link MoreKeysResources#dumpLanguageMap(OutputStream)} via {@link #getOutputArraySize()}.
+ // {@link MoreKeysResources#dumpLocaleMap(OutputStream)} via {@link #getOutputArraySize()}.
private int mOutputArraySize;
- public StringResourceMap(final InputStream is) {
+ public StringResourceMap(final String jarEntryName) {
+ mLocale = JarUtils.getLocaleFromEntryName(jarEntryName);
final StringResourceHandler handler = new StringResourceHandler();
final SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
+ final InputStream stream = JarUtils.openResource(jarEntryName);
try {
final SAXParser parser = factory.newSAXParser();
// In order to get comment tag.
parser.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
- parser.parse(is, handler);
+ parser.parse(stream, handler);
} catch (ParserConfigurationException e) {
+ throw new RuntimeException(e.getMessage(), e);
} catch (SAXParseException e) {
throw new RuntimeException(e.getMessage() + " at line " + e.getLineNumber()
- + ", column " + e.getColumnNumber());
+ + ", column " + e.getColumnNumber(), e);
} catch (SAXException e) {
- throw new RuntimeException(e.getMessage());
+ throw new RuntimeException(e.getMessage(), e);
} catch (IOException e) {
+ throw new RuntimeException(e.getMessage(), e);
+ } finally {
+ JarUtils.close(stream);
}
mResources = Collections.unmodifiableList(handler.mResources);