implement android import, update android project and build for release
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
#include "asset.h"
|
||||
#include "keymap.h"
|
||||
#include "main.h"
|
||||
#include "com_omixlab_panopainter_MainActivity.h"
|
||||
|
||||
typedef void (*GLDEBUGPROC)(GLenum source,
|
||||
GLenum type,
|
||||
@@ -51,6 +52,12 @@ typedef void (*fnDebugMessageCallback)(GLDEBUGPROC callback, const void* userPar
|
||||
EGLDisplay g_display = EGL_NO_DISPLAY;
|
||||
EGLContext g_context = EGL_NO_CONTEXT;
|
||||
|
||||
jint JNI_OnLoad(JavaVM* vm, void* /*reserved*/)
|
||||
{
|
||||
LOG("JNI_OnLoad");
|
||||
return JNI_VERSION_1_6;
|
||||
}
|
||||
|
||||
std::string utf8chr(int cp)
|
||||
{
|
||||
char c[5]={ 0x00,0x00,0x00,0x00,0x00 };
|
||||
@@ -226,6 +233,100 @@ void displayKeyboard(android_app* mApplication, bool pShow)
|
||||
lJavaVM->DetachCurrentThread();
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: com_omixlab_panopainter_MainActivity
|
||||
* Method: pickFileCallback
|
||||
* Signature: (Ljava/lang/String;)V
|
||||
*/
|
||||
std::function<void(std::string)> pick_file_callback;
|
||||
std::function<void()> pick_file_callback_context;
|
||||
extern "C"
|
||||
{
|
||||
JNIEXPORT void JNICALL Java_com_omixlab_panopainter_MainActivity_pickFileCallback(JNIEnv *env, jobject, jstring path)
|
||||
{
|
||||
const char* path_utf = env->GetStringUTFChars(path, nullptr);
|
||||
std::string file_path = path_utf; // create a copy
|
||||
env->ReleaseStringUTFChars(path, path_utf);
|
||||
|
||||
LOG("received %s", file_path.c_str());
|
||||
pick_file_callback_context = [file_path]
|
||||
{
|
||||
if (pick_file_callback)
|
||||
{
|
||||
LOG("callback");
|
||||
pick_file_callback(file_path);
|
||||
pick_file_callback = nullptr;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
void pick_file(android_app* mApplication, std::function<void(std::string)> callback)
|
||||
{
|
||||
// Attaches the current thread to the JVM.
|
||||
jint lResult;
|
||||
jint lFlags = 0;
|
||||
|
||||
JavaVM* lJavaVM = mApplication->activity->vm;
|
||||
JNIEnv* lJNIEnv = mApplication->activity->env;
|
||||
|
||||
JavaVMAttachArgs lJavaVMAttachArgs;
|
||||
lJavaVMAttachArgs.version = JNI_VERSION_1_6;
|
||||
lJavaVMAttachArgs.name = "NativeThread";
|
||||
lJavaVMAttachArgs.group = NULL;
|
||||
|
||||
lResult=lJavaVM->AttachCurrentThread(&lJNIEnv, &lJavaVMAttachArgs);
|
||||
if (lResult == JNI_ERR)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
pick_file_callback = callback;
|
||||
|
||||
// Retrieves NativeActivity.
|
||||
jobject lNativeActivity = mApplication->activity->clazz;
|
||||
jclass ClassNativeActivity = lJNIEnv->GetObjectClass(lNativeActivity);
|
||||
|
||||
jmethodID MethodPickFile = lJNIEnv->GetMethodID(ClassNativeActivity, "pickFile", "()V");
|
||||
lJNIEnv->CallVoidMethod(lNativeActivity, MethodPickFile);
|
||||
|
||||
// Finished with the JVM.
|
||||
lJavaVM->DetachCurrentThread();
|
||||
}
|
||||
|
||||
|
||||
float get_display_density(android_app* mApplication)
|
||||
{
|
||||
// Attaches the current thread to the JVM.
|
||||
jint lResult;
|
||||
jint lFlags = 0;
|
||||
|
||||
JavaVM* lJavaVM = mApplication->activity->vm;
|
||||
JNIEnv* lJNIEnv = mApplication->activity->env;
|
||||
|
||||
JavaVMAttachArgs lJavaVMAttachArgs;
|
||||
lJavaVMAttachArgs.version = JNI_VERSION_1_6;
|
||||
lJavaVMAttachArgs.name = "NativeThread";
|
||||
lJavaVMAttachArgs.group = NULL;
|
||||
|
||||
lResult=lJavaVM->AttachCurrentThread(&lJNIEnv, &lJavaVMAttachArgs);
|
||||
if (lResult == JNI_ERR)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Retrieves NativeActivity.
|
||||
jobject lNativeActivity = mApplication->activity->clazz;
|
||||
jclass ClassNativeActivity = lJNIEnv->GetObjectClass(lNativeActivity);
|
||||
|
||||
jmethodID MethodPickFile = lJNIEnv->GetMethodID(ClassNativeActivity, "getDensity", "()F");
|
||||
float density = lJNIEnv->CallFloatMethod(lNativeActivity, MethodPickFile);
|
||||
|
||||
// Finished with the JVM.
|
||||
lJavaVM->DetachCurrentThread();
|
||||
return density;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize an EGL context for the current display.
|
||||
*/
|
||||
@@ -376,12 +477,17 @@ static int engine_init_display(struct engine* engine) {
|
||||
engine->height = h;
|
||||
engine->state.angle = 0;
|
||||
|
||||
float density = get_display_density(engine->app);
|
||||
LOG("density %f", density);
|
||||
App::I.zoom = density / 1.5;
|
||||
|
||||
g_display = display;
|
||||
g_context = context;
|
||||
|
||||
if (resuming_context)
|
||||
{
|
||||
LOG("RESUME APP");
|
||||
App::I.and_app = engine->app;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -855,11 +961,12 @@ void android_main(struct android_app* state) {
|
||||
}
|
||||
|
||||
//if (engine.animating)
|
||||
if (engine.display != EGL_NO_DISPLAY)
|
||||
{
|
||||
// Done with events; draw next animation frame.
|
||||
engine.state.angle += .01f;
|
||||
if (engine.state.angle > 1) {
|
||||
engine.state.angle = 0;
|
||||
if (pick_file_callback_context)
|
||||
{
|
||||
pick_file_callback_context();
|
||||
pick_file_callback_context = nullptr;
|
||||
}
|
||||
|
||||
// Drawing is throttled to the screen update rate, so there
|
||||
|
||||
Reference in New Issue
Block a user