Auto-hide nav bar on Android App( NDK)

Started by
9 comments, last by Nanoha 8 years, 3 months ago

I am attempting to have the nav bar auto hide when my app hasn't been touched for a few moments. For example, when I look at a photo I can click it and that makes the photo app hide all the bars until you touch it again. I would like that behaviour. SimCity BuiltIt has similar behaviour but you have to drag the bar back on (I wouldn't mind that behaviour). I am struggling to even know where to start.

I found this http://developer.android.com/training/system-ui/navigation.html which explains how to do it but that's using Java and I am using c++/NDK and I can't find any similar functions and Google is less than helpful in this regards.

I checked through some of the Android headers and came across this:



ACONFIGURATION_NAVHIDDEN_ANY = 0x0000,
ACONFIGURATION_NAVHIDDEN_NO = 0x0001,
ACONFIGURATION_NAVHIDDEN_YES = 0x0002,

/**
* Set the current nav hidden in the configuration.
*/
void AConfiguration_setNavHidden(AConfiguration* config, int32_t navHidden);

I trief setting it to hidden but I saw no change. It doesn't help that I don't get access to the config until after the app is created (it is passed in to main). I can't see anything in the manifest options that mimics the behaviour either.

Is there a solution to this?

My app renders MandelbrotSet images so I want to be able to support screenshots (which it does automatically) but it has the nav bar in them. If I could auto crop or override the screenshot behaviour that would also work. I think it would be possible to render to texture and save as an image but I ideally want to avoid anything that means my App needs permissions.

I've attached a screenshot to show what I mean.

Thanks

Interested in Fractals? Check out my App, Fractal Scout, free on the Google Play store.

Advertisement

i believe you are using ogles, anyway theres a thing you need to setup in the i think AndroidManifest.xml

android:theme="@android:style/Theme.NoTitleBar.Fullscreen" i found that on the internet cant verify that.

i believe you are using ogles, anyway theres a thing you need to setup in the i think AndroidManifest.xml

android:theme="@android:style/Theme.NoTitleBar.Fullscreen" i found that on the internet cant verify that.

Thanks for the response. I am already using that and unfortunately that just gets rid of the top bar, rather than the bottom (nav bar). I do need the bottom bar as I use the back button but I would like it to auto hide itself.

Interested in Fractals? Check out my App, Fractal Scout, free on the Google Play store.

then theres something need to be set during window initialization i think, anyway are you using emulator or are you testing on device? if this is on emulator then you can disable uch bar in emulator settings, if not then (even when i never saw a phone without external those three buttons) maybe try to place there your own 'buttons'?

then theres something need to be set during window initialization i think, anyway are you using emulator or are you testing on device? if this is on emulator then you can disable uch bar in emulator settings, if not then (even when i never saw a phone without external those three buttons) maybe try to place there your own 'buttons'?

I am using 2 devices, Nexus 5 and some other phone that I can't recall the name of. Neither have real navigation buttons, they use part of the screen for the buttons but many full screen things hide those buttons (similar to how auto hide works on windows for the task bar).

I can't actually put my own buttons in that spot since I don't have access to that area to render on without hiding that nav bar but it is certainly an idea I might look into.

I've certainly seen how to do it with a Java app (one of my links showed this) but I can't see how it translated into a native app :(.

Interested in Fractals? Check out my App, Fractal Scout, free on the Google Play store.

nanoha maybe you should make a hybrid java/c++ application so opengl window initialization and touchpad input will be called in java (for touch input you will call c++ functions from java) and for ogl window initialization you will call something liek glinit in c++ from java. that would make few things alot easier.

since noone can find any info about doing that in c++ it seems that its java related api and you cant use that thing in c++, however you could search through ndk folder pharse like 'navigation' (search in file contents) maybe theres a header, with a function like hidenavbar or sth like this.

you could also try android dev forum on google

http://developer.android.com/support.html

https://groups.google.com/forum/#!forum/android-ndk

if you get an answer you could write it back here.


nanoha maybe you should make a hybrid java/c++ application so opengl window initialization and touchpad input will be called in java (for touch input you will call c++ functions from java) and for ogl window initialization you will call something liek glinit in c++ from java. that would make few things alot easier

That's not a bad idea, might try that.

I did search through the headers and all I could find was the parts I posted.

Interested in Fractals? Check out my App, Fractal Scout, free on the Google Play store.

yeah if you go that way i maybe will be able to help you if you use eclipse, if not, then i don't know how to config the project. and actually i have no idea if communication with java > c++ is the same on all IDEs maybe someone else could straight that.

the basic idea is to create a java class like lets name it render wrapper that extends glsurfaceview, (you create main activity in java, you call there that glsurfview initialization and you create the opengl context, then you create some kind of main header file (its good to create cpp file aswell) where you put your native code (dont worry its just something liek this:

note this is pseudo code i think my notebook will be repaired (where i have my android project) on feb 01 (2016 :P)

java code

class renverwrapper extends glsurfaceview

public native void override oncreate() { somekindoffunctionname() };

main.h

#include "game.h"

void InitializeOpenGL()

{

call openglinitialization from game.h

}

extern "C" {

jnivoid somekindoffunctionname_ble_bleble(jnienv * flflf)

{

InitializeOpenGL();

}

}

some kind of crap like that.

Well it took me a long time but I've done it!


void AutoHideNavBar(struct android_app* state)
{
	JNIEnv* env;
	state->activity->vm->AttachCurrentThread(&env, NULL);

	jclass activityClass = env->FindClass("android/app/NativeActivity");
	jmethodID getWindow = env->GetMethodID(activityClass, "getWindow", "()Landroid/view/Window;");

	jclass windowClass = env->FindClass("android/view/Window");
	jmethodID getDecorView = env->GetMethodID(windowClass, "getDecorView", "()Landroid/view/View;");

	jclass viewClass = env->FindClass("android/view/View");
	jmethodID setSystemUiVisibility = env->GetMethodID(viewClass, "setSystemUiVisibility", "(I)V");

	jobject window = env->CallObjectMethod(state->activity->clazz, getWindow);

	jobject decorView = env->CallObjectMethod(window, getDecorView);

	jfieldID flagFullscreenID = env->GetStaticFieldID(viewClass, "SYSTEM_UI_FLAG_FULLSCREEN", "I");
	jfieldID flagHideNavigationID = env->GetStaticFieldID(viewClass, "SYSTEM_UI_FLAG_HIDE_NAVIGATION", "I");

	int flagFullscreen = env->GetStaticIntField(viewClass, flagFullscreenID);
	int flagHideNavigation = env->GetStaticIntField(viewClass, flagHideNavigationID);

	int flag = flagFullscreen | flagHideNavigation;

	env->CallVoidMethod(decorView, setSystemUiVisibility, flag);

	state->activity->vm->DetachCurrentThread();
}

It's still not quite complete, there's no error checking for one.. but it's a start.

Interested in Fractals? Check out my App, Fractal Scout, free on the Google Play store.

this is a great piece of code

This topic is closed to new replies.

Advertisement