2012-07-31, 15:14
Hi,
I have written a JNI method call to call the above. It hides the nav bar on my nexus 7. It of course pops back up on touch input. I am looking for a pointer on where to look to make this call when media is playing. I find the bar annoying during media playback and would like to auto hide it.
My first go at JNI too, so if any one wants to critique my code here it is, will do a pull request when I have done, if I can get up to scratch):
void CXBMCApp::SetSystemUiVisibility(int visibility)
{
if (m_activity == NULL)
return;
JNIEnv *env = NULL;
AttachCurrentThread(&env);
jobject oActivity = m_activity->clazz;
jclass cActivity = env->GetObjectClass(oActivity);
android_printf("CXBMCApp::HideAndroidNavigationBar Looking for: setSystemUiVisibility");
jmethodID MethodGetWindow = env->GetMethodID(cActivity, "getWindow", "()Landroid/view/Window;");
jobject lWindow = env->CallObjectMethod(oActivity, MethodGetWindow);
jclass cWindow = env->FindClass("android/view/Window");
jclass cView = env->FindClass("android/view/View");
jmethodID MethodGetDecorView = env->GetMethodID(cWindow, "getDecorView", "()Landroid/view/View;");
jobject lDecorView = env->CallObjectMethod(lWindow, MethodGetDecorView);
jmethodID MethodSetSystemUiVisibility = env->GetMethodID(cView, "setSystemUiVisibility", "(I)V");
jint jVisibility = visibility;
env->CallVoidMethod(lDecorView, MethodSetSystemUiVisibility, jVisibility);
//cleanup
env->DeleteLocalRef(oActivity);
env->DeleteLocalRef(cActivity);
env->DeleteLocalRef(lWindow);
env->DeleteLocalRef(cWindow);
env->DeleteLocalRef(cView);
env->DeleteLocalRef(lDecorView);
DetachCurrentThread();
}
I have written a JNI method call to call the above. It hides the nav bar on my nexus 7. It of course pops back up on touch input. I am looking for a pointer on where to look to make this call when media is playing. I find the bar annoying during media playback and would like to auto hide it.
My first go at JNI too, so if any one wants to critique my code here it is, will do a pull request when I have done, if I can get up to scratch):
void CXBMCApp::SetSystemUiVisibility(int visibility)
{
if (m_activity == NULL)
return;
JNIEnv *env = NULL;
AttachCurrentThread(&env);
jobject oActivity = m_activity->clazz;
jclass cActivity = env->GetObjectClass(oActivity);
android_printf("CXBMCApp::HideAndroidNavigationBar Looking for: setSystemUiVisibility");
jmethodID MethodGetWindow = env->GetMethodID(cActivity, "getWindow", "()Landroid/view/Window;");
jobject lWindow = env->CallObjectMethod(oActivity, MethodGetWindow);
jclass cWindow = env->FindClass("android/view/Window");
jclass cView = env->FindClass("android/view/View");
jmethodID MethodGetDecorView = env->GetMethodID(cWindow, "getDecorView", "()Landroid/view/View;");
jobject lDecorView = env->CallObjectMethod(lWindow, MethodGetDecorView);
jmethodID MethodSetSystemUiVisibility = env->GetMethodID(cView, "setSystemUiVisibility", "(I)V");
jint jVisibility = visibility;
env->CallVoidMethod(lDecorView, MethodSetSystemUiVisibility, jVisibility);
//cleanup
env->DeleteLocalRef(oActivity);
env->DeleteLocalRef(cActivity);
env->DeleteLocalRef(lWindow);
env->DeleteLocalRef(cWindow);
env->DeleteLocalRef(cView);
env->DeleteLocalRef(lDecorView);
DetachCurrentThread();
}