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