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.systembar.element; 18 19 import android.annotation.IntDef; 20 import android.app.StatusBarManager; 21 import android.content.Context; 22 import android.content.res.TypedArray; 23 import android.util.AttributeSet; 24 25 import androidx.annotation.NonNull; 26 import androidx.annotation.Nullable; 27 28 import com.android.systemui.R; 29 30 import java.lang.annotation.Retention; 31 import java.lang.annotation.RetentionPolicy; 32 33 /** 34 * Flag definitions for applicable flag attributes for CarSystemBarElement views and helper 35 * functions for working with these attributes. 36 */ 37 public class CarSystemBarElementFlags { 38 static final int DISABLE_FLAG_NONE = 0; 39 static final int DISABLE_FLAG_EXPAND = 1; 40 static final int DISABLE_FLAG_NOTIFICATION_ICONS = 1 << 1; 41 static final int DISABLE_FLAG_NOTIFICATION_ALERTS = 1 << 2; 42 static final int DISABLE_FLAG_SYSTEM_INFO = 1 << 3; 43 static final int DISABLE_FLAG_HOME = 1 << 4; 44 static final int DISABLE_FLAG_RECENT = 1 << 5; 45 static final int DISABLE_FLAG_BACK = 1 << 6; 46 static final int DISABLE_FLAG_CLOCK = 1 << 7; 47 static final int DISABLE_FLAG_SEARCH = 1 << 8; 48 static final int DISABLE_FLAG_ONGOING_CALL_CHIP = 1 << 9; 49 @IntDef(flag = true, prefix = {"DISABLE_FLAG_"}, value = { 50 DISABLE_FLAG_NONE, 51 DISABLE_FLAG_EXPAND, 52 DISABLE_FLAG_NOTIFICATION_ICONS, 53 DISABLE_FLAG_NOTIFICATION_ALERTS, 54 DISABLE_FLAG_SYSTEM_INFO, 55 DISABLE_FLAG_HOME, 56 DISABLE_FLAG_RECENT, 57 DISABLE_FLAG_BACK, 58 DISABLE_FLAG_CLOCK, 59 DISABLE_FLAG_SEARCH, 60 DISABLE_FLAG_ONGOING_CALL_CHIP 61 }) 62 @Retention(RetentionPolicy.CLASS) 63 @interface SystemBarDisableFlags {} 64 65 static final int DISABLE2_FLAG_NONE = 0; 66 static final int DISABLE2_FLAG_QUICK_SETTINGS = 1; 67 static final int DISABLE2_FLAG_SYSTEM_ICONS = 1 << 1; 68 static final int DISABLE2_FLAG_NOTIFICATION_SHADE = 1 << 2; 69 static final int DISABLE2_FLAG_GLOBAL_ACTIONS = 1 << 3; 70 static final int DISABLE2_FLAG_ROTATE_SUGGESTIONS = 1 << 4; 71 @IntDef(flag = true, prefix = {"DISABLE2_FLAG_"}, value = { 72 DISABLE2_FLAG_NONE, 73 DISABLE2_FLAG_QUICK_SETTINGS, 74 DISABLE2_FLAG_SYSTEM_ICONS, 75 DISABLE2_FLAG_NOTIFICATION_SHADE, 76 DISABLE2_FLAG_GLOBAL_ACTIONS, 77 DISABLE2_FLAG_ROTATE_SUGGESTIONS 78 }) 79 @Retention(RetentionPolicy.CLASS) 80 @interface SystemBarDisable2Flags {} 81 82 /** Get the {@link StatusBarManager.DisableFlags} from the CarSystemBarElement attributes **/ 83 @StatusBarManager.DisableFlags getStatusBarManagerDisableFlagsFromAttributes(@onNull Context context, @Nullable AttributeSet attrs)84 public static int getStatusBarManagerDisableFlagsFromAttributes(@NonNull Context context, 85 @Nullable AttributeSet attrs) { 86 if (attrs == null) { 87 return getStatusBarManagerDisableFlagsFromElementFlags(DISABLE_FLAG_NONE); 88 } 89 TypedArray typedArray = context.obtainStyledAttributes(attrs, 90 R.styleable.CarSystemBarElement); 91 int flags = typedArray.getInt(R.styleable.CarSystemBarElement_systemBarDisableFlags, 92 DISABLE_FLAG_NONE); 93 typedArray.recycle(); 94 return getStatusBarManagerDisableFlagsFromElementFlags(flags); 95 } 96 97 /** 98 * Get the {@link StatusBarManager.DisableFlags} from the CarSystemBarElement 99 * {@link SystemBarDisableFlags} 100 */ 101 @StatusBarManager.DisableFlags getStatusBarManagerDisableFlagsFromElementFlags(int flags)102 public static int getStatusBarManagerDisableFlagsFromElementFlags(int flags) { 103 int newFlag = StatusBarManager.DISABLE_NONE; 104 if ((DISABLE_FLAG_EXPAND & flags) != 0) newFlag |= StatusBarManager.DISABLE_EXPAND; 105 if ((DISABLE_FLAG_NOTIFICATION_ICONS & flags) != 0) { 106 newFlag |= StatusBarManager.DISABLE_NOTIFICATION_ICONS; 107 } 108 if ((DISABLE_FLAG_NOTIFICATION_ALERTS & flags) != 0) { 109 newFlag |= StatusBarManager.DISABLE_NOTIFICATION_ALERTS; 110 } 111 if ((DISABLE_FLAG_SYSTEM_INFO & flags) != 0) { 112 newFlag |= StatusBarManager.DISABLE_SYSTEM_INFO; 113 } 114 if ((DISABLE_FLAG_HOME & flags) != 0) newFlag |= StatusBarManager.DISABLE_HOME; 115 if ((DISABLE_FLAG_RECENT & flags) != 0) newFlag |= StatusBarManager.DISABLE_RECENT; 116 if ((DISABLE_FLAG_BACK & flags) != 0) newFlag |= StatusBarManager.DISABLE_BACK; 117 if ((DISABLE_FLAG_CLOCK & flags) != 0) newFlag |= StatusBarManager.DISABLE_CLOCK; 118 if ((DISABLE_FLAG_SEARCH & flags) != 0) newFlag |= StatusBarManager.DISABLE_SEARCH; 119 if ((DISABLE_FLAG_ONGOING_CALL_CHIP & flags) != 0) { 120 newFlag |= StatusBarManager.DISABLE_ONGOING_CALL_CHIP; 121 } 122 return newFlag; 123 } 124 125 /** Get the {@link StatusBarManager.Disable2Flags} from the CarSystemBarElement attributes **/ 126 @StatusBarManager.Disable2Flags getStatusBarManagerDisable2FlagsFromAttributes(@onNull Context context, @Nullable AttributeSet attrs)127 public static int getStatusBarManagerDisable2FlagsFromAttributes(@NonNull Context context, 128 @Nullable AttributeSet attrs) { 129 if (attrs == null) { 130 return getStatusBarManagerDisable2FlagsFromElementFlags(DISABLE2_FLAG_NONE); 131 } 132 TypedArray typedArray = context.obtainStyledAttributes(attrs, 133 R.styleable.CarSystemBarElement); 134 int flags = typedArray.getInt(R.styleable.CarSystemBarElement_systemBarDisable2Flags, 135 DISABLE2_FLAG_NONE); 136 typedArray.recycle(); 137 return getStatusBarManagerDisable2FlagsFromElementFlags(flags); 138 } 139 140 /** 141 * Get the {@link StatusBarManager.Disable2Flags} from the CarSystemBarElement 142 * {@link SystemBar2DisableFlags} 143 */ 144 @StatusBarManager.Disable2Flags getStatusBarManagerDisable2FlagsFromElementFlags(int flags)145 public static int getStatusBarManagerDisable2FlagsFromElementFlags(int flags) { 146 int newFlag = StatusBarManager.DISABLE2_NONE; 147 if ((DISABLE2_FLAG_QUICK_SETTINGS & flags) != 0) { 148 newFlag |= StatusBarManager.DISABLE2_QUICK_SETTINGS; 149 } 150 if ((DISABLE2_FLAG_SYSTEM_ICONS & flags) != 0) { 151 newFlag |= StatusBarManager.DISABLE2_SYSTEM_ICONS; 152 } 153 if ((DISABLE2_FLAG_NOTIFICATION_SHADE & flags) != 0) { 154 newFlag |= StatusBarManager.DISABLE2_NOTIFICATION_SHADE; 155 } 156 if ((DISABLE2_FLAG_GLOBAL_ACTIONS & flags) != 0) { 157 newFlag |= StatusBarManager.DISABLE2_GLOBAL_ACTIONS; 158 } 159 if ((DISABLE2_FLAG_ROTATE_SUGGESTIONS & flags) != 0) { 160 newFlag |= StatusBarManager.DISABLE2_ROTATE_SUGGESTIONS; 161 } 162 return newFlag; 163 } 164 165 /** Get the disable for locked task mode state from the CarSystemBarElement attributes **/ getDisableForLockTaskModeLockedFromAttributes(@onNull Context context, @Nullable AttributeSet attrs)166 public static boolean getDisableForLockTaskModeLockedFromAttributes(@NonNull Context context, 167 @Nullable AttributeSet attrs) { 168 if (attrs == null) { 169 return false; 170 } 171 TypedArray typedArray = context.obtainStyledAttributes(attrs, 172 R.styleable.CarSystemBarElement); 173 boolean disable = typedArray.getBoolean( 174 R.styleable.CarSystemBarElement_disableForLockTaskModeLocked, false); 175 typedArray.recycle(); 176 return disable; 177 } 178 } 179