/** * As {@code setCurrent}, but without invalidating a drawable. Subclasses are responsible to call * {@code invalidateSelf} on their own. * * @param newDelegate * @return the previous delegate */ protected Drawable setCurrentWithoutInvalidate(Drawable newDelegate) { Drawable previousDelegate = mCurrentDelegate; DrawableUtils.setCallbacks(previousDelegate, null, null); DrawableUtils.setCallbacks(newDelegate, null, null); DrawableUtils.setDrawableProperties(newDelegate, mDrawableProperties); DrawableUtils.copyProperties(newDelegate, previousDelegate); DrawableUtils.setCallbacks(newDelegate, this, this); mCurrentDelegate = newDelegate; return previousDelegate; }
/** * Constructs a new layer drawable. * * @param layers the layers that this drawable displays */ public ArrayDrawable(Drawable[] layers) { Preconditions.checkNotNull(layers); mLayers = layers; for (int i = 0; i < mLayers.length; i++) { DrawableUtils.setCallbacks(mLayers[i], this, this); } mDrawableParents = new DrawableParent[mLayers.length]; }
/** Sets a new drawable at the specified index, and return the previous drawable, if any. */ @Nullable public Drawable setDrawable(int index, @Nullable Drawable drawable) { Preconditions.checkArgument(index >= 0); Preconditions.checkArgument(index < mLayers.length); final Drawable oldDrawable = mLayers[index]; if (drawable != oldDrawable) { if (drawable != null && mIsMutated) { drawable.mutate(); } DrawableUtils.setCallbacks(mLayers[index], null, null); DrawableUtils.setCallbacks(drawable, null, null); DrawableUtils.setDrawableProperties(drawable, mDrawableProperties); DrawableUtils.copyProperties(drawable, this); DrawableUtils.setCallbacks(drawable, this, this); mIsStatefulCalculated = false; mLayers[index] = drawable; invalidateSelf(); } return oldDrawable; }
/** * Constructs a new forwarding drawable. * * @param drawable drawable that this forwarding drawable will forward to */ public ForwardingDrawable(Drawable drawable) { mCurrentDelegate = drawable; DrawableUtils.setCallbacks(mCurrentDelegate, this, this); }