diff options
Diffstat (limited to 'graphics')
8 files changed, 91 insertions, 57 deletions
diff --git a/graphics/java/android/graphics/drawable/AnimatedRotateDrawable.java b/graphics/java/android/graphics/drawable/AnimatedRotateDrawable.java index 58206d4..39a7dd2 100644 --- a/graphics/java/android/graphics/drawable/AnimatedRotateDrawable.java +++ b/graphics/java/android/graphics/drawable/AnimatedRotateDrawable.java @@ -159,20 +159,23 @@ public class AnimatedRotateDrawable extends Drawable implements Drawable.Callbac } public void invalidateDrawable(Drawable who) { - if (mCallback != null) { - mCallback.invalidateDrawable(this); + final Callback callback = getCallback(); + if (callback != null) { + callback.invalidateDrawable(this); } } public void scheduleDrawable(Drawable who, Runnable what, long when) { - if (mCallback != null) { - mCallback.scheduleDrawable(this, what, when); + final Callback callback = getCallback(); + if (callback != null) { + callback.scheduleDrawable(this, what, when); } } public void unscheduleDrawable(Drawable who, Runnable what) { - if (mCallback != null) { - mCallback.unscheduleDrawable(this, what); + final Callback callback = getCallback(); + if (callback != null) { + callback.unscheduleDrawable(this, what); } } diff --git a/graphics/java/android/graphics/drawable/ClipDrawable.java b/graphics/java/android/graphics/drawable/ClipDrawable.java index a772871..0d44591 100644 --- a/graphics/java/android/graphics/drawable/ClipDrawable.java +++ b/graphics/java/android/graphics/drawable/ClipDrawable.java @@ -111,20 +111,23 @@ public class ClipDrawable extends Drawable implements Drawable.Callback { // overrides from Drawable.Callback public void invalidateDrawable(Drawable who) { - if (mCallback != null) { - mCallback.invalidateDrawable(this); + final Callback callback = getCallback(); + if (callback != null) { + callback.invalidateDrawable(this); } } public void scheduleDrawable(Drawable who, Runnable what, long when) { - if (mCallback != null) { - mCallback.scheduleDrawable(this, what, when); + final Callback callback = getCallback(); + if (callback != null) { + callback.scheduleDrawable(this, what, when); } } public void unscheduleDrawable(Drawable who, Runnable what) { - if (mCallback != null) { - mCallback.unscheduleDrawable(this, what); + final Callback callback = getCallback(); + if (callback != null) { + callback.unscheduleDrawable(this, what); } } diff --git a/graphics/java/android/graphics/drawable/Drawable.java b/graphics/java/android/graphics/drawable/Drawable.java index 6cdafdb..c423550 100644 --- a/graphics/java/android/graphics/drawable/Drawable.java +++ b/graphics/java/android/graphics/drawable/Drawable.java @@ -39,6 +39,7 @@ import android.util.Xml; import java.io.IOException; import java.io.InputStream; +import java.lang.ref.WeakReference; import java.util.Arrays; /** @@ -112,7 +113,7 @@ public abstract class Drawable { private int mLevel = 0; private int mChangingConfigurations = 0; private Rect mBounds = ZERO_BOUNDS_RECT; // lazily becomes a new Rect() - /*package*/ Callback mCallback = null; + private WeakReference<Callback> mCallback = null; private boolean mVisible = true; /** @@ -291,22 +292,41 @@ public abstract class Drawable { * that want to support animated drawables. * * @param cb The client's Callback implementation. + * + * @see #getCallback() */ public final void setCallback(Callback cb) { - mCallback = cb; + mCallback = new WeakReference<Callback>(cb); } /** + * Return the current {@link Callback} implementation attached to this + * Drawable. + * + * @return A {@link Callback} instance or null if no callback was set. + * + * @see #setCallback(android.graphics.drawable.Drawable.Callback) + */ + public Callback getCallback() { + if (mCallback != null) { + return mCallback.get(); + } + return null; + } + + /** * Use the current {@link Callback} implementation to have this Drawable * redrawn. Does nothing if there is no Callback attached to the * Drawable. * * @see Callback#invalidateDrawable + * @see #getCallback() + * @see #setCallback(android.graphics.drawable.Drawable.Callback) */ - public void invalidateSelf() - { - if (mCallback != null) { - mCallback.invalidateDrawable(this); + public void invalidateSelf() { + final Callback callback = getCallback(); + if (callback != null) { + callback.invalidateDrawable(this); } } @@ -320,10 +340,10 @@ public abstract class Drawable { * * @see Callback#scheduleDrawable */ - public void scheduleSelf(Runnable what, long when) - { - if (mCallback != null) { - mCallback.scheduleDrawable(this, what, when); + public void scheduleSelf(Runnable what, long when) { + final Callback callback = getCallback(); + if (callback != null) { + callback.scheduleDrawable(this, what, when); } } @@ -336,10 +356,10 @@ public abstract class Drawable { * * @see Callback#unscheduleDrawable */ - public void unscheduleSelf(Runnable what) - { - if (mCallback != null) { - mCallback.unscheduleDrawable(this, what); + public void unscheduleSelf(Runnable what) { + final Callback callback = getCallback(); + if (callback != null) { + callback.unscheduleDrawable(this, what); } } diff --git a/graphics/java/android/graphics/drawable/DrawableContainer.java b/graphics/java/android/graphics/drawable/DrawableContainer.java index e55a746..0a580eb 100644 --- a/graphics/java/android/graphics/drawable/DrawableContainer.java +++ b/graphics/java/android/graphics/drawable/DrawableContainer.java @@ -236,20 +236,20 @@ public class DrawableContainer extends Drawable implements Drawable.Callback { } public void invalidateDrawable(Drawable who) { - if (who == mCurrDrawable && mCallback != null) { - mCallback.invalidateDrawable(this); + if (who == mCurrDrawable && getCallback() != null) { + getCallback().invalidateDrawable(this); } } public void scheduleDrawable(Drawable who, Runnable what, long when) { - if (who == mCurrDrawable && mCallback != null) { - mCallback.scheduleDrawable(this, what, when); + if (who == mCurrDrawable && getCallback() != null) { + getCallback().scheduleDrawable(this, what, when); } } public void unscheduleDrawable(Drawable who, Runnable what) { - if (who == mCurrDrawable && mCallback != null) { - mCallback.unscheduleDrawable(this, what); + if (who == mCurrDrawable && getCallback() != null) { + getCallback().unscheduleDrawable(this, what); } } diff --git a/graphics/java/android/graphics/drawable/InsetDrawable.java b/graphics/java/android/graphics/drawable/InsetDrawable.java index a9c983e..3a74dfd 100644 --- a/graphics/java/android/graphics/drawable/InsetDrawable.java +++ b/graphics/java/android/graphics/drawable/InsetDrawable.java @@ -131,20 +131,23 @@ public class InsetDrawable extends Drawable implements Drawable.Callback // overrides from Drawable.Callback public void invalidateDrawable(Drawable who) { - if (mCallback != null) { - mCallback.invalidateDrawable(this); + final Callback callback = getCallback(); + if (callback != null) { + callback.invalidateDrawable(this); } } public void scheduleDrawable(Drawable who, Runnable what, long when) { - if (mCallback != null) { - mCallback.scheduleDrawable(this, what, when); + final Callback callback = getCallback(); + if (callback != null) { + callback.scheduleDrawable(this, what, when); } } public void unscheduleDrawable(Drawable who, Runnable what) { - if (mCallback != null) { - mCallback.unscheduleDrawable(this, what); + final Callback callback = getCallback(); + if (callback != null) { + callback.unscheduleDrawable(this, what); } } diff --git a/graphics/java/android/graphics/drawable/LayerDrawable.java b/graphics/java/android/graphics/drawable/LayerDrawable.java index 09c041f..84da170 100644 --- a/graphics/java/android/graphics/drawable/LayerDrawable.java +++ b/graphics/java/android/graphics/drawable/LayerDrawable.java @@ -26,7 +26,6 @@ import android.graphics.ColorFilter; import android.graphics.PixelFormat; import android.graphics.Rect; import android.util.AttributeSet; -import android.util.Slog; import android.view.View; import java.io.IOException; @@ -307,20 +306,23 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { // overrides from Drawable.Callback public void invalidateDrawable(Drawable who) { - if (mCallback != null) { - mCallback.invalidateDrawable(this); + final Callback callback = getCallback(); + if (callback != null) { + callback.invalidateDrawable(this); } } public void scheduleDrawable(Drawable who, Runnable what, long when) { - if (mCallback != null) { - mCallback.scheduleDrawable(this, what, when); + final Callback callback = getCallback(); + if (callback != null) { + callback.scheduleDrawable(this, what, when); } } public void unscheduleDrawable(Drawable who, Runnable what) { - if (mCallback != null) { - mCallback.unscheduleDrawable(this, what); + final Callback callback = getCallback(); + if (callback != null) { + callback.unscheduleDrawable(this, what); } } diff --git a/graphics/java/android/graphics/drawable/RotateDrawable.java b/graphics/java/android/graphics/drawable/RotateDrawable.java index f3f3653..212ddfa 100644 --- a/graphics/java/android/graphics/drawable/RotateDrawable.java +++ b/graphics/java/android/graphics/drawable/RotateDrawable.java @@ -117,20 +117,23 @@ public class RotateDrawable extends Drawable implements Drawable.Callback { } public void invalidateDrawable(Drawable who) { - if (mCallback != null) { - mCallback.invalidateDrawable(this); + final Callback callback = getCallback(); + if (callback != null) { + callback.invalidateDrawable(this); } } public void scheduleDrawable(Drawable who, Runnable what, long when) { - if (mCallback != null) { - mCallback.scheduleDrawable(this, what, when); + final Callback callback = getCallback(); + if (callback != null) { + callback.scheduleDrawable(this, what, when); } } public void unscheduleDrawable(Drawable who, Runnable what) { - if (mCallback != null) { - mCallback.unscheduleDrawable(this, what); + final Callback callback = getCallback(); + if (callback != null) { + callback.unscheduleDrawable(this, what); } } diff --git a/graphics/java/android/graphics/drawable/ScaleDrawable.java b/graphics/java/android/graphics/drawable/ScaleDrawable.java index dcaf20b..055576d 100644 --- a/graphics/java/android/graphics/drawable/ScaleDrawable.java +++ b/graphics/java/android/graphics/drawable/ScaleDrawable.java @@ -127,20 +127,20 @@ public class ScaleDrawable extends Drawable implements Drawable.Callback { // overrides from Drawable.Callback public void invalidateDrawable(Drawable who) { - if (mCallback != null) { - mCallback.invalidateDrawable(this); + if (getCallback() != null) { + getCallback().invalidateDrawable(this); } } public void scheduleDrawable(Drawable who, Runnable what, long when) { - if (mCallback != null) { - mCallback.scheduleDrawable(this, what, when); + if (getCallback() != null) { + getCallback().scheduleDrawable(this, what, when); } } public void unscheduleDrawable(Drawable who, Runnable what) { - if (mCallback != null) { - mCallback.unscheduleDrawable(this, what); + if (getCallback() != null) { + getCallback().unscheduleDrawable(this, what); } } |