aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2013-12-05 15:14:29 +0900
committerJean Chalard <jchalard@google.com>2013-12-06 13:06:49 +0900
commitb8481456f232e00e0be31dec0b199ee563de75a5 (patch)
treedc3852109a64cb82923ca448ed7dd8bb1138dbd7 /java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
parentf6b479d4825ab194d87f4c1f6713369fe7cafdf7 (diff)
downloadlatinime-b8481456f232e00e0be31dec0b199ee563de75a5.tar.gz
latinime-b8481456f232e00e0be31dec0b199ee563de75a5.tar.xz
latinime-b8481456f232e00e0be31dec0b199ee563de75a5.zip
[RF2] Some refactoring and some cleanup
Bug: 11281748 Change-Id: Iff45fdf6b23f77c08271a169c7d7ca45912c85e8
Diffstat (limited to 'java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java')
-rw-r--r--java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java33
1 files changed, 19 insertions, 14 deletions
diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
index f86517d12..98a18f6d3 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;
@@ -66,9 +65,6 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
private static final int DICTIONARY_FORMAT_VERSION = 4;
- private static final String SUPPORTS_DYNAMIC_UPDATE =
- FormatSpec.FileHeader.ATTRIBUTE_VALUE_TRUE;
-
/**
* A static map of update controllers, each of which records the time of accesses to a single
* binary dictionary file and tracks whether the file is regenerating. The key for this map is
@@ -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 hasValidContents() {
+ return mBinaryDictionary.hasValidContents();
+ }
+
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();
- }
}
});
}
@@ -564,7 +564,10 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
mDictionaryWriter.write(mFilename, getHeaderAttributeMap());
} else {
if (mBinaryDictionary == null || !mBinaryDictionary.isValidDictionary()
- || !isValidBinaryDictFormatVersion(mBinaryDictionary.getFormatVersion())) {
+ || !hasValidContents()
+ // TODO: remove the check below
+ || !matchesExpectedBinaryDictFormatVersionForThisType(
+ mBinaryDictionary.getFormatVersion())) {
final File file = new File(mContext.getFilesDir(), mFilename);
file.delete();
BinaryDictionary.createEmptyDictFile(file.getAbsolutePath(),
@@ -663,7 +666,9 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
loadBinaryDictionary();
}
if (mBinaryDictionary != null && !(mBinaryDictionary.isValidDictionary()
- && isValidBinaryDictFormatVersion(
+ && hasValidContents()
+ // TODO: remove the check below
+ && matchesExpectedBinaryDictFormatVersionForThisType(
mBinaryDictionary.getFormatVersion()))) {
// Binary dictionary or its format version is not valid. Regenerate the
// dictionary file.