diff --git a/meson.build b/meson.build index 22587d4d..5d4d0f27 100644 --- a/meson.build +++ b/meson.build @@ -88,6 +88,7 @@ libtranslationlayer_so = shared_library('translation_layer_main', [ 'src/api-impl-jni/location/android_location_LocationManager.c', 'src/api-impl-jni/app/android_app_Activity.c', 'src/api-impl-jni/app/android_app_AlertDialog.c', + 'src/api-impl-jni/app/android_app_Dialog.c', ] + marshal_files, install: true, install_dir : get_option('libdir') / 'java/dex/android_translation_layer/natives', diff --git a/src/api-impl-jni/app/android_app_AlertDialog.c b/src/api-impl-jni/app/android_app_AlertDialog.c index 6e70ff35..94c4b57f 100644 --- a/src/api-impl-jni/app/android_app_AlertDialog.c +++ b/src/api-impl-jni/app/android_app_AlertDialog.c @@ -4,21 +4,6 @@ #include "../defines.h" #include "../generated_headers/android_app_AlertDialog.h" -JNIEXPORT jlong JNICALL Java_android_app_AlertDialog_nativeInit(JNIEnv *env, jobject this) -{ - GtkWidget *dialog = gtk_dialog_new(); - g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_window_destroy), dialog); - return _INTPTR(dialog); -} - -JNIEXPORT void JNICALL Java_android_app_AlertDialog_nativeSetTitle(JNIEnv *env, jobject this, jlong ptr, jstring title) -{ - GtkWindow *dialog = GTK_WINDOW(_PTR(ptr)); - const char* nativeTitle = (*env)->GetStringUTFChars(env, title, NULL); - gtk_window_set_title(dialog, nativeTitle); - (*env)->ReleaseStringUTFChars(env, title, nativeTitle); -} - JNIEXPORT void JNICALL Java_android_app_AlertDialog_nativeSetMessage(JNIEnv *env, jobject this, jlong ptr, jstring message) { GtkDialog *dialog = GTK_DIALOG(_PTR(ptr)); @@ -107,9 +92,3 @@ JNIEXPORT void JNICALL Java_android_app_AlertDialog_nativeSetItems(JNIEnv *env, g_signal_connect(list, "activate", G_CALLBACK(activate_cb), callback_data); } - -JNIEXPORT void JNICALL Java_android_app_AlertDialog_nativeShow(JNIEnv *env, jobject this, jlong ptr) -{ - GtkWindow *dialog = GTK_WINDOW(_PTR(ptr)); - gtk_window_present(dialog); -} diff --git a/src/api-impl-jni/app/android_app_Dialog.c b/src/api-impl-jni/app/android_app_Dialog.c new file mode 100644 index 00000000..b4df6719 --- /dev/null +++ b/src/api-impl-jni/app/android_app_Dialog.c @@ -0,0 +1,34 @@ +#include +#include + +#include "../defines.h" +#include "../generated_headers/android_app_Dialog.h" + +JNIEXPORT jlong JNICALL Java_android_app_Dialog_nativeInit(JNIEnv *env, jobject this) +{ + GtkWidget *dialog = gtk_dialog_new(); + g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_window_destroy), dialog); + return _INTPTR(dialog); +} + +JNIEXPORT void JNICALL Java_android_app_Dialog_nativeSetTitle(JNIEnv *env, jobject this, jlong ptr, jstring title) +{ + GtkWindow *dialog = GTK_WINDOW(_PTR(ptr)); + const char* nativeTitle = (*env)->GetStringUTFChars(env, title, NULL); + gtk_window_set_title(dialog, nativeTitle); + (*env)->ReleaseStringUTFChars(env, title, nativeTitle); +} + +JNIEXPORT void JNICALL Java_android_app_Dialog_nativeSetContentView(JNIEnv *env, jobject this, jlong ptr, jlong widget_ptr) { + GtkDialog *dialog = GTK_DIALOG(_PTR(ptr)); + GtkWidget *widget = GTK_WIDGET(_PTR(widget_ptr)); + + GtkWidget *content_area = gtk_dialog_get_content_area(dialog); + gtk_box_append(GTK_BOX(content_area), gtk_widget_get_parent(widget)); +} + +JNIEXPORT void JNICALL Java_android_app_Dialog_nativeShow(JNIEnv *env, jobject this, jlong ptr) +{ + GtkWindow *dialog = GTK_WINDOW(_PTR(ptr)); + gtk_window_present(dialog); +} diff --git a/src/api-impl-jni/generated_headers/android_app_AlertDialog.h b/src/api-impl-jni/generated_headers/android_app_AlertDialog.h index b6ee7be1..666afa8b 100644 --- a/src/api-impl-jni/generated_headers/android_app_AlertDialog.h +++ b/src/api-impl-jni/generated_headers/android_app_AlertDialog.h @@ -7,22 +7,6 @@ #ifdef __cplusplus extern "C" { #endif -/* - * Class: android_app_AlertDialog - * Method: nativeInit - * Signature: ()J - */ -JNIEXPORT jlong JNICALL Java_android_app_AlertDialog_nativeInit - (JNIEnv *, jobject); - -/* - * Class: android_app_AlertDialog - * Method: nativeSetTitle - * Signature: (JLjava/lang/String;)V - */ -JNIEXPORT void JNICALL Java_android_app_AlertDialog_nativeSetTitle - (JNIEnv *, jobject, jlong, jstring); - /* * Class: android_app_AlertDialog * Method: nativeSetMessage @@ -47,14 +31,6 @@ JNIEXPORT void JNICALL Java_android_app_AlertDialog_nativeSetButton JNIEXPORT void JNICALL Java_android_app_AlertDialog_nativeSetItems (JNIEnv *, jobject, jlong, jobjectArray, jobject); -/* - * Class: android_app_AlertDialog - * Method: nativeShow - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_android_app_AlertDialog_nativeShow - (JNIEnv *, jobject, jlong); - #ifdef __cplusplus } #endif diff --git a/src/api-impl-jni/generated_headers/android_app_Dialog.h b/src/api-impl-jni/generated_headers/android_app_Dialog.h new file mode 100644 index 00000000..a79bc698 --- /dev/null +++ b/src/api-impl-jni/generated_headers/android_app_Dialog.h @@ -0,0 +1,45 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class android_app_Dialog */ + +#ifndef _Included_android_app_Dialog +#define _Included_android_app_Dialog +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: android_app_Dialog + * Method: nativeInit + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_android_app_Dialog_nativeInit + (JNIEnv *, jobject); + +/* + * Class: android_app_Dialog + * Method: nativeSetTitle + * Signature: (JLjava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_android_app_Dialog_nativeSetTitle + (JNIEnv *, jobject, jlong, jstring); + +/* + * Class: android_app_Dialog + * Method: nativeSetContentView + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL Java_android_app_Dialog_nativeSetContentView + (JNIEnv *, jobject, jlong, jlong); + +/* + * Class: android_app_Dialog + * Method: nativeShow + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_android_app_Dialog_nativeShow + (JNIEnv *, jobject, jlong); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/api-impl/android/app/AlertDialog.java b/src/api-impl/android/app/AlertDialog.java index 1aaf33e8..0cdc8e9e 100644 --- a/src/api-impl/android/app/AlertDialog.java +++ b/src/api-impl/android/app/AlertDialog.java @@ -2,28 +2,16 @@ package android.app; import android.content.Context; import android.content.DialogInterface; -import android.os.Handler; -import android.os.Looper; import android.view.View; public class AlertDialog extends Dialog implements DialogInterface { - private long nativePtr; - - private native long nativeInit(); - private native void nativeSetTitle(long ptr, String title); private native void nativeSetMessage(long ptr, String message); private native void nativeSetButton(long ptr, int whichButton, String text); private native void nativeSetItems(long ptr, String[] items, DialogInterface.OnClickListener listener); - private native void nativeShow(long ptr); public AlertDialog(Context context) { super(context, 0); - nativePtr = nativeInit(); - } - - public void setTitle(CharSequence title) { - nativeSetTitle(nativePtr, String.valueOf(title)); } public void setMessage(CharSequence message) { @@ -35,21 +23,6 @@ public class AlertDialog extends Dialog implements DialogInterface { nativeSetButton(nativePtr, whichButton, String.valueOf(text)); } - public boolean isShowing() { - return false; - } - - @Override - public void show() { - super.show(); - new Handler(Looper.getMainLooper()).post(new Runnable() { - @Override - public void run() { - nativeShow(nativePtr); - } - }); - } - public static class Builder { private AlertDialog dialog; diff --git a/src/api-impl/android/app/Dialog.java b/src/api-impl/android/app/Dialog.java index 11a54967..08d1e874 100644 --- a/src/api-impl/android/app/Dialog.java +++ b/src/api-impl/android/app/Dialog.java @@ -3,14 +3,23 @@ package android.app; import android.content.Context; import android.content.DialogInterface.OnCancelListener; import android.content.DialogInterface.OnDismissListener; +import android.os.Handler; +import android.os.Looper; import android.view.View; public class Dialog { + protected long nativePtr; + + private native long nativeInit(); + private native void nativeSetTitle(long ptr, String title); + private native void nativeSetContentView(long ptr, long widget); + private native void nativeShow(long ptr); private Context context; public Dialog(Context context, int themeResId) { this.context = context; + nativePtr = nativeInit(); } public final boolean requestWindowFeature(int featureId) { @@ -21,7 +30,13 @@ public class Dialog { return context; } - public void setContentView(View view) {} + public void setContentView(View view) { + nativeSetContentView(nativePtr, view.widget); + } + + public void setTitle(CharSequence title) { + nativeSetTitle(nativePtr, String.valueOf(title)); + } public void setOwnerActivity(Activity activity) {} @@ -33,6 +48,16 @@ public class Dialog { public void show() { System.out.println("totally showing the Dialog " + this + " right now, most definitely doing that"); + new Handler(Looper.getMainLooper()).post(new Runnable() { + @Override + public void run() { + nativeShow(nativePtr); + } + }); + } + + public boolean isShowing() { + return false; } public void dismiss() {