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