In Android, what are window insets? - android

This sounds like a dumb question, and I'm sorry if it is, but I've searched around to get a visual representation of what they are and came up with nothing.
Here is what Android has to say about it:
WindowInsets are immutable and may be expanded to include more inset types in the future.
http://developer.android.com/reference/android/view/WindowInsets.html
Google images autocorrect it to window inserts...
Why would anyone work with these "insets"? Do they have anything to do with the navigation bar on mobile phones with no home physical keys?

Insets are areas of your view that you should not put elements, like behind the status bar or navigation bar. Think of them like paddings for the window.
If you want to draw behind them, like putting an image to the top that should be behind a translucent status bar, you will need to consume the window insets. In some views this is as easy as putting android:fitsSystemWindows=true, but in others you will have to override the onApplyWindowInsets method.
Usually the window insets for phones are the size of the height of the status bar as the top, the size of the navigation bar as the bottom and 0 as left and right. But It can be different, like in watches or phones with physical buttons.

They are some kind of colored margin (used in Android Wear).
They are used to create a padding from the main content to the actual border:
There are a few examples here.
This is an image with 2 insets: Circle/Squared.
They can also be used in other views to handle especial rendering requirements, like in a ScrollView: where to put the actual scroll can be defined with an insideInset as mentioned in this question.
<ScrollView
android:id="#+id/view2"
android:layout_width="100dip"
android:layout_height="120dip"
android:padding="8dip"
android:scrollbarStyle="insideInset"
android:background="#android:color/white"
android:overScrollMode="never">

You may use onApplyWindowInsets:
#Override
public void onApplyWindowInsets(WindowInsets insets) {
super.onApplyWindowInsets(insets);
mRound = insets.isRound();
}
to detect if wearable android device is round or square, then using that information draw appropriate application interface (with round or square background)

WindowInsets is a class that represents the so-called window insets. They're some kind of margins/paddings your content should have not to overlap unusable areas of the screen. As many people suggested, they can be used to detect whether an Android Wear device is round and handle that shape. However, the probably most common case of use is on mobile phones. Status and navigation bars are both part of the System UI, and thus they cover different rooms of the screen you should not place your content in.
An Activity, depending on the window flags set in, can either use the whole screen or be resized below the status bar and above the navigation bar (see WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN and WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS). So, if you set your activity not to handle window insets, you'll have to do it all by yourself. And you would use View.setOnApplyWindowInsetsListener method to let yourself notice whenever those insets change, and you would handle UI changes (e.g. set some padding) based on the values provided in the listener.

I wrote sample.
This repository can help to grasp android windows insets idea and Edge-To-Edge concept + we can detect keyboard without assumption that "keyboard should be more than X part of screen"

Related

How to set completely transparent navigation bar (NOT TRANSLUCENT) and keep receiving window inset updates

The image below is basically my goal, a completely transparent navigation bar (NOT TRANSLUCENT) and the content behind it keeps getting inset updates so it draws behind it, but does not get any UI covered by the navigation controls.
So far the only way possible to achieve the result in the image above is to set the flag FLAG_LAYOUT_NO_LIMITS to the activity. The problem is when that is done, the app no longer receives any insets whatsoever, with the exception of Gesture insets, if gesture navigation is enabled.
I've tried all the combinations I could think of, but so far I am completely unable to achieve 100% transparent navigation bar + window insets.
I assume that the reason why the navigation bar is not translucent when setting that flag is because the system window insets are now 0, as such the translucent area shrinks to 0 height, leaving the navigation controls without background.
I also tried setting
<item name="android:navigationBarColor">#android:color/transparent</item>
However, all this does is leave the navigation bar fully white and the content does not display behind it.
And I also had the following enabled and disabled for all the tests I conducted
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
I've researched high and above the Window Insets nightmare and there's one way to find the window insets via getWindow().getDecorView().getRootWindowInsets(), but then I will be falling to the problem of adding insets when they aren't needed (multi-window mode, for example) and I still won't get window inset updates, such as when the keyboard is opened.
I've watched ( #chris-banes ) Chris Banes' "Becoming a master window fitter", however this specific scenario is never covered.
Is this impossible? We can achieve this result for the status bar, but we will never be able to do the same for the navigation bar? If not, then how can this be achieved?
All I want is a 100% transparent (NOT TRANSLUCENT) navigation bar and the app keeps receiving the window insets with the expected values instead of 0 for all the values.
Chris Banes also has a more recent blog post, going through exactly what you are asking for:
https://medium.com/androiddevelopers/windowinsets-listeners-to-layouts-8f9ccc8fa4d1
In short, set the following system ui flags on the root view:
rootView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
To get the following result:
Then you can update the padding or margin of your view to make it available for touch events by adding an onApplyWindowInsetsListener:
bottomNav.setOnApplyWindowInsetsListener { view, insets ->
view.updatePadding(bottom = insets.systemWindowInsetBottom)
insets
}
For the full solution, I suggest you read the whole post, it's a good read and has helped me a lot.

What is scrim in collapsibletoolbarlayout?

I read collapsible toolbar layout on developers android. There is a term scrim used there. What is it?
Scrim: A thing that conceals or obscures something.
As per Android CollapsingToolbarLayout:
Content scrim: A full-bleed scrim which is show or hidden when the scroll position has hit a certain threshold. You can change this via setContentScrim(Drawable).
You can use drawable as a scrim on top of the CollapsingToolbarLayouts content when it has been scrolled sufficiently off screen.
app:contentScrim="YOUR_TOOLBAR_COLOR"
Status bar scrim: A scrim which is show or hidden behind the status bar when the scroll position has hit a certain threshold. You can change this via setStatusBarScrim(Drawable). This only works on LOLLIPOP devices when we set to fit system windows.
You can use drawable as a scrim for the status bar content when the CollapsingToolbarLayout has been scrolled sufficiently off screen.
app:statusBarScrim="YOUR_STATUSBAR_COLOR"
Hope this will help!
Here's what the material design docs say:
https://material.io/design/environment/surfaces.html#attributes
Scrims are temporary treatments that can be applied to Material surfaces for the purpose of making content on a surface less prominent. They help direct user attention to other parts of the screen, away from the surface receiving a scrim.
Scrims can be applied in a variety of ways, including:
Darkening or lightening the surface and its content
Reducing the opacity of the surface and its content
Multiple surfaces on a screen at a time can display scrims. Scrims can appear at any elevation, whether in the foreground or background.

UI screen design

I am working on an Android application and have to code up the following design for one of the screens:
(Ignore the yellow stuff, I have just masked the Logo and the App-specific information for now)
My question is: How do I design this particular type of screen? The top pane is akin to an ActionBar in Android. However, when any button on the top pane is hit, this custom "popup" having a rectangular form with a small arrow on top pointing towards the button is display and does not interrupt the current/main activity.
I have looked around, but still dont understand how to accomplish this.
Any thoughts? Thanks!
You can use the native Action Bar along with the icons.
The only problem is if you want to show them all at once.
Some icons may be hidden depending on the size of the phone.
As for the custom pop-up, the toast feature is available to do that.
It is quite easy to adjust the position of toasts and customise toasts :
Customisation of toasts: http://developer.android.com/guide/topics/ui/notifiers/toasts.html#CustomToastView
Changing postion of toasts: How to change position of Toast in Android?

How can I create this UI navigation control?

This is a picture of my phone (Android 2.1 with HKC Sense):
The bit that's got a red border around it is in the Clock app and the Media player on my phone. What is it called? Is it a standard Android interface control?
I've been trying to figure out how to get something like this for the past while and I'm not seeing anything immediately obvious.
I've seen a lot of people referring to the ActionBar or Split ActionBar, but that seems to be something that is anchored to the top. I need this to be at the bottom without any component on the top.
*please excuse
It's an actual pic of the phone, rather than a screenshot - the screenshot app I downloaded wouldn't work.
The fact that the pic was taken with an iPhone, and that the apple logo is clearly reflected in the pic.
You can use Split ActionBar
android:uiOptions="splitActionBarWhenNarrow"
And that will force the action bar items to be hosted on the bottom of the screen for narrow devices, mostly phones. When this flag is set, no components are hosted on the top of the ActionBar, unless you use tab navigation.
See example Image
Keep in mind though, that should you be displaying the layout on a non-narrow device, like a tablet, then the items will be attached to the top ActionBar.
Some other things to consider
Creating a custom view, which you can set to the bottom of the layout. The View would be a scrollable ListView per say, and you can add as many icons as you'd like to it. Here's an example. That would not be a standard nav pattern though.

Vertical Action Bar for Android

I want to display the Action Bar Vertically in my App.
I have found few examples for the Horizontal One, but not any for the Vertical One.
Can anyone please give me any example for the Vertical Action Bar.
Thanks,
David Brown
There's nothing in the Android UI design guide about a vertical ActionBar. But you might be able to coerce a similar effect by locking the display orientation, and then applying a rotation to the View in the content area. You also might be able to get somewhere by downloading the source code for ActionBarSherlock and implementing your own version of the ActionBar. But I don't recommend either of these solutions. If you're really that intent on putting actions on the side of your screen, I suggest either a small vertical LinearLayout, or implement one of the side navigation solutions as discussed in Android Facebook style slide.

Categories

Resources