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