aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rw-r--r--java/res/drawable-hdpi/keyboard_popup_panel_background_holo.9.pngbin4047 -> 0 bytes
-rw-r--r--java/res/drawable-mdpi/keyboard_popup_panel_background_holo.9.pngbin3730 -> 0 bytes
-rw-r--r--java/res/layout/candidates_strip.xml31
-rw-r--r--java/res/values/styles.xml89
-rw-r--r--java/src/com/android/inputmethod/latin/CandidateView.java93
5 files changed, 133 insertions, 80 deletions
diff --git a/java/res/drawable-hdpi/keyboard_popup_panel_background_holo.9.png b/java/res/drawable-hdpi/keyboard_popup_panel_background_holo.9.png
deleted file mode 100644
index 4002dbe65..000000000
--- a/java/res/drawable-hdpi/keyboard_popup_panel_background_holo.9.png
+++ /dev/null
Binary files differ
diff --git a/java/res/drawable-mdpi/keyboard_popup_panel_background_holo.9.png b/java/res/drawable-mdpi/keyboard_popup_panel_background_holo.9.png
deleted file mode 100644
index 7be7ab7e2..000000000
--- a/java/res/drawable-mdpi/keyboard_popup_panel_background_holo.9.png
+++ /dev/null
Binary files differ
diff --git a/java/res/layout/candidates_strip.xml b/java/res/layout/candidates_strip.xml
index bcc1322b6..46cd691a7 100644
--- a/java/res/layout/candidates_strip.xml
+++ b/java/res/layout/candidates_strip.xml
@@ -25,35 +25,6 @@
<LinearLayout
android:id="@+id/candidates_strip"
android:orientation="horizontal"
- android:layout_weight="1.0"
- android:layout_width="0dp"
- android:layout_height="match_parent" />
- <LinearLayout
- android:id="@+id/touch_to_save"
- android:orientation="horizontal"
android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:visibility="gone"
- >
- <Button
- android:id="@+id/word_to_save"
- android:layout_weight="1.0"
- android:layout_width="0dp"
- android:layout_height="match_parent"
- android:layout_gravity="center_vertical"
- android:textSize="@dimen/candidate_text_size"
- android:singleLine="true"
- android:ellipsize="middle"
- style="?attr/suggestionBackgroundStyle" />
- <include
- layout="@layout/candidate_divider" />
- <TextView
- android:layout_weight="2.0"
- android:layout_width="0dp"
- android:layout_height="match_parent"
- android:gravity="left|center_vertical"
- android:text="@string/hint_add_to_dictionary"
- android:textSize="@dimen/candidate_text_size"
- android:background="@null" />
- </LinearLayout>
+ android:layout_height="match_parent" />
</merge>
diff --git a/java/res/values/styles.xml b/java/res/values/styles.xml
index cb9edb0b8..7936f3c3c 100644
--- a/java/res/values/styles.xml
+++ b/java/res/values/styles.xml
@@ -29,7 +29,8 @@
<item name="maxPopupKeyboardColumn">@integer/config_max_popup_keyboard_column</item>
</style>
<style name="LatinKeyboard">
- <item name="autoCorrectionSpacebarLedEnabled">@bool/config_auto_correction_spacebar_led_enabled</item>
+ <item name="autoCorrectionSpacebarLedEnabled">@bool/config_auto_correction_spacebar_led_enabled
+ </item>
<item name="spacebarTextColor">#FFC0C0C0</item>
<item name="spacebarTextShadowColor">#80000000</item>
</style>
@@ -66,7 +67,10 @@
<item name="shadowRadius">2.75</item>
<item name="backgroundDimAmount">0.5</item>
</style>
- <style name="PopupMiniKeyboardView" parent="KeyboardView">
+ <style
+ name="PopupMiniKeyboardView"
+ parent="KeyboardView"
+ >
<item name="keyBackground">@drawable/btn_keyboard_key_popup</item>
<item name="verticalCorrection">@dimen/mini_keyboard_vertical_correction</item>
</style>
@@ -84,7 +88,10 @@
<style name="SuggestionPreviewBackgroundStyle">
<item name="android:background">@drawable/candidate_feedback_background</item>
</style>
- <style name="CandidateViewStyle" parent="SuggestionsStripBackgroundStyle">
+ <style
+ name="CandidateViewStyle"
+ parent="SuggestionsStripBackgroundStyle"
+ >
<item name="suggestionStripOption">autoCorrectBold</item>
<item name="colorTypedWord">#FFFFFFFF</item>
<item name="colorAutoCorrect">#FFFCAE00</item>
@@ -93,23 +100,35 @@
<item name="centerCandidatePercentile">@integer/center_candidate_percentile</item>
</style>
<!-- Theme "Basic high contrast" -->
- <style name="KeyboardView.HighContrast" parent="KeyboardView">
+ <style
+ name="KeyboardView.HighContrast"
+ parent="KeyboardView"
+ >
<item name="android:background">@android:color/black</item>
<item name="keyBackground">@drawable/btn_keyboard_key3</item>
</style>
<!-- Theme "Stone" -->
- <style name="Keyboard.Stone" parent="Keyboard">
+ <style
+ name="Keyboard.Stone"
+ parent="Keyboard"
+ >
<item name="keyboardHeight">@dimen/keyboardHeight_stone</item>
<item name="keyboardTopPadding">@fraction/keyboard_top_padding_stone</item>
<item name="keyboardBottomPadding">@fraction/keyboard_bottom_padding_stone</item>
<item name="horizontalGap">@fraction/key_horizontal_gap_stone</item>
<item name="verticalGap">@fraction/key_bottom_gap_stone</item>
</style>
- <style name="LatinKeyboard.Stone" parent="LatinKeyboard">
+ <style
+ name="LatinKeyboard.Stone"
+ parent="LatinKeyboard"
+ >
<item name="spacebarTextColor">#FF000000</item>
<item name="spacebarTextShadowColor">#D0FFFFFF</item>
</style>
- <style name="KeyboardView.Stone" parent="KeyboardView">
+ <style
+ name="KeyboardView.Stone"
+ parent="KeyboardView"
+ >
<item name="keyBackground">@drawable/btn_keyboard_key_stone</item>
<item name="keyTextColor">#FF000000</item>
<item name="keyTextInactivatedColor">#FF808080</item>
@@ -119,39 +138,63 @@
<item name="keyUppercaseLetterActivatedColor">#CC000000</item>
<item name="shadowColor">#FFFFFFFF</item>
</style>
- <style name="PopupMiniKeyboardView.Stone" parent="PopupMiniKeyboardView">
+ <style
+ name="PopupMiniKeyboardView.Stone"
+ parent="PopupMiniKeyboardView"
+ >
<item name="keyBackground">@drawable/btn_keyboard_key_stone</item>
<item name="keyTextColor">#FF000000</item>
<item name="shadowColor">#FFFFFFFF</item>
</style>
<!-- Theme "Stone bold" -->
- <style name="KeyboardView.Stone.Bold" parent="KeyboardView.Stone">
+ <style
+ name="KeyboardView.Stone.Bold"
+ parent="KeyboardView.Stone"
+ >
<item name="keyTextStyle">bold</item>
</style>
<!-- Theme "Gingerbread" -->
- <style name="Keyboard.Gingerbread" parent="Keyboard">
+ <style
+ name="Keyboard.Gingerbread"
+ parent="Keyboard"
+ >
<item name="horizontalGap">@fraction/key_horizontal_gap_gb</item>
<item name="verticalGap">@fraction/key_bottom_gap_gb</item>
</style>
- <style name="KeyboardView.Gingerbread" parent="KeyboardView">
+ <style
+ name="KeyboardView.Gingerbread"
+ parent="KeyboardView"
+ >
<item name="android:background">@drawable/keyboard_dark_background</item>
<item name="keyBackground">@drawable/btn_keyboard_key_gingerbread</item>
<item name="keyTextStyle">bold</item>
</style>
- <style name="PopupMiniKeyboardView.Gingerbread" parent="PopupMiniKeyboardView">
+ <style
+ name="PopupMiniKeyboardView.Gingerbread"
+ parent="PopupMiniKeyboardView"
+ >
<item name="android:background">@null</item>
</style>
<!-- Theme "IceCreamSandwich" -->
- <style name="Keyboard.IceCreamSandwich" parent="Keyboard" >
+ <style
+ name="Keyboard.IceCreamSandwich"
+ parent="Keyboard"
+ >
<item name="keyboardTopPadding">@fraction/keyboard_top_padding_ics</item>
<item name="keyboardBottomPadding">@fraction/keyboard_bottom_padding_ics</item>
<item name="horizontalGap">@fraction/key_horizontal_gap_ics</item>
<item name="verticalGap">@fraction/key_bottom_gap_ics</item>
</style>
- <style name="LatinKeyboard.IceCreamSandwich" parent="LatinKeyboard">
+ <style
+ name="LatinKeyboard.IceCreamSandwich"
+ parent="LatinKeyboard"
+ >
<item name="disabledShortcutIcon">@drawable/sym_keyboard_voice_off_holo</item>
</style>
- <style name="KeyboardView.IceCreamSandwich" parent="KeyboardView">
+ <style
+ name="KeyboardView.IceCreamSandwich"
+ parent="KeyboardView"
+ >
<item name="android:background">@drawable/keyboard_background_holo</item>
<item name="keyBackground">@drawable/btn_keyboard_key_ics</item>
<item name="keyTextStyle">bold</item>
@@ -169,7 +212,10 @@
<item name="shadowColor">#00000000</item>
<item name="shadowRadius">0.0</item>
</style>
- <style name="PopupMiniKeyboardView.IceCreamSandwich" parent="PopupMiniKeyboardView">
+ <style
+ name="PopupMiniKeyboardView.IceCreamSandwich"
+ parent="PopupMiniKeyboardView"
+ >
<item name="android:background">@null</item>
<item name="keyBackground">@drawable/btn_keyboard_key_popup_ics</item>
</style>
@@ -184,10 +230,15 @@
<style name="SuggestionBackgroundStyle.IceCreamSandwich">
<item name="android:background">@drawable/btn_candidate_ics</item>
</style>
- <style name="SuggestionPreviewBackgroundStyle.IceCreamSandwich">
- <item name="android:background">@drawable/keyboard_popup_panel_background_holo</item>
+ <style
+ name="SuggestionPreviewBackgroundStyle.IceCreamSandwich"
+ parent="PopupMiniKeyboardPanelStyle.IceCreamSandwich"
+ >
</style>
- <style name="CandidateViewStyle.IceCreamSandwich" parent="SuggestionsStripBackgroundStyle.IceCreamSandwich">
+ <style
+ name="CandidateViewStyle.IceCreamSandwich"
+ parent="SuggestionsStripBackgroundStyle.IceCreamSandwich"
+ >
<item name="suggestionStripOption">autoCorrectBold|validTypedWordBold</item>
<item name="colorTypedWord">#FFBCBEC0</item>
<item name="colorAutoCorrect">#FF0099CC</item>
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;
}