Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.qs; |
| 18 | |
| 19 | import android.content.Context; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 20 | import android.util.AttributeSet; |
Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 21 | import android.view.Gravity; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 22 | import android.view.View; |
Jason Monk | 231b052 | 2018-01-04 10:49:55 -0500 | [diff] [blame] | 23 | import android.view.ViewGroup; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 24 | import android.widget.LinearLayout; |
Jason Monk | db50de8 | 2016-02-03 15:34:54 -0500 | [diff] [blame] | 25 | import android.widget.Space; |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 26 | |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 27 | import com.android.systemui.Dependency; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 28 | import com.android.systemui.R; |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 29 | import com.android.systemui.plugins.qs.QSTile; |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 30 | import com.android.systemui.plugins.qs.QSTile.SignalState; |
| 31 | import com.android.systemui.plugins.qs.QSTile.State; |
| 32 | import com.android.systemui.plugins.qs.QSTileView; |
Jason Monk | a9df999 | 2016-03-15 12:41:13 -0400 | [diff] [blame] | 33 | import com.android.systemui.qs.customize.QSCustomizer; |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 34 | import com.android.systemui.tuner.TunerService; |
| 35 | import com.android.systemui.tuner.TunerService.Tunable; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 36 | |
| 37 | import java.util.ArrayList; |
| 38 | import java.util.Collection; |
| 39 | |
| 40 | /** |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 41 | * Version of QSPanel that only shows N Quick Tiles in the QS Header. |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 42 | */ |
| 43 | public class QuickQSPanel extends QSPanel { |
| 44 | |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 45 | public static final String NUM_QUICK_TILES = "sysui_qqs_count"; |
| 46 | |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 47 | private boolean mDisabledByPolicy; |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 48 | private int mMaxTiles; |
Muyuan Li | 0e9f538 | 2016-04-27 15:51:15 -0700 | [diff] [blame] | 49 | protected QSPanel mFullPanel; |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 50 | |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 51 | public QuickQSPanel(Context context, AttributeSet attrs) { |
| 52 | super(context, attrs); |
phweiss | e398331 | 2017-02-17 15:14:19 +0100 | [diff] [blame] | 53 | if (mFooter != null) { |
Jason Monk | 231b052 | 2018-01-04 10:49:55 -0500 | [diff] [blame] | 54 | removeView(mFooter.getView()); |
phweiss | e398331 | 2017-02-17 15:14:19 +0100 | [diff] [blame] | 55 | } |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 56 | if (mTileLayout != null) { |
| 57 | for (int i = 0; i < mRecords.size(); i++) { |
| 58 | mTileLayout.removeTile(mRecords.get(i)); |
| 59 | } |
Amin Shaikh | 15781d6 | 2018-02-16 16:00:13 -0500 | [diff] [blame] | 60 | removeView((View) mTileLayout); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 61 | } |
| 62 | mTileLayout = new HeaderTileLayout(context); |
Jason Monk | 1bec6af | 2016-05-31 15:40:58 -0400 | [diff] [blame] | 63 | mTileLayout.setListening(mListening); |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 64 | addView((View) mTileLayout, 0 /* Between brightness and footer */); |
Jason Monk | 7b3d4e4 | 2017-05-30 12:47:10 -0400 | [diff] [blame] | 65 | super.setPadding(0, 0, 0, 0); |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public void setPadding(int left, int top, int right, int bottom) { |
| 70 | // Always have no padding. |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 71 | } |
| 72 | |
Jason Monk | 51c444b | 2016-01-06 16:32:29 -0500 | [diff] [blame] | 73 | @Override |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 74 | protected void addDivider() { |
| 75 | } |
| 76 | |
| 77 | @Override |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 78 | protected void onAttachedToWindow() { |
| 79 | super.onAttachedToWindow(); |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 80 | Dependency.get(TunerService.class).addTunable(mNumTiles, NUM_QUICK_TILES); |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | @Override |
| 84 | protected void onDetachedFromWindow() { |
| 85 | super.onDetachedFromWindow(); |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 86 | Dependency.get(TunerService.class).removeTunable(mNumTiles); |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 87 | } |
| 88 | |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 89 | public void setQSPanelAndHeader(QSPanel fullPanel, View header) { |
| 90 | mFullPanel = fullPanel; |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | @Override |
Xiaohui Chen | 6644893 | 2016-04-18 12:53:28 -0700 | [diff] [blame] | 94 | protected boolean shouldShowDetail() { |
| 95 | return !mExpanded; |
| 96 | } |
| 97 | |
| 98 | @Override |
Jason Monk | ec87a87 | 2016-03-01 15:00:16 -0500 | [diff] [blame] | 99 | protected void drawTile(TileRecord r, State state) { |
| 100 | if (state instanceof SignalState) { |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 101 | SignalState copy = new SignalState(); |
Jason Monk | ec87a87 | 2016-03-01 15:00:16 -0500 | [diff] [blame] | 102 | state.copyTo(copy); |
| 103 | // No activity shown in the quick panel. |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 104 | copy.activityIn = false; |
| 105 | copy.activityOut = false; |
Jason Monk | ec87a87 | 2016-03-01 15:00:16 -0500 | [diff] [blame] | 106 | state = copy; |
| 107 | } |
| 108 | super.drawTile(r, state); |
| 109 | } |
| 110 | |
| 111 | @Override |
Jason Monk | a9df999 | 2016-03-15 12:41:13 -0400 | [diff] [blame] | 112 | public void setHost(QSTileHost host, QSCustomizer customizer) { |
| 113 | super.setHost(host, customizer); |
| 114 | setTiles(mHost.getTiles()); |
| 115 | } |
| 116 | |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 117 | public void setMaxTiles(int maxTiles) { |
| 118 | mMaxTiles = maxTiles; |
Jason Monk | a9df999 | 2016-03-15 12:41:13 -0400 | [diff] [blame] | 119 | if (mHost != null) { |
| 120 | setTiles(mHost.getTiles()); |
| 121 | } |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | @Override |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 125 | public void onTuningChanged(String key, String newValue) { |
Evan Laird | 92fbcb2 | 2018-02-16 15:25:53 +0000 | [diff] [blame] | 126 | // No tunings for you. |
| 127 | if (key.equals(QS_SHOW_BRIGHTNESS)) { |
| 128 | // No Brightness for you. |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 129 | super.onTuningChanged(key, "0"); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | @Override |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 134 | public void setTiles(Collection<QSTile> tiles) { |
| 135 | ArrayList<QSTile> quickTiles = new ArrayList<>(); |
| 136 | for (QSTile tile : tiles) { |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 137 | quickTiles.add(tile); |
| 138 | if (quickTiles.size() == mMaxTiles) { |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 139 | break; |
| 140 | } |
| 141 | } |
Jason Monk | c59249f | 2016-06-17 10:19:43 -0400 | [diff] [blame] | 142 | super.setTiles(quickTiles, true); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 143 | } |
| 144 | |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 145 | private final Tunable mNumTiles = new Tunable() { |
| 146 | @Override |
| 147 | public void onTuningChanged(String key, String newValue) { |
| 148 | setMaxTiles(getNumQuickTiles(mContext)); |
| 149 | } |
| 150 | }; |
| 151 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 152 | public static int getNumQuickTiles(Context context) { |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 153 | return Dependency.get(TunerService.class).getValue(NUM_QUICK_TILES, 6); |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 154 | } |
| 155 | |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 156 | void setDisabledByPolicy(boolean disabled) { |
| 157 | if (disabled != mDisabledByPolicy) { |
| 158 | mDisabledByPolicy = disabled; |
| 159 | setVisibility(disabled ? View.GONE : View.VISIBLE); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Sets the visibility of this {@link QuickQSPanel}. This method has no effect when this panel |
| 165 | * is disabled by policy through {@link #setDisabledByPolicy(boolean)}, and in this case the |
| 166 | * visibility will always be {@link View#GONE}. This method is called externally by |
| 167 | * {@link QSAnimator} only. |
| 168 | */ |
| 169 | @Override |
| 170 | public void setVisibility(int visibility) { |
| 171 | if (mDisabledByPolicy) { |
| 172 | if (getVisibility() == View.GONE) { |
| 173 | return; |
| 174 | } |
| 175 | visibility = View.GONE; |
| 176 | } |
| 177 | super.setVisibility(visibility); |
| 178 | } |
| 179 | |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 180 | private static class HeaderTileLayout extends LinearLayout implements QSTileLayout { |
| 181 | |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 182 | protected final ArrayList<TileRecord> mRecords = new ArrayList<>(); |
Jason Monk | 1bec6af | 2016-05-31 15:40:58 -0400 | [diff] [blame] | 183 | private boolean mListening; |
Jason Monk | fece2ab | 2016-02-04 11:41:18 -0500 | [diff] [blame] | 184 | |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 185 | public HeaderTileLayout(Context context) { |
| 186 | super(context); |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 187 | setClipChildren(false); |
| 188 | setClipToPadding(false); |
Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 189 | setGravity(Gravity.CENTER_VERTICAL); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 190 | setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); |
Jason Monk | fece2ab | 2016-02-04 11:41:18 -0500 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | @Override |
Jason Monk | 1bec6af | 2016-05-31 15:40:58 -0400 | [diff] [blame] | 194 | public void setListening(boolean listening) { |
| 195 | if (mListening == listening) return; |
| 196 | mListening = listening; |
| 197 | for (TileRecord record : mRecords) { |
| 198 | record.tile.setListening(this, mListening); |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | @Override |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 203 | public void addTile(TileRecord tile) { |
Jason Monk | 4bb7b1a | 2016-05-27 15:19:15 -0400 | [diff] [blame] | 204 | if (getChildCount() != 0) { |
| 205 | // Add a spacer. |
| 206 | addView(new Space(mContext), getChildCount(), generateSpaceParams()); |
| 207 | } |
| 208 | addView(tile.tileView, getChildCount(), generateLayoutParams()); |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 209 | mRecords.add(tile); |
Jason Monk | 1bec6af | 2016-05-31 15:40:58 -0400 | [diff] [blame] | 210 | tile.tile.setListening(this, mListening); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 211 | } |
| 212 | |
Jason Monk | db50de8 | 2016-02-03 15:34:54 -0500 | [diff] [blame] | 213 | private LayoutParams generateSpaceParams() { |
Jason Monk | deba7a4 | 2015-12-08 16:14:10 -0500 | [diff] [blame] | 214 | int size = mContext.getResources().getDimensionPixelSize(R.dimen.qs_quick_tile_size); |
| 215 | LayoutParams lp = new LayoutParams(0, size); |
| 216 | lp.weight = 1; |
| 217 | lp.gravity = Gravity.CENTER; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 218 | return lp; |
| 219 | } |
| 220 | |
Jason Monk | db50de8 | 2016-02-03 15:34:54 -0500 | [diff] [blame] | 221 | private LayoutParams generateLayoutParams() { |
| 222 | int size = mContext.getResources().getDimensionPixelSize(R.dimen.qs_quick_tile_size); |
| 223 | LayoutParams lp = new LayoutParams(size, size); |
| 224 | lp.gravity = Gravity.CENTER; |
| 225 | return lp; |
| 226 | } |
| 227 | |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 228 | @Override |
| 229 | public void removeTile(TileRecord tile) { |
Jason Monk | db50de8 | 2016-02-03 15:34:54 -0500 | [diff] [blame] | 230 | int childIndex = getChildIndex(tile.tileView); |
| 231 | // Remove the tile. |
| 232 | removeViewAt(childIndex); |
Jason Monk | 4bb7b1a | 2016-05-27 15:19:15 -0400 | [diff] [blame] | 233 | if (getChildCount() != 0) { |
| 234 | // Remove its spacer as well. |
| 235 | removeViewAt(childIndex); |
| 236 | } |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 237 | mRecords.remove(tile); |
Jason Monk | 1bec6af | 2016-05-31 15:40:58 -0400 | [diff] [blame] | 238 | tile.tile.setListening(this, false); |
Jason Monk | db50de8 | 2016-02-03 15:34:54 -0500 | [diff] [blame] | 239 | } |
| 240 | |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 241 | private int getChildIndex(QSTileView tileView) { |
Jason Monk | db50de8 | 2016-02-03 15:34:54 -0500 | [diff] [blame] | 242 | final int N = getChildCount(); |
| 243 | for (int i = 0; i < N; i++) { |
| 244 | if (getChildAt(i) == tileView) { |
| 245 | return i; |
| 246 | } |
| 247 | } |
| 248 | return -1; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | @Override |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 252 | public int getOffsetTop(TileRecord tile) { |
| 253 | return 0; |
| 254 | } |
| 255 | |
| 256 | @Override |
Jason Monk | 9d02a43 | 2016-01-20 16:33:46 -0500 | [diff] [blame] | 257 | public boolean updateResources() { |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 258 | // No resources here. |
Jason Monk | 9d02a43 | 2016-01-20 16:33:46 -0500 | [diff] [blame] | 259 | return false; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 260 | } |
Jason Monk | c5bdafb | 2016-02-25 16:24:21 -0500 | [diff] [blame] | 261 | |
| 262 | @Override |
| 263 | public boolean hasOverlappingRendering() { |
| 264 | return false; |
| 265 | } |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 266 | |
| 267 | @Override |
| 268 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 269 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 270 | if (mRecords != null && mRecords.size() > 0) { |
| 271 | View previousView = this; |
| 272 | for (TileRecord record : mRecords) { |
| 273 | if (record.tileView.getVisibility() == GONE) continue; |
| 274 | previousView = record.tileView.updateAccessibilityOrder(previousView); |
| 275 | } |
| 276 | mRecords.get(0).tileView.setAccessibilityTraversalAfter( |
| 277 | R.id.alarm_status_collapsed); |
| 278 | mRecords.get(mRecords.size() - 1).tileView.setAccessibilityTraversalBefore( |
| 279 | R.id.expand_indicator); |
| 280 | } |
| 281 | } |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 282 | } |
| 283 | } |