From 71e2e8152f1f9a6b91108d578b3cf7b2d57b53d2 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 5 Sep 2012 19:03:02 +0900 Subject: [PATCH] Revise gesture floating preview design Bug: 7043127 Change-Id: Ibf9a6d57279263d9b60753e0eb734b658eeda9f2 --- java/res/values-land/dimens.xml | 6 + java/res/values-sw600dp-land/dimens.xml | 6 + java/res/values-sw600dp/dimens.xml | 9 ++ java/res/values-sw768dp-land/dimens.xml | 6 + java/res/values-sw768dp/dimens.xml | 9 ++ java/res/values/attrs.xml | 10 +- java/res/values/dimens.xml | 13 +- java/res/values/styles.xml | 12 +- .../inputmethod/keyboard/KeyboardView.java | 10 +- .../keyboard/internal/PreviewPlacerView.java | 114 ++++++++---------- 10 files changed, 108 insertions(+), 87 deletions(-) diff --git a/java/res/values-land/dimens.xml b/java/res/values-land/dimens.xml index a1546f11d..fdd94347d 100644 --- a/java/res/values-land/dimens.xml +++ b/java/res/values-land/dimens.xml @@ -73,4 +73,10 @@ 53.76dp -44.8dp + + + 23dp + 54dp + 23dp + 15dp diff --git a/java/res/values-sw600dp-land/dimens.xml b/java/res/values-sw600dp-land/dimens.xml index 9664bf9ed..51c710fa4 100644 --- a/java/res/values-sw600dp-land/dimens.xml +++ b/java/res/values-sw600dp-land/dimens.xml @@ -61,4 +61,10 @@ 252.0dp 5 50% + + + 26dp + 76dp + 26dp + 17dp diff --git a/java/res/values-sw600dp/dimens.xml b/java/res/values-sw600dp/dimens.xml index e608f7d7b..586fbe6da 100644 --- a/java/res/values-sw600dp/dimens.xml +++ b/java/res/values-sw600dp/dimens.xml @@ -84,4 +84,13 @@ 12dp 22dp 33dp + + + 2.5dp + + 28dp + 87dp + 28dp + 19dp + 3dp diff --git a/java/res/values-sw768dp-land/dimens.xml b/java/res/values-sw768dp-land/dimens.xml index 511217068..f4a57ffb0 100644 --- a/java/res/values-sw768dp-land/dimens.xml +++ b/java/res/values-sw768dp-land/dimens.xml @@ -64,4 +64,10 @@ 252.0dp 50% + + + 32dp + 100dp + 32dp + 21dp diff --git a/java/res/values-sw768dp/dimens.xml b/java/res/values-sw768dp/dimens.xml index ec9d75988..2fd732293 100644 --- a/java/res/values-sw768dp/dimens.xml +++ b/java/res/values-sw768dp/dimens.xml @@ -85,4 +85,13 @@ 8dp 22dp 33dp + + + 2.5dp + + 26dp + 86dp + 26dp + 17dp + 3dp diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index 05c53a40e..e60139704 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -77,12 +77,10 @@ - - - - - - + + + + diff --git a/java/res/values/dimens.xml b/java/res/values/dimens.xml index aa16c7770..9ccaaaf4e 100644 --- a/java/res/values/dimens.xml +++ b/java/res/values/dimens.xml @@ -99,13 +99,14 @@ 3 36% - + 2.5dp - 35dp - 75dp - 17.5dp - 7.5dp - 1.0dp + + 24dp + 73dp + 24dp + 16dp + 3dp 8dp diff --git a/java/res/values/styles.xml b/java/res/values/styles.xml index 40f1ff3f4..94fdbeb53 100644 --- a/java/res/values/styles.xml +++ b/java/res/values/styles.xml @@ -66,14 +66,12 @@ 128 @dimen/gesture_floating_preview_text_size - @android:color/white + @android:color/holo_blue_light @dimen/gesture_floating_preview_text_offset - @android:color/holo_blue_light - @dimen/gesture_floating_preview_text_shading_border - #FF252525 - @dimen/gesture_floating_preview_text_shadow_border - @android:color/white - @dimen/gesture_floating_preview_text_connector_width + #C0000000 + @dimen/gesture_floating_preview_horizontal_padding + @dimen/gesture_floating_preview_vertical_padding + @dimen/gesture_floating_preview_round_radius @integer/config_gesture_floating_preview_text_linger_timeout @integer/config_gesture_preview_trail_fadeout_start_delay @integer/config_gesture_preview_trail_fadeout_duration diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index ce7d79778..db3a7b1e9 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -71,12 +71,10 @@ import java.util.HashSet; * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextSize * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextColor * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextOffset - * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextShadingColor - * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextShadingBorder - * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextShadowColor - * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextShadowBorder - * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextConnectorColor - * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextConnectorWidth + * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewColor + * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewHorizontalPadding + * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewVerticalPadding + * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewRoundRadius * @attr ref R.styleable#KeyboardView_gestureFloatingPreviewTextLingerTimeout * @attr ref R.styleable#KeyboardView_gesturePreviewTrailFadeoutStartDelay * @attr ref R.styleable#KeyboardView_gesturePreviewTrailFadeoutDuration diff --git a/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java b/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java index 269b202b5..641fadf6d 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java +++ b/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java @@ -21,6 +21,8 @@ import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Paint.Align; +import android.graphics.Rect; +import android.graphics.RectF; import android.os.Message; import android.text.TextUtils; import android.util.AttributeSet; @@ -38,12 +40,10 @@ public class PreviewPlacerView extends RelativeLayout { private final Paint mTextPaint; 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 final int mGestureFloatingPreviewColor; + private final float mGestureFloatingPreviewHorizontalPadding; + private final float mGestureFloatingPreviewVerticalPadding; + private final float mGestureFloatingPreviewRoundRadius; /* package */ final int mGestureFloatingPreviewTextLingerTimeout; private int mXOrigin; @@ -54,8 +54,12 @@ public class PreviewPlacerView extends RelativeLayout { private final GesturePreviewTrailParams mGesturePreviewTrailParams; private String mGestureFloatingPreviewText; + private final int mGestureFloatingPreviewTextHeight; + // {@link RectF} is needed for {@link Canvas#drawRoundRect(RectF, float, float, Paint)}. + private final RectF mGestureFloatingPreviewRectangle = new RectF(); private int mLastPointerX; private int mLastPointerY; + private static final char[] TEXT_HEIGHT_REFERENCE_CHAR = { 'M' }; private boolean mDrawsGesturePreviewTrail; private boolean mDrawsGestureFloatingPreviewText; @@ -132,18 +136,14 @@ public class PreviewPlacerView extends RelativeLayout { 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); + mGestureFloatingPreviewColor = keyboardViewAttr.getColor( + R.styleable.KeyboardView_gestureFloatingPreviewColor, 0); + mGestureFloatingPreviewHorizontalPadding = keyboardViewAttr.getDimension( + R.styleable.KeyboardView_gestureFloatingPreviewHorizontalPadding, 0.0f); + mGestureFloatingPreviewVerticalPadding = keyboardViewAttr.getDimension( + R.styleable.KeyboardView_gestureFloatingPreviewVerticalPadding, 0.0f); + mGestureFloatingPreviewRoundRadius = keyboardViewAttr.getDimension( + R.styleable.KeyboardView_gestureFloatingPreviewRoundRadius, 0.0f); mGestureFloatingPreviewTextLingerTimeout = keyboardViewAttr.getInt( R.styleable.KeyboardView_gestureFloatingPreviewTextLingerTimeout, 0); final int gesturePreviewTrailColor = keyboardViewAttr.getColor( @@ -155,18 +155,23 @@ public class PreviewPlacerView extends RelativeLayout { mDrawingHandler = new DrawingHandler(this, mGesturePreviewTrailParams); - mGesturePaint = new Paint(); - mGesturePaint.setAntiAlias(true); - mGesturePaint.setStyle(Paint.Style.STROKE); - mGesturePaint.setStrokeJoin(Paint.Join.ROUND); - mGesturePaint.setColor(gesturePreviewTrailColor); - mGesturePaint.setStrokeWidth(gesturePreviewTrailWidth); + final Paint gesturePaint = new Paint(); + gesturePaint.setAntiAlias(true); + gesturePaint.setStyle(Paint.Style.STROKE); + gesturePaint.setStrokeJoin(Paint.Join.ROUND); + gesturePaint.setColor(gesturePreviewTrailColor); + gesturePaint.setStrokeWidth(gesturePreviewTrailWidth); + mGesturePaint = gesturePaint; - mTextPaint = new Paint(); - mTextPaint.setAntiAlias(true); - mTextPaint.setStrokeJoin(Paint.Join.ROUND); - mTextPaint.setTextAlign(Align.CENTER); - mTextPaint.setTextSize(gestureFloatingPreviewTextSize); + final Paint textPaint = new Paint(); + textPaint.setAntiAlias(true); + textPaint.setStyle(Paint.Style.FILL); + textPaint.setTextAlign(Align.CENTER); + textPaint.setTextSize(gestureFloatingPreviewTextSize); + mTextPaint = textPaint; + final Rect textRect = new Rect(); + textPaint.getTextBounds(TEXT_HEIGHT_REFERENCE_CHAR, 0, 1, textRect); + mGestureFloatingPreviewTextHeight = textRect.height(); } public void setOrigin(final int x, final int y) { @@ -242,45 +247,30 @@ public class PreviewPlacerView extends RelativeLayout { } final Paint paint = mTextPaint; + final RectF rectangle = mGestureFloatingPreviewRectangle; // TODO: Figure out how we should deal with the floating preview text with multiple moving // fingers. - final int lastX = mLastPointerX; - final int lastY = mLastPointerY; - final int textSize = (int)paint.getTextSize(); + + // Paint the round rectangle background. + final int textHeight = mGestureFloatingPreviewTextHeight; + final float textWidth = paint.measureText(gestureFloatingPreviewText); + final float hPad = mGestureFloatingPreviewHorizontalPadding; + final float vPad = mGestureFloatingPreviewVerticalPadding; + final float rectWidth = textWidth + hPad * 2.0f; + final float rectHeight = textHeight + vPad * 2.0f; final int canvasWidth = canvas.getWidth(); - - 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 - mGestureFloatingPreviewTextOffset); - if (textY < 0) { - // Paint black text shadow if preview extends above keyboard region. - paint.setStyle(Paint.Style.FILL_AND_STROKE); - 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(mGestureFloatingPreviewTextConnectorColor); - paint.setStrokeWidth(mGestureFloatingPreviewTextConnectorWidth); - final int lineTopY = textY - textSize / 4; - canvas.drawLine(lastX, lastY, lastX, lineTopY, paint); - if (lastX != textX) { - // Paint the horizontal line connection the touch point to the preview text. - canvas.drawLine(lastX, lineTopY, textX, lineTopY, paint); - } - - // Paint the shading for the text preview - paint.setStyle(Paint.Style.FILL_AND_STROKE); - paint.setColor(mGestureFloatingPreviewTextShadingColor); - paint.setStrokeWidth(mGestureFloatingPreviewTextShadingBorder); - canvas.drawText(gestureFloatingPreviewText, textX, textY, paint); + final float rectX = Math.min(Math.max(mLastPointerX - rectWidth / 2.0f, 0.0f), + canvasWidth - rectWidth); + final float rectY = mLastPointerY - mGestureFloatingPreviewTextOffset - rectHeight; + rectangle.set(rectX, rectY, rectX + rectWidth, rectY + rectHeight); + final float round = mGestureFloatingPreviewRoundRadius; + paint.setColor(mGestureFloatingPreviewColor); + canvas.drawRoundRect(rectangle, round, round, paint); // Paint the text preview paint.setColor(mGestureFloatingPreviewTextColor); - paint.setStyle(Paint.Style.FILL); + final float textX = rectX + hPad + textWidth / 2.0f; + final float textY = rectY + vPad + textHeight; canvas.drawText(gestureFloatingPreviewText, textX, textY, paint); } }