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; |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 24 | import android.content.BroadcastReceiver; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 25 | import android.content.Context; |
Evan Laird | 4ea2a49 | 2018-01-22 11:29:12 -0500 | [diff] [blame] | 26 | import android.content.Intent; |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 27 | import android.content.IntentFilter; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 28 | import android.content.res.Configuration; |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 29 | import android.content.res.Resources; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 30 | import android.graphics.Color; |
| 31 | import android.graphics.Rect; |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 32 | import android.media.AudioManager; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 33 | import android.os.Handler; |
Evan Laird | 4ea2a49 | 2018-01-22 11:29:12 -0500 | [diff] [blame] | 34 | import android.provider.AlarmClock; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 35 | import android.support.annotation.VisibleForTesting; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 36 | import android.text.format.DateUtils; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 37 | import android.util.AttributeSet; |
Rohan Shah | a160ab1 | 2018-03-09 15:47:36 -0800 | [diff] [blame] | 38 | import android.util.Log; |
Adrian Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 39 | import android.util.Pair; |
Jason Monk | 824ffff | 2017-04-11 15:49:06 -0400 | [diff] [blame] | 40 | import android.view.View; |
Adrian Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 41 | import android.view.WindowInsets; |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 42 | import android.widget.ImageView; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 43 | import android.widget.RelativeLayout; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 44 | import android.widget.TextView; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 45 | |
| 46 | import com.android.settingslib.Utils; |
| 47 | import com.android.systemui.BatteryMeterView; |
| 48 | import com.android.systemui.Dependency; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 49 | import com.android.systemui.Prefs; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 50 | import com.android.systemui.R; |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 51 | import com.android.systemui.SysUiServiceProvider; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 52 | import com.android.systemui.plugins.ActivityStarter; |
| 53 | import com.android.systemui.qs.QSDetail.Callback; |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 54 | import com.android.systemui.statusbar.CommandQueue; |
Adrian Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 55 | import com.android.systemui.statusbar.phone.PhoneStatusBarView; |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 56 | import com.android.systemui.statusbar.phone.StatusBarIconController; |
| 57 | import com.android.systemui.statusbar.phone.StatusBarIconController.TintedIconManager; |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 58 | import com.android.systemui.statusbar.policy.Clock; |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame] | 59 | import com.android.systemui.statusbar.policy.DarkIconDispatcher; |
Jason Monk | 824ffff | 2017-04-11 15:49:06 -0400 | [diff] [blame] | 60 | import com.android.systemui.statusbar.policy.DarkIconDispatcher.DarkReceiver; |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 61 | import com.android.systemui.statusbar.policy.DateView; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 62 | import com.android.systemui.statusbar.policy.NextAlarmController; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 63 | |
Lucas Dupin | 1f7374a | 2018-02-26 18:08:33 -0800 | [diff] [blame] | 64 | import java.util.Locale; |
| 65 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 66 | /** |
| 67 | * View that contains the top-most bits of the screen (primarily the status bar with date, time, and |
| 68 | * battery) and also contains the {@link QuickQSPanel} along with some of the panel's inner |
| 69 | * contents. |
| 70 | */ |
Amin Shaikh | f09450b | 2018-04-06 17:32:45 -0400 | [diff] [blame] | 71 | public class QuickStatusBarHeader extends RelativeLayout implements |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 72 | View.OnClickListener, NextAlarmController.NextAlarmChangeCallback { |
Rohan Shah | a160ab1 | 2018-03-09 15:47:36 -0800 | [diff] [blame] | 73 | private static final String TAG = "QuickStatusBarHeader"; |
| 74 | private static final boolean DEBUG = false; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 75 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 76 | /** Delay for auto fading out the long press tooltip after it's fully visible (in ms). */ |
| 77 | private static final long AUTO_FADE_OUT_DELAY_MS = DateUtils.SECOND_IN_MILLIS * 6; |
| 78 | private static final int FADE_ANIMATION_DURATION_MS = 300; |
| 79 | private static final int TOOLTIP_NOT_YET_SHOWN_COUNT = 0; |
Rohan Shah | b6a915c | 2018-03-01 11:57:00 -0800 | [diff] [blame] | 80 | public static final int MAX_TOOLTIP_SHOWN_COUNT = 2; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 81 | |
| 82 | private final Handler mHandler = new Handler(); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 83 | |
| 84 | private QSPanel mQsPanel; |
| 85 | |
| 86 | private boolean mExpanded; |
| 87 | private boolean mListening; |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 88 | private boolean mQsDisabled; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 89 | |
| 90 | protected QuickQSPanel mHeaderQsPanel; |
| 91 | protected QSTileHost mHost; |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 92 | private TintedIconManager mIconManager; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 93 | private TouchAnimator mStatusIconsAlphaAnimator; |
| 94 | private TouchAnimator mHeaderTextContainerAlphaAnimator; |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 95 | |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 96 | private View mSystemIconsView; |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 97 | private View mQuickQsStatusIcons; |
Evan Laird | 4ea2a49 | 2018-01-22 11:29:12 -0500 | [diff] [blame] | 98 | private View mDate; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 99 | private View mHeaderTextContainerView; |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 100 | /** View containing the next alarm and ringer mode info. */ |
| 101 | private View mStatusContainer; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 102 | /** Tooltip for educating users that they can long press on icons to see more details. */ |
| 103 | private View mLongPressTooltipView; |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 104 | |
| 105 | private int mRingerMode = AudioManager.RINGER_MODE_NORMAL; |
| 106 | private AlarmManager.AlarmClockInfo mNextAlarm; |
| 107 | |
| 108 | private ImageView mNextAlarmIcon; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 109 | /** {@link TextView} containing the actual text indicating when the next alarm will go off. */ |
| 110 | private TextView mNextAlarmTextView; |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 111 | private View mStatusSeparator; |
| 112 | private ImageView mRingerModeIcon; |
| 113 | private TextView mRingerModeTextView; |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 114 | private BatteryMeterView mBatteryMeterView; |
| 115 | private Clock mClockView; |
| 116 | private DateView mDateView; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 117 | |
| 118 | private NextAlarmController mAlarmController; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 119 | /** Counts how many times the long press tooltip has been shown to the user. */ |
| 120 | private int mShownCount; |
| 121 | |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 122 | private final BroadcastReceiver mRingerReceiver = new BroadcastReceiver() { |
| 123 | @Override |
| 124 | public void onReceive(Context context, Intent intent) { |
| 125 | mRingerMode = intent.getIntExtra(AudioManager.EXTRA_RINGER_MODE, -1); |
| 126 | updateStatusText(); |
| 127 | } |
| 128 | }; |
| 129 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 130 | /** |
| 131 | * Runnable for automatically fading out the long press tooltip (as if it were animating away). |
| 132 | */ |
| 133 | private final Runnable mAutoFadeOutTooltipRunnable = () -> hideLongPressTooltip(false); |
Evan Laird | 4ea2a49 | 2018-01-22 11:29:12 -0500 | [diff] [blame] | 134 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 135 | public QuickStatusBarHeader(Context context, AttributeSet attrs) { |
| 136 | super(context, attrs); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 137 | mAlarmController = Dependency.get(NextAlarmController.class); |
| 138 | mShownCount = getStoredShownCount(); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | @Override |
| 142 | protected void onFinishInflate() { |
| 143 | super.onFinishInflate(); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 144 | |
| 145 | mHeaderQsPanel = findViewById(R.id.quick_qs_panel); |
Evan Laird | 4ea2a49 | 2018-01-22 11:29:12 -0500 | [diff] [blame] | 146 | mDate = findViewById(R.id.date); |
| 147 | mDate.setOnClickListener(this); |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 148 | mSystemIconsView = findViewById(R.id.quick_status_bar_system_icons); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 149 | mQuickQsStatusIcons = findViewById(R.id.quick_qs_status_icons); |
| 150 | mIconManager = new TintedIconManager(findViewById(R.id.statusIcons)); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 151 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 152 | // Views corresponding to the header info section (e.g. tooltip and next alarm). |
| 153 | mHeaderTextContainerView = findViewById(R.id.header_text_container); |
| 154 | mLongPressTooltipView = findViewById(R.id.long_press_tooltip); |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 155 | mStatusContainer = findViewById(R.id.status_container); |
| 156 | mStatusSeparator = findViewById(R.id.status_separator); |
| 157 | mNextAlarmIcon = findViewById(R.id.next_alarm_icon); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 158 | mNextAlarmTextView = findViewById(R.id.next_alarm_text); |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 159 | mRingerModeIcon = findViewById(R.id.ringer_mode_icon); |
| 160 | mRingerModeTextView = findViewById(R.id.ringer_mode_text); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 161 | |
| 162 | updateResources(); |
| 163 | |
Jason Monk | 824ffff | 2017-04-11 15:49:06 -0400 | [diff] [blame] | 164 | Rect tintArea = new Rect(0, 0, 0, 0); |
Jason Chang | b4e879d | 2018-04-11 11:17:58 +0800 | [diff] [blame^] | 165 | int colorForeground = Utils.getColorAttrDefaultColor(getContext(), |
| 166 | android.R.attr.colorForeground); |
Amin Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame] | 167 | float intensity = getColorIntensity(colorForeground); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 168 | int fillColor = fillColorForIntensity(intensity, getContext()); |
| 169 | |
| 170 | // 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] | 171 | applyDarkness(R.id.clock, tintArea, 0, DarkIconDispatcher.DEFAULT_ICON_TINT); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 172 | |
| 173 | // Set the correct tint for the status icons so they contrast |
| 174 | mIconManager.setTint(fillColor); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 175 | |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 176 | mBatteryMeterView = findViewById(R.id.battery); |
| 177 | mBatteryMeterView.setForceShowPercent(true); |
| 178 | mClockView = findViewById(R.id.clock); |
| 179 | mDateView = findViewById(R.id.date); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 180 | } |
| 181 | |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 182 | private void updateStatusText() { |
| 183 | boolean ringerVisible = false; |
| 184 | if (mRingerMode == AudioManager.RINGER_MODE_VIBRATE) { |
| 185 | mRingerModeIcon.setImageResource(R.drawable.stat_sys_ringer_vibrate); |
Amin Shaikh | e4d25a9 | 2018-03-30 15:30:29 -0400 | [diff] [blame] | 186 | mRingerModeTextView.setText(R.string.qs_status_phone_vibrate); |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 187 | ringerVisible = true; |
| 188 | } else if (mRingerMode == AudioManager.RINGER_MODE_SILENT) { |
| 189 | mRingerModeIcon.setImageResource(R.drawable.stat_sys_ringer_silent); |
Amin Shaikh | e4d25a9 | 2018-03-30 15:30:29 -0400 | [diff] [blame] | 190 | mRingerModeTextView.setText(R.string.qs_status_phone_muted); |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 191 | ringerVisible = true; |
| 192 | } |
| 193 | mRingerModeIcon.setVisibility(ringerVisible ? View.VISIBLE : View.GONE); |
| 194 | mRingerModeTextView.setVisibility(ringerVisible ? View.VISIBLE : View.GONE); |
| 195 | |
| 196 | boolean alarmVisible = false; |
| 197 | if (mNextAlarm != null) { |
| 198 | alarmVisible = true; |
| 199 | mNextAlarmTextView.setText(formatNextAlarm(mNextAlarm)); |
| 200 | } |
| 201 | mNextAlarmIcon.setVisibility(alarmVisible ? View.VISIBLE : View.GONE); |
| 202 | mNextAlarmTextView.setVisibility(alarmVisible ? View.VISIBLE : View.GONE); |
| 203 | mStatusSeparator.setVisibility(alarmVisible && ringerVisible ? View.VISIBLE : View.GONE); |
| 204 | updateTooltipShow(); |
| 205 | } |
| 206 | |
| 207 | |
Jason Monk | 824ffff | 2017-04-11 15:49:06 -0400 | [diff] [blame] | 208 | private void applyDarkness(int id, Rect tintArea, float intensity, int color) { |
| 209 | View v = findViewById(id); |
| 210 | if (v instanceof DarkReceiver) { |
| 211 | ((DarkReceiver) v).onDarkChanged(tintArea, intensity, color); |
| 212 | } |
| 213 | } |
| 214 | |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 215 | private int fillColorForIntensity(float intensity, Context context) { |
| 216 | if (intensity == 0) { |
| 217 | return context.getColor(R.color.light_mode_icon_color_dual_tone_fill); |
| 218 | } |
| 219 | return context.getColor(R.color.dark_mode_icon_color_dual_tone_fill); |
| 220 | } |
| 221 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 222 | @Override |
| 223 | protected void onConfigurationChanged(Configuration newConfig) { |
| 224 | super.onConfigurationChanged(newConfig); |
| 225 | updateResources(); |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 226 | |
| 227 | // Update color schemes in landscape to use wallpaperTextColor |
| 228 | boolean shouldUseWallpaperTextColor = |
| 229 | newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE; |
| 230 | mBatteryMeterView.useWallpaperTextColor(shouldUseWallpaperTextColor); |
| 231 | mClockView.useWallpaperTextColor(shouldUseWallpaperTextColor); |
| 232 | mDateView.useWallpaperTextColor(shouldUseWallpaperTextColor); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | @Override |
| 236 | public void onRtlPropertiesChanged(int layoutDirection) { |
| 237 | super.onRtlPropertiesChanged(layoutDirection); |
| 238 | updateResources(); |
| 239 | } |
| 240 | |
| 241 | private void updateResources() { |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 242 | Resources resources = mContext.getResources(); |
| 243 | |
| 244 | // 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] | 245 | mHeaderTextContainerView.getLayoutParams().height = |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 246 | resources.getDimensionPixelSize(R.dimen.qs_header_tooltip_height); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 247 | mHeaderTextContainerView.setLayoutParams(mHeaderTextContainerView.getLayoutParams()); |
| 248 | |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 249 | mSystemIconsView.getLayoutParams().height = resources.getDimensionPixelSize( |
| 250 | com.android.internal.R.dimen.quick_qs_offset_height); |
| 251 | mSystemIconsView.setLayoutParams(mSystemIconsView.getLayoutParams()); |
| 252 | |
Amin Shaikh | f09450b | 2018-04-06 17:32:45 -0400 | [diff] [blame] | 253 | getLayoutParams().height = resources.getDimensionPixelSize(mQsDisabled |
| 254 | ? com.android.internal.R.dimen.quick_qs_offset_height |
| 255 | : com.android.internal.R.dimen.quick_qs_total_height); |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 256 | setLayoutParams(getLayoutParams()); |
| 257 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 258 | updateStatusIconAlphaAnimator(); |
| 259 | updateHeaderTextContainerAlphaAnimator(); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 260 | } |
| 261 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 262 | private void updateStatusIconAlphaAnimator() { |
| 263 | mStatusIconsAlphaAnimator = new TouchAnimator.Builder() |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 264 | .addFloat(mQuickQsStatusIcons, "alpha", 1, 0) |
| 265 | .build(); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 266 | } |
| 267 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 268 | private void updateHeaderTextContainerAlphaAnimator() { |
| 269 | mHeaderTextContainerAlphaAnimator = new TouchAnimator.Builder() |
| 270 | .addFloat(mHeaderTextContainerView, "alpha", 0, 1) |
| 271 | .setStartDelay(.5f) |
| 272 | .build(); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | public void setExpanded(boolean expanded) { |
| 276 | if (mExpanded == expanded) return; |
| 277 | mExpanded = expanded; |
| 278 | mHeaderQsPanel.setExpanded(expanded); |
| 279 | updateEverything(); |
| 280 | } |
| 281 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 282 | /** |
| 283 | * Animates the inner contents based on the given expansion details. |
| 284 | * |
| 285 | * @param isKeyguardShowing whether or not we're showing the keyguard (a.k.a. lockscreen) |
| 286 | * @param expansionFraction how much the QS panel is expanded/pulled out (up to 1f) |
| 287 | * @param panelTranslationY how much the panel has physically moved down vertically (required |
| 288 | * for keyguard animations only) |
| 289 | */ |
| 290 | public void setExpansion(boolean isKeyguardShowing, float expansionFraction, |
| 291 | float panelTranslationY) { |
| 292 | final float keyguardExpansionFraction = isKeyguardShowing ? 1f : expansionFraction; |
| 293 | if (mStatusIconsAlphaAnimator != null) { |
| 294 | mStatusIconsAlphaAnimator.setPosition(keyguardExpansionFraction); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 295 | } |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 296 | |
| 297 | if (isKeyguardShowing) { |
| 298 | // If the keyguard is showing, we want to offset the text so that it comes in at the |
| 299 | // same time as the panel as it slides down. |
| 300 | mHeaderTextContainerView.setTranslationY(panelTranslationY); |
| 301 | } else { |
| 302 | mHeaderTextContainerView.setTranslationY(0f); |
| 303 | } |
| 304 | |
| 305 | if (mHeaderTextContainerAlphaAnimator != null) { |
| 306 | mHeaderTextContainerAlphaAnimator.setPosition(keyguardExpansionFraction); |
| 307 | } |
| 308 | |
| 309 | // Check the original expansion fraction - we don't want to show the tooltip until the |
| 310 | // panel is pulled all the way out. |
| 311 | if (expansionFraction == 1f) { |
| 312 | // QS is fully expanded, bring in the tooltip. |
| 313 | showLongPressTooltip(); |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | /** Returns the latest stored tooltip shown count from SharedPreferences. */ |
| 318 | private int getStoredShownCount() { |
| 319 | return Prefs.getInt( |
| 320 | mContext, |
| 321 | Prefs.Key.QS_LONG_PRESS_TOOLTIP_SHOWN_COUNT, |
| 322 | TOOLTIP_NOT_YET_SHOWN_COUNT); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 323 | } |
| 324 | |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 325 | public void disable(int state1, int state2, boolean animate) { |
| 326 | final boolean disabled = (state2 & DISABLE2_QUICK_SETTINGS) != 0; |
| 327 | if (disabled == mQsDisabled) return; |
| 328 | mQsDisabled = disabled; |
| 329 | mHeaderQsPanel.setDisabledByPolicy(disabled); |
Amin Shaikh | f09450b | 2018-04-06 17:32:45 -0400 | [diff] [blame] | 330 | mHeaderTextContainerView.setVisibility(mQsDisabled ? View.GONE : View.VISIBLE); |
| 331 | mQuickQsStatusIcons.setVisibility(mQsDisabled ? View.GONE : View.VISIBLE); |
| 332 | updateResources(); |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | @Override |
| 336 | public void onAttachedToWindow() { |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 337 | Dependency.get(StatusBarIconController.class).addIconGroup(mIconManager); |
Adrian Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 338 | requestApplyInsets(); |
| 339 | } |
| 340 | |
| 341 | @Override |
| 342 | public WindowInsets onApplyWindowInsets(WindowInsets insets) { |
| 343 | Pair<Integer, Integer> padding = PhoneStatusBarView.cornerCutoutMargins( |
| 344 | insets.getDisplayCutout(), getDisplay()); |
| 345 | if (padding == null) { |
| 346 | setPadding(0, 0, 0, 0); |
| 347 | } else { |
| 348 | setPadding(padding.first, 0, padding.second, 0); |
| 349 | } |
| 350 | return super.onApplyWindowInsets(insets); |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | @Override |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 354 | @VisibleForTesting |
| 355 | public void onDetachedFromWindow() { |
| 356 | setListening(false); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 357 | Dependency.get(StatusBarIconController.class).removeIconGroup(mIconManager); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 358 | super.onDetachedFromWindow(); |
| 359 | } |
| 360 | |
| 361 | public void setListening(boolean listening) { |
| 362 | if (listening == mListening) { |
| 363 | return; |
| 364 | } |
| 365 | mHeaderQsPanel.setListening(listening); |
| 366 | mListening = listening; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 367 | |
| 368 | if (listening) { |
| 369 | mAlarmController.addCallback(this); |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 370 | mContext.registerReceiver(mRingerReceiver, |
| 371 | new IntentFilter(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION)); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 372 | } else { |
| 373 | mAlarmController.removeCallback(this); |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 374 | mContext.unregisterReceiver(mRingerReceiver); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 375 | } |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 376 | } |
| 377 | |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 378 | @Override |
| 379 | public void onClick(View v) { |
| 380 | if(v == mDate){ |
| 381 | Dependency.get(ActivityStarter.class).postStartActivityDismissingKeyguard(new Intent( |
| 382 | AlarmClock.ACTION_SHOW_ALARMS),0); |
| 383 | } |
| 384 | } |
| 385 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 386 | @Override |
| 387 | public void onNextAlarmChanged(AlarmManager.AlarmClockInfo nextAlarm) { |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 388 | mNextAlarm = nextAlarm; |
| 389 | updateStatusText(); |
| 390 | } |
Rohan Shah | a160ab1 | 2018-03-09 15:47:36 -0800 | [diff] [blame] | 391 | |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 392 | private void updateTooltipShow() { |
| 393 | if (hasStatusText()) { |
| 394 | hideLongPressTooltip(true /* shouldShowStatusText */); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 395 | } else { |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 396 | hideStatusText(); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 397 | } |
| 398 | updateHeaderTextContainerAlphaAnimator(); |
| 399 | } |
| 400 | |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 401 | private boolean hasStatusText() { |
| 402 | return mNextAlarmTextView.getVisibility() == View.VISIBLE |
| 403 | || mRingerModeTextView.getVisibility() == View.VISIBLE; |
| 404 | } |
| 405 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 406 | /** |
| 407 | * Animates in the long press tooltip (as long as the next alarm text isn't currently occupying |
| 408 | * the space). |
| 409 | */ |
| 410 | public void showLongPressTooltip() { |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 411 | // If we have status text to show, don't bother fading in the tooltip. |
| 412 | if (hasStatusText()) { |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 413 | return; |
| 414 | } |
| 415 | |
| 416 | if (mShownCount < MAX_TOOLTIP_SHOWN_COUNT) { |
| 417 | mLongPressTooltipView.animate().cancel(); |
| 418 | mLongPressTooltipView.setVisibility(View.VISIBLE); |
| 419 | mLongPressTooltipView.animate() |
| 420 | .alpha(1f) |
| 421 | .setDuration(FADE_ANIMATION_DURATION_MS) |
| 422 | .setListener(new AnimatorListenerAdapter() { |
| 423 | @Override |
| 424 | public void onAnimationEnd(Animator animation) { |
| 425 | mHandler.postDelayed( |
| 426 | mAutoFadeOutTooltipRunnable, AUTO_FADE_OUT_DELAY_MS); |
| 427 | } |
| 428 | }) |
| 429 | .start(); |
| 430 | |
| 431 | // Increment and drop the shown count in prefs for the next time we're deciding to |
| 432 | // fade in the tooltip. We first sanity check that the tooltip count hasn't changed yet |
| 433 | // in prefs (say, from a long press). |
| 434 | if (getStoredShownCount() <= mShownCount) { |
| 435 | Prefs.putInt(mContext, Prefs.Key.QS_LONG_PRESS_TOOLTIP_SHOWN_COUNT, ++mShownCount); |
| 436 | } |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | /** |
| 441 | * 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] | 442 | * animation. Additionally has the ability to fade in the status info text. |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 443 | * |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 444 | * @param shouldShowStatusText whether we should fade in the status text |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 445 | */ |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 446 | private void hideLongPressTooltip(boolean shouldShowStatusText) { |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 447 | mLongPressTooltipView.animate().cancel(); |
| 448 | if (mLongPressTooltipView.getVisibility() == View.VISIBLE |
| 449 | && mLongPressTooltipView.getAlpha() != 0f) { |
| 450 | mHandler.removeCallbacks(mAutoFadeOutTooltipRunnable); |
| 451 | mLongPressTooltipView.animate() |
| 452 | .alpha(0f) |
| 453 | .setDuration(FADE_ANIMATION_DURATION_MS) |
| 454 | .setListener(new AnimatorListenerAdapter() { |
| 455 | @Override |
| 456 | public void onAnimationEnd(Animator animation) { |
Rohan Shah | a160ab1 | 2018-03-09 15:47:36 -0800 | [diff] [blame] | 457 | if (DEBUG) Log.d(TAG, "hideLongPressTooltip: Hid long press tip"); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 458 | mLongPressTooltipView.setVisibility(View.INVISIBLE); |
| 459 | |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 460 | if (shouldShowStatusText) { |
| 461 | showStatus(); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 462 | } |
| 463 | } |
| 464 | }) |
| 465 | .start(); |
| 466 | } else { |
| 467 | mLongPressTooltipView.setVisibility(View.INVISIBLE); |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 468 | if (shouldShowStatusText) { |
| 469 | showStatus(); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 470 | } |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | /** |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 475 | * Fades in the updated status text. Note that if there's already a status showing, this will |
| 476 | * immediately hide it and fade in the updated status. |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 477 | */ |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 478 | private void showStatus() { |
| 479 | mStatusContainer.setAlpha(0f); |
| 480 | mStatusContainer.setVisibility(View.VISIBLE); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 481 | |
Rohan Shah | a160ab1 | 2018-03-09 15:47:36 -0800 | [diff] [blame] | 482 | // Animate the alarm back in. Make sure to clear the animator listener for the animation! |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 483 | mStatusContainer.animate() |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 484 | .alpha(1f) |
| 485 | .setDuration(FADE_ANIMATION_DURATION_MS) |
Rohan Shah | a160ab1 | 2018-03-09 15:47:36 -0800 | [diff] [blame] | 486 | .setListener(null) |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 487 | .start(); |
| 488 | } |
| 489 | |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 490 | /** Fades out and hides the status text. */ |
| 491 | private void hideStatusText() { |
| 492 | if (mStatusContainer.getVisibility() == View.VISIBLE) { |
| 493 | mStatusContainer.animate() |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 494 | .alpha(0f) |
| 495 | .setListener(new AnimatorListenerAdapter() { |
| 496 | @Override |
| 497 | public void onAnimationEnd(Animator animation) { |
Rohan Shah | a160ab1 | 2018-03-09 15:47:36 -0800 | [diff] [blame] | 498 | if (DEBUG) Log.d(TAG, "hideAlarmText: Hid alarm text"); |
| 499 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 500 | // Reset the alpha regardless of how the animation ends for the next |
| 501 | // time we show this view/want to animate it. |
Amin Shaikh | 761c566 | 2018-03-27 16:55:43 -0400 | [diff] [blame] | 502 | mStatusContainer.setVisibility(View.INVISIBLE); |
| 503 | mStatusContainer.setAlpha(1f); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 504 | } |
| 505 | }) |
| 506 | .start(); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 507 | } |
| 508 | } |
| 509 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 510 | public void updateEverything() { |
Jason Monk | 1fdde2d | 2017-03-08 09:39:21 -0500 | [diff] [blame] | 511 | post(() -> setClickable(false)); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | public void setQSPanel(final QSPanel qsPanel) { |
| 515 | mQsPanel = qsPanel; |
| 516 | setupHost(qsPanel.getHost()); |
| 517 | } |
| 518 | |
| 519 | public void setupHost(final QSTileHost host) { |
| 520 | mHost = host; |
| 521 | //host.setHeaderView(mExpandIndicator); |
| 522 | mHeaderQsPanel.setQSPanelAndHeader(mQsPanel, this); |
| 523 | mHeaderQsPanel.setHost(host, null /* No customization in header */); |
Evan Laird | ef160f2 | 2018-01-29 14:08:45 -0500 | [diff] [blame] | 524 | |
| 525 | // 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] | 526 | mBatteryMeterView.setColorsFromContext(mHost.getContext()); |
| 527 | mBatteryMeterView.onDarkChanged(new Rect(), 0, DarkIconDispatcher.DEFAULT_ICON_TINT); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | public void setCallback(Callback qsPanelCallback) { |
| 531 | mHeaderQsPanel.setCallback(qsPanelCallback); |
| 532 | } |
Lucas Dupin | 1f7374a | 2018-02-26 18:08:33 -0800 | [diff] [blame] | 533 | |
| 534 | private String formatNextAlarm(AlarmManager.AlarmClockInfo info) { |
| 535 | if (info == null) { |
| 536 | return ""; |
| 537 | } |
| 538 | String skeleton = android.text.format.DateFormat |
| 539 | .is24HourFormat(mContext, ActivityManager.getCurrentUser()) ? "EHm" : "Ehma"; |
| 540 | String pattern = android.text.format.DateFormat |
| 541 | .getBestDateTimePattern(Locale.getDefault(), skeleton); |
| 542 | return android.text.format.DateFormat.format(pattern, info.getTriggerTime()).toString(); |
| 543 | } |
Amin Shaikh | 0e00331 | 2018-03-08 11:39:01 -0500 | [diff] [blame] | 544 | |
| 545 | public static float getColorIntensity(@ColorInt int color) { |
| 546 | return color == Color.WHITE ? 0 : 1; |
| 547 | } |
| 548 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 549 | } |