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: allow non bitmap Drawables
Also pass size of child paintable in DrawableContainer
This commit is contained in:
@@ -215,6 +215,14 @@ JNIEXPORT jlong JNICALL Java_android_widget_ImageView_native_1constructor
|
||||
JNIEXPORT void JNICALL Java_android_widget_ImageView_native_1setPixbuf
|
||||
(JNIEnv *, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: android_widget_ImageView
|
||||
* Method: native_setDrawable
|
||||
* Signature: (JJ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_android_widget_ImageView_native_1setDrawable
|
||||
(JNIEnv *, jobject, jlong, jlong);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -15,6 +15,30 @@ static void container_paintable_snapshot(GdkPaintable *paintable, GdkSnapshot *s
|
||||
gdk_paintable_snapshot(container->child, snapshot, width, height);
|
||||
}
|
||||
|
||||
static double container_paintable_get_intrinsic_aspect_ratio(GdkPaintable *paintable) {
|
||||
ContainerPaintable *container = CONTAINER_PAINTABLE(paintable);
|
||||
if (container->child)
|
||||
return gdk_paintable_get_intrinsic_aspect_ratio(container->child);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int container_paintable_get_intrinsic_width(GdkPaintable *paintable) {
|
||||
ContainerPaintable *container = CONTAINER_PAINTABLE(paintable);
|
||||
if (container->child)
|
||||
return gdk_paintable_get_intrinsic_width(container->child);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int container_paintable_get_intrinsic_height(GdkPaintable *paintable) {
|
||||
ContainerPaintable *container = CONTAINER_PAINTABLE(paintable);
|
||||
if (container->child)
|
||||
return gdk_paintable_get_intrinsic_height(container->child);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void container_paintable_init(ContainerPaintable *container_paintable)
|
||||
{
|
||||
}
|
||||
@@ -22,6 +46,9 @@ static void container_paintable_init(ContainerPaintable *container_paintable)
|
||||
static void container_paintable_paintable_init(GdkPaintableInterface *iface)
|
||||
{
|
||||
iface->snapshot = container_paintable_snapshot;
|
||||
iface->get_intrinsic_aspect_ratio = container_paintable_get_intrinsic_aspect_ratio;
|
||||
iface->get_intrinsic_width = container_paintable_get_intrinsic_width;
|
||||
iface->get_intrinsic_height = container_paintable_get_intrinsic_height;
|
||||
}
|
||||
|
||||
static void container_paintable_class_init(ContainerPaintableClass *class) {
|
||||
@@ -40,4 +67,5 @@ JNIEXPORT void JNICALL Java_android_graphics_drawable_DrawableContainer_native_1
|
||||
ContainerPaintable *container = CONTAINER_PAINTABLE(_PTR(ptr));
|
||||
container->child = GDK_PAINTABLE(_PTR(child_ptr));
|
||||
gdk_paintable_invalidate_contents(GDK_PAINTABLE(container));
|
||||
gdk_paintable_invalidate_size(GDK_PAINTABLE(container));
|
||||
}
|
||||
|
||||
@@ -22,3 +22,10 @@ JNIEXPORT void JNICALL Java_android_widget_ImageView_native_1setPixbuf(JNIEnv *e
|
||||
GdkPixbuf *pixbuf = _PTR(pixbuf_ptr);
|
||||
gtk_picture_set_pixbuf(GTK_PICTURE(image), pixbuf);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_widget_ImageView_native_1setDrawable(JNIEnv *env, jobject this, jlong widget_ptr, jlong paintable_ptr)
|
||||
{
|
||||
GtkPicture *picture = _PTR(widget_ptr);
|
||||
GdkPaintable *paintable = _PTR(paintable_ptr);
|
||||
gtk_picture_set_paintable(picture, paintable);
|
||||
}
|
||||
|
||||
@@ -40,10 +40,13 @@ public class ImageView extends View {
|
||||
@Override
|
||||
protected native long native_constructor(Context context, AttributeSet attrs);
|
||||
protected native void native_setPixbuf(long pixbuf);
|
||||
protected native void native_setDrawable(long widget, long paintable);
|
||||
|
||||
public /*native*/ void setImageResource(final int resid) {
|
||||
if (Context.this_application.getResources().getString(resid).endsWith(".xml"))
|
||||
if (Context.this_application.getResources().getString(resid).endsWith(".xml")) {
|
||||
setImageDrawable(getResources().getDrawable(resid));
|
||||
return;
|
||||
}
|
||||
bitmap = BitmapFactory.decodeResource(Context.this_application.getResources(), resid);
|
||||
native_setPixbuf(bitmap.pixbuf);
|
||||
}
|
||||
@@ -64,6 +67,8 @@ public class ImageView extends View {
|
||||
public void setImageDrawable(Drawable drawable) {
|
||||
if (drawable instanceof BitmapDrawable) {
|
||||
setImageBitmap(((BitmapDrawable) drawable).getBitmap());
|
||||
} else if (drawable != null) {
|
||||
native_setDrawable(widget, drawable.paintable);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user