From 710c456ddb32fe05e13965183e7018015da52eae Mon Sep 17 00:00:00 2001 From: Adam Powell Date: Thu, 4 Sep 2014 15:36:01 -0700 Subject: [PATCH] Material EdgeEffect refinements Add back auto-recede for EdgeEffect, but with a longer delay. Removing it caused compatibility issues in existing custom views that never call onRelease. The longer delay will be a signal that something is amiss without disrupting the UX too badly. Recede the glow more quickly on release. Start translucent and fade to more opaque as the glow grows and is pulled further. Make the opacity stronger in the extreme cases so the glow is more prominent. Equalize glow size across the width and height. Bug 15146438 Bug 15936708 Change-Id: I020d705906e6225b044d0f5303bafa733a679a66 --- core/java/android/widget/EdgeEffect.java | 36 ++++++++++++++++-------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/core/java/android/widget/EdgeEffect.java b/core/java/android/widget/EdgeEffect.java index 57b8dcb9e7639..033b99a22d518 100644 --- a/core/java/android/widget/EdgeEffect.java +++ b/core/java/android/widget/EdgeEffect.java @@ -52,12 +52,15 @@ public class EdgeEffect { private static final String TAG = "EdgeEffect"; // Time it will take the effect to fully recede in ms - private static final int RECEDE_TIME = 1000; + private static final int RECEDE_TIME = 600; // Time it will take before a pulled glow begins receding in ms private static final int PULL_TIME = 167; - private static final float MAX_ALPHA = 1.f; + // Time it will take in ms for a pulled glow to decay to partial strength before release + private static final int PULL_DECAY_TIME = 2000; + + private static final float MAX_ALPHA = 0.5f; private static final float MAX_GLOW_SCALE = 2.f; @@ -93,12 +96,9 @@ public class EdgeEffect { private static final int STATE_RECEDE = 3; private static final int STATE_PULL_DECAY = 4; - // How much dragging should effect the height of the glow image. - // Number determined by user testing. - private static final int PULL_DISTANCE_GLOW_FACTOR = 7; - private static final float PULL_DISTANCE_ALPHA_GLOW_FACTOR = 1.1f; + private static final float PULL_DISTANCE_ALPHA_GLOW_FACTOR = 0.8f; - private static final int VELOCITY_GLOW_FACTOR = 12; + private static final int VELOCITY_GLOW_FACTOR = 6; private int mState = STATE_IDLE; @@ -107,7 +107,7 @@ public class EdgeEffect { private final Rect mBounds = new Rect(); private final Paint mPaint = new Paint(); private float mRadius; - private float mBaseGlowHeight; + private float mBaseGlowScale; private float mDisplacement = 0.5f; private float mTargetDisplacement = 0.5f; @@ -138,8 +138,12 @@ public class EdgeEffect { final float r = width * 0.75f / SIN; final float y = COS * r; final float h = r - y; + final float or = height * 0.75f / SIN; + final float oy = COS * or; + final float oh = or - oy; + mRadius = r; - mBaseGlowHeight = h; + mBaseGlowScale = h > 0 ? Math.min(oh / h, 1.f) : 1.f; mBounds.set(mBounds.left, mBounds.top, width, (int) Math.min(height, h)); } @@ -319,13 +323,14 @@ public class EdgeEffect { final float centerX = mBounds.centerX(); final float centerY = mBounds.height() - mRadius; - canvas.scale(1.f, Math.min(mGlowScaleY, 1.f), centerX, 0); + canvas.scale(1.f, Math.min(mGlowScaleY, 1.f) * mBaseGlowScale, centerX, 0); final float displacement = Math.max(0, Math.min(mDisplacement, 1.f)) - 0.5f; float translateX = mBounds.width() * displacement / 2; canvas.clipRect(mBounds); canvas.translate(translateX, 0); + mPaint.setAlpha((int) (0xff * mGlowAlpha)); canvas.drawCircle(centerX, centerY, mRadius, mPaint); canvas.restoreToCount(count); @@ -372,7 +377,16 @@ public class EdgeEffect { mGlowScaleYFinish = 0.f; break; case STATE_PULL: - // Hold in this state until explicitly released. + mState = STATE_PULL_DECAY; + mStartTime = AnimationUtils.currentAnimationTimeMillis(); + mDuration = PULL_DECAY_TIME; + + mGlowAlphaStart = mGlowAlpha; + mGlowScaleYStart = mGlowScaleY; + + // After pull, the glow should fade to nothing. + mGlowAlphaFinish = 0.f; + mGlowScaleYFinish = 0.f; break; case STATE_PULL_DECAY: mState = STATE_RECEDE;