aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMohammadinamul Sheik <inamul@google.com>2015-03-03 16:17:27 -0800
committerMohammadinamul Sheik <inamul@google.com>2015-03-03 16:17:27 -0800
commit6e29d261cb480ef0f0d90867d4582fabce0b9113 (patch)
tree0d5572f1d1bbfb478b3be090031bcbe2dd2d33a0
parent2281ba76668db4343e1d01fff82e031657bfcfd5 (diff)
downloadlatinime-6e29d261cb480ef0f0d90867d4582fabce0b9113.tar.gz
latinime-6e29d261cb480ef0f0d90867d4582fabce0b9113.tar.xz
latinime-6e29d261cb480ef0f0d90867d4582fabce0b9113.zip
Introduce DictionaryHeaderUtils to get dictionary header values
Change-Id: I86cef6c7f2f68a75428bb2b9c4d5a1dc1876b541
-rw-r--r--java-overridable/src/com/android/inputmethod/latin/utils/DictionaryHeaderUtils.java31
-rw-r--r--java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java27
2 files changed, 42 insertions, 16 deletions
diff --git a/java-overridable/src/com/android/inputmethod/latin/utils/DictionaryHeaderUtils.java b/java-overridable/src/com/android/inputmethod/latin/utils/DictionaryHeaderUtils.java
new file mode 100644
index 000000000..5eb613c9b
--- /dev/null
+++ b/java-overridable/src/com/android/inputmethod/latin/utils/DictionaryHeaderUtils.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2015 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 com.android.inputmethod.latin.AssetFileAddress;
+import com.android.inputmethod.latin.makedict.DictionaryHeader;
+
+import java.io.File;
+
+public class DictionaryHeaderUtils {
+
+ public static int getContentVersion(AssetFileAddress fileAddress) {
+ final DictionaryHeader header = DictionaryInfoUtils.getDictionaryFileHeaderOrNull(
+ new File(fileAddress.mFilename), fileAddress.mOffset, fileAddress.mLength);
+ return Integer.parseInt(header.mVersionString);
+ }
+}
diff --git a/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java b/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java
index 3ed6a021e..fd567f49d 100644
--- a/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java
+++ b/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java
@@ -340,7 +340,7 @@ public class DictionaryInfoUtils {
return getDictionaryFileHeaderOrNull(file, 0, file.length());
}
- private static DictionaryHeader getDictionaryFileHeaderOrNull(final File file,
+ public static DictionaryHeader getDictionaryFileHeaderOrNull(final File file,
final long offset, final long length) {
try {
final DictionaryHeader header =
@@ -357,23 +357,17 @@ public class DictionaryInfoUtils {
* Returns information of the dictionary.
*
* @param fileAddress the asset dictionary file address.
+ * @param locale Locale for this file.
* @return information of the specified dictionary.
*/
@Nullable
private static DictionaryInfo createDictionaryInfoFromFileAddress(
- final AssetFileAddress fileAddress) {
- // TODO: Read the header and update the version number for the new dictionaries.
- // This will make sure that the dictionary version is updated in the database.
- final DictionaryHeader header = getDictionaryFileHeaderOrNull(
- new File(fileAddress.mFilename), fileAddress.mOffset, fileAddress.mLength);
- if (header == null) {
- return null;
- }
- final String id = header.mIdString;
- final Locale locale = LocaleUtils.constructLocaleFromString(header.mLocaleString);
- final String description = header.getDescription();
- final String version = header.mVersionString;
- return new DictionaryInfo(id, locale, description, fileAddress, Integer.parseInt(version));
+ final AssetFileAddress fileAddress, Locale locale) {
+ final String id = getMainDictId(locale);
+ final int version = DictionaryHeaderUtils.getContentVersion(fileAddress);
+ final String description = SubtypeLocaleUtils
+ .getSubtypeLocaleDisplayName(locale.toString());
+ return new DictionaryInfo(id, locale, description, fileAddress, version);
}
private static void addOrUpdateDictInfo(final ArrayList<DictionaryInfo> dictList,
@@ -410,7 +404,7 @@ public class DictionaryInfoUtils {
final Locale locale = LocaleUtils.constructLocaleFromString(localeString);
final AssetFileAddress fileAddress = AssetFileAddress.makeFromFile(dict);
final DictionaryInfo dictionaryInfo =
- createDictionaryInfoFromFileAddress(fileAddress);
+ createDictionaryInfoFromFileAddress(fileAddress, locale);
// Protect against cases of a less-specific dictionary being found, like an
// en dictionary being used for an en_US locale. In this case, the en dictionary
// should be used for en_US but discounted for listing purposes.
@@ -435,7 +429,8 @@ public class DictionaryInfoUtils {
}
final AssetFileAddress fileAddress =
BinaryDictionaryGetter.loadFallbackResource(context, resourceId);
- final DictionaryInfo dictionaryInfo = createDictionaryInfoFromFileAddress(fileAddress);
+ final DictionaryInfo dictionaryInfo = createDictionaryInfoFromFileAddress(fileAddress,
+ locale);
// Protect against cases of a less-specific dictionary being found, like an
// en dictionary being used for an en_US locale. In this case, the en dictionary
// should be used for en_US but discounted for listing purposes.