Refresh opacity and statefulness on tint change
Also warns when LayerDrawable is created with an invalid child. This is not guaranteed to fail, but it's usually a bad sign. Bug: 33124798 Test: LayerDrawableTest, DrawableContainerTest Change-Id: Ie3e4200b27a9814cee7f5711d7df9710db513953
This commit is contained in:
@@ -210,6 +210,7 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
|
||||
/**
|
||||
* Change the global fade duration when a new drawable is entering
|
||||
* the scene.
|
||||
*
|
||||
* @param ms The amount of time to fade in milliseconds.
|
||||
*/
|
||||
public void setEnterFadeDuration(int ms) {
|
||||
@@ -219,6 +220,7 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
|
||||
/**
|
||||
* Change the global fade duration when a new drawable is leaving
|
||||
* the scene.
|
||||
*
|
||||
* @param ms The amount of time to fade in milliseconds.
|
||||
*/
|
||||
public void setExitFadeDuration(int ms) {
|
||||
@@ -375,6 +377,13 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
|
||||
|
||||
@Override
|
||||
public void invalidateDrawable(@NonNull Drawable who) {
|
||||
// This may have been called as the result of a tint changing, in
|
||||
// which case we may need to refresh the cached statefulness or
|
||||
// opacity.
|
||||
if (mDrawableContainerState != null) {
|
||||
mDrawableContainerState.invalidateCache();
|
||||
}
|
||||
|
||||
if (who == mCurrDrawable && getCallback() != null) {
|
||||
getCallback().invalidateDrawable(this);
|
||||
}
|
||||
@@ -822,8 +831,8 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
|
||||
mDrawables[pos] = dr;
|
||||
mNumChildren++;
|
||||
mChildrenChangingConfigurations |= dr.getChangingConfigurations();
|
||||
mCheckedStateful = false;
|
||||
mCheckedOpacity = false;
|
||||
|
||||
invalidateCache();
|
||||
|
||||
mConstantPadding = null;
|
||||
mCheckedPadding = false;
|
||||
@@ -833,6 +842,14 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
|
||||
return pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalidates the cached opacity and statefulness.
|
||||
*/
|
||||
void invalidateCache() {
|
||||
mCheckedOpacity = false;
|
||||
mCheckedStateful = false;
|
||||
}
|
||||
|
||||
final int getCapacity() {
|
||||
return mDrawables.length;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user