Merge "Hiding SuggestedWords.EMPTY and refactoring code that compares SuggestedWords instances directly to it to use isEmpty instead"

main
Adrian Velicu 2014-09-22 06:20:24 +00:00 committed by Android (Google) Code Review
commit b12c174c2f
7 changed files with 26 additions and 24 deletions

View File

@ -49,7 +49,7 @@ public class DrawingHandler extends LeakGuardHandlerWrapper<Callbacks> {
callbacks.dismissKeyPreviewWithoutDelay((Key)msg.obj); callbacks.dismissKeyPreviewWithoutDelay((Key)msg.obj);
break; break;
case MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT: case MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT:
callbacks.showGestureFloatingPreviewText(SuggestedWords.EMPTY); callbacks.showGestureFloatingPreviewText(SuggestedWords.getEmptyInstance());
break; break;
} }
} }

View File

@ -98,7 +98,7 @@ public class GestureFloatingTextDrawingPreview extends AbstractDrawingPreview {
private final RectF mGesturePreviewRectangle = new RectF(); private final RectF mGesturePreviewRectangle = new RectF();
private int mPreviewTextX; private int mPreviewTextX;
private int mPreviewTextY; private int mPreviewTextY;
private SuggestedWords mSuggestedWords = SuggestedWords.EMPTY; private SuggestedWords mSuggestedWords = SuggestedWords.getEmptyInstance();
private final int[] mLastPointerCoords = CoordinateUtils.newInstance(); private final int[] mLastPointerCoords = CoordinateUtils.newInstance();
public GestureFloatingTextDrawingPreview(final TypedArray mainKeyboardViewAttr) { public GestureFloatingTextDrawingPreview(final TypedArray mainKeyboardViewAttr) {

View File

@ -1491,7 +1491,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final boolean isEmptyApplicationSpecifiedCompletions = final boolean isEmptyApplicationSpecifiedCompletions =
currentSettingsValues.isApplicationSpecifiedCompletionsOn() currentSettingsValues.isApplicationSpecifiedCompletionsOn()
&& suggestedWords.isEmpty(); && suggestedWords.isEmpty();
final boolean noSuggestionsFromDictionaries = (SuggestedWords.EMPTY == suggestedWords) final boolean noSuggestionsFromDictionaries = suggestedWords.isEmpty()
|| suggestedWords.isPunctuationSuggestions() || suggestedWords.isPunctuationSuggestions()
|| isEmptyApplicationSpecifiedCompletions; || isEmptyApplicationSpecifiedCompletions;
final boolean isBeginningOfSentencePrediction = (suggestedWords.mInputStyle final boolean isBeginningOfSentencePrediction = (suggestedWords.mInputStyle
@ -1518,7 +1518,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final OnGetSuggestedWordsCallback callback) { final OnGetSuggestedWordsCallback callback) {
final Keyboard keyboard = mKeyboardSwitcher.getKeyboard(); final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
if (keyboard == null) { if (keyboard == null) {
callback.onGetSuggestedWords(SuggestedWords.EMPTY); callback.onGetSuggestedWords(SuggestedWords.getEmptyInstance());
return; return;
} }
mInputLogic.getSuggestedWords(mSettings.getCurrent(), keyboard.getProximityInfo(), mInputLogic.getSuggestedWords(mSettings.getCurrent(), keyboard.getProximityInfo(),
@ -1526,10 +1526,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} }
@Override @Override
public void showSuggestionStrip(final SuggestedWords sourceSuggestedWords) { public void showSuggestionStrip(final SuggestedWords suggestedWords) {
final SuggestedWords suggestedWords = if (suggestedWords.isEmpty()) {
sourceSuggestedWords.isEmpty() ? SuggestedWords.EMPTY : sourceSuggestedWords;
if (SuggestedWords.EMPTY == suggestedWords) {
setNeutralSuggestionStrip(); setNeutralSuggestionStrip();
} else { } else {
setSuggestedWords(suggestedWords); setSuggestedWords(suggestedWords);
@ -1537,7 +1535,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Cache the auto-correction in accessibility code so we can speak it if the user // Cache the auto-correction in accessibility code so we can speak it if the user
// touches a key that will insert it. // touches a key that will insert it.
AccessibilityUtils.getInstance().setAutoCorrection(suggestedWords, AccessibilityUtils.getInstance().setAutoCorrection(suggestedWords,
sourceSuggestedWords.mTypedWord); suggestedWords.mTypedWord);
} }
// Called from {@link SuggestionStripView} through the {@link SuggestionStripView#Listener} // Called from {@link SuggestionStripView} through the {@link SuggestionStripView#Listener}
@ -1572,7 +1570,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
public void setNeutralSuggestionStrip() { public void setNeutralSuggestionStrip() {
final SettingsValues currentSettings = mSettings.getCurrent(); final SettingsValues currentSettings = mSettings.getCurrent();
final SuggestedWords neutralSuggestions = currentSettings.mBigramPredictionEnabled final SuggestedWords neutralSuggestions = currentSettings.mBigramPredictionEnabled
? SuggestedWords.EMPTY : currentSettings.mSpacingAndPunctuations.mSuggestPuncList; ? SuggestedWords.getEmptyInstance()
: currentSettings.mSpacingAndPunctuations.mSuggestPuncList;
setSuggestedWords(neutralSuggestions); setSuggestedWords(neutralSuggestions);
} }

View File

@ -45,7 +45,7 @@ public class SuggestedWords {
public static final int MAX_SUGGESTIONS = 18; public static final int MAX_SUGGESTIONS = 18;
private static final ArrayList<SuggestedWordInfo> EMPTY_WORD_INFO_LIST = new ArrayList<>(0); private static final ArrayList<SuggestedWordInfo> EMPTY_WORD_INFO_LIST = new ArrayList<>(0);
public static final SuggestedWords EMPTY = new SuggestedWords( private static final SuggestedWords EMPTY = new SuggestedWords(
EMPTY_WORD_INFO_LIST, null /* rawSuggestions */, false /* typedWordValid */, EMPTY_WORD_INFO_LIST, null /* rawSuggestions */, false /* typedWordValid */,
false /* willAutoCorrect */, false /* isObsoleteSuggestions */, INPUT_STYLE_NONE); false /* willAutoCorrect */, false /* isObsoleteSuggestions */, INPUT_STYLE_NONE);
@ -196,6 +196,10 @@ public class SuggestedWords {
return result; return result;
} }
public static final SuggestedWords getEmptyInstance() {
return SuggestedWords.EMPTY;
}
// Should get rid of the first one (what the user typed previously) from suggestions // Should get rid of the first one (what the user typed previously) from suggestions
// and replace it with what the user currently typed. // and replace it with what the user currently typed.
public static ArrayList<SuggestedWordInfo> getTypedWordAndPreviousSuggestions( public static ArrayList<SuggestedWordInfo> getTypedWordAndPreviousSuggestions(

View File

@ -86,7 +86,7 @@ public final class InputLogic {
// Current space state of the input method. This can be any of the above constants. // Current space state of the input method. This can be any of the above constants.
private int mSpaceState; private int mSpaceState;
// Never null // Never null
public SuggestedWords mSuggestedWords = SuggestedWords.EMPTY; public SuggestedWords mSuggestedWords = SuggestedWords.getEmptyInstance();
public final Suggest mSuggest; public final Suggest mSuggest;
private final DictionaryFacilitator mDictionaryFacilitator; private final DictionaryFacilitator mDictionaryFacilitator;
@ -158,7 +158,7 @@ public final class InputLogic {
mSpaceState = SpaceState.NONE; mSpaceState = SpaceState.NONE;
mRecapitalizeStatus.disable(); // Do not perform recapitalize until the cursor is moved once mRecapitalizeStatus.disable(); // Do not perform recapitalize until the cursor is moved once
mCurrentlyPressedHardwareKeys.clear(); mCurrentlyPressedHardwareKeys.clear();
mSuggestedWords = SuggestedWords.EMPTY; mSuggestedWords = SuggestedWords.getEmptyInstance();
// In some cases (namely, after rotation of the device) editorInfo.initialSelStart is lying // In some cases (namely, after rotation of the device) editorInfo.initialSelStart is lying
// so we try using some heuristics to find out about these and fix them. // so we try using some heuristics to find out about these and fix them.
mConnection.tryFixLyingCursorPosition(); mConnection.tryFixLyingCursorPosition();
@ -332,7 +332,7 @@ public final class InputLogic {
// however need to reset the suggestion strip right away, because we know we can't take // however need to reset the suggestion strip right away, because we know we can't take
// the risk of calling commitCompletion twice because we don't know how the app will react. // the risk of calling commitCompletion twice because we don't know how the app will react.
if (suggestionInfo.isKindOf(SuggestedWordInfo.KIND_APP_DEFINED)) { if (suggestionInfo.isKindOf(SuggestedWordInfo.KIND_APP_DEFINED)) {
mSuggestedWords = SuggestedWords.EMPTY; mSuggestedWords = SuggestedWords.getEmptyInstance();
mSuggestionStripViewAccessor.setNeutralSuggestionStrip(); mSuggestionStripViewAccessor.setNeutralSuggestionStrip();
inputTransaction.requireShiftUpdate(InputTransaction.SHIFT_UPDATE_NOW); inputTransaction.requireShiftUpdate(InputTransaction.SHIFT_UPDATE_NOW);
resetComposingState(true /* alsoResetLastComposedWord */); resetComposingState(true /* alsoResetLastComposedWord */);
@ -508,7 +508,7 @@ public final class InputLogic {
final KeyboardSwitcher keyboardSwitcher, final LatinIME.UIHandler handler) { final KeyboardSwitcher keyboardSwitcher, final LatinIME.UIHandler handler) {
mInputLogicHandler.onStartBatchInput(); mInputLogicHandler.onStartBatchInput();
handler.showGesturePreviewAndSuggestionStrip( handler.showGesturePreviewAndSuggestionStrip(
SuggestedWords.EMPTY, false /* dismissGestureFloatingPreviewText */); SuggestedWords.getEmptyInstance(), false /* dismissGestureFloatingPreviewText */);
handler.cancelUpdateSuggestionStrip(); handler.cancelUpdateSuggestionStrip();
++mAutoCommitSequenceNumber; ++mAutoCommitSequenceNumber;
mConnection.beginBatchEdit(); mConnection.beginBatchEdit();
@ -607,14 +607,14 @@ public final class InputLogic {
public void onCancelBatchInput(final LatinIME.UIHandler handler) { public void onCancelBatchInput(final LatinIME.UIHandler handler) {
mInputLogicHandler.onCancelBatchInput(); mInputLogicHandler.onCancelBatchInput();
handler.showGesturePreviewAndSuggestionStrip( handler.showGesturePreviewAndSuggestionStrip(
SuggestedWords.EMPTY, true /* dismissGestureFloatingPreviewText */); SuggestedWords.getEmptyInstance(), true /* dismissGestureFloatingPreviewText */);
} }
// TODO: on the long term, this method should become private, but it will be difficult. // TODO: on the long term, this method should become private, but it will be difficult.
// Especially, how do we deal with InputMethodService.onDisplayCompletions? // Especially, how do we deal with InputMethodService.onDisplayCompletions?
public void setSuggestedWords(final SuggestedWords suggestedWords, public void setSuggestedWords(final SuggestedWords suggestedWords,
final SettingsValues settingsValues, final LatinIME.UIHandler handler) { final SettingsValues settingsValues, final LatinIME.UIHandler handler) {
if (SuggestedWords.EMPTY != suggestedWords) { if (!suggestedWords.isEmpty()) {
final String autoCorrection; final String autoCorrection;
final String dictType; final String dictType;
if (suggestedWords.mWillAutoCorrect) { if (suggestedWords.mWillAutoCorrect) {
@ -1400,7 +1400,7 @@ public final class InputLogic {
+ "requested!"); + "requested!");
} }
// Clear the suggestions strip. // Clear the suggestions strip.
mSuggestionStripViewAccessor.showSuggestionStrip(SuggestedWords.EMPTY); mSuggestionStripViewAccessor.showSuggestionStrip(SuggestedWords.getEmptyInstance());
return; return;
} }
@ -1892,9 +1892,8 @@ public final class InputLogic {
*/ */
private SuggestedWords retrieveOlderSuggestions(final String typedWord, private SuggestedWords retrieveOlderSuggestions(final String typedWord,
final SuggestedWords previousSuggestedWords) { final SuggestedWords previousSuggestedWords) {
final SuggestedWords oldSuggestedWords = final SuggestedWords oldSuggestedWords = previousSuggestedWords.isPunctuationSuggestions()
previousSuggestedWords.isPunctuationSuggestions() ? SuggestedWords.EMPTY ? SuggestedWords.getEmptyInstance() : previousSuggestedWords;
: previousSuggestedWords;
final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions = final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions =
SuggestedWords.getTypedWordAndPreviousSuggestions(typedWord, oldSuggestedWords); SuggestedWords.getTypedWordAndPreviousSuggestions(typedWord, oldSuggestedWords);
return new SuggestedWords(typedWordAndPreviousSuggestions, null /* rawSuggestions */, return new SuggestedWords(typedWordAndPreviousSuggestions, null /* rawSuggestions */,

View File

@ -82,7 +82,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
private final ArrayList<View> mDividerViews = new ArrayList<>(); private final ArrayList<View> mDividerViews = new ArrayList<>();
Listener mListener; Listener mListener;
private SuggestedWords mSuggestedWords = SuggestedWords.EMPTY; private SuggestedWords mSuggestedWords = SuggestedWords.getEmptyInstance();
private int mStartIndexOfMoreSuggestions; private int mStartIndexOfMoreSuggestions;
private final SuggestionStripLayoutHelper mLayoutHelper; private final SuggestionStripLayoutHelper mLayoutHelper;

View File

@ -147,7 +147,7 @@ public class SuggestedWordsTests extends AndroidTestCase {
assertNull(wordsWithoutTypedWord.getTypedWordInfoOrNull()); assertNull(wordsWithoutTypedWord.getTypedWordInfoOrNull());
// Make sure getTypedWordInfoOrNull() returns null. // Make sure getTypedWordInfoOrNull() returns null.
assertNull(SuggestedWords.EMPTY.getTypedWordInfoOrNull()); assertNull(SuggestedWords.getEmptyInstance().getTypedWordInfoOrNull());
final SuggestedWords emptySuggestedWords = new SuggestedWords( final SuggestedWords emptySuggestedWords = new SuggestedWords(
new ArrayList<SuggestedWordInfo>(), null /* rawSuggestions */, new ArrayList<SuggestedWordInfo>(), null /* rawSuggestions */,
@ -157,6 +157,6 @@ public class SuggestedWordsTests extends AndroidTestCase {
SuggestedWords.INPUT_STYLE_NONE); SuggestedWords.INPUT_STYLE_NONE);
assertNull(emptySuggestedWords.getTypedWordInfoOrNull()); assertNull(emptySuggestedWords.getTypedWordInfoOrNull());
assertNull(SuggestedWords.EMPTY.getTypedWordInfoOrNull()); assertNull(SuggestedWords.getEmptyInstance().getTypedWordInfoOrNull());
} }
} }