mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-04 06:06:17 +00:00
android: Add support for casting Context to Activity
This commit is contained in:
parent
43e0206abc
commit
65a7b490a8
|
@ -6,7 +6,7 @@ set(ANDROID_SOURCE_FILES
|
|||
android/android_ahardwarebuffer_allocator.h
|
||||
android/android_custom_surface.cpp
|
||||
android/android_custom_surface.h
|
||||
android/android_globals.c
|
||||
android/android_globals.cpp
|
||||
android/android_globals.h
|
||||
android/android_load_class.cpp
|
||||
android/android_load_class.hpp
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "android_globals.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <wrap/android.app.h>
|
||||
|
||||
/*!
|
||||
* @todo Do we need locking here? Do we need to create global refs for the
|
||||
|
@ -17,11 +18,11 @@
|
|||
*/
|
||||
static struct
|
||||
{
|
||||
struct _JavaVM *vm;
|
||||
void *activity;
|
||||
void *context;
|
||||
struct _ANativeWindow *window;
|
||||
} android_globals = {NULL, NULL, NULL};
|
||||
struct _JavaVM *vm = nullptr;
|
||||
void *activity = nullptr;
|
||||
void *context = nullptr;
|
||||
struct _ANativeWindow *window = nullptr;
|
||||
} android_globals;
|
||||
|
||||
void
|
||||
android_globals_store_vm_and_activity(struct _JavaVM *vm, void *activity)
|
||||
|
@ -33,11 +34,21 @@ android_globals_store_vm_and_activity(struct _JavaVM *vm, void *activity)
|
|||
void
|
||||
android_globals_store_vm_and_context(struct _JavaVM *vm, void *context)
|
||||
{
|
||||
|
||||
android_globals.vm = vm;
|
||||
android_globals.context = context;
|
||||
if (android_globals_is_instance_of_activity(vm, context)) {
|
||||
android_globals.activity = context;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
android_globals_is_instance_of_activity(struct _JavaVM *vm, void *obj)
|
||||
{
|
||||
jni::init(vm);
|
||||
|
||||
auto activity_cls = jni::Class(wrap::android::app::Activity::getTypeName());
|
||||
return JNI_TRUE == jni::env()->IsInstanceOf((jobject)obj, activity_cls.getHandle());
|
||||
}
|
||||
void
|
||||
android_globals_store_window(struct _ANativeWindow *window)
|
||||
{
|
|
@ -34,6 +34,13 @@ android_globals_store_vm_and_activity(struct _JavaVM *vm, void *activity);
|
|||
void
|
||||
android_globals_store_vm_and_context(struct _JavaVM *vm, void *context);
|
||||
|
||||
|
||||
/*!
|
||||
* Is the provided jobject an instance of android.app.Activity?
|
||||
*/
|
||||
bool
|
||||
android_globals_is_instance_of_activity(struct _JavaVM *vm, void *obj);
|
||||
|
||||
/*!
|
||||
* Retrieve the Java VM pointer previously stored, if any.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue