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 package com.android.systemui.car.distantdisplay.activity; 17 18 import android.app.Activity; 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.core.view.WindowCompat; 30 31 import com.android.systemui.R; 32 33 /** 34 * Used as the static wallpaper in root layer. 35 */ 36 public class RootTaskViewWallpaperActivity extends Activity { 37 private static final String TAG = 38 RootTaskViewWallpaperActivity.class.getSimpleName(); 39 40 private ViewGroup mContainer; 41 42 private final View.OnApplyWindowInsetsListener mOnApplyWindowInsetsListener = (v, insets) -> { 43 int insetTypes = WindowInsets.Type.systemBars(); 44 Insets appliedInsets = insets.getInsets(insetTypes); 45 v.setPadding(appliedInsets.left, /* top= */ 0, appliedInsets.right, /* bottom= */ 0); 46 if (mContainer != null) { 47 mContainer.setPadding(appliedInsets.left, appliedInsets.top, appliedInsets.right, 48 appliedInsets.bottom); 49 } else { 50 Log.e(TAG, "Container is null"); 51 } 52 return insets.inset(appliedInsets); 53 }; 54 55 /** Creates an intent that can be used to launch this activity. */ createIntent(Context context)56 public static Intent createIntent(Context context) { 57 Intent intent = new Intent(context, RootTaskViewWallpaperActivity.class); 58 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT); 59 return intent; 60 } 61 62 @Override onCreate(@ullable Bundle savedInstanceState)63 protected void onCreate(@Nullable Bundle savedInstanceState) { 64 super.onCreate(savedInstanceState); 65 setContentView(R.layout.car_distant_display_root_wallpaper_activity); 66 WindowCompat.setDecorFitsSystemWindows(getWindow(), /* decorFitsSystemWindows= */ false); 67 mContainer = findViewById(R.id.container); 68 getWindow().getDecorView().getRootView().setOnApplyWindowInsetsListener( 69 mOnApplyWindowInsetsListener); 70 } 71 } 72 73