2022-10-02 23:06:56 +02:00
|
|
|
package android.widget;
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
2023-06-18 10:57:19 +02:00
|
|
|
import android.graphics.Bitmap;
|
|
|
|
|
import android.graphics.BitmapFactory;
|
2023-08-22 14:41:01 +02:00
|
|
|
import android.graphics.Matrix;
|
2023-09-01 12:55:04 +02:00
|
|
|
import android.graphics.PorterDuff;
|
2023-08-06 14:27:30 +02:00
|
|
|
import android.graphics.drawable.BitmapDrawable;
|
|
|
|
|
import android.graphics.drawable.Drawable;
|
2023-06-22 11:45:46 +02:00
|
|
|
import android.util.AttributeSet;
|
2022-10-02 23:06:56 +02:00
|
|
|
import android.view.View;
|
|
|
|
|
|
|
|
|
|
public class ImageView extends View {
|
2023-08-06 14:27:30 +02:00
|
|
|
|
|
|
|
|
private Bitmap bitmap;
|
2023-09-01 12:55:04 +02:00
|
|
|
private ScaleType scaleType = ScaleType.FIT_CENTER;
|
2023-08-06 14:27:30 +02:00
|
|
|
|
2023-07-14 18:02:04 +02:00
|
|
|
public ImageView(Context context, AttributeSet attrs) {
|
|
|
|
|
super(context, attrs);
|
2022-10-02 23:06:56 +02:00
|
|
|
|
2023-08-17 10:46:24 +02:00
|
|
|
if (attrs != null) {
|
|
|
|
|
int resource = attrs.getAttributeResourceValue("http://schemas.android.com/apk/res/android", "src", 0);
|
|
|
|
|
if (resource != 0)
|
|
|
|
|
setImageResource(resource);
|
|
|
|
|
}
|
2022-10-02 23:06:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ImageView(Context context) {
|
|
|
|
|
super(context);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-17 12:59:37 +02:00
|
|
|
public ImageView(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
|
|
|
super(context, attrs, defStyleAttr);
|
2023-01-09 12:07:57 +01:00
|
|
|
}
|
|
|
|
|
|
2023-08-17 12:59:37 +02:00
|
|
|
@Override
|
|
|
|
|
protected native long native_constructor(Context context, AttributeSet attrs);
|
2023-08-22 13:53:52 +02:00
|
|
|
protected native void native_setPixbuf(long pixbuf);
|
2023-06-18 10:57:19 +02:00
|
|
|
|
|
|
|
|
public /*native*/ void setImageResource(final int resid) {
|
2023-06-22 11:45:46 +02:00
|
|
|
if (Context.this_application.getResources().getString(resid).endsWith(".xml"))
|
|
|
|
|
return;
|
2023-08-06 14:27:30 +02:00
|
|
|
bitmap = BitmapFactory.decodeResource(Context.this_application.getResources(), resid);
|
2023-06-22 11:45:46 +02:00
|
|
|
native_setPixbuf(bitmap.pixbuf);
|
|
|
|
|
}
|
2022-10-02 23:06:56 +02:00
|
|
|
public void setAdjustViewBounds(boolean adjustViewBounds) {}
|
|
|
|
|
|
2023-09-01 12:55:04 +02:00
|
|
|
public void setScaleType(ScaleType scaleType) {
|
|
|
|
|
this.scaleType = scaleType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ScaleType getScaleType() {
|
|
|
|
|
return scaleType;
|
|
|
|
|
}
|
2022-10-02 23:06:56 +02:00
|
|
|
|
2023-08-06 14:27:30 +02:00
|
|
|
public Drawable getDrawable() {
|
|
|
|
|
return new BitmapDrawable(getContext().getResources(), bitmap);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-17 10:46:24 +02:00
|
|
|
public void setImageDrawable(Drawable drawable) {}
|
|
|
|
|
|
2023-08-22 14:41:01 +02:00
|
|
|
public void setImageMatrix(Matrix matrix) {}
|
|
|
|
|
|
2023-09-01 12:55:04 +02:00
|
|
|
public void setImageBitmap(Bitmap bitmap) {
|
|
|
|
|
if (bitmap != null)
|
|
|
|
|
native_setPixbuf(bitmap.pixbuf);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 11:45:46 +02:00
|
|
|
/**
|
|
|
|
|
* Options for scaling the bounds of an image to the bounds of this view.
|
|
|
|
|
*/
|
|
|
|
|
public enum ScaleType {
|
|
|
|
|
/**
|
|
|
|
|
* Scale using the image matrix when drawing. The image matrix can be set using
|
|
|
|
|
* {@link ImageView#setImageMatrix(Matrix)}. From XML, use this syntax:
|
|
|
|
|
* <code>android:scaleType="matrix"</code>.
|
|
|
|
|
*/
|
|
|
|
|
MATRIX(0),
|
|
|
|
|
/**
|
|
|
|
|
* Scale the image using {@link Matrix.ScaleToFit#FILL}.
|
|
|
|
|
* From XML, use this syntax: <code>android:scaleType="fitXY"</code>.
|
|
|
|
|
*/
|
|
|
|
|
FIT_XY(1),
|
|
|
|
|
/**
|
|
|
|
|
* Scale the image using {@link Matrix.ScaleToFit#START}.
|
|
|
|
|
* From XML, use this syntax: <code>android:scaleType="fitStart"</code>.
|
|
|
|
|
*/
|
|
|
|
|
FIT_START(2),
|
|
|
|
|
/**
|
|
|
|
|
* Scale the image using {@link Matrix.ScaleToFit#CENTER}.
|
|
|
|
|
* From XML, use this syntax:
|
|
|
|
|
* <code>android:scaleType="fitCenter"</code>.
|
|
|
|
|
*/
|
|
|
|
|
FIT_CENTER(3),
|
|
|
|
|
/**
|
|
|
|
|
* Scale the image using {@link Matrix.ScaleToFit#END}.
|
|
|
|
|
* From XML, use this syntax: <code>android:scaleType="fitEnd"</code>.
|
|
|
|
|
*/
|
|
|
|
|
FIT_END(4),
|
|
|
|
|
/**
|
|
|
|
|
* Center the image in the view, but perform no scaling.
|
|
|
|
|
* From XML, use this syntax: <code>android:scaleType="center"</code>.
|
|
|
|
|
*/
|
|
|
|
|
CENTER(5),
|
|
|
|
|
/**
|
|
|
|
|
* Scale the image uniformly (maintain the image's aspect ratio) so
|
|
|
|
|
* that both dimensions (width and height) of the image will be equal
|
|
|
|
|
* to or larger than the corresponding dimension of the view
|
|
|
|
|
* (minus padding). The image is then centered in the view.
|
|
|
|
|
* From XML, use this syntax: <code>android:scaleType="centerCrop"</code>.
|
|
|
|
|
*/
|
|
|
|
|
CENTER_CROP(6),
|
|
|
|
|
/**
|
|
|
|
|
* Scale the image uniformly (maintain the image's aspect ratio) so
|
|
|
|
|
* that both dimensions (width and height) of the image will be equal
|
|
|
|
|
* to or less than the corresponding dimension of the view
|
|
|
|
|
* (minus padding). The image is then centered in the view.
|
|
|
|
|
* From XML, use this syntax: <code>android:scaleType="centerInside"</code>.
|
|
|
|
|
*/
|
|
|
|
|
CENTER_INSIDE(7);
|
|
|
|
|
|
|
|
|
|
ScaleType(int ni) {
|
|
|
|
|
nativeInt = ni;
|
|
|
|
|
}
|
|
|
|
|
final int nativeInt;
|
|
|
|
|
}
|
2023-09-01 12:55:04 +02:00
|
|
|
|
|
|
|
|
public final void setColorFilter(int color, PorterDuff.Mode mode) {}
|
2022-10-02 23:06:56 +02:00
|
|
|
}
|