Merge "Only block invalidation in DrawableContainer initialization" into nyc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
7a372a13af
@@ -75,6 +75,9 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
|
|||||||
private long mEnterAnimationEnd;
|
private long mEnterAnimationEnd;
|
||||||
private long mExitAnimationEnd;
|
private long mExitAnimationEnd;
|
||||||
|
|
||||||
|
/** Callback that blocks invalidation. Used for drawable initialization. */
|
||||||
|
private BlockInvalidateCallback mBlockInvalidateCallback;
|
||||||
|
|
||||||
// overrides from Drawable
|
// overrides from Drawable
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -500,11 +503,14 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
|
|||||||
* @param d The drawable to initialize.
|
* @param d The drawable to initialize.
|
||||||
*/
|
*/
|
||||||
private void initializeDrawableForDisplay(Drawable d) {
|
private void initializeDrawableForDisplay(Drawable d) {
|
||||||
|
if (mBlockInvalidateCallback == null) {
|
||||||
|
mBlockInvalidateCallback = new BlockInvalidateCallback();
|
||||||
|
}
|
||||||
|
|
||||||
// Temporary fix for suspending callbacks during initialization. We
|
// Temporary fix for suspending callbacks during initialization. We
|
||||||
// don't want any of these setters causing an invalidate() since that
|
// don't want any of these setters causing an invalidate() since that
|
||||||
// may call back into DrawableContainer.
|
// may call back into DrawableContainer.
|
||||||
final Callback cb = d.getCallback();
|
d.setCallback(mBlockInvalidateCallback.wrap(d.getCallback()));
|
||||||
d.setCallback(null);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (mDrawableContainerState.mEnterFadeDuration <= 0 && mHasAlpha) {
|
if (mDrawableContainerState.mEnterFadeDuration <= 0 && mHasAlpha) {
|
||||||
@@ -537,7 +543,7 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
|
|||||||
hotspotBounds.right, hotspotBounds.bottom);
|
hotspotBounds.right, hotspotBounds.bottom);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
d.setCallback(cb);
|
d.setCallback(mBlockInvalidateCallback.unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1215,4 +1221,41 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
|
|||||||
mLastIndex = -1;
|
mLastIndex = -1;
|
||||||
mLastDrawable = null;
|
mLastDrawable = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback that blocks drawable invalidation.
|
||||||
|
*/
|
||||||
|
private static class BlockInvalidateCallback implements Drawable.Callback {
|
||||||
|
private Drawable.Callback mCallback;
|
||||||
|
|
||||||
|
public BlockInvalidateCallback wrap(Drawable.Callback callback) {
|
||||||
|
mCallback = callback;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Drawable.Callback unwrap() {
|
||||||
|
final Drawable.Callback callback = mCallback;
|
||||||
|
mCallback = null;
|
||||||
|
return callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void invalidateDrawable(@NonNull Drawable who) {
|
||||||
|
// Ignore invalidation.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void scheduleDrawable(@NonNull Drawable who, @NonNull Runnable what, long when) {
|
||||||
|
if (mCallback != null) {
|
||||||
|
mCallback.scheduleDrawable(who, what, when);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unscheduleDrawable(@NonNull Drawable who, @NonNull Runnable what) {
|
||||||
|
if (mCallback != null) {
|
||||||
|
mCallback.unscheduleDrawable(who, what);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user