am 15a7e837: Merge "Dim previously suggested words" into honeycomb

* commit '15a7e837ab619df1e3844cd59b337c6ac56a0daf':
  Dim previously suggested words
main
satok 2011-01-20 22:23:45 -08:00 committed by Android Git Automerger
commit 1869d13742
5 changed files with 97 additions and 42 deletions

View File

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

View File

@ -1519,7 +1519,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mKeyboardSwitcher.setPreferredLetters(nextLettersFrequencies); mKeyboardSwitcher.setPreferredLetters(nextLettersFrequencies);
boolean correctionAvailable = !mInputTypeNoAutoCorrect && !mJustReverted boolean correctionAvailable = !mInputTypeNoAutoCorrect && !mJustReverted
&& mSuggest.hasMinimalCorrection(); && mSuggest.hasAutoCorrection();
final CharSequence typedWord = word.getTypedWord(); final CharSequence typedWord = word.getTypedWord();
// If we're in basic correct // If we're in basic correct
final boolean typedWordValid = mSuggest.isValidWord(typedWord) || 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>(); private ArrayList<CharSequence> mSuggestions = new ArrayList<CharSequence>();
ArrayList<CharSequence> mBigramSuggestions = new ArrayList<CharSequence>(); ArrayList<CharSequence> mBigramSuggestions = new ArrayList<CharSequence>();
private ArrayList<CharSequence> mStringPool = new ArrayList<CharSequence>(); private ArrayList<CharSequence> mStringPool = new ArrayList<CharSequence>();
private boolean mHaveAutoCorrection; private boolean mHasAutoCorrection;
private String mLowerOriginalWord; private String mLowerOriginalWord;
// TODO: Remove these member variables by passing more context to addWord() callback method // 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, public SuggestedWords.Builder getSuggestedWordBuilder(View view, WordComposer wordComposer,
CharSequence prevWordForBigram) { CharSequence prevWordForBigram) {
LatinImeLogger.onStartSuggestion(prevWordForBigram); LatinImeLogger.onStartSuggestion(prevWordForBigram);
mHaveAutoCorrection = false; mHasAutoCorrection = false;
mIsFirstCharCapitalized = wordComposer.isFirstCharCapitalized(); mIsFirstCharCapitalized = wordComposer.isFirstCharCapitalized();
mIsAllUpperCase = wordComposer.isAllUpperCase(); mIsAllUpperCase = wordComposer.isAllUpperCase();
collectGarbage(mSuggestions, mPrefMaxSuggestions); collectGarbage(mSuggestions, mPrefMaxSuggestions);
@ -278,7 +278,7 @@ public class Suggest implements Dictionary.WordCallback {
if (DBG) { if (DBG) {
Log.d(TAG, "Auto corrected by CORRECTION_FULL."); Log.d(TAG, "Auto corrected by CORRECTION_FULL.");
} }
mHaveAutoCorrection = true; mHasAutoCorrection = true;
} }
} }
if (mMainDict != null) mMainDict.getWords(wordComposer, this, mNextLettersFrequencies); if (mMainDict != null) mMainDict.getWords(wordComposer, this, mNextLettersFrequencies);
@ -297,7 +297,7 @@ public class Suggest implements Dictionary.WordCallback {
if (DBG) { if (DBG) {
Log.d(TAG, "Auto corrected by S-threthhold."); Log.d(TAG, "Auto corrected by S-threthhold.");
} }
mHaveAutoCorrection = true; mHasAutoCorrection = true;
} }
} }
} }
@ -342,7 +342,7 @@ public class Suggest implements Dictionary.WordCallback {
if (DBG) { if (DBG) {
Log.d(TAG, "Auto corrected by AUTOTEXT."); Log.d(TAG, "Auto corrected by AUTOTEXT.");
} }
mHaveAutoCorrection = true; mHasAutoCorrection = true;
mSuggestions.add(i + 1, autoText); mSuggestions.add(i + 1, autoText);
i++; i++;
} }
@ -350,7 +350,7 @@ public class Suggest implements Dictionary.WordCallback {
} }
} }
removeDupes(); removeDupes();
return new SuggestedWords.Builder().addWords(mSuggestions); return new SuggestedWords.Builder().addWords(mSuggestions, null);
} }
public int[] getNextLettersFrequencies() { public int[] getNextLettersFrequencies() {
@ -384,8 +384,8 @@ public class Suggest implements Dictionary.WordCallback {
} }
} }
public boolean hasMinimalCorrection() { public boolean hasAutoCorrection() {
return mHaveAutoCorrection; return mHasAutoCorrection;
} }
private boolean compareCaseInsensitive(final String mLowerOriginalWord, private boolean compareCaseInsensitive(final String mLowerOriginalWord,

View File

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