summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorAlan Viverette <alanv@google.com>2014-01-09 15:15:01 -0800
committerAlan Viverette <alanv@google.com>2014-01-09 15:15:01 -0800
commit8f164f64ec55a973fc043de932d853dd41772e4e (patch)
tree0bc5cb0b08f1004ac9e00f620978369f43c501bd /graphics
parentddf89c0cc847d1fac4d9885d2c91a2fb700e9d0c (diff)
downloadframeworks_base-8f164f64ec55a973fc043de932d853dd41772e4e.zip
frameworks_base-8f164f64ec55a973fc043de932d853dd41772e4e.tar.gz
frameworks_base-8f164f64ec55a973fc043de932d853dd41772e4e.tar.bz2
Fixing Drawable methods for find by layer ID and invalidation callback
BUG: 12475487, 12475575 Change-Id: Icbf11c76eaf9357fe2076bf60f7e448db65bc835
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/graphics/drawable/LayerDrawable.java20
1 files changed, 11 insertions, 9 deletions
diff --git a/graphics/java/android/graphics/drawable/LayerDrawable.java b/graphics/java/android/graphics/drawable/LayerDrawable.java
index f2e9988..7f00e50 100644
--- a/graphics/java/android/graphics/drawable/LayerDrawable.java
+++ b/graphics/java/android/graphics/drawable/LayerDrawable.java
@@ -229,15 +229,18 @@ public class LayerDrawable extends Drawable implements Drawable.Callback {
}
/**
- * Look for a layer with the given id, and returns its {@link Drawable}.
+ * Looks for a layer with the given ID and returns its {@link Drawable}.
+ * <p>
+ * If multiple layers are found for the given ID, returns the
+ * {@link Drawable} for the matching layer at the highest index.
*
* @param id The layer ID to search for.
- * @return The {@link Drawable} of the layer that has the given id in the hierarchy or null.
+ * @return The {@link Drawable} for the highest-indexed layer that has the
+ * given ID, or null if not found.
*/
public Drawable findDrawableByLayerId(int id) {
final ChildDrawable[] layers = mLayerState.mChildren;
- final int N = mLayerState.mNum;
- for (int i = 0; i < N; i++) {
+ for (int i = mLayerState.mNum - 1; i >= 0; i--) {
if (layers[i].mId == id) {
return layers[i].mDrawable;
}
@@ -370,7 +373,7 @@ public class LayerDrawable extends Drawable implements Drawable.Callback {
}
/**
- * Invalidates cached padding.
+ * Invalidates cached padding and recomputes child bounds.
*/
private void invalidatePadding() {
mHasCachedPadding = false;
@@ -379,10 +382,9 @@ public class LayerDrawable extends Drawable implements Drawable.Callback {
@Override
public void invalidateDrawable(Drawable who) {
- final Callback callback = getCallback();
- if (callback != null) {
- callback.invalidateDrawable(this);
- }
+ // Something changed, maybe it was the child drawable's padding.
+ invalidatePadding();
+ invalidateSelf();
}
@Override