aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/SuggestionsView.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/SuggestionsView.java')
-rw-r--r--java/src/com/android/inputmethod/latin/SuggestionsView.java62
1 files changed, 54 insertions, 8 deletions
diff --git a/java/src/com/android/inputmethod/latin/SuggestionsView.java b/java/src/com/android/inputmethod/latin/SuggestionsView.java
index 13beb4479..fbb277372 100644
--- a/java/src/com/android/inputmethod/latin/SuggestionsView.java
+++ b/java/src/com/android/inputmethod/latin/SuggestionsView.java
@@ -19,8 +19,14 @@ package com.android.inputmethod.latin;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.Paint.Align;
+import android.graphics.Rect;
import android.graphics.Typeface;
+import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Message;
import android.os.SystemClock;
@@ -167,6 +173,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
private final float mCenterSuggestionWeight;
private final int mCenterSuggestionIndex;
private final Drawable mMoreSuggestionsHint;
+ private static final String MORE_SUGGESTIONS_HINT = "\u2026";
private static final CharacterStyle BOLD_SPAN = new StyleSpan(Typeface.BOLD);
private static final CharacterStyle UNDERLINE_SPAN = new UnderlineSpan();
@@ -225,7 +232,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
mCenterSuggestionWeight = getPercent(a,
R.styleable.SuggestionsView_centerSuggestionPercentile,
DEFAULT_CENTER_SUGGESTION_PERCENTILE);
- mMoreSuggestionsHint = a.getDrawable(R.styleable.SuggestionsView_moreSuggestionsHint);
mMaxMoreSuggestionsRow = a.getInt(
R.styleable.SuggestionsView_maxMoreSuggestionsRow,
DEFAULT_MAX_MORE_SUGGESTIONS_ROW);
@@ -233,6 +239,8 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
R.styleable.SuggestionsView_minMoreSuggestionsWidth);
a.recycle();
+ mMoreSuggestionsHint = getMoreSuggestionsHint(res,
+ res.getDimension(R.dimen.more_suggestions_hint_text_size), mColorAutoCorrect);
mCenterSuggestionIndex = mSuggestionsCountInStrip / 2;
mMoreSuggestionsBottomGap = res.getDimensionPixelOffset(
R.dimen.more_suggestions_bottom_gap);
@@ -246,6 +254,23 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
mHintToSaveText = context.getText(R.string.hint_add_to_dictionary);
}
+ private static Drawable getMoreSuggestionsHint(Resources res, float textSize, int color) {
+ final Paint paint = new Paint();
+ paint.setAntiAlias(true);
+ paint.setTextAlign(Align.CENTER);
+ paint.setTextSize(textSize);
+ paint.setColor(color);
+ final Rect bounds = new Rect();
+ paint.getTextBounds(MORE_SUGGESTIONS_HINT, 0, 1, bounds);
+ final int width = Math.round(bounds.width() + 0.5f);
+ final int height = Math.round(bounds.height() + 0.5f);
+ final Bitmap buffer = Bitmap.createBitmap(
+ width, (height * 3 / 2), Bitmap.Config.ARGB_8888);
+ final Canvas canvas = new Canvas(buffer);
+ canvas.drawText(MORE_SUGGESTIONS_HINT, width / 2, height, paint);
+ return new BitmapDrawable(res, buffer);
+ }
+
// Read integer value in TypedArray as percent.
private static float getPercent(TypedArray a, int index, int defValue) {
return a.getInt(index, defValue) / 100.0f;
@@ -524,6 +549,21 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
R.dimen.more_suggestions_modal_tolerance);
}
+ private final View.OnTouchListener mMoreSuggestionsCanceller = new View.OnTouchListener() {
+ @Override
+ public boolean onTouch(View view, MotionEvent me) {
+ if (!mMoreSuggestionsWindow.isShowing()) return false;
+
+ switch (me.getAction()) {
+ case MotionEvent.ACTION_UP:
+ case MotionEvent.ACTION_POINTER_UP:
+ return mMoreSuggestionsView.dismissMoreKeysPanel();
+ default:
+ return true;
+ }
+ }
+ };
+
/**
* A connection back to the input method.
* @param listener
@@ -739,6 +779,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
if (mMoreSuggestionsWindow.isShowing()) {
mMoreSuggestionsWindow.dismiss();
mKeyboardView.dimEntireKeyboard(false);
+ mKeyboardView.setOnTouchListener(null);
return true;
}
return false;
@@ -770,18 +811,22 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
moreKeysPanel.showMoreKeysPanel(
this, mMoreSuggestionsController, pointX, pointY,
mMoreSuggestionsWindow, mMoreSuggestionsListener);
- mCheckingIfModalOrSlidingMode = true;
+ mMoreSuggestionsMode = MORE_SUGGESTIONS_CHECKING_MODAL_OR_SLIDING;
mOriginX = mLastX;
mOriginY = mLastY;
view.setPressed(false);
mKeyboardView.dimEntireKeyboard(true);
+ mKeyboardView.setOnTouchListener(mMoreSuggestionsCanceller);
return true;
}
return false;
}
// Working variables for onLongClick and dispatchTouchEvent.
- private boolean mCheckingIfModalOrSlidingMode;
+ private int mMoreSuggestionsMode = MORE_SUGGESTIONS_IN_MODAL_MODE;
+ private static final int MORE_SUGGESTIONS_IN_MODAL_MODE = 0;
+ private static final int MORE_SUGGESTIONS_CHECKING_MODAL_OR_SLIDING = 1;
+ private static final int MORE_SUGGESTIONS_IN_SLIDING_MODE = 2;
private int mLastX;
private int mLastY;
private int mOriginX;
@@ -790,7 +835,8 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
@Override
public boolean dispatchTouchEvent(MotionEvent me) {
- if (!mMoreSuggestionsWindow.isShowing()) {
+ if (!mMoreSuggestionsWindow.isShowing()
+ || mMoreSuggestionsMode == MORE_SUGGESTIONS_IN_MODAL_MODE) {
mLastX = (int)me.getX();
mLastY = (int)me.getY();
return super.dispatchTouchEvent(me);
@@ -807,22 +853,22 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
final int translatedX = moreKeysPanel.translateX(x);
final int translatedY = moreKeysPanel.translateY(y);
- if (mCheckingIfModalOrSlidingMode) {
+ if (mMoreSuggestionsMode == MORE_SUGGESTIONS_CHECKING_MODAL_OR_SLIDING) {
if (Math.abs(x - mOriginX) >= mMoreSuggestionsModalTolerance
|| mOriginY - y >= mMoreSuggestionsModalTolerance) {
// Decided to be in the sliding input mode only when the touch point has been moved
// upward.
- mCheckingIfModalOrSlidingMode = false;
+ mMoreSuggestionsMode = MORE_SUGGESTIONS_IN_SLIDING_MODE;
tracker.onShowMoreKeysPanel(
translatedX, translatedY, SystemClock.uptimeMillis(), moreKeysPanel);
} else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) {
// Decided to be in the modal input mode
- mCheckingIfModalOrSlidingMode = false;
+ mMoreSuggestionsMode = MORE_SUGGESTIONS_IN_MODAL_MODE;
}
return true;
}
- // Process sliding motion events
+ // MORE_SUGGESTIONS_IN_SLIDING_MODE
tracker.processMotionEvent(action, translatedX, translatedY, eventTime, moreKeysPanel);
return true;
}