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 = 32 "android.software.car.display_compatibility"; 33 CarDisplayCompatSystemBarView(Context context, AttributeSet attrs)34 public CarDisplayCompatSystemBarView(Context context, AttributeSet attrs) { 35 super(context, attrs); 36 37 TypedArray a = context.obtainStyledAttributes(attrs, 38 R.styleable.CarDisplayCompatSystemBarView, 0, 0); 39 int defaultLayoutId = 40 a.getResourceId(R.styleable.CarDisplayCompatSystemBarView_default_layout, 0); 41 if (defaultLayoutId == 0) { 42 throw new IllegalArgumentException("default_layout attribute is not set"); 43 } 44 int displayCompatLayoutId = 45 a.getResourceId(R.styleable.CarDisplayCompatSystemBarView_displaycompat_layout, 0); 46 int displayCompatConfig = context.getResources() 47 .getInteger(R.integer.config_showDisplayCompatToolbarOnSystemBar); 48 int compatDisplaySide = a.getInt( 49 R.styleable.CarDisplayCompatSystemBarView_displaycompat_side, 0); 50 a.recycle(); 51 52 PackageManager packageManager = context.getPackageManager(); 53 if (packageManager.hasSystemFeature(DISPLAYCOMPAT_SYSTEM_FEATURE) 54 && displayCompatConfig != 0 55 && displayCompatConfig == compatDisplaySide) { 56 inflate(context, displayCompatLayoutId, this); 57 } else { 58 inflate(context, defaultLayoutId, this); 59 } 60 } 61 } 62