From 120960e4669866817a28379393ce545c04404a04 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Tue, 30 Jan 2018 17:16:13 -0500 Subject: [PATCH] Lazily create AnimatedImageDrawable's runnable Test: manual This is only necessary for the software case. No need to create it for the more typical case of drawing in hardware. Change-Id: I0f041d59445f874160eeea5b13a54fd89fa26df8 --- .../graphics/drawable/AnimatedImageDrawable.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/graphics/java/android/graphics/drawable/AnimatedImageDrawable.java b/graphics/java/android/graphics/drawable/AnimatedImageDrawable.java index 27c8fda0d6e95..86e6fa8c2fc57 100644 --- a/graphics/java/android/graphics/drawable/AnimatedImageDrawable.java +++ b/graphics/java/android/graphics/drawable/AnimatedImageDrawable.java @@ -81,12 +81,7 @@ public class AnimatedImageDrawable extends Drawable implements Animatable2 { private State mState; - private Runnable mRunnable = new Runnable() { - @Override - public void run() { - invalidateSelf(); - } - }; + private Runnable mRunnable; /** * Pass this to {@link #setLoopCount} to loop infinitely. @@ -242,6 +237,9 @@ public class AnimatedImageDrawable extends Drawable implements Animatable2 { // a value <= 0 indicates that the drawable is stopped or that renderThread // will manage the animation if (nextUpdate > 0) { + if (mRunnable == null) { + mRunnable = this::invalidateSelf; + } scheduleSelf(mRunnable, nextUpdate); } else if (nextUpdate == FINISHED) { // This means the animation was drawn in software mode and ended.