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; |
Evan Laird | 4ea2a49 | 2018-01-22 11:29:12 -0500 | [diff] [blame^] | 21 | import android.content.Intent; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 22 | import android.content.res.Configuration; |
| 23 | import android.content.res.Resources; |
| 24 | import android.graphics.Color; |
| 25 | import android.graphics.Rect; |
Evan Laird | 4ea2a49 | 2018-01-22 11:29:12 -0500 | [diff] [blame^] | 26 | import android.provider.AlarmClock; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 27 | import android.support.annotation.VisibleForTesting; |
| 28 | import android.util.AttributeSet; |
Jason Monk | 824ffff | 2017-04-11 15:49:06 -0400 | [diff] [blame] | 29 | import android.view.View; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 30 | import android.widget.RelativeLayout; |
Jason Monk | 01df36f | 2017-06-07 13:02:47 -0400 | [diff] [blame] | 31 | import android.widget.TextClock; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 32 | |
| 33 | import com.android.settingslib.Utils; |
| 34 | import com.android.systemui.BatteryMeterView; |
| 35 | import com.android.systemui.Dependency; |
| 36 | import com.android.systemui.R; |
Jason Monk | 01df36f | 2017-06-07 13:02:47 -0400 | [diff] [blame] | 37 | import com.android.systemui.R.id; |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 38 | import com.android.systemui.SysUiServiceProvider; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 39 | import com.android.systemui.plugins.ActivityStarter; |
| 40 | import com.android.systemui.qs.QSDetail.Callback; |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 41 | import com.android.systemui.statusbar.CommandQueue; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 42 | import com.android.systemui.statusbar.SignalClusterView; |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame] | 43 | import com.android.systemui.statusbar.policy.DarkIconDispatcher; |
Jason Monk | 824ffff | 2017-04-11 15:49:06 -0400 | [diff] [blame] | 44 | import com.android.systemui.statusbar.policy.DarkIconDispatcher.DarkReceiver; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 45 | |
Evan Laird | 4ea2a49 | 2018-01-22 11:29:12 -0500 | [diff] [blame^] | 46 | public class QuickStatusBarHeader extends RelativeLayout |
| 47 | implements CommandQueue.Callbacks, View.OnClickListener { |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 48 | |
| 49 | private ActivityStarter mActivityStarter; |
| 50 | |
| 51 | private QSPanel mQsPanel; |
| 52 | |
| 53 | private boolean mExpanded; |
| 54 | private boolean mListening; |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 55 | private boolean mQsDisabled; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 56 | |
| 57 | protected QuickQSPanel mHeaderQsPanel; |
| 58 | protected QSTileHost mHost; |
| 59 | |
Evan Laird | 4ea2a49 | 2018-01-22 11:29:12 -0500 | [diff] [blame^] | 60 | private View mDate; |
| 61 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 62 | public QuickStatusBarHeader(Context context, AttributeSet attrs) { |
| 63 | super(context, attrs); |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | protected void onFinishInflate() { |
| 68 | super.onFinishInflate(); |
| 69 | Resources res = getResources(); |
| 70 | |
| 71 | mHeaderQsPanel = findViewById(R.id.quick_qs_panel); |
Evan Laird | 4ea2a49 | 2018-01-22 11:29:12 -0500 | [diff] [blame^] | 72 | mDate = findViewById(R.id.date); |
| 73 | mDate.setOnClickListener(this); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 74 | |
| 75 | // RenderThread is doing more harm than good when touching the header (to expand quick |
| 76 | // settings), so disable it for this view |
| 77 | |
| 78 | updateResources(); |
| 79 | |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame] | 80 | // 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] | 81 | int colorForeground = Utils.getColorAttr(getContext(), android.R.attr.colorForeground); |
Jason Monk | 824ffff | 2017-04-11 15:49:06 -0400 | [diff] [blame] | 82 | Rect tintArea = new Rect(0, 0, 0, 0); |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame] | 83 | applyDarkness(R.id.clock, tintArea, 0, DarkIconDispatcher.DEFAULT_ICON_TINT); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 84 | |
| 85 | BatteryMeterView battery = findViewById(R.id.battery); |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame] | 86 | battery.setFillColor(Color.WHITE); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 87 | battery.setForceShowPercent(true); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 88 | |
| 89 | mActivityStarter = Dependency.get(ActivityStarter.class); |
| 90 | } |
| 91 | |
Jason Monk | 824ffff | 2017-04-11 15:49:06 -0400 | [diff] [blame] | 92 | private void applyDarkness(int id, Rect tintArea, float intensity, int color) { |
| 93 | View v = findViewById(id); |
| 94 | if (v instanceof DarkReceiver) { |
| 95 | ((DarkReceiver) v).onDarkChanged(tintArea, intensity, color); |
| 96 | } |
| 97 | } |
| 98 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 99 | @Override |
| 100 | protected void onConfigurationChanged(Configuration newConfig) { |
| 101 | super.onConfigurationChanged(newConfig); |
| 102 | updateResources(); |
| 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public void onRtlPropertiesChanged(int layoutDirection) { |
| 107 | super.onRtlPropertiesChanged(layoutDirection); |
| 108 | updateResources(); |
| 109 | } |
| 110 | |
| 111 | private void updateResources() { |
| 112 | } |
| 113 | |
| 114 | public int getCollapsedHeight() { |
| 115 | return getHeight(); |
| 116 | } |
| 117 | |
| 118 | public int getExpandedHeight() { |
| 119 | return getHeight(); |
| 120 | } |
| 121 | |
| 122 | public void setExpanded(boolean expanded) { |
| 123 | if (mExpanded == expanded) return; |
| 124 | mExpanded = expanded; |
| 125 | mHeaderQsPanel.setExpanded(expanded); |
| 126 | updateEverything(); |
| 127 | } |
| 128 | |
| 129 | public void setExpansion(float headerExpansionFraction) { |
| 130 | } |
| 131 | |
| 132 | @Override |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 133 | public void disable(int state1, int state2, boolean animate) { |
| 134 | final boolean disabled = (state2 & DISABLE2_QUICK_SETTINGS) != 0; |
| 135 | if (disabled == mQsDisabled) return; |
| 136 | mQsDisabled = disabled; |
| 137 | mHeaderQsPanel.setDisabledByPolicy(disabled); |
| 138 | final int rawHeight = (int) getResources().getDimension(R.dimen.status_bar_header_height); |
| 139 | getLayoutParams().height = disabled ? (rawHeight - mHeaderQsPanel.getHeight()) : rawHeight; |
| 140 | } |
| 141 | |
| 142 | @Override |
| 143 | public void onAttachedToWindow() { |
| 144 | SysUiServiceProvider.getComponent(getContext(), CommandQueue.class).addCallbacks(this); |
| 145 | } |
| 146 | |
| 147 | @Override |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 148 | @VisibleForTesting |
| 149 | public void onDetachedFromWindow() { |
| 150 | setListening(false); |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 151 | SysUiServiceProvider.getComponent(getContext(), CommandQueue.class).removeCallbacks(this); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 152 | super.onDetachedFromWindow(); |
| 153 | } |
| 154 | |
Evan Laird | 4ea2a49 | 2018-01-22 11:29:12 -0500 | [diff] [blame^] | 155 | @Override |
| 156 | public void onClick(View v) { |
| 157 | if (v == mDate) { |
| 158 | Dependency.get(ActivityStarter.class).postStartActivityDismissingKeyguard(new Intent( |
| 159 | AlarmClock.ACTION_SHOW_ALARMS), 0); |
| 160 | } |
| 161 | } |
| 162 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 163 | public void setListening(boolean listening) { |
| 164 | if (listening == mListening) { |
| 165 | return; |
| 166 | } |
| 167 | mHeaderQsPanel.setListening(listening); |
| 168 | mListening = listening; |
| 169 | } |
| 170 | |
| 171 | public void updateEverything() { |
Jason Monk | 1fdde2d | 2017-03-08 09:39:21 -0500 | [diff] [blame] | 172 | post(() -> setClickable(false)); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | public void setQSPanel(final QSPanel qsPanel) { |
| 176 | mQsPanel = qsPanel; |
| 177 | setupHost(qsPanel.getHost()); |
| 178 | } |
| 179 | |
| 180 | public void setupHost(final QSTileHost host) { |
| 181 | mHost = host; |
| 182 | //host.setHeaderView(mExpandIndicator); |
| 183 | mHeaderQsPanel.setQSPanelAndHeader(mQsPanel, this); |
| 184 | mHeaderQsPanel.setHost(host, null /* No customization in header */); |
| 185 | } |
| 186 | |
| 187 | public void setCallback(Callback qsPanelCallback) { |
| 188 | mHeaderQsPanel.setCallback(qsPanelCallback); |
| 189 | } |
| 190 | } |