2023-07-25 14:29:43 +02:00
|
|
|
package android.graphics.drawable;
|
|
|
|
|
|
2023-12-30 17:31:56 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
|
|
import org.xmlpull.v1.XmlPullParser;
|
|
|
|
|
import org.xmlpull.v1.XmlPullParserException;
|
|
|
|
|
|
|
|
|
|
import com.android.internal.R;
|
|
|
|
|
|
2023-07-25 14:29:43 +02:00
|
|
|
import android.content.res.Resources;
|
2023-12-30 17:31:56 +01:00
|
|
|
import android.content.res.Resources.Theme;
|
|
|
|
|
import android.content.res.TypedArray;
|
2023-07-25 14:29:43 +02:00
|
|
|
import android.graphics.Bitmap;
|
2023-08-06 14:27:30 +02:00
|
|
|
import android.graphics.Canvas;
|
|
|
|
|
import android.graphics.Rect;
|
|
|
|
|
import android.graphics.RectF;
|
2023-12-30 17:31:56 +01:00
|
|
|
import android.util.AttributeSet;
|
2023-07-25 14:29:43 +02:00
|
|
|
|
|
|
|
|
public class BitmapDrawable extends Drawable {
|
2023-08-06 14:27:30 +02:00
|
|
|
|
|
|
|
|
private Bitmap bitmap;
|
|
|
|
|
|
2023-12-30 17:31:56 +01:00
|
|
|
public BitmapDrawable() {
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-06 14:27:30 +02:00
|
|
|
public BitmapDrawable(Resources res, Bitmap bitmap) {
|
|
|
|
|
this.bitmap = bitmap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void draw(Canvas canvas) {
|
|
|
|
|
canvas.drawBitmap(bitmap, new Rect(0, 0, bitmap.getWidth(), bitmap.getWidth()), new RectF(getBounds()), null);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-01 12:55:04 +02:00
|
|
|
public Bitmap getBitmap() {
|
|
|
|
|
return bitmap;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-30 17:31:56 +01:00
|
|
|
public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Theme theme)
|
|
|
|
|
throws XmlPullParserException, IOException {
|
|
|
|
|
final TypedArray a = r.obtainAttributes(attrs, R.styleable.BitmapDrawable);
|
|
|
|
|
if (a.hasValue(R.styleable.BitmapDrawable_src)) {
|
|
|
|
|
paintable = a.getDrawable(R.styleable.BitmapDrawable_src).paintable;
|
|
|
|
|
}
|
|
|
|
|
a.recycle();
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-25 14:29:43 +02:00
|
|
|
}
|