diff options
| author | 2014-07-13 17:49:39 -0700 | |
|---|---|---|
| committer | 2014-07-16 00:06:14 +0000 | |
| commit | 7068c39526459c18a020e29c1ebfa6aed54e2d0f (patch) | |
| tree | 82a88b511a75b0ce26fca637efd01abba14c27b5 | |
| parent | 67eb5bbd5374fe96209cf7b68543cb48ee959b96 (diff) | |
Fix hotspot movement on focus change
BUG: 15726988
Change-Id: I97f88e5f7e404ecfcd5c254fddd18c8f6616064e
6 files changed, 75 insertions, 2 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index a09a0619fbbc..fdbc61966127 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -4852,8 +4852,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ private void manageFocusHotspot(boolean focused, View v) { final Rect r = new Rect(); - if (!focused && v != null && mAttachInfo != null) { - v.getBoundsOnScreen(r); + if (v != null && mAttachInfo != null) { + v.getHotspotBounds(r); final int[] location = mAttachInfo.mTmpLocation; getLocationOnScreen(location); r.offset(-location[0], -location[1]); @@ -4867,6 +4867,22 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } /** + * Populates <code>outRect</code> with the hotspot bounds. By default, + * the hotspot bounds are identical to the screen bounds. + * + * @param outRect rect to populate with hotspot bounds + * @hide Only for internal use by views and widgets. + */ + public void getHotspotBounds(Rect outRect) { + final Drawable background = getBackground(); + if (background != null) { + background.getHotspotBounds(outRect); + } else { + getBoundsOnScreen(outRect); + } + } + + /** * Request that a rectangle of this view be visible on the screen, * scrolling if necessary just enough. * diff --git a/graphics/java/android/graphics/drawable/Drawable.java b/graphics/java/android/graphics/drawable/Drawable.java index e7a073c2e944..89236ad5c87e 100644 --- a/graphics/java/android/graphics/drawable/Drawable.java +++ b/graphics/java/android/graphics/drawable/Drawable.java @@ -516,6 +516,11 @@ public abstract class Drawable { */ public void setHotspotBounds(int left, int top, int right, int bottom) {} + /** @hide For internal use only. Individual results may vary. */ + public void getHotspotBounds(Rect outRect) { + outRect.set(getBounds()); + } + /** * Whether this drawable requests projection. * diff --git a/graphics/java/android/graphics/drawable/DrawableContainer.java b/graphics/java/android/graphics/drawable/DrawableContainer.java index ed44cde4d632..771322dfbfef 100644 --- a/graphics/java/android/graphics/drawable/DrawableContainer.java +++ b/graphics/java/android/graphics/drawable/DrawableContainer.java @@ -52,6 +52,7 @@ public class DrawableContainer extends Drawable implements Drawable.Callback { */ private static final boolean DEFAULT_DITHER = true; private DrawableContainerState mDrawableContainerState; + private Rect mHotspotBounds; private Drawable mCurrDrawable; private int mAlpha = 0xFF; @@ -273,11 +274,27 @@ public class DrawableContainer extends Drawable implements Drawable.Callback { @Override public void setHotspotBounds(int left, int top, int right, int bottom) { + if (mHotspotBounds == null) { + mHotspotBounds = new Rect(left, top, bottom, right); + } else { + mHotspotBounds.set(left, top, bottom, right); + } + if (mCurrDrawable != null) { mCurrDrawable.setHotspotBounds(left, top, right, bottom); } } + /** @hide */ + @Override + public void getHotspotBounds(Rect outRect) { + if (mHotspotBounds != null) { + outRect.set(mHotspotBounds); + } else { + super.getHotspotBounds(outRect); + } + } + @Override protected boolean onStateChange(int[] state) { if (mLastDrawable != null) { @@ -430,6 +447,12 @@ public class DrawableContainer extends Drawable implements Drawable.Callback { d.setBounds(getBounds()); d.setLayoutDirection(getLayoutDirection()); d.setAutoMirrored(mDrawableContainerState.mAutoMirrored); + + final Rect hotspotBounds = mHotspotBounds; + if (hotspotBounds != null) { + d.setHotspotBounds(hotspotBounds.left, hotspotBounds.top, + hotspotBounds.right, hotspotBounds.bottom); + } } } else { mCurrDrawable = null; diff --git a/graphics/java/android/graphics/drawable/InsetDrawable.java b/graphics/java/android/graphics/drawable/InsetDrawable.java index d214a4736367..6db96b694c6c 100644 --- a/graphics/java/android/graphics/drawable/InsetDrawable.java +++ b/graphics/java/android/graphics/drawable/InsetDrawable.java @@ -232,6 +232,12 @@ public class InsetDrawable extends Drawable implements Drawable.Callback { mInsetState.mDrawable.setHotspotBounds(left, top, right, bottom); } + /** @hide */ + @Override + public void getHotspotBounds(Rect outRect) { + mInsetState.mDrawable.getHotspotBounds(outRect); + } + @Override public boolean setVisible(boolean visible, boolean restart) { mInsetState.mDrawable.setVisible(visible, restart); diff --git a/graphics/java/android/graphics/drawable/LayerDrawable.java b/graphics/java/android/graphics/drawable/LayerDrawable.java index fa68bc5a468a..8d83c74069c2 100644 --- a/graphics/java/android/graphics/drawable/LayerDrawable.java +++ b/graphics/java/android/graphics/drawable/LayerDrawable.java @@ -80,6 +80,7 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { private int[] mPaddingB; private final Rect mTmpRect = new Rect(); + private Rect mHotspotBounds; private boolean mMutated; /** @@ -630,6 +631,22 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { for (int i = 0; i < N; i++) { array[i].mDrawable.setHotspotBounds(left, top, right, bottom); } + + if (mHotspotBounds == null) { + mHotspotBounds = new Rect(left, top, right, bottom); + } else { + mHotspotBounds.set(left, top, right, bottom); + } + } + + /** @hide */ + @Override + public void getHotspotBounds(Rect outRect) { + if (mHotspotBounds != null) { + outRect.set(mHotspotBounds); + } else { + super.getHotspotBounds(outRect); + } } @Override diff --git a/graphics/java/android/graphics/drawable/RippleDrawable.java b/graphics/java/android/graphics/drawable/RippleDrawable.java index 4f0531390d13..f955f7c39db0 100644 --- a/graphics/java/android/graphics/drawable/RippleDrawable.java +++ b/graphics/java/android/graphics/drawable/RippleDrawable.java @@ -471,6 +471,12 @@ public class RippleDrawable extends LayerDrawable { onHotspotBoundsChanged(); } + /** @hide */ + @Override + public void getHotspotBounds(Rect outRect) { + outRect.set(mHotspotBounds); + } + /** * Notifies all the animating ripples that the hotspot bounds have changed. */ |