blob: 6e459b22e6573fb8c4d7b3c255cdb29d5ecb0ee1 [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;
Jorim Jaggib7848b72018-12-28 14:38:21 +010026import static android.view.WindowInsetsController.APPEARANCE_LIGHT_SIDE_BARS;
27import static android.view.WindowInsetsController.APPEARANCE_LIGHT_TOP_BAR;
28import static android.view.WindowInsetsController.APPEARANCE_LOW_PROFILE_BARS;
Jorim Jaggi956ca412019-01-07 14:49:14 +010029import static android.view.WindowInsetsController.APPEARANCE_OPAQUE_SIDE_BARS;
30import static android.view.WindowInsetsController.APPEARANCE_OPAQUE_TOP_BAR;
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(
Jorim Jaggi956ca412019-01-07 14:49:14 +010046 mask = APPEARANCE_OPAQUE_TOP_BAR,
47 equals = APPEARANCE_OPAQUE_TOP_BAR,
48 name = "OPAQUE_TOP_BAR"),
49 @ViewDebug.FlagToString(
50 mask = APPEARANCE_OPAQUE_SIDE_BARS,
51 equals = APPEARANCE_OPAQUE_SIDE_BARS,
52 name = "OPAQUE_SIDE_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(
58 mask = APPEARANCE_LIGHT_TOP_BAR,
59 equals = APPEARANCE_LIGHT_TOP_BAR,
60 name = "LIGHT_TOP_BAR"),
61 @ViewDebug.FlagToString(
62 mask = APPEARANCE_LIGHT_SIDE_BARS,
63 equals = APPEARANCE_LIGHT_SIDE_BARS,
64 name = "LIGHT_SIDE_BARS")
65 })
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,
91 APPEARANCE_LIGHT_TOP_BAR);
92 appearance |= convertFlag(systemUiVisibility, SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR,
93 APPEARANCE_LIGHT_SIDE_BARS);
94 appearance |= convertNoFlag(systemUiVisibility,
95 STATUS_BAR_TRANSLUCENT | STATUS_BAR_TRANSPARENT, APPEARANCE_OPAQUE_TOP_BAR);
96 appearance |= convertNoFlag(systemUiVisibility,
97 NAVIGATION_BAR_TRANSLUCENT | NAVIGATION_BAR_TRANSPARENT,
98 APPEARANCE_OPAQUE_SIDE_BARS);
99 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}