aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/CandidateView.java
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2011-08-26 15:13:30 +0900
committerTadashi G. Takaoka <takaoka@google.com>2011-08-26 18:55:36 +0900
commitc04bbc1ae9be81d25a356407c27a8e7fa22028bf (patch)
tree9091618999ca52760809337be5913a3e6dca3168 /java/src/com/android/inputmethod/latin/CandidateView.java
parentde4e8dedccc7b6db6df4c3f75d9f2458432c558a (diff)
downloadlatinime-c04bbc1ae9be81d25a356407c27a8e7fa22028bf.tar.gz
latinime-c04bbc1ae9be81d25a356407c27a8e7fa22028bf.tar.xz
latinime-c04bbc1ae9be81d25a356407c27a8e7fa22028bf.zip
Fix "touch to save" colors
Bug: 5218662 Change-Id: I094b2ceb7438148eb5bdf620b188f598e8442a07
Diffstat (limited to 'java/src/com/android/inputmethod/latin/CandidateView.java')
-rw-r--r--java/src/com/android/inputmethod/latin/CandidateView.java93
1 files changed, 62 insertions, 31 deletions
diff --git a/java/src/com/android/inputmethod/latin/CandidateView.java b/java/src/com/android/inputmethod/latin/CandidateView.java
index 5f20c70b4..85870f38e 100644
--- a/java/src/com/android/inputmethod/latin/CandidateView.java
+++ b/java/src/com/android/inputmethod/latin/CandidateView.java
@@ -76,13 +76,9 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
private final PopupWindow mPreviewPopup;
private final TextView mPreviewText;
- private final View mTouchToSave;
- private final TextView mWordToSave;
-
private Listener mListener;
private SuggestedWords mSuggestions = SuggestedWords.EMPTY;
private boolean mShowingAutoCorrectionInverted;
- private boolean mShowingAddToDictionary;
private final SuggestionsStripParams mStripParams;
private final SuggestionsPaneParams mPaneParams;
@@ -94,7 +90,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
private static final int MSG_HIDE_PREVIEW = 0;
private static final int MSG_UPDATE_SUGGESTION = 1;
- private static final long DELAY_HIDE_PREVIEW = 1000;
+ private static final long DELAY_HIDE_PREVIEW = 1300;
private static final long DELAY_UPDATE_SUGGESTION = 300;
public UiHandler(CandidateView outerInstance) {
@@ -274,13 +270,16 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
private static final int AUTO_CORRECT_INVERT = 0x04;
private static final int VALID_TYPED_WORD_BOLD = 0x08;
- private final TextPaint mPaint;
private final int mSuggestionStripOption;
private final ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>();
public boolean mMoreSuggestionsAvailable;
+ public final TextView mWordToSaveView;
+ private final TextView mHintToSaveView;
+ private final CharSequence mHintToSaveText;
+
public SuggestionsStripParams(Context context, AttributeSet attrs, int defStyle,
List<TextView> words, List<View> dividers, List<TextView> infos) {
super(words, dividers, infos);
@@ -305,9 +304,10 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
mInvertedForegroundColorSpan = new ForegroundColorSpan(mColorTypedWord ^ 0x00ffffff);
mInvertedBackgroundColorSpan = new BackgroundColorSpan(mColorTypedWord);
- mPaint = new TextPaint();
- final float textSize = res.getDimension(R.dimen.candidate_text_size);
- mPaint.setTextSize(textSize);
+ final LayoutInflater inflater = LayoutInflater.from(context);
+ mWordToSaveView = (TextView)inflater.inflate(R.layout.candidate_word, null);
+ mHintToSaveView = (TextView)inflater.inflate(R.layout.candidate_word, null);
+ mHintToSaveText = context.getText(R.string.hint_add_to_dictionary);
}
public int getTextColor() {
@@ -498,6 +498,33 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
mMoreSuggestionsAvailable = false;
return countInStrip;
}
+
+ public void layoutAddToDictionaryHint(CharSequence word, ViewGroup stripView,
+ int stripWidth) {
+ final int width = stripWidth - mDividerWidth - mPadding * 2;
+
+ final TextView wordView = mWordToSaveView;
+ wordView.setTextColor(mColorTypedWord);
+ final int wordWidth = (int)(width * mCenterCandidateWeight);
+ final CharSequence text = getEllipsizedText(word, wordWidth, wordView.getPaint());
+ final float wordScaleX = wordView.getTextScaleX();
+ wordView.setTag(word);
+ wordView.setText(text);
+ wordView.setTextScaleX(wordScaleX);
+ stripView.addView(wordView);
+ setLayoutWeight(wordView, mCenterCandidateWeight, MATCH_PARENT);
+
+ stripView.addView(mDividers.get(0));
+
+ final TextView hintView = mHintToSaveView;
+ hintView.setTextColor(mColorAutoCorrect);
+ final int hintWidth = width - wordWidth;
+ final float hintScaleX = getTextScaleX(mHintToSaveText, hintWidth, hintView.getPaint());
+ hintView.setText(mHintToSaveText);
+ hintView.setTextScaleX(hintScaleX);
+ stripView.addView(hintView);
+ setLayoutWeight(hintView, 1.0f - mCenterCandidateWeight, MATCH_PARENT);
+ }
}
/**
@@ -517,7 +544,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
super(context, attrs);
if (defStyle != R.attr.candidateViewStyle) {
throw new IllegalArgumentException(
- "can't accept defStyle other than R.attr.candidayeViewStyle: defStyle="
+ "can't accept defStyle other than R.attr.candidateViewStyle: defStyle="
+ defStyle);
}
setBackgroundDrawable(LinearLayoutCompatUtils.getBackgroundDrawable(
@@ -546,13 +573,10 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
mInfos.add((TextView)inflater.inflate(R.layout.candidate_info, null));
}
- mTouchToSave = findViewById(R.id.touch_to_save);
- mWordToSave = (TextView)findViewById(R.id.word_to_save);
- mWordToSave.setOnClickListener(this);
-
mStripParams = new SuggestionsStripParams(context, attrs, defStyle, mWords, mDividers,
mInfos);
mPaneParams = new SuggestionsPaneParams(mWords, mDividers, mInfos);
+ mStripParams.mWordToSaveView.setOnClickListener(this);
}
/**
@@ -636,6 +660,15 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
}
}
+ private static float getTextScaleX(CharSequence text, int maxWidth, TextPaint paint) {
+ paint.setTextScaleX(1.0f);
+ final int width = getTextWidth(text, paint);
+ if (width <= maxWidth) {
+ return 1.0f;
+ }
+ return maxWidth / (float)width;
+ }
+
private static CharSequence getEllipsizedText(CharSequence text, int maxWidth,
TextPaint paint) {
if (text == null) return null;
@@ -718,20 +751,21 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
}
public boolean isShowingAddToDictionaryHint() {
- return mShowingAddToDictionary;
+ return mCandidatesStrip.getChildCount() > 0
+ && mCandidatesStrip.getChildAt(0) == mStripParams.mWordToSaveView;
}
public void showAddToDictionaryHint(CharSequence word) {
- mWordToSave.setText(word);
- mShowingAddToDictionary = true;
- mCandidatesStrip.setVisibility(GONE);
- mTouchToSave.setVisibility(VISIBLE);
+ clear();
+ mStripParams.layoutAddToDictionaryHint(word, mCandidatesStrip, getWidth());
}
public boolean dismissAddToDictionaryHint() {
- if (!mShowingAddToDictionary) return false;
- clear();
- return true;
+ if (isShowingAddToDictionaryHint()) {
+ clear();
+ return true;
+ }
+ return false;
}
public SuggestedWords getSuggestions() {
@@ -739,10 +773,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
}
public void clear() {
- mShowingAddToDictionary = false;
mShowingAutoCorrectionInverted = false;
- mTouchToSave.setVisibility(GONE);
- mCandidatesStrip.setVisibility(VISIBLE);
mCandidatesStrip.removeAllViews();
mCandidatesPane.removeAllViews();
closeCandidatesPane();
@@ -752,7 +783,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
mPreviewPopup.dismiss();
}
- private void showPreview(int index, CharSequence word) {
+ private void showPreview(View view, CharSequence word) {
if (TextUtils.isEmpty(word))
return;
@@ -761,9 +792,8 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
previewText.setText(word);
previewText.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
- View v = mWords.get(index);
final int[] offsetInWindow = new int[2];
- v.getLocationInWindow(offsetInWindow);
+ view.getLocationInWindow(offsetInWindow);
final int posX = offsetInWindow[0];
final int posY = offsetInWindow[1] - previewText.getMeasuredHeight();
final PopupWindow previewPopup = mPreviewPopup;
@@ -778,7 +808,8 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
private void addToDictionary(CharSequence word) {
if (mListener.addWordToDictionary(word.toString())) {
- showPreview(0, getContext().getString(R.string.added_word, word));
+ final CharSequence message = getContext().getString(R.string.added_word, word);
+ showPreview(mStripParams.mWordToSaveView, message);
}
}
@@ -793,8 +824,8 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo
@Override
public void onClick(View view) {
- if (view == mWordToSave) {
- addToDictionary(((TextView)view).getText());
+ if (view == mStripParams.mWordToSaveView) {
+ addToDictionary((CharSequence)view.getTag());
clear();
return;
}