You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
ImageView: use GtkPicture and actually show the image
GtkImage is intended for icons GtkPicture fits better
This commit is contained in:
@@ -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
|
JNIEXPORT void JNICALL Java_android_widget_ImageView_native_1constructor__Landroid_content_Context_2
|
||||||
(JNIEnv *, jobject, jobject);
|
(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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -10,15 +10,21 @@
|
|||||||
JNIEXPORT void JNICALL Java_android_widget_ImageView_native_1constructor__Landroid_util_AttributeSet_2(JNIEnv *env, jobject this, jobject attrs)
|
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 *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);
|
wrapper_widget_set_child(WRAPPER_WIDGET(wrapper), image);
|
||||||
_SET_LONG_FIELD(this, "widget", _INTPTR(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)
|
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 *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);
|
wrapper_widget_set_child(WRAPPER_WIDGET(wrapper), image);
|
||||||
_SET_LONG_FIELD(this, "widget", _INTPTR(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);
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ package android.widget;
|
|||||||
|
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
public class ImageView extends View {
|
public class ImageView extends View {
|
||||||
@@ -10,6 +11,8 @@ public class ImageView extends View {
|
|||||||
super(attrs);
|
super(attrs);
|
||||||
|
|
||||||
native_constructor(attrs);
|
native_constructor(attrs);
|
||||||
|
int resource = attrs.getAttributeResourceValue("http://schemas.android.com/apk/res/android", "src", 0);
|
||||||
|
setImageResource(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImageView(Context context) {
|
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(AttributeSet attrs);
|
||||||
private native void native_constructor(Context context);
|
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 setAdjustViewBounds(boolean adjustViewBounds) {}
|
||||||
|
|
||||||
public void setScaleType(ScaleType scaleType) {}
|
public void setScaleType(ScaleType scaleType) {}
|
||||||
|
|||||||
Reference in New Issue
Block a user