blob: 385b0bf960ef0188d4a6d11e4431e922e067c1a9 [file] [log] [blame]
Jorim Jaggib7848b72018-12-28 14:38:21 +01001/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.view;
18
Jorim Jaggi956ca412019-01-07 14:49:14 +010019import static android.view.View.NAVIGATION_BAR_TRANSLUCENT;
20import static android.view.View.NAVIGATION_BAR_TRANSPARENT;
21import static android.view.View.STATUS_BAR_TRANSLUCENT;
22import static android.view.View.STATUS_BAR_TRANSPARENT;
23import static android.view.View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
24import static android.view.View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
25import static android.view.View.SYSTEM_UI_FLAG_LOW_PROFILE;
Tiger Huang332793b2019-10-29 23:21:27 +080026import static android.view.WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS;
27import static android.view.WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS;
Jorim Jaggib7848b72018-12-28 14:38:21 +010028import static android.view.WindowInsetsController.APPEARANCE_LOW_PROFILE_BARS;
Tiger Huang332793b2019-10-29 23:21:27 +080029import static android.view.WindowInsetsController.APPEARANCE_OPAQUE_NAVIGATION_BARS;
30import static android.view.WindowInsetsController.APPEARANCE_OPAQUE_STATUS_BARS;
Jorim Jaggib7848b72018-12-28 14:38:21 +010031import static android.view.WindowInsetsController.BEHAVIOR_SHOW_BARS_BY_SWIPE;
32import static android.view.WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE;
33
34import android.view.WindowInsetsController.Appearance;
35import android.view.WindowInsetsController.Behavior;
36
37/**
38 * Contains the information about {@link Appearance} and {@link Behavior} of system windows which
39 * can produce insets. This is for carrying the request from a client to the system server.
40 * @hide
41 */
42public class InsetsFlags {
43
44 @ViewDebug.ExportedProperty(flagMapping = {
45 @ViewDebug.FlagToString(
Tiger Huang332793b2019-10-29 23:21:27 +080046 mask = APPEARANCE_OPAQUE_STATUS_BARS,
47 equals = APPEARANCE_OPAQUE_STATUS_BARS,
48 name = "OPAQUE_STATUS_BARS"),
Jorim Jaggi956ca412019-01-07 14:49:14 +010049 @ViewDebug.FlagToString(
Tiger Huang332793b2019-10-29 23:21:27 +080050 mask = APPEARANCE_OPAQUE_NAVIGATION_BARS,
51 equals = APPEARANCE_OPAQUE_NAVIGATION_BARS,
52 name = "OPAQUE_NAVIGATION_BARS"),
Jorim Jaggib7848b72018-12-28 14:38:21 +010053 @ViewDebug.FlagToString(
54 mask = APPEARANCE_LOW_PROFILE_BARS,
55 equals = APPEARANCE_LOW_PROFILE_BARS,
56 name = "LOW_PROFILE_BARS"),
57 @ViewDebug.FlagToString(
Tiger Huang332793b2019-10-29 23:21:27 +080058 mask = APPEARANCE_LIGHT_STATUS_BARS,
59 equals = APPEARANCE_LIGHT_STATUS_BARS,
60 name = "LIGHT_STATUS_BARS"),
Jorim Jaggib7848b72018-12-28 14:38:21 +010061 @ViewDebug.FlagToString(
Tiger Huang332793b2019-10-29 23:21:27 +080062 mask = APPEARANCE_LIGHT_NAVIGATION_BARS,
63 equals = APPEARANCE_LIGHT_NAVIGATION_BARS,
64 name = "LIGHT_NAVIGATION_BARS")
Jorim Jaggib7848b72018-12-28 14:38:21 +010065 })
66 public @Appearance int appearance;
67
68 @ViewDebug.ExportedProperty(flagMapping = {
69 @ViewDebug.FlagToString(
70 mask = BEHAVIOR_SHOW_BARS_BY_SWIPE,
71 equals = BEHAVIOR_SHOW_BARS_BY_SWIPE,
72 name = "SHOW_BARS_BY_SWIPE"),
73 @ViewDebug.FlagToString(
74 mask = BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE,
75 equals = BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE,
76 name = "SHOW_TRANSIENT_BARS_BY_SWIPE")
77 })
78 public @Behavior int behavior;
Jorim Jaggi956ca412019-01-07 14:49:14 +010079
80 /**
81 * Converts system UI visibility to appearance.
82 *
83 * @param systemUiVisibility the system UI visibility to be converted.
84 * @return the outcome {@link Appearance}
85 */
86 public static @Appearance int getAppearance(int systemUiVisibility) {
87 int appearance = 0;
88 appearance |= convertFlag(systemUiVisibility, SYSTEM_UI_FLAG_LOW_PROFILE,
89 APPEARANCE_LOW_PROFILE_BARS);
90 appearance |= convertFlag(systemUiVisibility, SYSTEM_UI_FLAG_LIGHT_STATUS_BAR,
Tiger Huang332793b2019-10-29 23:21:27 +080091 APPEARANCE_LIGHT_STATUS_BARS);
Jorim Jaggi956ca412019-01-07 14:49:14 +010092 appearance |= convertFlag(systemUiVisibility, SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR,
Tiger Huang332793b2019-10-29 23:21:27 +080093 APPEARANCE_LIGHT_NAVIGATION_BARS);
Jorim Jaggi956ca412019-01-07 14:49:14 +010094 appearance |= convertNoFlag(systemUiVisibility,
Tiger Huang332793b2019-10-29 23:21:27 +080095 STATUS_BAR_TRANSLUCENT | STATUS_BAR_TRANSPARENT, APPEARANCE_OPAQUE_STATUS_BARS);
Jorim Jaggi956ca412019-01-07 14:49:14 +010096 appearance |= convertNoFlag(systemUiVisibility,
97 NAVIGATION_BAR_TRANSLUCENT | NAVIGATION_BAR_TRANSPARENT,
Tiger Huang332793b2019-10-29 23:21:27 +080098 APPEARANCE_OPAQUE_NAVIGATION_BARS);
Jorim Jaggi956ca412019-01-07 14:49:14 +010099 return appearance;
100 }
101
102 /**
103 * Converts the system UI visibility into an appearance flag if the given visibility contains
104 * the given system UI flag.
105 */
106 private static @Appearance int convertFlag(int systemUiVisibility, int systemUiFlag,
107 @Appearance int appearance) {
108 return (systemUiVisibility & systemUiFlag) != 0 ? appearance : 0;
109 }
110
111 /**
112 * Converts the system UI visibility into an appearance flag if the given visibility doesn't
113 * contains the given system UI flag.
114 */
115 private static @Appearance int convertNoFlag(int systemUiVisibility, int systemUiFlag,
116 @Appearance int appearance) {
117 return (systemUiVisibility & systemUiFlag) == 0 ? appearance : 0;
118 }
Jorim Jaggib7848b72018-12-28 14:38:21 +0100119}