From a22a380fbbe224783d8b82440ca8692b0ff5b0a2 Mon Sep 17 00:00:00 2001 From: Dan Sandler Date: Wed, 13 May 2015 00:12:47 -0400 Subject: Add Icon support to ImageView. ImageView.setImageIcon() is remotable, so you can also call RemoteViews.setImageViewIcon(). Bug: 18568715 Change-Id: I456cfa65102e1983d3392d822584d154a6cd761a --- core/java/android/widget/ImageView.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'core/java/android/widget/ImageView.java') diff --git a/core/java/android/widget/ImageView.java b/core/java/android/widget/ImageView.java index 05059bc..94cda88 100644 --- a/core/java/android/widget/ImageView.java +++ b/core/java/android/widget/ImageView.java @@ -36,8 +36,10 @@ import android.graphics.RectF; import android.graphics.Xfermode; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; +import android.graphics.drawable.Icon; import android.net.Uri; import android.os.Build; +import android.os.Handler; import android.text.TextUtils; import android.util.AttributeSet; import android.util.Log; @@ -462,6 +464,21 @@ public class ImageView extends View { } /** + * Sets the content of this ImageView to the specified Icon. + * + *

Depending on the Icon type, this may do Bitmap reading and decoding + * on the UI thread, which can cause UI jank. If that's a concern, consider using + * {@link Icon#loadDrawableAsync(Context, Handler, Icon.OnDrawableLoadedListener)} + * and then {@link #setImageDrawable(android.graphics.drawable.Drawable)} instead.

+ * + * @param icon an Icon holding the desired image + */ + @android.view.RemotableViewMethod + public void setImageIcon(Icon icon) { + setImageDrawable(icon.loadDrawable(mContext)); + } + + /** * Applies a tint to the image drawable. Does not modify the current tint * mode, which is {@link PorterDuff.Mode#SRC_IN} by default. *

-- cgit v1.1