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; |
| 20 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 21 | import android.animation.Animator; |
| 22 | import android.animation.AnimatorListenerAdapter; |
Amin Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame] | 23 | import android.annotation.ColorInt; |
Lucas Dupin | 1f7374a | 2018-02-26 18:08:33 -0800 | [diff] [blame] | 24 | import android.app.ActivityManager; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 25 | import android.app.AlarmManager; |
Fabian Kozynski | 1263824 | 2018-10-12 15:33:41 -0400 | [diff] [blame] | 26 | import android.app.Dialog; |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 27 | import android.content.BroadcastReceiver; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 28 | import android.content.Context; |
Evan Laird | 4ea2a49 | 2018-01-22 11:29:12 -0500 | [diff] [blame] | 29 | import android.content.Intent; |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 30 | import android.content.IntentFilter; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 31 | import android.content.res.Configuration; |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 32 | import android.content.res.Resources; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 33 | import android.graphics.Color; |
| 34 | import android.graphics.Rect; |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 35 | import android.media.AudioManager; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 36 | import android.os.Handler; |
Fabian Kozynski | 1263824 | 2018-10-12 15:33:41 -0400 | [diff] [blame] | 37 | import android.os.Looper; |
Evan Laird | 4ea2a49 | 2018-01-22 11:29:12 -0500 | [diff] [blame] | 38 | import android.provider.AlarmClock; |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 39 | import android.service.notification.ZenModeConfig; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 40 | import android.text.format.DateUtils; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 41 | import android.util.AttributeSet; |
Rohan Shah | a160ab1 | 2018-03-09 15:47:36 -0800 | [diff] [blame] | 42 | import android.util.Log; |
Adrian Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 43 | import android.util.Pair; |
Fabian Kozynski | bfd6d85 | 2019-02-15 15:08:16 -0500 | [diff] [blame] | 44 | import android.util.StatsLog; |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 45 | import android.view.DisplayCutout; |
Jason Monk | 824ffff | 2017-04-11 15:49:06 -0400 | [diff] [blame] | 46 | import android.view.View; |
Adrian Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 47 | import android.view.WindowInsets; |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 48 | import android.widget.FrameLayout; |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 49 | import android.widget.ImageView; |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 50 | import android.widget.LinearLayout; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 51 | import android.widget.RelativeLayout; |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 52 | import android.widget.Space; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 53 | import android.widget.TextView; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 54 | |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 55 | import androidx.annotation.VisibleForTesting; |
| 56 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 57 | import com.android.settingslib.Utils; |
| 58 | import com.android.systemui.BatteryMeterView; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 59 | import com.android.systemui.Prefs; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 60 | import com.android.systemui.R; |
| 61 | import com.android.systemui.plugins.ActivityStarter; |
Beverly | 1be62f4 | 2018-12-19 17:17:48 -0500 | [diff] [blame] | 62 | import com.android.systemui.plugins.DarkIconDispatcher; |
| 63 | import com.android.systemui.plugins.DarkIconDispatcher.DarkReceiver; |
Fabian Kozynski | 1263824 | 2018-10-12 15:33:41 -0400 | [diff] [blame] | 64 | import com.android.systemui.privacy.OngoingPrivacyChip; |
| 65 | import com.android.systemui.privacy.OngoingPrivacyDialog; |
Fabian Kozynski | afd5002 | 2019-02-05 09:41:42 -0500 | [diff] [blame] | 66 | import com.android.systemui.privacy.PrivacyDialogBuilder; |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 67 | import com.android.systemui.privacy.PrivacyItem; |
| 68 | import com.android.systemui.privacy.PrivacyItemController; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 69 | import com.android.systemui.qs.QSDetail.Callback; |
Adrian Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 70 | import com.android.systemui.statusbar.phone.PhoneStatusBarView; |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 71 | import com.android.systemui.statusbar.phone.StatusBarIconController; |
| 72 | import com.android.systemui.statusbar.phone.StatusBarIconController.TintedIconManager; |
Evan Laird | 20b87bf | 2018-04-12 09:54:11 -0400 | [diff] [blame] | 73 | import com.android.systemui.statusbar.phone.StatusIconContainer; |
Fabian Kozynski | 1263824 | 2018-10-12 15:33:41 -0400 | [diff] [blame] | 74 | import com.android.systemui.statusbar.phone.SystemUIDialog; |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 75 | import com.android.systemui.statusbar.policy.Clock; |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 76 | import com.android.systemui.statusbar.policy.DateView; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 77 | import com.android.systemui.statusbar.policy.NextAlarmController; |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 78 | import com.android.systemui.statusbar.policy.ZenModeController; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 79 | |
Evan Laird | f435fd2 | 2019-02-15 13:35:45 -0500 | [diff] [blame] | 80 | import java.util.ArrayList; |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 81 | import java.util.List; |
Lucas Dupin | 1f7374a | 2018-02-26 18:08:33 -0800 | [diff] [blame] | 82 | import java.util.Locale; |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 83 | import java.util.Objects; |
Lucas Dupin | 1f7374a | 2018-02-26 18:08:33 -0800 | [diff] [blame] | 84 | |
Jason Monk | ea54e8a | 2018-12-20 10:01:48 -0500 | [diff] [blame] | 85 | import javax.inject.Inject; |
| 86 | import javax.inject.Named; |
| 87 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 88 | /** |
| 89 | * View that contains the top-most bits of the screen (primarily the status bar with date, time, and |
| 90 | * battery) and also contains the {@link QuickQSPanel} along with some of the panel's inner |
| 91 | * contents. |
| 92 | */ |
Amin Shaikh | f09450b | 2018-04-06 17:32:45 -0400 | [diff] [blame] | 93 | public class QuickStatusBarHeader extends RelativeLayout implements |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 94 | View.OnClickListener, NextAlarmController.NextAlarmChangeCallback, |
| 95 | ZenModeController.Callback { |
Rohan Shah | a160ab1 | 2018-03-09 15:47:36 -0800 | [diff] [blame] | 96 | private static final String TAG = "QuickStatusBarHeader"; |
| 97 | private static final boolean DEBUG = false; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 98 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 99 | /** Delay for auto fading out the long press tooltip after it's fully visible (in ms). */ |
| 100 | private static final long AUTO_FADE_OUT_DELAY_MS = DateUtils.SECOND_IN_MILLIS * 6; |
| 101 | private static final int FADE_ANIMATION_DURATION_MS = 300; |
| 102 | private static final int TOOLTIP_NOT_YET_SHOWN_COUNT = 0; |
Rohan Shah | b6a915c | 2018-03-01 11:57:00 -0800 | [diff] [blame] | 103 | public static final int MAX_TOOLTIP_SHOWN_COUNT = 2; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 104 | |
| 105 | private final Handler mHandler = new Handler(); |
Jason Monk | ea54e8a | 2018-12-20 10:01:48 -0500 | [diff] [blame] | 106 | private final NextAlarmController mAlarmController; |
| 107 | private final ZenModeController mZenController; |
| 108 | private final StatusBarIconController mStatusBarIconController; |
| 109 | private final ActivityStarter mActivityStarter; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 110 | |
| 111 | private QSPanel mQsPanel; |
| 112 | |
| 113 | private boolean mExpanded; |
| 114 | private boolean mListening; |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 115 | private boolean mQsDisabled; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 116 | |
Fabian Kozynski | 4e76d1f | 2019-02-25 16:30:04 -0500 | [diff] [blame] | 117 | private QSCarrierGroup mCarrierGroup; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 118 | protected QuickQSPanel mHeaderQsPanel; |
| 119 | protected QSTileHost mHost; |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 120 | private TintedIconManager mIconManager; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 121 | private TouchAnimator mStatusIconsAlphaAnimator; |
| 122 | private TouchAnimator mHeaderTextContainerAlphaAnimator; |
Fabian Kozynski | 216812e | 2019-02-01 13:49:00 -0500 | [diff] [blame] | 123 | private TouchAnimator mPrivacyChipAlphaAnimator; |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 124 | |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 125 | private View mSystemIconsView; |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 126 | private View mQuickQsStatusIcons; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 127 | private View mHeaderTextContainerView; |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 128 | /** View containing the next alarm and ringer mode info. */ |
| 129 | private View mStatusContainer; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 130 | /** Tooltip for educating users that they can long press on icons to see more details. */ |
| 131 | private View mLongPressTooltipView; |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 132 | |
| 133 | private int mRingerMode = AudioManager.RINGER_MODE_NORMAL; |
| 134 | private AlarmManager.AlarmClockInfo mNextAlarm; |
| 135 | |
| 136 | private ImageView mNextAlarmIcon; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 137 | /** {@link TextView} containing the actual text indicating when the next alarm will go off. */ |
| 138 | private TextView mNextAlarmTextView; |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 139 | private View mStatusSeparator; |
| 140 | private ImageView mRingerModeIcon; |
| 141 | private TextView mRingerModeTextView; |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 142 | private Clock mClockView; |
| 143 | private DateView mDateView; |
Fabian Kozynski | 1263824 | 2018-10-12 15:33:41 -0400 | [diff] [blame] | 144 | private OngoingPrivacyChip mPrivacyChip; |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 145 | private Space mSpace; |
Evan Laird | 4bf21df | 2018-10-22 14:24:32 -0400 | [diff] [blame] | 146 | private BatteryMeterView mBatteryRemainingIcon; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 147 | |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 148 | private PrivacyItemController mPrivacyItemController; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 149 | /** Counts how many times the long press tooltip has been shown to the user. */ |
| 150 | private int mShownCount; |
| 151 | |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 152 | private final BroadcastReceiver mRingerReceiver = new BroadcastReceiver() { |
| 153 | @Override |
| 154 | public void onReceive(Context context, Intent intent) { |
| 155 | mRingerMode = intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1); |
| 156 | updateStatusText(); |
| 157 | } |
| 158 | }; |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 159 | private boolean mHasTopCutout = false; |
Fabian Kozynski | bfd6d85 | 2019-02-15 15:08:16 -0500 | [diff] [blame] | 160 | private boolean mPrivacyChipLogged = false; |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 161 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 162 | /** |
| 163 | * Runnable for automatically fading out the long press tooltip (as if it were animating away). |
| 164 | */ |
| 165 | private final Runnable mAutoFadeOutTooltipRunnable = () -> hideLongPressTooltip(false); |
Evan Laird | 4ea2a49 | 2018-01-22 11:29:12 -0500 | [diff] [blame] | 166 | |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 167 | private PrivacyItemController.Callback mPICCallback = new PrivacyItemController.Callback() { |
| 168 | @Override |
| 169 | public void privacyChanged(List<PrivacyItem> privacyItems) { |
| 170 | mPrivacyChip.setPrivacyList(privacyItems); |
| 171 | setChipVisibility(!privacyItems.isEmpty()); |
| 172 | } |
| 173 | }; |
| 174 | |
Jason Monk | ea54e8a | 2018-12-20 10:01:48 -0500 | [diff] [blame] | 175 | @Inject |
| 176 | public QuickStatusBarHeader(@Named(VIEW_CONTEXT) Context context, AttributeSet attrs, |
| 177 | NextAlarmController nextAlarmController, ZenModeController zenModeController, |
Evan Laird | 85ee4a3 | 2019-03-06 18:09:20 -0500 | [diff] [blame] | 178 | StatusBarIconController statusBarIconController, |
Fabian Kozynski | 04f83eb | 2019-01-22 10:38:40 -0500 | [diff] [blame] | 179 | ActivityStarter activityStarter, PrivacyItemController privacyItemController) { |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 180 | super(context, attrs); |
Jason Monk | ea54e8a | 2018-12-20 10:01:48 -0500 | [diff] [blame] | 181 | mAlarmController = nextAlarmController; |
| 182 | mZenController = zenModeController; |
Jason Monk | ea54e8a | 2018-12-20 10:01:48 -0500 | [diff] [blame] | 183 | mStatusBarIconController = statusBarIconController; |
| 184 | mActivityStarter = activityStarter; |
Fabian Kozynski | 04f83eb | 2019-01-22 10:38:40 -0500 | [diff] [blame] | 185 | mPrivacyItemController = privacyItemController; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 186 | mShownCount = getStoredShownCount(); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | @Override |
| 190 | protected void onFinishInflate() { |
| 191 | super.onFinishInflate(); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 192 | |
| 193 | mHeaderQsPanel = findViewById(R.id.quick_qs_panel); |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 194 | mSystemIconsView = findViewById(R.id.quick_status_bar_system_icons); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 195 | mQuickQsStatusIcons = findViewById(R.id.quick_qs_status_icons); |
Evan Laird | 20b87bf | 2018-04-12 09:54:11 -0400 | [diff] [blame] | 196 | StatusIconContainer iconContainer = findViewById(R.id.statusIcons); |
Evan Laird | f435fd2 | 2019-02-15 13:35:45 -0500 | [diff] [blame] | 197 | // Ignore privacy icons because they show in the space above QQS |
| 198 | iconContainer.addIgnoredSlots(getIgnoredIconSlots()); |
Evan Laird | 20b87bf | 2018-04-12 09:54:11 -0400 | [diff] [blame] | 199 | iconContainer.setShouldRestrictIcons(false); |
| 200 | mIconManager = new TintedIconManager(iconContainer); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 201 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 202 | // Views corresponding to the header info section (e.g. tooltip and next alarm). |
| 203 | mHeaderTextContainerView = findViewById(R.id.header_text_container); |
| 204 | mLongPressTooltipView = findViewById(R.id.long_press_tooltip); |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 205 | mStatusContainer = findViewById(R.id.status_container); |
| 206 | mStatusSeparator = findViewById(R.id.status_separator); |
| 207 | mNextAlarmIcon = findViewById(R.id.next_alarm_icon); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 208 | mNextAlarmTextView = findViewById(R.id.next_alarm_text); |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 209 | mRingerModeIcon = findViewById(R.id.ringer_mode_icon); |
| 210 | mRingerModeTextView = findViewById(R.id.ringer_mode_text); |
Fabian Kozynski | 216812e | 2019-02-01 13:49:00 -0500 | [diff] [blame] | 211 | mPrivacyChip = findViewById(R.id.privacy_chip); |
| 212 | mPrivacyChip.setOnClickListener(this); |
Fabian Kozynski | 4e76d1f | 2019-02-25 16:30:04 -0500 | [diff] [blame] | 213 | mCarrierGroup = findViewById(R.id.carrier_group); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 214 | |
Fabian Kozynski | bfd6d85 | 2019-02-15 15:08:16 -0500 | [diff] [blame] | 215 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 216 | updateResources(); |
| 217 | |
Jason Monk | 824ffff | 2017-04-11 15:49:06 -0400 | [diff] [blame] | 218 | Rect tintArea = new Rect(0, 0, 0, 0); |
Jason Chang | b4e879d | 2018-04-11 11:17:58 +0800 | [diff] [blame] | 219 | int colorForeground = Utils.getColorAttrDefaultColor(getContext(), |
| 220 | android.R.attr.colorForeground); |
Amin Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame] | 221 | float intensity = getColorIntensity(colorForeground); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 222 | int fillColor = fillColorForIntensity(intensity, getContext()); |
| 223 | |
| 224 | // 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] | 225 | applyDarkness(R.id.clock, tintArea, 0, DarkIconDispatcher.DEFAULT_ICON_TINT); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 226 | |
| 227 | // Set the correct tint for the status icons so they contrast |
| 228 | mIconManager.setTint(fillColor); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 229 | |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 230 | mClockView = findViewById(R.id.clock); |
Amin Shaikh | 39bdc50 | 2018-05-15 23:43:34 -0400 | [diff] [blame] | 231 | mClockView.setOnClickListener(this); |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 232 | mDateView = findViewById(R.id.date); |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 233 | mSpace = findViewById(R.id.space); |
Evan Laird | 4bf21df | 2018-10-22 14:24:32 -0400 | [diff] [blame] | 234 | |
| 235 | // Tint for the battery icons are handled in setupHost() |
| 236 | mBatteryRemainingIcon = findViewById(R.id.batteryRemainingIcon); |
Evan Laird | 698839b | 2018-12-05 15:49:12 -0500 | [diff] [blame] | 237 | // Don't need to worry about tuner settings for this icon |
| 238 | mBatteryRemainingIcon.setIgnoreTunerUpdates(true); |
Evan Laird | 85ee4a3 | 2019-03-06 18:09:20 -0500 | [diff] [blame] | 239 | // QS will always show the estimate, and BatteryMeterView handles the case where |
| 240 | // it's unavailable or charging |
| 241 | mBatteryRemainingIcon.setPercentShowMode(BatteryMeterView.MODE_ESTIMATE); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 242 | } |
| 243 | |
Evan Laird | f435fd2 | 2019-02-15 13:35:45 -0500 | [diff] [blame] | 244 | private List<String> getIgnoredIconSlots() { |
| 245 | ArrayList<String> ignored = new ArrayList<>(); |
| 246 | ignored.add(mContext.getResources().getString( |
| 247 | com.android.internal.R.string.status_bar_camera)); |
| 248 | ignored.add(mContext.getResources().getString( |
| 249 | com.android.internal.R.string.status_bar_microphone)); |
| 250 | ignored.add(mContext.getResources().getString( |
| 251 | com.android.internal.R.string.status_bar_location)); |
| 252 | |
| 253 | return ignored; |
| 254 | } |
| 255 | |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 256 | private void updateStatusText() { |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 257 | boolean changed = updateRingerStatus() || updateAlarmStatus(); |
| 258 | |
| 259 | if (changed) { |
| 260 | boolean alarmVisible = mNextAlarmTextView.getVisibility() == View.VISIBLE; |
| 261 | boolean ringerVisible = mRingerModeTextView.getVisibility() == View.VISIBLE; |
| 262 | mStatusSeparator.setVisibility(alarmVisible && ringerVisible ? View.VISIBLE |
| 263 | : View.GONE); |
| 264 | updateTooltipShow(); |
| 265 | } |
| 266 | } |
| 267 | |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 268 | private void setChipVisibility(boolean chipVisible) { |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 269 | if (chipVisible) { |
| 270 | mPrivacyChip.setVisibility(View.VISIBLE); |
Fabian Kozynski | bfd6d85 | 2019-02-15 15:08:16 -0500 | [diff] [blame] | 271 | // Makes sure that the chip is logged as viewed at most once each time QS is opened |
| 272 | // mListening makes sure that the callback didn't return after the user closed QS |
| 273 | if (!mPrivacyChipLogged && mListening) { |
| 274 | mPrivacyChipLogged = true; |
| 275 | StatsLog.write(StatsLog.PRIVACY_INDICATORS_INTERACTED, |
| 276 | StatsLog.PRIVACY_INDICATORS_INTERACTED__TYPE__CHIP_VIEWED); |
| 277 | } |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 278 | } else { |
| 279 | mPrivacyChip.setVisibility(View.GONE); |
| 280 | } |
| 281 | } |
| 282 | |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 283 | private boolean updateRingerStatus() { |
| 284 | boolean isOriginalVisible = mRingerModeTextView.getVisibility() == View.VISIBLE; |
| 285 | CharSequence originalRingerText = mRingerModeTextView.getText(); |
| 286 | |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 287 | boolean ringerVisible = false; |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 288 | if (!ZenModeConfig.isZenOverridingRinger(mZenController.getZen(), |
Beverly | ff2df9b | 2018-10-10 16:54:10 -0400 | [diff] [blame] | 289 | mZenController.getConsolidatedPolicy())) { |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 290 | if (mRingerMode == AudioManager.RINGER_MODE_VIBRATE) { |
| 291 | mRingerModeIcon.setImageResource(R.drawable.stat_sys_ringer_vibrate); |
| 292 | mRingerModeTextView.setText(R.string.qs_status_phone_vibrate); |
| 293 | ringerVisible = true; |
| 294 | } else if (mRingerMode == AudioManager.RINGER_MODE_SILENT) { |
| 295 | mRingerModeIcon.setImageResource(R.drawable.stat_sys_ringer_silent); |
| 296 | mRingerModeTextView.setText(R.string.qs_status_phone_muted); |
| 297 | ringerVisible = true; |
| 298 | } |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 299 | } |
| 300 | mRingerModeIcon.setVisibility(ringerVisible ? View.VISIBLE : View.GONE); |
| 301 | mRingerModeTextView.setVisibility(ringerVisible ? View.VISIBLE : View.GONE); |
| 302 | |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 303 | return isOriginalVisible != ringerVisible || |
| 304 | !Objects.equals(originalRingerText, mRingerModeTextView.getText()); |
| 305 | } |
| 306 | |
| 307 | private boolean updateAlarmStatus() { |
| 308 | boolean isOriginalVisible = mNextAlarmTextView.getVisibility() == View.VISIBLE; |
| 309 | CharSequence originalAlarmText = mNextAlarmTextView.getText(); |
| 310 | |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 311 | boolean alarmVisible = false; |
| 312 | if (mNextAlarm != null) { |
| 313 | alarmVisible = true; |
| 314 | mNextAlarmTextView.setText(formatNextAlarm(mNextAlarm)); |
| 315 | } |
| 316 | mNextAlarmIcon.setVisibility(alarmVisible ? View.VISIBLE : View.GONE); |
| 317 | mNextAlarmTextView.setVisibility(alarmVisible ? View.VISIBLE : View.GONE); |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 318 | |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 319 | return isOriginalVisible != alarmVisible || |
| 320 | !Objects.equals(originalAlarmText, mNextAlarmTextView.getText()); |
| 321 | } |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 322 | |
Jason Monk | 824ffff | 2017-04-11 15:49:06 -0400 | [diff] [blame] | 323 | private void applyDarkness(int id, Rect tintArea, float intensity, int color) { |
| 324 | View v = findViewById(id); |
| 325 | if (v instanceof DarkReceiver) { |
| 326 | ((DarkReceiver) v).onDarkChanged(tintArea, intensity, color); |
| 327 | } |
| 328 | } |
| 329 | |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 330 | private int fillColorForIntensity(float intensity, Context context) { |
| 331 | if (intensity == 0) { |
Amin Shaikh | 9cac338 | 2018-04-11 17:10:07 -0400 | [diff] [blame] | 332 | return context.getColor(R.color.light_mode_icon_color_single_tone); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 333 | } |
Amin Shaikh | 9cac338 | 2018-04-11 17:10:07 -0400 | [diff] [blame] | 334 | return context.getColor(R.color.dark_mode_icon_color_single_tone); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 335 | } |
| 336 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 337 | @Override |
| 338 | protected void onConfigurationChanged(Configuration newConfig) { |
| 339 | super.onConfigurationChanged(newConfig); |
| 340 | updateResources(); |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 341 | |
| 342 | // Update color schemes in landscape to use wallpaperTextColor |
| 343 | boolean shouldUseWallpaperTextColor = |
| 344 | newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE; |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 345 | mClockView.useWallpaperTextColor(shouldUseWallpaperTextColor); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 346 | } |
| 347 | |
Fabian Kozynski | ef12449 | 2018-11-02 11:02:11 -0400 | [diff] [blame] | 348 | |
| 349 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 350 | @Override |
| 351 | public void onRtlPropertiesChanged(int layoutDirection) { |
| 352 | super.onRtlPropertiesChanged(layoutDirection); |
| 353 | updateResources(); |
| 354 | } |
| 355 | |
Evan Laird | 84b9895 | 2018-07-02 17:43:59 -0400 | [diff] [blame] | 356 | /** |
| 357 | * The height of QQS should always be the status bar height + 128dp. This is normally easy, but |
| 358 | * when there is a notch involved the status bar can remain a fixed pixel size. |
| 359 | */ |
| 360 | private void updateMinimumHeight() { |
| 361 | int sbHeight = mContext.getResources().getDimensionPixelSize( |
| 362 | com.android.internal.R.dimen.status_bar_height); |
| 363 | int qqsHeight = mContext.getResources().getDimensionPixelSize( |
| 364 | R.dimen.qs_quick_header_panel_height); |
| 365 | |
| 366 | setMinimumHeight(sbHeight + qqsHeight); |
| 367 | } |
| 368 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 369 | private void updateResources() { |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 370 | Resources resources = mContext.getResources(); |
Evan Laird | 84b9895 | 2018-07-02 17:43:59 -0400 | [diff] [blame] | 371 | updateMinimumHeight(); |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 372 | |
| 373 | // 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] | 374 | mHeaderTextContainerView.getLayoutParams().height = |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 375 | resources.getDimensionPixelSize(R.dimen.qs_header_tooltip_height); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 376 | mHeaderTextContainerView.setLayoutParams(mHeaderTextContainerView.getLayoutParams()); |
| 377 | |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 378 | mSystemIconsView.getLayoutParams().height = resources.getDimensionPixelSize( |
| 379 | com.android.internal.R.dimen.quick_qs_offset_height); |
| 380 | mSystemIconsView.setLayoutParams(mSystemIconsView.getLayoutParams()); |
| 381 | |
Evan Laird | 84b9895 | 2018-07-02 17:43:59 -0400 | [diff] [blame] | 382 | FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams(); |
| 383 | if (mQsDisabled) { |
| 384 | lp.height = resources.getDimensionPixelSize( |
| 385 | com.android.internal.R.dimen.quick_qs_offset_height); |
| 386 | } else { |
| 387 | lp.height = Math.max(getMinimumHeight(), |
| 388 | resources.getDimensionPixelSize( |
Evan Laird | bf3794a | 2018-07-17 15:55:40 -0400 | [diff] [blame] | 389 | com.android.internal.R.dimen.quick_qs_total_height)); |
Evan Laird | 84b9895 | 2018-07-02 17:43:59 -0400 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | setLayoutParams(lp); |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 393 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 394 | updateStatusIconAlphaAnimator(); |
| 395 | updateHeaderTextContainerAlphaAnimator(); |
Fabian Kozynski | 216812e | 2019-02-01 13:49:00 -0500 | [diff] [blame] | 396 | updatePrivacyChipAlphaAnimator(); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 397 | } |
| 398 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 399 | private void updateStatusIconAlphaAnimator() { |
| 400 | mStatusIconsAlphaAnimator = new TouchAnimator.Builder() |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 401 | .addFloat(mQuickQsStatusIcons, "alpha", 1, 0) |
| 402 | .build(); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 403 | } |
| 404 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 405 | private void updateHeaderTextContainerAlphaAnimator() { |
| 406 | mHeaderTextContainerAlphaAnimator = new TouchAnimator.Builder() |
| 407 | .addFloat(mHeaderTextContainerView, "alpha", 0, 1) |
| 408 | .setStartDelay(.5f) |
| 409 | .build(); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 410 | } |
| 411 | |
Fabian Kozynski | 216812e | 2019-02-01 13:49:00 -0500 | [diff] [blame] | 412 | private void updatePrivacyChipAlphaAnimator() { |
| 413 | mPrivacyChipAlphaAnimator = new TouchAnimator.Builder() |
| 414 | .addFloat(mPrivacyChip, "alpha", 1, 0, 1) |
| 415 | .build(); |
| 416 | } |
| 417 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 418 | public void setExpanded(boolean expanded) { |
| 419 | if (mExpanded == expanded) return; |
| 420 | mExpanded = expanded; |
| 421 | mHeaderQsPanel.setExpanded(expanded); |
Fabian Kozynski | f3a7701 | 2019-01-09 15:37:30 +0000 | [diff] [blame] | 422 | updateEverything(); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 423 | } |
| 424 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 425 | /** |
| 426 | * Animates the inner contents based on the given expansion details. |
| 427 | * |
| 428 | * @param isKeyguardShowing whether or not we're showing the keyguard (a.k.a. lockscreen) |
| 429 | * @param expansionFraction how much the QS panel is expanded/pulled out (up to 1f) |
| 430 | * @param panelTranslationY how much the panel has physically moved down vertically (required |
| 431 | * for keyguard animations only) |
| 432 | */ |
| 433 | public void setExpansion(boolean isKeyguardShowing, float expansionFraction, |
| 434 | float panelTranslationY) { |
| 435 | final float keyguardExpansionFraction = isKeyguardShowing ? 1f : expansionFraction; |
| 436 | if (mStatusIconsAlphaAnimator != null) { |
| 437 | mStatusIconsAlphaAnimator.setPosition(keyguardExpansionFraction); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 438 | } |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 439 | |
| 440 | if (isKeyguardShowing) { |
| 441 | // If the keyguard is showing, we want to offset the text so that it comes in at the |
| 442 | // same time as the panel as it slides down. |
| 443 | mHeaderTextContainerView.setTranslationY(panelTranslationY); |
| 444 | } else { |
| 445 | mHeaderTextContainerView.setTranslationY(0f); |
| 446 | } |
| 447 | |
| 448 | if (mHeaderTextContainerAlphaAnimator != null) { |
| 449 | mHeaderTextContainerAlphaAnimator.setPosition(keyguardExpansionFraction); |
| 450 | } |
Fabian Kozynski | 216812e | 2019-02-01 13:49:00 -0500 | [diff] [blame] | 451 | if (mPrivacyChipAlphaAnimator != null) { |
| 452 | mPrivacyChip.setExpanded(expansionFraction > 0.5); |
| 453 | mPrivacyChipAlphaAnimator.setPosition(keyguardExpansionFraction); |
| 454 | } |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 455 | |
| 456 | // Check the original expansion fraction - we don't want to show the tooltip until the |
| 457 | // panel is pulled all the way out. |
| 458 | if (expansionFraction == 1f) { |
| 459 | // QS is fully expanded, bring in the tooltip. |
| 460 | showLongPressTooltip(); |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | /** Returns the latest stored tooltip shown count from SharedPreferences. */ |
| 465 | private int getStoredShownCount() { |
| 466 | return Prefs.getInt( |
| 467 | mContext, |
| 468 | Prefs.Key.QS_LONG_PRESS_TOOLTIP_SHOWN_COUNT, |
| 469 | TOOLTIP_NOT_YET_SHOWN_COUNT); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 470 | } |
| 471 | |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 472 | public void disable(int state1, int state2, boolean animate) { |
| 473 | final boolean disabled = (state2 & DISABLE2_QUICK_SETTINGS) != 0; |
| 474 | if (disabled == mQsDisabled) return; |
| 475 | mQsDisabled = disabled; |
| 476 | mHeaderQsPanel.setDisabledByPolicy(disabled); |
Amin Shaikh | f09450b | 2018-04-06 17:32:45 -0400 | [diff] [blame] | 477 | mHeaderTextContainerView.setVisibility(mQsDisabled ? View.GONE : View.VISIBLE); |
| 478 | mQuickQsStatusIcons.setVisibility(mQsDisabled ? View.GONE : View.VISIBLE); |
| 479 | updateResources(); |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | @Override |
| 483 | public void onAttachedToWindow() { |
Amin Shaikh | a59215a | 2018-04-23 08:52:38 -0400 | [diff] [blame] | 484 | super.onAttachedToWindow(); |
Jason Monk | ea54e8a | 2018-12-20 10:01:48 -0500 | [diff] [blame] | 485 | mStatusBarIconController.addIconGroup(mIconManager); |
Adrian Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 486 | requestApplyInsets(); |
| 487 | } |
| 488 | |
| 489 | @Override |
| 490 | public WindowInsets onApplyWindowInsets(WindowInsets insets) { |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 491 | DisplayCutout cutout = insets.getDisplayCutout(); |
Adrian Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 492 | Pair<Integer, Integer> padding = PhoneStatusBarView.cornerCutoutMargins( |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 493 | cutout, getDisplay()); |
Adrian Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 494 | if (padding == null) { |
Amin Shaikh | 7d86b04 | 2018-04-16 16:00:12 -0400 | [diff] [blame] | 495 | mSystemIconsView.setPaddingRelative( |
| 496 | getResources().getDimensionPixelSize(R.dimen.status_bar_padding_start), 0, |
| 497 | getResources().getDimensionPixelSize(R.dimen.status_bar_padding_end), 0); |
Adrian Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 498 | } else { |
Amin Shaikh | 7d86b04 | 2018-04-16 16:00:12 -0400 | [diff] [blame] | 499 | mSystemIconsView.setPadding(padding.first, 0, padding.second, 0); |
| 500 | |
Adrian Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 501 | } |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 502 | LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mSpace.getLayoutParams(); |
| 503 | if (cutout != null) { |
| 504 | Rect topCutout = cutout.getBoundingRectTop(); |
| 505 | if (topCutout.isEmpty()) { |
| 506 | mHasTopCutout = false; |
| 507 | lp.width = 0; |
| 508 | mSpace.setVisibility(View.GONE); |
| 509 | } else { |
| 510 | mHasTopCutout = true; |
| 511 | lp.width = topCutout.width(); |
| 512 | mSpace.setVisibility(View.VISIBLE); |
| 513 | } |
| 514 | } |
| 515 | mSpace.setLayoutParams(lp); |
Fabian Kozynski | 8d06c71 | 2018-11-07 10:33:02 -0500 | [diff] [blame] | 516 | setChipVisibility(mPrivacyChip.getVisibility() == View.VISIBLE); |
Adrian Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 517 | return super.onApplyWindowInsets(insets); |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | @Override |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 521 | @VisibleForTesting |
| 522 | public void onDetachedFromWindow() { |
| 523 | setListening(false); |
Jason Monk | ea54e8a | 2018-12-20 10:01:48 -0500 | [diff] [blame] | 524 | mStatusBarIconController.removeIconGroup(mIconManager); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 525 | super.onDetachedFromWindow(); |
| 526 | } |
| 527 | |
| 528 | public void setListening(boolean listening) { |
| 529 | if (listening == mListening) { |
| 530 | return; |
| 531 | } |
| 532 | mHeaderQsPanel.setListening(listening); |
| 533 | mListening = listening; |
Fabian Kozynski | 4e76d1f | 2019-02-25 16:30:04 -0500 | [diff] [blame] | 534 | mCarrierGroup.setListening(mListening); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 535 | |
| 536 | if (listening) { |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 537 | mZenController.addCallback(this); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 538 | mAlarmController.addCallback(this); |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 539 | mContext.registerReceiver(mRingerReceiver, |
| 540 | new IntentFilter(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION)); |
Fabian Kozynski | 04f83eb | 2019-01-22 10:38:40 -0500 | [diff] [blame] | 541 | mPrivacyItemController.addCallback(mPICCallback); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 542 | } else { |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 543 | mZenController.removeCallback(this); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 544 | mAlarmController.removeCallback(this); |
Fabian Kozynski | 04f83eb | 2019-01-22 10:38:40 -0500 | [diff] [blame] | 545 | mPrivacyItemController.removeCallback(mPICCallback); |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 546 | mContext.unregisterReceiver(mRingerReceiver); |
Fabian Kozynski | bfd6d85 | 2019-02-15 15:08:16 -0500 | [diff] [blame] | 547 | mPrivacyChipLogged = false; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 548 | } |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 549 | } |
| 550 | |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 551 | @Override |
| 552 | public void onClick(View v) { |
Amin Shaikh | 39bdc50 | 2018-05-15 23:43:34 -0400 | [diff] [blame] | 553 | if (v == mClockView) { |
Jason Monk | ea54e8a | 2018-12-20 10:01:48 -0500 | [diff] [blame] | 554 | mActivityStarter.postStartActivityDismissingKeyguard(new Intent( |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 555 | AlarmClock.ACTION_SHOW_ALARMS),0); |
Fabian Kozynski | 1263824 | 2018-10-12 15:33:41 -0400 | [diff] [blame] | 556 | } else if (v == mPrivacyChip) { |
Fabian Kozynski | afd5002 | 2019-02-05 09:41:42 -0500 | [diff] [blame] | 557 | // Makes sure that the builder is grabbed as soon as the chip is pressed |
| 558 | PrivacyDialogBuilder builder = mPrivacyChip.getBuilder(); |
| 559 | if (builder.getAppsAndTypes().size() == 0) return; |
Fabian Kozynski | 1263824 | 2018-10-12 15:33:41 -0400 | [diff] [blame] | 560 | Handler mUiHandler = new Handler(Looper.getMainLooper()); |
Fabian Kozynski | bfd6d85 | 2019-02-15 15:08:16 -0500 | [diff] [blame] | 561 | StatsLog.write(StatsLog.PRIVACY_INDICATORS_INTERACTED, |
| 562 | StatsLog.PRIVACY_INDICATORS_INTERACTED__TYPE__CHIP_CLICKED); |
Fabian Kozynski | 1263824 | 2018-10-12 15:33:41 -0400 | [diff] [blame] | 563 | mUiHandler.post(() -> { |
Fabian Kozynski | afd5002 | 2019-02-05 09:41:42 -0500 | [diff] [blame] | 564 | Dialog mDialog = new OngoingPrivacyDialog(mContext, builder).createDialog(); |
Fabian Kozynski | 8f3660e | 2019-02-11 11:02:11 -0500 | [diff] [blame] | 565 | SystemUIDialog.setShowForAllUsers(mDialog, false); |
Fabian Kozynski | 1263824 | 2018-10-12 15:33:41 -0400 | [diff] [blame] | 566 | SystemUIDialog.registerDismissListener(mDialog); |
| 567 | SystemUIDialog.setWindowOnTop(mDialog); |
Fabian Kozynski | 8f3660e | 2019-02-11 11:02:11 -0500 | [diff] [blame] | 568 | mActivityStarter.postQSRunnableDismissingKeyguard(() -> mDialog.show()); |
Fabian Kozynski | 1263824 | 2018-10-12 15:33:41 -0400 | [diff] [blame] | 569 | mHost.collapsePanels(); |
| 570 | }); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 571 | } |
| 572 | } |
| 573 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 574 | @Override |
| 575 | public void onNextAlarmChanged(AlarmManager.AlarmClockInfo nextAlarm) { |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 576 | mNextAlarm = nextAlarm; |
| 577 | updateStatusText(); |
| 578 | } |
Rohan Shah | a160ab1 | 2018-03-09 15:47:36 -0800 | [diff] [blame] | 579 | |
Beverly | b9826dd | 2018-04-12 15:02:45 -0400 | [diff] [blame] | 580 | @Override |
| 581 | public void onZenChanged(int zen) { |
| 582 | updateStatusText(); |
| 583 | |
| 584 | } |
| 585 | |
| 586 | @Override |
| 587 | public void onConfigChanged(ZenModeConfig config) { |
| 588 | updateStatusText(); |
| 589 | } |
| 590 | |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 591 | private void updateTooltipShow() { |
| 592 | if (hasStatusText()) { |
| 593 | hideLongPressTooltip(true /* shouldShowStatusText */); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 594 | } else { |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 595 | hideStatusText(); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 596 | } |
| 597 | updateHeaderTextContainerAlphaAnimator(); |
| 598 | } |
| 599 | |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 600 | private boolean hasStatusText() { |
| 601 | return mNextAlarmTextView.getVisibility() == View.VISIBLE |
| 602 | || mRingerModeTextView.getVisibility() == View.VISIBLE; |
| 603 | } |
| 604 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 605 | /** |
| 606 | * Animates in the long press tooltip (as long as the next alarm text isn't currently occupying |
| 607 | * the space). |
| 608 | */ |
| 609 | public void showLongPressTooltip() { |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 610 | // If we have status text to show, don't bother fading in the tooltip. |
| 611 | if (hasStatusText()) { |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 612 | return; |
| 613 | } |
| 614 | |
| 615 | if (mShownCount < MAX_TOOLTIP_SHOWN_COUNT) { |
| 616 | mLongPressTooltipView.animate().cancel(); |
| 617 | mLongPressTooltipView.setVisibility(View.VISIBLE); |
| 618 | mLongPressTooltipView.animate() |
| 619 | .alpha(1f) |
| 620 | .setDuration(FADE_ANIMATION_DURATION_MS) |
| 621 | .setListener(new AnimatorListenerAdapter() { |
| 622 | @Override |
| 623 | public void onAnimationEnd(Animator animation) { |
| 624 | mHandler.postDelayed( |
| 625 | mAutoFadeOutTooltipRunnable, AUTO_FADE_OUT_DELAY_MS); |
| 626 | } |
| 627 | }) |
| 628 | .start(); |
| 629 | |
| 630 | // Increment and drop the shown count in prefs for the next time we're deciding to |
| 631 | // fade in the tooltip. We first sanity check that the tooltip count hasn't changed yet |
| 632 | // in prefs (say, from a long press). |
| 633 | if (getStoredShownCount() <= mShownCount) { |
| 634 | Prefs.putInt(mContext, Prefs.Key.QS_LONG_PRESS_TOOLTIP_SHOWN_COUNT, ++mShownCount); |
| 635 | } |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | /** |
| 640 | * Fades out the long press tooltip if it's partially visible - short circuits any running |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 641 | * animation. Additionally has the ability to fade in the status info text. |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 642 | * |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 643 | * @param shouldShowStatusText whether we should fade in the status text |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 644 | */ |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 645 | private void hideLongPressTooltip(boolean shouldShowStatusText) { |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 646 | mLongPressTooltipView.animate().cancel(); |
| 647 | if (mLongPressTooltipView.getVisibility() == View.VISIBLE |
| 648 | && mLongPressTooltipView.getAlpha() != 0f) { |
| 649 | mHandler.removeCallbacks(mAutoFadeOutTooltipRunnable); |
| 650 | mLongPressTooltipView.animate() |
| 651 | .alpha(0f) |
| 652 | .setDuration(FADE_ANIMATION_DURATION_MS) |
| 653 | .setListener(new AnimatorListenerAdapter() { |
| 654 | @Override |
| 655 | public void onAnimationEnd(Animator animation) { |
Rohan Shah | a160ab1 | 2018-03-09 15:47:36 -0800 | [diff] [blame] | 656 | if (DEBUG) Log.d(TAG, "hideLongPressTooltip: Hid long press tip"); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 657 | mLongPressTooltipView.setVisibility(View.INVISIBLE); |
| 658 | |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 659 | if (shouldShowStatusText) { |
| 660 | showStatus(); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 661 | } |
| 662 | } |
| 663 | }) |
| 664 | .start(); |
| 665 | } else { |
| 666 | mLongPressTooltipView.setVisibility(View.INVISIBLE); |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 667 | if (shouldShowStatusText) { |
| 668 | showStatus(); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 669 | } |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | /** |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 674 | * Fades in the updated status text. Note that if there's already a status showing, this will |
Fabian Kozynski | 3f78933 | 2018-09-04 16:42:43 -0400 | [diff] [blame] | 675 | * immediately fade it out and fade in the updated status. |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 676 | */ |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 677 | private void showStatus() { |
| 678 | mStatusContainer.setAlpha(0f); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 679 | |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 680 | mStatusContainer.animate() |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 681 | .alpha(1f) |
| 682 | .setDuration(FADE_ANIMATION_DURATION_MS) |
| 683 | .start(); |
| 684 | } |
| 685 | |
Fabian Kozynski | 3f78933 | 2018-09-04 16:42:43 -0400 | [diff] [blame] | 686 | /** Fades out the status text. */ |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 687 | private void hideStatusText() { |
Fabian Kozynski | 3f78933 | 2018-09-04 16:42:43 -0400 | [diff] [blame] | 688 | mStatusContainer.animate() |
| 689 | .alpha(0f) |
| 690 | .setDuration(FADE_ANIMATION_DURATION_MS) |
| 691 | .start(); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 692 | } |
| 693 | |
Fabian Kozynski | f3a7701 | 2019-01-09 15:37:30 +0000 | [diff] [blame] | 694 | public void updateEverything() { |
Fabian Kozynski | 9a15b7c | 2019-01-10 11:13:27 -0500 | [diff] [blame] | 695 | post(() -> setClickable(!mExpanded)); |
Fabian Kozynski | f3a7701 | 2019-01-09 15:37:30 +0000 | [diff] [blame] | 696 | } |
| 697 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 698 | public void setQSPanel(final QSPanel qsPanel) { |
| 699 | mQsPanel = qsPanel; |
| 700 | setupHost(qsPanel.getHost()); |
| 701 | } |
| 702 | |
| 703 | public void setupHost(final QSTileHost host) { |
| 704 | mHost = host; |
| 705 | //host.setHeaderView(mExpandIndicator); |
| 706 | mHeaderQsPanel.setQSPanelAndHeader(mQsPanel, this); |
| 707 | mHeaderQsPanel.setHost(host, null /* No customization in header */); |
Evan Laird | ef160f2 | 2018-01-29 14:08:45 -0500 | [diff] [blame] | 708 | |
Evan Laird | 4bf21df | 2018-10-22 14:24:32 -0400 | [diff] [blame] | 709 | |
| 710 | Rect tintArea = new Rect(0, 0, 0, 0); |
| 711 | int colorForeground = Utils.getColorAttrDefaultColor(getContext(), |
| 712 | android.R.attr.colorForeground); |
| 713 | float intensity = getColorIntensity(colorForeground); |
| 714 | int fillColor = fillColorForIntensity(intensity, getContext()); |
| 715 | mBatteryRemainingIcon.setColorsFromContext(mHost.getContext()); |
| 716 | mBatteryRemainingIcon.onDarkChanged(tintArea, intensity, fillColor); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | public void setCallback(Callback qsPanelCallback) { |
| 720 | mHeaderQsPanel.setCallback(qsPanelCallback); |
| 721 | } |
Lucas Dupin | 1f7374a | 2018-02-26 18:08:33 -0800 | [diff] [blame] | 722 | |
| 723 | private String formatNextAlarm(AlarmManager.AlarmClockInfo info) { |
| 724 | if (info == null) { |
| 725 | return ""; |
| 726 | } |
| 727 | String skeleton = android.text.format.DateFormat |
| 728 | .is24HourFormat(mContext, ActivityManager.getCurrentUser()) ? "EHm" : "Ehma"; |
| 729 | String pattern = android.text.format.DateFormat |
| 730 | .getBestDateTimePattern(Locale.getDefault(), skeleton); |
| 731 | return android.text.format.DateFormat.format(pattern, info.getTriggerTime()).toString(); |
| 732 | } |
Amin Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame] | 733 | |
| 734 | public static float getColorIntensity(@ColorInt int color) { |
| 735 | return color == Color.WHITE ? 0 : 1; |
| 736 | } |
Amin Shaikh | 50d2d1e | 2018-04-25 14:48:13 -0400 | [diff] [blame] | 737 | |
| 738 | public void setMargins(int sideMargins) { |
| 739 | for (int i = 0; i < getChildCount(); i++) { |
| 740 | View v = getChildAt(i); |
Fabian Kozynski | ef12449 | 2018-11-02 11:02:11 -0400 | [diff] [blame] | 741 | if (v == mSystemIconsView || v == mQuickQsStatusIcons || v == mHeaderQsPanel |
| 742 | || v == mPrivacyChip) { |
Amin Shaikh | 50d2d1e | 2018-04-25 14:48:13 -0400 | [diff] [blame] | 743 | continue; |
| 744 | } |
| 745 | RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) v.getLayoutParams(); |
| 746 | lp.leftMargin = sideMargins; |
| 747 | lp.rightMargin = sideMargins; |
| 748 | } |
| 749 | } |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 750 | } |