diff options
author | Alan Viverette <alanv@google.com> | 2014-04-22 19:07:06 -0700 |
---|---|---|
committer | Alan Viverette <alanv@google.com> | 2014-04-22 19:07:06 -0700 |
commit | 61956606818918194a38e045a8e35e7108480e5e (patch) | |
tree | 328d1ebf6485b410f19d0b5263712bead1f8630d /graphics/java/android | |
parent | b78263d37690a6a5cb12dd31d82ad2e140b3dfc7 (diff) | |
download | frameworks_base-61956606818918194a38e045a8e35e7108480e5e.zip frameworks_base-61956606818918194a38e045a8e35e7108480e5e.tar.gz frameworks_base-61956606818918194a38e045a8e35e7108480e5e.tar.bz2 |
Add ripple to switches, radio buttons, check boxes, seek bars
BUG: 14231772
Change-Id: Ie40eac9f68815294460175965a999dd75f4144b5
Diffstat (limited to 'graphics/java/android')
4 files changed, 67 insertions, 5 deletions
diff --git a/graphics/java/android/graphics/drawable/Drawable.java b/graphics/java/android/graphics/drawable/Drawable.java index 21cd5db..74d1219 100644 --- a/graphics/java/android/graphics/drawable/Drawable.java +++ b/graphics/java/android/graphics/drawable/Drawable.java @@ -518,9 +518,16 @@ public abstract class Drawable { public void removeHotspot(int key) {} /** - * Removes all hotspots from the drawable. + * Immediately removes all hotspots from the drawable. */ public void clearHotspots() {} + + /** + * Sets the bounds to which hotspots are constrained. + * + * @hide until we finalize these APIs + */ + public void setHotspotBounds(int left, int top, int right, int bottom) {} /** * Whether this drawable requests projection. diff --git a/graphics/java/android/graphics/drawable/LayerDrawable.java b/graphics/java/android/graphics/drawable/LayerDrawable.java index b366987..639d719 100644 --- a/graphics/java/android/graphics/drawable/LayerDrawable.java +++ b/graphics/java/android/graphics/drawable/LayerDrawable.java @@ -290,6 +290,26 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { return false; } + + /** + * @hide + */ + @Override + public boolean isProjected() { + if (super.isProjected()) { + return true; + } + + final ChildDrawable[] layers = mLayerState.mChildren; + final int N = mLayerState.mNum; + for (int i = 0; i < N; i++) { + if (layers[i].mDrawable.isProjected()) { + return true; + } + } + + return false; + } /** * Add a new layer to this drawable. The new layer is identified by an id. diff --git a/graphics/java/android/graphics/drawable/Ripple.java b/graphics/java/android/graphics/drawable/Ripple.java index 796da50..e3f57e9 100644 --- a/graphics/java/android/graphics/drawable/Ripple.java +++ b/graphics/java/android/graphics/drawable/Ripple.java @@ -139,8 +139,8 @@ class Ripple { public boolean draw(Canvas c, Paint p) { final Rect bounds = mBounds; final Rect padding = mPadding; - final float dX = Math.max(mX, bounds.right - mX); - final float dY = Math.max(mY, bounds.bottom - mY); + final float dX = Math.max(mX - bounds.left, bounds.right - mX); + final float dY = Math.max(mY - bounds.top, bounds.bottom - mY); final int maxRadius = (int) Math.ceil(Math.sqrt(dX * dX + dY * dY)); final float enterState = mEnterState; diff --git a/graphics/java/android/graphics/drawable/TouchFeedbackDrawable.java b/graphics/java/android/graphics/drawable/TouchFeedbackDrawable.java index 813d755..1958cfe 100644 --- a/graphics/java/android/graphics/drawable/TouchFeedbackDrawable.java +++ b/graphics/java/android/graphics/drawable/TouchFeedbackDrawable.java @@ -53,6 +53,9 @@ public class TouchFeedbackDrawable extends LayerDrawable { private final Rect mTempRect = new Rect(); private final Rect mPaddingRect = new Rect(); + /** Current ripple effect bounds, used to constrain ripple effects. */ + private final Rect mHotspotBounds = new Rect(); + /** Current drawing bounds, used to compute dirty region. */ private final Rect mDrawingBounds = new Rect(); @@ -83,6 +86,9 @@ public class TouchFeedbackDrawable extends LayerDrawable { /** Whether the animation runnable has been posted. */ private boolean mAnimating; + /** Whether bounds are being overridden. */ + private boolean mOverrideBounds; + TouchFeedbackDrawable() { this(new TouchFeedbackState(null, null, null), null, null); } @@ -114,9 +120,22 @@ public class TouchFeedbackDrawable extends LayerDrawable { @Override protected void onBoundsChange(Rect bounds) { super.onBoundsChange(bounds); + + if (!mOverrideBounds) { + mHotspotBounds.set(bounds); + } + onHotspotBoundsChange(); + } + + private void onHotspotBoundsChange() { + final int x = mHotspotBounds.centerX(); + final int y = mHotspotBounds.centerY(); final int N = mActiveRipplesCount; for (int i = 0; i < N; i++) { + if (mState.mPinned) { + mActiveRipples[i].move(x, y); + } mActiveRipples[i].onBoundsChanged(); } } @@ -292,10 +311,10 @@ public class TouchFeedbackDrawable extends LayerDrawable { final Ripple ripple = mTouchedRipples.get(id); if (ripple == null) { - final Rect bounds = getBounds(); final Rect padding = mPaddingRect; getPadding(padding); + final Rect bounds = mHotspotBounds; if (mState.mPinned) { x = bounds.exactCenterX(); y = bounds.exactCenterY(); @@ -308,7 +327,12 @@ public class TouchFeedbackDrawable extends LayerDrawable { mActiveRipples[mActiveRipplesCount++] = newRipple; mTouchedRipples.put(id, newRipple); - } else if (!mState.mPinned) { + } else if (mState.mPinned) { + final Rect bounds = mHotspotBounds; + x = bounds.exactCenterX(); + y = bounds.exactCenterY(); + ripple.move(x, y); + } else { ripple.move(x, y); } @@ -338,6 +362,7 @@ public class TouchFeedbackDrawable extends LayerDrawable { final int n = mTouchedRipples.size(); for (int i = 0; i < n; i++) { + // TODO: Use a fast exit, maybe just fade out? mTouchedRipples.valueAt(i).animate().exit(); } @@ -348,6 +373,16 @@ public class TouchFeedbackDrawable extends LayerDrawable { } /** + * @hide + */ + @Override + public void setHotspotBounds(int left, int top, int right, int bottom) { + mOverrideBounds = true; + mHotspotBounds.set(left, top, right, bottom); + onHotspotBoundsChange(); + } + + /** * Schedules the next animation, if necessary. */ private void scheduleAnimation() { |