27 #include <android/log.h> 28 #include <android_native_app_glue.h> 31 ((void)__android_log_print( \ 32 ANDROID_LOG_INFO, ndk_helper::JNIHelper::GetInstance()->GetAppName(), \ 35 ((void)__android_log_print( \ 36 ANDROID_LOG_WARN, ndk_helper::JNIHelper::GetInstance()->GetAppName(), \ 39 ((void)__android_log_print( \ 40 ANDROID_LOG_ERROR, ndk_helper::JNIHelper::GetInstance()->GetAppName(), \ 62 std::string app_name_;
64 ANativeActivity* activity_;
65 jobject jni_helper_java_ref_;
66 jclass jni_helper_java_class_;
68 jstring GetExternalFilesDirJString(JNIEnv* env);
69 jclass RetrieveClass(JNIEnv* jni,
const char* class_name);
73 JNIHelper(
const JNIHelper& rhs);
74 JNIHelper& operator=(
const JNIHelper& rhs);
76 std::string app_label_;
81 mutable std::mutex mutex_;
86 jobject CallObjectMethod(
const char* strMethodName,
const char* strSignature,
88 void CallVoidMethod(
const char* strMethodName,
const char* strSignature, ...);
93 static void DetachCurrentThreadDtor(
void* p) {
94 LOGI(
"detached current thread");
95 ANativeActivity* activity = (ANativeActivity*)p;
96 activity->vm->DetachCurrentThread();
112 static void Init(ANativeActivity* activity,
const char* helper_class_name);
128 static void Init(ANativeActivity* activity,
const char* helper_class_name,
129 const char* native_soname);
137 static JNIHelper* GetInstance();
155 bool ReadFile(
const char* file_name, std::vector<uint8_t>* buffer_ref);
176 uint32_t LoadTexture(
const char* file_name, int32_t* outWidth =
nullptr,
177 int32_t* outHeight =
nullptr,
bool* hasAlpha =
nullptr);
193 uint32_t LoadCubemapTexture(
const char* file_name,
const int32_t face,
194 const int32_t miplevel,
const bool sRGB,
195 int32_t* outWidth =
nullptr,
196 int32_t* outHeight =
nullptr,
197 bool* hasAlpha =
nullptr);
211 jobject LoadImage(
const char* file_name, int32_t* outWidth =
nullptr,
212 int32_t* outHeight =
nullptr,
bool* hasAlpha =
nullptr);
224 std::string ConvertString(
const char* str,
const char* encode);
230 std::string GetExternalFilesDir();
239 std::string GetStringResource(
const std::string& resourceName);
250 int32_t GetNativeAudioBufferSize();
260 int32_t GetNativeAudioSampleRate();
268 const char* GetAppName()
const {
return app_name_.c_str(); }
276 const char* GetAppLabel()
const {
return app_label_.c_str(); }
286 void RunOnUiThread(std::function<
void()> callback);
293 JNIEnv* AttachCurrentThread() {
295 if (activity_->vm->GetEnv((
void**)&env, JNI_VERSION_1_4) == JNI_OK)
297 activity_->vm->AttachCurrentThread(&env, NULL);
298 pthread_key_create((int32_t*)activity_, DetachCurrentThreadDtor);
302 void DetachCurrentThread() {
303 activity_->vm->DetachCurrentThread();
312 void DeleteObject(jobject obj);
317 jobject CreateObject(
const char* class_name);
318 jobject CallObjectMethod(jobject
object,
const char* strMethodName,
319 const char* strSignature, ...);
320 void CallVoidMethod(jobject
object,
const char* strMethodName,
321 const char* strSignature, ...);
322 float CallFloatMethod(jobject
object,
const char* strMethodName,
323 const char* strSignature, ...);
324 int32_t CallIntMethod(jobject
object,
const char* strMethodName,
325 const char* strSignature, ...);
326 bool CallBooleanMethod(jobject
object,
const char* strMethodName,
327 const char* strSignature, ...);
Definition: gestureDetector.h:32