diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index 1d52e46bbe84b846a5138499e8066d1a0ac29f15..02e8eeb3b490236113ac6798b8b10014e8b8b792 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -118,6 +118,18 @@ <enum name="italic" value="2" /> <enum name="boldItalic" value="3" /> </attr> + + <attr name="gestureFloatingPreviewTextSize" format="dimension" /> + <attr name="gestureFloatingPreviewTextColor" format="color" /> + <attr name="gestureFloatingPreviewTextOffset" format="dimension" /> + <attr name="gestureFloatingPreviewTextShadingColor" format="color" /> + <attr name="gestureFloatingPreviewTextShadingBorder" format="dimension" /> + <attr name="gestureFloatingPreviewTextShadowColor" format="color" /> + <attr name="gestureFloatingPreviewTextShadowBorder" format="dimension" /> + <attr name="gestureFloatingPreviewTextConnectorColor" format="color" /> + <attr name="gestureFloatingPreviewTextConnectorWidth" format="dimension" /> + <attr name="gesturePreviewTrailColor" format="color" /> + <attr name="gesturePreviewTrailWidth" format="dimension" /> </declare-styleable> <declare-styleable name="MainKeyboardView"> diff --git a/java/res/values/dimens.xml b/java/res/values/dimens.xml index b47897f3c268237b624a8b23eeaaeb87c0857694..c59bad302ca5671fe81eddc49b1760d0dc292c96 100644 --- a/java/res/values/dimens.xml +++ b/java/res/values/dimens.xml @@ -96,9 +96,9 @@ <!-- Gesture preview parameters --> <dimen name="gesture_preview_trail_width">2.5dp</dimen> - <dimen name="gesture_preview_text_size">35dp</dimen> - <dimen name="gesture_preview_text_offset">75dp</dimen> - <dimen name="gesture_preview_text_shadow_border">17.5dp</dimen> - <dimen name="gesture_preview_text_shading_border">7.5dp</dimen> - <dimen name="gesture_preview_text_connector_width">1.0dp</dimen> + <dimen name="gesture_floating_preview_text_size">35dp</dimen> + <dimen name="gesture_floating_preview_text_offset">75dp</dimen> + <dimen name="gesture_floating_preview_text_shadow_border">17.5dp</dimen> + <dimen name="gesture_floating_preview_text_shading_border">7.5dp</dimen> + <dimen name="gesture_floating_preview_text_connector_width">1.0dp</dimen> </resources> diff --git a/java/res/values/styles.xml b/java/res/values/styles.xml index 8797fd7aa2f7d7fd5dea974e621690ef55d1a871..955a276315cbe79fcbbbee692f96ad9dfc9ca379 100644 --- a/java/res/values/styles.xml +++ b/java/res/values/styles.xml @@ -14,7 +14,7 @@ limitations under the License. --> -<resources> +<resources xmlns:android="http://schemas.android.com/apk/res/android"> <!-- Theme "Basic" --> <style name="Keyboard"> <!-- This should be aligned with KeyboardSwitcher.KEYBOARD_THEMES[] --> @@ -67,6 +67,18 @@ <item name="shadowColor">#BB000000</item> <item name="shadowRadius">2.75</item> <item name="backgroundDimAlpha">128</item> + <!-- android:color/holo_blue_light=#FF33B5E5 --> + <item name="gestureFloatingPreviewTextSize">@dimen/gesture_floating_preview_text_size</item> + <item name="gestureFloatingPreviewTextColor">@android:color/white</item> + <item name="gestureFloatingPreviewTextOffset">@dimen/gesture_floating_preview_text_offset</item> + <item name="gestureFloatingPreviewTextShadingColor">@android:color/holo_blue_light</item> + <item name="gestureFloatingPreviewTextShadingBorder">@dimen/gesture_floating_preview_text_shading_border</item> + <item name="gestureFloatingPreviewTextShadowColor">#FF252525</item> + <item name="gestureFloatingPreviewTextShadowBorder">@dimen/gesture_floating_preview_text_shadow_border</item> + <item name="gestureFloatingPreviewTextConnectorColor">@android:color/white</item> + <item name="gestureFloatingPreviewTextConnectorWidth">@dimen/gesture_floating_preview_text_connector_width</item> + <item name="gesturePreviewTrailColor">@android:color/holo_blue_light</item> + <item name="gesturePreviewTrailWidth">@dimen/gesture_preview_trail_width</item> <!-- Common attributes of MainKeyboardView --> <item name="keyHysteresisDistance">@dimen/config_key_hysteresis_distance</item> <item name="touchNoiseThresholdTime">@integer/config_touch_noise_threshold_time</item> diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index 6dc13d24c5d83b602dc6f7e2c178076f7acb6ca4..d7ce659e7c07b93a7a318201e1e1decc593aa38c 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -376,13 +376,12 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { R.styleable.KeyboardView_verticalCorrection, 0); mMoreKeysLayout = a.getResourceId(R.styleable.KeyboardView_moreKeysLayout, 0); mBackgroundDimAlpha = a.getInt(R.styleable.KeyboardView_backgroundDimAlpha, 0); + mPreviewPlacerView = new PreviewPlacerView(context, a); a.recycle(); mDelayAfterPreview = mKeyPreviewDrawParams.mLingerTimeout; mPaint.setAntiAlias(true); - - mPreviewPlacerView = new PreviewPlacerView(context); } // Read fraction value in TypedArray as float. @@ -903,9 +902,9 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { windowContentView.addView(mPreviewPlacerView); } - public void showGesturePreviewText(String gesturePreviewText) { + public void showGestureFloatingPreviewText(String gestureFloatingPreviewText) { locatePreviewPlacerView(); - mPreviewPlacerView.setGesturePreviewText(gesturePreviewText); + mPreviewPlacerView.setGestureFloatingPreviewText(gestureFloatingPreviewText); } @Override diff --git a/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java b/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java index a400fda15cd26f6a95e733df7513dbd30f9f9b30..c38febf493502f5f8cd03e4a201cfe463a3c9e76 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java +++ b/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java @@ -17,9 +17,8 @@ package com.android.inputmethod.keyboard.internal; import android.content.Context; -import android.content.res.Resources; +import android.content.res.TypedArray; import android.graphics.Canvas; -import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Align; import android.text.TextUtils; @@ -30,60 +29,65 @@ import com.android.inputmethod.keyboard.PointerTracker; import com.android.inputmethod.latin.R; public class PreviewPlacerView extends RelativeLayout { - // TODO: Move these parameters to attributes of {@link KeyboardView}. - private final static int GESTURE_DRAWING_COLOR = 0xff33b5e5; - private static final int GESTURE_PREVIEW_TEXT_COLOR = Color.WHITE; - private static final int GESTURE_PREVIEW_TEXT_SHADING_COLOR = 0xff33b5e5; - private static final int GESTURE_PREVIEW_TEXT_SHADOW_COLOR = 0xff252525; - private static final int GESTURE_PREVIEW_CONNECTOR_COLOR = Color.WHITE; - private final Paint mGesturePaint; - private final int mGesturePreviewTraileWidth; private final Paint mTextPaint; - private final int mGesturePreviewTextOffset; - private final int mGesturePreviewTextShadowBorder; - private final int mGesturePreviewTextShadingBorder; - private final int mGesturePreviewTextConnectorWidth; + private final int mGestureFloatingPreviewTextColor; + private final int mGestureFloatingPreviewTextOffset; + private final int mGestureFloatingPreviewTextShadowColor; + private final int mGestureFloatingPreviewTextShadowBorder; + private final int mGestureFloatingPreviewTextShadingColor; + private final int mGestureFloatingPreviewTextShadingBorder; + private final int mGestureFloatingPreviewTextConnectorColor; + private final int mGestureFloatingPreviewTextConnectorWidth; private int mXOrigin; private int mYOrigin; private final SparseArray<PointerTracker> mPointers = new SparseArray<PointerTracker>(); - private String mGesturePreviewText; + private String mGestureFloatingPreviewText; private boolean mDrawsGesturePreviewTrail; private boolean mDrawsGestureFloatingPreviewText; - public PreviewPlacerView(Context context) { + public PreviewPlacerView(Context context, TypedArray keyboardViewAttr) { super(context); setWillNotDraw(false); - final Resources res = getResources(); - // TODO: Move these parameters to attributes of {@link KeyboardView}. - mGesturePreviewTraileWidth = res.getDimensionPixelSize( - R.dimen.gesture_preview_trail_width); - final int textSize = res.getDimensionPixelSize(R.dimen.gesture_preview_text_size); - mGesturePreviewTextOffset = res.getDimensionPixelSize( - R.dimen.gesture_preview_text_offset); - mGesturePreviewTextShadowBorder = res.getDimensionPixelOffset( - R.dimen.gesture_preview_text_shadow_border); - mGesturePreviewTextShadingBorder = res.getDimensionPixelOffset( - R.dimen.gesture_preview_text_shading_border); - mGesturePreviewTextConnectorWidth = res.getDimensionPixelOffset( - R.dimen.gesture_preview_text_connector_width); + final int gestureFloatingPreviewTextSize = keyboardViewAttr.getDimensionPixelSize( + R.styleable.KeyboardView_gestureFloatingPreviewTextSize, 0); + mGestureFloatingPreviewTextColor = keyboardViewAttr.getColor( + R.styleable.KeyboardView_gestureFloatingPreviewTextColor, 0); + mGestureFloatingPreviewTextOffset = keyboardViewAttr.getDimensionPixelOffset( + R.styleable.KeyboardView_gestureFloatingPreviewTextOffset, 0); + mGestureFloatingPreviewTextShadowColor = keyboardViewAttr.getColor( + R.styleable.KeyboardView_gestureFloatingPreviewTextShadowColor, 0); + mGestureFloatingPreviewTextShadowBorder = keyboardViewAttr.getDimensionPixelSize( + R.styleable.KeyboardView_gestureFloatingPreviewTextShadowBorder, 0); + mGestureFloatingPreviewTextShadingColor = keyboardViewAttr.getColor( + R.styleable.KeyboardView_gestureFloatingPreviewTextShadingColor, 0); + mGestureFloatingPreviewTextShadingBorder = keyboardViewAttr.getDimensionPixelSize( + R.styleable.KeyboardView_gestureFloatingPreviewTextShadingBorder, 0); + mGestureFloatingPreviewTextConnectorColor = keyboardViewAttr.getColor( + R.styleable.KeyboardView_gestureFloatingPreviewTextConnectorColor, 0); + mGestureFloatingPreviewTextConnectorWidth = keyboardViewAttr.getDimensionPixelSize( + R.styleable.KeyboardView_gestureFloatingPreviewTextConnectorWidth, 0); + final int gesturePreviewTrailColor = keyboardViewAttr.getColor( + R.styleable.KeyboardView_gesturePreviewTrailColor, 0); + final int gesturePreviewTrailWidth = keyboardViewAttr.getDimensionPixelSize( + R.styleable.KeyboardView_gesturePreviewTrailWidth, 0); mGesturePaint = new Paint(); mGesturePaint.setAntiAlias(true); mGesturePaint.setStyle(Paint.Style.STROKE); mGesturePaint.setStrokeJoin(Paint.Join.ROUND); - mGesturePaint.setColor(GESTURE_DRAWING_COLOR); - mGesturePaint.setStrokeWidth(mGesturePreviewTraileWidth); + mGesturePaint.setColor(gesturePreviewTrailColor); + mGesturePaint.setStrokeWidth(gesturePreviewTrailWidth); mTextPaint = new Paint(); mTextPaint.setAntiAlias(true); mTextPaint.setStrokeJoin(Paint.Join.ROUND); mTextPaint.setTextAlign(Align.CENTER); - mTextPaint.setTextSize(textSize); + mTextPaint.setTextSize(gestureFloatingPreviewTextSize); } public void setOrigin(int x, int y) { @@ -119,7 +123,7 @@ public class PreviewPlacerView extends RelativeLayout { } // TODO: Figure out more cleaner way to draw gesture preview text. if (mDrawsGestureFloatingPreviewText && !hasDrawnFloatingPreviewText) { - drawGesturePreviewText(canvas, tracker, mGesturePreviewText); + drawGestureFloatingPreviewText(canvas, tracker, mGestureFloatingPreviewText); hasDrawnFloatingPreviewText = true; } } @@ -127,14 +131,14 @@ public class PreviewPlacerView extends RelativeLayout { } } - public void setGesturePreviewText(String gesturePreviewText) { - mGesturePreviewText = gesturePreviewText; + public void setGestureFloatingPreviewText(String gestureFloatingPreviewText) { + mGestureFloatingPreviewText = gestureFloatingPreviewText; invalidate(); } - private void drawGesturePreviewText(Canvas canvas, PointerTracker tracker, - String gesturePreviewText) { - if (TextUtils.isEmpty(gesturePreviewText)) { + private void drawGestureFloatingPreviewText(Canvas canvas, PointerTracker tracker, + String gestureFloatingPreviewText) { + if (TextUtils.isEmpty(gestureFloatingPreviewText)) { return; } @@ -144,22 +148,22 @@ public class PreviewPlacerView extends RelativeLayout { final int textSize = (int)paint.getTextSize(); final int canvasWidth = canvas.getWidth(); - final int halfTextWidth = (int)paint.measureText(gesturePreviewText) / 2 + textSize; + final int halfTextWidth = (int)paint.measureText(gestureFloatingPreviewText) / 2 + textSize; final int textX = Math.min(Math.max(lastX, halfTextWidth), canvasWidth - halfTextWidth); - int textY = Math.max(-textSize, lastY - mGesturePreviewTextOffset); + int textY = Math.max(-textSize, lastY - mGestureFloatingPreviewTextOffset); if (textY < 0) { // Paint black text shadow if preview extends above keyboard region. paint.setStyle(Paint.Style.FILL_AND_STROKE); - paint.setColor(GESTURE_PREVIEW_TEXT_SHADOW_COLOR); - paint.setStrokeWidth(mGesturePreviewTextShadowBorder); - canvas.drawText(gesturePreviewText, textX, textY, paint); + paint.setColor(mGestureFloatingPreviewTextShadowColor); + paint.setStrokeWidth(mGestureFloatingPreviewTextShadowBorder); + canvas.drawText(gestureFloatingPreviewText, textX, textY, paint); } // Paint the vertical line connecting the touch point to the preview text. paint.setStyle(Paint.Style.STROKE); - paint.setColor(GESTURE_PREVIEW_CONNECTOR_COLOR); - paint.setStrokeWidth(mGesturePreviewTextConnectorWidth); + paint.setColor(mGestureFloatingPreviewTextConnectorColor); + paint.setStrokeWidth(mGestureFloatingPreviewTextConnectorWidth); final int lineTopY = textY - textSize / 4; canvas.drawLine(lastX, lastY, lastX, lineTopY, paint); if (lastX != textX) { @@ -169,13 +173,13 @@ public class PreviewPlacerView extends RelativeLayout { // Paint the shading for the text preview paint.setStyle(Paint.Style.FILL_AND_STROKE); - paint.setColor(GESTURE_PREVIEW_TEXT_SHADING_COLOR); - paint.setStrokeWidth(mGesturePreviewTextShadingBorder); - canvas.drawText(gesturePreviewText, textX, textY, paint); + paint.setColor(mGestureFloatingPreviewTextShadingColor); + paint.setStrokeWidth(mGestureFloatingPreviewTextShadingBorder); + canvas.drawText(gestureFloatingPreviewText, textX, textY, paint); // Paint the text preview - paint.setColor(GESTURE_PREVIEW_TEXT_COLOR); + paint.setColor(mGestureFloatingPreviewTextColor); paint.setStyle(Paint.Style.FILL); - canvas.drawText(gesturePreviewText, textX, textY, paint); + canvas.drawText(gestureFloatingPreviewText, textX, textY, paint); } } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 22213be5e18f4c49c0a86028646193023a2128da..95d75ebb79e261f1f45f68de9738704d15cb1ed6 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1363,9 +1363,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mWordComposer.setBatchInputPointers(batchPointers); final SuggestedWords suggestedWords = getSuggestedWords(); showSuggestionStrip(suggestedWords, null); - final String gesturePreviewText = (suggestedWords.size() > 0) + final String gestureFloatingPreviewText = (suggestedWords.size() > 0) ? suggestedWords.getWord(0) : null; - mKeyboardSwitcher.getKeyboardView().showGesturePreviewText(gesturePreviewText); + mKeyboardSwitcher.getKeyboardView() + .showGestureFloatingPreviewText(gestureFloatingPreviewText); } @Override @@ -1373,7 +1374,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mWordComposer.setBatchInputPointers(batchPointers); final SuggestedWords suggestedWords = getSuggestedWords(); showSuggestionStrip(suggestedWords, null); - mKeyboardSwitcher.getKeyboardView().showGesturePreviewText(null); + mKeyboardSwitcher.getKeyboardView().showGestureFloatingPreviewText(null); if (suggestedWords == null || suggestedWords.size() == 0) { return; }