[Android] Do not hardcode java const values (JNI)

This commit is contained in:
Jonathan De Wachter 2014-06-24 07:40:16 +02:00
parent ed7c80f6bb
commit d73418261b
2 changed files with 12 additions and 7 deletions

View File

@ -440,8 +440,15 @@ void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_
jobject objectDecorView = lJNIEnv->CallObjectMethod(objectWindow, methodGetDecorView); jobject objectDecorView = lJNIEnv->CallObjectMethod(objectWindow, methodGetDecorView);
jclass classView = lJNIEnv->FindClass("android/view/View"); jclass classView = lJNIEnv->FindClass("android/view/View");
jfieldID FieldSYSTEM_UI_FLAG_HIDE_NAVIGATION = lJNIEnv->GetStaticFieldID(classView, "SYSTEM_UI_FLAG_HIDE_NAVIGATION", "I");
jint SYSTEM_UI_FLAG_HIDE_NAVIGATION = lJNIEnv->GetStaticIntField(classView, FieldSYSTEM_UI_FLAG_HIDE_NAVIGATION);
jfieldID FieldSYSTEM_UI_FLAG_FULLSCREEN = lJNIEnv->GetStaticFieldID(classView, "SYSTEM_UI_FLAG_FULLSCREEN", "I");
jint SYSTEM_UI_FLAG_FULLSCREEN = lJNIEnv->GetStaticIntField(classView, FieldSYSTEM_UI_FLAG_FULLSCREEN);
jmethodID methodsetSystemUiVisibility = lJNIEnv->GetMethodID(classView, "setSystemUiVisibility", "(I)V"); jmethodID methodsetSystemUiVisibility = lJNIEnv->GetMethodID(classView, "setSystemUiVisibility", "(I)V");
lJNIEnv->CallVoidMethod(objectDecorView, methodsetSystemUiVisibility, (jint)(2 | 4)); lJNIEnv->CallVoidMethod(objectDecorView, methodsetSystemUiVisibility, SYSTEM_UI_FLAG_HIDE_NAVIGATION | SYSTEM_UI_FLAG_FULLSCREEN);
// Initialize the display // Initialize the display
eglInitialize(states->display, NULL, NULL); eglInitialize(states->display, NULL, NULL);

View File

@ -152,13 +152,11 @@ void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_
jclass ClassPackageManager = lJNIEnv->FindClass("android/content/pm/PackageManager"); jclass ClassPackageManager = lJNIEnv->FindClass("android/content/pm/PackageManager");
//jfieldID FieldGET_META_DATA = lJNIEnv->GetStaticFieldID(ClassPackageManager, "GET_META_DATA", "L"); jfieldID FieldGET_META_DATA = lJNIEnv->GetStaticFieldID(ClassPackageManager, "GET_META_DATA", "I");
//jobject GET_META_DATA = lJNIEnv->GetStaticObjectField(ClassPackageManager, FieldGET_META_DATA); jint GET_META_DATA = lJNIEnv->GetStaticIntField(ClassPackageManager, FieldGET_META_DATA);
// getActivityInfo(getIntent().getComponent(), PackageManager.GET_META_DATA) -> ActivityInfo object
jmethodID MethodGetActivityInfo = lJNIEnv->GetMethodID(ClassPackageManager, "getActivityInfo", "(Landroid/content/ComponentName;I)Landroid/content/pm/ActivityInfo;");
// todo: do not hardcode the GET_META_DATA integer value but retrieve it instead jmethodID MethodGetActivityInfo = lJNIEnv->GetMethodID(ClassPackageManager, "getActivityInfo", "(Landroid/content/ComponentName;I)Landroid/content/pm/ActivityInfo;");
jobject ObjectActivityInfo = lJNIEnv->CallObjectMethod(ObjectPackageManager, MethodGetActivityInfo, ObjectComponentName, (jint)128); jobject ObjectActivityInfo = lJNIEnv->CallObjectMethod(ObjectPackageManager, MethodGetActivityInfo, ObjectComponentName, GET_META_DATA);
// Load our libraries in reverse order // Load our libraries in reverse order
loadLibrary("c++_shared", lJNIEnv, ObjectActivityInfo); loadLibrary("c++_shared", lJNIEnv, ObjectActivityInfo);