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
handle 'SEND' intent by copying to clipboard, make Activity subclass ContextWrapper, code style fixes
This commit is contained in:
@@ -11,7 +11,8 @@
|
||||
static GList *activity_backlog = NULL;
|
||||
static jobject activity_current = NULL;
|
||||
|
||||
static void activity_close(JNIEnv *env, jobject activity) {
|
||||
static void activity_close(JNIEnv *env, jobject activity)
|
||||
{
|
||||
// in case some exception was left unhandled in native code, print it here so we don't confuse it with an exception thrown by onDestroy
|
||||
if((*env)->ExceptionCheck(env)) {
|
||||
fprintf(stderr, "app_exit: seems there was a pending exception... :");
|
||||
@@ -24,7 +25,8 @@ static void activity_close(JNIEnv *env, jobject activity) {
|
||||
(*env)->ExceptionDescribe(env);
|
||||
}
|
||||
|
||||
static void activity_update_current(JNIEnv *env) {
|
||||
static void activity_update_current(JNIEnv *env)
|
||||
{
|
||||
jobject activity_new = activity_backlog ? g_list_first(activity_backlog)->data : NULL;
|
||||
|
||||
if (activity_current != activity_new) {
|
||||
@@ -59,7 +61,8 @@ static void activity_update_current(JNIEnv *env) {
|
||||
}
|
||||
}
|
||||
|
||||
void activity_window_ready(void) {
|
||||
void activity_window_ready(void)
|
||||
{
|
||||
JNIEnv *env = get_jni_env();
|
||||
|
||||
for (GList *l = activity_backlog; l != NULL; l = l->next) {
|
||||
@@ -69,7 +72,8 @@ void activity_window_ready(void) {
|
||||
}
|
||||
}
|
||||
|
||||
void activity_close_all(void) {
|
||||
void activity_close_all(void)
|
||||
{
|
||||
GList *activities, *l;
|
||||
JNIEnv *env = get_jni_env();
|
||||
// local backup of the backlog
|
||||
@@ -85,7 +89,8 @@ void activity_close_all(void) {
|
||||
g_list_free(activities);
|
||||
}
|
||||
|
||||
void activity_start(JNIEnv *env, jobject activity_object) {
|
||||
void activity_start(JNIEnv *env, jobject activity_object)
|
||||
{
|
||||
/* -- run the activity's onCreate -- */
|
||||
(*env)->CallVoidMethod(env, activity_object, handle_cache.activity.onCreate, NULL);
|
||||
if((*env)->ExceptionCheck(env))
|
||||
@@ -95,7 +100,8 @@ void activity_start(JNIEnv *env, jobject activity_object) {
|
||||
activity_update_current(env);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_app_Activity_nativeFinish(JNIEnv *env, jobject this, jlong window) {
|
||||
JNIEXPORT void JNICALL Java_android_app_Activity_nativeFinish(JNIEnv *env, jobject this, jlong window)
|
||||
{
|
||||
GList *l;
|
||||
jobject removed_activity = NULL;
|
||||
for (l = activity_backlog; l != NULL; l = l->next) {
|
||||
@@ -113,17 +119,29 @@ JNIEXPORT void JNICALL Java_android_app_Activity_nativeFinish(JNIEnv *env, jobje
|
||||
gtk_window_close(GTK_WINDOW(_PTR(window)));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_app_Activity_nativeStartActivity(JNIEnv *env, jclass class, jobject activity) {
|
||||
JNIEXPORT void JNICALL Java_android_app_Activity_nativeStartActivity(JNIEnv *env, jclass class, jobject activity)
|
||||
{
|
||||
activity_start(env, activity);
|
||||
}
|
||||
|
||||
static XdpPortal *portal = NULL;
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_app_Activity_nativeOpenURI(JNIEnv *env, jclass class, jstring uriString) {
|
||||
JNIEXPORT void JNICALL Java_android_app_Activity_nativeOpenURI(JNIEnv *env, jclass class, jstring uriString)
|
||||
{
|
||||
static XdpPortal *portal = NULL;
|
||||
if (!portal) {
|
||||
portal = xdp_portal_new();
|
||||
}
|
||||
const char* uri = (*env)->GetStringUTFChars(env, uriString, NULL);
|
||||
|
||||
const char *uri = (*env)->GetStringUTFChars(env, uriString, NULL);
|
||||
xdp_portal_open_uri(portal, NULL, uri, XDP_OPEN_URI_FLAG_NONE, NULL, NULL, NULL);
|
||||
(*env)->ReleaseStringUTFChars(env, uriString, uri);
|
||||
}
|
||||
|
||||
extern GtkWindow *window; // TODO: get this in a better way
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_app_Activity_nativeShare(JNIEnv *env, jclass class, jstring text_jstring)
|
||||
{
|
||||
const char *text = (*env)->GetStringUTFChars(env, text_jstring, NULL);
|
||||
GdkClipboard *clipboard = gdk_display_get_clipboard(gtk_root_get_display(GTK_ROOT(window)));
|
||||
gdk_clipboard_set_text(clipboard, text);
|
||||
(*env)->ReleaseStringUTFChars(env, text_jstring, text);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user