1 /* 2 * Copyright (C) 2023 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.portraitlauncher.homeactivities; 18 19 import android.content.Context; 20 import android.content.Intent; 21 import android.graphics.Insets; 22 import android.os.Bundle; 23 import android.util.Log; 24 import android.view.View; 25 import android.view.ViewGroup; 26 import android.view.WindowInsets; 27 28 import androidx.annotation.Nullable; 29 import androidx.appcompat.app.AppCompatActivity; 30 import androidx.core.view.WindowCompat; 31 32 import com.android.car.portraitlauncher.R; 33 34 /** 35 * Used as the static wallpaper in base layer. This activity is at the bottom of the base layer 36 * stack and is visible when there is no other base layer application is running. 37 */ 38 public class BackgroundPanelBaseActivity extends AppCompatActivity { 39 private static final String TAG = BackgroundPanelBaseActivity.class.getSimpleName(); 40 41 private ViewGroup mContainer; 42 43 private final View.OnApplyWindowInsetsListener mOnApplyWindowInsetsListener = (v, insets) -> { 44 int insetTypes = WindowInsets.Type.systemBars(); 45 Insets appliedInsets = insets.getInsets(insetTypes); 46 v.setPadding(appliedInsets.left, /* top= */ 0, appliedInsets.right, /* bottom= */ 0); 47 if (mContainer != null) { 48 mContainer.setPadding(appliedInsets.left, appliedInsets.top, appliedInsets.right, 49 appliedInsets.bottom); 50 } else { 51 Log.e(TAG, "Container is null"); 52 } 53 return insets.inset(appliedInsets); 54 }; 55 56 /** Creates an intent that can be used to launch this activity. */ createIntent(Context context)57 public static Intent createIntent(Context context) { 58 Intent intent = new Intent(context, BackgroundPanelBaseActivity.class); 59 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT); 60 return intent; 61 } 62 63 @Override onCreate(@ullable Bundle savedInstanceState)64 protected void onCreate(@Nullable Bundle savedInstanceState) { 65 super.onCreate(savedInstanceState); 66 setContentView(R.layout.car_ui_portrait_background_panel_base); 67 WindowCompat.setDecorFitsSystemWindows(getWindow(), /* decorFitsSystemWindows= */ false); 68 mContainer = findViewById(R.id.container); 69 getWindow().getDecorView().getRootView().setOnApplyWindowInsetsListener( 70 mOnApplyWindowInsetsListener); 71 } 72 73 @SuppressWarnings("MissingSuperCall") 74 @Override onBackPressed()75 public void onBackPressed() { 76 // no-op - this activity should always be present and not closed on back press. 77 } 78 } 79