am ea077349: [ML15] First step in removing DictionaryFacilitator.getLocale

* commit 'ea077349563d704dc3fdecf31a6f9f7f95ce4ad4':
  [ML15] First step in removing DictionaryFacilitator.getLocale
This commit is contained in:
Jean Chalard 2014-10-07 07:24:21 +00:00 committed by Android Git Automerger
commit 42666bda43
3 changed files with 29 additions and 22 deletions

View file

@ -214,6 +214,7 @@ public class DictionaryFacilitator {
mPersonalizationHelper.updateEnabledSubtypes(enabledSubtypes); mPersonalizationHelper.updateEnabledSubtypes(enabledSubtypes);
} }
// TODO: remove this, it's confusing with seamless multiple language switching
public void setIsMonolingualUser(final boolean isMonolingualUser) { public void setIsMonolingualUser(final boolean isMonolingualUser) {
mPersonalizationHelper.setIsMonolingualUser(isMonolingualUser); mPersonalizationHelper.setIsMonolingualUser(isMonolingualUser);
} }
@ -223,16 +224,25 @@ public class DictionaryFacilitator {
return mDictionaryGroups[0].mLocale; return mDictionaryGroups[0].mLocale;
} }
public boolean isActive() {
return null != mDictionaryGroups[0].mLocale;
}
/** /**
* Returns the primary locale among all currently active locales. BE CAREFUL using this. * Returns the most probable locale among all currently active locales. BE CAREFUL using this.
* *
* DO NOT USE THIS just because it's convenient. Use it when it's correct, for example when * DO NOT USE THIS just because it's convenient. Use it when it's correct, for example when
* choosing what dictionary to put a word in, or when changing the capitalization of a typed * choosing what dictionary to put a word in, or when changing the capitalization of a typed
* string. * string.
* @return the primary active locale * @return the most probable locale
*/ */
public Locale getPrimaryLocale() { public Locale getMostProbableLocale() {
return mDictionaryGroups[0].mLocale; return getDictionaryGroupForMostProbableLanguage().mLocale;
}
private DictionaryGroup getDictionaryGroupForMostProbableLanguage() {
// TODO: implement this
return mDictionaryGroups[0];
} }
private static ExpandableBinaryDictionary getSubDict(final String dictType, private static ExpandableBinaryDictionary getSubDict(final String dictType,
@ -274,11 +284,6 @@ public class DictionaryFacilitator {
return null; return null;
} }
private DictionaryGroup getDictionaryGroupForActiveLanguage() {
// TODO: implement this
return mDictionaryGroups[0];
}
public void resetDictionariesWithDictNamePrefix(final Context context, public void resetDictionariesWithDictNamePrefix(final Context context,
final Locale newLocaleToUse, final Locale newLocaleToUse,
final boolean useContactsDict, final boolean usePersonalizedDicts, final boolean useContactsDict, final boolean usePersonalizedDicts,
@ -542,17 +547,18 @@ public class DictionaryFacilitator {
} }
public void addWordToUserDictionary(final Context context, final String word) { public void addWordToUserDictionary(final Context context, final String word) {
final Locale locale = getLocale(); final Locale locale = getMostProbableLocale();
if (locale == null) { if (locale == null) {
return; return;
} }
// TODO: add a toast telling what language this is being added to?
UserBinaryDictionary.addWordToUserDictionary(context, locale, word); UserBinaryDictionary.addWordToUserDictionary(context, locale, word);
} }
public void addToUserHistory(final String suggestion, final boolean wasAutoCapitalized, public void addToUserHistory(final String suggestion, final boolean wasAutoCapitalized,
final NgramContext ngramContext, final int timeStampInSeconds, final NgramContext ngramContext, final int timeStampInSeconds,
final boolean blockPotentiallyOffensive) { final boolean blockPotentiallyOffensive) {
final DictionaryGroup dictionaryGroup = getDictionaryGroupForActiveLanguage(); final DictionaryGroup dictionaryGroup = getDictionaryGroupForMostProbableLanguage();
final String[] words = suggestion.split(Constants.WORD_SEPARATOR); final String[] words = suggestion.split(Constants.WORD_SEPARATOR);
NgramContext ngramContextForCurrentWord = ngramContext; NgramContext ngramContextForCurrentWord = ngramContext;
for (int i = 0; i < words.length; i++) { for (int i = 0; i < words.length; i++) {
@ -620,7 +626,7 @@ public class DictionaryFacilitator {
private void removeWord(final String dictName, final String word) { private void removeWord(final String dictName, final String word) {
final ExpandableBinaryDictionary dictionary = final ExpandableBinaryDictionary dictionary =
getDictionaryGroupForActiveLanguage().getSubDict(dictName); getDictionaryGroupForMostProbableLanguage().getSubDict(dictName);
if (dictionary != null) { if (dictionary != null) {
dictionary.removeUnigramEntryDynamically(word); dictionary.removeUnigramEntryDynamically(word);
} }
@ -747,7 +753,8 @@ public class DictionaryFacilitator {
final SpacingAndPunctuations spacingAndPunctuations, final SpacingAndPunctuations spacingAndPunctuations,
final AddMultipleDictionaryEntriesCallback callback) { final AddMultipleDictionaryEntriesCallback callback) {
mPersonalizationHelper.addEntriesToPersonalizationDictionariesToUpdate( mPersonalizationHelper.addEntriesToPersonalizationDictionariesToUpdate(
getLocale(), personalizationDataChunk, spacingAndPunctuations, callback); getMostProbableLocale(), personalizationDataChunk, spacingAndPunctuations,
callback);
} }
@UsedForTesting @UsedForTesting
@ -756,7 +763,7 @@ public class DictionaryFacilitator {
// TODO: we're inserting the phrase into the dictionary for the active language. Rethink // TODO: we're inserting the phrase into the dictionary for the active language. Rethink
// this a bit from a theoretical point of view. // this a bit from a theoretical point of view.
final ExpandableBinaryDictionary contextualDict = final ExpandableBinaryDictionary contextualDict =
getDictionaryGroupForActiveLanguage().getSubDict(Dictionary.TYPE_CONTEXTUAL); getDictionaryGroupForMostProbableLanguage().getSubDict(Dictionary.TYPE_CONTEXTUAL);
if (contextualDict == null) { if (contextualDict == null) {
return; return;
} }

View file

@ -1627,7 +1627,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} }
final String wordToShow; final String wordToShow;
if (CapsModeUtils.isAutoCapsMode(mInputLogic.mLastComposedWord.mCapitalizedMode)) { if (CapsModeUtils.isAutoCapsMode(mInputLogic.mLastComposedWord.mCapitalizedMode)) {
wordToShow = word.toLowerCase(mDictionaryFacilitator.getPrimaryLocale()); wordToShow = word.toLowerCase(mDictionaryFacilitator.getMostProbableLocale());
} else { } else {
wordToShow = word; wordToShow = word;
} }
@ -1912,7 +1912,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} }
public void dumpDictionaryForDebug(final String dictName) { public void dumpDictionaryForDebug(final String dictName) {
if (mDictionaryFacilitator.getLocale() == null) { if (!mDictionaryFacilitator.isActive()) {
resetDictionaryFacilitatorIfNecessary(); resetDictionaryFacilitatorIfNecessary();
} }
mDictionaryFacilitator.dumpDictionaryForDebug(dictName); mDictionaryFacilitator.dumpDictionaryForDebug(dictName);

View file

@ -55,10 +55,6 @@ public final class Suggest {
mDictionaryFacilitator = dictionaryFacilitator; mDictionaryFacilitator = dictionaryFacilitator;
} }
public Locale getLocale() {
return mDictionaryFacilitator.getLocale();
}
public void setAutoCorrectionThreshold(final float threshold) { public void setAutoCorrectionThreshold(final float threshold) {
mAutoCorrectionThreshold = threshold; mAutoCorrectionThreshold = threshold;
} }
@ -136,7 +132,10 @@ 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, mDictionaryFacilitator.getLocale()); trailingSingleQuotesCount,
// For transforming suggestions that don't come for any dictionary, we
// use the currently most probable locale as it's our best bet.
mDictionaryFacilitator.getMostProbableLocale());
final boolean didRemoveTypedWord = final boolean didRemoveTypedWord =
SuggestedWordInfo.removeDups(wordComposer.getTypedWord(), suggestionsContainer); SuggestedWordInfo.removeDups(wordComposer.getTypedWord(), suggestionsContainer);
@ -216,7 +215,8 @@ public final class Suggest {
final SuggestionResults suggestionResults = mDictionaryFacilitator.getSuggestionResults( final SuggestionResults suggestionResults = mDictionaryFacilitator.getSuggestionResults(
wordComposer, ngramContext, proximityInfo, settingsValuesForSuggestion, wordComposer, ngramContext, proximityInfo, settingsValuesForSuggestion,
SESSION_ID_GESTURE); SESSION_ID_GESTURE);
final Locale defaultLocale = mDictionaryFacilitator.getLocale(); // For transforming words that don't come from a dictionary, because it's our best bet
final Locale defaultLocale = mDictionaryFacilitator.getMostProbableLocale();
final ArrayList<SuggestedWordInfo> suggestionsContainer = final ArrayList<SuggestedWordInfo> suggestionsContainer =
new ArrayList<>(suggestionResults); new ArrayList<>(suggestionResults);
final int suggestionsCount = suggestionsContainer.size(); final int suggestionsCount = suggestionsContainer.size();