Loading java-overridable/src/com/android/inputmethod/latin/utils/DictionaryHeaderUtils.java 0 → 100644 +31 −0 Original line number Diff line number Diff line /* * 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); } } java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java +11 −16 Original line number Diff line number Diff line Loading @@ -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 = Loading @@ -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, Loading Loading @@ -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. Loading @@ -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. Loading Loading
java-overridable/src/com/android/inputmethod/latin/utils/DictionaryHeaderUtils.java 0 → 100644 +31 −0 Original line number Diff line number Diff line /* * 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); } }
java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java +11 −16 Original line number Diff line number Diff line Loading @@ -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 = Loading @@ -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, Loading Loading @@ -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. Loading @@ -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. Loading