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: handle setScaleType where it maps trivially to Gtk
This commit is contained in:
@@ -223,6 +223,14 @@ JNIEXPORT void JNICALL Java_android_widget_ImageView_native_1setPixbuf
|
|||||||
JNIEXPORT void JNICALL Java_android_widget_ImageView_native_1setDrawable
|
JNIEXPORT void JNICALL Java_android_widget_ImageView_native_1setDrawable
|
||||||
(JNIEnv *, jobject, jlong, jlong);
|
(JNIEnv *, jobject, jlong, jlong);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: android_widget_ImageView
|
||||||
|
* Method: native_setScaleType
|
||||||
|
* Signature: (JI)V
|
||||||
|
*/
|
||||||
|
JNIEXPORT void JNICALL Java_android_widget_ImageView_native_1setScaleType
|
||||||
|
(JNIEnv *, jobject, jlong, jint);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -7,6 +7,15 @@
|
|||||||
|
|
||||||
#include "../generated_headers/android_widget_ImageView.h"
|
#include "../generated_headers/android_widget_ImageView.h"
|
||||||
|
|
||||||
|
#define SCALE_TYPE_MATRIX 0
|
||||||
|
#define SCALE_TYPE_FIT_XY 1
|
||||||
|
#define SCALE_TYPE_FIT_START 2
|
||||||
|
#define SCALE_TYPE_FIT_CENTER 3
|
||||||
|
#define SCALE_TYPE_FIT_END 4
|
||||||
|
#define SCALE_TYPE_CENTER 5
|
||||||
|
#define SCALE_TYPE_CENTER_CROP 6
|
||||||
|
#define SCALE_TYPE_CENTER_INSIDE 7
|
||||||
|
|
||||||
JNIEXPORT jlong JNICALL Java_android_widget_ImageView_native_1constructor(JNIEnv *env, jobject this, jobject context, jobject attrs)
|
JNIEXPORT jlong JNICALL Java_android_widget_ImageView_native_1constructor(JNIEnv *env, jobject this, jobject context, jobject attrs)
|
||||||
{
|
{
|
||||||
GtkWidget *wrapper = g_object_ref(wrapper_widget_new());
|
GtkWidget *wrapper = g_object_ref(wrapper_widget_new());
|
||||||
@@ -29,3 +38,24 @@ JNIEXPORT void JNICALL Java_android_widget_ImageView_native_1setDrawable(JNIEnv
|
|||||||
GdkPaintable *paintable = _PTR(paintable_ptr);
|
GdkPaintable *paintable = _PTR(paintable_ptr);
|
||||||
gtk_picture_set_paintable(picture, paintable);
|
gtk_picture_set_paintable(picture, paintable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL Java_android_widget_ImageView_native_1setScaleType(JNIEnv *env, jobject this, jlong widget_ptr, jint scale_type)
|
||||||
|
{
|
||||||
|
GtkPicture *picture = _PTR(widget_ptr);
|
||||||
|
/* TODO: somehow handle all the types */
|
||||||
|
switch (scale_type) {
|
||||||
|
case SCALE_TYPE_FIT_XY:
|
||||||
|
gtk_picture_set_content_fit(picture, GTK_CONTENT_FIT_FILL);
|
||||||
|
break;
|
||||||
|
case SCALE_TYPE_CENTER:
|
||||||
|
/* should probably let it overflow instead */
|
||||||
|
gtk_picture_set_content_fit(picture, GTK_CONTENT_FIT_SCALE_DOWN);
|
||||||
|
break;
|
||||||
|
case SCALE_TYPE_CENTER_CROP:
|
||||||
|
gtk_picture_set_content_fit(picture, GTK_CONTENT_FIT_COVER);
|
||||||
|
break;
|
||||||
|
case SCALE_TYPE_CENTER_INSIDE:
|
||||||
|
gtk_picture_set_content_fit(picture, GTK_CONTENT_FIT_CONTAIN);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -31,15 +31,11 @@ public class ImageView extends View {
|
|||||||
haveCustomMeasure = false;
|
haveCustomMeasure = false;
|
||||||
TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.ImageView, defStyleAttr, 0);
|
TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.ImageView, defStyleAttr, 0);
|
||||||
setImageDrawable(a.getDrawable(com.android.internal.R.styleable.ImageView_src));
|
setImageDrawable(a.getDrawable(com.android.internal.R.styleable.ImageView_src));
|
||||||
|
setScaleType(scaletype_from_int[a.getInt(com.android.internal.R.styleable.ImageView_scaleType, 3 /*CENTER*/)]);
|
||||||
a.recycle();
|
a.recycle();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void setImageResource(final int resid) {
|
||||||
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));
|
setImageDrawable(getResources().getDrawable(resid));
|
||||||
return;
|
return;
|
||||||
@@ -51,6 +47,7 @@ public class ImageView extends View {
|
|||||||
|
|
||||||
public void setScaleType(ScaleType scaleType) {
|
public void setScaleType(ScaleType scaleType) {
|
||||||
this.scaleType = scaleType;
|
this.scaleType = scaleType;
|
||||||
|
native_setScaleType(widget, scaleType.nativeInt);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScaleType getScaleType() {
|
public ScaleType getScaleType() {
|
||||||
@@ -138,6 +135,16 @@ public class ImageView extends View {
|
|||||||
}
|
}
|
||||||
final int nativeInt;
|
final int nativeInt;
|
||||||
}
|
}
|
||||||
|
private final ScaleType[] scaletype_from_int = {
|
||||||
|
ScaleType.MATRIX,
|
||||||
|
ScaleType.FIT_XY,
|
||||||
|
ScaleType.FIT_START,
|
||||||
|
ScaleType.FIT_CENTER,
|
||||||
|
ScaleType.FIT_END,
|
||||||
|
ScaleType.CENTER,
|
||||||
|
ScaleType.CENTER_CROP,
|
||||||
|
ScaleType.CENTER_INSIDE,
|
||||||
|
};
|
||||||
|
|
||||||
public final void setColorFilter(int color, PorterDuff.Mode mode) {}
|
public final void setColorFilter(int color, PorterDuff.Mode mode) {}
|
||||||
|
|
||||||
@@ -150,4 +157,10 @@ public class ImageView extends View {
|
|||||||
public void setMaxHeight(int height) {}
|
public void setMaxHeight(int height) {}
|
||||||
|
|
||||||
public void setImageState(int[] state, boolean merge) {}
|
public void setImageState(int[] state, boolean merge) {}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
protected native void native_setScaleType(long widget, int scale_type);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user