ImageView: use GtkPicture and actually show the image

GtkImage is intended for icons GtkPicture fits better
This commit is contained in:
Julian Winkler
2023-06-18 10:57:19 +02:00
parent 8ca8124ff1
commit c21d8532bc
3 changed files with 27 additions and 4 deletions

View File

@@ -165,6 +165,14 @@ JNIEXPORT void JNICALL Java_android_widget_ImageView_native_1constructor__Landro
JNIEXPORT void JNICALL Java_android_widget_ImageView_native_1constructor__Landroid_content_Context_2
(JNIEnv *, jobject, jobject);
/*
* Class: android_widget_ImageView
* Method: native_setPixbuf
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_android_widget_ImageView_native_1setPixbuf
(JNIEnv *, jobject, jlong);
#ifdef __cplusplus
}
#endif

View File

@@ -10,15 +10,21 @@
JNIEXPORT void JNICALL Java_android_widget_ImageView_native_1constructor__Landroid_util_AttributeSet_2(JNIEnv *env, jobject this, jobject attrs)
{
GtkWidget *wrapper = wrapper_widget_new();
GtkWidget *image = gtk_image_new_from_icon_name("FIXME"); // will not actually use gtk_image_new_from_icon_name when implementing this, but we want that nice "broken image" icon
GtkWidget *image = gtk_picture_new_for_resource("/org/gtk/libgtk/icons/16x16/status/image-missing.png"); // show "broken image" icon
wrapper_widget_set_child(WRAPPER_WIDGET(wrapper), image);
_SET_LONG_FIELD(this, "widget", _INTPTR(image));}
JNIEXPORT void JNICALL Java_android_widget_ImageView_native_1constructor__Landroid_content_Context_2(JNIEnv *env, jobject this, jobject context)
{
GtkWidget *wrapper = wrapper_widget_new();
GtkWidget *image = gtk_image_new_from_icon_name("FIXME"); // will not actually use gtk_image_new_from_icon_name when implementing this, but we want that nice "broken image" icon
GtkWidget *image = gtk_picture_new_for_resource("/org/gtk/libgtk/icons/16x16/status/image-missing.png"); // show "broken image" icon
wrapper_widget_set_child(WRAPPER_WIDGET(wrapper), image);
_SET_LONG_FIELD(this, "widget", _INTPTR(image));
}
JNIEXPORT void JNICALL Java_android_widget_ImageView_native_1setPixbuf(JNIEnv *env, jobject this, jlong pixbuf_ptr)
{
GtkWidget *image = _PTR(_GET_LONG_FIELD(this, "widget"));
GdkPixbuf *pixbuf = _PTR(pixbuf_ptr);
gtk_picture_set_pixbuf(GTK_PICTURE(image), pixbuf);
}

View File

@@ -2,7 +2,8 @@ package android.widget;
import android.util.AttributeSet;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;
public class ImageView extends View {
@@ -10,6 +11,8 @@ public class ImageView extends View {
super(attrs);
native_constructor(attrs);
int resource = attrs.getAttributeResourceValue("http://schemas.android.com/apk/res/android", "src", 0);
setImageResource(resource);
}
public ImageView(Context context) {
@@ -26,8 +29,14 @@ public class ImageView extends View {
private native void native_constructor(AttributeSet attrs);
private native void native_constructor(Context context);
private native void native_setPixbuf(long pixbuf);
public /*native*/ void setImageResource(final int resid) {}
public /*native*/ void setImageResource(final int resid) {
if (Context.this_application.getResources().getString(resid).endsWith(".xml"))
return;
Bitmap bitmap = BitmapFactory.decodeResource(Context.this_application.getResources(), resid);
native_setPixbuf(bitmap.pixbuf);
}
public void setAdjustViewBounds(boolean adjustViewBounds) {}
public void setScaleType(ScaleType scaleType) {}