blob: 17ede6586402a0b50ecbe557fbcd917b98c3f3c1 [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);
Evan Laird39254d42018-01-18 16:05:30 -0500100 battery.setFillColor(Color.WHITE);
Jason Monke5b770e2017-03-03 21:49:29 -0500101 battery.setForceShowPercent(true);
Jason Monke5b770e2017-03-03 21:49:29 -0500102
103 mActivityStarter = Dependency.get(ActivityStarter.class);
104 }
105
Jason Monk824ffff2017-04-11 15:49:06 -0400106 private void applyDarkness(int id, Rect tintArea, float intensity, int color) {
107 View v = findViewById(id);
108 if (v instanceof DarkReceiver) {
109 ((DarkReceiver) v).onDarkChanged(tintArea, intensity, color);
110 }
111 }
112
Evan Laird95896952018-01-22 19:30:05 -0500113 private int fillColorForIntensity(float intensity, Context context) {
114 if (intensity == 0) {
115 return context.getColor(R.color.light_mode_icon_color_dual_tone_fill);
116 }
117 return context.getColor(R.color.dark_mode_icon_color_dual_tone_fill);
118 }
119
Jason Monke5b770e2017-03-03 21:49:29 -0500120 @Override
121 protected void onConfigurationChanged(Configuration newConfig) {
122 super.onConfigurationChanged(newConfig);
123 updateResources();
124 }
125
126 @Override
127 public void onRtlPropertiesChanged(int layoutDirection) {
128 super.onRtlPropertiesChanged(layoutDirection);
129 updateResources();
130 }
131
132 private void updateResources() {
Evan Laird95896952018-01-22 19:30:05 -0500133 updateAlphaAnimator();
134 }
135
136 private void updateAlphaAnimator() {
137 mAlphaAnimator = new TouchAnimator.Builder()
138 .addFloat(mQuickQsStatusIcons, "alpha", 1, 0)
139 .build();
Jason Monke5b770e2017-03-03 21:49:29 -0500140 }
141
142 public int getCollapsedHeight() {
143 return getHeight();
144 }
145
146 public int getExpandedHeight() {
147 return getHeight();
148 }
149
150 public void setExpanded(boolean expanded) {
151 if (mExpanded == expanded) return;
152 mExpanded = expanded;
153 mHeaderQsPanel.setExpanded(expanded);
154 updateEverything();
155 }
156
157 public void setExpansion(float headerExpansionFraction) {
Evan Laird95896952018-01-22 19:30:05 -0500158 if (mAlphaAnimator != null ) {
159 mAlphaAnimator.setPosition(headerExpansionFraction);
160 }
Jason Monke5b770e2017-03-03 21:49:29 -0500161 }
162
163 @Override
Charles Hece2a7c02017-10-11 20:25:20 +0100164 public void disable(int state1, int state2, boolean animate) {
165 final boolean disabled = (state2 & DISABLE2_QUICK_SETTINGS) != 0;
166 if (disabled == mQsDisabled) return;
167 mQsDisabled = disabled;
168 mHeaderQsPanel.setDisabledByPolicy(disabled);
169 final int rawHeight = (int) getResources().getDimension(R.dimen.status_bar_header_height);
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 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 */);
218 }
219
220 public void setCallback(Callback qsPanelCallback) {
221 mHeaderQsPanel.setCallback(qsPanelCallback);
222 }
223}