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; |
Fabian Kozynski | 5272830 | 2018-09-07 12:45:59 +0000 | [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; |
Fabian Kozynski | 5272830 | 2018-09-07 12:45:59 +0000 | [diff] [blame^] | 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; |
Bill Lin | ad15fe33 | 2018-06-13 19:26:15 +0800 | [diff] [blame] | 48 | private static int mDefaultMaxTiles; |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 49 | private int mMaxTiles; |
Muyuan Li | 0e9f538 | 2016-04-27 15:51:15 -0700 | [diff] [blame] | 50 | protected QSPanel mFullPanel; |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 51 | |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 52 | public QuickQSPanel(Context context, AttributeSet attrs) { |
| 53 | super(context, attrs); |
phweiss | e398331 | 2017-02-17 15:14:19 +0100 | [diff] [blame] | 54 | if (mFooter != null) { |
Jason Monk | 231b052 | 2018-01-04 10:49:55 -0500 | [diff] [blame] | 55 | removeView(mFooter.getView()); |
phweiss | e398331 | 2017-02-17 15:14:19 +0100 | [diff] [blame] | 56 | } |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 57 | if (mTileLayout != null) { |
| 58 | for (int i = 0; i < mRecords.size(); i++) { |
| 59 | mTileLayout.removeTile(mRecords.get(i)); |
| 60 | } |
Amin Shaikh | 15781d6 | 2018-02-16 16:00:13 -0500 | [diff] [blame] | 61 | removeView((View) mTileLayout); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 62 | } |
Bill Lin | ad15fe33 | 2018-06-13 19:26:15 +0800 | [diff] [blame] | 63 | mDefaultMaxTiles = getResources().getInteger(R.integer.quick_qs_panel_max_columns); |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 64 | mTileLayout = new HeaderTileLayout(context); |
Jason Monk | 1bec6af | 2016-05-31 15:40:58 -0400 | [diff] [blame] | 65 | mTileLayout.setListening(mListening); |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 66 | addView((View) mTileLayout, 0 /* Between brightness and footer */); |
Jason Monk | 7b3d4e4 | 2017-05-30 12:47:10 -0400 | [diff] [blame] | 67 | super.setPadding(0, 0, 0, 0); |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public void setPadding(int left, int top, int right, int bottom) { |
| 72 | // Always have no padding. |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 73 | } |
| 74 | |
Jason Monk | 51c444b | 2016-01-06 16:32:29 -0500 | [diff] [blame] | 75 | @Override |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 76 | protected void addDivider() { |
| 77 | } |
| 78 | |
| 79 | @Override |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 80 | protected void onAttachedToWindow() { |
| 81 | super.onAttachedToWindow(); |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 82 | Dependency.get(TunerService.class).addTunable(mNumTiles, NUM_QUICK_TILES); |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | @Override |
| 86 | protected void onDetachedFromWindow() { |
| 87 | super.onDetachedFromWindow(); |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 88 | Dependency.get(TunerService.class).removeTunable(mNumTiles); |
Jason Monk | 8fb7787 | 2016-03-03 16:39:42 -0500 | [diff] [blame] | 89 | } |
| 90 | |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 91 | public void setQSPanelAndHeader(QSPanel fullPanel, View header) { |
| 92 | mFullPanel = fullPanel; |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | @Override |
Xiaohui Chen | 6644893 | 2016-04-18 12:53:28 -0700 | [diff] [blame] | 96 | protected boolean shouldShowDetail() { |
| 97 | return !mExpanded; |
| 98 | } |
| 99 | |
| 100 | @Override |
Jason Monk | ec87a87 | 2016-03-01 15:00:16 -0500 | [diff] [blame] | 101 | protected void drawTile(TileRecord r, State state) { |
| 102 | if (state instanceof SignalState) { |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 103 | SignalState copy = new SignalState(); |
Jason Monk | ec87a87 | 2016-03-01 15:00:16 -0500 | [diff] [blame] | 104 | state.copyTo(copy); |
| 105 | // No activity shown in the quick panel. |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 106 | copy.activityIn = false; |
| 107 | copy.activityOut = false; |
Jason Monk | ec87a87 | 2016-03-01 15:00:16 -0500 | [diff] [blame] | 108 | state = copy; |
| 109 | } |
| 110 | super.drawTile(r, state); |
| 111 | } |
| 112 | |
| 113 | @Override |
Jason Monk | a9df999 | 2016-03-15 12:41:13 -0400 | [diff] [blame] | 114 | public void setHost(QSTileHost host, QSCustomizer customizer) { |
| 115 | super.setHost(host, customizer); |
| 116 | setTiles(mHost.getTiles()); |
| 117 | } |
| 118 | |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 119 | public void setMaxTiles(int maxTiles) { |
| 120 | mMaxTiles = maxTiles; |
Jason Monk | a9df999 | 2016-03-15 12:41:13 -0400 | [diff] [blame] | 121 | if (mHost != null) { |
| 122 | setTiles(mHost.getTiles()); |
| 123 | } |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | @Override |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 127 | public void onTuningChanged(String key, String newValue) { |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 128 | if (QS_SHOW_BRIGHTNESS.equals(key)) { |
Rohan Shah | db2cfa3 | 2018-02-20 11:27:22 -0800 | [diff] [blame] | 129 | // No Brightness or Tooltip for you! |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 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) { |
Bill Lin | ad15fe33 | 2018-06-13 19:26:15 +0800 | [diff] [blame] | 154 | return Dependency.get(TunerService.class).getValue(NUM_QUICK_TILES, mDefaultMaxTiles); |
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 | |
Fabian Kozynski | 5272830 | 2018-09-07 12:45:59 +0000 | [diff] [blame^] | 181 | private static class HeaderTileLayout extends LinearLayout implements QSTileLayout { |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 182 | |
Fabian Kozynski | 5272830 | 2018-09-07 12:45:59 +0000 | [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; |
Fabian Kozynski | 5272830 | 2018-09-07 12:45:59 +0000 | [diff] [blame^] | 185 | /** Size of the QS tile (width & height). */ |
| 186 | private int mTileDimensionSize; |
Jason Monk | fece2ab | 2016-02-04 11:41:18 -0500 | [diff] [blame] | 187 | |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 188 | public HeaderTileLayout(Context context) { |
| 189 | super(context); |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 190 | setClipChildren(false); |
| 191 | setClipToPadding(false); |
Fabian Kozynski | 5272830 | 2018-09-07 12:45:59 +0000 | [diff] [blame^] | 192 | |
| 193 | mTileDimensionSize = mContext.getResources().getDimensionPixelSize( |
| 194 | R.dimen.qs_quick_tile_size); |
| 195 | updateLayoutParams(); |
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); |
Fabian Kozynski | 5272830 | 2018-09-07 12:45:59 +0000 | [diff] [blame^] | 201 | updateLayoutParams(); |
Amin Shaikh | 6a298d6 | 2018-06-18 16:44:14 -0400 | [diff] [blame] | 202 | } |
Rohan Shah | 1439464 | 2018-03-13 20:10:12 -0700 | [diff] [blame] | 203 | |
Amin Shaikh | 6a298d6 | 2018-06-18 16:44:14 -0400 | [diff] [blame] | 204 | private void updateLayoutParams() { |
Fabian Kozynski | 5272830 | 2018-09-07 12:45:59 +0000 | [diff] [blame^] | 205 | setGravity(Gravity.CENTER); |
Amin Shaikh | 6a298d6 | 2018-06-18 16:44:14 -0400 | [diff] [blame] | 206 | int width = getResources().getDimensionPixelSize(R.dimen.qs_quick_layout_width); |
Fabian Kozynski | 5272830 | 2018-09-07 12:45:59 +0000 | [diff] [blame^] | 207 | LayoutParams lp = new LayoutParams(width, LayoutParams.MATCH_PARENT); |
Amin Shaikh | 6a298d6 | 2018-06-18 16:44:14 -0400 | [diff] [blame] | 208 | lp.gravity = Gravity.CENTER_HORIZONTAL; |
| 209 | setLayoutParams(lp); |
Rohan Shah | 1439464 | 2018-03-13 20:10:12 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Fabian Kozynski | 5272830 | 2018-09-07 12:45:59 +0000 | [diff] [blame^] | 212 | /** |
| 213 | * Returns {@link LayoutParams} based on the given {@code spaceWidth}. If the width is 0, |
| 214 | * then we're going to have the space expand to take up as much space as possible. If the |
| 215 | * width is non-zero, we want the inter-tile spacers to be fixed. |
| 216 | */ |
| 217 | private LayoutParams generateSpaceLayoutParams() { |
| 218 | LayoutParams lp = new LayoutParams(0, mTileDimensionSize); |
| 219 | lp.weight = 1; |
| 220 | lp.gravity = Gravity.CENTER; |
Jason Monk | db50de8 | 2016-02-03 15:34:54 -0500 | [diff] [blame] | 221 | return lp; |
| 222 | } |
| 223 | |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 224 | @Override |
Fabian Kozynski | 5272830 | 2018-09-07 12:45:59 +0000 | [diff] [blame^] | 225 | public void setListening(boolean listening) { |
| 226 | if (mListening == listening) return; |
| 227 | mListening = listening; |
| 228 | for (TileRecord record : mRecords) { |
| 229 | record.tile.setListening(this, mListening); |
| 230 | } |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | @Override |
Fabian Kozynski | 5272830 | 2018-09-07 12:45:59 +0000 | [diff] [blame^] | 234 | public void addTile(TileRecord tile) { |
| 235 | if (getChildCount() != 0) { |
| 236 | addView(new Space(mContext), getChildCount(), generateSpaceLayoutParams()); |
Fabian Kozynski | 40c9f0d | 2018-08-29 16:21:42 -0400 | [diff] [blame] | 237 | } |
| 238 | |
Fabian Kozynski | 5272830 | 2018-09-07 12:45:59 +0000 | [diff] [blame^] | 239 | addView(tile.tileView, getChildCount(), generateTileLayoutParams()); |
| 240 | mRecords.add(tile); |
| 241 | tile.tile.setListening(this, mListening); |
| 242 | } |
| 243 | |
| 244 | private LayoutParams generateTileLayoutParams() { |
| 245 | LayoutParams lp = new LayoutParams(mTileDimensionSize, mTileDimensionSize); |
| 246 | lp.gravity = Gravity.CENTER; |
| 247 | return lp; |
| 248 | } |
| 249 | |
| 250 | @Override |
| 251 | public void removeTile(TileRecord tile) { |
| 252 | int childIndex = getChildIndex(tile.tileView); |
| 253 | // Remove the tile. |
| 254 | removeViewAt(childIndex); |
| 255 | if (getChildCount() != 0) { |
| 256 | // Remove its spacer as well. |
| 257 | removeViewAt(childIndex); |
| 258 | } |
| 259 | mRecords.remove(tile); |
| 260 | tile.tile.setListening(this, false); |
| 261 | } |
| 262 | |
| 263 | private int getChildIndex(QSTileView tileView) { |
| 264 | final int childViewCount = getChildCount(); |
| 265 | for (int i = 0; i < childViewCount; i++) { |
| 266 | if (getChildAt(i) == tileView) { |
| 267 | return i; |
| 268 | } |
| 269 | } |
| 270 | return -1; |
| 271 | } |
| 272 | |
| 273 | @Override |
| 274 | public int getOffsetTop(TileRecord tile) { |
| 275 | return 0; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | @Override |
Jason Monk | 9d02a43 | 2016-01-20 16:33:46 -0500 | [diff] [blame] | 279 | public boolean updateResources() { |
Fabian Kozynski | 5272830 | 2018-09-07 12:45:59 +0000 | [diff] [blame^] | 280 | // No resources here. |
Jason Monk | 9d02a43 | 2016-01-20 16:33:46 -0500 | [diff] [blame] | 281 | return false; |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 282 | } |
Jason Monk | c5bdafb | 2016-02-25 16:24:21 -0500 | [diff] [blame] | 283 | |
Fabian Kozynski | 5272830 | 2018-09-07 12:45:59 +0000 | [diff] [blame^] | 284 | @Override |
| 285 | public boolean hasOverlappingRendering() { |
| 286 | return false; |
Fabian Kozynski | 40c9f0d | 2018-08-29 16:21:42 -0400 | [diff] [blame] | 287 | } |
| 288 | |
Fabian Kozynski | 5272830 | 2018-09-07 12:45:59 +0000 | [diff] [blame^] | 289 | @Override |
| 290 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 291 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 292 | if (hideOverflowingChildren(widthMeasureSpec)) { |
| 293 | return; // Rely on visibility change to trigger remeasure. |
| 294 | } |
| 295 | |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 296 | if (mRecords != null && mRecords.size() > 0) { |
| 297 | View previousView = this; |
| 298 | for (TileRecord record : mRecords) { |
| 299 | if (record.tileView.getVisibility() == GONE) continue; |
| 300 | previousView = record.tileView.updateAccessibilityOrder(previousView); |
| 301 | } |
| 302 | mRecords.get(0).tileView.setAccessibilityTraversalAfter( |
| 303 | R.id.alarm_status_collapsed); |
| 304 | mRecords.get(mRecords.size() - 1).tileView.setAccessibilityTraversalBefore( |
| 305 | R.id.expand_indicator); |
| 306 | } |
| 307 | } |
Amin Shaikh | 6a298d6 | 2018-06-18 16:44:14 -0400 | [diff] [blame] | 308 | |
Fabian Kozynski | 5272830 | 2018-09-07 12:45:59 +0000 | [diff] [blame^] | 309 | /** |
| 310 | * Hide child views that would otherwise be clipped. |
| 311 | * @return {@code true} if any child visibilities have changed. |
| 312 | */ |
| 313 | private boolean hideOverflowingChildren(int widthMeasureSpec) { |
| 314 | if (getChildCount() == 0) { |
| 315 | return false; |
Amin Shaikh | 6a298d6 | 2018-06-18 16:44:14 -0400 | [diff] [blame] | 316 | } |
Fabian Kozynski | 5272830 | 2018-09-07 12:45:59 +0000 | [diff] [blame^] | 317 | boolean childVisibilityChanged = false; |
| 318 | int widthRemaining = MeasureSpec.getSize(widthMeasureSpec) |
| 319 | - getChildAt(0).getMeasuredWidth() - getPaddingStart() - getPaddingEnd(); |
| 320 | for (int i = 2; i < getChildCount(); i += 2) { |
| 321 | View tileChild = getChildAt(i); |
| 322 | LayoutParams lp = (LayoutParams) tileChild.getLayoutParams(); |
| 323 | // All Space views have 0 width; only tiles contribute to the total width. |
| 324 | widthRemaining = widthRemaining |
| 325 | - tileChild.getMeasuredWidth() - lp.getMarginEnd() - lp.getMarginStart(); |
| 326 | int newVisibility = widthRemaining < 0 ? View.GONE : View.VISIBLE; |
| 327 | if (tileChild.getVisibility() != newVisibility) { |
| 328 | tileChild.setVisibility(newVisibility); |
| 329 | getChildAt(i - 1).setVisibility(newVisibility); // Hide spacer as well. |
| 330 | childVisibilityChanged = true; |
| 331 | } |
| 332 | } |
| 333 | return childVisibilityChanged; |
Amin Shaikh | 6a298d6 | 2018-06-18 16:44:14 -0400 | [diff] [blame] | 334 | } |
Jason Monk | c34befb | 2015-10-07 16:40:02 -0400 | [diff] [blame] | 335 | } |
| 336 | } |