am a341e7d2: Merge "[ML3] Put the locale in SuggestedWordInfo"

* commit 'a341e7d24465efe6c6805ff42b87e7921d13b76b':
  [ML3] Put the locale in SuggestedWordInfo
main
Jean Chalard 2014-09-02 06:51:32 +00:00 committed by Android Git Automerger
commit 46bb5f0431
9 changed files with 36 additions and 35 deletions

View File

@ -83,7 +83,6 @@ public final class BinaryDictionary extends Dictionary {
public static final String DIR_NAME_SUFFIX_FOR_RECORD_MIGRATION = ".migrating"; public static final String DIR_NAME_SUFFIX_FOR_RECORD_MIGRATION = ".migrating";
private long mNativeDict; private long mNativeDict;
private final Locale mLocale;
private final long mDictSize; private final long mDictSize;
private final String mDictFilePath; private final String mDictFilePath;
private final boolean mUseFullEditDistance; private final boolean mUseFullEditDistance;
@ -117,8 +116,7 @@ public final class BinaryDictionary extends Dictionary {
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) { final boolean isUpdatable) {
super(dictType); super(dictType, locale);
mLocale = locale;
mDictSize = length; mDictSize = length;
mDictFilePath = filename; mDictFilePath = filename;
mIsUpdatable = isUpdatable; mIsUpdatable = isUpdatable;
@ -138,8 +136,7 @@ public final class BinaryDictionary extends Dictionary {
public BinaryDictionary(final String filename, final boolean useFullEditDistance, public BinaryDictionary(final String filename, final boolean useFullEditDistance,
final Locale locale, final String dictType, final long formatVersion, final Locale locale, final String dictType, final long formatVersion,
final Map<String, String> attributeMap) { final Map<String, String> attributeMap) {
super(dictType); super(dictType, locale);
mLocale = locale;
mDictSize = 0; mDictSize = 0;
mDictFilePath = filename; mDictFilePath = filename;
// On memory dictionary is always updatable. // On memory dictionary is always updatable.

View File

@ -16,12 +16,12 @@
package com.android.inputmethod.latin; package com.android.inputmethod.latin;
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.keyboard.ProximityInfo; import com.android.inputmethod.keyboard.ProximityInfo;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.settings.SettingsValuesForSuggestion; import com.android.inputmethod.latin.settings.SettingsValuesForSuggestion;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Locale;
/** /**
* Abstract base class for a dictionary that can do a fuzzy search for words based on a set of key * Abstract base class for a dictionary that can do a fuzzy search for words based on a set of key
@ -62,9 +62,12 @@ public abstract class Dictionary {
// Contextual dictionary. // Contextual dictionary.
public static final String TYPE_CONTEXTUAL = "contextual"; public static final String TYPE_CONTEXTUAL = "contextual";
public final String mDictType; public final String mDictType;
// The locale for this dictionary. May be null if unknown (phony dictionary for example).
public final Locale mLocale;
public Dictionary(final String dictType) { public Dictionary(final String dictType, final Locale locale) {
mDictType = dictType; mDictType = dictType;
mLocale = locale;
} }
/** /**
@ -162,7 +165,7 @@ public abstract class Dictionary {
private static class PhonyDictionary extends Dictionary { private static class PhonyDictionary extends Dictionary {
// This class is not publicly instantiable. // This class is not publicly instantiable.
private PhonyDictionary(final String type) { private PhonyDictionary(final String type) {
super(type); super(type, null);
} }
@Override @Override

View File

@ -25,6 +25,7 @@ import com.android.inputmethod.latin.settings.SettingsValuesForSuggestion;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Locale;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
/** /**
@ -34,13 +35,14 @@ public final class DictionaryCollection extends Dictionary {
private final String TAG = DictionaryCollection.class.getSimpleName(); private final String TAG = DictionaryCollection.class.getSimpleName();
protected final CopyOnWriteArrayList<Dictionary> mDictionaries; protected final CopyOnWriteArrayList<Dictionary> mDictionaries;
public DictionaryCollection(final String dictType) { public DictionaryCollection(final String dictType, final Locale locale) {
super(dictType); super(dictType, locale);
mDictionaries = new CopyOnWriteArrayList<>(); mDictionaries = new CopyOnWriteArrayList<>();
} }
public DictionaryCollection(final String dictType, final Dictionary... dictionaries) { public DictionaryCollection(final String dictType, final Locale locale,
super(dictType); final Dictionary... dictionaries) {
super(dictType, locale);
if (null == dictionaries) { if (null == dictionaries) {
mDictionaries = new CopyOnWriteArrayList<>(); mDictionaries = new CopyOnWriteArrayList<>();
} else { } else {
@ -49,8 +51,9 @@ public final class DictionaryCollection extends Dictionary {
} }
} }
public DictionaryCollection(final String dictType, final Collection<Dictionary> dictionaries) { public DictionaryCollection(final String dictType, final Locale locale,
super(dictType); final Collection<Dictionary> dictionaries) {
super(dictType, locale);
mDictionaries = new CopyOnWriteArrayList<>(dictionaries); mDictionaries = new CopyOnWriteArrayList<>(dictionaries);
mDictionaries.removeAll(Collections.singleton(null)); mDictionaries.removeAll(Collections.singleton(null));
} }

View File

@ -503,7 +503,7 @@ public class DictionaryFacilitator {
final SettingsValuesForSuggestion settingsValuesForSuggestion, final int sessionId) { final SettingsValuesForSuggestion settingsValuesForSuggestion, final int sessionId) {
final Dictionaries dictionaries = mDictionaries; final Dictionaries dictionaries = mDictionaries;
final SuggestionResults suggestionResults = final SuggestionResults suggestionResults =
new SuggestionResults(dictionaries.mLocale, SuggestedWords.MAX_SUGGESTIONS); new SuggestionResults(SuggestedWords.MAX_SUGGESTIONS);
final float[] languageWeight = new float[] { Dictionary.NOT_A_LANGUAGE_WEIGHT }; final float[] languageWeight = new float[] { Dictionary.NOT_A_LANGUAGE_WEIGHT };
for (final String dictType : DICT_TYPES_ORDERED_TO_GET_SUGGESTIONS) { for (final String dictType : DICT_TYPES_ORDERED_TO_GET_SUGGESTIONS) {
final Dictionary dictionary = dictionaries.getDict(dictType); final Dictionary dictionary = dictionaries.getDict(dictType);

View File

@ -50,7 +50,7 @@ public final class DictionaryFactory {
final Locale locale, final boolean useFullEditDistance) { final Locale locale, 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(Dictionary.TYPE_MAIN, return new DictionaryCollection(Dictionary.TYPE_MAIN, locale,
createReadOnlyBinaryDictionary(context, locale)); createReadOnlyBinaryDictionary(context, locale));
} }
@ -75,7 +75,7 @@ public final class DictionaryFactory {
// If the list is empty, that means we should not use any dictionary (for example, the user // If the list is empty, that means we should not use any dictionary (for example, the user
// explicitly disabled the main dictionary), so the following is okay. dictList is never // explicitly disabled the main dictionary), so the following is okay. dictList is never
// null, but if for some reason it is, DictionaryCollection handles it gracefully. // null, but if for some reason it is, DictionaryCollection handles it gracefully.
return new DictionaryCollection(Dictionary.TYPE_MAIN, dictList); return new DictionaryCollection(Dictionary.TYPE_MAIN, locale, dictList);
} }
/** /**
@ -188,7 +188,7 @@ public final class DictionaryFactory {
public static Dictionary createDictionaryForTest(final AssetFileAddress[] dictionaryList, public static Dictionary createDictionaryForTest(final AssetFileAddress[] dictionaryList,
final boolean useFullEditDistance, Locale locale) { final boolean useFullEditDistance, Locale locale) {
final DictionaryCollection dictionaryCollection = final DictionaryCollection dictionaryCollection =
new DictionaryCollection(Dictionary.TYPE_MAIN); new DictionaryCollection(Dictionary.TYPE_MAIN, locale);
for (final AssetFileAddress address : dictionaryList) { for (final AssetFileAddress address : dictionaryList) {
final ReadOnlyBinaryDictionary readOnlyBinaryDictionary = new ReadOnlyBinaryDictionary( final ReadOnlyBinaryDictionary readOnlyBinaryDictionary = new ReadOnlyBinaryDictionary(
address.mFilename, address.mOffset, address.mLength, useFullEditDistance, address.mFilename, address.mOffset, address.mLength, useFullEditDistance,

View File

@ -86,9 +86,6 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
*/ */
private final String mDictName; private final String mDictName;
/** Dictionary locale */
private final Locale mLocale;
/** Dictionary file */ /** Dictionary file */
private final File mDictFile; private final File mDictFile;
@ -137,10 +134,9 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
*/ */
public ExpandableBinaryDictionary(final Context context, final String dictName, public ExpandableBinaryDictionary(final Context context, final String dictName,
final Locale locale, final String dictType, final File dictFile) { final Locale locale, final String dictType, final File dictFile) {
super(dictType); super(dictType, locale);
mDictName = dictName; mDictName = dictName;
mContext = context; mContext = context;
mLocale = locale;
mDictFile = getDictFile(context, dictName, dictFile); mDictFile = getDictFile(context, dictName, dictFile);
mBinaryDictionary = null; mBinaryDictionary = null;
mIsReloading = new AtomicBoolean(); mIsReloading = new AtomicBoolean();

View File

@ -40,7 +40,7 @@ public final class ReadOnlyBinaryDictionary extends Dictionary {
public ReadOnlyBinaryDictionary(final String filename, final long offset, final long length, public ReadOnlyBinaryDictionary(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) {
super(dictType); super(dictType, locale);
mBinaryDictionary = new BinaryDictionary(filename, offset, length, useFullEditDistance, mBinaryDictionary = new BinaryDictionary(filename, offset, length, useFullEditDistance,
locale, dictType, false /* isUpdatable */); locale, dictType, false /* isUpdatable */);
} }

View File

@ -84,7 +84,7 @@ public final class Suggest {
private static ArrayList<SuggestedWordInfo> getTransformedSuggestedWordInfoList( private static ArrayList<SuggestedWordInfo> getTransformedSuggestedWordInfoList(
final WordComposer wordComposer, final SuggestionResults results, final WordComposer wordComposer, final SuggestionResults results,
final int trailingSingleQuotesCount) { final int trailingSingleQuotesCount, final Locale defaultLocale) {
final boolean shouldMakeSuggestionsAllUpperCase = wordComposer.isAllUpperCase() final boolean shouldMakeSuggestionsAllUpperCase = wordComposer.isAllUpperCase()
&& !wordComposer.isResumed(); && !wordComposer.isResumed();
final boolean isOnlyFirstCharCapitalized = final boolean isOnlyFirstCharCapitalized =
@ -96,9 +96,11 @@ public final class Suggest {
|| 0 != trailingSingleQuotesCount) { || 0 != trailingSingleQuotesCount) {
for (int i = 0; i < suggestionsCount; ++i) { for (int i = 0; i < suggestionsCount; ++i) {
final SuggestedWordInfo wordInfo = suggestionsContainer.get(i); final SuggestedWordInfo wordInfo = suggestionsContainer.get(i);
final Locale wordLocale = wordInfo.mSourceDict.mLocale;
final SuggestedWordInfo transformedWordInfo = getTransformedSuggestedWordInfo( final SuggestedWordInfo transformedWordInfo = getTransformedSuggestedWordInfo(
wordInfo, results.mLocale, shouldMakeSuggestionsAllUpperCase, wordInfo, null == wordLocale ? defaultLocale : wordLocale,
isOnlyFirstCharCapitalized, trailingSingleQuotesCount); shouldMakeSuggestionsAllUpperCase, isOnlyFirstCharCapitalized,
trailingSingleQuotesCount);
suggestionsContainer.set(i, transformedWordInfo); suggestionsContainer.set(i, transformedWordInfo);
} }
} }
@ -134,7 +136,7 @@ public final class Suggest {
SESSION_ID_TYPING); SESSION_ID_TYPING);
final ArrayList<SuggestedWordInfo> suggestionsContainer = final ArrayList<SuggestedWordInfo> suggestionsContainer =
getTransformedSuggestedWordInfoList(wordComposer, suggestionResults, getTransformedSuggestedWordInfoList(wordComposer, suggestionResults,
trailingSingleQuotesCount); trailingSingleQuotesCount, mDictionaryFacilitator.getLocale());
final boolean didRemoveTypedWord = final boolean didRemoveTypedWord =
SuggestedWordInfo.removeDups(wordComposer.getTypedWord(), suggestionsContainer); SuggestedWordInfo.removeDups(wordComposer.getTypedWord(), suggestionsContainer);
@ -208,6 +210,7 @@ public final class Suggest {
final SuggestionResults suggestionResults = mDictionaryFacilitator.getSuggestionResults( final SuggestionResults suggestionResults = mDictionaryFacilitator.getSuggestionResults(
wordComposer, prevWordsInfo, proximityInfo, settingsValuesForSuggestion, wordComposer, prevWordsInfo, proximityInfo, settingsValuesForSuggestion,
SESSION_ID_GESTURE); SESSION_ID_GESTURE);
final Locale defaultLocale = mDictionaryFacilitator.getLocale();
final ArrayList<SuggestedWordInfo> suggestionsContainer = final ArrayList<SuggestedWordInfo> suggestionsContainer =
new ArrayList<>(suggestionResults); new ArrayList<>(suggestionResults);
final int suggestionsCount = suggestionsContainer.size(); final int suggestionsCount = suggestionsContainer.size();
@ -216,9 +219,10 @@ public final class Suggest {
if (isFirstCharCapitalized || isAllUpperCase) { if (isFirstCharCapitalized || isAllUpperCase) {
for (int i = 0; i < suggestionsCount; ++i) { for (int i = 0; i < suggestionsCount; ++i) {
final SuggestedWordInfo wordInfo = suggestionsContainer.get(i); final SuggestedWordInfo wordInfo = suggestionsContainer.get(i);
final Locale wordlocale = wordInfo.mSourceDict.mLocale;
final SuggestedWordInfo transformedWordInfo = getTransformedSuggestedWordInfo( final SuggestedWordInfo transformedWordInfo = getTransformedSuggestedWordInfo(
wordInfo, suggestionResults.mLocale, isAllUpperCase, isFirstCharCapitalized, wordInfo, null == wordlocale ? defaultLocale : wordlocale, isAllUpperCase,
0 /* trailingSingleQuotesCount */); isFirstCharCapitalized, 0 /* trailingSingleQuotesCount */);
suggestionsContainer.set(i, transformedWordInfo); suggestionsContainer.set(i, transformedWordInfo);
} }
} }

View File

@ -30,18 +30,16 @@ import java.util.TreeSet;
* than its limit * than its limit
*/ */
public final class SuggestionResults extends TreeSet<SuggestedWordInfo> { public final class SuggestionResults extends TreeSet<SuggestedWordInfo> {
public final Locale mLocale;
public final ArrayList<SuggestedWordInfo> mRawSuggestions; public final ArrayList<SuggestedWordInfo> mRawSuggestions;
private final int mCapacity; private final int mCapacity;
public SuggestionResults(final Locale locale, final int capacity) { public SuggestionResults(final int capacity) {
this(locale, sSuggestedWordInfoComparator, capacity); this(sSuggestedWordInfoComparator, capacity);
} }
public SuggestionResults(final Locale locale, final Comparator<SuggestedWordInfo> comparator, public SuggestionResults(final Comparator<SuggestedWordInfo> comparator,
final int capacity) { final int capacity) {
super(comparator); super(comparator);
mLocale = locale;
mCapacity = capacity; mCapacity = capacity;
if (ProductionFlags.INCLUDE_RAW_SUGGESTIONS) { if (ProductionFlags.INCLUDE_RAW_SUGGESTIONS) {
mRawSuggestions = new ArrayList<>(); mRawSuggestions = new ArrayList<>();