Skip to content

Commit 8448d50

Browse files
committed
- more android backend impl
1 parent f69676e commit 8448d50

File tree

2 files changed

+99
-22
lines changed

2 files changed

+99
-22
lines changed

core/pen/source/android/os.cpp

Lines changed: 98 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ FILE* stdin = NULL;
2525
FILE* stdout = NULL;
2626
FILE* stderr = NULL;
2727

28-
// setup diig android build
28+
// generate or create a wrapper for pen_activity + new manifest
2929
// filesystem functions
3030
// openURL etc
31+
// OSK
3132

3233
// BLOG NOTES:
3334
// - gradle version, always changing, sdk etc bs bs bs
@@ -42,6 +43,7 @@ FILE* stderr = NULL;
4243
// 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.
4344
// DEBUGGER INTERMITTENT HANG AND FAIL
4445
// DEBUG INFO works better with device
46+
// horrors of getting jvm methods, name mangling etc
4547

4648
// DONE:
4749
// call c++ from java
@@ -57,26 +59,16 @@ FILE* stderr = NULL;
5759
// orientation changes
5860
// debug info? on device
5961
// sort out fmod version
62+
// setup diig android build
6063

6164
#define PEN_JNIFUNC(ret, actname, funcname) extern "C" JNIEXPORT ret JNICALL Java_cc_pmtech_##actname##_##funcname
6265

6366
// global externs
6467
pen::user_info pen_user_info;
6568
pen::window_creation_params pen_window;
6669

67-
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved)
68-
{
69-
return JNI_VERSION_1_6;
70-
}
71-
7270
extern void audio_init_fmod_android(JNIEnv* env, jobject thiz, jobject activity);
7371

74-
extern "C" JNIEXPORT void JNICALL
75-
Java_cc_pmtech_pen_1activity_initFMOD(JNIEnv* env, jobject thiz, jobject activity)
76-
{
77-
audio_init_fmod_android(env, thiz, activity);
78-
}
79-
8072
namespace
8173
{
8274
struct egl_context
@@ -94,6 +86,8 @@ namespace
9486
ANativeWindow* m_window = nullptr;
9587
jclass m_surface_wrapper_class;
9688
jobject m_surface_wrapper_object;
89+
jobject m_activity_object;
90+
jclass m_activity_class;
9791
};
9892
android_context s_android_context;
9993

@@ -102,10 +96,41 @@ namespace
10296
pen::window_frame window;
10397
pen::pen_creation_params params;
10498
Str user_dir;
99+
bool keyboard_visible = false;
105100
};
106101
pmtech_context s_pmtech_context;
107102
}
108103

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+
109134
void pen_make_gl_context_current()
110135
{
111136

@@ -235,6 +260,39 @@ PEN_JNIFUNC(void, SurfaceWrapper, on_1touch_1cancelled)(JNIEnv* env, jclass thiz
235260

236261
namespace pen
237262
{
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+
238296
u32 window_init(void* params)
239297
{
240298
return 0;
@@ -322,12 +380,12 @@ namespace pen
322380

323381
Str os_get_persistent_data_directory()
324382
{
325-
383+
return "";
326384
}
327385

328386
Str os_get_cache_data_directory()
329387
{
330-
388+
return "";
331389
}
332390

333391
void os_create_directory(const Str& dir)
@@ -357,7 +415,16 @@ namespace pen
357415

358416
f32 os_get_status_bar_portrait_height()
359417
{
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+
}
360426

427+
return 0.0f;
361428
}
362429

363430
void os_haptic_selection_feedback()
@@ -367,27 +434,37 @@ namespace pen
367434

368435
void os_init_on_screen_keyboard()
369436
{
370-
437+
// ??
371438
}
372439

373440
void os_show_on_screen_keyboard(bool show)
374441
{
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);
375450

451+
s_pmtech_context.keyboard_visible = show;
452+
}
376453
}
377454

378455
bool os_set_keychain_item(const Str& identifier, const Str& key, const Str& value)
379456
{
380-
457+
return false;
381458
}
382459

383460
Str os_get_keychain_item(const Str& identifier, const Str& key)
384461
{
385-
462+
return "";
386463
}
387464

388465
bool os_is_backgrounded()
389466
{
390-
467+
return false;
391468
}
392469

393470
void os_register_background_callback(void (*callback)(bool))
@@ -397,19 +474,19 @@ namespace pen
397474

398475
bool os_require_audio_reinit(bool reset)
399476
{
400-
477+
return false;
401478
}
402479

403480
// music
404481

405482
const music_item* music_get_items()
406483
{
407-
484+
return nullptr;
408485
}
409486

410487
music_file music_open_file(const music_item& item)
411488
{
412-
489+
return {};
413490
}
414491

415492
void music_close_file(const music_file& file)

core/put/source/dev_ui.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ namespace
6666

6767
for(auto& font : fonts)
6868
{
69-
const Str font_path = pen::os_path_for_resource(font.name.c_str());
69+
const Str font_path = font.name.c_str(); //pen::os_path_for_resource(font.name.c_str());
7070
config.MergeMode = font.merge;
7171

7272
if(font.range_min != 0 && font.range_max != 0)

0 commit comments

Comments
 (0)