1 /*
2  * Copyright (C) 2016 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 com.android.car.mapsplaceholder;
18 
19 import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
20 
21 import android.app.Activity;
22 import android.graphics.Insets;
23 import android.os.Bundle;
24 import android.view.View;
25 import android.view.Window;
26 import android.view.WindowInsets;
27 import android.view.WindowManager;
28 
29 import androidx.core.view.WindowCompat;
30 import androidx.core.view.WindowInsetsControllerCompat;
31 
32 /**
33  * An activity that notifies the user that no maps application has been installed.
34  */
35 public class MapsPlaceholderActivity extends Activity {
36     @Override
onCreate(Bundle savedInstanceState)37     protected void onCreate(Bundle savedInstanceState) {
38         super.onCreate(savedInstanceState);
39         setContentView(R.layout.maps_placeholder_activity);
40 
41         if (getResources().getConfiguration().orientation == ORIENTATION_PORTRAIT) {
42             showTransparentStatusBar(getWindow());
43             findViewById(android.R.id.content).getRootView()
44                     .setOnApplyWindowInsetsListener((view, insets) -> {
45                         Insets inset = insets.getInsets(WindowInsets.Type.systemOverlays());
46                         View contentView = findViewById(R.id.aosp_nav);
47                         contentView.setPadding(0, inset.top, 0, inset.bottom);
48                         return insets;
49                     });
50         }
51     }
52 
53     /** Configures the window to render behind a transparent status bar. */
showTransparentStatusBar(Window window)54     public static void showTransparentStatusBar(Window window) {
55         updateWindowFlagsToSetStatusbarColor(window);
56         window.setStatusBarColor(
57                 window.getContext().getResources().getColor(android.R.color.transparent));
58     }
59 
updateWindowFlagsToSetStatusbarColor(Window window)60     private static void updateWindowFlagsToSetStatusbarColor(Window window) {
61         WindowCompat.setDecorFitsSystemWindows(window, false);
62         WindowInsetsControllerCompat controller =  WindowCompat
63                 .getInsetsController(window, window.getDecorView());
64         controller.setSystemBarsBehavior(
65                 WindowInsetsControllerCompat.BEHAVIOR_DEFAULT);
66         // Set up window flags to enable setting the status bar color.
67         // Note that setting FLAG_DRAWS_SYSTEM_BAR_BACKGROUND does not automatically make the
68         // navigation bar transparent in cars.
69 
70         window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
71         window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
72     }
73 }
74