1 /* 2 * Copyright (C) 2021 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.systemui.car.qc; 18 19 import android.content.Context; 20 import android.content.res.TypedArray; 21 import android.util.AttributeSet; 22 23 import androidx.annotation.Nullable; 24 25 import com.android.car.qc.view.QCView; 26 import com.android.systemui.R; 27 import com.android.systemui.car.systembar.element.CarSystemBarElement; 28 import com.android.systemui.car.systembar.element.CarSystemBarElementFlags; 29 import com.android.systemui.car.systembar.element.CarSystemBarElementResolver; 30 31 /** 32 * Quick Control View Element for CarSystemUI. 33 * 34 * This extended class allows for specifying a local or remote quick controls provider via xml 35 * attributes. This is then retrieved by a {@link SystemUIQCViewController} to be bound and 36 * controlled. 37 * 38 * @attr ref R.styleable#SystemUIQCView_remoteQCProvider 39 * @attr ref R.styleable#SystemUIQCView_localQCProvider 40 */ 41 public class SystemUIQCView extends QCView implements CarSystemBarElement { 42 private Class<?> mElementControllerClassAttr; 43 private int mSystemBarDisableFlags; 44 private int mSystemBarDisable2Flags; 45 private boolean mDisableForLockTaskModeLocked; 46 private String mRemoteUri; 47 private String mLocalClass; 48 SystemUIQCView(Context context)49 public SystemUIQCView(Context context) { 50 super(context); 51 init(context, /* attrs= */ null); 52 } 53 SystemUIQCView(Context context, AttributeSet attrs)54 public SystemUIQCView(Context context, AttributeSet attrs) { 55 super(context, attrs); 56 init(context, attrs); 57 } 58 SystemUIQCView(Context context, AttributeSet attrs, int defStyleAttr)59 public SystemUIQCView(Context context, AttributeSet attrs, int defStyleAttr) { 60 super(context, attrs, defStyleAttr); 61 init(context, attrs); 62 } 63 SystemUIQCView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)64 public SystemUIQCView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 65 super(context, attrs, defStyleAttr, defStyleRes); 66 init(context, attrs); 67 } 68 init(Context context, AttributeSet attrs)69 private void init(Context context, AttributeSet attrs) { 70 mElementControllerClassAttr = 71 CarSystemBarElementResolver.getElementControllerClassFromAttributes(context, attrs); 72 mSystemBarDisableFlags = 73 CarSystemBarElementFlags.getStatusBarManagerDisableFlagsFromAttributes(context, 74 attrs); 75 mSystemBarDisable2Flags = 76 CarSystemBarElementFlags.getStatusBarManagerDisable2FlagsFromAttributes(context, 77 attrs); 78 mDisableForLockTaskModeLocked = 79 CarSystemBarElementFlags.getDisableForLockTaskModeLockedFromAttributes(context, 80 attrs); 81 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SystemUIQCView); 82 mRemoteUri = a.getString(R.styleable.SystemUIQCView_remoteQCProvider); 83 mLocalClass = a.getString(R.styleable.SystemUIQCView_localQCProvider); 84 a.recycle(); 85 } 86 87 @Nullable getRemoteUriString()88 public String getRemoteUriString() { 89 return mRemoteUri; 90 } 91 92 @Nullable getLocalClassString()93 public String getLocalClassString() { 94 return mLocalClass; 95 } 96 97 @Override getElementControllerClass()98 public Class<?> getElementControllerClass() { 99 if (mElementControllerClassAttr != null) { 100 return mElementControllerClassAttr; 101 } 102 return SystemUIQCViewController.class; 103 } 104 105 @Override getSystemBarDisableFlags()106 public int getSystemBarDisableFlags() { 107 return mSystemBarDisableFlags; 108 } 109 110 @Override getSystemBarDisable2Flags()111 public int getSystemBarDisable2Flags() { 112 return mSystemBarDisable2Flags; 113 } 114 115 @Override disableForLockTaskModeLocked()116 public boolean disableForLockTaskModeLocked() { 117 return mDisableForLockTaskModeLocked; 118 } 119 } 120