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