Merge "Dim previously suggested words" into honeycomb

main
satok 2011-01-20 22:22:13 -08:00 committed by Android (Google) Code Review
commit 15a7e837ab
5 changed files with 97 additions and 42 deletions

View File

@ -16,8 +16,11 @@
package com.android.inputmethod.latin;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Handler;
import android.os.Message;
@ -43,6 +46,7 @@ import android.widget.PopupWindow;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
public class CandidateView extends LinearLayout implements OnClickListener, OnLongClickListener {
@ -50,6 +54,8 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
private static final CharacterStyle UNDERLINE_SPAN = new UnderlineSpan();
private static final int MAX_SUGGESTIONS = 16;
private static boolean DBG = LatinImeLogger.sDBG;
private final ArrayList<View> mWords = new ArrayList<View>();
private final boolean mConfigCandidateHighlightFontColorEnabled;
private final CharacterStyle mInvertedForegroundColorSpan;
@ -175,11 +181,12 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
final SuggestedWords suggestions = mSuggestions;
clear();
final int count = suggestions.size();
final Object[] debugInfo = suggestions.mDebugInfo;
for (int i = 0; i < count; i++) {
CharSequence word = suggestions.getWord(i);
if (word == null) continue;
final int wordLength = word.length();
final List<SuggestedWordInfo> suggestedWordInfoList =
suggestions.mSuggestedWordInfoList;
final View v = mWords.get(i);
final TextView tv = (TextView)v.findViewById(R.id.candidate_word);
@ -209,10 +216,21 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
}
tv.setText(word);
tv.setClickable(true);
if (debugInfo != null && i < debugInfo.length && debugInfo[i] != null
&& !TextUtils.isEmpty(debugInfo[i].toString())) {
dv.setText(debugInfo[i].toString());
dv.setVisibility(VISIBLE);
if (suggestedWordInfoList != null && suggestedWordInfoList.get(i) != null) {
final SuggestedWordInfo info = suggestedWordInfoList.get(i);
if (info.isPreviousSuggestedWord()) {
int color = tv.getCurrentTextColor();
tv.setTextColor(Color.argb((int)(Color.alpha(color) * 0.5f), Color.red(color),
Color.green(color), Color.blue(color)));
}
final String debugString = info.getDebugString();
if (DBG) {
if (!TextUtils.isEmpty(debugString)) {
dv.setText(debugString);
dv.setVisibility(VISIBLE);
}
}
} else {
dv.setVisibility(GONE);
}

View File

@ -1519,7 +1519,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mKeyboardSwitcher.setPreferredLetters(nextLettersFrequencies);
boolean correctionAvailable = !mInputTypeNoAutoCorrect && !mJustReverted
&& mSuggest.hasMinimalCorrection();
&& mSuggest.hasAutoCorrection();
final CharSequence typedWord = word.getTypedWord();
// If we're in basic correct
final boolean typedWordValid = mSuggest.isValidWord(typedWord) ||

View File

@ -95,7 +95,7 @@ public class Suggest implements Dictionary.WordCallback {
private ArrayList<CharSequence> mSuggestions = new ArrayList<CharSequence>();
ArrayList<CharSequence> mBigramSuggestions = new ArrayList<CharSequence>();
private ArrayList<CharSequence> mStringPool = new ArrayList<CharSequence>();
private boolean mHaveAutoCorrection;
private boolean mHasAutoCorrection;
private String mLowerOriginalWord;
// TODO: Remove these member variables by passing more context to addWord() callback method
@ -200,7 +200,7 @@ public class Suggest implements Dictionary.WordCallback {
public SuggestedWords.Builder getSuggestedWordBuilder(View view, WordComposer wordComposer,
CharSequence prevWordForBigram) {
LatinImeLogger.onStartSuggestion(prevWordForBigram);
mHaveAutoCorrection = false;
mHasAutoCorrection = false;
mIsFirstCharCapitalized = wordComposer.isFirstCharCapitalized();
mIsAllUpperCase = wordComposer.isAllUpperCase();
collectGarbage(mSuggestions, mPrefMaxSuggestions);
@ -278,7 +278,7 @@ public class Suggest implements Dictionary.WordCallback {
if (DBG) {
Log.d(TAG, "Auto corrected by CORRECTION_FULL.");
}
mHaveAutoCorrection = true;
mHasAutoCorrection = true;
}
}
if (mMainDict != null) mMainDict.getWords(wordComposer, this, mNextLettersFrequencies);
@ -297,7 +297,7 @@ public class Suggest implements Dictionary.WordCallback {
if (DBG) {
Log.d(TAG, "Auto corrected by S-threthhold.");
}
mHaveAutoCorrection = true;
mHasAutoCorrection = true;
}
}
}
@ -342,7 +342,7 @@ public class Suggest implements Dictionary.WordCallback {
if (DBG) {
Log.d(TAG, "Auto corrected by AUTOTEXT.");
}
mHaveAutoCorrection = true;
mHasAutoCorrection = true;
mSuggestions.add(i + 1, autoText);
i++;
}
@ -350,7 +350,7 @@ public class Suggest implements Dictionary.WordCallback {
}
}
removeDupes();
return new SuggestedWords.Builder().addWords(mSuggestions);
return new SuggestedWords.Builder().addWords(mSuggestions, null);
}
public int[] getNextLettersFrequencies() {
@ -384,8 +384,8 @@ public class Suggest implements Dictionary.WordCallback {
}
}
public boolean hasMinimalCorrection() {
return mHaveAutoCorrection;
public boolean hasAutoCorrection() {
return mHasAutoCorrection;
}
private boolean compareCaseInsensitive(final String mLowerOriginalWord,

View File

@ -29,10 +29,11 @@ public class SuggestedWords {
public final boolean mIsApplicationSpecifiedCompletions;
public final boolean mTypedWordValid;
public final boolean mHasMinimalSuggestion;
public final Object[] mDebugInfo;
public final List<SuggestedWordInfo> mSuggestedWordInfoList;
private SuggestedWords(List<CharSequence> words, boolean isApplicationSpecifiedCompletions,
boolean typedWordValid, boolean hasMinamlSuggestion, Object[] debugInfo) {
boolean typedWordValid, boolean hasMinamlSuggestion,
List<SuggestedWordInfo> suggestedWordInfoList) {
if (words != null) {
mWords = words;
} else {
@ -41,7 +42,7 @@ public class SuggestedWords {
mIsApplicationSpecifiedCompletions = isApplicationSpecifiedCompletions;
mTypedWordValid = typedWordValid;
mHasMinimalSuggestion = hasMinamlSuggestion;
mDebugInfo = debugInfo;
mSuggestedWordInfoList = suggestedWordInfoList;
}
public int size() {
@ -61,38 +62,46 @@ public class SuggestedWords {
}
public static class Builder {
private List<CharSequence> mWords;
private List<CharSequence> mWords = new ArrayList<CharSequence>();
private boolean mIsCompletions;
private boolean mTypedWordValid;
private boolean mHasMinimalSuggestion;
private Object[] mDebugInfo;
private List<SuggestedWordInfo> mSuggestedWordInfoList =
new ArrayList<SuggestedWordInfo>();
public Builder() {
// Nothing to do here.
}
public Builder addWords(List<CharSequence> words) {
for (final CharSequence word : words)
addWord(word);
return this;
}
public Builder setDebugInfo(Object[] debuginfo) {
mDebugInfo = debuginfo;
return this;
}
public Builder addWord(int pos, CharSequence word) {
if (mWords == null)
mWords = new ArrayList<CharSequence>();
mWords.add(pos, word);
public Builder addWords(List<CharSequence> words,
List<SuggestedWordInfo> suggestedWordInfoList) {
final int N = words.size();
for (int i = 0; i < N; ++i) {
SuggestedWordInfo suggestedWordInfo = null;
if (suggestedWordInfoList != null) {
suggestedWordInfo = suggestedWordInfoList.get(i);
}
if (suggestedWordInfo == null) {
suggestedWordInfo = new SuggestedWordInfo();
}
addWord(words.get(i), suggestedWordInfo);
}
return this;
}
public Builder addWord(CharSequence word) {
if (mWords == null)
mWords = new ArrayList<CharSequence>();
return addWord(word, null, false);
}
public Builder addWord(CharSequence word, CharSequence debugString,
boolean isPreviousSuggestedWord) {
SuggestedWordInfo info = new SuggestedWordInfo(debugString, isPreviousSuggestedWord);
return addWord(word, info);
}
private Builder addWord(CharSequence word, SuggestedWordInfo suggestedWordInfo) {
mWords.add(word);
mSuggestedWordInfoList.add(suggestedWordInfo);
return this;
}
@ -117,11 +126,12 @@ public class SuggestedWords {
// and replace it with what the user currently typed.
public Builder addTypedWordAndPreviousSuggestions(CharSequence typedWord,
SuggestedWords previousSuggestions) {
if (mWords != null) mWords.clear();
addWord(typedWord);
mWords.clear();
mSuggestedWordInfoList.clear();
addWord(typedWord, null, false);
final int previousSize = previousSuggestions.size();
for (int pos = 1; pos < previousSize; pos++)
addWord(previousSuggestions.getWord(pos));
addWord(previousSuggestions.getWord(pos), null, true);
mIsCompletions = false;
mTypedWordValid = false;
mHasMinimalSuggestion = false;
@ -130,15 +140,42 @@ public class SuggestedWords {
public SuggestedWords build() {
return new SuggestedWords(mWords, mIsCompletions, mTypedWordValid,
mHasMinimalSuggestion, mDebugInfo);
mHasMinimalSuggestion, mSuggestedWordInfoList);
}
public int size() {
return mWords == null ? 0 : mWords.size();
return mWords.size();
}
public CharSequence getWord(int pos) {
return mWords.get(pos);
}
}
public static class SuggestedWordInfo {
private final CharSequence mDebugString;
private final boolean mPreviousSuggestedWord;
public SuggestedWordInfo() {
mDebugString = "";
mPreviousSuggestedWord = false;
}
public SuggestedWordInfo(CharSequence debugString, boolean previousSuggestedWord) {
mDebugString = debugString;
mPreviousSuggestedWord = previousSuggestedWord;
}
public String getDebugString() {
if (mDebugString == null) {
return "";
} else {
return mDebugString.toString();
}
}
public boolean isPreviousSuggestedWord () {
return mPreviousSuggestedWord;
}
}
}

View File

@ -437,7 +437,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
builder.addWord(word);
}
} else {
builder.addWords(suggestions);
builder.addWords(suggestions, null);
}
builder.setTypedWordValid(true).setHasMinimalSuggestion(true);
mService.setSuggestions(builder.build());