Add SuggestedWords.isEmpty() method

Change-Id: I0fcb104a6a81aee4b99f5ee848eba7495630dc7d
This commit is contained in:
Tadashi G. Takaoka 2012-10-03 14:06:44 +09:00
parent 3e5a3c18be
commit c6ff7c42d9
4 changed files with 14 additions and 17 deletions

View file

@ -108,8 +108,8 @@ public final class SuggestionSpanUtils {
CharSequence pickedWord, SuggestedWords suggestedWords, boolean dictionaryAvailable) { CharSequence pickedWord, SuggestedWords suggestedWords, boolean dictionaryAvailable) {
if (!dictionaryAvailable || TextUtils.isEmpty(pickedWord) if (!dictionaryAvailable || TextUtils.isEmpty(pickedWord)
|| CONSTRUCTOR_SuggestionSpan == null || CONSTRUCTOR_SuggestionSpan == null
|| suggestedWords == null || suggestedWords.size() == 0 || suggestedWords.isEmpty() || suggestedWords.mIsPrediction
|| suggestedWords.mIsPrediction || suggestedWords.mIsPunctuationSuggestions || suggestedWords.mIsPunctuationSuggestions
|| OBJ_SUGGESTIONS_MAX_SIZE == null) { || OBJ_SUGGESTIONS_MAX_SIZE == null) {
return pickedWord; return pickedWord;
} }

View file

@ -1518,8 +1518,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
private void showGesturePreviewAndSuggestionStrip(final SuggestedWords suggestedWords, private void showGesturePreviewAndSuggestionStrip(final SuggestedWords suggestedWords,
final boolean dismissGestureFloatingPreviewText) { final boolean dismissGestureFloatingPreviewText) {
final String batchInputText = (suggestedWords.size() > 0) final String batchInputText = suggestedWords.isEmpty()
? suggestedWords.getWord(0) : null; ? null : suggestedWords.getWord(0);
final KeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView(); final KeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
mainKeyboardView.showGestureFloatingPreviewText(batchInputText); mainKeyboardView.showGestureFloatingPreviewText(batchInputText);
showSuggestionStrip(suggestedWords, null); showSuggestionStrip(suggestedWords, null);
@ -1537,8 +1537,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
public void onEndBatchInput(final InputPointers batchPointers) { public void onEndBatchInput(final InputPointers batchPointers) {
final SuggestedWords suggestedWords = BatchInputUpdater.getInstance().onEndBatchInput( final SuggestedWords suggestedWords = BatchInputUpdater.getInstance().onEndBatchInput(
batchPointers, this); batchPointers, this);
final String batchInputText = (suggestedWords.size() > 0) final String batchInputText = suggestedWords.isEmpty()
? suggestedWords.getWord(0) : null; ? null : suggestedWords.getWord(0);
if (TextUtils.isEmpty(batchInputText)) { if (TextUtils.isEmpty(batchInputText)) {
return; return;
} }
@ -1963,19 +1963,15 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
private void showSuggestionStrip(final SuggestedWords suggestedWords, private void showSuggestionStrip(final SuggestedWords suggestedWords,
final CharSequence typedWord) { final CharSequence typedWord) {
if (null == suggestedWords || suggestedWords.size() <= 0) { if (suggestedWords.isEmpty()) {
clearSuggestionStrip(); clearSuggestionStrip();
return; return;
} }
final CharSequence autoCorrection; final CharSequence autoCorrection;
if (suggestedWords.size() > 0) { if (suggestedWords.mWillAutoCorrect) {
if (suggestedWords.mWillAutoCorrect) { autoCorrection = suggestedWords.getWord(1);
autoCorrection = suggestedWords.getWord(1);
} else {
autoCorrection = typedWord;
}
} else { } else {
autoCorrection = null; autoCorrection = typedWord;
} }
mWordComposer.setAutoCorrection(autoCorrection); mWordComposer.setAutoCorrection(autoCorrection);
final boolean isAutoCorrection = suggestedWords.willAutoCorrect(); final boolean isAutoCorrection = suggestedWords.willAutoCorrect();

View file

@ -53,6 +53,10 @@ public final class SuggestedWords {
mIsPrediction = isPrediction; mIsPrediction = isPrediction;
} }
public boolean isEmpty() {
return mSuggestedWordInfoList.isEmpty();
}
public int size() { public int size() {
return mSuggestedWordInfoList.size(); return mSuggestedWordInfoList.size();
} }

View file

@ -672,9 +672,6 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
} }
public void setSuggestions(final SuggestedWords suggestedWords) { public void setSuggestions(final SuggestedWords suggestedWords) {
if (suggestedWords == null)
return;
clear(); clear();
mSuggestedWords = suggestedWords; mSuggestedWords = suggestedWords;
mParams.layout(mSuggestedWords, mSuggestionsStrip, this, getWidth()); mParams.layout(mSuggestedWords, mSuggestionsStrip, this, getWidth());