1 /* 2 * Copyright (C) 2024 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.statusicon; 18 19 20 import android.content.Context; 21 import android.util.AttributeSet; 22 import android.util.Log; 23 import android.widget.ImageView; 24 25 import androidx.annotation.Nullable; 26 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 public class StatusIconView extends ImageView implements CarSystemBarElement { 32 private static final String TAG = StatusIconView.class.getSimpleName(); 33 34 private Class<?> mElementControllerClassAttr; 35 private int mSystemBarDisableFlags; 36 private int mSystemBarDisable2Flags; 37 private boolean mDisableForLockTaskModeLocked; 38 StatusIconView(Context context)39 public StatusIconView(Context context) { 40 super(context); 41 init(context, /* attrs= */ null); 42 } 43 StatusIconView(Context context, @Nullable AttributeSet attrs)44 public StatusIconView(Context context, @Nullable AttributeSet attrs) { 45 super(context, attrs); 46 init(context, attrs); 47 } 48 StatusIconView(Context context, @Nullable AttributeSet attrs, int defStyleAttr)49 public StatusIconView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 50 super(context, attrs, defStyleAttr); 51 init(context, attrs); 52 } 53 StatusIconView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes)54 public StatusIconView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, 55 int defStyleRes) { 56 super(context, attrs, defStyleAttr, defStyleRes); 57 init(context, attrs); 58 } 59 init(Context context, @Nullable AttributeSet attrs)60 private void init(Context context, @Nullable AttributeSet attrs) { 61 mElementControllerClassAttr = 62 CarSystemBarElementResolver.getElementControllerClassFromAttributes(context, attrs); 63 mSystemBarDisableFlags = 64 CarSystemBarElementFlags.getStatusBarManagerDisableFlagsFromAttributes(context, 65 attrs); 66 mSystemBarDisable2Flags = 67 CarSystemBarElementFlags.getStatusBarManagerDisable2FlagsFromAttributes(context, 68 attrs); 69 mDisableForLockTaskModeLocked = 70 CarSystemBarElementFlags.getDisableForLockTaskModeLockedFromAttributes(context, 71 attrs); 72 } 73 74 @Override getElementControllerClass()75 public Class<?> getElementControllerClass() { 76 if (mElementControllerClassAttr != null) { 77 if (StatusIconViewController.class.isAssignableFrom(mElementControllerClassAttr)) { 78 return mElementControllerClassAttr; 79 } else { 80 Log.w(TAG, "Class " + mElementControllerClassAttr 81 + " is not of type StatusIconViewController - returning null"); 82 } 83 } 84 return null; 85 } 86 87 @Override getSystemBarDisableFlags()88 public int getSystemBarDisableFlags() { 89 return mSystemBarDisableFlags; 90 } 91 92 @Override getSystemBarDisable2Flags()93 public int getSystemBarDisable2Flags() { 94 return mSystemBarDisable2Flags; 95 } 96 97 @Override disableForLockTaskModeLocked()98 public boolean disableForLockTaskModeLocked() { 99 return mDisableForLockTaskModeLocked; 100 } 101 } 102