Change the flags to a boolean in constructors.

Change-Id: I9939204f3b16346aaebd4d726315ba9c4faf910a
main
Jean Chalard 2012-04-06 19:12:05 +09:00
parent aa8df59914
commit 24aee9100e
4 changed files with 30 additions and 39 deletions

View File

@ -64,7 +64,7 @@ public class BinaryDictionary extends Dictionary {
// FULL_EDIT_DISTANCE is a flag that forces the dictionary to use full words
// when computing edit distance, instead of the default behavior of stopping
// the evaluation at the size the user typed.
public static final Flag FLAG_USE_FULL_EDIT_DISTANCE = new Flag(0x2);
public static final int FLAG_USE_FULL_EDIT_DISTANCE = 0x2;
// Can create a new flag from extravalue :
// public static final Flag FLAG_MYFLAG =
@ -85,7 +85,7 @@ public class BinaryDictionary extends Dictionary {
FLAG_REQUIRES_FRENCH_LIGATURES_PROCESSING,
};
private int mFlags = 0;
private final int mFlags;
/**
* Constructor for the binary dictionary. This is supposed to be called from the
@ -95,26 +95,20 @@ public class BinaryDictionary extends Dictionary {
* @param filename the name of the file to read through native code.
* @param offset the offset of the dictionary data within the file.
* @param length the length of the binary data.
* @param flagArray the flags to limit the dictionary to, or null for default.
* @param useFullEditDistance whether to use the full edit distance in suggestions
*/
public BinaryDictionary(final Context context,
final String filename, final long offset, final long length, final Flag[] flagArray,
Locale locale) {
final String filename, final long offset, final long length,
final boolean useFullEditDistance, final Locale locale) {
// Note: at the moment a binary dictionary is always of the "main" type.
// Initializing this here will help transitioning out of the scheme where
// the Suggest class knows everything about every single dictionary.
mDicTypeId = Suggest.DIC_MAIN;
// TODO: Stop relying on the state of SubtypeSwitcher, get it as a parameter
final RunInLocale<Void> job = new RunInLocale<Void>() {
@Override
protected Void job(Resources res) {
// TODO: remove this when all flags are moved to the native code
mFlags = Flag.initFlags(null == flagArray ? ALL_CONFIG_FLAGS : flagArray, context,
SubtypeSwitcher.getInstance());
return null;
}
};
job.runInLocale(context.getResources(), locale);
if (useFullEditDistance) {
mFlags = FLAG_USE_FULL_EDIT_DISTANCE;
} else {
mFlags = 0;
}
loadDictionary(filename, offset, length);
}

View File

@ -43,11 +43,11 @@ public class DictionaryFactory {
* @param context application context for reading resources
* @param locale the locale for which to create the dictionary
* @param fallbackResId the id of the resource to use as a fallback if no pack is found
* @param flagArray an array of flags to use
* @param useFullEditDistance whether to use the full edit distance in suggestions
* @return an initialized instance of DictionaryCollection
*/
public static DictionaryCollection createDictionaryFromManager(final Context context,
final Locale locale, final int fallbackResId, final Flag[] flagArray) {
final Locale locale, final int fallbackResId, final boolean useFullEditDistance) {
if (null == locale) {
Log.e(TAG, "No locale defined for dictionary");
return new DictionaryCollection(createBinaryDictionary(context, fallbackResId, locale));
@ -59,8 +59,8 @@ public class DictionaryFactory {
if (null != assetFileList) {
for (final AssetFileAddress f : assetFileList) {
final BinaryDictionary binaryDictionary =
new BinaryDictionary(context, f.mFilename, f.mOffset, f.mLength, flagArray,
locale);
new BinaryDictionary(context, f.mFilename, f.mOffset, f.mLength,
useFullEditDistance, locale);
if (binaryDictionary.isValidDictionary()) {
dictList.add(binaryDictionary);
}
@ -86,7 +86,8 @@ public class DictionaryFactory {
*/
public static DictionaryCollection createDictionaryFromManager(final Context context,
final Locale locale, final int fallbackResId) {
return createDictionaryFromManager(context, locale, fallbackResId, null);
return createDictionaryFromManager(context, locale, fallbackResId,
false /* useFullEditDistance */);
}
/**
@ -119,8 +120,8 @@ public class DictionaryFactory {
Log.e(TAG, "sourceDir is not a file: " + sourceDir);
return null;
}
return new BinaryDictionary(context,
sourceDir, afd.getStartOffset(), afd.getLength(), null, locale);
return new BinaryDictionary(context, sourceDir, afd.getStartOffset(), afd.getLength(),
false /* useFullEditDistance */, locale);
} catch (android.content.res.Resources.NotFoundException e) {
Log.e(TAG, "Could not find the resource. resId=" + resId);
return null;
@ -141,14 +142,14 @@ public class DictionaryFactory {
* @param dictionary the file to read
* @param startOffset the offset in the file where the data starts
* @param length the length of the data
* @param flagArray the flags to use with this data for testing
* @param useFullEditDistance whether to use the full edit distance in suggestions
* @return the created dictionary, or null.
*/
public static Dictionary createDictionaryForTest(Context context, File dictionary,
long startOffset, long length, Flag[] flagArray, Locale locale) {
long startOffset, long length, final boolean useFullEditDistance, Locale locale) {
if (dictionary.isFile()) {
return new BinaryDictionary(context, dictionary.getAbsolutePath(), startOffset, length,
flagArray, locale);
useFullEditDistance, locale);
} else {
Log.e(TAG, "Could not find the file. path=" + dictionary.getAbsolutePath());
return null;

View File

@ -108,11 +108,18 @@ public class Suggest implements Dictionary.WordCallback {
initAsynchronously(context, dictionaryResId, locale);
}
// TODO: remove when the tests are updated
/* package for test */ Suggest(final Context context, final File dictionary,
final long startOffset, final long length, final Flag[] flagArray,
final Locale locale) {
initSynchronously(context, DictionaryFactory.createDictionaryForTest(context, dictionary,
startOffset, length, flagArray, locale), locale);
startOffset, length /* useFullEditDistance */, false, locale), locale);
}
/* package for test */ Suggest(final Context context, final File dictionary,
final long startOffset, final long length, final Locale locale) {
initSynchronously(context, DictionaryFactory.createDictionaryForTest(context, dictionary,
startOffset, length /* useFullEditDistance */, false, locale), locale);
}
private void initWhitelistAndAutocorrectAndPool(final Context context, final Locale locale) {

View File

@ -68,17 +68,6 @@ public class AndroidSpellCheckerService extends SpellCheckerService
private static final int CAPITALIZE_ALL = 2; // All caps
private final static String[] EMPTY_STRING_ARRAY = new String[0];
private final static Flag[] USE_FULL_EDIT_DISTANCE_FLAG_ARRAY;
static {
// See BinaryDictionary.java for an explanation of these flags
// Specifially, ALL_CONFIG_FLAGS means that we want to consider all flags with the
// current dictionary configuration - for example, consider the UMLAUT flag
// so that it will be turned on for German dictionaries and off for others.
USE_FULL_EDIT_DISTANCE_FLAG_ARRAY = Arrays.copyOf(BinaryDictionary.ALL_CONFIG_FLAGS,
BinaryDictionary.ALL_CONFIG_FLAGS.length + 1);
USE_FULL_EDIT_DISTANCE_FLAG_ARRAY[BinaryDictionary.ALL_CONFIG_FLAGS.length] =
BinaryDictionary.FLAG_USE_FULL_EDIT_DISTANCE;
}
private Map<String, DictionaryPool> mDictionaryPools =
Collections.synchronizedMap(new TreeMap<String, DictionaryPool>());
private Map<String, Dictionary> mUserDictionaries =
@ -402,7 +391,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService
final int fallbackResourceId = DictionaryFactory.getMainDictionaryResourceId(resources);
final DictionaryCollection dictionaryCollection =
DictionaryFactory.createDictionaryFromManager(this, locale, fallbackResourceId,
USE_FULL_EDIT_DISTANCE_FLAG_ARRAY);
true /* useFullEditDistance */);
final String localeStr = locale.toString();
Dictionary userDictionary = mUserDictionaries.get(localeStr);
if (null == userDictionary) {