[ML15] First step in removing DictionaryFacilitator.getLocale

Bug: 11230254
Change-Id: Ied010ec6f1024080e8a499f682d2fc1780e82ef7
main
Jean Chalard 2014-10-07 14:29:14 +09:00
parent 3ead4d7f8a
commit ea07734956
3 changed files with 29 additions and 22 deletions

View File

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

View File

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

View File

@ -55,10 +55,6 @@ public final class Suggest {
mDictionaryFacilitator = dictionaryFacilitator;
}
public Locale getLocale() {
return mDictionaryFacilitator.getLocale();
}
public void setAutoCorrectionThreshold(final float threshold) {
mAutoCorrectionThreshold = threshold;
}
@ -136,7 +132,10 @@ public final class Suggest {
SESSION_ID_TYPING);
final ArrayList<SuggestedWordInfo> suggestionsContainer =
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 =
SuggestedWordInfo.removeDups(wordComposer.getTypedWord(), suggestionsContainer);
@ -216,7 +215,8 @@ public final class Suggest {
final SuggestionResults suggestionResults = mDictionaryFacilitator.getSuggestionResults(
wordComposer, ngramContext, proximityInfo, settingsValuesForSuggestion,
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 =
new ArrayList<>(suggestionResults);
final int suggestionsCount = suggestionsContainer.size();