@Test public void mutateTest() { double delta = .005f; CompositeDrawable parent = new CompositeDrawable(); FitWidthBitmapDrawable child = new FitWidthBitmapDrawable(); parent.addChildDrawable(child); parent.getChildAt(0).getBoundsRule().bottom = ValueRule.inheritFromParentWithOffset(.5f, 100); CompositeDrawable newDrawable = (CompositeDrawable) parent.getConstantState().newDrawable(); parent.mutate(); assertTrue(parent.mMutated); CompositeDrawable.ChildDrawable newChild = newDrawable.getChildAt(0); assertNotSame(parent.getChildAt(0), newChild); assertEquals(parent.getChildAt(0).getBoundsRule().bottom.getAbsoluteValue(), newChild.getBoundsRule().bottom.getAbsoluteValue()); assertEquals(parent.getChildAt(0).getBoundsRule().bottom.getFraction(), newChild.getBoundsRule().bottom.getFraction(), delta); }
@Override public Drawable mutate() { if (!mMutated && super.mutate() == this) { mState = new CompositeState(mState, this, null); final ArrayList<ChildDrawable> children = mState.mChildren; for (int i = 0, n = children.size(); i < n; i++) { final Drawable dr = children.get(i).mDrawable; if (dr != null) { dr.mutate(); } } mMutated = true; } return this; }
CompositeDrawable extends Drawable implements Drawable.Callback { @Override public Drawable mutate() { if (!mMutated && super.mutate() == this) { mState = new CompositeState(mState, this, null); final ArrayList<ChildDrawable> children = mState.mChildren; for (int i = 0, n = children.size(); i < n; i++) { final Drawable dr = children.get(i).mDrawable; if (dr != null) { dr.mutate(); } } mMutated = true; } return this; } }
CompositeDrawable extends Drawable implements Drawable.Callback { @Override public Drawable mutate() { if (!mMutated && super.mutate() == this) { mState = new CompositeState(mState, this, null); final ArrayList<ChildDrawable> children = mState.mChildren; for (int i = 0, n = children.size(); i < n; i++) { final Drawable dr = children.get(i).mDrawable; if (dr != null) { dr.mutate(); } } mMutated = true; } return this; } CompositeDrawable();   CompositeDrawable(CompositeState state); }
CompositeDrawable extends Drawable implements Drawable.Callback { @Override public Drawable mutate() { if (!mMutated && super.mutate() == this) { mState = new CompositeState(mState, this, null); final ArrayList<ChildDrawable> children = mState.mChildren; for (int i = 0, n = children.size(); i < n; i++) { final Drawable dr = children.get(i).mDrawable; if (dr != null) { dr.mutate(); } } mMutated = true; } return this; } CompositeDrawable();   CompositeDrawable(CompositeState state); @Override ConstantState getConstantState(); @Override Drawable mutate(); void addChildDrawable(Drawable drawable); void setChildDrawableAt(int index, Drawable drawable); Drawable getDrawable(int index); ChildDrawable getChildAt(int index); void removeChild(int index); void removeDrawable(Drawable drawable); int getChildCount(); @Override void draw(Canvas canvas); @Override void setColorFilter(ColorFilter colorFilter); @Override int getOpacity(); @Override void setAlpha(int alpha); @Override int getAlpha(); @Override void invalidateDrawable(Drawable who); @Override void scheduleDrawable(Drawable who, Runnable what, long when); @Override void unscheduleDrawable(Drawable who, Runnable what); }
CompositeDrawable extends Drawable implements Drawable.Callback { @Override public Drawable mutate() { if (!mMutated && super.mutate() == this) { mState = new CompositeState(mState, this, null); final ArrayList<ChildDrawable> children = mState.mChildren; for (int i = 0, n = children.size(); i < n; i++) { final Drawable dr = children.get(i).mDrawable; if (dr != null) { dr.mutate(); } } mMutated = true; } return this; } CompositeDrawable();   CompositeDrawable(CompositeState state); @Override ConstantState getConstantState(); @Override Drawable mutate(); void addChildDrawable(Drawable drawable); void setChildDrawableAt(int index, Drawable drawable); Drawable getDrawable(int index); ChildDrawable getChildAt(int index); void removeChild(int index); void removeDrawable(Drawable drawable); int getChildCount(); @Override void draw(Canvas canvas); @Override void setColorFilter(ColorFilter colorFilter); @Override int getOpacity(); @Override void setAlpha(int alpha); @Override int getAlpha(); @Override void invalidateDrawable(Drawable who); @Override void scheduleDrawable(Drawable who, Runnable what, long when); @Override void unscheduleDrawable(Drawable who, Runnable what);  }