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.systemui.car.qc; 18 19 import android.content.Context; 20 import android.content.Intent; 21 import android.content.res.TypedArray; 22 import android.util.AttributeSet; 23 24 import androidx.annotation.Nullable; 25 import androidx.constraintlayout.widget.ConstraintLayout; 26 27 import com.android.systemui.R; 28 import com.android.systemui.car.systembar.element.CarSystemBarElement; 29 import com.android.systemui.car.systembar.element.CarSystemBarElementFlags; 30 import com.android.systemui.car.systembar.element.CarSystemBarElementResolver; 31 32 import java.net.URISyntaxException; 33 34 /** 35 * Footer layout which contains one or multiple views for quick control panels. 36 * 37 * Allows for an intent action to be specified via the 38 * {@link R.styleable.QCFooterView_intent} attribute and for enabled state to be set 39 * according to driving mode via the {@link R.styleable.QCFooterView_disableWhileDriving} 40 * attribute. 41 */ 42 public class QCFooterView extends ConstraintLayout implements CarSystemBarElement { 43 private static final String TAG = QCFooterView.class.getSimpleName(); 44 45 private final Class<?> mElementControllerClassAttr; 46 private final int mSystemBarDisableFlags; 47 private final int mSystemBarDisable2Flags; 48 private final boolean mDisableForLockTaskModeLocked; 49 private final Intent mIntent; 50 private final boolean mDisableWhileDriving; 51 QCFooterView(Context context)52 public QCFooterView(Context context) { 53 this(context, null); 54 } 55 QCFooterView(Context context, AttributeSet attrs)56 public QCFooterView(Context context, AttributeSet attrs) { 57 this(context, attrs, 0); 58 } 59 QCFooterView(Context context, AttributeSet attrs, int defStyleAttr)60 public QCFooterView(Context context, AttributeSet attrs, int defStyleAttr) { 61 this(context, attrs, defStyleAttr, 0); 62 } 63 QCFooterView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)64 public QCFooterView(Context context, AttributeSet attrs, int defStyleAttr, 65 int defStyleRes) { 66 super(context, attrs, defStyleAttr, defStyleRes); 67 mElementControllerClassAttr = 68 CarSystemBarElementResolver.getElementControllerClassFromAttributes(context, attrs); 69 mSystemBarDisableFlags = 70 CarSystemBarElementFlags.getStatusBarManagerDisableFlagsFromAttributes(context, 71 attrs); 72 mSystemBarDisable2Flags = 73 CarSystemBarElementFlags.getStatusBarManagerDisable2FlagsFromAttributes(context, 74 attrs); 75 mDisableForLockTaskModeLocked = 76 CarSystemBarElementFlags.getDisableForLockTaskModeLockedFromAttributes(context, 77 attrs); 78 79 if (attrs == null) { 80 mIntent = null; 81 mDisableWhileDriving = false; 82 return; 83 } 84 85 TypedArray typedArray = context.obtainStyledAttributes(attrs, 86 R.styleable.QCFooterView); 87 String intentString = typedArray.getString(R.styleable.QCFooterView_intent); 88 if (intentString != null) { 89 try { 90 mIntent = Intent.parseUri(intentString, Intent.URI_INTENT_SCHEME); 91 } catch (URISyntaxException e) { 92 throw new RuntimeException("Failed to attach intent", e); 93 } 94 } else { 95 mIntent = null; 96 } 97 mDisableWhileDriving = typedArray.getBoolean( 98 R.styleable.QCFooterView_disableWhileDriving, /* defValue= */ false); 99 typedArray.recycle(); 100 } 101 102 @Nullable getOnClickIntent()103 public Intent getOnClickIntent() { 104 return mIntent; 105 } 106 isDisableWhileDriving()107 public boolean isDisableWhileDriving() { 108 return mDisableWhileDriving; 109 } 110 111 @Override getElementControllerClass()112 public Class<?> getElementControllerClass() { 113 if (mElementControllerClassAttr != null) { 114 return mElementControllerClassAttr; 115 } 116 return QCFooterViewController.class; 117 } 118 119 @Override getSystemBarDisableFlags()120 public int getSystemBarDisableFlags() { 121 return mSystemBarDisableFlags; 122 } 123 124 @Override getSystemBarDisable2Flags()125 public int getSystemBarDisable2Flags() { 126 return mSystemBarDisable2Flags; 127 } 128 129 @Override disableForLockTaskModeLocked()130 public boolean disableForLockTaskModeLocked() { 131 return mDisableForLockTaskModeLocked; 132 } 133 } 134