Skip to content

Commit 37419d7

Browse files
committed
Fix bug 5581874 - Animated drawables don't start as expected
Fix a bug that caused animated drawables to not schedule properly when a view has not yet been attached. Also make ImageViews update their drawable visibility state properly, which will handle scheduling concerns as ImageViews are attached and detached from their windows. This should also fix the bug where animated notification icons in the status bar do not animate until the posting app posts an update to the notification. Change-Id: I24c403182831258d1f251736e920c9efe1d38299
1 parent 843e04d commit 37419d7

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

core/java/android/view/View.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11402,8 +11402,12 @@ public void invalidateDrawable(Drawable drawable) {
1140211402
* {@link SystemClock#uptimeMillis} timebase.
1140311403
*/
1140411404
public void scheduleDrawable(Drawable who, Runnable what, long when) {
11405-
if (verifyDrawable(who) && what != null && mAttachInfo != null) {
11406-
mAttachInfo.mHandler.postAtTime(what, who, when);
11405+
if (verifyDrawable(who) && what != null) {
11406+
if (mAttachInfo != null) {
11407+
mAttachInfo.mHandler.postAtTime(what, who, when);
11408+
} else {
11409+
ViewRootImpl.getRunQueue().postDelayed(what, when - SystemClock.uptimeMillis());
11410+
}
1140711411
}
1140811412
}
1140911413

@@ -11414,8 +11418,12 @@ public void scheduleDrawable(Drawable who, Runnable what, long when) {
1141411418
* @param what the action to cancel
1141511419
*/
1141611420
public void unscheduleDrawable(Drawable who, Runnable what) {
11417-
if (verifyDrawable(who) && what != null && mAttachInfo != null) {
11418-
mAttachInfo.mHandler.removeCallbacks(what, who);
11421+
if (verifyDrawable(who) && what != null) {
11422+
if (mAttachInfo != null) {
11423+
mAttachInfo.mHandler.removeCallbacks(what, who);
11424+
} else {
11425+
ViewRootImpl.getRunQueue().removeCallbacks(what);
11426+
}
1141911427
}
1142011428
}
1142111429

core/java/android/widget/ImageView.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,4 +1035,28 @@ private void applyColorMod() {
10351035
mDrawable.setAlpha(mAlpha * mViewAlphaScale >> 8);
10361036
}
10371037
}
1038+
1039+
@Override
1040+
public void setVisibility(int visibility) {
1041+
super.setVisibility(visibility);
1042+
if (mDrawable != null) {
1043+
mDrawable.setVisible(visibility == VISIBLE, false);
1044+
}
1045+
}
1046+
1047+
@Override
1048+
public void onAttachedToWindow() {
1049+
super.onAttachedToWindow();
1050+
if (mDrawable != null) {
1051+
mDrawable.setVisible(getVisibility() == VISIBLE, false);
1052+
}
1053+
}
1054+
1055+
@Override
1056+
public void onDetachedFromWindow() {
1057+
super.onDetachedFromWindow();
1058+
if (mDrawable != null) {
1059+
mDrawable.setVisible(false, false);
1060+
}
1061+
}
10381062
}

0 commit comments

Comments
 (0)