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
implement WindowManager for composeUI popups
currently everything is created as GtkPopover which is not ideal for toplevel windows, so print a warning in that case.
This commit is contained in:
@@ -128,6 +128,7 @@ libtranslationlayer_so = shared_library('translation_layer_main', [
|
||||
'src/api-impl-jni/views/AndroidLayout.c',
|
||||
'src/api-impl-jni/views/android_view_View.c',
|
||||
'src/api-impl-jni/views/android_view_ViewGroup.c',
|
||||
'src/api-impl-jni/views/android_view_WindowManagerImpl.c',
|
||||
'src/api-impl-jni/widgets/WrapperWidget.c',
|
||||
'src/api-impl-jni/widgets/android_view_SurfaceView.c',
|
||||
'src/api-impl-jni/widgets/android_webkit_WebView.c',
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class android_view_WindowManagerImpl */
|
||||
|
||||
#ifndef _Included_android_view_WindowManagerImpl
|
||||
#define _Included_android_view_WindowManagerImpl
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: android_view_WindowManagerImpl
|
||||
* Method: native_addView
|
||||
* Signature: (JIIIII)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_android_view_WindowManagerImpl_native_1addView
|
||||
(JNIEnv *, jclass, jlong, jint, jint, jint, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: android_view_WindowManagerImpl
|
||||
* Method: native_updateViewLayout
|
||||
* Signature: (JIIII)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_android_view_WindowManagerImpl_native_1updateViewLayout
|
||||
(JNIEnv *, jclass, jlong, jint, jint, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: android_view_WindowManagerImpl
|
||||
* Method: native_removeView
|
||||
* Signature: (J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_android_view_WindowManagerImpl_native_1removeView
|
||||
(JNIEnv *, jclass, jlong);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
45
src/api-impl-jni/views/android_view_WindowManagerImpl.c
Normal file
45
src/api-impl-jni/views/android_view_WindowManagerImpl.c
Normal file
@@ -0,0 +1,45 @@
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "../defines.h"
|
||||
#include "gdk/gdk.h"
|
||||
#include "glib-object.h"
|
||||
#include "../generated_headers/android_view_WindowManagerImpl.h"
|
||||
|
||||
#define FIRST_SUB_WINDOW 1000
|
||||
#define LAST_SUB_WINDOW 1999
|
||||
|
||||
extern GtkWindow *window;
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_view_WindowManagerImpl_native_1addView(JNIEnv *env, jclass clazz, jlong widget_ptr, jint type, jint x, jint y, jint width, jint height)
|
||||
{
|
||||
GtkWidget *widget = _PTR(widget_ptr);
|
||||
if (type < FIRST_SUB_WINDOW || type > LAST_SUB_WINDOW) {
|
||||
// TODO: handle toplevel windows properly
|
||||
printf("WARNING: non subwindow types not implemented properly in WindowManagerImpl\n");
|
||||
}
|
||||
GtkPopover *popover = GTK_POPOVER(g_object_ref(gtk_popover_new()));
|
||||
gtk_popover_set_child(popover, gtk_widget_get_parent(widget));
|
||||
printf("::: x=%d, y=%d, width=%d, height=%d\n", x, y, width, height);
|
||||
gtk_popover_set_autohide(popover, FALSE);
|
||||
gtk_popover_set_pointing_to(popover, &(GdkRectangle){.x=x, .y=y});
|
||||
gtk_widget_insert_before(GTK_WIDGET(popover), gtk_window_get_child(window), NULL);
|
||||
gtk_popover_present(popover);
|
||||
gtk_popover_popup(popover);
|
||||
gtk_widget_queue_allocate(gtk_widget_get_parent(gtk_window_get_child(window)));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_view_WindowManagerImpl_native_1updateViewLayout(JNIEnv *env, jclass clazz, jlong widget_ptr, jint x, jint y, jint width, jint height)
|
||||
{
|
||||
GtkPopover *popover = GTK_POPOVER(gtk_widget_get_parent(gtk_widget_get_parent(gtk_widget_get_parent(GTK_WIDGET(_PTR(widget_ptr))))));
|
||||
printf("updateViewLayout::: x=%d, y=%d, width=%d, height=%d\n", x, y, width, height);
|
||||
gtk_popover_set_pointing_to(popover, &(GdkRectangle){.x=x, .y=y});
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_view_WindowManagerImpl_native_1removeView(JNIEnv *env, jclass clazz, jlong widget_ptr)
|
||||
{
|
||||
GtkPopover *popover = GTK_POPOVER(gtk_widget_get_parent(gtk_widget_get_parent(gtk_widget_get_parent(GTK_WIDGET(_PTR(widget_ptr))))));
|
||||
gtk_popover_popdown(popover);
|
||||
gtk_widget_unparent(GTK_WIDGET(popover));
|
||||
gtk_popover_set_child(popover, NULL);
|
||||
g_object_unref(popover);
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import android.os.IBinder;
|
||||
public interface WindowManager {
|
||||
public android.view.Display getDefaultDisplay();
|
||||
|
||||
public void removeViewImmediate(View view);
|
||||
|
||||
public class LayoutParams extends ViewGroup.LayoutParams {
|
||||
public static final int FLAG_KEEP_SCREEN_ON = 0;
|
||||
public static final int FLAG_DIM_BEHIND = 2;
|
||||
|
||||
@@ -8,16 +8,31 @@ public class WindowManagerImpl implements WindowManager, ViewManager {
|
||||
@Override
|
||||
public void addView(View view, android.view.ViewGroup.LayoutParams params) {
|
||||
System.out.println("WindowManagerImpl.addView(" + view + ", " + params + ") called");
|
||||
view.setLayoutParams(params);
|
||||
view.onAttachedToWindow();
|
||||
WindowManager.LayoutParams windowParams = (WindowManager.LayoutParams)params;
|
||||
native_addView(view.widget, windowParams.type, windowParams.x, windowParams.y, params.width, params.height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateViewLayout(View view, android.view.ViewGroup.LayoutParams params) {
|
||||
System.out.println("WindowManagerImpl.updateViewLayout(" + view + ", " + params + ") called");
|
||||
WindowManager.LayoutParams windowParams = (WindowManager.LayoutParams)params;
|
||||
view.setLayoutParams(params);
|
||||
native_updateViewLayout(view.widget, windowParams.x, windowParams.y, params.width, params.height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeView(View view) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'removeView'");
|
||||
native_removeView(view.widget);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeViewImmediate(View view) {
|
||||
removeView(view);
|
||||
}
|
||||
|
||||
private static native void native_addView(long widget, int type, int x, int y, int width, int height);
|
||||
private static native void native_updateViewLayout(long widget, int x, int y, int width, int height);
|
||||
private static native void native_removeView(long widget);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user