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; |
Rohan Shah | 1439464 | 2018-03-13 20:10:12 -0700 | [diff] [blame^] | 20 | import android.content.res.Configuration; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 21 | import android.util.AttributeSet; |
Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 22 | import android.view.Gravity; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 23 | import android.view.View; |
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) { |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 126 | if (QS_SHOW_BRIGHTNESS.equals(key)) { |
Rohan Shah | db2cfa3 | 2018-02-20 11:27:22 -0800 | [diff] [blame] | 127 | // No Brightness or Tooltip for you! |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 128 | super.onTuningChanged(key, "0"); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | @Override |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 133 | public void setTiles(Collection<QSTile> tiles) { |
| 134 | ArrayList<QSTile> quickTiles = new ArrayList<>(); |
| 135 | for (QSTile tile : tiles) { |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 136 | quickTiles.add(tile); |
| 137 | if (quickTiles.size() == mMaxTiles) { |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 138 | break; |
| 139 | } |
| 140 | } |
Jason Monk | c59249f | 2016-06-17 10:19:43 -0400 | [diff] [blame] | 141 | super.setTiles(quickTiles, true); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 142 | } |
| 143 | |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 144 | private final Tunable mNumTiles = new Tunable() { |
| 145 | @Override |
| 146 | public void onTuningChanged(String key, String newValue) { |
| 147 | setMaxTiles(getNumQuickTiles(mContext)); |
| 148 | } |
| 149 | }; |
| 150 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 151 | public static int getNumQuickTiles(Context context) { |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 152 | return Dependency.get(TunerService.class).getValue(NUM_QUICK_TILES, 6); |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 153 | } |
| 154 | |
Charles He | ce2a7c0 | 2017-10-11 20:25:20 +0100 | [diff] [blame] | 155 | void setDisabledByPolicy(boolean disabled) { |
| 156 | if (disabled != mDisabledByPolicy) { |
| 157 | mDisabledByPolicy = disabled; |
| 158 | setVisibility(disabled ? View.GONE : View.VISIBLE); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Sets the visibility of this {@link QuickQSPanel}. This method has no effect when this panel |
| 164 | * is disabled by policy through {@link #setDisabledByPolicy(boolean)}, and in this case the |
| 165 | * visibility will always be {@link View#GONE}. This method is called externally by |
| 166 | * {@link QSAnimator} only. |
| 167 | */ |
| 168 | @Override |
| 169 | public void setVisibility(int visibility) { |
| 170 | if (mDisabledByPolicy) { |
| 171 | if (getVisibility() == View.GONE) { |
| 172 | return; |
| 173 | } |
| 174 | visibility = View.GONE; |
| 175 | } |
| 176 | super.setVisibility(visibility); |
| 177 | } |
| 178 | |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 179 | private static class HeaderTileLayout extends LinearLayout implements QSTileLayout { |
| 180 | |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 181 | protected final ArrayList<TileRecord> mRecords = new ArrayList<>(); |
Jason Monk | 1bec6af | 2016-05-31 15:40:58 -0400 | [diff] [blame] | 182 | private boolean mListening; |
Rohan Shah | 1439464 | 2018-03-13 20:10:12 -0700 | [diff] [blame^] | 183 | /** Size of the QS tile (width & height). */ |
| 184 | private int mTileDimensionSize; |
Jason Monk | fece2ab | 2016-02-04 11:41:18 -0500 | [diff] [blame] | 185 | |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 186 | public HeaderTileLayout(Context context) { |
| 187 | super(context); |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 188 | setClipChildren(false); |
| 189 | setClipToPadding(false); |
Rohan Shah | 1439464 | 2018-03-13 20:10:12 -0700 | [diff] [blame^] | 190 | |
| 191 | mTileDimensionSize = mContext.getResources().getDimensionPixelSize( |
| 192 | R.dimen.qs_quick_tile_size); |
| 193 | |
| 194 | setGravity(Gravity.CENTER); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 195 | setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); |
Jason Monk | fece2ab | 2016-02-04 11:41:18 -0500 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | @Override |
Rohan Shah | 1439464 | 2018-03-13 20:10:12 -0700 | [diff] [blame^] | 199 | protected void onConfigurationChanged(Configuration newConfig) { |
| 200 | super.onConfigurationChanged(newConfig); |
| 201 | |
| 202 | setGravity(Gravity.CENTER); |
| 203 | LayoutParams staticSpaceLayoutParams = generateSpaceLayoutParams( |
| 204 | mContext.getResources().getDimensionPixelSize( |
| 205 | R.dimen.qs_quick_tile_space_width)); |
| 206 | |
| 207 | // Update space params since they fill any open space in portrait orientation and have |
| 208 | // a static width in landscape orientation. |
| 209 | final int childViewCount = getChildCount(); |
| 210 | for (int i = 0; i < childViewCount; i++) { |
| 211 | View childView = getChildAt(i); |
| 212 | if (childView instanceof Space) { |
| 213 | childView.setLayoutParams(staticSpaceLayoutParams); |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | /** |
| 219 | * Returns {@link LayoutParams} based on the given {@code spaceWidth}. If the width is 0, |
| 220 | * then we're going to have the space expand to take up as much space as possible. If the |
| 221 | * width is non-zero, we want the inter-tile spacers to be fixed. |
| 222 | */ |
| 223 | private LayoutParams generateSpaceLayoutParams(int spaceWidth) { |
| 224 | LayoutParams lp = new LayoutParams(spaceWidth, mTileDimensionSize); |
| 225 | if (spaceWidth == 0) { |
| 226 | lp.weight = 1; |
| 227 | } |
| 228 | lp.gravity = Gravity.CENTER; |
| 229 | return lp; |
| 230 | } |
| 231 | |
| 232 | @Override |
Jason Monk | 1bec6af | 2016-05-31 15:40:58 -0400 | [diff] [blame] | 233 | public void setListening(boolean listening) { |
| 234 | if (mListening == listening) return; |
| 235 | mListening = listening; |
| 236 | for (TileRecord record : mRecords) { |
| 237 | record.tile.setListening(this, mListening); |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | @Override |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 242 | public void addTile(TileRecord tile) { |
Jason Monk | 4bb7b1a | 2016-05-27 15:19:15 -0400 | [diff] [blame] | 243 | if (getChildCount() != 0) { |
Rohan Shah | 1439464 | 2018-03-13 20:10:12 -0700 | [diff] [blame^] | 244 | // Add a spacer between tiles. We want static-width spaces if we're in landscape to |
| 245 | // keep the tiles close. For portrait, we stick with spaces that fill up any |
| 246 | // available space. |
| 247 | LayoutParams spaceLayoutParams = generateSpaceLayoutParams( |
| 248 | mContext.getResources().getDimensionPixelSize( |
| 249 | R.dimen.qs_quick_tile_space_width)); |
| 250 | addView(new Space(mContext), getChildCount(), spaceLayoutParams); |
Jason Monk | 4bb7b1a | 2016-05-27 15:19:15 -0400 | [diff] [blame] | 251 | } |
Rohan Shah | 1439464 | 2018-03-13 20:10:12 -0700 | [diff] [blame^] | 252 | |
| 253 | addView(tile.tileView, getChildCount(), generateTileLayoutParams()); |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 254 | mRecords.add(tile); |
Jason Monk | 1bec6af | 2016-05-31 15:40:58 -0400 | [diff] [blame] | 255 | tile.tile.setListening(this, mListening); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 256 | } |
| 257 | |
Rohan Shah | 1439464 | 2018-03-13 20:10:12 -0700 | [diff] [blame^] | 258 | private LayoutParams generateTileLayoutParams() { |
| 259 | LayoutParams lp = new LayoutParams(mTileDimensionSize, mTileDimensionSize); |
Jason Monk | db50de8 | 2016-02-03 15:34:54 -0500 | [diff] [blame] | 260 | lp.gravity = Gravity.CENTER; |
| 261 | return lp; |
| 262 | } |
| 263 | |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 264 | @Override |
| 265 | public void removeTile(TileRecord tile) { |
Jason Monk | db50de8 | 2016-02-03 15:34:54 -0500 | [diff] [blame] | 266 | int childIndex = getChildIndex(tile.tileView); |
| 267 | // Remove the tile. |
| 268 | removeViewAt(childIndex); |
Jason Monk | 4bb7b1a | 2016-05-27 15:19:15 -0400 | [diff] [blame] | 269 | if (getChildCount() != 0) { |
| 270 | // Remove its spacer as well. |
| 271 | removeViewAt(childIndex); |
| 272 | } |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 273 | mRecords.remove(tile); |
Jason Monk | 1bec6af | 2016-05-31 15:40:58 -0400 | [diff] [blame] | 274 | tile.tile.setListening(this, false); |
Jason Monk | db50de8 | 2016-02-03 15:34:54 -0500 | [diff] [blame] | 275 | } |
| 276 | |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 277 | private int getChildIndex(QSTileView tileView) { |
Rohan Shah | 1439464 | 2018-03-13 20:10:12 -0700 | [diff] [blame^] | 278 | final int childViewCount = getChildCount(); |
| 279 | for (int i = 0; i < childViewCount; i++) { |
Jason Monk | db50de8 | 2016-02-03 15:34:54 -0500 | [diff] [blame] | 280 | if (getChildAt(i) == tileView) { |
| 281 | return i; |
| 282 | } |
| 283 | } |
| 284 | return -1; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | @Override |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 288 | public int getOffsetTop(TileRecord tile) { |
| 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | @Override |
Jason Monk | 9d02a43 | 2016-01-20 16:33:46 -0500 | [diff] [blame] | 293 | public boolean updateResources() { |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 294 | // No resources here. |
Jason Monk | 9d02a43 | 2016-01-20 16:33:46 -0500 | [diff] [blame] | 295 | return false; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 296 | } |
Jason Monk | c5bdafb | 2016-02-25 16:24:21 -0500 | [diff] [blame] | 297 | |
| 298 | @Override |
| 299 | public boolean hasOverlappingRendering() { |
| 300 | return false; |
| 301 | } |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 302 | |
| 303 | @Override |
| 304 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 305 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 306 | if (mRecords != null && mRecords.size() > 0) { |
| 307 | View previousView = this; |
| 308 | for (TileRecord record : mRecords) { |
| 309 | if (record.tileView.getVisibility() == GONE) continue; |
| 310 | previousView = record.tileView.updateAccessibilityOrder(previousView); |
| 311 | } |
| 312 | mRecords.get(0).tileView.setAccessibilityTraversalAfter( |
| 313 | R.id.alarm_status_collapsed); |
| 314 | mRecords.get(mRecords.size() - 1).tileView.setAccessibilityTraversalBefore( |
| 315 | R.id.expand_indicator); |
| 316 | } |
| 317 | } |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 318 | } |
| 319 | } |