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; |
| 18 | import static android.app.StatusBarManager.DISABLE_NONE; |
| 19 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 20 | import android.content.Context; |
Evan Laird | 4ea2a49 | 2018-01-22 11:29:12 -0500 | [diff] [blame] | 21 | import android.content.Intent; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 22 | import android.content.res.Configuration; |
| 23 | import android.content.res.Resources; |
| 24 | import android.graphics.Color; |
| 25 | import android.graphics.Rect; |
Evan Laird | 4ea2a49 | 2018-01-22 11:29:12 -0500 | [diff] [blame] | 26 | import android.provider.AlarmClock; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 27 | import android.support.annotation.VisibleForTesting; |
| 28 | import android.util.AttributeSet; |
Jason Monk | 824ffff | 2017-04-11 15:49:06 -0400 | [diff] [blame] | 29 | import android.view.View; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 30 | import android.widget.RelativeLayout; |
Jason Monk | 01df36f | 2017-06-07 13:02:47 -0400 | [diff] [blame] | 31 | import android.widget.TextClock; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 32 | |
| 33 | import com.android.settingslib.Utils; |
| 34 | import com.android.systemui.BatteryMeterView; |
| 35 | import com.android.systemui.Dependency; |
| 36 | import com.android.systemui.R; |
Jason Monk | 01df36f | 2017-06-07 13:02:47 -0400 | [diff] [blame] | 37 | import com.android.systemui.R.id; |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 38 | import com.android.systemui.SysUiServiceProvider; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 39 | import com.android.systemui.plugins.ActivityStarter; |
| 40 | import com.android.systemui.qs.QSDetail.Callback; |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 41 | import com.android.systemui.statusbar.CommandQueue; |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 42 | import com.android.systemui.statusbar.phone.StatusBarIconController; |
| 43 | import com.android.systemui.statusbar.phone.StatusBarIconController.TintedIconManager; |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame] | 44 | import com.android.systemui.statusbar.policy.DarkIconDispatcher; |
Jason Monk | 824ffff | 2017-04-11 15:49:06 -0400 | [diff] [blame] | 45 | import com.android.systemui.statusbar.policy.DarkIconDispatcher.DarkReceiver; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 46 | |
Evan Laird | 4ea2a49 | 2018-01-22 11:29:12 -0500 | [diff] [blame] | 47 | public class QuickStatusBarHeader extends RelativeLayout |
| 48 | implements CommandQueue.Callbacks, View.OnClickListener { |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 49 | |
| 50 | private ActivityStarter mActivityStarter; |
| 51 | |
| 52 | private QSPanel mQsPanel; |
| 53 | |
| 54 | private boolean mExpanded; |
| 55 | private boolean mListening; |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 56 | private boolean mQsDisabled; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 57 | |
| 58 | protected QuickQSPanel mHeaderQsPanel; |
| 59 | protected QSTileHost mHost; |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 60 | private TintedIconManager mIconManager; |
| 61 | private TouchAnimator mAlphaAnimator; |
| 62 | |
| 63 | private View mQuickQsStatusIcons; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 64 | |
Evan Laird | 4ea2a49 | 2018-01-22 11:29:12 -0500 | [diff] [blame] | 65 | private View mDate; |
| 66 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 67 | public QuickStatusBarHeader(Context context, AttributeSet attrs) { |
| 68 | super(context, attrs); |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | protected void onFinishInflate() { |
| 73 | super.onFinishInflate(); |
| 74 | Resources res = getResources(); |
| 75 | |
| 76 | mHeaderQsPanel = findViewById(R.id.quick_qs_panel); |
Evan Laird | 4ea2a49 | 2018-01-22 11:29:12 -0500 | [diff] [blame] | 77 | mDate = findViewById(R.id.date); |
| 78 | mDate.setOnClickListener(this); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 79 | mQuickQsStatusIcons = findViewById(R.id.quick_qs_status_icons); |
| 80 | mIconManager = new TintedIconManager(findViewById(R.id.statusIcons)); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 81 | |
| 82 | // RenderThread is doing more harm than good when touching the header (to expand quick |
| 83 | // settings), so disable it for this view |
| 84 | |
| 85 | updateResources(); |
| 86 | |
Jason Monk | 824ffff | 2017-04-11 15:49:06 -0400 | [diff] [blame] | 87 | Rect tintArea = new Rect(0, 0, 0, 0); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 88 | int colorForeground = Utils.getColorAttr(getContext(), android.R.attr.colorForeground); |
| 89 | float intensity = colorForeground == Color.WHITE ? 0 : 1; |
| 90 | int fillColor = fillColorForIntensity(intensity, getContext()); |
| 91 | |
| 92 | // 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] | 93 | applyDarkness(R.id.clock, tintArea, 0, DarkIconDispatcher.DEFAULT_ICON_TINT); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 94 | applyDarkness(id.signal_cluster, tintArea, intensity, colorForeground); |
| 95 | |
| 96 | // Set the correct tint for the status icons so they contrast |
| 97 | mIconManager.setTint(fillColor); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 98 | |
| 99 | BatteryMeterView battery = findViewById(R.id.battery); |
| 100 | battery.setForceShowPercent(true); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 101 | |
| 102 | mActivityStarter = Dependency.get(ActivityStarter.class); |
| 103 | } |
| 104 | |
Jason Monk | 824ffff | 2017-04-11 15:49:06 -0400 | [diff] [blame] | 105 | private void applyDarkness(int id, Rect tintArea, float intensity, int color) { |
| 106 | View v = findViewById(id); |
| 107 | if (v instanceof DarkReceiver) { |
| 108 | ((DarkReceiver) v).onDarkChanged(tintArea, intensity, color); |
| 109 | } |
| 110 | } |
| 111 | |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 112 | private int fillColorForIntensity(float intensity, Context context) { |
| 113 | if (intensity == 0) { |
| 114 | return context.getColor(R.color.light_mode_icon_color_dual_tone_fill); |
| 115 | } |
| 116 | return context.getColor(R.color.dark_mode_icon_color_dual_tone_fill); |
| 117 | } |
| 118 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 119 | @Override |
| 120 | protected void onConfigurationChanged(Configuration newConfig) { |
| 121 | super.onConfigurationChanged(newConfig); |
| 122 | updateResources(); |
| 123 | } |
| 124 | |
| 125 | @Override |
| 126 | public void onRtlPropertiesChanged(int layoutDirection) { |
| 127 | super.onRtlPropertiesChanged(layoutDirection); |
| 128 | updateResources(); |
| 129 | } |
| 130 | |
| 131 | private void updateResources() { |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 132 | updateAlphaAnimator(); |
| 133 | } |
| 134 | |
| 135 | private void updateAlphaAnimator() { |
| 136 | mAlphaAnimator = new TouchAnimator.Builder() |
| 137 | .addFloat(mQuickQsStatusIcons, "alpha", 1, 0) |
| 138 | .build(); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | public int getCollapsedHeight() { |
| 142 | return getHeight(); |
| 143 | } |
| 144 | |
| 145 | public int getExpandedHeight() { |
| 146 | return getHeight(); |
| 147 | } |
| 148 | |
| 149 | public void setExpanded(boolean expanded) { |
| 150 | if (mExpanded == expanded) return; |
| 151 | mExpanded = expanded; |
| 152 | mHeaderQsPanel.setExpanded(expanded); |
| 153 | updateEverything(); |
| 154 | } |
| 155 | |
| 156 | public void setExpansion(float headerExpansionFraction) { |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 157 | if (mAlphaAnimator != null ) { |
| 158 | mAlphaAnimator.setPosition(headerExpansionFraction); |
| 159 | } |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | @Override |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 163 | public void disable(int state1, int state2, boolean animate) { |
| 164 | final boolean disabled = (state2 & DISABLE2_QUICK_SETTINGS) != 0; |
| 165 | if (disabled == mQsDisabled) return; |
| 166 | mQsDisabled = disabled; |
| 167 | mHeaderQsPanel.setDisabledByPolicy(disabled); |
Evan Laird | 19bf52c | 2018-01-24 19:54:58 -0500 | [diff] [blame] | 168 | final int rawHeight = (int) getResources().getDimension( |
| 169 | com.android.internal.R.dimen.quick_qs_total_height); |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 170 | getLayoutParams().height = disabled ? (rawHeight - mHeaderQsPanel.getHeight()) : rawHeight; |
| 171 | } |
| 172 | |
| 173 | @Override |
| 174 | public void onAttachedToWindow() { |
| 175 | SysUiServiceProvider.getComponent(getContext(), CommandQueue.class).addCallbacks(this); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 176 | Dependency.get(StatusBarIconController.class).addIconGroup(mIconManager); |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | @Override |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 180 | @VisibleForTesting |
| 181 | public void onDetachedFromWindow() { |
| 182 | setListening(false); |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 183 | SysUiServiceProvider.getComponent(getContext(), CommandQueue.class).removeCallbacks(this); |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 184 | Dependency.get(StatusBarIconController.class).removeIconGroup(mIconManager); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 185 | super.onDetachedFromWindow(); |
| 186 | } |
| 187 | |
| 188 | public void setListening(boolean listening) { |
| 189 | if (listening == mListening) { |
| 190 | return; |
| 191 | } |
| 192 | mHeaderQsPanel.setListening(listening); |
| 193 | mListening = listening; |
| 194 | } |
| 195 | |
Evan Laird | 9589695 | 2018-01-22 19:30:05 -0500 | [diff] [blame] | 196 | @Override |
| 197 | public void onClick(View v) { |
| 198 | if(v == mDate){ |
| 199 | Dependency.get(ActivityStarter.class).postStartActivityDismissingKeyguard(new Intent( |
| 200 | AlarmClock.ACTION_SHOW_ALARMS),0); |
| 201 | } |
| 202 | } |
| 203 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 204 | public void updateEverything() { |
Jason Monk | 1fdde2d | 2017-03-08 09:39:21 -0500 | [diff] [blame] | 205 | post(() -> setClickable(false)); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | public void setQSPanel(final QSPanel qsPanel) { |
| 209 | mQsPanel = qsPanel; |
| 210 | setupHost(qsPanel.getHost()); |
| 211 | } |
| 212 | |
| 213 | public void setupHost(final QSTileHost host) { |
| 214 | mHost = host; |
| 215 | //host.setHeaderView(mExpandIndicator); |
| 216 | mHeaderQsPanel.setQSPanelAndHeader(mQsPanel, this); |
| 217 | mHeaderQsPanel.setHost(host, null /* No customization in header */); |
Evan Laird | ef160f2 | 2018-01-29 14:08:45 -0500 | [diff] [blame^] | 218 | |
| 219 | // Use SystemUI context to get battery meter colors, and let it use the default tint (white) |
| 220 | BatteryMeterView battery = findViewById(R.id.battery); |
| 221 | battery.setColorsFromContext(mHost.getContext()); |
| 222 | battery.onDarkChanged(new Rect(), 0, DarkIconDispatcher.DEFAULT_ICON_TINT); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | public void setCallback(Callback qsPanelCallback) { |
| 226 | mHeaderQsPanel.setCallback(qsPanelCallback); |
| 227 | } |
| 228 | } |