blob: 4d7333b99eeecbad46891c805cf82a2ce146f233 [file] [log] [blame]
Jason Monke5b770e2017-03-03 21:49:29 -05001/*
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
15package com.android.systemui.qs;
16
Charles Hece2a7c02017-10-11 20:25:20 +010017import static android.app.StatusBarManager.DISABLE2_QUICK_SETTINGS;
18import static android.app.StatusBarManager.DISABLE_NONE;
19
Jason Monke5b770e2017-03-03 21:49:29 -050020import android.content.Context;
Evan Laird4ea2a492018-01-22 11:29:12 -050021import android.content.Intent;
Jason Monke5b770e2017-03-03 21:49:29 -050022import android.content.res.Configuration;
23import android.content.res.Resources;
24import android.graphics.Color;
25import android.graphics.Rect;
Evan Laird4ea2a492018-01-22 11:29:12 -050026import android.provider.AlarmClock;
Jason Monke5b770e2017-03-03 21:49:29 -050027import android.support.annotation.VisibleForTesting;
28import android.util.AttributeSet;
Jason Monk824ffff2017-04-11 15:49:06 -040029import android.view.View;
Jason Monke5b770e2017-03-03 21:49:29 -050030import android.widget.RelativeLayout;
Jason Monk01df36f2017-06-07 13:02:47 -040031import android.widget.TextClock;
Jason Monke5b770e2017-03-03 21:49:29 -050032
33import com.android.settingslib.Utils;
34import com.android.systemui.BatteryMeterView;
35import com.android.systemui.Dependency;
36import com.android.systemui.R;
Jason Monk01df36f2017-06-07 13:02:47 -040037import com.android.systemui.R.id;
Charles Hece2a7c02017-10-11 20:25:20 +010038import com.android.systemui.SysUiServiceProvider;
Jason Monke5b770e2017-03-03 21:49:29 -050039import com.android.systemui.plugins.ActivityStarter;
40import com.android.systemui.qs.QSDetail.Callback;
Charles Hece2a7c02017-10-11 20:25:20 +010041import com.android.systemui.statusbar.CommandQueue;
Evan Laird95896952018-01-22 19:30:05 -050042import com.android.systemui.statusbar.phone.StatusBarIconController;
43import com.android.systemui.statusbar.phone.StatusBarIconController.TintedIconManager;
Evan Laird39254d42018-01-18 16:05:30 -050044import com.android.systemui.statusbar.policy.DarkIconDispatcher;
Jason Monk824ffff2017-04-11 15:49:06 -040045import com.android.systemui.statusbar.policy.DarkIconDispatcher.DarkReceiver;
Jason Monke5b770e2017-03-03 21:49:29 -050046
Evan Laird4ea2a492018-01-22 11:29:12 -050047public class QuickStatusBarHeader extends RelativeLayout
48 implements CommandQueue.Callbacks, View.OnClickListener {
Jason Monke5b770e2017-03-03 21:49:29 -050049
50 private ActivityStarter mActivityStarter;
51
52 private QSPanel mQsPanel;
53
54 private boolean mExpanded;
55 private boolean mListening;
Charles Hece2a7c02017-10-11 20:25:20 +010056 private boolean mQsDisabled;
Jason Monke5b770e2017-03-03 21:49:29 -050057
58 protected QuickQSPanel mHeaderQsPanel;
59 protected QSTileHost mHost;
Evan Laird95896952018-01-22 19:30:05 -050060 private TintedIconManager mIconManager;
61 private TouchAnimator mAlphaAnimator;
62
63 private View mQuickQsStatusIcons;
Jason Monke5b770e2017-03-03 21:49:29 -050064
Evan Laird4ea2a492018-01-22 11:29:12 -050065 private View mDate;
66
Jason Monke5b770e2017-03-03 21:49:29 -050067 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 Laird4ea2a492018-01-22 11:29:12 -050077 mDate = findViewById(R.id.date);
78 mDate.setOnClickListener(this);
Evan Laird95896952018-01-22 19:30:05 -050079 mQuickQsStatusIcons = findViewById(R.id.quick_qs_status_icons);
80 mIconManager = new TintedIconManager(findViewById(R.id.statusIcons));
Jason Monke5b770e2017-03-03 21:49:29 -050081
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 Monk824ffff2017-04-11 15:49:06 -040087 Rect tintArea = new Rect(0, 0, 0, 0);
Evan Laird95896952018-01-22 19:30:05 -050088 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 Laird39254d42018-01-18 16:05:30 -050093 applyDarkness(R.id.clock, tintArea, 0, DarkIconDispatcher.DEFAULT_ICON_TINT);
Evan Laird95896952018-01-22 19:30:05 -050094 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 Monke5b770e2017-03-03 21:49:29 -050098
99 BatteryMeterView battery = findViewById(R.id.battery);
100 battery.setForceShowPercent(true);
Jason Monke5b770e2017-03-03 21:49:29 -0500101
102 mActivityStarter = Dependency.get(ActivityStarter.class);
103 }
104
Jason Monk824ffff2017-04-11 15:49:06 -0400105 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 Laird95896952018-01-22 19:30:05 -0500112 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 Monke5b770e2017-03-03 21:49:29 -0500119 @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 Laird95896952018-01-22 19:30:05 -0500132 updateAlphaAnimator();
133 }
134
135 private void updateAlphaAnimator() {
136 mAlphaAnimator = new TouchAnimator.Builder()
137 .addFloat(mQuickQsStatusIcons, "alpha", 1, 0)
138 .build();
Jason Monke5b770e2017-03-03 21:49:29 -0500139 }
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 Laird95896952018-01-22 19:30:05 -0500157 if (mAlphaAnimator != null ) {
158 mAlphaAnimator.setPosition(headerExpansionFraction);
159 }
Jason Monke5b770e2017-03-03 21:49:29 -0500160 }
161
162 @Override
Charles Hece2a7c02017-10-11 20:25:20 +0100163 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 Laird19bf52c2018-01-24 19:54:58 -0500168 final int rawHeight = (int) getResources().getDimension(
169 com.android.internal.R.dimen.quick_qs_total_height);
Charles Hece2a7c02017-10-11 20:25:20 +0100170 getLayoutParams().height = disabled ? (rawHeight - mHeaderQsPanel.getHeight()) : rawHeight;
171 }
172
173 @Override
174 public void onAttachedToWindow() {
175 SysUiServiceProvider.getComponent(getContext(), CommandQueue.class).addCallbacks(this);
Evan Laird95896952018-01-22 19:30:05 -0500176 Dependency.get(StatusBarIconController.class).addIconGroup(mIconManager);
Charles Hece2a7c02017-10-11 20:25:20 +0100177 }
178
179 @Override
Jason Monke5b770e2017-03-03 21:49:29 -0500180 @VisibleForTesting
181 public void onDetachedFromWindow() {
182 setListening(false);
Charles Hece2a7c02017-10-11 20:25:20 +0100183 SysUiServiceProvider.getComponent(getContext(), CommandQueue.class).removeCallbacks(this);
Evan Laird95896952018-01-22 19:30:05 -0500184 Dependency.get(StatusBarIconController.class).removeIconGroup(mIconManager);
Jason Monke5b770e2017-03-03 21:49:29 -0500185 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 Laird95896952018-01-22 19:30:05 -0500196 @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 Monke5b770e2017-03-03 21:49:29 -0500204 public void updateEverything() {
Jason Monk1fdde2d2017-03-08 09:39:21 -0500205 post(() -> setClickable(false));
Jason Monke5b770e2017-03-03 21:49:29 -0500206 }
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 Lairdef160f22018-01-29 14:08:45 -0500218
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 Monke5b770e2017-03-03 21:49:29 -0500223 }
224
225 public void setCallback(Callback qsPanelCallback) {
226 mHeaderQsPanel.setCallback(qsPanelCallback);
227 }
228}