DrawableContainer was not respecting the value returned by Drawable.getPadding(Rect).
Before this change, DrawableContainer would always return true from getPadding(Rect)
even if all of its children were returning false from getPadding(Rect). This change
modifies this behavior to respect getPadding(Rect): mConstantPadding is kept null
when getPadding(Rect) returns false for all of the children and a flag is set
to avoid recomputing that value every time getConstantPadding() is invoked.
diff --git a/graphics/java/android/graphics/drawable/DrawableContainer.java b/graphics/java/android/graphics/drawable/DrawableContainer.java
index 376b1df..dc80cf5 100644
--- a/graphics/java/android/graphics/drawable/DrawableContainer.java
+++ b/graphics/java/android/graphics/drawable/DrawableContainer.java
@@ -272,6 +272,8 @@
boolean mCheckedConstantState;
boolean mCanConstantState;
+ boolean mPaddingChecked = false;
+
DrawableContainerState(DrawableContainerState orig, DrawableContainer owner) {
mOwner = owner;
@@ -334,6 +336,7 @@
mHaveStateful = false;
mConstantPadding = null;
+ mPaddingChecked = false;
mComputedConstantSize = false;
return pos;
@@ -359,23 +362,25 @@
if (mVariablePadding) {
return null;
}
- if (mConstantPadding != null) {
+ if (mConstantPadding != null || mPaddingChecked) {
return mConstantPadding;
}
- final Rect r = new Rect(0, 0, 0, 0);
+ Rect r = null;
final Rect t = new Rect();
final int N = getChildCount();
final Drawable[] drawables = mDrawables;
for (int i = 0; i < N; i++) {
if (drawables[i].getPadding(t)) {
+ if (r == null) r = new Rect(0, 0, 0, 0);
if (t.left > r.left) r.left = t.left;
if (t.top > r.top) r.top = t.top;
if (t.right > r.right) r.right = t.right;
if (t.bottom > r.bottom) r.bottom = t.bottom;
}
}
- return (mConstantPadding=r);
+ mPaddingChecked = true;
+ return (mConstantPadding = r);
}
public final void setConstantSize(boolean constant) {