Jorim Jaggi | b7848b7 | 2018-12-28 14:38:21 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.view; |
| 18 | |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 19 | import static android.view.View.NAVIGATION_BAR_TRANSLUCENT; |
| 20 | import static android.view.View.NAVIGATION_BAR_TRANSPARENT; |
| 21 | import static android.view.View.STATUS_BAR_TRANSLUCENT; |
| 22 | import static android.view.View.STATUS_BAR_TRANSPARENT; |
| 23 | import static android.view.View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; |
| 24 | import static android.view.View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 25 | import static android.view.View.SYSTEM_UI_FLAG_LOW_PROFILE; |
Jorim Jaggi | b7848b7 | 2018-12-28 14:38:21 +0100 | [diff] [blame] | 26 | import static android.view.WindowInsetsController.APPEARANCE_LIGHT_SIDE_BARS; |
| 27 | import static android.view.WindowInsetsController.APPEARANCE_LIGHT_TOP_BAR; |
| 28 | import static android.view.WindowInsetsController.APPEARANCE_LOW_PROFILE_BARS; |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 29 | import static android.view.WindowInsetsController.APPEARANCE_OPAQUE_SIDE_BARS; |
| 30 | import static android.view.WindowInsetsController.APPEARANCE_OPAQUE_TOP_BAR; |
Jorim Jaggi | b7848b7 | 2018-12-28 14:38:21 +0100 | [diff] [blame] | 31 | import static android.view.WindowInsetsController.BEHAVIOR_SHOW_BARS_BY_SWIPE; |
| 32 | import static android.view.WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE; |
| 33 | |
| 34 | import android.view.WindowInsetsController.Appearance; |
| 35 | import 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 | */ |
| 42 | public class InsetsFlags { |
| 43 | |
| 44 | @ViewDebug.ExportedProperty(flagMapping = { |
| 45 | @ViewDebug.FlagToString( |
Jorim Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 46 | 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 Jaggi | b7848b7 | 2018-12-28 14:38:21 +0100 | [diff] [blame] | 53 | @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 Jaggi | 956ca41 | 2019-01-07 14:49:14 +0100 | [diff] [blame] | 79 | |
| 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 Jaggi | b7848b7 | 2018-12-28 14:38:21 +0100 | [diff] [blame] | 119 | } |