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