2022-05-15 13:01:15 +02:00
|
|
|
#include "android_dialogs.h"
|
2022-05-15 21:26:27 +02:00
|
|
|
|
2026-01-13 21:40:02 +01:00
|
|
|
#include "logger.h"
|
|
|
|
|
#include <android/asset_manager.h>
|
2022-05-15 13:01:15 +02:00
|
|
|
#include <android/log.h>
|
|
|
|
|
#include <android_native_app_glue.h>
|
|
|
|
|
|
2026-01-13 21:40:02 +01:00
|
|
|
extern struct android_app *g_App;
|
2022-05-15 13:01:15 +02:00
|
|
|
|
2022-05-15 20:15:19 +02:00
|
|
|
void show_select_file_dialog()
|
2022-05-15 13:01:15 +02:00
|
|
|
{
|
2024-01-21 21:52:54 -05:00
|
|
|
JavaVM *java_vm = g_App->activity->vm;
|
2022-05-15 13:01:15 +02:00
|
|
|
JNIEnv *java_env = NULL;
|
|
|
|
|
|
|
|
|
|
jint jni_return = java_vm->GetEnv((void **)&java_env, JNI_VERSION_1_6);
|
|
|
|
|
if (jni_return == JNI_ERR)
|
|
|
|
|
throw std::runtime_error("Could not get JNI environement");
|
|
|
|
|
|
|
|
|
|
jni_return = java_vm->AttachCurrentThread(&java_env, NULL);
|
|
|
|
|
if (jni_return != JNI_OK)
|
|
|
|
|
throw std::runtime_error("Could not attach to thread");
|
|
|
|
|
|
2024-01-21 21:52:54 -05:00
|
|
|
jclass native_activity_clazz = java_env->GetObjectClass(g_App->activity->clazz);
|
2022-05-15 13:01:15 +02:00
|
|
|
if (native_activity_clazz == NULL)
|
|
|
|
|
throw std::runtime_error("Could not get MainActivity class");
|
|
|
|
|
|
2022-05-15 20:15:19 +02:00
|
|
|
jmethodID method_id = java_env->GetMethodID(native_activity_clazz, "select_file", "()V");
|
2022-05-15 13:01:15 +02:00
|
|
|
if (method_id == NULL)
|
|
|
|
|
throw std::runtime_error("Could not get methode ID");
|
|
|
|
|
|
2024-01-21 21:52:54 -05:00
|
|
|
java_env->CallVoidMethod(g_App->activity->clazz, method_id);
|
2022-05-15 13:01:15 +02:00
|
|
|
|
|
|
|
|
jni_return = java_vm->DetachCurrentThread();
|
|
|
|
|
if (jni_return != JNI_OK)
|
|
|
|
|
throw std::runtime_error("Could not detach from thread");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string get_select_file_dialog_result()
|
|
|
|
|
{
|
2024-01-21 21:52:54 -05:00
|
|
|
JavaVM *java_vm = g_App->activity->vm;
|
2022-05-15 13:01:15 +02:00
|
|
|
JNIEnv *java_env = NULL;
|
|
|
|
|
|
|
|
|
|
jint jni_return = java_vm->GetEnv((void **)&java_env, JNI_VERSION_1_6);
|
|
|
|
|
if (jni_return == JNI_ERR)
|
|
|
|
|
throw std::runtime_error("Could not get JNI environement");
|
|
|
|
|
|
|
|
|
|
jni_return = java_vm->AttachCurrentThread(&java_env, NULL);
|
|
|
|
|
if (jni_return != JNI_OK)
|
|
|
|
|
throw std::runtime_error("Could not attach to thread");
|
|
|
|
|
|
2024-01-21 21:52:54 -05:00
|
|
|
jclass native_activity_clazz = java_env->GetObjectClass(g_App->activity->clazz);
|
2022-05-15 13:01:15 +02:00
|
|
|
if (native_activity_clazz == NULL)
|
|
|
|
|
throw std::runtime_error("Could not get MainActivity class");
|
|
|
|
|
|
2022-05-15 20:15:19 +02:00
|
|
|
jmethodID method_id = java_env->GetMethodID(native_activity_clazz, "select_file_get", "()Ljava/lang/String;");
|
2022-05-15 13:01:15 +02:00
|
|
|
if (method_id == NULL)
|
|
|
|
|
throw std::runtime_error("Could not get methode ID");
|
|
|
|
|
|
2024-01-21 21:52:54 -05:00
|
|
|
jstring jstr = (jstring)java_env->CallObjectMethod(g_App->activity->clazz, method_id);
|
2022-05-15 13:01:15 +02:00
|
|
|
|
|
|
|
|
const char *_str = java_env->GetStringUTFChars(jstr, NULL);
|
|
|
|
|
std::string str(_str);
|
|
|
|
|
java_env->ReleaseStringUTFChars(jstr, _str);
|
|
|
|
|
|
|
|
|
|
jni_return = java_vm->DetachCurrentThread();
|
|
|
|
|
if (jni_return != JNI_OK)
|
|
|
|
|
throw std::runtime_error("Could not detach from thread");
|
|
|
|
|
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-15 20:15:19 +02:00
|
|
|
void show_select_directory_dialog()
|
2022-05-15 13:01:15 +02:00
|
|
|
{
|
2024-01-21 21:52:54 -05:00
|
|
|
JavaVM *java_vm = g_App->activity->vm;
|
2022-05-15 13:01:15 +02:00
|
|
|
JNIEnv *java_env = NULL;
|
|
|
|
|
|
|
|
|
|
jint jni_return = java_vm->GetEnv((void **)&java_env, JNI_VERSION_1_6);
|
|
|
|
|
if (jni_return == JNI_ERR)
|
|
|
|
|
throw std::runtime_error("Could not get JNI environement");
|
|
|
|
|
|
|
|
|
|
jni_return = java_vm->AttachCurrentThread(&java_env, NULL);
|
|
|
|
|
if (jni_return != JNI_OK)
|
|
|
|
|
throw std::runtime_error("Could not attach to thread");
|
|
|
|
|
|
2024-01-21 21:52:54 -05:00
|
|
|
jclass native_activity_clazz = java_env->GetObjectClass(g_App->activity->clazz);
|
2022-05-15 13:01:15 +02:00
|
|
|
if (native_activity_clazz == NULL)
|
|
|
|
|
throw std::runtime_error("Could not get MainActivity class");
|
|
|
|
|
|
2022-05-15 20:15:19 +02:00
|
|
|
jmethodID method_id = java_env->GetMethodID(native_activity_clazz, "select_directory", "()V");
|
2022-05-15 13:01:15 +02:00
|
|
|
if (method_id == NULL)
|
|
|
|
|
throw std::runtime_error("Could not get methode ID");
|
|
|
|
|
|
2024-01-21 21:52:54 -05:00
|
|
|
java_env->CallVoidMethod(g_App->activity->clazz, method_id);
|
2022-05-15 13:01:15 +02:00
|
|
|
|
|
|
|
|
jni_return = java_vm->DetachCurrentThread();
|
|
|
|
|
if (jni_return != JNI_OK)
|
|
|
|
|
throw std::runtime_error("Could not detach from thread");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string get_select_directory_dialog_result()
|
|
|
|
|
{
|
2024-01-21 21:52:54 -05:00
|
|
|
JavaVM *java_vm = g_App->activity->vm;
|
2022-05-15 13:01:15 +02:00
|
|
|
JNIEnv *java_env = NULL;
|
|
|
|
|
|
|
|
|
|
jint jni_return = java_vm->GetEnv((void **)&java_env, JNI_VERSION_1_6);
|
|
|
|
|
if (jni_return == JNI_ERR)
|
|
|
|
|
throw std::runtime_error("Could not get JNI environement");
|
|
|
|
|
|
|
|
|
|
jni_return = java_vm->AttachCurrentThread(&java_env, NULL);
|
|
|
|
|
if (jni_return != JNI_OK)
|
|
|
|
|
throw std::runtime_error("Could not attach to thread");
|
|
|
|
|
|
2024-01-21 21:52:54 -05:00
|
|
|
jclass native_activity_clazz = java_env->GetObjectClass(g_App->activity->clazz);
|
2022-05-15 13:01:15 +02:00
|
|
|
if (native_activity_clazz == NULL)
|
|
|
|
|
throw std::runtime_error("Could not get MainActivity class");
|
|
|
|
|
|
2022-05-15 20:15:19 +02:00
|
|
|
jmethodID method_id = java_env->GetMethodID(native_activity_clazz, "select_directory_get", "()Ljava/lang/String;");
|
2022-05-15 13:01:15 +02:00
|
|
|
if (method_id == NULL)
|
|
|
|
|
throw std::runtime_error("Could not get methode ID");
|
|
|
|
|
|
2024-01-21 21:52:54 -05:00
|
|
|
jstring jstr = (jstring)java_env->CallObjectMethod(g_App->activity->clazz, method_id);
|
2022-05-15 13:01:15 +02:00
|
|
|
|
|
|
|
|
const char *_str = java_env->GetStringUTFChars(jstr, NULL);
|
|
|
|
|
std::string str(_str);
|
|
|
|
|
java_env->ReleaseStringUTFChars(jstr, _str);
|
|
|
|
|
|
|
|
|
|
jni_return = java_vm->DetachCurrentThread();
|
|
|
|
|
if (jni_return != JNI_OK)
|
|
|
|
|
throw std::runtime_error("Could not detach from thread");
|
|
|
|
|
|
|
|
|
|
return str;
|
|
|
|
|
}
|