blob: 8c1c89feb0243e4fd912b01f742c744db8d0f648 [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
17import android.content.Context;
18import android.content.res.Configuration;
19import android.content.res.Resources;
20import android.graphics.Color;
21import android.graphics.Rect;
22import android.support.annotation.VisibleForTesting;
23import android.util.AttributeSet;
24import android.widget.RelativeLayout;
25
26import com.android.settingslib.Utils;
27import com.android.systemui.BatteryMeterView;
28import com.android.systemui.Dependency;
29import com.android.systemui.R;
30import com.android.systemui.plugins.ActivityStarter;
31import com.android.systemui.qs.QSDetail.Callback;
32import com.android.systemui.statusbar.SignalClusterView;
33
34
35public class QuickStatusBarHeader extends RelativeLayout {
36
37 private ActivityStarter mActivityStarter;
38
39 private QSPanel mQsPanel;
40
41 private boolean mExpanded;
42 private boolean mListening;
43
44 protected QuickQSPanel mHeaderQsPanel;
45 protected QSTileHost mHost;
46
47 public QuickStatusBarHeader(Context context, AttributeSet attrs) {
48 super(context, attrs);
49 }
50
51 @Override
52 protected void onFinishInflate() {
53 super.onFinishInflate();
54 Resources res = getResources();
55
56 mHeaderQsPanel = findViewById(R.id.quick_qs_panel);
57 mHeaderQsPanel.setVisibility(res.getBoolean(R.bool.config_showQuickSettingsRow)
58 ? VISIBLE : GONE);
59
60 // RenderThread is doing more harm than good when touching the header (to expand quick
61 // settings), so disable it for this view
62
63 updateResources();
64
65 // Set the light/dark theming on the header status UI to match the current theme.
66 SignalClusterView cluster = findViewById(R.id.signal_cluster);
67 int colorForeground = Utils.getColorAttr(getContext(), android.R.attr.colorForeground);
68 float intensity = colorForeground == Color.WHITE ? 0 : 1;
69 cluster.onDarkChanged(new Rect(0, 0, 0, 0), intensity, colorForeground);
70
71 BatteryMeterView battery = findViewById(R.id.battery);
72 battery.setForceShowPercent(true);
73 int colorSecondary = Utils.getColorAttr(getContext(), android.R.attr.textColorSecondary);
74 battery.setRawColors(colorForeground, colorSecondary);
75
76 mActivityStarter = Dependency.get(ActivityStarter.class);
77 }
78
79 @Override
80 protected void onConfigurationChanged(Configuration newConfig) {
81 super.onConfigurationChanged(newConfig);
82 updateResources();
83 }
84
85 @Override
86 public void onRtlPropertiesChanged(int layoutDirection) {
87 super.onRtlPropertiesChanged(layoutDirection);
88 updateResources();
89 }
90
91 private void updateResources() {
92 }
93
94 public int getCollapsedHeight() {
95 return getHeight();
96 }
97
98 public int getExpandedHeight() {
99 return getHeight();
100 }
101
102 public void setExpanded(boolean expanded) {
103 if (mExpanded == expanded) return;
104 mExpanded = expanded;
105 mHeaderQsPanel.setExpanded(expanded);
106 updateEverything();
107 }
108
109 public void setExpansion(float headerExpansionFraction) {
110 }
111
112 @Override
113 @VisibleForTesting
114 public void onDetachedFromWindow() {
115 setListening(false);
116 super.onDetachedFromWindow();
117 }
118
119 public void setListening(boolean listening) {
120 if (listening == mListening) {
121 return;
122 }
123 mHeaderQsPanel.setListening(listening);
124 mListening = listening;
125 }
126
127 public void updateEverything() {
128 post(() -> {
129 setClickable(false);
130 });
131 }
132
133 public void setQSPanel(final QSPanel qsPanel) {
134 mQsPanel = qsPanel;
135 setupHost(qsPanel.getHost());
136 }
137
138 public void setupHost(final QSTileHost host) {
139 mHost = host;
140 //host.setHeaderView(mExpandIndicator);
141 mHeaderQsPanel.setQSPanelAndHeader(mQsPanel, this);
142 mHeaderQsPanel.setHost(host, null /* No customization in header */);
143 }
144
145 public void setCallback(Callback qsPanelCallback) {
146 mHeaderQsPanel.setCallback(qsPanelCallback);
147 }
148}