QuickStatusBarHeader.java revision ce2a7c0d50a8a9c59b5236115e84c526357846e3
1/*
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 static android.app.StatusBarManager.DISABLE2_QUICK_SETTINGS;
18import static android.app.StatusBarManager.DISABLE_NONE;
19
20import 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;
27import android.view.View;
28import android.widget.RelativeLayout;
29import android.widget.TextClock;
30
31import com.android.settingslib.Utils;
32import com.android.systemui.BatteryMeterView;
33import com.android.systemui.Dependency;
34import com.android.systemui.R;
35import com.android.systemui.R.id;
36import com.android.systemui.SysUiServiceProvider;
37import com.android.systemui.plugins.ActivityStarter;
38import com.android.systemui.qs.QSDetail.Callback;
39import com.android.systemui.statusbar.CommandQueue;
40import com.android.systemui.statusbar.SignalClusterView;
41import com.android.systemui.statusbar.policy.DarkIconDispatcher.DarkReceiver;
42
43public class QuickStatusBarHeader extends RelativeLayout implements CommandQueue.Callbacks {
44
45    private ActivityStarter mActivityStarter;
46
47    private QSPanel mQsPanel;
48
49    private boolean mExpanded;
50    private boolean mListening;
51    private boolean mQsDisabled;
52
53    protected QuickQSPanel mHeaderQsPanel;
54    protected QSTileHost mHost;
55
56    public QuickStatusBarHeader(Context context, AttributeSet attrs) {
57        super(context, attrs);
58    }
59
60    @Override
61    protected void onFinishInflate() {
62        super.onFinishInflate();
63        Resources res = getResources();
64
65        mHeaderQsPanel = findViewById(R.id.quick_qs_panel);
66
67        // RenderThread is doing more harm than good when touching the header (to expand quick
68        // settings), so disable it for this view
69
70        updateResources();
71
72        // Set the light/dark theming on the header status UI to match the current theme.
73        int colorForeground = Utils.getColorAttr(getContext(), android.R.attr.colorForeground);
74        float intensity = colorForeground == Color.WHITE ? 0 : 1;
75        Rect tintArea = new Rect(0, 0, 0, 0);
76
77        applyDarkness(R.id.battery, tintArea, intensity, colorForeground);
78        applyDarkness(R.id.clock, tintArea, intensity, colorForeground);
79
80        BatteryMeterView battery = findViewById(R.id.battery);
81        battery.setForceShowPercent(true);
82
83        mActivityStarter = Dependency.get(ActivityStarter.class);
84    }
85
86    private void applyDarkness(int id, Rect tintArea, float intensity, int color) {
87        View v = findViewById(id);
88        if (v instanceof DarkReceiver) {
89            ((DarkReceiver) v).onDarkChanged(tintArea, intensity, color);
90        }
91    }
92
93    @Override
94    protected void onConfigurationChanged(Configuration newConfig) {
95        super.onConfigurationChanged(newConfig);
96        updateResources();
97    }
98
99    @Override
100    public void onRtlPropertiesChanged(int layoutDirection) {
101        super.onRtlPropertiesChanged(layoutDirection);
102        updateResources();
103    }
104
105    private void updateResources() {
106    }
107
108    public int getCollapsedHeight() {
109        return getHeight();
110    }
111
112    public int getExpandedHeight() {
113        return getHeight();
114    }
115
116    public void setExpanded(boolean expanded) {
117        if (mExpanded == expanded) return;
118        mExpanded = expanded;
119        mHeaderQsPanel.setExpanded(expanded);
120        updateEverything();
121    }
122
123    public void setExpansion(float headerExpansionFraction) {
124    }
125
126    @Override
127    public void disable(int state1, int state2, boolean animate) {
128        final boolean disabled = (state2 & DISABLE2_QUICK_SETTINGS) != 0;
129        if (disabled == mQsDisabled) return;
130        mQsDisabled = disabled;
131        mHeaderQsPanel.setDisabledByPolicy(disabled);
132        final int rawHeight = (int) getResources().getDimension(R.dimen.status_bar_header_height);
133        getLayoutParams().height = disabled ? (rawHeight - mHeaderQsPanel.getHeight()) : rawHeight;
134    }
135
136    @Override
137    public void onAttachedToWindow() {
138        SysUiServiceProvider.getComponent(getContext(), CommandQueue.class).addCallbacks(this);
139    }
140
141    @Override
142    @VisibleForTesting
143    public void onDetachedFromWindow() {
144        setListening(false);
145        SysUiServiceProvider.getComponent(getContext(), CommandQueue.class).removeCallbacks(this);
146        super.onDetachedFromWindow();
147    }
148
149    public void setListening(boolean listening) {
150        if (listening == mListening) {
151            return;
152        }
153        mHeaderQsPanel.setListening(listening);
154        mListening = listening;
155    }
156
157    public void updateEverything() {
158        post(() -> setClickable(false));
159    }
160
161    public void setQSPanel(final QSPanel qsPanel) {
162        mQsPanel = qsPanel;
163        setupHost(qsPanel.getHost());
164    }
165
166    public void setupHost(final QSTileHost host) {
167        mHost = host;
168        //host.setHeaderView(mExpandIndicator);
169        mHeaderQsPanel.setQSPanelAndHeader(mQsPanel, this);
170        mHeaderQsPanel.setHost(host, null /* No customization in header */);
171    }
172
173    public void setCallback(Callback qsPanelCallback) {
174        mHeaderQsPanel.setCallback(qsPanelCallback);
175    }
176}
177