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