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
unify View construction and measurement
No longer allow constructing Views without Context. Lets have only one onMeasure() method to unify behaviour
This commit is contained in:
@@ -42,17 +42,19 @@ JNIEXPORT jlong JNICALL Java_android_view_ViewGroup_native_1constructor(JNIEnv *
|
||||
wrapper_widget_set_child(WRAPPER_WIDGET(wrapper), box);
|
||||
wrapper_widget_set_jobject(WRAPPER_WIDGET(wrapper), env, this);
|
||||
|
||||
const char *name = _CSTRING((*env)->CallObjectMethod(env, _CLASS(this),
|
||||
jclass class = _CLASS(this);
|
||||
const char *name = _CSTRING((*env)->CallObjectMethod(env, class,
|
||||
_METHOD((*env)->FindClass(env, "java/lang/Class"), "getName", "()Ljava/lang/String;")));
|
||||
gtk_widget_set_name(box, name);
|
||||
|
||||
/* this should better match default android behavior */
|
||||
gtk_widget_set_overflow(wrapper, GTK_OVERFLOW_HIDDEN);
|
||||
|
||||
jmethodID measure_method = _METHOD(_CLASS(this), "onMeasure", "(II)V");
|
||||
jmethodID layout_method = _METHOD(_CLASS(this), "onLayout", "(ZIIII)V");
|
||||
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(box, android_layout_new(_REF(this)));
|
||||
(*env)->SetBooleanField(env, this, _FIELD_ID(class, "haveCustomMeasure", "Z"), true);
|
||||
}
|
||||
if (_METHOD(_CLASS(this), "onGenericMotionEvent", "(Landroid/view/MotionEvent;)Z") != handle_cache.view.onGenericMotionEvent) {
|
||||
GtkEventController *controller = gtk_event_controller_scroll_new(GTK_EVENT_CONTROLLER_SCROLL_VERTICAL);
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.view.ViewGroup;
|
||||
public class GestureOverlayView extends ViewGroup {
|
||||
|
||||
public GestureOverlayView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public void setGestureStrokeType(int type) {
|
||||
|
||||
@@ -814,14 +814,11 @@ public class View extends Object {
|
||||
private int oldWidth;
|
||||
private int oldHeight;
|
||||
private boolean haveCustomMeasure;
|
||||
protected boolean haveComplexMeasure = false;
|
||||
|
||||
private int visibility = View.VISIBLE;
|
||||
private float alpha = 1.0f;
|
||||
|
||||
public View() {
|
||||
this(Context.this_application);
|
||||
} // FIXME
|
||||
|
||||
public View(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
@@ -970,7 +967,7 @@ public class View extends Object {
|
||||
if (haveCustomMeasure) // calling native_measure here would create infinite loop
|
||||
setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec), getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec));
|
||||
else
|
||||
native_measure(widget, widthMeasureSpec, heightMeasureSpec, false);
|
||||
native_measure(widget, widthMeasureSpec, heightMeasureSpec, haveComplexMeasure);
|
||||
}
|
||||
|
||||
public void setPressed(boolean pressed) {
|
||||
|
||||
@@ -12,38 +12,23 @@ public class ViewGroup extends View implements ViewParent, ViewManager {
|
||||
public int id;
|
||||
public ArrayList<View> children;
|
||||
|
||||
public ViewGroup() {
|
||||
children = new ArrayList<View>();
|
||||
}
|
||||
|
||||
public ViewGroup(Context context) {
|
||||
super(context);
|
||||
|
||||
children = new ArrayList<View>();
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public ViewGroup(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
children = new ArrayList<View>();
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public ViewGroup(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs);
|
||||
|
||||
children = new ArrayList<View>();
|
||||
this(context, attrs, defStyleAttr, 0);
|
||||
}
|
||||
|
||||
public ViewGroup(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
|
||||
children = new ArrayList<View>();
|
||||
}
|
||||
|
||||
public ViewGroup(int _id) { // FIXME
|
||||
children = new ArrayList<View>();
|
||||
|
||||
id = _id;
|
||||
haveComplexMeasure = true;
|
||||
}
|
||||
|
||||
public void addView(View child) {
|
||||
@@ -128,11 +113,6 @@ public class ViewGroup extends View implements ViewParent, ViewManager {
|
||||
removeView(child);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
native_measure(widget, widthMeasureSpec, heightMeasureSpec, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected native long native_constructor(Context context, AttributeSet attrs);
|
||||
protected native void native_addView(long widget, long child, int index, LayoutParams params);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package android.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.SurfaceHolder;
|
||||
|
||||
public class Window {
|
||||
@@ -49,7 +50,7 @@ public class Window {
|
||||
public View getDecorView() {
|
||||
if (contentView != null)
|
||||
return contentView;
|
||||
return new View(); // FIXME: this can probably backfire
|
||||
return new View(Context.this_application); // FIXME: this can probably backfire
|
||||
}
|
||||
|
||||
private native void set_widget_as_root(long native_window, long widget);
|
||||
|
||||
@@ -17,26 +17,24 @@ public class ImageView extends View {
|
||||
private ScaleType scaleType = ScaleType.FIT_CENTER;
|
||||
|
||||
public ImageView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
if (attrs != null) {
|
||||
int resource = attrs.getAttributeResourceValue("http://schemas.android.com/apk/res/android", "src", 0);
|
||||
if (resource != 0)
|
||||
setImageResource(resource);
|
||||
}
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public ImageView(Context context) {
|
||||
super(context);
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public ImageView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
native_measure(widget, widthMeasureSpec, heightMeasureSpec, true);
|
||||
haveComplexMeasure = true;
|
||||
if (attrs != null) {
|
||||
int resid = attrs.getAttributeResourceValue("http://schemas.android.com/apk/res/android", "src", 0);
|
||||
if (resid != 0 && !getResources().getString(resid).endsWith(".xml")) {
|
||||
bitmap = BitmapFactory.decodeResource(getResources(), resid);
|
||||
native_setPixbuf(bitmap.pixbuf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,10 +22,6 @@ import android.view.View;
|
||||
public class TextView extends View {
|
||||
public String text;
|
||||
|
||||
public TextView(int _id) { // FIXME
|
||||
id = _id;
|
||||
}
|
||||
|
||||
public TextView(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
@@ -50,6 +46,7 @@ public class TextView extends View {
|
||||
}
|
||||
a.recycle();
|
||||
}
|
||||
haveComplexMeasure = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,11 +68,6 @@ public class TextView extends View {
|
||||
setText(getContext().getResources().getText(resId));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
native_measure(widget, widthMeasureSpec, heightMeasureSpec, true);
|
||||
}
|
||||
|
||||
private native final void native_set_markup(int bool);
|
||||
|
||||
public native final void native_setText(String text);
|
||||
|
||||
Reference in New Issue
Block a user