Merge change 1463 into donut

* changes:
  Fixes #1846038. DrawableContainer was wrongly returning its opacity by ignoring the visibility of the currently selected layer. This change simply reports a TRANSPARENT opacity if there is no currently selected layer of if the selected layer is not visible. Otherwise it reports the opacity computed by the state class.
This commit is contained in:
Android (Google) Code Review
2009-05-12 11:10:34 -07:00
3 changed files with 30 additions and 39 deletions

View File

@@ -4556,6 +4556,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback {
* *
* @hide Pending API council approval * @hide Pending API council approval
*/ */
@ViewDebug.ExportedProperty
public boolean isOpaque() { public boolean isOpaque() {
return mBGDrawable != null && mBGDrawable.getOpacity() == PixelFormat.OPAQUE; return mBGDrawable != null && mBGDrawable.getOpacity() == PixelFormat.OPAQUE;
} }

View File

@@ -823,7 +823,7 @@ public class RelativeLayout extends ViewGroup {
@ViewDebug.IntToString(from = RIGHT_OF, to = "rightOf") @ViewDebug.IntToString(from = RIGHT_OF, to = "rightOf")
}, mapping = { }, mapping = {
@ViewDebug.IntToString(from = TRUE, to = "true"), @ViewDebug.IntToString(from = TRUE, to = "true"),
@ViewDebug.IntToString(from = 0, to = "NO_ID") @ViewDebug.IntToString(from = 0, to = "FALSE/NO_ID")
}) })
private int[] mRules = new int[VERB_COUNT]; private int[] mRules = new int[VERB_COUNT];

View File

@@ -181,7 +181,8 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
@Override @Override
public int getOpacity() { public int getOpacity() {
return mDrawableContainerState.getOpacity(); return mCurrDrawable == null || !mCurrDrawable.isVisible() ? PixelFormat.TRANSPARENT :
mDrawableContainerState.getOpacity();
} }
public boolean selectDrawable(int idx) public boolean selectDrawable(int idx)
@@ -336,13 +337,11 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
return pos; return pos;
} }
public final int getChildCount() public final int getChildCount() {
{
return mNumChildren; return mNumChildren;
} }
public final Drawable[] getChildren() public final Drawable[] getChildren() {
{
return mDrawables; return mDrawables;
} }
@@ -350,13 +349,11 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
* all frames in the set (false), or to use the padding value of the frame * all frames in the set (false), or to use the padding value of the frame
* being shown (true). Default value is false. * being shown (true). Default value is false.
*/ */
public final void setVariablePadding(boolean variable) public final void setVariablePadding(boolean variable) {
{
mVariablePadding = variable; mVariablePadding = variable;
} }
public final Rect getConstantPadding() public final Rect getConstantPadding() {
{
if (mVariablePadding) { if (mVariablePadding) {
return null; return null;
} }
@@ -364,11 +361,12 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
return mConstantPadding; return mConstantPadding;
} }
Rect r = new Rect(0, 0, 0, 0); final Rect r = new Rect(0, 0, 0, 0);
Rect t = new Rect(); final Rect t = new Rect();
final int N = getChildCount(); final int N = getChildCount();
final Drawable[] drawables = mDrawables;
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
if (mDrawables[i].getPadding(t)) { if (drawables[i].getPadding(t)) {
if (t.left > r.left) r.left = t.left; if (t.left > r.left) r.left = t.left;
if (t.top > r.top) r.top = t.top; if (t.top > r.top) r.top = t.top;
if (t.right > r.right) r.right = t.right; if (t.right > r.right) r.right = t.right;
@@ -378,18 +376,15 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
return (mConstantPadding=r); return (mConstantPadding=r);
} }
public final void setConstantSize(boolean constant) public final void setConstantSize(boolean constant) {
{
mConstantSize = constant; mConstantSize = constant;
} }
public final boolean isConstantSize() public final boolean isConstantSize() {
{
return mConstantSize; return mConstantSize;
} }
public final int getConstantWidth() public final int getConstantWidth() {
{
if (!mComputedConstantSize) { if (!mComputedConstantSize) {
computeConstantSize(); computeConstantSize();
} }
@@ -397,8 +392,7 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
return mConstantWidth; return mConstantWidth;
} }
public final int getConstantHeight() public final int getConstantHeight() {
{
if (!mComputedConstantSize) { if (!mComputedConstantSize) {
computeConstantSize(); computeConstantSize();
} }
@@ -406,8 +400,7 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
return mConstantHeight; return mConstantHeight;
} }
public final int getConstantMinimumWidth() public final int getConstantMinimumWidth() {
{
if (!mComputedConstantSize) { if (!mComputedConstantSize) {
computeConstantSize(); computeConstantSize();
} }
@@ -415,8 +408,7 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
return mConstantMinimumWidth; return mConstantMinimumWidth;
} }
public final int getConstantMinimumHeight() public final int getConstantMinimumHeight() {
{
if (!mComputedConstantSize) { if (!mComputedConstantSize) {
computeConstantSize(); computeConstantSize();
} }
@@ -424,15 +416,15 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
return mConstantMinimumHeight; return mConstantMinimumHeight;
} }
private void computeConstantSize() private void computeConstantSize() {
{
mComputedConstantSize = true; mComputedConstantSize = true;
final int N = getChildCount(); final int N = getChildCount();
final Drawable[] drawables = mDrawables;
mConstantWidth = mConstantHeight = 0; mConstantWidth = mConstantHeight = 0;
mConstantMinimumWidth = mConstantMinimumHeight = 0; mConstantMinimumWidth = mConstantMinimumHeight = 0;
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
Drawable dr = mDrawables[i]; Drawable dr = drawables[i];
int s = dr.getIntrinsicWidth(); int s = dr.getIntrinsicWidth();
if (s > mConstantWidth) mConstantWidth = s; if (s > mConstantWidth) mConstantWidth = s;
s = dr.getIntrinsicHeight(); s = dr.getIntrinsicHeight();
@@ -444,17 +436,16 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
} }
} }
public final int getOpacity() public final int getOpacity() {
{
if (mHaveOpacity) { if (mHaveOpacity) {
return mOpacity; return mOpacity;
} }
final int N = getChildCount(); final int N = getChildCount();
int op = N > 0 final Drawable[] drawables = mDrawables;
? mDrawables[0].getOpacity() : PixelFormat.TRANSPARENT; int op = N > 0 ? drawables[0].getOpacity() : PixelFormat.TRANSPARENT;
for (int i = 1; i < N; i++) { for (int i = 1; i < N; i++) {
op = Drawable.resolveOpacity(op, mDrawables[i].getOpacity()); op = Drawable.resolveOpacity(op, drawables[i].getOpacity());
} }
mOpacity = op; mOpacity = op;
mHaveOpacity = true; mHaveOpacity = true;
@@ -480,8 +471,7 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
return stateful; return stateful;
} }
public void growArray(int oldSize, int newSize) public void growArray(int oldSize, int newSize) {
{
Drawable[] newDrawables = new Drawable[newSize]; Drawable[] newDrawables = new Drawable[newSize];
System.arraycopy(mDrawables, 0, newDrawables, 0, oldSize); System.arraycopy(mDrawables, 0, newDrawables, 0, oldSize);
mDrawables = newDrawables; mDrawables = newDrawables;