From 6a6ca22ebeac6e167614228f03eae30a100d546d Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sat, 5 Nov 2022 19:24:14 -0500 Subject: [PATCH] Furnace has stopped. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Diagnose later --- src/gui/fileDialog.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++ src/gui/fileDialog.h | 9 ++++++++ src/gui/settings.cpp | 3 +-- 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/gui/fileDialog.cpp b/src/gui/fileDialog.cpp index 8d524ab4..c5103019 100644 --- a/src/gui/fileDialog.cpp +++ b/src/gui/fileDialog.cpp @@ -4,6 +4,8 @@ #ifdef USE_NFD #include +#elif defined(ANDROID) +#include #else #include "../../extern/pfd-fixed/portable-file-dialogs.h" #endif @@ -87,6 +89,45 @@ bool FurnaceGUIFileDialog::openLoad(String header, std::vector filter, c #else dialogO=new std::thread(_nfdThread,NFDState(false,header,filter,path,clickCallback,allowMultiple),&dialogOK,&nfdResult,&hasError); #endif +#elif defined(ANDROID) + hasError=false; + if (jniEnv==NULL) { + jniEnv=(JNIEnv*)SDL_AndroidGetJNIEnv(); + if (jniEnv==NULL) { + hasError=true; + logE("could not acquire JNI env!"); + return false; + } + } + + jobject activity=(jobject)SDL_AndroidGetActivity(); + if (activity==NULL) { + hasError=true; + logE("the Activity is NULL!"); + return false; + } + + jclass class_=jniEnv->GetObjectClass(activity); + jmethodID showFileDialog=jniEnv->GetMethodID(class_,"showFileDialog","()B"); + + if (showFileDialog==NULL) { + logE("method showFileDialog not found!"); + hasError=true; + jniEnv->DeleteLocalRef(class_); + jniEnv->DeleteLocalRef(activity); + return false; + } + + jboolean mret=jniEnv->CallBooleanMethod(activity,showFileDialog); + + if (!(bool)mret) { + hasError=true; + logW("could not open Android file picker..."); + } + + jniEnv->DeleteLocalRef(class_); + jniEnv->DeleteLocalRef(activity); + return true; #else dialogO=new pfd::open_file(header,path,filter,allowMultiple?(pfd::opt::multiselect):(pfd::opt::none)); hasError=!pfd::settings::available(); @@ -113,6 +154,8 @@ bool FurnaceGUIFileDialog::openSave(String header, std::vector filter, c #else dialogS=new std::thread(_nfdThread,NFDState(true,header,filter,path,NULL,false),&dialogOK,&nfdResult,&hasError); #endif +#elif defined(ANDROID) + hasError=true; // TODO #else dialogS=new pfd::save_file(header,path,filter); hasError=!pfd::settings::available(); @@ -141,7 +184,9 @@ void FurnaceGUIFileDialog::close() { #ifdef USE_NFD dialogS->join(); #endif +#ifndef ANDROID delete dialogS; +#endif dialogS=NULL; } } else { @@ -149,7 +194,9 @@ void FurnaceGUIFileDialog::close() { #ifdef USE_NFD dialogO->join(); #endif +#ifndef ANDROID delete dialogO; +#endif dialogO=NULL; } } @@ -179,6 +226,9 @@ bool FurnaceGUIFileDialog::render(const ImVec2& min, const ImVec2& max) { return true; } return false; +#elif defined(ANDROID) + // TODO: detect when file picker is closed + return false; #else if (saving) { if (dialogS!=NULL) { diff --git a/src/gui/fileDialog.h b/src/gui/fileDialog.h index 7990b037..0fbeeb46 100644 --- a/src/gui/fileDialog.h +++ b/src/gui/fileDialog.h @@ -15,6 +15,8 @@ #define NFD_NON_THREADED #endif +#elif defined(ANDROID) +#include #else namespace pfd { class open_file; @@ -36,6 +38,10 @@ class FurnaceGUIFileDialog { std::thread* dialogS; std::atomic dialogOK; std::vector nfdResult; +#elif defined(ANDROID) + JNIEnv* jniEnv; + void* dialogO; + void* dialogS; #else pfd::open_file* dialogO; pfd::save_file* dialogS; @@ -55,6 +61,9 @@ class FurnaceGUIFileDialog { opened(false), saving(false), hasError(false), +#ifdef ANDROID + jniEnv(NULL), +#endif dialogO(NULL), dialogS(NULL) {} }; diff --git a/src/gui/settings.cpp b/src/gui/settings.cpp index 13844302..a05c98cc 100644 --- a/src/gui/settings.cpp +++ b/src/gui/settings.cpp @@ -40,9 +40,8 @@ #define POWER_SAVE_DEFAULT 0 #endif -#if defined(__HAIKU__) || defined(IS_MOBILE) +#if defined(__HAIKU__) // NFD doesn't support Haiku -// I still haven't implemented Android file picker #define SYS_FILE_DIALOG_DEFAULT 0 #else #define SYS_FILE_DIALOG_DEFAULT 1