From c71dde9cb5a477d75b34057b27a9b049c048f1bf Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 16 Apr 2013 16:44:23 +0900 Subject: [PATCH] Add shadow to gesture preview trail Bug: 7167303 Change-Id: I8f76fe0aec6cb32388e7c85d04516d1dd7d28c29 --- java/res/values/attrs.xml | 4 +++ java/res/values/config.xml | 3 +++ java/res/values/dimens.xml | 3 +++ java/res/values/styles.xml | 4 +++ .../internal/GesturePreviewTrail.java | 27 ++++++++++++++++--- .../internal/SlidingKeyInputPreview.java | 20 +++++++++++--- 6 files changed, 53 insertions(+), 8 deletions(-) diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index 3a7b39e3a..a71e7cc11 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -85,6 +85,8 @@ + + @@ -115,6 +117,8 @@ + + diff --git a/java/res/values/config.xml b/java/res/values/config.xml index a90ba8014..d4fff620c 100644 --- a/java/res/values/config.xml +++ b/java/res/values/config.xml @@ -58,6 +58,9 @@ true 8.0dp + + 80 + 50 400 50 300 diff --git a/java/res/values/dimens.xml b/java/res/values/dimens.xml index dd42acf3c..db33ad812 100644 --- a/java/res/values/dimens.xml +++ b/java/res/values/dimens.xml @@ -103,6 +103,9 @@ 10.0dp 2.5dp + + 80 + 50 24dp 73dp diff --git a/java/res/values/styles.xml b/java/res/values/styles.xml index fb59c745f..436e080f7 100644 --- a/java/res/values/styles.xml +++ b/java/res/values/styles.xml @@ -70,6 +70,8 @@ @color/highlight_color_default @dimen/gesture_preview_trail_start_width @dimen/gesture_preview_trail_end_width + @integer/gesture_preview_trail_body_ratio + @integer/gesture_preview_trail_shadow_ratio @dimen/config_key_hysteresis_distance @dimen/config_key_hysteresis_distance_for_sliding_modifier @@ -78,6 +80,8 @@ @bool/config_sliding_key_input_enabled @color/highlight_translucent_color_default @dimen/config_sliding_key_input_preview_width + @integer/config_sliding_key_input_preview_body_ratio + @integer/config_sliding_key_input_preview_shadow_ratio @integer/config_key_repeat_start_timeout @integer/config_key_repeat_interval @integer/config_longpress_shift_lock_timeout diff --git a/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java b/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java index f682b518f..0c050610d 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java +++ b/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java @@ -51,6 +51,9 @@ final class GesturePreviewTrail { public final int mTrailColor; public final float mTrailStartWidth; public final float mTrailEndWidth; + public final float mTrailBodyRatio; + public boolean mTrailShadowEnabled; + public final float mTrailShadowRatio; public final int mFadeoutStartDelay; public final int mFadeoutDuration; public final int mUpdateInterval; @@ -64,6 +67,14 @@ final class GesturePreviewTrail { R.styleable.MainKeyboardView_gesturePreviewTrailStartWidth, 0.0f); mTrailEndWidth = mainKeyboardViewAttr.getDimension( R.styleable.MainKeyboardView_gesturePreviewTrailEndWidth, 0.0f); + final int PERCENTAGE_INT = 100; + mTrailBodyRatio = (float)mainKeyboardViewAttr.getInt( + R.styleable.MainKeyboardView_gesturePreviewTrailBodyRatio, PERCENTAGE_INT) + / (float)PERCENTAGE_INT; + final int trailShadowRatioInt = mainKeyboardViewAttr.getInt( + R.styleable.MainKeyboardView_gesturePreviewTrailShadowRatio, 0); + mTrailShadowEnabled = (trailShadowRatioInt > 0); + mTrailShadowRatio = (float)trailShadowRatioInt / (float)PERCENTAGE_INT; mFadeoutStartDelay = mainKeyboardViewAttr.getInt( R.styleable.MainKeyboardView_gesturePreviewTrailFadeoutStartDelay, 0); mFadeoutDuration = mainKeyboardViewAttr.getInt( @@ -219,14 +230,22 @@ final class GesturePreviewTrail { final float r2 = getWidth(elapsedTime, params) / 2.0f; // Draw trail line only when the current point isn't a down point. if (!isDownEventXCoord(xCoords[i])) { - final Path path = roundedLine.makePath(p1x, p1y, r1, p2x, p2y, r2); + final float body1 = r1 * params.mTrailBodyRatio; + final float body2 = r2 * params.mTrailBodyRatio; + final Path path = roundedLine.makePath(p1x, p1y, body1, p2x, p2y, body2); if (path != null) { + roundedLine.getBounds(mRoundedLineBounds); + if (params.mTrailShadowEnabled) { + final float shadow2 = r2 * params.mTrailShadowRatio; + paint.setShadowLayer(shadow2, 0.0f, 0.0f, params.mTrailColor); + final int shadowInset = -(int)Math.ceil(shadow2); + mRoundedLineBounds.inset(shadowInset, shadowInset); + } + // Take union for the bounds. + outBoundsRect.union(mRoundedLineBounds); final int alpha = getAlpha(elapsedTime, params); paint.setAlpha(alpha); canvas.drawPath(path, paint); - // Take union for the bounds. - roundedLine.getBounds(mRoundedLineBounds); - outBoundsRect.union(mRoundedLineBounds); } } p1x = p2x; diff --git a/java/src/com/android/inputmethod/keyboard/internal/SlidingKeyInputPreview.java b/java/src/com/android/inputmethod/keyboard/internal/SlidingKeyInputPreview.java index 37f4e3582..33dbbafa3 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/SlidingKeyInputPreview.java +++ b/java/src/com/android/inputmethod/keyboard/internal/SlidingKeyInputPreview.java @@ -30,7 +30,7 @@ import com.android.inputmethod.latin.R; * Draw rubber band preview graphics during sliding key input. */ public final class SlidingKeyInputPreview extends AbstractDrawingPreview { - private final int mPreviewWidth; + private final float mPreviewBodyRadius; private boolean mShowSlidingKeyInputPreview; private final int[] mPreviewFrom = CoordinateUtils.newInstance(); @@ -44,8 +44,20 @@ public final class SlidingKeyInputPreview extends AbstractDrawingPreview { super(drawingView); final int previewColor = mainKeyboardViewAttr.getColor( R.styleable.MainKeyboardView_slidingKeyInputPreviewColor, 0); - mPreviewWidth = mainKeyboardViewAttr.getDimensionPixelSize( - R.styleable.MainKeyboardView_slidingKeyInputPreviewWidth, 0); + final float previewRadius = mainKeyboardViewAttr.getDimension( + R.styleable.MainKeyboardView_slidingKeyInputPreviewWidth, 0) / 2.0f; + final int PERCENTAGE_INT = 100; + final float previewBodyRatio = (float)mainKeyboardViewAttr.getInt( + R.styleable.MainKeyboardView_slidingKeyInputPreviewBodyRatio, PERCENTAGE_INT) + / (float)PERCENTAGE_INT; + mPreviewBodyRadius = previewRadius * previewBodyRatio; + final int previewShadowRatioInt = mainKeyboardViewAttr.getInt( + R.styleable.MainKeyboardView_slidingKeyInputPreviewShadowRatio, 0); + if (previewShadowRatioInt > 0) { + final float previewShadowRatio = (float)previewShadowRatioInt / (float)PERCENTAGE_INT; + final float shadowRadius = previewRadius * previewShadowRatio; + mPaint.setShadowLayer(shadowRadius, 0.0f, 0.0f, previewColor); + } mPaint.setColor(previewColor); } @@ -65,7 +77,7 @@ public final class SlidingKeyInputPreview extends AbstractDrawingPreview { } // TODO: Finalize the rubber band preview implementation. - final int radius = mPreviewWidth / 2; + final float radius = mPreviewBodyRadius; final Path path = mRoundedLine.makePath( CoordinateUtils.x(mPreviewFrom), CoordinateUtils.y(mPreviewFrom), radius, CoordinateUtils.x(mPreviewTo), CoordinateUtils.y(mPreviewTo), radius);