summaryrefslogtreecommitdiff
path: root/src/com/android/bitmap/view/BasicImageView.java
blob: eaaf9535929676d802539f98a90dd427da462035 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.android.bitmap.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.util.AttributeSet;
import android.widget.ImageView;

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.
 */
public class BasicImageView extends ImageView {
    private BasicBitmapDrawable mDrawable;

    public BasicImageView(final Context context) {
        this(context, null);
    }

    public BasicImageView(final Context context, final AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public BasicImageView(final Context context, final AttributeSet attrs, final int defStyle) {
        super(context, attrs, defStyle);
    }

    /**
     * Set the given BasicBitmapDrawable as the source for this BasicImageView.
     * @param drawable The source drawable.
     */
    public void setDrawable(BasicBitmapDrawable drawable) {
        super.setImageDrawable(drawable);
        mDrawable = drawable;
    }

    public BasicBitmapDrawable getDrawable() {
        return mDrawable;
    }

    @Override
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();

        mDrawable.unbind();
    }

    @Override
    public void setImageDrawable(final Drawable drawable) {
        throw new UnsupportedOperationException(
                "BasicImageView is only compatible with BasicBitmapDrawable. Use setDrawable() "
                        + "instead.");
    }

    @Override
    public void setImageResource(final int resId) {
        throw new UnsupportedOperationException(
                "BasicImageView is only compatible with BasicBitmapDrawable. Use setDrawable() "
                        + "instead.");
    }

    @Override
    public void setImageURI(final Uri uri) {
        throw new UnsupportedOperationException(
                "BasicImageView is only compatible with BasicBitmapDrawable. Use setDrawable() "
                        + "instead.");
    }

    @Override
    public void setImageBitmap(final Bitmap bm) {
        throw new UnsupportedOperationException(
                "BasicImageView is only compatible with BasicBitmapDrawable. Use setDrawable() "
                        + "instead.");
    }
}