replace LinearLayout with AOSPs implementation

Also update QuickHelp.md, as LinearLayout was the last custom
implemented ViewGroup
This commit is contained in:
Julian Winkler
2024-02-04 16:15:26 +01:00
parent 6eeb6b0232
commit 88254d822f
5 changed files with 1774 additions and 313 deletions

View File

@@ -93,13 +93,9 @@ to get to work in order to cut down on the amount of stubbing you need to do.
There are two basic types of widgets (Views): containers (Layouts) and the rest. There are two basic types of widgets (Views): containers (Layouts) and the rest.
To implement a container widget, simply copy an existing container widget implementation (e.g LinearLayout Initially all container widgets where backed by Gtk container widgets. As this caused lots of behaviour diffeneces with AOSP,
(`src/api-impl/android/widget/LinearLayout.java` and `src/api-impl-jni/widgets/android_widget_LinearLayout.c`)), and that's we have instead implemented the API of ViewGroup, which is the super class of all container widgets. This allows to more or
it! Now, chances are that you wanted something slightly different, but this will at least display the child less completely reuse specialized container widget implementation from AOSP source code.
widgets so that you can focus on implementing those.
When you get around to properly implementing the particularities of the specific container widget, it's
basically the same process as below.
To implement any other widget, copy a widget that is closest to what you're looking for, and if Gtk has To implement any other widget, copy a widget that is closest to what you're looking for, and if Gtk has
a better approximation for your widget, then change to that as the backing Gtk widget. If Gtk doesn't have a better approximation for your widget, then change to that as the backing Gtk widget. If Gtk doesn't have

View File

@@ -98,7 +98,6 @@ libtranslationlayer_so = shared_library('translation_layer_main', [
'src/api-impl-jni/widgets/android_widget_ImageView.c', 'src/api-impl-jni/widgets/android_widget_ImageView.c',
'src/api-impl-jni/widgets/WrapperWidget.c', 'src/api-impl-jni/widgets/WrapperWidget.c',
'src/api-impl-jni/widgets/android_widget_TextView.c', 'src/api-impl-jni/widgets/android_widget_TextView.c',
'src/api-impl-jni/widgets/android_widget_LinearLayout.c',
'src/api-impl-jni/widgets/android_widget_Progressbar.c', 'src/api-impl-jni/widgets/android_widget_Progressbar.c',
'src/api-impl-jni/widgets/android_view_SurfaceView.c', 'src/api-impl-jni/widgets/android_view_SurfaceView.c',
'src/api-impl-jni/views/AndroidLayout.c', 'src/api-impl-jni/views/AndroidLayout.c',

View File

@@ -1,237 +0,0 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class android_widget_LinearLayout */
#ifndef _Included_android_widget_LinearLayout
#define _Included_android_widget_LinearLayout
#ifdef __cplusplus
extern "C" {
#endif
#undef android_widget_LinearLayout_NO_ID
#define android_widget_LinearLayout_NO_ID -1L
#undef android_widget_LinearLayout_NOT_FOCUSABLE
#define android_widget_LinearLayout_NOT_FOCUSABLE 0L
#undef android_widget_LinearLayout_FOCUSABLE
#define android_widget_LinearLayout_FOCUSABLE 1L
#undef android_widget_LinearLayout_FOCUSABLE_MASK
#define android_widget_LinearLayout_FOCUSABLE_MASK 1L
#undef android_widget_LinearLayout_FITS_SYSTEM_WINDOWS
#define android_widget_LinearLayout_FITS_SYSTEM_WINDOWS 2L
#undef android_widget_LinearLayout_VISIBLE
#define android_widget_LinearLayout_VISIBLE 0L
#undef android_widget_LinearLayout_INVISIBLE
#define android_widget_LinearLayout_INVISIBLE 4L
#undef android_widget_LinearLayout_GONE
#define android_widget_LinearLayout_GONE 8L
#undef android_widget_LinearLayout_VISIBILITY_MASK
#define android_widget_LinearLayout_VISIBILITY_MASK 12L
#undef android_widget_LinearLayout_ENABLED
#define android_widget_LinearLayout_ENABLED 0L
#undef android_widget_LinearLayout_DISABLED
#define android_widget_LinearLayout_DISABLED 32L
#undef android_widget_LinearLayout_ENABLED_MASK
#define android_widget_LinearLayout_ENABLED_MASK 32L
#undef android_widget_LinearLayout_WILL_NOT_DRAW
#define android_widget_LinearLayout_WILL_NOT_DRAW 128L
#undef android_widget_LinearLayout_DRAW_MASK
#define android_widget_LinearLayout_DRAW_MASK 128L
#undef android_widget_LinearLayout_SCROLLBARS_NONE
#define android_widget_LinearLayout_SCROLLBARS_NONE 0L
#undef android_widget_LinearLayout_SCROLLBARS_HORIZONTAL
#define android_widget_LinearLayout_SCROLLBARS_HORIZONTAL 256L
#undef android_widget_LinearLayout_SCROLLBARS_VERTICAL
#define android_widget_LinearLayout_SCROLLBARS_VERTICAL 512L
#undef android_widget_LinearLayout_SCROLLBARS_MASK
#define android_widget_LinearLayout_SCROLLBARS_MASK 768L
#undef android_widget_LinearLayout_FILTER_TOUCHES_WHEN_OBSCURED
#define android_widget_LinearLayout_FILTER_TOUCHES_WHEN_OBSCURED 1024L
#undef android_widget_LinearLayout_OPTIONAL_FITS_SYSTEM_WINDOWS
#define android_widget_LinearLayout_OPTIONAL_FITS_SYSTEM_WINDOWS 2048L
#undef android_widget_LinearLayout_FADING_EDGE_NONE
#define android_widget_LinearLayout_FADING_EDGE_NONE 0L
#undef android_widget_LinearLayout_FADING_EDGE_HORIZONTAL
#define android_widget_LinearLayout_FADING_EDGE_HORIZONTAL 4096L
#undef android_widget_LinearLayout_FADING_EDGE_VERTICAL
#define android_widget_LinearLayout_FADING_EDGE_VERTICAL 8192L
#undef android_widget_LinearLayout_FADING_EDGE_MASK
#define android_widget_LinearLayout_FADING_EDGE_MASK 12288L
#undef android_widget_LinearLayout_CLICKABLE
#define android_widget_LinearLayout_CLICKABLE 16384L
#undef android_widget_LinearLayout_DRAWING_CACHE_ENABLED
#define android_widget_LinearLayout_DRAWING_CACHE_ENABLED 32768L
#undef android_widget_LinearLayout_SAVE_DISABLED
#define android_widget_LinearLayout_SAVE_DISABLED 65536L
#undef android_widget_LinearLayout_SAVE_DISABLED_MASK
#define android_widget_LinearLayout_SAVE_DISABLED_MASK 65536L
#undef android_widget_LinearLayout_WILL_NOT_CACHE_DRAWING
#define android_widget_LinearLayout_WILL_NOT_CACHE_DRAWING 131072L
#undef android_widget_LinearLayout_FOCUSABLE_IN_TOUCH_MODE
#define android_widget_LinearLayout_FOCUSABLE_IN_TOUCH_MODE 262144L
#undef android_widget_LinearLayout_DRAWING_CACHE_QUALITY_LOW
#define android_widget_LinearLayout_DRAWING_CACHE_QUALITY_LOW 524288L
#undef android_widget_LinearLayout_DRAWING_CACHE_QUALITY_HIGH
#define android_widget_LinearLayout_DRAWING_CACHE_QUALITY_HIGH 1048576L
#undef android_widget_LinearLayout_DRAWING_CACHE_QUALITY_AUTO
#define android_widget_LinearLayout_DRAWING_CACHE_QUALITY_AUTO 0L
#undef android_widget_LinearLayout_DRAWING_CACHE_QUALITY_MASK
#define android_widget_LinearLayout_DRAWING_CACHE_QUALITY_MASK 1572864L
#undef android_widget_LinearLayout_LONG_CLICKABLE
#define android_widget_LinearLayout_LONG_CLICKABLE 2097152L
#undef android_widget_LinearLayout_DUPLICATE_PARENT_STATE
#define android_widget_LinearLayout_DUPLICATE_PARENT_STATE 4194304L
#undef android_widget_LinearLayout_SCROLLBARS_INSIDE_OVERLAY
#define android_widget_LinearLayout_SCROLLBARS_INSIDE_OVERLAY 0L
#undef android_widget_LinearLayout_SCROLLBARS_INSIDE_INSET
#define android_widget_LinearLayout_SCROLLBARS_INSIDE_INSET 16777216L
#undef android_widget_LinearLayout_SCROLLBARS_OUTSIDE_OVERLAY
#define android_widget_LinearLayout_SCROLLBARS_OUTSIDE_OVERLAY 33554432L
#undef android_widget_LinearLayout_SCROLLBARS_OUTSIDE_INSET
#define android_widget_LinearLayout_SCROLLBARS_OUTSIDE_INSET 50331648L
#undef android_widget_LinearLayout_SCROLLBARS_INSET_MASK
#define android_widget_LinearLayout_SCROLLBARS_INSET_MASK 16777216L
#undef android_widget_LinearLayout_SCROLLBARS_OUTSIDE_MASK
#define android_widget_LinearLayout_SCROLLBARS_OUTSIDE_MASK 33554432L
#undef android_widget_LinearLayout_SCROLLBARS_STYLE_MASK
#define android_widget_LinearLayout_SCROLLBARS_STYLE_MASK 50331648L
#undef android_widget_LinearLayout_KEEP_SCREEN_ON
#define android_widget_LinearLayout_KEEP_SCREEN_ON 67108864L
#undef android_widget_LinearLayout_SOUND_EFFECTS_ENABLED
#define android_widget_LinearLayout_SOUND_EFFECTS_ENABLED 134217728L
#undef android_widget_LinearLayout_HAPTIC_FEEDBACK_ENABLED
#define android_widget_LinearLayout_HAPTIC_FEEDBACK_ENABLED 268435456L
#undef android_widget_LinearLayout_PARENT_SAVE_DISABLED
#define android_widget_LinearLayout_PARENT_SAVE_DISABLED 536870912L
#undef android_widget_LinearLayout_PARENT_SAVE_DISABLED_MASK
#define android_widget_LinearLayout_PARENT_SAVE_DISABLED_MASK 536870912L
#undef android_widget_LinearLayout_FOCUSABLES_ALL
#define android_widget_LinearLayout_FOCUSABLES_ALL 0L
#undef android_widget_LinearLayout_FOCUSABLES_TOUCH_MODE
#define android_widget_LinearLayout_FOCUSABLES_TOUCH_MODE 1L
#undef android_widget_LinearLayout_FOCUS_BACKWARD
#define android_widget_LinearLayout_FOCUS_BACKWARD 1L
#undef android_widget_LinearLayout_FOCUS_FORWARD
#define android_widget_LinearLayout_FOCUS_FORWARD 2L
#undef android_widget_LinearLayout_FOCUS_LEFT
#define android_widget_LinearLayout_FOCUS_LEFT 17L
#undef android_widget_LinearLayout_FOCUS_UP
#define android_widget_LinearLayout_FOCUS_UP 33L
#undef android_widget_LinearLayout_FOCUS_RIGHT
#define android_widget_LinearLayout_FOCUS_RIGHT 66L
#undef android_widget_LinearLayout_FOCUS_DOWN
#define android_widget_LinearLayout_FOCUS_DOWN 130L
#undef android_widget_LinearLayout_MEASURED_SIZE_MASK
#define android_widget_LinearLayout_MEASURED_SIZE_MASK 16777215L
#undef android_widget_LinearLayout_MEASURED_STATE_MASK
#define android_widget_LinearLayout_MEASURED_STATE_MASK -16777216L
#undef android_widget_LinearLayout_MEASURED_HEIGHT_STATE_SHIFT
#define android_widget_LinearLayout_MEASURED_HEIGHT_STATE_SHIFT 16L
#undef android_widget_LinearLayout_MEASURED_STATE_TOO_SMALL
#define android_widget_LinearLayout_MEASURED_STATE_TOO_SMALL 16777216L
#undef android_widget_LinearLayout_PFLAG2_DRAG_CAN_ACCEPT
#define android_widget_LinearLayout_PFLAG2_DRAG_CAN_ACCEPT 1L
#undef android_widget_LinearLayout_PFLAG2_DRAG_HOVERED
#define android_widget_LinearLayout_PFLAG2_DRAG_HOVERED 2L
#undef android_widget_LinearLayout_LAYOUT_DIRECTION_LTR
#define android_widget_LinearLayout_LAYOUT_DIRECTION_LTR 0L
#undef android_widget_LinearLayout_LAYOUT_DIRECTION_RTL
#define android_widget_LinearLayout_LAYOUT_DIRECTION_RTL 1L
#undef android_widget_LinearLayout_LAYOUT_DIRECTION_INHERIT
#define android_widget_LinearLayout_LAYOUT_DIRECTION_INHERIT 2L
#undef android_widget_LinearLayout_LAYOUT_DIRECTION_LOCALE
#define android_widget_LinearLayout_LAYOUT_DIRECTION_LOCALE 3L
#undef android_widget_LinearLayout_PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT
#define android_widget_LinearLayout_PFLAG2_LAYOUT_DIRECTION_MASK_SHIFT 2L
#undef android_widget_LinearLayout_PFLAG2_LAYOUT_DIRECTION_MASK
#define android_widget_LinearLayout_PFLAG2_LAYOUT_DIRECTION_MASK 12L
#undef android_widget_LinearLayout_PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL
#define android_widget_LinearLayout_PFLAG2_LAYOUT_DIRECTION_RESOLVED_RTL 16L
#undef android_widget_LinearLayout_PFLAG2_LAYOUT_DIRECTION_RESOLVED
#define android_widget_LinearLayout_PFLAG2_LAYOUT_DIRECTION_RESOLVED 32L
#undef android_widget_LinearLayout_PFLAG2_LAYOUT_DIRECTION_RESOLVED_MASK
#define android_widget_LinearLayout_PFLAG2_LAYOUT_DIRECTION_RESOLVED_MASK 48L
#undef android_widget_LinearLayout_STATUS_BAR_HIDDEN
#define android_widget_LinearLayout_STATUS_BAR_HIDDEN 1L
#undef android_widget_LinearLayout_STATUS_BAR_VISIBLE
#define android_widget_LinearLayout_STATUS_BAR_VISIBLE 0L
#undef android_widget_LinearLayout_SYSTEM_UI_FLAG_FULLSCREEN
#define android_widget_LinearLayout_SYSTEM_UI_FLAG_FULLSCREEN 4L
#undef android_widget_LinearLayout_SYSTEM_UI_FLAG_HIDE_NAVIGATION
#define android_widget_LinearLayout_SYSTEM_UI_FLAG_HIDE_NAVIGATION 2L
#undef android_widget_LinearLayout_SYSTEM_UI_FLAG_IMMERSIVE
#define android_widget_LinearLayout_SYSTEM_UI_FLAG_IMMERSIVE 2048L
#undef android_widget_LinearLayout_SYSTEM_UI_FLAG_IMMERSIVE_STICKY
#define android_widget_LinearLayout_SYSTEM_UI_FLAG_IMMERSIVE_STICKY 4096L
#undef android_widget_LinearLayout_SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
#define android_widget_LinearLayout_SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 1024L
#undef android_widget_LinearLayout_SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
#define android_widget_LinearLayout_SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 512L
#undef android_widget_LinearLayout_SYSTEM_UI_FLAG_LAYOUT_STABLE
#define android_widget_LinearLayout_SYSTEM_UI_FLAG_LAYOUT_STABLE 256L
#undef android_widget_LinearLayout_SYSTEM_UI_FLAG_LOW_PROFILE
#define android_widget_LinearLayout_SYSTEM_UI_FLAG_LOW_PROFILE 1L
#undef android_widget_LinearLayout_SYSTEM_UI_FLAG_VISIBLE
#define android_widget_LinearLayout_SYSTEM_UI_FLAG_VISIBLE 0L
#undef android_widget_LinearLayout_SYSTEM_UI_LAYOUT_FLAGS
#define android_widget_LinearLayout_SYSTEM_UI_LAYOUT_FLAGS 1536L
#undef android_widget_LinearLayout_TEXT_ALIGNMENT_CENTER
#define android_widget_LinearLayout_TEXT_ALIGNMENT_CENTER 4L
#undef android_widget_LinearLayout_TEXT_ALIGNMENT_GRAVITY
#define android_widget_LinearLayout_TEXT_ALIGNMENT_GRAVITY 1L
#undef android_widget_LinearLayout_TEXT_ALIGNMENT_INHERIT
#define android_widget_LinearLayout_TEXT_ALIGNMENT_INHERIT 0L
#undef android_widget_LinearLayout_TEXT_ALIGNMENT_TEXT_END
#define android_widget_LinearLayout_TEXT_ALIGNMENT_TEXT_END 3L
#undef android_widget_LinearLayout_TEXT_ALIGNMENT_TEXT_START
#define android_widget_LinearLayout_TEXT_ALIGNMENT_TEXT_START 2L
#undef android_widget_LinearLayout_TEXT_ALIGNMENT_VIEW_END
#define android_widget_LinearLayout_TEXT_ALIGNMENT_VIEW_END 6L
#undef android_widget_LinearLayout_TEXT_ALIGNMENT_VIEW_START
#define android_widget_LinearLayout_TEXT_ALIGNMENT_VIEW_START 5L
#undef android_widget_LinearLayout_TEXT_DIRECTION_ANY_RTL
#define android_widget_LinearLayout_TEXT_DIRECTION_ANY_RTL 2L
#undef android_widget_LinearLayout_TEXT_DIRECTION_FIRST_STRONG
#define android_widget_LinearLayout_TEXT_DIRECTION_FIRST_STRONG 1L
#undef android_widget_LinearLayout_TEXT_DIRECTION_INHERIT
#define android_widget_LinearLayout_TEXT_DIRECTION_INHERIT 0L
#undef android_widget_LinearLayout_TEXT_DIRECTION_LOCALE
#define android_widget_LinearLayout_TEXT_DIRECTION_LOCALE 5L
#undef android_widget_LinearLayout_TEXT_DIRECTION_LTR
#define android_widget_LinearLayout_TEXT_DIRECTION_LTR 3L
#undef android_widget_LinearLayout_TEXT_DIRECTION_RTL
#define android_widget_LinearLayout_TEXT_DIRECTION_RTL 4L
/*
* Class: android_widget_LinearLayout
* Method: native_constructor
* Signature: (Landroid/content/Context;Landroid/util/AttributeSet;)J
*/
JNIEXPORT jlong JNICALL Java_android_widget_LinearLayout_native_1constructor
(JNIEnv *, jobject, jobject, jobject);
/*
* Class: android_widget_LinearLayout
* Method: setOrientation
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_android_widget_LinearLayout_setOrientation
(JNIEnv *, jobject, jint);
/*
* Class: android_widget_LinearLayout
* Method: getOrientation
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_android_widget_LinearLayout_getOrientation
(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
}
#endif
#endif

View File

@@ -1,44 +0,0 @@
#include <gtk/gtk.h>
#include "../defines.h"
#include "../util.h"
#include "WrapperWidget.h"
#include "../generated_headers/android_widget_LinearLayout.h"
#include "../generated_headers/android_view_ViewGroup.h"
JNIEXPORT jlong JNICALL Java_android_widget_LinearLayout_native_1constructor(JNIEnv *env, jobject this, jobject context, jobject attrs)
{
int orientation = attribute_set_get_int(env, attrs, "orientation", NULL, 0);
GtkWidget *wrapper = g_object_ref(wrapper_widget_new());
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_jobject(WRAPPER_WIDGET(wrapper), env, this);
gtk_widget_set_name(GTK_WIDGET(box), "LinearLayout");
if (!attrs) {
gtk_widget_set_hexpand_set(box, true); // FIXME: to counteract expand on drawing areas
gtk_widget_set_vexpand_set(box, true); // XXX
}
return _INTPTR(box);
// struct ninepatch_t *ninepatch = ninepatch_new("/home/Mis012/Github_and_other_sources/org.happysanta.gd_29_src.tar.gz/res/drawable-mdpi/btn_br_down.9.png");
// g_object_set_data(G_OBJECT(wrapper), "background_ninepatch", ninepatch);
}
JNIEXPORT void JNICALL Java_android_widget_LinearLayout_setOrientation(JNIEnv *env, jobject this, jint orientation)
{
gtk_orientable_set_orientation(GTK_ORIENTABLE(_PTR(_GET_LONG_FIELD(this, "widget"))), orientation ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL);
}
JNIEXPORT jint JNICALL Java_android_widget_LinearLayout_getOrientation(JNIEnv *env, jobject this)
{
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);
}

File diff suppressed because it is too large Load Diff