diff options
Diffstat (limited to 'java/src/com/android/inputmethod')
12 files changed, 145 insertions, 189 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java index cb4663777..accfaedcb 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java @@ -78,10 +78,10 @@ public final class KeySpecParser { * or has no key specifications. */ public static String[] splitKeySpecs(final String text) { - final int size = text.length(); - if (size == 0) { + if (TextUtils.isEmpty(text)) { return null; } + final int size = text.length(); // Optimization for one-letter key specification. if (size == 1) { return text.charAt(0) == COMMA ? null : new String[] { text }; @@ -380,6 +380,9 @@ public final class KeySpecParser { public static String resolveTextReference(final String rawText, final KeyboardTextsSet textsSet) { + if (TextUtils.isEmpty(rawText)) { + return null; + } int level = 0; String text = rawText; StringBuilder sb; @@ -392,7 +395,7 @@ public final class KeySpecParser { final int prefixLen = PREFIX_TEXT.length(); final int size = text.length(); if (size < prefixLen) { - return text; + return TextUtils.isEmpty(text) ? null : text; } sb = null; @@ -421,7 +424,7 @@ public final class KeySpecParser { text = sb.toString(); } } while (sb != null); - return text; + return TextUtils.isEmpty(text) ? null : text; } private static int searchTextNameEnd(final String text, final int start) { diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java index 1ea4d3ac7..36a12addd 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java @@ -208,8 +208,8 @@ public final class KeyboardTextsSet { /* 103 */ "keylabel_for_symbols_question", /* 104 */ "keylabel_for_symbols_semicolon", /* 105 */ "keylabel_for_symbols_percent", - /* 106 */ "more_keys_for_symbols_exclamation", - /* 107 */ "more_keys_for_symbols_question", + /* 106 */ "more_keys_for_exclamation", + /* 107 */ "more_keys_for_question", /* 108 */ "more_keys_for_symbols_semicolon", /* 109 */ "more_keys_for_symbols_percent", /* 110 */ "keylabel_for_tablet_comma", @@ -217,47 +217,44 @@ public final class KeyboardTextsSet { /* 112 */ "more_keys_for_tablet_comma", /* 113 */ "keyhintlabel_for_period", /* 114 */ "more_keys_for_period", - /* 115 */ "keylabel_for_apostrophe", - /* 116 */ "keyhintlabel_for_apostrophe", - /* 117 */ "more_keys_for_apostrophe", - /* 118 */ "more_keys_for_q", - /* 119 */ "more_keys_for_x", - /* 120 */ "keylabel_for_q", - /* 121 */ "keylabel_for_w", - /* 122 */ "keylabel_for_y", - /* 123 */ "keylabel_for_x", - /* 124 */ "keylabel_for_spanish_row2_10", - /* 125 */ "more_keys_for_am_pm", - /* 126 */ "settings_as_more_key", - /* 127 */ "shortcut_as_more_key", - /* 128 */ "action_next_as_more_key", - /* 129 */ "action_previous_as_more_key", - /* 130 */ "label_to_more_symbol_key", - /* 131 */ "label_to_more_symbol_for_tablet_key", - /* 132 */ "label_tab_key", - /* 133 */ "label_to_phone_numeric_key", - /* 134 */ "label_to_phone_symbols_key", - /* 135 */ "label_time_am", - /* 136 */ "label_time_pm", - /* 137 */ "keylabel_for_popular_domain", - /* 138 */ "more_keys_for_popular_domain", - /* 139 */ "more_keys_for_smiley", - /* 140 */ "single_laqm_raqm", - /* 141 */ "single_laqm_raqm_rtl", - /* 142 */ "single_raqm_laqm", - /* 143 */ "double_laqm_raqm", - /* 144 */ "double_laqm_raqm_rtl", - /* 145 */ "double_raqm_laqm", - /* 146 */ "single_lqm_rqm", - /* 147 */ "single_9qm_lqm", - /* 148 */ "single_9qm_rqm", - /* 149 */ "double_lqm_rqm", - /* 150 */ "double_9qm_lqm", - /* 151 */ "double_9qm_rqm", - /* 152 */ "more_keys_for_single_quote", - /* 153 */ "more_keys_for_double_quote", - /* 154 */ "more_keys_for_tablet_double_quote", - /* 155 */ "emoji_key_as_more_key", + /* 115 */ "more_keys_for_q", + /* 116 */ "more_keys_for_x", + /* 117 */ "keylabel_for_q", + /* 118 */ "keylabel_for_w", + /* 119 */ "keylabel_for_y", + /* 120 */ "keylabel_for_x", + /* 121 */ "keylabel_for_spanish_row2_10", + /* 122 */ "more_keys_for_am_pm", + /* 123 */ "settings_as_more_key", + /* 124 */ "shortcut_as_more_key", + /* 125 */ "action_next_as_more_key", + /* 126 */ "action_previous_as_more_key", + /* 127 */ "label_to_more_symbol_key", + /* 128 */ "label_to_more_symbol_for_tablet_key", + /* 129 */ "label_tab_key", + /* 130 */ "label_to_phone_numeric_key", + /* 131 */ "label_to_phone_symbols_key", + /* 132 */ "label_time_am", + /* 133 */ "label_time_pm", + /* 134 */ "keylabel_for_popular_domain", + /* 135 */ "more_keys_for_popular_domain", + /* 136 */ "more_keys_for_smiley", + /* 137 */ "single_laqm_raqm", + /* 138 */ "single_laqm_raqm_rtl", + /* 139 */ "single_raqm_laqm", + /* 140 */ "double_laqm_raqm", + /* 141 */ "double_laqm_raqm_rtl", + /* 142 */ "double_raqm_laqm", + /* 143 */ "single_lqm_rqm", + /* 144 */ "single_9qm_lqm", + /* 145 */ "single_9qm_rqm", + /* 146 */ "double_lqm_rqm", + /* 147 */ "double_9qm_lqm", + /* 148 */ "double_9qm_rqm", + /* 149 */ "more_keys_for_single_quote", + /* 150 */ "more_keys_for_double_quote", + /* 151 */ "more_keys_for_tablet_double_quote", + /* 152 */ "emoji_key_as_more_key", }; private static final String EMPTY = ""; @@ -372,41 +369,38 @@ public final class KeyboardTextsSet { /* ~113 */ // U+2026: "…" HORIZONTAL ELLIPSIS /* 114 */ "\u2026", - /* 115 */ "\'", - /* 116 */ "\"", - /* 117 */ "\"", - /* 118 */ EMPTY, - /* 119 */ EMPTY, - /* 120 */ "q", - /* 121 */ "w", - /* 122 */ "y", - /* 123 */ "x", - /* 124 */ EMPTY, - /* 125 */ "!fixedColumnOrder!2,!hasLabels!,!text/label_time_am,!text/label_time_pm", - /* 126 */ "!icon/settings_key|!code/key_settings", - /* 127 */ "!icon/shortcut_key|!code/key_shortcut", - /* 128 */ "!hasLabels!,!text/label_next_key|!code/key_action_next", - /* 129 */ "!hasLabels!,!text/label_previous_key|!code/key_action_previous", + /* 115 */ EMPTY, + /* 116 */ EMPTY, + /* 117 */ "q", + /* 118 */ "w", + /* 119 */ "y", + /* 120 */ "x", + /* 121 */ EMPTY, + /* 122 */ "!fixedColumnOrder!2,!hasLabels!,!text/label_time_am,!text/label_time_pm", + /* 123 */ "!icon/settings_key|!code/key_settings", + /* 124 */ "!icon/shortcut_key|!code/key_shortcut", + /* 125 */ "!hasLabels!,!text/label_next_key|!code/key_action_next", + /* 126 */ "!hasLabels!,!text/label_previous_key|!code/key_action_previous", // Label for "switch to more symbol" modifier key. Must be short to fit on key! - /* 130 */ "= \\ <", + /* 127 */ "= \\ <", // Label for "switch to more symbol" modifier key on tablets. Must be short to fit on key! - /* 131 */ "~ [ <", + /* 128 */ "~ [ <", // Label for "Tab" key. Must be short to fit on key! - /* 132 */ "Tab", + /* 129 */ "Tab", // Label for "switch to phone numeric" key. Must be short to fit on key! - /* 133 */ "123", + /* 130 */ "123", // Label for "switch to phone symbols" key. Must be short to fit on key! // U+FF0A: "*" FULLWIDTH ASTERISK // U+FF03: "#" FULLWIDTH NUMBER SIGN - /* 134 */ "\uFF0A\uFF03", + /* 131 */ "\uFF0A\uFF03", // Key label for "ante meridiem" - /* 135 */ "AM", + /* 132 */ "AM", // Key label for "post meridiem" - /* 136 */ "PM", - /* 137 */ ".com", + /* 133 */ "PM", + /* 134 */ ".com", // popular web domains for the locale - most popular, displayed on the keyboard - /* 138 */ "!hasLabels!,.net,.org,.gov,.edu", - /* 139 */ "!fixedColumnOrder!5,!hasLabels!,=-O|=-O ,:-P|:-P ,;-)|;-) ,:-(|:-( ,:-)|:-) ,:-!|:-! ,:-$|:-$ ,B-)|B-) ,:O|:O ,:-*|:-* ,:-D|:-D ,:\'(|:\'( ,:-\\\\|:-\\\\ ,O:-)|O:-) ,:-[|:-[ ", + /* 135 */ "!hasLabels!,.net,.org,.gov,.edu", + /* 136 */ "!fixedColumnOrder!5,!hasLabels!,=-O|=-O ,:-P|:-P ,;-)|;-) ,:-(|:-( ,:-)|:-) ,:-!|:-! ,:-$|:-$ ,B-)|B-) ,:O|:O ,:-*|:-* ,:-D|:-D ,:\'(|:\'( ,:-\\\\|:-\\\\ ,O:-)|O:-) ,:-[|:-[ ", // U+2039: "‹" SINGLE LEFT-POINTING ANGLE QUOTATION MARK // U+203A: "›" SINGLE RIGHT-POINTING ANGLE QUOTATION MARK // U+00AB: "«" LEFT-POINTING DOUBLE ANGLE QUOTATION MARK @@ -428,25 +422,25 @@ public final class KeyboardTextsSet { // The following each quotation mark pair consist of // <opening quotation mark>, <closing quotation mark> // and is named after (single|double)_<opening quotation mark>_<closing quotation mark>. - /* 140 */ "\u2039,\u203A", - /* 141 */ "\u2039|\u203A,\u203A|\u2039", - /* 142 */ "\u203A,\u2039", - /* 143 */ "\u00AB,\u00BB", - /* 144 */ "\u00AB|\u00BB,\u00BB|\u00AB", - /* 145 */ "\u00BB,\u00AB", + /* 137 */ "\u2039,\u203A", + /* 138 */ "\u2039|\u203A,\u203A|\u2039", + /* 139 */ "\u203A,\u2039", + /* 140 */ "\u00AB,\u00BB", + /* 141 */ "\u00AB|\u00BB,\u00BB|\u00AB", + /* 142 */ "\u00BB,\u00AB", // The following each quotation mark triplet consists of // <another quotation mark>, <opening quotation mark>, <closing quotation mark> // and is named after (single|double)_<opening quotation mark>_<closing quotation mark>. - /* 146 */ "\u201A,\u2018,\u2019", - /* 147 */ "\u2019,\u201A,\u2018", - /* 148 */ "\u2018,\u201A,\u2019", - /* 149 */ "\u201E,\u201C,\u201D", - /* 150 */ "\u201D,\u201E,\u201C", - /* 151 */ "\u201C,\u201E,\u201D", - /* 152 */ "!fixedColumnOrder!5,!text/single_quotes,!text/single_angle_quotes", - /* 153 */ "!fixedColumnOrder!5,!text/double_quotes,!text/double_angle_quotes", - /* 154 */ "!fixedColumnOrder!6,!text/double_quotes,!text/single_quotes,!text/double_angle_quotes,!text/single_angle_quotes", - /* 155 */ "!icon/emoji_key|!code/key_emoji", + /* 143 */ "\u201A,\u2018,\u2019", + /* 144 */ "\u2019,\u201A,\u2018", + /* 145 */ "\u2018,\u201A,\u2019", + /* 146 */ "\u201E,\u201C,\u201D", + /* 147 */ "\u201D,\u201E,\u201C", + /* 148 */ "\u201C,\u201E,\u201D", + /* 149 */ "!fixedColumnOrder!5,!text/single_quotes,!text/single_angle_quotes", + /* 150 */ "!fixedColumnOrder!5,!text/double_quotes,!text/double_angle_quotes", + /* 151 */ "!fixedColumnOrder!6,!text/double_quotes,!text/single_quotes,!text/double_angle_quotes,!text/single_angle_quotes", + /* 152 */ "!icon/emoji_key|!code/key_emoji", }; /* Language af: Afrikaans */ @@ -523,9 +517,6 @@ public final class KeyboardTextsSet { /* 56~ */ null, null, null, /* ~58 */ - // U+061F: "؟" ARABIC QUESTION MARK - // U+060C: "،" ARABIC COMMA - // U+061B: "؛" ARABIC SEMICOLON /* 59 */ "!fixedColumnOrder!8,\",\',#,-,:,!,\u060C,\u061F,@,&,\\%,+,\u061B,/,(|),)|(", // U+2605: "★" BLACK STAR // U+066D: "٭" ARABIC FIVE POINTED STAR @@ -614,19 +605,17 @@ public final class KeyboardTextsSet { // U+066A: "٪" ARABIC PERCENT SIGN /* 105 */ "\u066A", /* 106 */ null, - /* 107 */ "?", + // U+00BF: "¿" INVERTED QUESTION MARK + /* 107 */ "?,\u00BF", /* 108 */ ";", // U+2030: "‰" PER MILLE SIGN /* 109 */ "\\%,\u2030", - /* 110~ */ - null, null, null, null, null, - /* ~114 */ + // U+061F: "؟" ARABIC QUESTION MARK // U+060C: "،" ARABIC COMMA // U+061B: "؛" ARABIC SEMICOLON - // U+061F: "؟" ARABIC QUESTION MARK - /* 115 */ "\u060C", - /* 116 */ "\u061F", - /* 117 */ "\u061F,\u061B,!,:,-,/,\',\"", + /* 110 */ "\u060C", + /* 111 */ "\u061F", + /* 112 */ "!fixedColumnOrder!4,:,!,\u061F,\u061B,-,/,\",\'", }; /* Language az: Azerbaijani */ @@ -804,10 +793,10 @@ public final class KeyboardTextsSet { /* ~113 */ /* 114 */ "?,\u00B7", /* 115~ */ - null, null, null, null, null, null, null, null, null, - /* ~123 */ + null, null, null, null, null, null, + /* ~120 */ // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA - /* 124 */ "\u00E7", + /* 121 */ "\u00E7", }; /* Language cs: Czech */ @@ -1206,20 +1195,20 @@ public final class KeyboardTextsSet { null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, - null, null, null, null, null, null, null, null, - /* ~117 */ - /* 118 */ "q", - /* 119 */ "x", + null, null, null, null, null, + /* ~114 */ + /* 115 */ "q", + /* 116 */ "x", // U+015D: "ŝ" LATIN SMALL LETTER S WITH CIRCUMFLEX - /* 120 */ "\u015D", + /* 117 */ "\u015D", // U+011D: "ĝ" LATIN SMALL LETTER G WITH CIRCUMFLEX - /* 121 */ "\u011D", + /* 118 */ "\u011D", // U+016D: "ŭ" LATIN SMALL LETTER U WITH BREVE - /* 122 */ "\u016D", + /* 119 */ "\u016D", // U+0109: "ĉ" LATIN SMALL LETTER C WITH CIRCUMFLEX - /* 123 */ "\u0109", + /* 120 */ "\u0109", // U+0135: "ĵ" LATIN SMALL LETTER J WITH CIRCUMFLEX - /* 124 */ "\u0135", + /* 121 */ "\u0135", }; /* Language es: Spanish */ @@ -1282,26 +1271,16 @@ public final class KeyboardTextsSet { /* ~58 */ // U+00A1: "¡" INVERTED EXCLAMATION MARK // U+00BF: "¿" INVERTED QUESTION MARK - /* 59 */ "!fixedColumnOrder!4,;,!,\\,,?,:,\u00A1,@,\u00BF", + /* 59 */ "!fixedColumnOrder!9,\u00A1,;,/,(,),#,!,\\,,?,\u00BF,&,\\%,+,\",-,:,',@", /* 60~ */ null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, - null, null, null, null, null, null, null, - /* ~111 */ - // U+00A1: "¡" INVERTED EXCLAMATION MARK - /* 112 */ "!,\u00A1", - /* 113 */ null, - // U+00BF: "¿" INVERTED QUESTION MARK - /* 114 */ "?,\u00BF", - /* 115 */ "\"", - /* 116 */ "\'", - /* 117 */ "\'", - /* 118~ */ - null, null, null, null, null, null, - /* ~123 */ + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, + /* ~120 */ // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE - /* 124 */ "\u00F1", + /* 121 */ "\u00F1", }; /* Language et: Estonian */ @@ -1523,7 +1502,8 @@ public final class KeyboardTextsSet { // U+066A: "٪" ARABIC PERCENT SIGN /* 105 */ "\u066A", /* 106 */ null, - /* 107 */ "?", + // U+00BF: "¿" INVERTED QUESTION MARK + /* 107 */ "?,\u00BF", /* 108 */ ";", // U+2030: "‰" PER MILLE SIGN /* 109 */ "\\%,\u2030", @@ -1533,13 +1513,10 @@ public final class KeyboardTextsSet { // U+00AB: "«" LEFT-POINTING DOUBLE ANGLE QUOTATION MARK // U+00BB: "»" RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK /* 110 */ "\u060C", - /* 111 */ "!", - /* 112 */ "!,\\,", + /* 111 */ "\u061F", + /* 112 */ "!fixedColumnOrder!4,:,!,\u061F,\u061B,-,/,\u00AB|\u00BB,\u00BB|\u00AB", /* 113 */ "\u061F", /* 114 */ "\u061F,?", - /* 115 */ "\u060C", - /* 116 */ "\u061F", - /* 117 */ "!fixedColumnOrder!4,:,!,\u061F,\u061B,-,/,\u00AB|\u00BB,\u00BB|\u00AB", }; /* Language fi: Finnish */ diff --git a/java/src/com/android/inputmethod/latin/AbstractDictionaryWriter.java b/java/src/com/android/inputmethod/latin/AbstractDictionaryWriter.java index d034515ca..59d556956 100644 --- a/java/src/com/android/inputmethod/latin/AbstractDictionaryWriter.java +++ b/java/src/com/android/inputmethod/latin/AbstractDictionaryWriter.java @@ -27,15 +27,13 @@ import java.io.File; import java.io.IOException; import java.util.Map; -// TODO: Quit extending Dictionary after implementing dynamic binary dictionary. -abstract public class AbstractDictionaryWriter extends Dictionary { +abstract public class AbstractDictionaryWriter { /** Used for Log actions from this class */ private static final String TAG = AbstractDictionaryWriter.class.getSimpleName(); private final Context mContext; - public AbstractDictionaryWriter(final Context context, final String dictType) { - super(dictType); + public AbstractDictionaryWriter(final Context context) { mContext = context; } diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java index 49a198d1e..db4234c63 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java @@ -135,7 +135,6 @@ public final class BinaryDictionary extends Dictionary { String[] attributeKeyStringArray, String[] attributeValueStringArray); private static native long openNative(String sourceDir, long dictOffset, long dictSize, boolean isUpdatable); - private static native boolean hasValidContentsNative(long dict); private static native void flushNative(long dict, String filePath); private static native boolean needsToRunGCNative(long dict, boolean mindsBlockByGC); private static native void flushWithGCNative(long dict, String filePath); @@ -261,10 +260,6 @@ public final class BinaryDictionary extends Dictionary { return mNativeDict != 0; } - public boolean hasValidContents() { - return hasValidContentsNative(mNativeDict); - } - public int getFormatVersion() { return getFormatVersionNative(mNativeDict); } diff --git a/java/src/com/android/inputmethod/latin/DictionaryFactory.java b/java/src/com/android/inputmethod/latin/DictionaryFactory.java index bcb38da38..e09c309ea 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryFactory.java +++ b/java/src/com/android/inputmethod/latin/DictionaryFactory.java @@ -63,7 +63,7 @@ public final class DictionaryFactory { final ReadOnlyBinaryDictionary readOnlyBinaryDictionary = new ReadOnlyBinaryDictionary(f.mFilename, f.mOffset, f.mLength, useFullEditDistance, locale, Dictionary.TYPE_MAIN); - if (readOnlyBinaryDictionary.hasValidContents()) { + if (readOnlyBinaryDictionary.isValidDictionary()) { dictList.add(readOnlyBinaryDictionary); } else { readOnlyBinaryDictionary.close(); diff --git a/java/src/com/android/inputmethod/latin/DictionaryWriter.java b/java/src/com/android/inputmethod/latin/DictionaryWriter.java index f1a054162..f960c5343 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryWriter.java +++ b/java/src/com/android/inputmethod/latin/DictionaryWriter.java @@ -43,8 +43,8 @@ public class DictionaryWriter extends AbstractDictionaryWriter { private FusionDictionary mFusionDictionary; - public DictionaryWriter(final Context context, final String dictType) { - super(context, dictType); + public DictionaryWriter(final Context context) { + super(context); clear(); } @@ -92,18 +92,4 @@ public class DictionaryWriter extends AbstractDictionaryWriter { } dictEncoder.writeDictionary(mFusionDictionary, FORMAT_OPTIONS); } - - @Override - public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer, - final String prevWord, final ProximityInfo proximityInfo, - boolean blockOffensiveWords, final int[] additionalFeaturesOptions) { - // This class doesn't support suggestion. - return null; - } - - @Override - public boolean isValidWord(String word) { - // This class doesn't support dictionary retrieval. - return false; - } } diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java index f86517d12..41661573d 100644 --- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java @@ -28,7 +28,6 @@ import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.utils.AsyncResultHolder; import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.PrioritizedSerialExecutor; -import com.android.inputmethod.latin.utils.StringUtils; import java.io.File; import java.util.ArrayList; @@ -64,10 +63,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { */ protected static final int MAX_WORD_LENGTH = Constants.DICTIONARY_MAX_WORD_LENGTH; - private static final int DICTIONARY_FORMAT_VERSION = 4; - - private static final String SUPPORTS_DYNAMIC_UPDATE = - FormatSpec.FileHeader.ATTRIBUTE_VALUE_TRUE; + private static final int DICTIONARY_FORMAT_VERSION = FormatSpec.VERSION4; /** * A static map of update controllers, each of which records the time of accesses to a single @@ -135,11 +131,18 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { */ protected abstract boolean hasContentChanged(); - protected boolean isValidBinaryDictFormatVersion(final int formatVersion) { - // TODO: Use ver4 format. + protected boolean matchesExpectedBinaryDictFormatVersionForThisType(final int formatVersion) { + // This class is using format 2 because it's used by the User and Contacts dictionary + // only, which right now use format 2 (dicts using format 4 use Decaying*, which overrides + // this method). + // TODO: Migrate these dicts to ver4 format, and remove this function. return formatVersion == 2; } + public boolean isValidDictionary() { + return mBinaryDictionary.isValidDictionary(); + } + protected String getFileNameExtentionToOpenDict() { return ""; } @@ -174,11 +177,11 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { } private static AbstractDictionaryWriter getDictionaryWriter(final Context context, - final String dictType, final boolean isDynamicPersonalizationDictionary) { + final boolean isDynamicPersonalizationDictionary) { if (isDynamicPersonalizationDictionary) { return null; } else { - return new DictionaryWriter(context, dictType); + return new DictionaryWriter(context); } } @@ -203,7 +206,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { mBinaryDictionary = null; mFilenameDictionaryUpdateController = getDictionaryUpdateController(filename); // Currently, only dynamic personalization dictionary is updatable. - mDictionaryWriter = getDictionaryWriter(context, dictType, isUpdatable); + mDictionaryWriter = getDictionaryWriter(context, isUpdatable); } protected static String getFilenameWithLocale(final String name, final Locale locale) { @@ -222,9 +225,6 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { mBinaryDictionary.close(); mBinaryDictionary = null; } - if (mDictionaryWriter != null) { - mDictionaryWriter.close(); - } } }); } @@ -563,8 +563,10 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { loadDictionaryAsync(); mDictionaryWriter.write(mFilename, getHeaderAttributeMap()); } else { - if (mBinaryDictionary == null || !mBinaryDictionary.isValidDictionary() - || !isValidBinaryDictFormatVersion(mBinaryDictionary.getFormatVersion())) { + if (mBinaryDictionary == null || !isValidDictionary() + // TODO: remove the check below + || !matchesExpectedBinaryDictFormatVersionForThisType( + mBinaryDictionary.getFormatVersion())) { final File file = new File(mContext.getFilesDir(), mFilename); file.delete(); BinaryDictionary.createEmptyDictFile(file.getAbsolutePath(), @@ -662,8 +664,9 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { // load the shared dictionary. loadBinaryDictionary(); } - if (mBinaryDictionary != null && !(mBinaryDictionary.isValidDictionary() - && isValidBinaryDictFormatVersion( + if (mBinaryDictionary != null && !(isValidDictionary() + // TODO: remove the check below + && matchesExpectedBinaryDictFormatVersionForThisType( mBinaryDictionary.getFormatVersion()))) { // Binary dictionary or its format version is not valid. Regenerate the // dictionary file. diff --git a/java/src/com/android/inputmethod/latin/ReadOnlyBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ReadOnlyBinaryDictionary.java index c8e4014bb..68505ce38 100644 --- a/java/src/com/android/inputmethod/latin/ReadOnlyBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/ReadOnlyBinaryDictionary.java @@ -44,15 +44,6 @@ public final class ReadOnlyBinaryDictionary extends Dictionary { locale, dictType, false /* isUpdatable */); } - public boolean hasValidContents() { - mLock.readLock().lock(); - try { - return mBinaryDictionary.hasValidContents(); - } finally { - mLock.readLock().unlock(); - } - } - public boolean isValidDictionary() { return mBinaryDictionary.isValidDictionary(); } diff --git a/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java b/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java index 93ccc62b4..b81c8d8e5 100644 --- a/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java +++ b/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java @@ -204,8 +204,8 @@ public final class FormatSpec { static final int NOT_A_VERSION_NUMBER = -1; static final int FIRST_VERSION_WITH_DYNAMIC_UPDATE = 3; static final int FIRST_VERSION_WITH_TERMINAL_ID = 4; - static final int VERSION3 = 3; - static final int VERSION4 = 4; + public static final int VERSION3 = 3; + public static final int VERSION4 = 4; // These options need to be the same numeric values as the one in the native reading code. static final int GERMAN_UMLAUT_PROCESSING_FLAG = 0x1; diff --git a/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java b/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java index 8833c35aa..2cbec7cec 100644 --- a/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java +++ b/java/src/com/android/inputmethod/latin/makedict/Ver4DictDecoder.java @@ -161,7 +161,7 @@ public class Ver4DictDecoder extends AbstractDictDecoder { } final FileHeader header = super.readHeader(mDictBuffer); final int version = header.mFormatOptions.mVersion; - if (version != 4) { + if (version != FormatSpec.VERSION4) { throw new UnsupportedFormatException("File header has a wrong version : " + version); } return header; diff --git a/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java b/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java index 529ddc257..f9733f725 100644 --- a/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java +++ b/java/src/com/android/inputmethod/latin/personalization/DecayingExpandableBinaryDictionaryBase.java @@ -114,8 +114,10 @@ public abstract class DecayingExpandableBinaryDictionaryBase extends ExpandableB } @Override - protected boolean isValidBinaryDictFormatVersion(final int formatVersion) { - return formatVersion >= REQUIRED_BINARY_DICTIONARY_VERSION; + protected boolean matchesExpectedBinaryDictFormatVersionForThisType(final int formatVersion) { + // This class is using format 4 because it's used by all version 4 dictionaries. + // TODO: remove this when all dynamically generated dicts use version 4. + return formatVersion == REQUIRED_BINARY_DICTIONARY_VERSION; } @Override diff --git a/java/src/com/android/inputmethod/latin/spellcheck/DictionaryPool.java b/java/src/com/android/inputmethod/latin/spellcheck/DictionaryPool.java index a0aed2829..b7a5a4026 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/DictionaryPool.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/DictionaryPool.java @@ -49,6 +49,7 @@ public final class DictionaryPool extends LinkedBlockingQueue<DictAndKeyboard> { final static ArrayList<SuggestedWordInfo> noSuggestions = CollectionUtils.newArrayList(); private final static DictAndKeyboard dummyDict = new DictAndKeyboard( new Dictionary(Dictionary.TYPE_MAIN) { + // TODO: this dummy dictionary should be a singleton in the Dictionary class. @Override public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer, final String prevWord, final ProximityInfo proximityInfo, |