* commit 'd1b16386e7a2c793bb0fc3d19708f1c2853e92da': Improve ImageView drawable re-use
This commit is contained in:
@@ -91,6 +91,7 @@ public class ImageView extends View {
|
|||||||
private boolean mColorMod = false;
|
private boolean mColorMod = false;
|
||||||
|
|
||||||
private Drawable mDrawable = null;
|
private Drawable mDrawable = null;
|
||||||
|
private ImageViewBitmapDrawable mRecycleableBitmapDrawable = null;
|
||||||
private ColorStateList mDrawableTintList = null;
|
private ColorStateList mDrawableTintList = null;
|
||||||
private PorterDuff.Mode mDrawableTintMode = null;
|
private PorterDuff.Mode mDrawableTintMode = null;
|
||||||
private boolean mHasDrawableTint = false;
|
private boolean mHasDrawableTint = false;
|
||||||
@@ -588,18 +589,16 @@ public class ImageView extends View {
|
|||||||
*/
|
*/
|
||||||
@android.view.RemotableViewMethod
|
@android.view.RemotableViewMethod
|
||||||
public void setImageBitmap(Bitmap bm) {
|
public void setImageBitmap(Bitmap bm) {
|
||||||
// if this is used frequently, may handle bitmaps explicitly
|
// Hacky fix to force setImageDrawable to do a full setImageDrawable
|
||||||
// to reduce the intermediate drawable object
|
// instead of doing an object reference comparison
|
||||||
if (mDrawable instanceof ImageViewBitmapDrawable) {
|
mDrawable = null;
|
||||||
ImageViewBitmapDrawable recycledDrawable = (ImageViewBitmapDrawable) mDrawable;
|
if (mRecycleableBitmapDrawable == null) {
|
||||||
// Hacky fix to force setImageDrawable to do a full setImageDrawable
|
mRecycleableBitmapDrawable = new ImageViewBitmapDrawable(
|
||||||
// instead of doing an object reference comparison
|
mContext.getResources(), bm);
|
||||||
mDrawable = null;
|
|
||||||
recycledDrawable.setBitmap(bm);
|
|
||||||
setImageDrawable(recycledDrawable);
|
|
||||||
} else {
|
} else {
|
||||||
setImageDrawable(new ImageViewBitmapDrawable(mContext.getResources(), bm));
|
mRecycleableBitmapDrawable.setBitmap(bm);
|
||||||
}
|
}
|
||||||
|
setImageDrawable(mRecycleableBitmapDrawable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setImageState(int[] state, boolean merge) {
|
public void setImageState(int[] state, boolean merge) {
|
||||||
@@ -868,6 +867,10 @@ public class ImageView extends View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateDrawable(Drawable d) {
|
private void updateDrawable(Drawable d) {
|
||||||
|
if (d != mRecycleableBitmapDrawable && mRecycleableBitmapDrawable != null) {
|
||||||
|
mRecycleableBitmapDrawable.setBitmap(null);
|
||||||
|
}
|
||||||
|
|
||||||
if (mDrawable != null) {
|
if (mDrawable != null) {
|
||||||
mDrawable.setCallback(null);
|
mDrawable.setCallback(null);
|
||||||
unscheduleDrawable(mDrawable);
|
unscheduleDrawable(mDrawable);
|
||||||
|
|||||||
Reference in New Issue
Block a user