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.displaycompat; 17 18 import android.content.Context; 19 import android.content.pm.PackageManager; 20 import android.content.res.TypedArray; 21 import android.util.AttributeSet; 22 23 import com.android.systemui.R; 24 import com.android.systemui.car.systembar.CarSystemBarView; 25 26 /** 27 * 28 */ 29 public class CarDisplayCompatSystemBarView extends CarSystemBarView { 30 31 public static final String DISPLAYCOMPAT_SYSTEM_FEATURE = "android.car.displaycompatibility"; 32 CarDisplayCompatSystemBarView(Context context, AttributeSet attrs)33 public CarDisplayCompatSystemBarView(Context context, AttributeSet attrs) { 34 super(context, attrs); 35 36 TypedArray a = context.obtainStyledAttributes(attrs, 37 R.styleable.CarDisplayCompatSystemBarView, 0, 0); 38 int defaultLayoutId = 39 a.getResourceId(R.styleable.CarDisplayCompatSystemBarView_default_layout, 0); 40 if (defaultLayoutId == 0) { 41 throw new IllegalArgumentException("default_layout attribute is not set"); 42 } 43 int displayCompatLayoutId = 44 a.getResourceId(R.styleable.CarDisplayCompatSystemBarView_displaycompat_layout, 0); 45 int displayCompatConfig = context.getResources() 46 .getInteger(R.integer.config_showDisplayCompatToolbarOnSystemBar); 47 int compatDisplaySide = a.getInt( 48 R.styleable.CarDisplayCompatSystemBarView_displaycompat_side, 0); 49 a.recycle(); 50 51 PackageManager packageManager = context.getPackageManager(); 52 if (packageManager.hasSystemFeature(DISPLAYCOMPAT_SYSTEM_FEATURE) 53 && displayCompatConfig != 0 54 && displayCompatConfig == compatDisplaySide) { 55 inflate(context, displayCompatLayoutId, this); 56 } else { 57 inflate(context, defaultLayoutId, this); 58 } 59 } 60 } 61