[IL111] Remove a member.

...and improve encapsulation and readability.

Bug: 8636060
Change-Id: I36407630b307df0721ea7fdb7e7a22cdf2b018b3
main
Jean Chalard 2014-02-26 14:39:51 +09:00
parent f2b0829aa1
commit 32c6d4caea
3 changed files with 30 additions and 22 deletions

View File

@ -124,9 +124,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private View mKeyPreviewBackingView;
private SuggestionStripView mSuggestionStripView;
// TODO[IL]: remove this member completely.
public CompletionInfo[] mApplicationSpecifiedCompletions;
private RichInputMethodManager mRichImm;
@UsedForTesting final KeyboardSwitcher mKeyboardSwitcher;
private final SubtypeSwitcher mSubtypeSwitcher;
@ -812,7 +809,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// The EditorInfo might have a flag that affects fullscreen mode.
// Note: This call should be done by InputMethodService?
updateFullscreenMode();
mApplicationSpecifiedCompletions = null;
// The app calling setText() has the effect of clearing the composing
// span, so we should reset our state unconditionally, even if restarting is true.
@ -1034,8 +1030,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
return;
}
mApplicationSpecifiedCompletions =
CompletionInfoUtils.removeNulls(applicationSpecifiedCompletions);
final ArrayList<SuggestedWords.SuggestedWordInfo> applicationSuggestedWords =
SuggestedWords.getFromApplicationSpecifiedCompletions(

View File

@ -167,15 +167,10 @@ public class SuggestedWords {
final CompletionInfo[] infos) {
final ArrayList<SuggestedWordInfo> result = CollectionUtils.newArrayList();
for (final CompletionInfo info : infos) {
if (info == null) continue;
final CharSequence text = info.getText();
if (null == text) continue;
final SuggestedWordInfo suggestedWordInfo = new SuggestedWordInfo(text.toString(),
SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_APP_DEFINED,
Dictionary.DICTIONARY_APPLICATION_DEFINED,
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */,
SuggestedWordInfo.NOT_A_CONFIDENCE /* autoCommitFirstWordConfidence */);
result.add(suggestedWordInfo);
if (null == info || null == info.getText()) {
continue;
}
result.add(new SuggestedWordInfo(info));
}
return result;
}
@ -234,6 +229,9 @@ public class SuggestedWords {
public static final int KIND_FLAG_EXACT_MATCH = 0x40000000;
public final String mWord;
// The completion info from the application. Null for suggestions that don't come from
// the application (including keyboard-computed ones, so this is almost always null)
public final CompletionInfo mApplicationSpecifiedCompletionInfo;
public final int mScore;
public final int mKind; // one of the KIND_* constants above
public final int mCodePointCount;
@ -260,6 +258,7 @@ public class SuggestedWords {
final Dictionary sourceDict, final int indexOfTouchPointOfSecondWord,
final int autoCommitFirstWordConfidence) {
mWord = word;
mApplicationSpecifiedCompletionInfo = null;
mScore = score;
mKind = kind;
mSourceDict = sourceDict;
@ -268,6 +267,22 @@ public class SuggestedWords {
mAutoCommitFirstWordConfidence = autoCommitFirstWordConfidence;
}
/**
* Create a new suggested word info from an application-specified completion.
* If the passed argument or its contained text is null, this throws a NPE.
* @param applicationSpecifiedCompletion The application-specified completion info.
*/
public SuggestedWordInfo(final CompletionInfo applicationSpecifiedCompletion) {
mWord = applicationSpecifiedCompletion.getText().toString();
mApplicationSpecifiedCompletionInfo = applicationSpecifiedCompletion;
mScore = SuggestedWordInfo.MAX_SCORE;
mKind = SuggestedWordInfo.KIND_APP_DEFINED;
mSourceDict = Dictionary.DICTIONARY_APPLICATION_DEFINED;
mCodePointCount = StringUtils.codePointCount(mWord);
mIndexOfTouchPointOfSecondWord = SuggestedWordInfo.NOT_AN_INDEX;
mAutoCommitFirstWordConfidence = SuggestedWordInfo.NOT_A_CONFIDENCE;
}
public boolean isEligibleForAutoCommit() {
return (KIND_CORRECTION == mKind && NOT_AN_INDEX != mIndexOfTouchPointOfSecondWord);
}

View File

@ -227,17 +227,16 @@ public final class InputLogic {
}
}
// TODO: stop relying on mApplicationSpecifiedCompletions. The SuggestionInfo object
// should contain a reference to the CompletionInfo instead.
if (settingsValues.isApplicationSpecifiedCompletionsOn()
&& mLatinIME.mApplicationSpecifiedCompletions != null
&& index >= 0 && index < mLatinIME.mApplicationSpecifiedCompletions.length) {
// TODO: We should not need the following branch. We should be able to take the same
// code path as for other kinds, use commitChosenWord, and do everything normally. We will
// 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.
if (SuggestedWordInfo.KIND_APP_DEFINED == suggestionInfo.mKind) {
mSuggestedWords = SuggestedWords.EMPTY;
mSuggestionStripViewAccessor.setNeutralSuggestionStrip();
keyboardSwitcher.updateShiftState();
resetComposingState(true /* alsoResetLastComposedWord */);
final CompletionInfo completionInfo = mLatinIME.mApplicationSpecifiedCompletions[index];
mConnection.commitCompletion(completionInfo);
mConnection.commitCompletion(suggestionInfo.mApplicationSpecifiedCompletionInfo);
mConnection.endBatchEdit();
return;
}