/** * 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; }
/** 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; }