blob: e6fd2f4697ddc4c830d4085c2e184a616ebbcb66 [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;
21import android.content.res.Configuration;
22import android.content.res.Resources;
23import android.graphics.Color;
24import android.graphics.Rect;
25import android.support.annotation.VisibleForTesting;
26import android.util.AttributeSet;
Jason Monk824ffff2017-04-11 15:49:06 -040027import android.view.View;
Jason Monke5b770e2017-03-03 21:49:29 -050028import android.widget.RelativeLayout;
Jason Monk01df36f2017-06-07 13:02:47 -040029import android.widget.TextClock;
Jason Monke5b770e2017-03-03 21:49:29 -050030
31import com.android.settingslib.Utils;
32import com.android.systemui.BatteryMeterView;
33import com.android.systemui.Dependency;
34import com.android.systemui.R;
Jason Monk01df36f2017-06-07 13:02:47 -040035import com.android.systemui.R.id;
Charles Hece2a7c02017-10-11 20:25:20 +010036import com.android.systemui.SysUiServiceProvider;
Jason Monke5b770e2017-03-03 21:49:29 -050037import com.android.systemui.plugins.ActivityStarter;
38import com.android.systemui.qs.QSDetail.Callback;
Charles Hece2a7c02017-10-11 20:25:20 +010039import com.android.systemui.statusbar.CommandQueue;
Jason Monke5b770e2017-03-03 21:49:29 -050040import com.android.systemui.statusbar.SignalClusterView;
Evan Laird39254d42018-01-18 16:05:30 -050041import com.android.systemui.statusbar.policy.DarkIconDispatcher;
Jason Monk824ffff2017-04-11 15:49:06 -040042import com.android.systemui.statusbar.policy.DarkIconDispatcher.DarkReceiver;
Jason Monke5b770e2017-03-03 21:49:29 -050043
Charles Hece2a7c02017-10-11 20:25:20 +010044public class QuickStatusBarHeader extends RelativeLayout implements CommandQueue.Callbacks {
Jason Monke5b770e2017-03-03 21:49:29 -050045
46 private ActivityStarter mActivityStarter;
47
48 private QSPanel mQsPanel;
49
50 private boolean mExpanded;
51 private boolean mListening;
Charles Hece2a7c02017-10-11 20:25:20 +010052 private boolean mQsDisabled;
Jason Monke5b770e2017-03-03 21:49:29 -050053
54 protected QuickQSPanel mHeaderQsPanel;
55 protected QSTileHost mHost;
56
57 public QuickStatusBarHeader(Context context, AttributeSet attrs) {
58 super(context, attrs);
59 }
60
61 @Override
62 protected void onFinishInflate() {
63 super.onFinishInflate();
64 Resources res = getResources();
65
66 mHeaderQsPanel = findViewById(R.id.quick_qs_panel);
Jason Monke5b770e2017-03-03 21:49:29 -050067
68 // RenderThread is doing more harm than good when touching the header (to expand quick
69 // settings), so disable it for this view
70
71 updateResources();
72
Evan Laird39254d42018-01-18 16:05:30 -050073 // Set light text on the header icons because they will always be on a black background
Jason Monke5b770e2017-03-03 21:49:29 -050074 int colorForeground = Utils.getColorAttr(getContext(), android.R.attr.colorForeground);
Jason Monk824ffff2017-04-11 15:49:06 -040075 Rect tintArea = new Rect(0, 0, 0, 0);
Evan Laird39254d42018-01-18 16:05:30 -050076 applyDarkness(R.id.clock, tintArea, 0, DarkIconDispatcher.DEFAULT_ICON_TINT);
Jason Monke5b770e2017-03-03 21:49:29 -050077
78 BatteryMeterView battery = findViewById(R.id.battery);
Evan Laird39254d42018-01-18 16:05:30 -050079 battery.setFillColor(Color.WHITE);
Jason Monke5b770e2017-03-03 21:49:29 -050080 battery.setForceShowPercent(true);
Jason Monke5b770e2017-03-03 21:49:29 -050081
82 mActivityStarter = Dependency.get(ActivityStarter.class);
83 }
84
Jason Monk824ffff2017-04-11 15:49:06 -040085 private void applyDarkness(int id, Rect tintArea, float intensity, int color) {
86 View v = findViewById(id);
87 if (v instanceof DarkReceiver) {
88 ((DarkReceiver) v).onDarkChanged(tintArea, intensity, color);
89 }
90 }
91
Jason Monke5b770e2017-03-03 21:49:29 -050092 @Override
93 protected void onConfigurationChanged(Configuration newConfig) {
94 super.onConfigurationChanged(newConfig);
95 updateResources();
96 }
97
98 @Override
99 public void onRtlPropertiesChanged(int layoutDirection) {
100 super.onRtlPropertiesChanged(layoutDirection);
101 updateResources();
102 }
103
104 private void updateResources() {
105 }
106
107 public int getCollapsedHeight() {
108 return getHeight();
109 }
110
111 public int getExpandedHeight() {
112 return getHeight();
113 }
114
115 public void setExpanded(boolean expanded) {
116 if (mExpanded == expanded) return;
117 mExpanded = expanded;
118 mHeaderQsPanel.setExpanded(expanded);
119 updateEverything();
120 }
121
122 public void setExpansion(float headerExpansionFraction) {
123 }
124
125 @Override
Charles Hece2a7c02017-10-11 20:25:20 +0100126 public void disable(int state1, int state2, boolean animate) {
127 final boolean disabled = (state2 & DISABLE2_QUICK_SETTINGS) != 0;
128 if (disabled == mQsDisabled) return;
129 mQsDisabled = disabled;
130 mHeaderQsPanel.setDisabledByPolicy(disabled);
131 final int rawHeight = (int) getResources().getDimension(R.dimen.status_bar_header_height);
132 getLayoutParams().height = disabled ? (rawHeight - mHeaderQsPanel.getHeight()) : rawHeight;
133 }
134
135 @Override
136 public void onAttachedToWindow() {
137 SysUiServiceProvider.getComponent(getContext(), CommandQueue.class).addCallbacks(this);
138 }
139
140 @Override
Jason Monke5b770e2017-03-03 21:49:29 -0500141 @VisibleForTesting
142 public void onDetachedFromWindow() {
143 setListening(false);
Charles Hece2a7c02017-10-11 20:25:20 +0100144 SysUiServiceProvider.getComponent(getContext(), CommandQueue.class).removeCallbacks(this);
Jason Monke5b770e2017-03-03 21:49:29 -0500145 super.onDetachedFromWindow();
146 }
147
148 public void setListening(boolean listening) {
149 if (listening == mListening) {
150 return;
151 }
152 mHeaderQsPanel.setListening(listening);
153 mListening = listening;
154 }
155
156 public void updateEverything() {
Jason Monk1fdde2d2017-03-08 09:39:21 -0500157 post(() -> setClickable(false));
Jason Monke5b770e2017-03-03 21:49:29 -0500158 }
159
160 public void setQSPanel(final QSPanel qsPanel) {
161 mQsPanel = qsPanel;
162 setupHost(qsPanel.getHost());
163 }
164
165 public void setupHost(final QSTileHost host) {
166 mHost = host;
167 //host.setHeaderView(mExpandIndicator);
168 mHeaderQsPanel.setQSPanelAndHeader(mQsPanel, this);
169 mHeaderQsPanel.setHost(host, null /* No customization in header */);
170 }
171
172 public void setCallback(Callback qsPanelCallback) {
173 mHeaderQsPanel.setCallback(qsPanelCallback);
174 }
175}