ImageButton: implement setDrawable()

This commit is contained in:
Julian Winkler 2024-03-24 16:55:04 +01:00
parent 93b88ad0c3
commit 35f26faa90
4 changed files with 20 additions and 0 deletions

View file

@ -215,6 +215,14 @@ JNIEXPORT jlong JNICALL Java_android_widget_ImageButton_native_1constructor
JNIEXPORT void JNICALL Java_android_widget_ImageButton_native_1setPixbuf JNIEXPORT void JNICALL Java_android_widget_ImageButton_native_1setPixbuf
(JNIEnv *, jobject, jlong); (JNIEnv *, jobject, jlong);
/*
* Class: android_widget_ImageButton
* Method: native_setDrawable
* Signature: (JJ)V
*/
JNIEXPORT void JNICALL Java_android_widget_ImageButton_native_1setDrawable
(JNIEnv *, jobject, jlong, jlong);
/* /*
* Class: android_widget_ImageButton * Class: android_widget_ImageButton
* Method: native_setOnClickListener * Method: native_setOnClickListener

View file

@ -62,3 +62,11 @@ JNIEXPORT void JNICALL Java_android_widget_ImageButton_native_1setOnClickListene
g_signal_connect(button, "clicked", G_CALLBACK(clicked_cb), callback_data); g_signal_connect(button, "clicked", G_CALLBACK(clicked_cb), callback_data);
} }
JNIEXPORT void JNICALL Java_android_widget_ImageButton_native_1setDrawable(JNIEnv *env, jobject this, jlong widget_ptr, jlong paintable_ptr)
{
GtkButton *button = _PTR(_GET_LONG_FIELD(this, "widget"));
GtkPicture *picture = GTK_PICTURE(gtk_button_get_child(GTK_BUTTON(button)));
GdkPaintable *paintable = _PTR(paintable_ptr);
gtk_picture_set_paintable(picture, paintable);
}

View file

@ -21,6 +21,8 @@ public class ImageButton extends ImageView {
protected native long native_constructor(Context context, AttributeSet attrs); protected native long native_constructor(Context context, AttributeSet attrs);
@Override @Override
protected native void native_setPixbuf(long pixbuf); protected native void native_setPixbuf(long pixbuf);
@Override
protected native void native_setDrawable(long widget, long paintable);
protected native void native_setOnClickListener(long widget, OnClickListener l); protected native void native_setOnClickListener(long widget, OnClickListener l);
@Override @Override

View file

@ -33,6 +33,8 @@ public class ImageView extends View {
if (resid != 0 && !getResources().getString(resid).endsWith(".xml")) { if (resid != 0 && !getResources().getString(resid).endsWith(".xml")) {
bitmap = BitmapFactory.decodeResource(getResources(), resid); bitmap = BitmapFactory.decodeResource(getResources(), resid);
native_setPixbuf(bitmap.pixbuf); native_setPixbuf(bitmap.pixbuf);
} else if (resid != 0) {
setImageDrawable(getResources().getDrawable(resid));
} }
} }
} }