Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 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 | |
| 15 | package com.android.systemui.qs; |
| 16 | |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 17 | import static android.app.StatusBarManager.DISABLE2_QUICK_SETTINGS; |
| 18 | import static android.app.StatusBarManager.DISABLE_NONE; |
| 19 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 20 | import android.content.Context; |
| 21 | import android.content.res.Configuration; |
| 22 | import android.content.res.Resources; |
| 23 | import android.graphics.Color; |
| 24 | import android.graphics.Rect; |
| 25 | import android.support.annotation.VisibleForTesting; |
| 26 | import android.util.AttributeSet; |
Jason Monk | 824ffff | 2017-04-11 15:49:06 -0400 | [diff] [blame] | 27 | import android.view.View; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 28 | import android.widget.RelativeLayout; |
Jason Monk | 01df36f | 2017-06-07 13:02:47 -0400 | [diff] [blame] | 29 | import android.widget.TextClock; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 30 | |
| 31 | import com.android.settingslib.Utils; |
| 32 | import com.android.systemui.BatteryMeterView; |
| 33 | import com.android.systemui.Dependency; |
| 34 | import com.android.systemui.R; |
Jason Monk | 01df36f | 2017-06-07 13:02:47 -0400 | [diff] [blame] | 35 | import com.android.systemui.R.id; |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 36 | import com.android.systemui.SysUiServiceProvider; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 37 | import com.android.systemui.plugins.ActivityStarter; |
| 38 | import com.android.systemui.qs.QSDetail.Callback; |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 39 | import com.android.systemui.statusbar.CommandQueue; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 40 | import com.android.systemui.statusbar.SignalClusterView; |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame^] | 41 | import com.android.systemui.statusbar.policy.DarkIconDispatcher; |
Jason Monk | 824ffff | 2017-04-11 15:49:06 -0400 | [diff] [blame] | 42 | import com.android.systemui.statusbar.policy.DarkIconDispatcher.DarkReceiver; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 43 | |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 44 | public class QuickStatusBarHeader extends RelativeLayout implements CommandQueue.Callbacks { |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 45 | |
| 46 | private ActivityStarter mActivityStarter; |
| 47 | |
| 48 | private QSPanel mQsPanel; |
| 49 | |
| 50 | private boolean mExpanded; |
| 51 | private boolean mListening; |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 52 | private boolean mQsDisabled; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 53 | |
| 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 Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 67 | |
| 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 Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame^] | 73 | // Set light text on the header icons because they will always be on a black background |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 74 | int colorForeground = Utils.getColorAttr(getContext(), android.R.attr.colorForeground); |
Jason Monk | 824ffff | 2017-04-11 15:49:06 -0400 | [diff] [blame] | 75 | Rect tintArea = new Rect(0, 0, 0, 0); |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame^] | 76 | applyDarkness(R.id.clock, tintArea, 0, DarkIconDispatcher.DEFAULT_ICON_TINT); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 77 | |
| 78 | BatteryMeterView battery = findViewById(R.id.battery); |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame^] | 79 | battery.setFillColor(Color.WHITE); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 80 | battery.setForceShowPercent(true); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 81 | |
| 82 | mActivityStarter = Dependency.get(ActivityStarter.class); |
| 83 | } |
| 84 | |
Jason Monk | 824ffff | 2017-04-11 15:49:06 -0400 | [diff] [blame] | 85 | 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 Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 92 | @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 He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 126 | 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 Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 141 | @VisibleForTesting |
| 142 | public void onDetachedFromWindow() { |
| 143 | setListening(false); |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 144 | SysUiServiceProvider.getComponent(getContext(), CommandQueue.class).removeCallbacks(this); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 145 | 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 Monk | 1fdde2d | 2017-03-08 09:39:21 -0500 | [diff] [blame] | 157 | post(() -> setClickable(false)); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 158 | } |
| 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 | } |