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
LinearLayout: set GtkBox to homogeneous if all child weights are equal
Real weighted allocation is not supported by GtkBox
This commit is contained in:
@@ -223,6 +223,14 @@ JNIEXPORT void JNICALL Java_android_widget_LinearLayout_setOrientation
|
|||||||
JNIEXPORT jint JNICALL Java_android_widget_LinearLayout_getOrientation
|
JNIEXPORT jint JNICALL Java_android_widget_LinearLayout_getOrientation
|
||||||
(JNIEnv *, jobject);
|
(JNIEnv *, jobject);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: android_widget_LinearLayout
|
||||||
|
* Method: native_setHomogenousWeight
|
||||||
|
* Signature: (JZ)V
|
||||||
|
*/
|
||||||
|
JNIEXPORT void JNICALL Java_android_widget_LinearLayout_native_1setHomogenousWeight
|
||||||
|
(JNIEnv *, jobject, jlong, jboolean);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ JNIEXPORT jlong JNICALL Java_android_widget_LinearLayout_native_1constructor(JNI
|
|||||||
|
|
||||||
GtkWidget *wrapper = g_object_ref(wrapper_widget_new());
|
GtkWidget *wrapper = g_object_ref(wrapper_widget_new());
|
||||||
GtkWidget *box = gtk_box_new(orientation ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL, 0); // spacing of 0
|
GtkWidget *box = gtk_box_new(orientation ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL, 0); // spacing of 0
|
||||||
|
gtk_box_set_homogeneous(GTK_BOX(box), TRUE);
|
||||||
wrapper_widget_set_child(WRAPPER_WIDGET(wrapper), box);
|
wrapper_widget_set_child(WRAPPER_WIDGET(wrapper), box);
|
||||||
gtk_widget_set_name(GTK_WIDGET(box), "LinearLayout");
|
gtk_widget_set_name(GTK_WIDGET(box), "LinearLayout");
|
||||||
if (!attrs) {
|
if (!attrs) {
|
||||||
@@ -50,3 +51,8 @@ JNIEXPORT jint JNICALL Java_android_widget_LinearLayout_getOrientation(JNIEnv *e
|
|||||||
{
|
{
|
||||||
return gtk_orientable_get_orientation(GTK_ORIENTABLE(_PTR(_GET_LONG_FIELD(this, "widget"))));
|
return gtk_orientable_get_orientation(GTK_ORIENTABLE(_PTR(_GET_LONG_FIELD(this, "widget"))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL Java_android_widget_LinearLayout_native_1setHomogenousWeight(JNIEnv *env, jobject this, jlong widget_ptr, jboolean homogeneous)
|
||||||
|
{
|
||||||
|
gtk_box_set_homogeneous(_PTR(widget_ptr), homogeneous);
|
||||||
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public class ViewGroup extends View implements ViewParent, ViewManager {
|
|||||||
addView(child, params);
|
addView(child, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addViewInternal(View child, int index, LayoutParams params) {
|
protected void addViewInternal(View child, int index, LayoutParams params) {
|
||||||
if (child.parent == this)
|
if (child.parent == this)
|
||||||
return;
|
return;
|
||||||
if (!checkLayoutParams(params)) {
|
if (!checkLayoutParams(params)) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package android.widget;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
public class LinearLayout extends ViewGroup {
|
public class LinearLayout extends ViewGroup {
|
||||||
@@ -19,8 +20,23 @@ public class LinearLayout extends ViewGroup {
|
|||||||
|
|
||||||
public native void setOrientation(int orientation);
|
public native void setOrientation(int orientation);
|
||||||
public native int getOrientation();
|
public native int getOrientation();
|
||||||
|
protected native void native_setHomogenousWeight(long widget, boolean homogenous);
|
||||||
public void setWeightSum(float weightSum) {}
|
public void setWeightSum(float weightSum) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void addViewInternal(View child, int index, ViewGroup.LayoutParams params) {
|
||||||
|
super.addViewInternal(child, index, params);
|
||||||
|
// check if all children have the same weight and set GtkBox to homogeneous if so
|
||||||
|
float weight = params.weight;
|
||||||
|
for (int i = 0; i < children.size(); i++) {
|
||||||
|
if (children.get(i).getLayoutParams().weight != weight) {
|
||||||
|
weight = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
native_setHomogenousWeight(widget, weight > 0);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LayoutParams generateLayoutParams(AttributeSet attrs) {
|
public LayoutParams generateLayoutParams(AttributeSet attrs) {
|
||||||
return new LayoutParams(getContext(), attrs);
|
return new LayoutParams(getContext(), attrs);
|
||||||
|
|||||||
Reference in New Issue
Block a user