mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Change the flags to a boolean in constructors.
Change-Id: I9939204f3b16346aaebd4d726315ba9c4faf910a
This commit is contained in:
parent
aa8df59914
commit
24aee9100e
@ -64,7 +64,7 @@ public class BinaryDictionary extends Dictionary {
|
|||||||
// FULL_EDIT_DISTANCE is a flag that forces the dictionary to use full words
|
// 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
|
// when computing edit distance, instead of the default behavior of stopping
|
||||||
// the evaluation at the size the user typed.
|
// 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 :
|
// Can create a new flag from extravalue :
|
||||||
// public static final Flag FLAG_MYFLAG =
|
// public static final Flag FLAG_MYFLAG =
|
||||||
@ -85,7 +85,7 @@ public class BinaryDictionary extends Dictionary {
|
|||||||
FLAG_REQUIRES_FRENCH_LIGATURES_PROCESSING,
|
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
|
* 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 filename the name of the file to read through native code.
|
||||||
* @param offset the offset of the dictionary data within the file.
|
* @param offset the offset of the dictionary data within the file.
|
||||||
* @param length the length of the binary data.
|
* @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,
|
public BinaryDictionary(final Context context,
|
||||||
final String filename, final long offset, final long length, final Flag[] flagArray,
|
final String filename, final long offset, final long length,
|
||||||
Locale locale) {
|
final boolean useFullEditDistance, final Locale locale) {
|
||||||
// Note: at the moment a binary dictionary is always of the "main" type.
|
// Note: at the moment a binary dictionary is always of the "main" type.
|
||||||
// Initializing this here will help transitioning out of the scheme where
|
// Initializing this here will help transitioning out of the scheme where
|
||||||
// the Suggest class knows everything about every single dictionary.
|
// the Suggest class knows everything about every single dictionary.
|
||||||
mDicTypeId = Suggest.DIC_MAIN;
|
mDicTypeId = Suggest.DIC_MAIN;
|
||||||
// TODO: Stop relying on the state of SubtypeSwitcher, get it as a parameter
|
if (useFullEditDistance) {
|
||||||
final RunInLocale<Void> job = new RunInLocale<Void>() {
|
mFlags = FLAG_USE_FULL_EDIT_DISTANCE;
|
||||||
@Override
|
} else {
|
||||||
protected Void job(Resources res) {
|
mFlags = 0;
|
||||||
// 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);
|
|
||||||
loadDictionary(filename, offset, length);
|
loadDictionary(filename, offset, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,11 +43,11 @@ public class DictionaryFactory {
|
|||||||
* @param context application context for reading resources
|
* @param context application context for reading resources
|
||||||
* @param locale the locale for which to create the dictionary
|
* @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 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
|
* @return an initialized instance of DictionaryCollection
|
||||||
*/
|
*/
|
||||||
public static DictionaryCollection createDictionaryFromManager(final Context context,
|
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) {
|
if (null == locale) {
|
||||||
Log.e(TAG, "No locale defined for dictionary");
|
Log.e(TAG, "No locale defined for dictionary");
|
||||||
return new DictionaryCollection(createBinaryDictionary(context, fallbackResId, locale));
|
return new DictionaryCollection(createBinaryDictionary(context, fallbackResId, locale));
|
||||||
@ -59,8 +59,8 @@ public class DictionaryFactory {
|
|||||||
if (null != assetFileList) {
|
if (null != assetFileList) {
|
||||||
for (final AssetFileAddress f : assetFileList) {
|
for (final AssetFileAddress f : assetFileList) {
|
||||||
final BinaryDictionary binaryDictionary =
|
final BinaryDictionary binaryDictionary =
|
||||||
new BinaryDictionary(context, f.mFilename, f.mOffset, f.mLength, flagArray,
|
new BinaryDictionary(context, f.mFilename, f.mOffset, f.mLength,
|
||||||
locale);
|
useFullEditDistance, locale);
|
||||||
if (binaryDictionary.isValidDictionary()) {
|
if (binaryDictionary.isValidDictionary()) {
|
||||||
dictList.add(binaryDictionary);
|
dictList.add(binaryDictionary);
|
||||||
}
|
}
|
||||||
@ -86,7 +86,8 @@ public class DictionaryFactory {
|
|||||||
*/
|
*/
|
||||||
public static DictionaryCollection createDictionaryFromManager(final Context context,
|
public static DictionaryCollection createDictionaryFromManager(final Context context,
|
||||||
final Locale locale, final int fallbackResId) {
|
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);
|
Log.e(TAG, "sourceDir is not a file: " + sourceDir);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new BinaryDictionary(context,
|
return new BinaryDictionary(context, sourceDir, afd.getStartOffset(), afd.getLength(),
|
||||||
sourceDir, afd.getStartOffset(), afd.getLength(), null, locale);
|
false /* useFullEditDistance */, locale);
|
||||||
} catch (android.content.res.Resources.NotFoundException e) {
|
} catch (android.content.res.Resources.NotFoundException e) {
|
||||||
Log.e(TAG, "Could not find the resource. resId=" + resId);
|
Log.e(TAG, "Could not find the resource. resId=" + resId);
|
||||||
return null;
|
return null;
|
||||||
@ -141,14 +142,14 @@ public class DictionaryFactory {
|
|||||||
* @param dictionary the file to read
|
* @param dictionary the file to read
|
||||||
* @param startOffset the offset in the file where the data starts
|
* @param startOffset the offset in the file where the data starts
|
||||||
* @param length the length of the data
|
* @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.
|
* @return the created dictionary, or null.
|
||||||
*/
|
*/
|
||||||
public static Dictionary createDictionaryForTest(Context context, File dictionary,
|
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()) {
|
if (dictionary.isFile()) {
|
||||||
return new BinaryDictionary(context, dictionary.getAbsolutePath(), startOffset, length,
|
return new BinaryDictionary(context, dictionary.getAbsolutePath(), startOffset, length,
|
||||||
flagArray, locale);
|
useFullEditDistance, locale);
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "Could not find the file. path=" + dictionary.getAbsolutePath());
|
Log.e(TAG, "Could not find the file. path=" + dictionary.getAbsolutePath());
|
||||||
return null;
|
return null;
|
||||||
|
@ -108,11 +108,18 @@ public class Suggest implements Dictionary.WordCallback {
|
|||||||
initAsynchronously(context, dictionaryResId, locale);
|
initAsynchronously(context, dictionaryResId, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: remove when the tests are updated
|
||||||
/* package for test */ Suggest(final Context context, final File dictionary,
|
/* package for test */ Suggest(final Context context, final File dictionary,
|
||||||
final long startOffset, final long length, final Flag[] flagArray,
|
final long startOffset, final long length, final Flag[] flagArray,
|
||||||
final Locale locale) {
|
final Locale locale) {
|
||||||
initSynchronously(context, DictionaryFactory.createDictionaryForTest(context, dictionary,
|
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) {
|
private void initWhitelistAndAutocorrectAndPool(final Context context, final Locale locale) {
|
||||||
|
@ -68,17 +68,6 @@ public class AndroidSpellCheckerService extends SpellCheckerService
|
|||||||
private static final int CAPITALIZE_ALL = 2; // All caps
|
private static final int CAPITALIZE_ALL = 2; // All caps
|
||||||
|
|
||||||
private final static String[] EMPTY_STRING_ARRAY = new String[0];
|
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 =
|
private Map<String, DictionaryPool> mDictionaryPools =
|
||||||
Collections.synchronizedMap(new TreeMap<String, DictionaryPool>());
|
Collections.synchronizedMap(new TreeMap<String, DictionaryPool>());
|
||||||
private Map<String, Dictionary> mUserDictionaries =
|
private Map<String, Dictionary> mUserDictionaries =
|
||||||
@ -402,7 +391,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService
|
|||||||
final int fallbackResourceId = DictionaryFactory.getMainDictionaryResourceId(resources);
|
final int fallbackResourceId = DictionaryFactory.getMainDictionaryResourceId(resources);
|
||||||
final DictionaryCollection dictionaryCollection =
|
final DictionaryCollection dictionaryCollection =
|
||||||
DictionaryFactory.createDictionaryFromManager(this, locale, fallbackResourceId,
|
DictionaryFactory.createDictionaryFromManager(this, locale, fallbackResourceId,
|
||||||
USE_FULL_EDIT_DISTANCE_FLAG_ARRAY);
|
true /* useFullEditDistance */);
|
||||||
final String localeStr = locale.toString();
|
final String localeStr = locale.toString();
|
||||||
Dictionary userDictionary = mUserDictionaries.get(localeStr);
|
Dictionary userDictionary = mUserDictionaries.get(localeStr);
|
||||||
if (null == userDictionary) {
|
if (null == userDictionary) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user