diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index 3a7b39e3a4b0da2eb9b91b974a35b3ebe540b2e2..a71e7cc112ab085663d9e5ecccb7be24e3bbfbc8 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -85,6 +85,8 @@ <attr name="slidingKeyInputEnable" format="boolean" /> <attr name="slidingKeyInputPreviewColor" format="color" /> <attr name="slidingKeyInputPreviewWidth" format="dimension" /> + <attr name="slidingKeyInputPreviewBodyRatio" format="integer" /> + <attr name="slidingKeyInputPreviewShadowRatio" format="integer" /> <!-- Key repeat start timeout --> <attr name="keyRepeatStartTimeout" format="integer" /> <!-- Key repeat interval in millisecond. --> @@ -115,6 +117,8 @@ <attr name="gesturePreviewTrailColor" format="color" /> <attr name="gesturePreviewTrailStartWidth" format="dimension" /> <attr name="gesturePreviewTrailEndWidth" format="dimension" /> + <attr name="gesturePreviewTrailBodyRatio" format="integer" /> + <attr name="gesturePreviewTrailShadowRatio" format="integer" /> <!-- Delay after gesture input and gesture floating preview text dismissing in millisecond --> <attr name="gestureFloatingPreviewTextLingerTimeout" format="integer" /> <!-- Attributes for GestureFloatingPreviewText --> diff --git a/java/res/values/config.xml b/java/res/values/config.xml index a90ba801424bc6e40067dd473cc5fbbbf23cccfa..d4fff620ce6db94b7c823859659a441fe8635f1e 100644 --- a/java/res/values/config.xml +++ b/java/res/values/config.xml @@ -58,6 +58,9 @@ <bool name="config_sliding_key_input_enabled">true</bool> <!-- Sliding key input preview parameters --> <dimen name="config_sliding_key_input_preview_width">8.0dp</dimen> + <!-- Percentages of sliding key input preview body and shadow, in proportion to the width. --> + <integer name="config_sliding_key_input_preview_body_ratio">80</integer> + <integer name="config_sliding_key_input_preview_shadow_ratio">50</integer> <integer name="config_key_repeat_start_timeout">400</integer> <integer name="config_key_repeat_interval">50</integer> <integer name="config_default_longpress_key_timeout">300</integer> <!-- milliseconds --> diff --git a/java/res/values/dimens.xml b/java/res/values/dimens.xml index dd42acf3c063e22217c3a79851c44b7d4197980b..db33ad8127e999eb57f2d656f0e210954ae1a357 100644 --- a/java/res/values/dimens.xml +++ b/java/res/values/dimens.xml @@ -103,6 +103,9 @@ <!-- Gesture preview trail parameters --> <dimen name="gesture_preview_trail_start_width">10.0dp</dimen> <dimen name="gesture_preview_trail_end_width">2.5dp</dimen> + <!-- Percentages of gesture preview taril body and shadow, in proportion to the trail width. --> + <integer name="gesture_preview_trail_body_ratio">80</integer> + <integer name="gesture_preview_trail_shadow_ratio">50</integer> <!-- Gesture floating preview text parameters --> <dimen name="gesture_floating_preview_text_size">24dp</dimen> <dimen name="gesture_floating_preview_text_offset">73dp</dimen> diff --git a/java/res/values/styles.xml b/java/res/values/styles.xml index fb59c745fa01292c9d9373037081d12c1503fc11..436e080f7011ca6a620621924fd886064f9d8c0c 100644 --- a/java/res/values/styles.xml +++ b/java/res/values/styles.xml @@ -70,6 +70,8 @@ <item name="gesturePreviewTrailColor">@color/highlight_color_default</item> <item name="gesturePreviewTrailStartWidth">@dimen/gesture_preview_trail_start_width</item> <item name="gesturePreviewTrailEndWidth">@dimen/gesture_preview_trail_end_width</item> + <item name="gesturePreviewTrailBodyRatio">@integer/gesture_preview_trail_body_ratio</item> + <item name="gesturePreviewTrailShadowRatio">@integer/gesture_preview_trail_shadow_ratio</item> <!-- Common attributes of MainKeyboardView --> <item name="keyHysteresisDistance">@dimen/config_key_hysteresis_distance</item> <item name="keyHysteresisDistanceForSlidingModifier">@dimen/config_key_hysteresis_distance_for_sliding_modifier</item> @@ -78,6 +80,8 @@ <item name="slidingKeyInputEnable">@bool/config_sliding_key_input_enabled</item> <item name="slidingKeyInputPreviewColor">@color/highlight_translucent_color_default</item> <item name="slidingKeyInputPreviewWidth">@dimen/config_sliding_key_input_preview_width</item> + <item name="slidingKeyInputPreviewBodyRatio">@integer/config_sliding_key_input_preview_body_ratio</item> + <item name="slidingKeyInputPreviewShadowRatio">@integer/config_sliding_key_input_preview_shadow_ratio</item> <item name="keyRepeatStartTimeout">@integer/config_key_repeat_start_timeout</item> <item name="keyRepeatInterval">@integer/config_key_repeat_interval</item> <item name="longPressShiftLockTimeout">@integer/config_longpress_shift_lock_timeout</item> diff --git a/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java b/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java index f682b518f465384d26ce1086296dd4d943e0e8b8..0c050610dc173f15627f7ce4bfdcc7e45476dd47 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 37f4e3582303889d3f023cdb440d87ff3abad1f1..33dbbafa3f42a9eb1a5b5f133a3e6bbf3d723961 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);