blob: a97b35cba048b95161eaa369d652d1a93218bc1b [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;
Jason Monke5b770e2017-03-03 21:49:29 -050042import com.android.systemui.statusbar.SignalClusterView;
Evan Laird39254d42018-01-18 16:05:30 -050043import com.android.systemui.statusbar.policy.DarkIconDispatcher;
Jason Monk824ffff2017-04-11 15:49:06 -040044import com.android.systemui.statusbar.policy.DarkIconDispatcher.DarkReceiver;
Jason Monke5b770e2017-03-03 21:49:29 -050045
Evan Laird4ea2a492018-01-22 11:29:12 -050046public class QuickStatusBarHeader extends RelativeLayout
47 implements CommandQueue.Callbacks, View.OnClickListener {
Jason Monke5b770e2017-03-03 21:49:29 -050048
49 private ActivityStarter mActivityStarter;
50
51 private QSPanel mQsPanel;
52
53 private boolean mExpanded;
54 private boolean mListening;
Charles Hece2a7c02017-10-11 20:25:20 +010055 private boolean mQsDisabled;
Jason Monke5b770e2017-03-03 21:49:29 -050056
57 protected QuickQSPanel mHeaderQsPanel;
58 protected QSTileHost mHost;
59
Evan Laird4ea2a492018-01-22 11:29:12 -050060 private View mDate;
61
Jason Monke5b770e2017-03-03 21:49:29 -050062 public QuickStatusBarHeader(Context context, AttributeSet attrs) {
63 super(context, attrs);
64 }
65
66 @Override
67 protected void onFinishInflate() {
68 super.onFinishInflate();
69 Resources res = getResources();
70
71 mHeaderQsPanel = findViewById(R.id.quick_qs_panel);
Evan Laird4ea2a492018-01-22 11:29:12 -050072 mDate = findViewById(R.id.date);
73 mDate.setOnClickListener(this);
Jason Monke5b770e2017-03-03 21:49:29 -050074
75 // RenderThread is doing more harm than good when touching the header (to expand quick
76 // settings), so disable it for this view
77
78 updateResources();
79
Evan Laird39254d42018-01-18 16:05:30 -050080 // Set light text on the header icons because they will always be on a black background
Jason Monke5b770e2017-03-03 21:49:29 -050081 int colorForeground = Utils.getColorAttr(getContext(), android.R.attr.colorForeground);
Jason Monk824ffff2017-04-11 15:49:06 -040082 Rect tintArea = new Rect(0, 0, 0, 0);
Evan Laird39254d42018-01-18 16:05:30 -050083 applyDarkness(R.id.clock, tintArea, 0, DarkIconDispatcher.DEFAULT_ICON_TINT);
Jason Monke5b770e2017-03-03 21:49:29 -050084
85 BatteryMeterView battery = findViewById(R.id.battery);
Evan Laird39254d42018-01-18 16:05:30 -050086 battery.setFillColor(Color.WHITE);
Jason Monke5b770e2017-03-03 21:49:29 -050087 battery.setForceShowPercent(true);
Jason Monke5b770e2017-03-03 21:49:29 -050088
89 mActivityStarter = Dependency.get(ActivityStarter.class);
90 }
91
Jason Monk824ffff2017-04-11 15:49:06 -040092 private void applyDarkness(int id, Rect tintArea, float intensity, int color) {
93 View v = findViewById(id);
94 if (v instanceof DarkReceiver) {
95 ((DarkReceiver) v).onDarkChanged(tintArea, intensity, color);
96 }
97 }
98
Jason Monke5b770e2017-03-03 21:49:29 -050099 @Override
100 protected void onConfigurationChanged(Configuration newConfig) {
101 super.onConfigurationChanged(newConfig);
102 updateResources();
103 }
104
105 @Override
106 public void onRtlPropertiesChanged(int layoutDirection) {
107 super.onRtlPropertiesChanged(layoutDirection);
108 updateResources();
109 }
110
111 private void updateResources() {
112 }
113
114 public int getCollapsedHeight() {
115 return getHeight();
116 }
117
118 public int getExpandedHeight() {
119 return getHeight();
120 }
121
122 public void setExpanded(boolean expanded) {
123 if (mExpanded == expanded) return;
124 mExpanded = expanded;
125 mHeaderQsPanel.setExpanded(expanded);
126 updateEverything();
127 }
128
129 public void setExpansion(float headerExpansionFraction) {
130 }
131
132 @Override
Charles Hece2a7c02017-10-11 20:25:20 +0100133 public void disable(int state1, int state2, boolean animate) {
134 final boolean disabled = (state2 & DISABLE2_QUICK_SETTINGS) != 0;
135 if (disabled == mQsDisabled) return;
136 mQsDisabled = disabled;
137 mHeaderQsPanel.setDisabledByPolicy(disabled);
138 final int rawHeight = (int) getResources().getDimension(R.dimen.status_bar_header_height);
139 getLayoutParams().height = disabled ? (rawHeight - mHeaderQsPanel.getHeight()) : rawHeight;
140 }
141
142 @Override
143 public void onAttachedToWindow() {
144 SysUiServiceProvider.getComponent(getContext(), CommandQueue.class).addCallbacks(this);
145 }
146
147 @Override
Jason Monke5b770e2017-03-03 21:49:29 -0500148 @VisibleForTesting
149 public void onDetachedFromWindow() {
150 setListening(false);
Charles Hece2a7c02017-10-11 20:25:20 +0100151 SysUiServiceProvider.getComponent(getContext(), CommandQueue.class).removeCallbacks(this);
Jason Monke5b770e2017-03-03 21:49:29 -0500152 super.onDetachedFromWindow();
153 }
154
Evan Laird4ea2a492018-01-22 11:29:12 -0500155 @Override
156 public void onClick(View v) {
157 if (v == mDate) {
158 Dependency.get(ActivityStarter.class).postStartActivityDismissingKeyguard(new Intent(
159 AlarmClock.ACTION_SHOW_ALARMS), 0);
160 }
161 }
162
Jason Monke5b770e2017-03-03 21:49:29 -0500163 public void setListening(boolean listening) {
164 if (listening == mListening) {
165 return;
166 }
167 mHeaderQsPanel.setListening(listening);
168 mListening = listening;
169 }
170
171 public void updateEverything() {
Jason Monk1fdde2d2017-03-08 09:39:21 -0500172 post(() -> setClickable(false));
Jason Monke5b770e2017-03-03 21:49:29 -0500173 }
174
175 public void setQSPanel(final QSPanel qsPanel) {
176 mQsPanel = qsPanel;
177 setupHost(qsPanel.getHost());
178 }
179
180 public void setupHost(final QSTileHost host) {
181 mHost = host;
182 //host.setHeaderView(mExpandIndicator);
183 mHeaderQsPanel.setQSPanelAndHeader(mQsPanel, this);
184 mHeaderQsPanel.setHost(host, null /* No customization in header */);
185 }
186
187 public void setCallback(Callback qsPanelCallback) {
188 mHeaderQsPanel.setCallback(qsPanelCallback);
189 }
190}