Add shadow to gesture preview trail

Bug: 7167303
Change-Id: I8f76fe0aec6cb32388e7c85d04516d1dd7d28c29
main
Tadashi G. Takaoka 2013-04-16 16:44:23 +09:00
parent 785c5068e4
commit c71dde9cb5
6 changed files with 53 additions and 8 deletions

View File

@ -85,6 +85,8 @@
<attr name="slidingKeyInputEnable" format="boolean" /> <attr name="slidingKeyInputEnable" format="boolean" />
<attr name="slidingKeyInputPreviewColor" format="color" /> <attr name="slidingKeyInputPreviewColor" format="color" />
<attr name="slidingKeyInputPreviewWidth" format="dimension" /> <attr name="slidingKeyInputPreviewWidth" format="dimension" />
<attr name="slidingKeyInputPreviewBodyRatio" format="integer" />
<attr name="slidingKeyInputPreviewShadowRatio" format="integer" />
<!-- Key repeat start timeout --> <!-- Key repeat start timeout -->
<attr name="keyRepeatStartTimeout" format="integer" /> <attr name="keyRepeatStartTimeout" format="integer" />
<!-- Key repeat interval in millisecond. --> <!-- Key repeat interval in millisecond. -->
@ -115,6 +117,8 @@
<attr name="gesturePreviewTrailColor" format="color" /> <attr name="gesturePreviewTrailColor" format="color" />
<attr name="gesturePreviewTrailStartWidth" format="dimension" /> <attr name="gesturePreviewTrailStartWidth" format="dimension" />
<attr name="gesturePreviewTrailEndWidth" 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 --> <!-- Delay after gesture input and gesture floating preview text dismissing in millisecond -->
<attr name="gestureFloatingPreviewTextLingerTimeout" format="integer" /> <attr name="gestureFloatingPreviewTextLingerTimeout" format="integer" />
<!-- Attributes for GestureFloatingPreviewText --> <!-- Attributes for GestureFloatingPreviewText -->

View File

@ -58,6 +58,9 @@
<bool name="config_sliding_key_input_enabled">true</bool> <bool name="config_sliding_key_input_enabled">true</bool>
<!-- Sliding key input preview parameters --> <!-- Sliding key input preview parameters -->
<dimen name="config_sliding_key_input_preview_width">8.0dp</dimen> <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_start_timeout">400</integer>
<integer name="config_key_repeat_interval">50</integer> <integer name="config_key_repeat_interval">50</integer>
<integer name="config_default_longpress_key_timeout">300</integer> <!-- milliseconds --> <integer name="config_default_longpress_key_timeout">300</integer> <!-- milliseconds -->

View File

@ -103,6 +103,9 @@
<!-- Gesture preview trail parameters --> <!-- Gesture preview trail parameters -->
<dimen name="gesture_preview_trail_start_width">10.0dp</dimen> <dimen name="gesture_preview_trail_start_width">10.0dp</dimen>
<dimen name="gesture_preview_trail_end_width">2.5dp</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 --> <!-- Gesture floating preview text parameters -->
<dimen name="gesture_floating_preview_text_size">24dp</dimen> <dimen name="gesture_floating_preview_text_size">24dp</dimen>
<dimen name="gesture_floating_preview_text_offset">73dp</dimen> <dimen name="gesture_floating_preview_text_offset">73dp</dimen>

View File

@ -70,6 +70,8 @@
<item name="gesturePreviewTrailColor">@color/highlight_color_default</item> <item name="gesturePreviewTrailColor">@color/highlight_color_default</item>
<item name="gesturePreviewTrailStartWidth">@dimen/gesture_preview_trail_start_width</item> <item name="gesturePreviewTrailStartWidth">@dimen/gesture_preview_trail_start_width</item>
<item name="gesturePreviewTrailEndWidth">@dimen/gesture_preview_trail_end_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 --> <!-- Common attributes of MainKeyboardView -->
<item name="keyHysteresisDistance">@dimen/config_key_hysteresis_distance</item> <item name="keyHysteresisDistance">@dimen/config_key_hysteresis_distance</item>
<item name="keyHysteresisDistanceForSlidingModifier">@dimen/config_key_hysteresis_distance_for_sliding_modifier</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="slidingKeyInputEnable">@bool/config_sliding_key_input_enabled</item>
<item name="slidingKeyInputPreviewColor">@color/highlight_translucent_color_default</item> <item name="slidingKeyInputPreviewColor">@color/highlight_translucent_color_default</item>
<item name="slidingKeyInputPreviewWidth">@dimen/config_sliding_key_input_preview_width</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="keyRepeatStartTimeout">@integer/config_key_repeat_start_timeout</item>
<item name="keyRepeatInterval">@integer/config_key_repeat_interval</item> <item name="keyRepeatInterval">@integer/config_key_repeat_interval</item>
<item name="longPressShiftLockTimeout">@integer/config_longpress_shift_lock_timeout</item> <item name="longPressShiftLockTimeout">@integer/config_longpress_shift_lock_timeout</item>

View File

@ -51,6 +51,9 @@ final class GesturePreviewTrail {
public final int mTrailColor; public final int mTrailColor;
public final float mTrailStartWidth; public final float mTrailStartWidth;
public final float mTrailEndWidth; public final float mTrailEndWidth;
public final float mTrailBodyRatio;
public boolean mTrailShadowEnabled;
public final float mTrailShadowRatio;
public final int mFadeoutStartDelay; public final int mFadeoutStartDelay;
public final int mFadeoutDuration; public final int mFadeoutDuration;
public final int mUpdateInterval; public final int mUpdateInterval;
@ -64,6 +67,14 @@ final class GesturePreviewTrail {
R.styleable.MainKeyboardView_gesturePreviewTrailStartWidth, 0.0f); R.styleable.MainKeyboardView_gesturePreviewTrailStartWidth, 0.0f);
mTrailEndWidth = mainKeyboardViewAttr.getDimension( mTrailEndWidth = mainKeyboardViewAttr.getDimension(
R.styleable.MainKeyboardView_gesturePreviewTrailEndWidth, 0.0f); 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( mFadeoutStartDelay = mainKeyboardViewAttr.getInt(
R.styleable.MainKeyboardView_gesturePreviewTrailFadeoutStartDelay, 0); R.styleable.MainKeyboardView_gesturePreviewTrailFadeoutStartDelay, 0);
mFadeoutDuration = mainKeyboardViewAttr.getInt( mFadeoutDuration = mainKeyboardViewAttr.getInt(
@ -219,14 +230,22 @@ final class GesturePreviewTrail {
final float r2 = getWidth(elapsedTime, params) / 2.0f; final float r2 = getWidth(elapsedTime, params) / 2.0f;
// Draw trail line only when the current point isn't a down point. // Draw trail line only when the current point isn't a down point.
if (!isDownEventXCoord(xCoords[i])) { 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) { 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); final int alpha = getAlpha(elapsedTime, params);
paint.setAlpha(alpha); paint.setAlpha(alpha);
canvas.drawPath(path, paint); canvas.drawPath(path, paint);
// Take union for the bounds.
roundedLine.getBounds(mRoundedLineBounds);
outBoundsRect.union(mRoundedLineBounds);
} }
} }
p1x = p2x; p1x = p2x;

View File

@ -30,7 +30,7 @@ import com.android.inputmethod.latin.R;
* Draw rubber band preview graphics during sliding key input. * Draw rubber band preview graphics during sliding key input.
*/ */
public final class SlidingKeyInputPreview extends AbstractDrawingPreview { public final class SlidingKeyInputPreview extends AbstractDrawingPreview {
private final int mPreviewWidth; private final float mPreviewBodyRadius;
private boolean mShowSlidingKeyInputPreview; private boolean mShowSlidingKeyInputPreview;
private final int[] mPreviewFrom = CoordinateUtils.newInstance(); private final int[] mPreviewFrom = CoordinateUtils.newInstance();
@ -44,8 +44,20 @@ public final class SlidingKeyInputPreview extends AbstractDrawingPreview {
super(drawingView); super(drawingView);
final int previewColor = mainKeyboardViewAttr.getColor( final int previewColor = mainKeyboardViewAttr.getColor(
R.styleable.MainKeyboardView_slidingKeyInputPreviewColor, 0); R.styleable.MainKeyboardView_slidingKeyInputPreviewColor, 0);
mPreviewWidth = mainKeyboardViewAttr.getDimensionPixelSize( final float previewRadius = mainKeyboardViewAttr.getDimension(
R.styleable.MainKeyboardView_slidingKeyInputPreviewWidth, 0); 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); mPaint.setColor(previewColor);
} }
@ -65,7 +77,7 @@ public final class SlidingKeyInputPreview extends AbstractDrawingPreview {
} }
// TODO: Finalize the rubber band preview implementation. // TODO: Finalize the rubber band preview implementation.
final int radius = mPreviewWidth / 2; final float radius = mPreviewBodyRadius;
final Path path = mRoundedLine.makePath( final Path path = mRoundedLine.makePath(
CoordinateUtils.x(mPreviewFrom), CoordinateUtils.y(mPreviewFrom), radius, CoordinateUtils.x(mPreviewFrom), CoordinateUtils.y(mPreviewFrom), radius,
CoordinateUtils.x(mPreviewTo), CoordinateUtils.y(mPreviewTo), radius); CoordinateUtils.x(mPreviewTo), CoordinateUtils.y(mPreviewTo), radius);