diff options
| author | Alan Viverette <alanv@google.com> | 2015-05-15 17:22:24 -0700 |
|---|---|---|
| committer | Alan Viverette <alanv@google.com> | 2015-05-15 17:22:24 -0700 |
| commit | 5bc0144302bb378e5f007baa4bf6620ab9031879 (patch) | |
| tree | 5d2599ade2dbee0097edfe42c07a7a0113909e47 | |
| parent | afabc217226c11bad46de4eac557f8fe2e15f708 (diff) | |
| download | frameworks_base-5bc0144302bb378e5f007baa4bf6620ab9031879.zip frameworks_base-5bc0144302bb378e5f007baa4bf6620ab9031879.tar.gz frameworks_base-5bc0144302bb378e5f007baa4bf6620ab9031879.tar.bz2 | |
Update ripple drawable target radius on bounds change
Only bothers with the background and active ripple, since the exiting
ripples are in hardware animation mode anyway and can't be updated.
Bug: 21079749
Change-Id: I0f70c0c0feea32e2c70bb9b1b0fa3b7846b20c7f
| -rw-r--r-- | graphics/java/android/graphics/drawable/RippleComponent.java | 17 | ||||
| -rw-r--r-- | graphics/java/android/graphics/drawable/RippleDrawable.java | 9 |
2 files changed, 22 insertions, 4 deletions
diff --git a/graphics/java/android/graphics/drawable/RippleComponent.java b/graphics/java/android/graphics/drawable/RippleComponent.java index 0412e35..5ba2f93 100644 --- a/graphics/java/android/graphics/drawable/RippleComponent.java +++ b/graphics/java/android/graphics/drawable/RippleComponent.java @@ -57,14 +57,19 @@ abstract class RippleComponent { mBounds = bounds; } + public void onBoundsChange() { + if (!mHasMaxRadius) { + mTargetRadius = getTargetRadius(mBounds); + onTargetRadiusChanged(mTargetRadius); + } + } + public final void setup(float maxRadius, float density) { if (maxRadius >= 0) { mHasMaxRadius = true; mTargetRadius = maxRadius; } else { - final float halfWidth = mBounds.width() / 2.0f; - final float halfHeight = mBounds.height() / 2.0f; - mTargetRadius = (float) Math.sqrt(halfWidth * halfWidth + halfHeight * halfHeight); + mTargetRadius = getTargetRadius(mBounds); } mDensity = density; @@ -72,6 +77,12 @@ abstract class RippleComponent { onTargetRadiusChanged(mTargetRadius); } + private static float getTargetRadius(Rect bounds) { + final float halfWidth = bounds.width() / 2.0f; + final float halfHeight = bounds.height() / 2.0f; + return (float) Math.sqrt(halfWidth * halfWidth + halfHeight * halfHeight); + } + /** * Starts a ripple enter animation. * diff --git a/graphics/java/android/graphics/drawable/RippleDrawable.java b/graphics/java/android/graphics/drawable/RippleDrawable.java index efc171c..f7e8ed0 100644 --- a/graphics/java/android/graphics/drawable/RippleDrawable.java +++ b/graphics/java/android/graphics/drawable/RippleDrawable.java @@ -31,7 +31,6 @@ import android.graphics.Bitmap; import android.graphics.BitmapShader; import android.graphics.Canvas; import android.graphics.Color; -import android.graphics.ColorFilter; import android.graphics.Matrix; import android.graphics.Outline; import android.graphics.Paint; @@ -294,6 +293,14 @@ public class RippleDrawable extends LayerDrawable { onHotspotBoundsChanged(); } + if (mBackground != null) { + mBackground.onBoundsChange(); + } + + if (mRipple != null) { + mRipple.onBoundsChange(); + } + invalidateSelf(); } |
