Merge "Add a parameter isUpdatable to the constructor of BinaryDictionary."

main
Keisuke Kuroynagi 2013-06-25 08:44:48 +00:00 committed by Android (Google) Code Review
commit 38b542629a
3 changed files with 12 additions and 8 deletions

View File

@ -78,13 +78,15 @@ public final class BinaryDictionary extends Dictionary {
* @param length the length of the binary data. * @param length the length of the binary data.
* @param useFullEditDistance whether to use the full edit distance in suggestions * @param useFullEditDistance whether to use the full edit distance in suggestions
* @param dictType the dictionary type, as a human-readable string * @param dictType the dictionary type, as a human-readable string
* @param isUpdatable whether to open the dictionary file in writable mode.
*/ */
public BinaryDictionary(final String filename, final long offset, final long length, public BinaryDictionary(final String filename, final long offset, final long length,
final boolean useFullEditDistance, final Locale locale, final String dictType) { final boolean useFullEditDistance, final Locale locale, final String dictType,
final boolean isUpdatable) {
super(dictType); super(dictType);
mLocale = locale; mLocale = locale;
mNativeSuggestOptions.setUseFullEditDistance(useFullEditDistance); mNativeSuggestOptions.setUseFullEditDistance(useFullEditDistance);
loadDictionary(filename, offset, length); loadDictionary(filename, offset, length, isUpdatable);
} }
static { static {
@ -106,8 +108,8 @@ public final class BinaryDictionary extends Dictionary {
// TODO: Move native dict into session // TODO: Move native dict into session
private final void loadDictionary(final String path, final long startOffset, private final void loadDictionary(final String path, final long startOffset,
final long length) { final long length, final boolean isUpdatable) {
mNativeDict = openNative(path, startOffset, length, false /* isUpdatable */); mNativeDict = openNative(path, startOffset, length, isUpdatable);
} }
@Override @Override

View File

@ -60,7 +60,8 @@ public final class DictionaryFactory {
if (null != assetFileList) { if (null != assetFileList) {
for (final AssetFileAddress f : assetFileList) { for (final AssetFileAddress f : assetFileList) {
final BinaryDictionary binaryDictionary = new BinaryDictionary(f.mFilename, final BinaryDictionary binaryDictionary = new BinaryDictionary(f.mFilename,
f.mOffset, f.mLength, useFullEditDistance, locale, Dictionary.TYPE_MAIN); f.mOffset, f.mLength, useFullEditDistance, locale, Dictionary.TYPE_MAIN,
false /* isUpdatable */);
if (binaryDictionary.isValidDictionary()) { if (binaryDictionary.isValidDictionary()) {
dictList.add(binaryDictionary); dictList.add(binaryDictionary);
} }
@ -113,7 +114,8 @@ public final class DictionaryFactory {
return null; return null;
} }
return new BinaryDictionary(sourceDir, afd.getStartOffset(), afd.getLength(), return new BinaryDictionary(sourceDir, afd.getStartOffset(), afd.getLength(),
false /* useFullEditDistance */, locale, Dictionary.TYPE_MAIN); false /* useFullEditDistance */, locale, Dictionary.TYPE_MAIN,
false /* isUpdatable */);
} catch (android.content.res.Resources.NotFoundException e) { } catch (android.content.res.Resources.NotFoundException e) {
Log.e(TAG, "Could not find the resource"); Log.e(TAG, "Could not find the resource");
return null; return null;
@ -142,7 +144,7 @@ public final class DictionaryFactory {
for (final AssetFileAddress address : dictionaryList) { for (final AssetFileAddress address : dictionaryList) {
final BinaryDictionary binaryDictionary = new BinaryDictionary(address.mFilename, final BinaryDictionary binaryDictionary = new BinaryDictionary(address.mFilename,
address.mOffset, address.mLength, useFullEditDistance, locale, address.mOffset, address.mLength, useFullEditDistance, locale,
Dictionary.TYPE_MAIN); Dictionary.TYPE_MAIN, false /* isUpdatable */);
dictionaryCollection.addDictionary(binaryDictionary); dictionaryCollection.addDictionary(binaryDictionary);
} }
return dictionaryCollection; return dictionaryCollection;

View File

@ -286,7 +286,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
// Build the new binary dictionary // Build the new binary dictionary
final BinaryDictionary newBinaryDictionary = new BinaryDictionary(filename, 0, length, final BinaryDictionary newBinaryDictionary = new BinaryDictionary(filename, 0, length,
true /* useFullEditDistance */, null, mDictType); true /* useFullEditDistance */, null, mDictType, false /* isUpdatable */);
if (mBinaryDictionary != null) { if (mBinaryDictionary != null) {
// Ensure all threads accessing the current dictionary have finished before swapping in // Ensure all threads accessing the current dictionary have finished before swapping in