1717#include < EGL/egl.h>
1818#include < EGL/eglext.h>
1919
20- // setup diig android build
20+ #undef stdin
21+ #undef stdout
22+ #undef stderr
23+
24+ FILE* stdin = NULL ;
25+ FILE* stdout = NULL ;
26+ FILE* stderr = NULL ;
27+
28+ // generate or create a wrapper for pen_activity + new manifest
2129// filesystem functions
2230// openURL etc
31+ // OSK
2332
2433// BLOG NOTES:
2534// - gradle version, always changing, sdk etc bs bs bs
3443// Cannot use @TaskAction annotation on method IncrementalTask.taskAction$gradle_core() because interface org.gradle.api.tasks.incremental.IncrementalTaskInputs is not a valid parameter to an action method.
3544// DEBUGGER INTERMITTENT HANG AND FAIL
3645// DEBUG INFO works better with device
46+ // horrors of getting jvm methods, name mangling etc
3747
3848// DONE:
3949// call c++ from java
4959// orientation changes
5060// debug info? on device
5161// sort out fmod version
62+ // setup diig android build
5263
5364#define PEN_JNIFUNC (ret, actname, funcname ) extern " C" JNIEXPORT ret JNICALL Java_cc_pmtech_##actname##_##funcname
5465
5566// global externs
5667pen::user_info pen_user_info;
5768pen::window_creation_params pen_window;
5869
59- JNIEXPORT jint JNI_OnLoad (JavaVM* vm, void * reserved)
60- {
61- return JNI_VERSION_1_6;
62- }
63-
6470extern void audio_init_fmod_android (JNIEnv* env, jobject thiz, jobject activity);
6571
66- extern " C" JNIEXPORT void JNICALL
67- Java_cc_pmtech_pen_1activity_initFMOD (JNIEnv* env, jobject thiz, jobject activity)
68- {
69- audio_init_fmod_android (env, thiz, activity);
70- }
71-
7272namespace
7373{
7474 struct egl_context
@@ -86,6 +86,8 @@ namespace
8686 ANativeWindow* m_window = nullptr ;
8787 jclass m_surface_wrapper_class;
8888 jobject m_surface_wrapper_object;
89+ jobject m_activity_object;
90+ jclass m_activity_class;
8991 };
9092 android_context s_android_context;
9193
@@ -94,10 +96,41 @@ namespace
9496 pen::window_frame window;
9597 pen::pen_creation_params params;
9698 Str user_dir;
99+ bool keyboard_visible = false ;
97100 };
98101 pmtech_context s_pmtech_context;
99102}
100103
104+ extern " C" JNIEXPORT void JNICALL
105+ Java_cc_pmtech_pen_1activity_init (JNIEnv* env, jobject thiz, jobject activity)
106+ {
107+ s_android_context.m_activity_object = env->NewGlobalRef ((jobject)activity);
108+ s_android_context.m_activity_class = (jclass)env->NewGlobalRef (env->GetObjectClass (s_android_context.m_activity_object ));
109+
110+ audio_init_fmod_android (env, thiz, activity);
111+ }
112+
113+ PEN_JNIFUNC (void , pen_1activity, native_1on_1key_1down)(JNIEnv* env, jclass thiz,int key_code, int unicode_char)
114+ {
115+ int a = 0 ;
116+ }
117+
118+ PEN_JNIFUNC (void , pen_1activity, native_1on_1key_1up)(JNIEnv* env, jclass thiz, int key_code)
119+ {
120+ int a = 0 ;
121+ }
122+
123+ PEN_JNIFUNC (void , pen_1activity, native_1back_1button_1pressed)(JNIEnv* env, jclass thiz)
124+ {
125+ int a = 0 ;
126+ }
127+
128+ JNIEXPORT jint JNI_OnLoad (JavaVM* vm, void * reserved)
129+ {
130+ s_android_context.m_java_vm = vm;
131+ return JNI_VERSION_1_6;
132+ }
133+
101134void pen_make_gl_context_current ()
102135{
103136
@@ -227,6 +260,39 @@ PEN_JNIFUNC(void, SurfaceWrapper, on_1touch_1cancelled)(JNIEnv* env, jclass thiz
227260
228261namespace pen
229262{
263+ JNIEnv* get_jni_env ()
264+ {
265+ if (!s_android_context.m_java_vm )
266+ return nullptr ;
267+
268+ JNIEnv* env;
269+ int status = s_android_context.m_java_vm ->GetEnv ((void **)&env, JNI_VERSION_1_4);
270+ if (status == JNI_EDETACHED)
271+ {
272+ if (s_android_context.m_java_vm ->AttachCurrentThread (&env, nullptr ) != 0 )
273+ return nullptr ;
274+ }
275+ else if (status != JNI_OK)
276+ {
277+ return nullptr ;
278+ }
279+ return env;
280+ }
281+
282+ void get_jni_data (void *& vm, void *& env, void *& instance)
283+ {
284+ /*
285+ JNIEnv* env = get_jni_env();
286+ if(env)
287+ {
288+ jmethodID idGetInstance = env->GetStaticMethodID(s_context.m_device.m_activityClass, "getInstance", "()Landroid/app/Activity;");
289+ instance = env->CallStaticObjectMethod(s_context.m_device.m_activityClass, idGetInstance);
290+ vm = getJavaVM();
291+ env = (void*)env;
292+ }
293+ */
294+ }
295+
230296 u32 window_init (void * params)
231297 {
232298 return 0 ;
@@ -294,7 +360,7 @@ namespace pen
294360
295361 void os_set_cursor_pos (u32 client_x, u32 client_y)
296362 {
297-
363+
298364 }
299365
300366 const user_info& os_get_user_info ()
@@ -312,6 +378,144 @@ namespace pen
312378 return false ;
313379 }
314380
381+ Str os_get_persistent_data_directory ()
382+ {
383+ return " " ;
384+ }
385+
386+ Str os_get_cache_data_directory ()
387+ {
388+ return " " ;
389+ }
390+
391+ void os_create_directory (const Str& dir)
392+ {
393+
394+ }
395+
396+ bool os_delete_directory (const Str& filename)
397+ {
398+
399+ }
400+
401+ void os_open_url (const Str& url)
402+ {
403+
404+ }
405+
406+ void os_ignore_slient ()
407+ {
408+
409+ }
410+
411+ void os_enable_background_audio (bool enabled)
412+ {
413+
414+ }
415+
416+ f32 os_get_status_bar_portrait_height ()
417+ {
418+ auto env= get_jni_env ();
419+
420+ if (env)
421+ {
422+ jmethodID method = env->GetMethodID (s_android_context.m_activity_class , " getStatusBarHeight" , " ()I" );
423+ int res = env->CallIntMethod (s_android_context.m_activity_object , method);
424+ return (f32 )res;
425+ }
426+
427+ return 0 .0f ;
428+ }
429+
430+ void os_haptic_selection_feedback ()
431+ {
432+
433+ }
434+
435+ void os_init_on_screen_keyboard ()
436+ {
437+ // ??
438+ }
439+
440+ void os_show_on_screen_keyboard (bool show)
441+ {
442+ if (s_pmtech_context.keyboard_visible == show)
443+ return ;
444+
445+ auto env = get_jni_env ();
446+ if (env)
447+ {
448+ jmethodID method = env->GetStaticMethodID (s_android_context.m_activity_class , " showKeyboard" , " (Z)V" );
449+ env->CallStaticVoidMethod (s_android_context.m_activity_class , method, show);
450+
451+ s_pmtech_context.keyboard_visible = show;
452+ }
453+ }
454+
455+ bool os_set_keychain_item (const Str& identifier, const Str& key, const Str& value)
456+ {
457+ return false ;
458+ }
459+
460+ Str os_get_keychain_item (const Str& identifier, const Str& key)
461+ {
462+ return " " ;
463+ }
464+
465+ bool os_is_backgrounded ()
466+ {
467+ return false ;
468+ }
469+
470+ void os_register_background_callback (void (*callback)(bool ))
471+ {
472+
473+ }
474+
475+ bool os_require_audio_reinit (bool reset)
476+ {
477+ return false ;
478+ }
479+
480+ // music
481+
482+ const music_item* music_get_items ()
483+ {
484+ return nullptr ;
485+ }
486+
487+ music_file music_open_file (const music_item& item)
488+ {
489+ return {};
490+ }
491+
492+ void music_close_file (const music_file& file)
493+ {
494+
495+ }
496+
497+ void music_enable_remote_control (const music_player_remote& fns)
498+ {
499+
500+ }
501+
502+ void music_set_now_playing (const Str& artist, const Str& album, const Str& track)
503+ {
504+
505+ }
506+
507+ void music_set_now_playing_artwork (void * data, u32 w, u32 h, u32 bpp, u32 row_pitch)
508+ {
509+
510+ }
511+
512+ void music_set_now_playing_time_info (u32 position_ms, u32 duration_ms)
513+ {
514+
515+ }
516+
517+ // filesystem
518+
315519 const c8* filesystem_get_user_directory ()
316520 {
317521 return s_pmtech_context.user_dir .c_str ();
0 commit comments