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
use AndroidLayout class also in View implementation
drop the onMeasure hack from WrapperWidget
This commit is contained in:
committed by
Julian Winkler
parent
3c03223085
commit
0a8b8a3874
@@ -266,6 +266,14 @@ JNIEXPORT jlong JNICALL Java_android_view_View_native_1constructor(JNIEnv *env,
|
||||
wrapper_widget_set_child(WRAPPER_WIDGET(wrapper), widget);
|
||||
wrapper_widget_set_jobject(WRAPPER_WIDGET(wrapper), env, this);
|
||||
|
||||
jclass class = _CLASS(this);
|
||||
jmethodID measure_method = _METHOD(class, "onMeasure", "(II)V");
|
||||
jmethodID layout_method = _METHOD(class, "onLayout", "(ZIIII)V");
|
||||
if (measure_method != handle_cache.view.onMeasure || layout_method != handle_cache.view.onLayout) {
|
||||
gtk_widget_set_layout_manager(widget, android_layout_new(_REF(this)));
|
||||
(*env)->SetBooleanField(env, this, _FIELD_ID(class, "haveCustomMeasure", "Z"), true);
|
||||
}
|
||||
|
||||
return _INTPTR(widget);
|
||||
}
|
||||
|
||||
|
||||
@@ -77,25 +77,6 @@ void wrapper_widget_set_child(WrapperWidget *parent, GtkWidget *child) // TODO:
|
||||
parent->child = child;
|
||||
}
|
||||
|
||||
#define MEASURE_SPEC_EXACTLY (1 << 30)
|
||||
|
||||
static void on_mapped(GtkWidget* self, gpointer data)
|
||||
{
|
||||
WrapperWidget *wrapper = WRAPPER_WIDGET(self);
|
||||
if (wrapper->jvm) {
|
||||
JNIEnv *env;
|
||||
(*wrapper->jvm)->GetEnv(wrapper->jvm, (void**)&env, JNI_VERSION_1_6);
|
||||
|
||||
(*env)->CallVoidMethod(env, wrapper->jobj, wrapper->measure_method, MEASURE_SPEC_EXACTLY | gtk_widget_get_width(self), MEASURE_SPEC_EXACTLY | gtk_widget_get_height(self));
|
||||
int width = (*env)->CallIntMethod(env, wrapper->jobj, handle_cache.view.getMeasuredWidth);
|
||||
if (width > 0)
|
||||
g_object_set(G_OBJECT(self), "width-request", width, NULL);
|
||||
int height = (*env)->CallIntMethod(env, wrapper->jobj, handle_cache.view.getMeasuredHeight);
|
||||
if (height > 0)
|
||||
g_object_set(G_OBJECT(self), "height-request", height, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static guint sk_area_queue_queue_redraw(GtkWidget *sk_area)
|
||||
{
|
||||
gtk_widget_queue_draw(sk_area);
|
||||
@@ -133,13 +114,6 @@ void wrapper_widget_set_jobject(WrapperWidget *wrapper, JNIEnv *env, jobject job
|
||||
// gtk_widget_add_tick_callback(sk_area, tick_callback, NULL, NULL);
|
||||
}
|
||||
|
||||
jmethodID measure_method = _METHOD(_CLASS(jobj), "onMeasure", "(II)V");
|
||||
if (measure_method != handle_cache.view.onMeasure) {
|
||||
wrapper->measure_method = measure_method;
|
||||
// add a callback for when the widget is mapped, which will call onMeasure to figure out what size the widget wants to be
|
||||
g_signal_connect(wrapper, "map", G_CALLBACK(on_mapped), NULL);
|
||||
}
|
||||
|
||||
jmethodID ontouchevent_method = _METHOD(_CLASS(jobj), "onTouchEvent", "(Landroid/view/MotionEvent;)Z");
|
||||
if (ontouchevent_method != handle_cache.view.onTouchEvent) {
|
||||
/* use wrapper->child since the jobject may not have the "widget" variable set yet */
|
||||
|
||||
@@ -88,6 +88,7 @@ public class Context extends Object {
|
||||
InputStream inStream = ClassLoader.getSystemClassLoader().getResourceAsStream("AndroidManifest.xml");
|
||||
try {
|
||||
manifest = AndroidManifestBlock.load(inStream);
|
||||
application_info.targetSdkVersion = manifest.getTargetSdkVersion();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -809,9 +809,10 @@ public class View extends Object {
|
||||
|
||||
private int oldWidthMeasureSpec;
|
||||
private int oldHeightMeasureSpec;
|
||||
private boolean layoutRequested;
|
||||
private boolean layoutRequested = true;
|
||||
private int oldWidth;
|
||||
private int oldHeight;
|
||||
private boolean haveCustomMeasure;
|
||||
|
||||
public View() {
|
||||
this(Context.this_application);
|
||||
@@ -951,7 +952,10 @@ public class View extends Object {
|
||||
};
|
||||
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
native_measure(widget, widthMeasureSpec, heightMeasureSpec, false);
|
||||
if (haveCustomMeasure) // calling native_measure here would create infinite loop
|
||||
setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec), getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec));
|
||||
else
|
||||
native_measure(widget, widthMeasureSpec, heightMeasureSpec, false);
|
||||
}
|
||||
|
||||
public void setPressed(boolean pressed) {
|
||||
@@ -1121,10 +1125,10 @@ public class View extends Object {
|
||||
}
|
||||
|
||||
protected int getSuggestedMinimumHeight() {
|
||||
return 50;
|
||||
return 10;
|
||||
}
|
||||
protected int getSuggestedMinimumWidth() {
|
||||
return 100;
|
||||
return 10;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user