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
support layout margins
This makes the menu in Gravity Defied not get behind the keyboard. Also makes the TabLayout in NewPipe not get behing the titlebar.
This commit is contained in:
@@ -242,10 +242,10 @@ JNIEXPORT jlong JNICALL Java_android_view_View_native_1constructor
|
||||
/*
|
||||
* Class: android_view_View
|
||||
* Method: native_setLayoutParams
|
||||
* Signature: (JIIIF)V
|
||||
* Signature: (JIIIFIIII)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_android_view_View_native_1setLayoutParams
|
||||
(JNIEnv *, jobject, jlong, jint, jint, jint, jfloat);
|
||||
(JNIEnv *, jobject, jlong, jint, jint, jint, jfloat, jint, jint, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: android_view_View
|
||||
|
||||
@@ -174,7 +174,8 @@ JNIEXPORT jint JNICALL Java_android_view_View_getHeight(JNIEnv *env, jobject thi
|
||||
|
||||
#define MATCH_PARENT (-1)
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_view_View_native_1setLayoutParams(JNIEnv *env, jobject this, jlong widget_ptr, jint width, jint height, jint gravity, jfloat weight)
|
||||
JNIEXPORT void JNICALL Java_android_view_View_native_1setLayoutParams(JNIEnv *env, jobject this, jlong widget_ptr, jint width, jint height, jint gravity, jfloat weight,
|
||||
jint leftMargin, jint topMargin, jint rightMargin, jint bottomMargin)
|
||||
{
|
||||
GtkWidget *widget = gtk_widget_get_parent(GTK_WIDGET(_PTR(widget_ptr)));
|
||||
|
||||
@@ -234,6 +235,15 @@ JNIEXPORT void JNICALL Java_android_view_View_native_1setLayoutParams(JNIEnv *en
|
||||
if(height > 0)
|
||||
g_object_set(G_OBJECT(widget), "height-request", height, NULL);
|
||||
|
||||
GtkWidget *parent = gtk_widget_get_parent(widget);
|
||||
// if parent is Java widget, it will handle the margins by itself
|
||||
if (parent && !ATL_IS_ANDROID_LAYOUT(gtk_widget_get_layout_manager(parent))) {
|
||||
gtk_widget_set_margin_start(widget, leftMargin);
|
||||
gtk_widget_set_margin_top(widget, topMargin);
|
||||
gtk_widget_set_margin_end(widget, rightMargin);
|
||||
gtk_widget_set_margin_bottom(widget, bottomMargin);
|
||||
}
|
||||
|
||||
GtkLayoutManager *layout_manager = gtk_widget_get_layout_manager(WRAPPER_WIDGET(widget)->child);
|
||||
if (ATL_IS_ANDROID_LAYOUT(layout_manager))
|
||||
android_layout_set_params(ATL_ANDROID_LAYOUT(layout_manager), width, height);
|
||||
|
||||
@@ -877,7 +877,18 @@ public class View extends Object {
|
||||
if (gravity == -1 && parent != null)
|
||||
gravity = parent.gravity;
|
||||
|
||||
native_setLayoutParams(widget, params.width, params.height, gravity, params.weight);
|
||||
int leftMargin = 0;
|
||||
int topMargin = 0;
|
||||
int rightMargin = 0;
|
||||
int bottomMargin = 0;
|
||||
if (params instanceof ViewGroup.MarginLayoutParams) {
|
||||
leftMargin = ((ViewGroup.MarginLayoutParams) params).leftMargin;
|
||||
topMargin = ((ViewGroup.MarginLayoutParams) params).topMargin;
|
||||
rightMargin = ((ViewGroup.MarginLayoutParams) params).rightMargin;
|
||||
bottomMargin = ((ViewGroup.MarginLayoutParams) params).bottomMargin;
|
||||
}
|
||||
|
||||
native_setLayoutParams(widget, params.width, params.height, gravity, params.weight, leftMargin, topMargin, rightMargin, bottomMargin);
|
||||
|
||||
layout_params = params;
|
||||
}
|
||||
@@ -910,7 +921,7 @@ public class View extends Object {
|
||||
public native final int getHeight();
|
||||
|
||||
protected native long native_constructor(Context context, AttributeSet attrs); // will create a custom GtkWidget with a custom drawing function
|
||||
public native void native_setLayoutParams(long widget, int width, int height, int gravity, float weight);
|
||||
public native void native_setLayoutParams(long widget, int width, int height, int gravity, float weight, int leftMargin, int topMargin, int rightMargin, int bottomMargin);
|
||||
protected native void native_destructor(long widget);
|
||||
/**
|
||||
* We decide between simple widgets which handles MEASURE_SPEC_AT_MOST the same way as
|
||||
|
||||
@@ -348,8 +348,6 @@ public class ViewGroup extends View implements ViewParent, ViewManager {
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
public void setMargins(int left, int top, int right, int bottom) {}
|
||||
|
||||
/**
|
||||
* Used to animate layouts.
|
||||
*/
|
||||
@@ -382,6 +380,19 @@ public class ViewGroup extends View implements ViewParent, ViewManager {
|
||||
|
||||
public MarginLayoutParams(Context context, AttributeSet attributeSet) {
|
||||
super(context, attributeSet);
|
||||
TypedArray a = context.obtainStyledAttributes(attributeSet, R.styleable.ViewGroup_MarginLayout);
|
||||
leftMargin = a.getDimensionPixelSize(R.styleable.ViewGroup_MarginLayout_layout_marginLeft, 0);
|
||||
topMargin = a.getDimensionPixelSize(R.styleable.ViewGroup_MarginLayout_layout_marginTop, 0);
|
||||
rightMargin = a.getDimensionPixelSize(R.styleable.ViewGroup_MarginLayout_layout_marginRight, 0);
|
||||
bottomMargin = a.getDimensionPixelSize(R.styleable.ViewGroup_MarginLayout_layout_marginBottom, 0);
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
public void setMargins(int left, int top, int right, int bottom) {
|
||||
leftMargin = left;
|
||||
topMargin = top;
|
||||
rightMargin = right;
|
||||
bottomMargin = bottom;
|
||||
}
|
||||
|
||||
public int getMarginStart() {
|
||||
@@ -392,8 +403,12 @@ public class ViewGroup extends View implements ViewParent, ViewManager {
|
||||
return rightMargin;
|
||||
}
|
||||
|
||||
public void setMarginStart(int marginStart) {}
|
||||
public void setMarginEnd(int marginEnd) {}
|
||||
public void setMarginStart(int marginStart) {
|
||||
leftMargin = marginStart;
|
||||
}
|
||||
public void setMarginEnd(int marginEnd) {
|
||||
rightMargin = marginEnd;
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnHierarchyChangeListener {
|
||||
|
||||
Reference in New Issue
Block a user