Remove the callback argument to getBigrams() (A16)

Bug: 6252660
Bug: 6166228
Bug: 2704000
Bug: 6225530
Change-Id: I7457ac04f8cd4019fb86c986725aae3de1b1a65e
main
Jean Chalard 2012-06-21 13:40:51 +09:00
parent 89239eeb74
commit 2f1b6c9ea4
7 changed files with 14 additions and 17 deletions

View File

@ -108,7 +108,7 @@ public class BinaryDictionary extends Dictionary {
@Override @Override
public ArrayList<SuggestedWordInfo> getBigrams(final WordComposer codes, public ArrayList<SuggestedWordInfo> getBigrams(final WordComposer codes,
final CharSequence previousWord, final WordCallback callback) { final CharSequence previousWord) {
if (mNativeDict == 0) return null; if (mNativeDict == 0) return null;
int[] codePoints = StringUtils.toCodePointArray(previousWord.toString()); int[] codePoints = StringUtils.toCodePointArray(previousWord.toString());

View File

@ -70,15 +70,13 @@ public abstract class Dictionary {
final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo); final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo);
/** /**
* Searches for pairs in the bigram dictionary that matches the previous word and all the * Searches for pairs in the bigram dictionary that matches the previous word.
* possible words following are added through the callback object.
* @param composer the key sequence to match * @param composer the key sequence to match
* @param previousWord the word before * @param previousWord the word before
* @param callback the callback object to send possible word following previous word
* @return the list of suggestions * @return the list of suggestions
*/ */
public abstract ArrayList<SuggestedWordInfo> getBigrams(final WordComposer composer, public abstract ArrayList<SuggestedWordInfo> getBigrams(final WordComposer composer,
final CharSequence previousWord, final WordCallback callback); final CharSequence previousWord);
/** /**
* Checks if the given word occurs in the dictionary * Checks if the given word occurs in the dictionary

View File

@ -72,18 +72,18 @@ public class DictionaryCollection extends Dictionary {
@Override @Override
public ArrayList<SuggestedWordInfo> getBigrams(final WordComposer composer, public ArrayList<SuggestedWordInfo> getBigrams(final WordComposer composer,
final CharSequence previousWord, final WordCallback callback) { final CharSequence previousWord) {
final CopyOnWriteArrayList<Dictionary> dictionaries = mDictionaries; final CopyOnWriteArrayList<Dictionary> dictionaries = mDictionaries;
if (dictionaries.isEmpty()) return null; if (dictionaries.isEmpty()) return null;
// To avoid creating unnecessary objects, we get the list out of the first // To avoid creating unnecessary objects, we get the list out of the first
// dictionary and add the rest to it if not null, hence the get(0) // dictionary and add the rest to it if not null, hence the get(0)
ArrayList<SuggestedWordInfo> suggestions = dictionaries.get(0).getBigrams(composer, ArrayList<SuggestedWordInfo> suggestions = dictionaries.get(0).getBigrams(composer,
previousWord, callback); previousWord);
if (null == suggestions) suggestions = new ArrayList<SuggestedWordInfo>(); if (null == suggestions) suggestions = new ArrayList<SuggestedWordInfo>();
final int length = dictionaries.size(); final int length = dictionaries.size();
for (int i = 0; i < length; ++ i) { for (int i = 0; i < length; ++ i) {
final ArrayList<SuggestedWordInfo> sugg = final ArrayList<SuggestedWordInfo> sugg =
dictionaries.get(i).getBigrams(composer, previousWord, callback); dictionaries.get(i).getBigrams(composer, previousWord);
if (null != sugg) suggestions.addAll(sugg); if (null != sugg) suggestions.addAll(sugg);
} }
return suggestions; return suggestions;

View File

@ -219,17 +219,17 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
@Override @Override
public ArrayList<SuggestedWordInfo> getBigrams(final WordComposer codes, public ArrayList<SuggestedWordInfo> getBigrams(final WordComposer codes,
final CharSequence previousWord, final WordCallback callback) { final CharSequence previousWord) {
asyncReloadDictionaryIfRequired(); asyncReloadDictionaryIfRequired();
return getBigramsInner(codes, previousWord, callback); return getBigramsInner(codes, previousWord);
} }
protected ArrayList<SuggestedWordInfo> getBigramsInner(final WordComposer codes, protected ArrayList<SuggestedWordInfo> getBigramsInner(final WordComposer codes,
final CharSequence previousWord, final WordCallback callback) { final CharSequence previousWord) {
if (mLocalDictionaryController.tryLock()) { if (mLocalDictionaryController.tryLock()) {
try { try {
if (mBinaryDictionary != null) { if (mBinaryDictionary != null) {
return mBinaryDictionary.getBigrams(codes, previousWord, callback); return mBinaryDictionary.getBigrams(codes, previousWord);
} }
} finally { } finally {
mLocalDictionaryController.unlock(); mLocalDictionaryController.unlock();

View File

@ -612,7 +612,7 @@ public class ExpandableDictionary extends Dictionary {
@Override @Override
public ArrayList<SuggestedWordInfo> getBigrams(final WordComposer codes, public ArrayList<SuggestedWordInfo> getBigrams(final WordComposer codes,
final CharSequence previousWord, final WordCallback callback) { final CharSequence previousWord) {
if (!reloadDictionaryIfRequired()) { if (!reloadDictionaryIfRequired()) {
final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<SuggestedWordInfo>(); final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<SuggestedWordInfo>();
runBigramReverseLookUp(previousWord, suggestions); runBigramReverseLookUp(previousWord, suggestions);

View File

@ -263,10 +263,9 @@ public class Suggest implements Dictionary.WordCallback {
final int dicTypeId = sDictKeyToDictIndex.get(key); final int dicTypeId = sDictKeyToDictIndex.get(key);
final Dictionary dictionary = mBigramDictionaries.get(key); final Dictionary dictionary = mBigramDictionaries.get(key);
final ArrayList<SuggestedWordInfo> suggestions = final ArrayList<SuggestedWordInfo> suggestions =
dictionary.getBigrams(wordComposer, prevWordForBigram, this); dictionary.getBigrams(wordComposer, prevWordForBigram);
if (null != lowerPrevWord) { if (null != lowerPrevWord) {
suggestions.addAll(dictionary.getBigrams(wordComposer, lowerPrevWord, suggestions.addAll(dictionary.getBigrams(wordComposer, lowerPrevWord));
this));
} }
for (final SuggestedWordInfo suggestion : suggestions) { for (final SuggestedWordInfo suggestion : suggestions) {
final String suggestionStr = suggestion.mWord.toString(); final String suggestionStr = suggestion.mWord.toString();

View File

@ -789,7 +789,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService
dictInfo = mDictionaryPool.takeOrGetNull(); dictInfo = mDictionaryPool.takeOrGetNull();
if (null == dictInfo) return getNotInDictEmptySuggestions(); if (null == dictInfo) return getNotInDictEmptySuggestions();
final ArrayList<SuggestedWordInfo> suggestions = dictInfo.mDictionary.getWords( final ArrayList<SuggestedWordInfo> suggestions = dictInfo.mDictionary.getWords(
composer, prevWord, suggestionsGatherer, dictInfo.mProximityInfo); composer, prevWord, dictInfo.mProximityInfo);
for (final SuggestedWordInfo suggestion : suggestions) { for (final SuggestedWordInfo suggestion : suggestions) {
final String suggestionStr = suggestion.mWord.toString(); final String suggestionStr = suggestion.mWord.toString();
suggestionsGatherer.oldAddWord(suggestionStr.toCharArray(), null, 0, suggestionsGatherer.oldAddWord(suggestionStr.toCharArray(), null, 0,