Hide Navigation Bar when starting the Daydream service? - android

I am adding the Dreamservice to my app, where I would like to play a video during the dream. Roughly the same code I use to hide the navigation control during my Main Activity
// Hide navigation controls
View v = findViewById(R.id.dream);
v.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
causes the Daydream to crash. Looking at some other Daydreams, it seems like none of them hide the bar either. Is it possible to do this? Otherwise, the video I am playing during the Daydream isn't able to center properly.

Try a little different approach.
View view = getWindow().getDecorView();
view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | view.getSystemUiVisibility());
Any of getWindow() or getDecorView() might return null, especially when not dreaming.
Keep the docs in mind. You might need to reapply this flag regularly. If the DreamService is interactive, it will not dismiss on the first input event either, just on the second.

Related

Navigation Bar won't re-hide when switching back to the app from another one and also when I take a screenshot?

So I am working on an app which has full screen. The code does work excellently. But when I do switch to any other app and come back to it, the navigation bar and status bar both won't hide. This also happens when I take a screenshot.
Here is a preview:
Coming back, here is what I have coded:
private fun funcFullScreen() {
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_IMMERSIVE
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_FULLSCREEN
or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)
}
And I just simply call the function like this funcFullScreen().
What I have tried?
1] androidFocusableInTouchMode="true"
2] I also tried adding onWindowFocusChange thing but that gave me another headache, the navigation bar will appear for a second or two when I switch the activities in my app itself. And fixing that seems difficult, I've already tried every possible solution for that available on the internet.
Any way to solve this? By the I'm fine with either Java or Kotlin, my app is made up from both (some activities in Java while others in Kotlin) and both suffer from this issue.
3] Also tried adding the code in onResume, this works when I switch back from another app but not when I take a screenshot.
So basically I think you are writing this all code in onCreate() method of that activity, When you go to another app, it's activity screen by default show status bar and navigation bar, and you again come back then you don't get a callback in onCreate(), instead, get it in onResume(), So you need to move your code in OnResume() from onCreate() so that it gets called when you come back again to this screen.

Android 4 overlay/replace/hide soft buttons

I'm currently working on an app for blind people. What I need is to prevent users from accidentally going outside of my app, so I'm trying to overlay/replace/hide soft buttons in Android 4. I know this must be possible because it is used for example in MXPlayer (you can "lock" screen when playing video).
I've tried to override all three buttons (back,home,recent apps). No problem with back and home, but I couldn't figure out how to override(disable) recent apps. I've tried solution described here without success.
Next idea was to overlay the entire screen. I've successfully created system overlay mentioned in this question, but I didn't find out how to overlay my soft buttons.
Do you have any idea how to solve this problem without rooting the phone and using custom ROM?
edit: I've also tried hiding the buttons with SYSTEM_UI_FLAG_LOW_PROFILE(turns buttons into dots) and SYSTEM_UI_FLAG_HIDE_NAVIGATION(hides buttons till next touch). Unfortunately this also doesn't solve my problem because after touch buttons work as usual. Maybe there's a way how to catch "unhiding" a override showing them again?
From Android docs :
The SYSTEM_UI_FLAG_LOW_PROFILE flag replaces the STATUS_BAR_HIDDEN flag. When set, this flag enables “low profile" mode for the system bar or navigation bar. Navigation buttons dim and other elements in the system bar also hide. Enabling this is useful for creating more immersive games without distraction for the system navigation buttons.
The SYSTEM_UI_FLAG_VISIBLE flag replaces the STATUS_BAR_VISIBLE flag to request the system bar or navigation bar be visible.
The SYSTEM_UI_FLAG_HIDE_NAVIGATION is a new flag that requests the navigation bar hide completely. Be aware that this works only for the navigation bar used by some handsets (it does not hide the system bar on tablets). The navigation bar returns to view as soon as the system receives user input. As such, this mode is useful primarily for video playback or other cases in which the whole screen is needed but user input is not required.

android full screen mode(ICS), first touch shows the navigation bar

In my video play app, I use this flag: SYSTEM_UI_FLAG_HIDE_NAVIGATION to make the navigation bar disappear, but when I touch the screen, the navigation bar appears, after the first touch, my touch events and other events work fine.
My question is how can I take over the first touch?
You can't really take over the first event. You could implement View.OnSystemUiVisibilityChangeListener and be notified when the navigation bar is shown or hidden again, and then depending on its current state do what you wanted on the first touch, if possible.
However, there is no way you can completely take over the first touch, as stated in the documentation for SYSTEM_UI_FLAG_HIDE_NAVIGATION:
There is a limitation: because navigation controls are so important, the least user interaction will cause them to reappear immediately. When this happens, both this flag and SYSTEM_UI_FLAG_FULLSCREEN will be cleared automatically, so that both elements reappear at the same time.
For anyone coming across this post, if your intention is to hide the navigation/status bar and not have it come back up when you touch the screen, take a look at the different "immersive" configurations as described here: https://developer.android.com/training/system-ui/immersive
for example:
currentActivity?.window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or
View.SYSTEM_UI_FLAG_FULLSCREEN or
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
That would effectively put your screen in "Full Screen" Mode regardless of any interaction the user has with the screen
To show the navigation/status bar again, simply change it back to:
currentActivity?.window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE

Using SystemUiHider to keep the navigation bar hidden

In older versions of Android, it was necessary to use: android:theme="#android:style/Theme.NoTitleBar.Fullscreen" in the manifest to make the title bar disappear.
In the newer ADT versions, I have noticed a SystemUiHider class, which lets you make calls to it's hide() method to remove not only the title bar, but also the action bar and navigation bar.
I am trying to write a fullscreen app, that I would like to stay full screen (for a kiosk implementation), unless a small hidden button is pressed.
I've tried taking the standard FullscreenActivity (generated from the new android project wizard), and prevent the UI from reappearing in a number of ways:
Making calls to mSystemUiHider.hide() in the setOnVisibilityChangeListener (to try and immediately hide the UI when it detects a change in visibility)
Setting: AUTO_HIDE_DELAY_MILLIS = 0 (to try and immediately hide it if it is visible)
Preventing the call to mSystemUiHider.show(); within the onClick method of the contentView.setOnClickListener (to prevent it from being shown)
I have also seen the setSystemUiVisibility example in the docs for android.view (again to try and hide it immediately if shown or visibility is changed)
None of them seem to work (Android defaults to the Low Profile Mode for the Navigation Bar when any of these are tried.
I understand that they probably don't want developers doing what I'm trying to do, but I was hoping that I could extend SystemUiHider (and/or SystemUiHiderBase) and override the show() methods to essentially not show unless passed a true flag. I can't seem to find any documentation on either of these classes (perhaps because they're utility classes?).
Any interaction with the device brings back the navigation bar.
https://developer.android.com/reference/android/view/View.html#SYSTEM_UI_FLAG_HIDE_NAVIGATION

How do I implement a slide-out drawer on the Android's call screen?

The Android app Thrutu puts a drawer on top of the in call screen which has several functions and only takes up a fraction of the screen. The call control buttons below still are fully functional. Even a transparent activity would not allow this behaviour. Any idea on how to implement this?
The trick to making the underlying buttons work is to implement the UI using a Service rather than an Activity, make the Window you add (using WindowManager.addView) one of the higher-priority types (e.g. TYPE_PHONE), then use FLAG_NOT_TOUCH_MODAL.
I think you need android.permission.SYSTEM_ALERT_WINDOW.
Take a look at How to display a fullscreen TYPE_SYSTEM_ALERT window? and in particular Creating a system overlay where the home buttons still work?

Categories

Resources