Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file |
| 5 | * except in compliance with the License. You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software distributed under the |
| 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 11 | * KIND, either express or implied. See the License for the specific language governing |
| 12 | * permissions and limitations under the License. |
| 13 | */ |
| 14 | |
| 15 | package com.android.systemui.qs; |
| 16 | |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 17 | import static android.app.StatusBarManager.DISABLE2_QUICK_SETTINGS; |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 18 | |
Jason Monk | ea54e8a | 2018-12-20 10:01:48 -0500 | [diff] [blame] | 19 | import static com.android.systemui.util.InjectionInflationController.VIEW_CONTEXT; |
Matt Pietal | 5a19cb6 | 2019-10-30 12:31:07 -0400 | [diff] [blame] | 20 | import static com.android.systemui.util.Utils.useQsMediaPlayer; |
Jason Monk | ea54e8a | 2018-12-20 10:01:48 -0500 | [diff] [blame] | 21 | |
Amin Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame] | 22 | import android.annotation.ColorInt; |
Lucas Dupin | 1f7374a | 2018-02-26 18:08:33 -0800 | [diff] [blame] | 23 | import android.app.ActivityManager; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 24 | import android.app.AlarmManager; |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 25 | import android.content.BroadcastReceiver; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 26 | import android.content.Context; |
Evan Laird | 4ea2a49 | 2018-01-22 11:29:12 -0500 | [diff] [blame] | 27 | import android.content.Intent; |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 28 | import android.content.IntentFilter; |
Fabian Kozynski | f86df99 | 2019-04-22 14:23:47 -0400 | [diff] [blame] | 29 | import android.content.res.ColorStateList; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 30 | import android.content.res.Configuration; |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 31 | import android.content.res.Resources; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 32 | import android.graphics.Color; |
| 33 | import android.graphics.Rect; |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 34 | import android.media.AudioManager; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 35 | import android.os.Handler; |
Fabian Kozynski | 1263824 | 2018-10-12 15:33:41 -0400 | [diff] [blame] | 36 | import android.os.Looper; |
Evan Laird | 4ea2a49 | 2018-01-22 11:29:12 -0500 | [diff] [blame] | 37 | import android.provider.AlarmClock; |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 38 | import android.provider.DeviceConfig; |
Fabian Kozynski | b1aee81 | 2019-04-04 14:17:48 -0400 | [diff] [blame] | 39 | import android.provider.Settings; |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 40 | import android.service.notification.ZenModeConfig; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 41 | import android.text.format.DateUtils; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 42 | import android.util.AttributeSet; |
Fabian Kozynski | a354471 | 2019-04-25 17:05:21 -0400 | [diff] [blame] | 43 | import android.util.Log; |
Adrian Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 44 | import android.util.Pair; |
Fabian Kozynski | bfd6d85 | 2019-02-15 15:08:16 -0500 | [diff] [blame] | 45 | import android.util.StatsLog; |
Fabian Kozynski | f86df99 | 2019-04-22 14:23:47 -0400 | [diff] [blame] | 46 | import android.view.ContextThemeWrapper; |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 47 | import android.view.DisplayCutout; |
Jason Monk | 824ffff | 2017-04-11 15:49:06 -0400 | [diff] [blame] | 48 | import android.view.View; |
Adrian Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 49 | import android.view.WindowInsets; |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 50 | import android.widget.FrameLayout; |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 51 | import android.widget.ImageView; |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 52 | import android.widget.LinearLayout; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 53 | import android.widget.RelativeLayout; |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 54 | import android.widget.Space; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 55 | import android.widget.TextView; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 56 | |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 57 | import androidx.annotation.VisibleForTesting; |
| 58 | |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 59 | import com.android.internal.config.sysui.SystemUiDeviceConfigFlags; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 60 | import com.android.settingslib.Utils; |
| 61 | import com.android.systemui.BatteryMeterView; |
Fabian Kozynski | f86df99 | 2019-04-22 14:23:47 -0400 | [diff] [blame] | 62 | import com.android.systemui.DualToneHandler; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 63 | import com.android.systemui.R; |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 64 | import com.android.systemui.broadcast.BroadcastDispatcher; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 65 | import com.android.systemui.plugins.ActivityStarter; |
Beverly | 1be62f4 | 2018-12-19 17:17:48 -0500 | [diff] [blame] | 66 | import com.android.systemui.plugins.DarkIconDispatcher; |
| 67 | import com.android.systemui.plugins.DarkIconDispatcher.DarkReceiver; |
Fabian Kozynski | 1263824 | 2018-10-12 15:33:41 -0400 | [diff] [blame] | 68 | import com.android.systemui.privacy.OngoingPrivacyChip; |
Fabian Kozynski | afd5002 | 2019-02-05 09:41:42 -0500 | [diff] [blame] | 69 | import com.android.systemui.privacy.PrivacyDialogBuilder; |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 70 | import com.android.systemui.privacy.PrivacyItem; |
| 71 | import com.android.systemui.privacy.PrivacyItemController; |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 72 | import com.android.systemui.privacy.PrivacyItemControllerKt; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 73 | import com.android.systemui.qs.QSDetail.Callback; |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 74 | import com.android.systemui.statusbar.CommandQueue; |
Adrian Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 75 | import com.android.systemui.statusbar.phone.PhoneStatusBarView; |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 76 | import com.android.systemui.statusbar.phone.StatusBarIconController; |
| 77 | import com.android.systemui.statusbar.phone.StatusBarIconController.TintedIconManager; |
Evan Laird | 20b87bf | 2018-04-12 09:54:11 -0400 | [diff] [blame] | 78 | import com.android.systemui.statusbar.phone.StatusIconContainer; |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 79 | import com.android.systemui.statusbar.policy.Clock; |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 80 | import com.android.systemui.statusbar.policy.DateView; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 81 | import com.android.systemui.statusbar.policy.NextAlarmController; |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 82 | import com.android.systemui.statusbar.policy.ZenModeController; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 83 | |
Evan Laird | f435fd2 | 2019-02-15 13:35:45 -0500 | [diff] [blame] | 84 | import java.util.ArrayList; |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 85 | import java.util.List; |
Lucas Dupin | 1f7374a | 2018-02-26 18:08:33 -0800 | [diff] [blame] | 86 | import java.util.Locale; |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 87 | import java.util.Objects; |
Lucas Dupin | 1f7374a | 2018-02-26 18:08:33 -0800 | [diff] [blame] | 88 | |
Jason Monk | ea54e8a | 2018-12-20 10:01:48 -0500 | [diff] [blame] | 89 | import javax.inject.Inject; |
| 90 | import javax.inject.Named; |
| 91 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 92 | /** |
| 93 | * View that contains the top-most bits of the screen (primarily the status bar with date, time, and |
| 94 | * battery) and also contains the {@link QuickQSPanel} along with some of the panel's inner |
| 95 | * contents. |
| 96 | */ |
Amin Shaikh | f09450b | 2018-04-06 17:32:45 -0400 | [diff] [blame] | 97 | public class QuickStatusBarHeader extends RelativeLayout implements |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 98 | View.OnClickListener, NextAlarmController.NextAlarmChangeCallback, |
| 99 | ZenModeController.Callback { |
Rohan Shah | a160ab1 | 2018-03-09 15:47:36 -0800 | [diff] [blame] | 100 | private static final String TAG = "QuickStatusBarHeader"; |
| 101 | private static final boolean DEBUG = false; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 102 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 103 | /** Delay for auto fading out the long press tooltip after it's fully visible (in ms). */ |
| 104 | private static final long AUTO_FADE_OUT_DELAY_MS = DateUtils.SECOND_IN_MILLIS * 6; |
| 105 | private static final int FADE_ANIMATION_DURATION_MS = 300; |
| 106 | private static final int TOOLTIP_NOT_YET_SHOWN_COUNT = 0; |
Rohan Shah | b6a915c | 2018-03-01 11:57:00 -0800 | [diff] [blame] | 107 | public static final int MAX_TOOLTIP_SHOWN_COUNT = 2; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 108 | |
| 109 | private final Handler mHandler = new Handler(); |
Jason Monk | ea54e8a | 2018-12-20 10:01:48 -0500 | [diff] [blame] | 110 | private final NextAlarmController mAlarmController; |
| 111 | private final ZenModeController mZenController; |
| 112 | private final StatusBarIconController mStatusBarIconController; |
| 113 | private final ActivityStarter mActivityStarter; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 114 | |
| 115 | private QSPanel mQsPanel; |
| 116 | |
| 117 | private boolean mExpanded; |
| 118 | private boolean mListening; |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 119 | private boolean mQsDisabled; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 120 | |
Fabian Kozynski | 4e76d1f | 2019-02-25 16:30:04 -0500 | [diff] [blame] | 121 | private QSCarrierGroup mCarrierGroup; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 122 | protected QuickQSPanel mHeaderQsPanel; |
| 123 | protected QSTileHost mHost; |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 124 | private TintedIconManager mIconManager; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 125 | private TouchAnimator mStatusIconsAlphaAnimator; |
| 126 | private TouchAnimator mHeaderTextContainerAlphaAnimator; |
Fabian Kozynski | 216812e | 2019-02-01 13:49:00 -0500 | [diff] [blame] | 127 | private TouchAnimator mPrivacyChipAlphaAnimator; |
Fabian Kozynski | f86df99 | 2019-04-22 14:23:47 -0400 | [diff] [blame] | 128 | private DualToneHandler mDualToneHandler; |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 129 | private final CommandQueue mCommandQueue; |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 130 | |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 131 | private View mSystemIconsView; |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 132 | private View mQuickQsStatusIcons; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 133 | private View mHeaderTextContainerView; |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 134 | |
| 135 | private int mRingerMode = AudioManager.RINGER_MODE_NORMAL; |
| 136 | private AlarmManager.AlarmClockInfo mNextAlarm; |
| 137 | |
| 138 | private ImageView mNextAlarmIcon; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 139 | /** {@link TextView} containing the actual text indicating when the next alarm will go off. */ |
| 140 | private TextView mNextAlarmTextView; |
Fabian Kozynski | b1aee81 | 2019-04-04 14:17:48 -0400 | [diff] [blame] | 141 | private View mNextAlarmContainer; |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 142 | private View mStatusSeparator; |
| 143 | private ImageView mRingerModeIcon; |
| 144 | private TextView mRingerModeTextView; |
Fabian Kozynski | b1aee81 | 2019-04-04 14:17:48 -0400 | [diff] [blame] | 145 | private View mRingerContainer; |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 146 | private Clock mClockView; |
| 147 | private DateView mDateView; |
Fabian Kozynski | 1263824 | 2018-10-12 15:33:41 -0400 | [diff] [blame] | 148 | private OngoingPrivacyChip mPrivacyChip; |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 149 | private Space mSpace; |
Evan Laird | 4bf21df | 2018-10-22 14:24:32 -0400 | [diff] [blame] | 150 | private BatteryMeterView mBatteryRemainingIcon; |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 151 | private boolean mPermissionsHubEnabled; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 152 | |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 153 | private PrivacyItemController mPrivacyItemController; |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 154 | private BroadcastDispatcher mBroadcastDispatcher; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 155 | |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 156 | private final BroadcastReceiver mRingerReceiver = new BroadcastReceiver() { |
| 157 | @Override |
| 158 | public void onReceive(Context context, Intent intent) { |
| 159 | mRingerMode = intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1); |
| 160 | updateStatusText(); |
| 161 | } |
| 162 | }; |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 163 | private boolean mHasTopCutout = false; |
Fabian Kozynski | bfd6d85 | 2019-02-15 15:08:16 -0500 | [diff] [blame] | 164 | private boolean mPrivacyChipLogged = false; |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 165 | |
Matt Pape | cb88879 | 2019-05-22 15:32:32 -0700 | [diff] [blame] | 166 | private final DeviceConfig.OnPropertiesChangedListener mPropertiesListener = |
| 167 | new DeviceConfig.OnPropertiesChangedListener() { |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 168 | @Override |
Matt Pape | cb88879 | 2019-05-22 15:32:32 -0700 | [diff] [blame] | 169 | public void onPropertiesChanged(DeviceConfig.Properties properties) { |
| 170 | if (DeviceConfig.NAMESPACE_PRIVACY.equals(properties.getNamespace()) |
| 171 | && properties.getKeyset() |
| 172 | .contains(SystemUiDeviceConfigFlags.PROPERTY_PERMISSIONS_HUB_ENABLED)) { |
| 173 | mPermissionsHubEnabled = properties.getBoolean( |
| 174 | SystemUiDeviceConfigFlags.PROPERTY_PERMISSIONS_HUB_ENABLED, false); |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 175 | StatusIconContainer iconContainer = findViewById(R.id.statusIcons); |
| 176 | iconContainer.setIgnoredSlots(getIgnoredIconSlots()); |
| 177 | } |
| 178 | } |
| 179 | }; |
| 180 | |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 181 | private PrivacyItemController.Callback mPICCallback = new PrivacyItemController.Callback() { |
| 182 | @Override |
| 183 | public void privacyChanged(List<PrivacyItem> privacyItems) { |
| 184 | mPrivacyChip.setPrivacyList(privacyItems); |
| 185 | setChipVisibility(!privacyItems.isEmpty()); |
| 186 | } |
| 187 | }; |
| 188 | |
Jason Monk | ea54e8a | 2018-12-20 10:01:48 -0500 | [diff] [blame] | 189 | @Inject |
| 190 | public QuickStatusBarHeader(@Named(VIEW_CONTEXT) Context context, AttributeSet attrs, |
| 191 | NextAlarmController nextAlarmController, ZenModeController zenModeController, |
Evan Laird | 85ee4a3 | 2019-03-06 18:09:20 -0500 | [diff] [blame] | 192 | StatusBarIconController statusBarIconController, |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 193 | ActivityStarter activityStarter, PrivacyItemController privacyItemController, |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 194 | CommandQueue commandQueue, BroadcastDispatcher broadcastDispatcher) { |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 195 | super(context, attrs); |
Jason Monk | ea54e8a | 2018-12-20 10:01:48 -0500 | [diff] [blame] | 196 | mAlarmController = nextAlarmController; |
| 197 | mZenController = zenModeController; |
Jason Monk | ea54e8a | 2018-12-20 10:01:48 -0500 | [diff] [blame] | 198 | mStatusBarIconController = statusBarIconController; |
| 199 | mActivityStarter = activityStarter; |
Fabian Kozynski | 04f83eb | 2019-01-22 10:38:40 -0500 | [diff] [blame] | 200 | mPrivacyItemController = privacyItemController; |
Fabian Kozynski | f86df99 | 2019-04-22 14:23:47 -0400 | [diff] [blame] | 201 | mDualToneHandler = new DualToneHandler( |
| 202 | new ContextThemeWrapper(context, R.style.QSHeaderTheme)); |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 203 | mBroadcastDispatcher = broadcastDispatcher; |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 204 | mCommandQueue = commandQueue; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | @Override |
| 208 | protected void onFinishInflate() { |
| 209 | super.onFinishInflate(); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 210 | |
| 211 | mHeaderQsPanel = findViewById(R.id.quick_qs_panel); |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 212 | mSystemIconsView = findViewById(R.id.quick_status_bar_system_icons); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 213 | mQuickQsStatusIcons = findViewById(R.id.quick_qs_status_icons); |
Evan Laird | 20b87bf | 2018-04-12 09:54:11 -0400 | [diff] [blame] | 214 | StatusIconContainer iconContainer = findViewById(R.id.statusIcons); |
Evan Laird | f435fd2 | 2019-02-15 13:35:45 -0500 | [diff] [blame] | 215 | // Ignore privacy icons because they show in the space above QQS |
| 216 | iconContainer.addIgnoredSlots(getIgnoredIconSlots()); |
Evan Laird | 20b87bf | 2018-04-12 09:54:11 -0400 | [diff] [blame] | 217 | iconContainer.setShouldRestrictIcons(false); |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 218 | mIconManager = new TintedIconManager(iconContainer, mCommandQueue); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 219 | |
Fabian Kozynski | 121adb4 | 2019-04-22 15:10:43 -0400 | [diff] [blame] | 220 | // Views corresponding to the header info section (e.g. ringer and next alarm). |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 221 | mHeaderTextContainerView = findViewById(R.id.header_text_container); |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 222 | mStatusSeparator = findViewById(R.id.status_separator); |
| 223 | mNextAlarmIcon = findViewById(R.id.next_alarm_icon); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 224 | mNextAlarmTextView = findViewById(R.id.next_alarm_text); |
Fabian Kozynski | b1aee81 | 2019-04-04 14:17:48 -0400 | [diff] [blame] | 225 | mNextAlarmContainer = findViewById(R.id.alarm_container); |
| 226 | mNextAlarmContainer.setOnClickListener(this::onClick); |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 227 | mRingerModeIcon = findViewById(R.id.ringer_mode_icon); |
| 228 | mRingerModeTextView = findViewById(R.id.ringer_mode_text); |
Fabian Kozynski | b1aee81 | 2019-04-04 14:17:48 -0400 | [diff] [blame] | 229 | mRingerContainer = findViewById(R.id.ringer_container); |
| 230 | mRingerContainer.setOnClickListener(this::onClick); |
Fabian Kozynski | 216812e | 2019-02-01 13:49:00 -0500 | [diff] [blame] | 231 | mPrivacyChip = findViewById(R.id.privacy_chip); |
Fabian Kozynski | b1aee81 | 2019-04-04 14:17:48 -0400 | [diff] [blame] | 232 | mPrivacyChip.setOnClickListener(this::onClick); |
Fabian Kozynski | 4e76d1f | 2019-02-25 16:30:04 -0500 | [diff] [blame] | 233 | mCarrierGroup = findViewById(R.id.carrier_group); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 234 | |
Fabian Kozynski | bfd6d85 | 2019-02-15 15:08:16 -0500 | [diff] [blame] | 235 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 236 | updateResources(); |
| 237 | |
Jason Monk | 824ffff | 2017-04-11 15:49:06 -0400 | [diff] [blame] | 238 | Rect tintArea = new Rect(0, 0, 0, 0); |
Jason Chang | b4e879d | 2018-04-11 11:17:58 +0800 | [diff] [blame] | 239 | int colorForeground = Utils.getColorAttrDefaultColor(getContext(), |
| 240 | android.R.attr.colorForeground); |
Amin Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame] | 241 | float intensity = getColorIntensity(colorForeground); |
Fabian Kozynski | f86df99 | 2019-04-22 14:23:47 -0400 | [diff] [blame] | 242 | int fillColor = mDualToneHandler.getSingleColor(intensity); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 243 | |
| 244 | // Set light text on the header icons because they will always be on a black background |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame] | 245 | applyDarkness(R.id.clock, tintArea, 0, DarkIconDispatcher.DEFAULT_ICON_TINT); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 246 | |
| 247 | // Set the correct tint for the status icons so they contrast |
| 248 | mIconManager.setTint(fillColor); |
Fabian Kozynski | f86df99 | 2019-04-22 14:23:47 -0400 | [diff] [blame] | 249 | mNextAlarmIcon.setImageTintList(ColorStateList.valueOf(fillColor)); |
| 250 | mRingerModeIcon.setImageTintList(ColorStateList.valueOf(fillColor)); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 251 | |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 252 | mClockView = findViewById(R.id.clock); |
Amin Shaikh | 39bdc50 | 2018-05-15 23:43:34 -0400 | [diff] [blame] | 253 | mClockView.setOnClickListener(this); |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 254 | mDateView = findViewById(R.id.date); |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 255 | mSpace = findViewById(R.id.space); |
Evan Laird | 4bf21df | 2018-10-22 14:24:32 -0400 | [diff] [blame] | 256 | |
| 257 | // Tint for the battery icons are handled in setupHost() |
| 258 | mBatteryRemainingIcon = findViewById(R.id.batteryRemainingIcon); |
Evan Laird | 698839b | 2018-12-05 15:49:12 -0500 | [diff] [blame] | 259 | // Don't need to worry about tuner settings for this icon |
| 260 | mBatteryRemainingIcon.setIgnoreTunerUpdates(true); |
Evan Laird | 85ee4a3 | 2019-03-06 18:09:20 -0500 | [diff] [blame] | 261 | // QS will always show the estimate, and BatteryMeterView handles the case where |
| 262 | // it's unavailable or charging |
| 263 | mBatteryRemainingIcon.setPercentShowMode(BatteryMeterView.MODE_ESTIMATE); |
Fabian Kozynski | b1aee81 | 2019-04-04 14:17:48 -0400 | [diff] [blame] | 264 | mRingerModeTextView.setSelected(true); |
| 265 | mNextAlarmTextView.setSelected(true); |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 266 | |
| 267 | mPermissionsHubEnabled = PrivacyItemControllerKt.isPermissionsHubEnabled(); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 268 | } |
| 269 | |
Evan Laird | f435fd2 | 2019-02-15 13:35:45 -0500 | [diff] [blame] | 270 | private List<String> getIgnoredIconSlots() { |
| 271 | ArrayList<String> ignored = new ArrayList<>(); |
| 272 | ignored.add(mContext.getResources().getString( |
| 273 | com.android.internal.R.string.status_bar_camera)); |
| 274 | ignored.add(mContext.getResources().getString( |
| 275 | com.android.internal.R.string.status_bar_microphone)); |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 276 | if (mPermissionsHubEnabled) { |
| 277 | ignored.add(mContext.getResources().getString( |
| 278 | com.android.internal.R.string.status_bar_location)); |
| 279 | } |
Evan Laird | f435fd2 | 2019-02-15 13:35:45 -0500 | [diff] [blame] | 280 | |
| 281 | return ignored; |
| 282 | } |
| 283 | |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 284 | private void updateStatusText() { |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 285 | boolean changed = updateRingerStatus() || updateAlarmStatus(); |
| 286 | |
| 287 | if (changed) { |
| 288 | boolean alarmVisible = mNextAlarmTextView.getVisibility() == View.VISIBLE; |
| 289 | boolean ringerVisible = mRingerModeTextView.getVisibility() == View.VISIBLE; |
| 290 | mStatusSeparator.setVisibility(alarmVisible && ringerVisible ? View.VISIBLE |
| 291 | : View.GONE); |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 292 | } |
| 293 | } |
| 294 | |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 295 | private void setChipVisibility(boolean chipVisible) { |
Fabian Kozynski | 16b2699 | 2019-05-06 10:18:41 -0400 | [diff] [blame] | 296 | if (chipVisible && mPermissionsHubEnabled) { |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 297 | mPrivacyChip.setVisibility(View.VISIBLE); |
Fabian Kozynski | bfd6d85 | 2019-02-15 15:08:16 -0500 | [diff] [blame] | 298 | // Makes sure that the chip is logged as viewed at most once each time QS is opened |
| 299 | // mListening makes sure that the callback didn't return after the user closed QS |
| 300 | if (!mPrivacyChipLogged && mListening) { |
| 301 | mPrivacyChipLogged = true; |
| 302 | StatsLog.write(StatsLog.PRIVACY_INDICATORS_INTERACTED, |
| 303 | StatsLog.PRIVACY_INDICATORS_INTERACTED__TYPE__CHIP_VIEWED); |
| 304 | } |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 305 | } else { |
| 306 | mPrivacyChip.setVisibility(View.GONE); |
| 307 | } |
| 308 | } |
| 309 | |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 310 | private boolean updateRingerStatus() { |
| 311 | boolean isOriginalVisible = mRingerModeTextView.getVisibility() == View.VISIBLE; |
| 312 | CharSequence originalRingerText = mRingerModeTextView.getText(); |
| 313 | |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 314 | boolean ringerVisible = false; |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 315 | if (!ZenModeConfig.isZenOverridingRinger(mZenController.getZen(), |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 316 | mZenController.getConsolidatedPolicy())) { |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 317 | if (mRingerMode == AudioManager.RINGER_MODE_VIBRATE) { |
Fabian Kozynski | b1aee81 | 2019-04-04 14:17:48 -0400 | [diff] [blame] | 318 | mRingerModeIcon.setImageResource(R.drawable.ic_volume_ringer_vibrate); |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 319 | mRingerModeTextView.setText(R.string.qs_status_phone_vibrate); |
| 320 | ringerVisible = true; |
| 321 | } else if (mRingerMode == AudioManager.RINGER_MODE_SILENT) { |
Fabian Kozynski | b1aee81 | 2019-04-04 14:17:48 -0400 | [diff] [blame] | 322 | mRingerModeIcon.setImageResource(R.drawable.ic_volume_ringer_mute); |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 323 | mRingerModeTextView.setText(R.string.qs_status_phone_muted); |
| 324 | ringerVisible = true; |
| 325 | } |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 326 | } |
| 327 | mRingerModeIcon.setVisibility(ringerVisible ? View.VISIBLE : View.GONE); |
| 328 | mRingerModeTextView.setVisibility(ringerVisible ? View.VISIBLE : View.GONE); |
Fabian Kozynski | ceb057b | 2019-05-17 14:06:38 -0400 | [diff] [blame] | 329 | mRingerContainer.setVisibility(ringerVisible ? View.VISIBLE : View.GONE); |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 330 | |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 331 | return isOriginalVisible != ringerVisible || |
| 332 | !Objects.equals(originalRingerText, mRingerModeTextView.getText()); |
| 333 | } |
| 334 | |
| 335 | private boolean updateAlarmStatus() { |
| 336 | boolean isOriginalVisible = mNextAlarmTextView.getVisibility() == View.VISIBLE; |
| 337 | CharSequence originalAlarmText = mNextAlarmTextView.getText(); |
| 338 | |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 339 | boolean alarmVisible = false; |
| 340 | if (mNextAlarm != null) { |
| 341 | alarmVisible = true; |
| 342 | mNextAlarmTextView.setText(formatNextAlarm(mNextAlarm)); |
| 343 | } |
| 344 | mNextAlarmIcon.setVisibility(alarmVisible ? View.VISIBLE : View.GONE); |
| 345 | mNextAlarmTextView.setVisibility(alarmVisible ? View.VISIBLE : View.GONE); |
Fabian Kozynski | ceb057b | 2019-05-17 14:06:38 -0400 | [diff] [blame] | 346 | mNextAlarmContainer.setVisibility(alarmVisible ? View.VISIBLE : View.GONE); |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 347 | |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 348 | return isOriginalVisible != alarmVisible || |
| 349 | !Objects.equals(originalAlarmText, mNextAlarmTextView.getText()); |
| 350 | } |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 351 | |
Jason Monk | 824ffff | 2017-04-11 15:49:06 -0400 | [diff] [blame] | 352 | private void applyDarkness(int id, Rect tintArea, float intensity, int color) { |
| 353 | View v = findViewById(id); |
| 354 | if (v instanceof DarkReceiver) { |
| 355 | ((DarkReceiver) v).onDarkChanged(tintArea, intensity, color); |
| 356 | } |
| 357 | } |
| 358 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 359 | @Override |
| 360 | protected void onConfigurationChanged(Configuration newConfig) { |
| 361 | super.onConfigurationChanged(newConfig); |
| 362 | updateResources(); |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 363 | |
| 364 | // Update color schemes in landscape to use wallpaperTextColor |
| 365 | boolean shouldUseWallpaperTextColor = |
| 366 | newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE; |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 367 | mClockView.useWallpaperTextColor(shouldUseWallpaperTextColor); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | @Override |
| 371 | public void onRtlPropertiesChanged(int layoutDirection) { |
| 372 | super.onRtlPropertiesChanged(layoutDirection); |
| 373 | updateResources(); |
| 374 | } |
| 375 | |
Evan Laird | 84b9895 | 2018-07-02 17:43:59 -0400 | [diff] [blame] | 376 | /** |
| 377 | * The height of QQS should always be the status bar height + 128dp. This is normally easy, but |
| 378 | * when there is a notch involved the status bar can remain a fixed pixel size. |
| 379 | */ |
| 380 | private void updateMinimumHeight() { |
| 381 | int sbHeight = mContext.getResources().getDimensionPixelSize( |
| 382 | com.android.internal.R.dimen.status_bar_height); |
| 383 | int qqsHeight = mContext.getResources().getDimensionPixelSize( |
| 384 | R.dimen.qs_quick_header_panel_height); |
| 385 | |
| 386 | setMinimumHeight(sbHeight + qqsHeight); |
| 387 | } |
| 388 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 389 | private void updateResources() { |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 390 | Resources resources = mContext.getResources(); |
Evan Laird | 84b9895 | 2018-07-02 17:43:59 -0400 | [diff] [blame] | 391 | updateMinimumHeight(); |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 392 | |
| 393 | // Update height for a few views, especially due to landscape mode restricting space. |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 394 | mHeaderTextContainerView.getLayoutParams().height = |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 395 | resources.getDimensionPixelSize(R.dimen.qs_header_tooltip_height); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 396 | mHeaderTextContainerView.setLayoutParams(mHeaderTextContainerView.getLayoutParams()); |
| 397 | |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 398 | mSystemIconsView.getLayoutParams().height = resources.getDimensionPixelSize( |
| 399 | com.android.internal.R.dimen.quick_qs_offset_height); |
| 400 | mSystemIconsView.setLayoutParams(mSystemIconsView.getLayoutParams()); |
| 401 | |
Evan Laird | 84b9895 | 2018-07-02 17:43:59 -0400 | [diff] [blame] | 402 | FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams(); |
Beth Thibodeau | 07d20c3 | 2019-10-16 13:45:56 -0400 | [diff] [blame] | 403 | |
Evan Laird | 84b9895 | 2018-07-02 17:43:59 -0400 | [diff] [blame] | 404 | if (mQsDisabled) { |
| 405 | lp.height = resources.getDimensionPixelSize( |
| 406 | com.android.internal.R.dimen.quick_qs_offset_height); |
Matt Pietal | 5a19cb6 | 2019-10-30 12:31:07 -0400 | [diff] [blame] | 407 | } else if (useQsMediaPlayer(mContext)) { |
Beth Thibodeau | 07d20c3 | 2019-10-16 13:45:56 -0400 | [diff] [blame] | 408 | lp.height = Math.max(getMinimumHeight(), |
| 409 | resources.getDimensionPixelSize( |
| 410 | com.android.internal.R.dimen.quick_qs_total_height_with_media)); |
Evan Laird | 84b9895 | 2018-07-02 17:43:59 -0400 | [diff] [blame] | 411 | } else { |
| 412 | lp.height = Math.max(getMinimumHeight(), |
| 413 | resources.getDimensionPixelSize( |
Evan Laird | bf3794a | 2018-07-17 15:55:40 -0400 | [diff] [blame] | 414 | com.android.internal.R.dimen.quick_qs_total_height)); |
Evan Laird | 84b9895 | 2018-07-02 17:43:59 -0400 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | setLayoutParams(lp); |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 418 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 419 | updateStatusIconAlphaAnimator(); |
| 420 | updateHeaderTextContainerAlphaAnimator(); |
Fabian Kozynski | 216812e | 2019-02-01 13:49:00 -0500 | [diff] [blame] | 421 | updatePrivacyChipAlphaAnimator(); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 422 | } |
| 423 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 424 | private void updateStatusIconAlphaAnimator() { |
| 425 | mStatusIconsAlphaAnimator = new TouchAnimator.Builder() |
Fabian Kozynski | 0e8449f | 2019-03-14 15:03:48 -0400 | [diff] [blame] | 426 | .addFloat(mQuickQsStatusIcons, "alpha", 1, 0, 0) |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 427 | .build(); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 428 | } |
| 429 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 430 | private void updateHeaderTextContainerAlphaAnimator() { |
| 431 | mHeaderTextContainerAlphaAnimator = new TouchAnimator.Builder() |
Fabian Kozynski | 0e8449f | 2019-03-14 15:03:48 -0400 | [diff] [blame] | 432 | .addFloat(mHeaderTextContainerView, "alpha", 0, 0, 1) |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 433 | .build(); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 434 | } |
| 435 | |
Fabian Kozynski | 216812e | 2019-02-01 13:49:00 -0500 | [diff] [blame] | 436 | private void updatePrivacyChipAlphaAnimator() { |
| 437 | mPrivacyChipAlphaAnimator = new TouchAnimator.Builder() |
| 438 | .addFloat(mPrivacyChip, "alpha", 1, 0, 1) |
| 439 | .build(); |
| 440 | } |
| 441 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 442 | public void setExpanded(boolean expanded) { |
| 443 | if (mExpanded == expanded) return; |
| 444 | mExpanded = expanded; |
| 445 | mHeaderQsPanel.setExpanded(expanded); |
Fabian Kozynski | f3a7701 | 2019-01-09 15:37:30 +0000 | [diff] [blame] | 446 | updateEverything(); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 447 | } |
| 448 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 449 | /** |
| 450 | * Animates the inner contents based on the given expansion details. |
| 451 | * |
Selim Cinek | b0fada6 | 2019-06-17 19:03:59 -0700 | [diff] [blame] | 452 | * @param forceExpanded whether we should show the state expanded forcibly |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 453 | * @param expansionFraction how much the QS panel is expanded/pulled out (up to 1f) |
| 454 | * @param panelTranslationY how much the panel has physically moved down vertically (required |
| 455 | * for keyguard animations only) |
| 456 | */ |
Selim Cinek | b0fada6 | 2019-06-17 19:03:59 -0700 | [diff] [blame] | 457 | public void setExpansion(boolean forceExpanded, float expansionFraction, |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 458 | float panelTranslationY) { |
Selim Cinek | b0fada6 | 2019-06-17 19:03:59 -0700 | [diff] [blame] | 459 | final float keyguardExpansionFraction = forceExpanded ? 1f : expansionFraction; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 460 | if (mStatusIconsAlphaAnimator != null) { |
| 461 | mStatusIconsAlphaAnimator.setPosition(keyguardExpansionFraction); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 462 | } |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 463 | |
Selim Cinek | b0fada6 | 2019-06-17 19:03:59 -0700 | [diff] [blame] | 464 | if (forceExpanded) { |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 465 | // If the keyguard is showing, we want to offset the text so that it comes in at the |
| 466 | // same time as the panel as it slides down. |
| 467 | mHeaderTextContainerView.setTranslationY(panelTranslationY); |
| 468 | } else { |
| 469 | mHeaderTextContainerView.setTranslationY(0f); |
| 470 | } |
| 471 | |
| 472 | if (mHeaderTextContainerAlphaAnimator != null) { |
| 473 | mHeaderTextContainerAlphaAnimator.setPosition(keyguardExpansionFraction); |
Aran Ink | 7dd05dc | 2019-05-31 11:47:23 -0400 | [diff] [blame] | 474 | if (keyguardExpansionFraction > 0) { |
| 475 | mHeaderTextContainerView.setVisibility(VISIBLE); |
| 476 | } else { |
| 477 | mHeaderTextContainerView.setVisibility(INVISIBLE); |
| 478 | } |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 479 | } |
Fabian Kozynski | 216812e | 2019-02-01 13:49:00 -0500 | [diff] [blame] | 480 | if (mPrivacyChipAlphaAnimator != null) { |
| 481 | mPrivacyChip.setExpanded(expansionFraction > 0.5); |
| 482 | mPrivacyChipAlphaAnimator.setPosition(keyguardExpansionFraction); |
| 483 | } |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 484 | } |
| 485 | |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 486 | public void disable(int state1, int state2, boolean animate) { |
| 487 | final boolean disabled = (state2 & DISABLE2_QUICK_SETTINGS) != 0; |
| 488 | if (disabled == mQsDisabled) return; |
| 489 | mQsDisabled = disabled; |
| 490 | mHeaderQsPanel.setDisabledByPolicy(disabled); |
Amin Shaikh | f09450b | 2018-04-06 17:32:45 -0400 | [diff] [blame] | 491 | mHeaderTextContainerView.setVisibility(mQsDisabled ? View.GONE : View.VISIBLE); |
| 492 | mQuickQsStatusIcons.setVisibility(mQsDisabled ? View.GONE : View.VISIBLE); |
| 493 | updateResources(); |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | @Override |
| 497 | public void onAttachedToWindow() { |
Amin Shaikh | a59215a | 2018-04-23 08:52:38 -0400 | [diff] [blame] | 498 | super.onAttachedToWindow(); |
Jason Monk | ea54e8a | 2018-12-20 10:01:48 -0500 | [diff] [blame] | 499 | mStatusBarIconController.addIconGroup(mIconManager); |
Adrian Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 500 | requestApplyInsets(); |
Winson Chung | efaacc3 | 2019-09-25 14:44:05 -0700 | [diff] [blame] | 501 | // Change the ignored slots when DeviceConfig flag changes |
| 502 | DeviceConfig.addOnPropertiesChangedListener(DeviceConfig.NAMESPACE_PRIVACY, |
| 503 | mContext.getMainExecutor(), mPropertiesListener); |
Adrian Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | @Override |
| 507 | public WindowInsets onApplyWindowInsets(WindowInsets insets) { |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 508 | DisplayCutout cutout = insets.getDisplayCutout(); |
Adrian Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 509 | Pair<Integer, Integer> padding = PhoneStatusBarView.cornerCutoutMargins( |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 510 | cutout, getDisplay()); |
Adrian Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 511 | if (padding == null) { |
Amin Shaikh | 7d86b04 | 2018-04-16 16:00:12 -0400 | [diff] [blame] | 512 | mSystemIconsView.setPaddingRelative( |
| 513 | getResources().getDimensionPixelSize(R.dimen.status_bar_padding_start), 0, |
| 514 | getResources().getDimensionPixelSize(R.dimen.status_bar_padding_end), 0); |
Adrian Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 515 | } else { |
Amin Shaikh | 7d86b04 | 2018-04-16 16:00:12 -0400 | [diff] [blame] | 516 | mSystemIconsView.setPadding(padding.first, 0, padding.second, 0); |
| 517 | |
Adrian Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 518 | } |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 519 | LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mSpace.getLayoutParams(); |
| 520 | if (cutout != null) { |
| 521 | Rect topCutout = cutout.getBoundingRectTop(); |
| 522 | if (topCutout.isEmpty()) { |
| 523 | mHasTopCutout = false; |
| 524 | lp.width = 0; |
| 525 | mSpace.setVisibility(View.GONE); |
| 526 | } else { |
| 527 | mHasTopCutout = true; |
| 528 | lp.width = topCutout.width(); |
| 529 | mSpace.setVisibility(View.VISIBLE); |
| 530 | } |
| 531 | } |
| 532 | mSpace.setLayoutParams(lp); |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 533 | setChipVisibility(mPrivacyChip.getVisibility() == View.VISIBLE); |
Adrian Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 534 | return super.onApplyWindowInsets(insets); |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | @Override |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 538 | @VisibleForTesting |
| 539 | public void onDetachedFromWindow() { |
| 540 | setListening(false); |
Jason Monk | ea54e8a | 2018-12-20 10:01:48 -0500 | [diff] [blame] | 541 | mStatusBarIconController.removeIconGroup(mIconManager); |
Winson Chung | efaacc3 | 2019-09-25 14:44:05 -0700 | [diff] [blame] | 542 | DeviceConfig.removeOnPropertiesChangedListener(mPropertiesListener); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 543 | super.onDetachedFromWindow(); |
| 544 | } |
| 545 | |
| 546 | public void setListening(boolean listening) { |
| 547 | if (listening == mListening) { |
| 548 | return; |
| 549 | } |
| 550 | mHeaderQsPanel.setListening(listening); |
| 551 | mListening = listening; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 552 | |
| 553 | if (listening) { |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 554 | mZenController.addCallback(this); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 555 | mAlarmController.addCallback(this); |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 556 | mBroadcastDispatcher.registerReceiver(mRingerReceiver, |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 557 | new IntentFilter(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION)); |
Fabian Kozynski | 04f83eb | 2019-01-22 10:38:40 -0500 | [diff] [blame] | 558 | mPrivacyItemController.addCallback(mPICCallback); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 559 | } else { |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 560 | mZenController.removeCallback(this); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 561 | mAlarmController.removeCallback(this); |
Fabian Kozynski | 04f83eb | 2019-01-22 10:38:40 -0500 | [diff] [blame] | 562 | mPrivacyItemController.removeCallback(mPICCallback); |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 563 | mBroadcastDispatcher.unregisterReceiver(mRingerReceiver); |
Fabian Kozynski | bfd6d85 | 2019-02-15 15:08:16 -0500 | [diff] [blame] | 564 | mPrivacyChipLogged = false; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 565 | } |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 566 | } |
| 567 | |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 568 | @Override |
| 569 | public void onClick(View v) { |
Fabian Kozynski | f3db35c | 2019-04-24 14:37:35 -0400 | [diff] [blame] | 570 | if (v == mClockView) { |
Jason Monk | ea54e8a | 2018-12-20 10:01:48 -0500 | [diff] [blame] | 571 | mActivityStarter.postStartActivityDismissingKeyguard(new Intent( |
Fabian Kozynski | f3db35c | 2019-04-24 14:37:35 -0400 | [diff] [blame] | 572 | AlarmClock.ACTION_SHOW_ALARMS), 0); |
Fabian Kozynski | 1bdb0b9 | 2019-04-26 10:25:30 -0400 | [diff] [blame] | 573 | } else if (v == mNextAlarmContainer && mNextAlarmContainer.isVisibleToUser()) { |
Fabian Kozynski | a354471 | 2019-04-25 17:05:21 -0400 | [diff] [blame] | 574 | if (mNextAlarm.getShowIntent() != null) { |
Fabian Kozynski | f3db35c | 2019-04-24 14:37:35 -0400 | [diff] [blame] | 575 | mActivityStarter.postStartActivityDismissingKeyguard( |
Fabian Kozynski | a354471 | 2019-04-25 17:05:21 -0400 | [diff] [blame] | 576 | mNextAlarm.getShowIntent()); |
Fabian Kozynski | f3db35c | 2019-04-24 14:37:35 -0400 | [diff] [blame] | 577 | } else { |
Fabian Kozynski | a354471 | 2019-04-25 17:05:21 -0400 | [diff] [blame] | 578 | Log.d(TAG, "No PendingIntent for next alarm. Using default intent"); |
Fabian Kozynski | f3db35c | 2019-04-24 14:37:35 -0400 | [diff] [blame] | 579 | mActivityStarter.postStartActivityDismissingKeyguard(new Intent( |
| 580 | AlarmClock.ACTION_SHOW_ALARMS), 0); |
| 581 | } |
Fabian Kozynski | 1263824 | 2018-10-12 15:33:41 -0400 | [diff] [blame] | 582 | } else if (v == mPrivacyChip) { |
Fabian Kozynski | afd5002 | 2019-02-05 09:41:42 -0500 | [diff] [blame] | 583 | // Makes sure that the builder is grabbed as soon as the chip is pressed |
| 584 | PrivacyDialogBuilder builder = mPrivacyChip.getBuilder(); |
| 585 | if (builder.getAppsAndTypes().size() == 0) return; |
Fabian Kozynski | 1263824 | 2018-10-12 15:33:41 -0400 | [diff] [blame] | 586 | Handler mUiHandler = new Handler(Looper.getMainLooper()); |
Fabian Kozynski | bfd6d85 | 2019-02-15 15:08:16 -0500 | [diff] [blame] | 587 | StatsLog.write(StatsLog.PRIVACY_INDICATORS_INTERACTED, |
| 588 | StatsLog.PRIVACY_INDICATORS_INTERACTED__TYPE__CHIP_CLICKED); |
Fabian Kozynski | 1263824 | 2018-10-12 15:33:41 -0400 | [diff] [blame] | 589 | mUiHandler.post(() -> { |
Joel Galenson | f8b6292 | 2019-03-15 12:51:16 -0700 | [diff] [blame] | 590 | mActivityStarter.postStartActivityDismissingKeyguard( |
| 591 | new Intent(Intent.ACTION_REVIEW_ONGOING_PERMISSION_USAGE), 0); |
Fabian Kozynski | 1263824 | 2018-10-12 15:33:41 -0400 | [diff] [blame] | 592 | mHost.collapsePanels(); |
| 593 | }); |
Fabian Kozynski | 1bdb0b9 | 2019-04-26 10:25:30 -0400 | [diff] [blame] | 594 | } else if (v == mRingerContainer && mRingerContainer.isVisibleToUser()) { |
Fabian Kozynski | b1aee81 | 2019-04-04 14:17:48 -0400 | [diff] [blame] | 595 | mActivityStarter.postStartActivityDismissingKeyguard(new Intent( |
| 596 | Settings.ACTION_SOUND_SETTINGS), 0); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 597 | } |
| 598 | } |
| 599 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 600 | @Override |
| 601 | public void onNextAlarmChanged(AlarmManager.AlarmClockInfo nextAlarm) { |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 602 | mNextAlarm = nextAlarm; |
| 603 | updateStatusText(); |
| 604 | } |
Rohan Shah | a160ab1 | 2018-03-09 15:47:36 -0800 | [diff] [blame] | 605 | |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 606 | @Override |
| 607 | public void onZenChanged(int zen) { |
| 608 | updateStatusText(); |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | @Override |
| 612 | public void onConfigChanged(ZenModeConfig config) { |
| 613 | updateStatusText(); |
| 614 | } |
| 615 | |
Fabian Kozynski | f3a7701 | 2019-01-09 15:37:30 +0000 | [diff] [blame] | 616 | public void updateEverything() { |
Fabian Kozynski | 9a15b7c | 2019-01-10 11:13:27 -0500 | [diff] [blame] | 617 | post(() -> setClickable(!mExpanded)); |
Fabian Kozynski | f3a7701 | 2019-01-09 15:37:30 +0000 | [diff] [blame] | 618 | } |
| 619 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 620 | public void setQSPanel(final QSPanel qsPanel) { |
| 621 | mQsPanel = qsPanel; |
| 622 | setupHost(qsPanel.getHost()); |
| 623 | } |
| 624 | |
| 625 | public void setupHost(final QSTileHost host) { |
| 626 | mHost = host; |
| 627 | //host.setHeaderView(mExpandIndicator); |
| 628 | mHeaderQsPanel.setQSPanelAndHeader(mQsPanel, this); |
| 629 | mHeaderQsPanel.setHost(host, null /* No customization in header */); |
Evan Laird | ef160f2 | 2018-01-29 14:08:45 -0500 | [diff] [blame] | 630 | |
Evan Laird | 4bf21df | 2018-10-22 14:24:32 -0400 | [diff] [blame] | 631 | |
| 632 | Rect tintArea = new Rect(0, 0, 0, 0); |
| 633 | int colorForeground = Utils.getColorAttrDefaultColor(getContext(), |
| 634 | android.R.attr.colorForeground); |
| 635 | float intensity = getColorIntensity(colorForeground); |
Fabian Kozynski | f86df99 | 2019-04-22 14:23:47 -0400 | [diff] [blame] | 636 | int fillColor = mDualToneHandler.getSingleColor(intensity); |
Evan Laird | 4bf21df | 2018-10-22 14:24:32 -0400 | [diff] [blame] | 637 | mBatteryRemainingIcon.onDarkChanged(tintArea, intensity, fillColor); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | public void setCallback(Callback qsPanelCallback) { |
| 641 | mHeaderQsPanel.setCallback(qsPanelCallback); |
| 642 | } |
Lucas Dupin | 1f7374a | 2018-02-26 18:08:33 -0800 | [diff] [blame] | 643 | |
| 644 | private String formatNextAlarm(AlarmManager.AlarmClockInfo info) { |
| 645 | if (info == null) { |
| 646 | return ""; |
| 647 | } |
| 648 | String skeleton = android.text.format.DateFormat |
| 649 | .is24HourFormat(mContext, ActivityManager.getCurrentUser()) ? "EHm" : "Ehma"; |
| 650 | String pattern = android.text.format.DateFormat |
| 651 | .getBestDateTimePattern(Locale.getDefault(), skeleton); |
| 652 | return android.text.format.DateFormat.format(pattern, info.getTriggerTime()).toString(); |
| 653 | } |
Amin Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame] | 654 | |
| 655 | public static float getColorIntensity(@ColorInt int color) { |
| 656 | return color == Color.WHITE ? 0 : 1; |
| 657 | } |
Amin Shaikh | 50d2d1e | 2018-04-25 14:48:13 -0400 | [diff] [blame] | 658 | |
| 659 | public void setMargins(int sideMargins) { |
| 660 | for (int i = 0; i < getChildCount(); i++) { |
| 661 | View v = getChildAt(i); |
Fabian Kozynski | b1aee81 | 2019-04-04 14:17:48 -0400 | [diff] [blame] | 662 | // Prevents these views from getting set a margin. |
| 663 | // The Icon views all have the same padding set in XML to be aligned. |
Fabian Kozynski | ef12449 | 2018-11-02 11:02:11 -0400 | [diff] [blame] | 664 | if (v == mSystemIconsView || v == mQuickQsStatusIcons || v == mHeaderQsPanel |
Fabian Kozynski | b1aee81 | 2019-04-04 14:17:48 -0400 | [diff] [blame] | 665 | || v == mHeaderTextContainerView) { |
Amin Shaikh | 50d2d1e | 2018-04-25 14:48:13 -0400 | [diff] [blame] | 666 | continue; |
| 667 | } |
| 668 | RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) v.getLayoutParams(); |
| 669 | lp.leftMargin = sideMargins; |
| 670 | lp.rightMargin = sideMargins; |
| 671 | } |
| 672 | } |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 673 | } |