blob: 5ca7dcd5c37cac2d89054612d6ce443cb2f5f671 (
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
|
package com.example.bitmapsample;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import com.android.bitmap.BitmapCache;
import com.android.bitmap.drawable.BasicBitmapDrawable;
public class BitmapView extends View {
private BasicBitmapDrawable mBitmapDrawable;
private float mDensity;
public BitmapView(Context c) {
this(c, null);
}
public BitmapView(Context c, AttributeSet attrs) {
super(c, attrs);
mDensity = getResources().getDisplayMetrics().density;
}
@Override
protected int getSuggestedMinimumHeight() {
return (int) (100 * mDensity);
}
@Override
protected void onSizeChanged(final int w, final int h, int oldw, int oldh) {
mBitmapDrawable.setDecodeDimensions(w, h);
}
public void setImage(String uriString) {
if (mBitmapDrawable != null) {
mBitmapDrawable.bind(new BitmapRequestKeyImpl(uriString));
}
}
public void initialize(BitmapCache cache) {
mBitmapDrawable = new BasicBitmapDrawable(getResources(), cache);
setBackground(mBitmapDrawable);
}
}
|