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