xref: /aosp_15_r20/cts/tests/tests/systemui/src/android/systemui/cts/LightBarActivity.java (revision b7c941bb3fa97aba169d73cee0bed2de8ac964bf)
1 /*
2  * Copyright (C) 2015 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 package android.systemui.cts;
17 
18 import static android.view.WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS;
19 import static android.view.WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS;
20 import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
21 
22 import android.os.Bundle;
23 import android.view.View;
24 import android.view.WindowInsetsController;
25 
26 /**
27  * An activity that exercises SYSTEM_UI_FLAG_LIGHT_STATUS_BAR and
28  * SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR.
29  */
30 public class LightBarActivity extends LightBarBaseActivity {
31 
32     @Override
onCreate(Bundle bundle)33     protected void onCreate(Bundle bundle){
34         super.onCreate(bundle);
35 
36         // Make the window extend into the waterfall insets.
37         getWindow().getAttributes().layoutInDisplayCutoutMode =
38                 LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
39     }
40 
setLightStatusBarLegacy(boolean lightStatusBar)41     public void setLightStatusBarLegacy(boolean lightStatusBar) {
42         setLightBarLegacy(lightStatusBar, View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
43     }
44 
setLightNavigationBarLegacy(boolean lightNavigationBar)45     public void setLightNavigationBarLegacy(boolean lightNavigationBar) {
46         setLightBarLegacy(lightNavigationBar, View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
47     }
48 
setLightBarLegacy(boolean light, int systemUiFlag)49     private void setLightBarLegacy(boolean light, int systemUiFlag) {
50         int vis = getWindow().getDecorView().getSystemUiVisibility();
51         if (light) {
52             vis |= systemUiFlag;
53         } else {
54             vis &= ~systemUiFlag;
55         }
56         getWindow().getDecorView().setSystemUiVisibility(vis);
57     }
58 
setLightStatusBarAppearance(boolean lightStatusBar)59     public void setLightStatusBarAppearance(boolean lightStatusBar) {
60         setLightBarAppearance(lightStatusBar, APPEARANCE_LIGHT_STATUS_BARS);
61     }
62 
setLightNavigationBarAppearance(boolean lightNavigationBar)63     public void setLightNavigationBarAppearance(boolean lightNavigationBar) {
64         setLightBarAppearance(lightNavigationBar, APPEARANCE_LIGHT_NAVIGATION_BARS);
65     }
66 
setLightBarAppearance(boolean light, int appearanceFlag)67     private void setLightBarAppearance(boolean light, int appearanceFlag) {
68         final WindowInsetsController controller =
69                 getWindow().getDecorView().getWindowInsetsController();
70         int appearance = controller.getSystemBarsAppearance();
71         if (light) {
72             appearance |= appearanceFlag;
73         } else {
74             appearance &= ~appearanceFlag;
75         }
76         controller.setSystemBarsAppearance(appearance, appearanceFlag);
77     }
78 }
79