diff options
Diffstat (limited to 'src/com/android/bitmap/view')
-rw-r--r-- | src/com/android/bitmap/view/BitmapDrawableImageView.java (renamed from src/com/android/bitmap/view/BasicImageView.java) | 67 |
1 files changed, 38 insertions, 29 deletions
diff --git a/src/com/android/bitmap/view/BasicImageView.java b/src/com/android/bitmap/view/BitmapDrawableImageView.java index 3e48af5..a55b864 100644 --- a/src/com/android/bitmap/view/BasicImageView.java +++ b/src/com/android/bitmap/view/BitmapDrawableImageView.java @@ -27,68 +27,77 @@ import com.android.bitmap.drawable.BasicBitmapDrawable; /** * A helpful ImageView replacement that can generally be used in lieu of ImageView. - * BasicImageView has logic to unbind its BasicBitmapDrawable when it is detached from the window. + * BitmapDrawableImageView has logic to unbind its BasicBitmapDrawable when it is detached from the + * window. */ -public class BasicImageView extends ImageView { +public class BitmapDrawableImageView extends ImageView { private BasicBitmapDrawable mDrawable; - public BasicImageView(final Context context) { + public BitmapDrawableImageView(final Context context) { this(context, null); } - public BasicImageView(final Context context, final AttributeSet attrs) { + public BitmapDrawableImageView(final Context context, final AttributeSet attrs) { this(context, attrs, 0); } - public BasicImageView(final Context context, final AttributeSet attrs, final int defStyle) { + public BitmapDrawableImageView(final Context context, final AttributeSet attrs, + final int defStyle) { super(context, attrs, defStyle); } /** - * Set the given BasicBitmapDrawable as the source for this BasicImageView. + * Get the source BasicBitmapDrawable for this BitmapDrawableImageView. + * @return The source drawable. + */ + public BasicBitmapDrawable getBasicBitmapDrawable() { + return mDrawable; + } + + /** + * Set the given BasicBitmapDrawable as the source for this BitmapDrawableImageView. * @param drawable The source drawable. */ - public void setDrawable(BasicBitmapDrawable drawable) { + public void setBasicBitmapDrawable(BasicBitmapDrawable drawable) { super.setImageDrawable(drawable); + unbindDrawable(); mDrawable = drawable; } - public BasicBitmapDrawable getDrawable() { - return mDrawable; + private void unbindDrawable() { + if (mDrawable != null) { + mDrawable.unbind(); + mDrawable = null; + } } @Override - protected void onDetachedFromWindow() { - super.onDetachedFromWindow(); - - mDrawable.unbind(); + public void setImageResource(final int resId) { + super.setImageResource(resId); + unbindDrawable(); } @Override - public void setImageDrawable(final Drawable drawable) { - throw new UnsupportedOperationException( - "BasicImageView is only compatible with BasicBitmapDrawable. Use setDrawable() " - + "instead."); + public void setImageURI(final Uri uri) { + super.setImageURI(uri); + unbindDrawable(); } @Override - public void setImageResource(final int resId) { - throw new UnsupportedOperationException( - "BasicImageView is only compatible with BasicBitmapDrawable. Use setDrawable() " - + "instead."); + public void setImageDrawable(final Drawable drawable) { + super.setImageDrawable(drawable); + unbindDrawable(); } @Override - public void setImageURI(final Uri uri) { - throw new UnsupportedOperationException( - "BasicImageView is only compatible with BasicBitmapDrawable. Use setDrawable() " - + "instead."); + public void setImageBitmap(final Bitmap bm) { + super.setImageBitmap(bm); + unbindDrawable(); } @Override - public void setImageBitmap(final Bitmap bm) { - throw new UnsupportedOperationException( - "BasicImageView is only compatible with BasicBitmapDrawable. Use setDrawable() " - + "instead."); + protected void onDetachedFromWindow() { + super.onDetachedFromWindow(); + unbindDrawable(); } } |