John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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.animation.Animator; |
| 20 | import android.animation.Animator.AnimatorListener; |
| 21 | import android.animation.AnimatorListenerAdapter; |
| 22 | import android.content.Context; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 23 | import android.content.Intent; |
John Spurlock | 4bf3198 | 2014-05-21 13:04:22 -0400 | [diff] [blame] | 24 | import android.content.res.Resources; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 25 | import android.os.Handler; |
| 26 | import android.os.Message; |
| 27 | import android.util.AttributeSet; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 28 | import android.view.LayoutInflater; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 29 | import android.view.View; |
| 30 | import android.view.ViewGroup; |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 31 | import android.widget.ImageView; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 32 | |
| 33 | import com.android.systemui.R; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 34 | import com.android.systemui.qs.QSTile.DetailAdapter; |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 35 | import com.android.systemui.settings.BrightnessController; |
| 36 | import com.android.systemui.settings.ToggleSlider; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 37 | |
| 38 | import java.util.ArrayList; |
| 39 | |
| 40 | /** View that represents the quick settings tile panel. **/ |
| 41 | public class QSPanel extends ViewGroup { |
John Spurlock | 4bf3198 | 2014-05-21 13:04:22 -0400 | [diff] [blame] | 42 | private static final float TILE_ASPECT = 1.2f; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 43 | |
| 44 | private final Context mContext; |
| 45 | private final ArrayList<TileRecord> mRecords = new ArrayList<TileRecord>(); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 46 | private final View mDetail; |
| 47 | private final ViewGroup mDetailContent; |
| 48 | private final View mDetailSettingsButton; |
| 49 | private final View mDetailDoneButton; |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 50 | private final View mBrightnessView; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 51 | private final CircularClipper mClipper; |
| 52 | private final H mHandler = new H(); |
| 53 | |
| 54 | private int mColumns; |
| 55 | private int mCellWidth; |
| 56 | private int mCellHeight; |
| 57 | private int mLargeCellWidth; |
| 58 | private int mLargeCellHeight; |
John Spurlock | 92d9b19 | 2014-06-29 12:54:24 -0400 | [diff] [blame] | 59 | private int mPanelPaddingBottom; |
John Spurlock | 39076ed | 2014-06-30 20:47:20 -0400 | [diff] [blame] | 60 | private int mDualTileUnderlap; |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 61 | private boolean mExpanded; |
Jorim Jaggi | e65e310 | 2014-07-01 22:00:50 +0200 | [diff] [blame] | 62 | private boolean mListening; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 63 | |
| 64 | private TileRecord mDetailRecord; |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 65 | private Callback mCallback; |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 66 | private BrightnessController mBrightnessController; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 67 | |
| 68 | public QSPanel(Context context) { |
| 69 | this(context, null); |
| 70 | } |
| 71 | |
| 72 | public QSPanel(Context context, AttributeSet attrs) { |
| 73 | super(context, attrs); |
| 74 | mContext = context; |
| 75 | |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 76 | mDetail = LayoutInflater.from(context).inflate(R.layout.qs_detail, this, false); |
| 77 | mDetailContent = (ViewGroup) mDetail.findViewById(android.R.id.content); |
| 78 | mDetailSettingsButton = mDetail.findViewById(android.R.id.button2); |
| 79 | mDetailDoneButton = mDetail.findViewById(android.R.id.button1); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 80 | mDetail.setVisibility(GONE); |
| 81 | mDetail.setClickable(true); |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 82 | mBrightnessView = LayoutInflater.from(context).inflate( |
| 83 | R.layout.quick_settings_brightness_dialog, this, false); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 84 | addView(mDetail); |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 85 | addView(mBrightnessView); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 86 | mClipper = new CircularClipper(mDetail); |
| 87 | updateResources(); |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 88 | |
| 89 | mBrightnessController = new BrightnessController(getContext(), |
| 90 | (ImageView) findViewById(R.id.brightness_icon), |
| 91 | (ToggleSlider) findViewById(R.id.brightness_slider)); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 92 | } |
| 93 | |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 94 | public void setCallback(Callback callback) { |
| 95 | mCallback = callback; |
| 96 | } |
| 97 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 98 | public void updateResources() { |
John Spurlock | 4bf3198 | 2014-05-21 13:04:22 -0400 | [diff] [blame] | 99 | final Resources res = mContext.getResources(); |
| 100 | final int columns = Math.max(1, res.getInteger(R.integer.quick_settings_num_columns)); |
| 101 | mCellHeight = res.getDimensionPixelSize(R.dimen.qs_tile_height); |
| 102 | mCellWidth = (int)(mCellHeight * TILE_ASPECT); |
| 103 | mLargeCellHeight = res.getDimensionPixelSize(R.dimen.qs_dual_tile_height); |
| 104 | mLargeCellWidth = (int)(mLargeCellHeight * TILE_ASPECT); |
John Spurlock | 92d9b19 | 2014-06-29 12:54:24 -0400 | [diff] [blame] | 105 | mPanelPaddingBottom = res.getDimensionPixelSize(R.dimen.qs_panel_padding_bottom); |
John Spurlock | 39076ed | 2014-06-30 20:47:20 -0400 | [diff] [blame] | 106 | mDualTileUnderlap = res.getDimensionPixelSize(R.dimen.qs_dual_tile_padding_vertical); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 107 | if (mColumns != columns) { |
| 108 | mColumns = columns; |
| 109 | postInvalidate(); |
| 110 | } |
John Spurlock | 1a462c1 | 2014-07-14 10:52:01 -0400 | [diff] [blame^] | 111 | if (mListening) { |
| 112 | refreshAllTiles(); |
| 113 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | public void setExpanded(boolean expanded) { |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 117 | if (mExpanded == expanded) return; |
| 118 | mExpanded = expanded; |
| 119 | if (!mExpanded) { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 120 | showDetail(false /*show*/, mDetailRecord); |
| 121 | } |
Jorim Jaggi | e65e310 | 2014-07-01 22:00:50 +0200 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | public void setListening(boolean listening) { |
| 125 | if (mListening == listening) return; |
| 126 | mListening = listening; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 127 | for (TileRecord r : mRecords) { |
Jorim Jaggi | e65e310 | 2014-07-01 22:00:50 +0200 | [diff] [blame] | 128 | r.tile.setListening(mListening); |
John Spurlock | 1a462c1 | 2014-07-14 10:52:01 -0400 | [diff] [blame^] | 129 | } |
| 130 | if (mListening) { |
| 131 | refreshAllTiles(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 132 | } |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 133 | if (listening) { |
| 134 | mBrightnessController.registerCallbacks(); |
| 135 | } else { |
| 136 | mBrightnessController.unregisterCallbacks(); |
| 137 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 138 | } |
| 139 | |
John Spurlock | 1a462c1 | 2014-07-14 10:52:01 -0400 | [diff] [blame^] | 140 | private void refreshAllTiles() { |
| 141 | for (TileRecord r : mRecords) { |
| 142 | r.tile.refreshState(); |
| 143 | } |
| 144 | } |
| 145 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 146 | private void showDetail(boolean show, TileRecord r) { |
| 147 | mHandler.obtainMessage(H.SHOW_DETAIL, show ? 1 : 0, 0, r).sendToTarget(); |
| 148 | } |
| 149 | |
| 150 | private void setTileVisibility(View v, boolean visible) { |
| 151 | mHandler.obtainMessage(H.SET_TILE_VISIBILITY, visible ? 1 : 0, 0, v).sendToTarget(); |
| 152 | } |
| 153 | |
| 154 | private void handleSetTileVisibility(View v, boolean visible) { |
John Spurlock | 360e15b | 2014-07-08 18:45:21 -0400 | [diff] [blame] | 155 | if (visible == (v.getVisibility() == VISIBLE)) return; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 156 | v.setVisibility(visible ? VISIBLE : GONE); |
| 157 | } |
| 158 | |
| 159 | public void addTile(final QSTile<?> tile) { |
| 160 | final TileRecord r = new TileRecord(); |
| 161 | r.tile = tile; |
| 162 | r.tileView = tile.createTileView(mContext); |
| 163 | r.tileView.setVisibility(View.GONE); |
| 164 | r.tile.setCallback(new QSTile.Callback() { |
| 165 | @Override |
| 166 | public void onStateChanged(QSTile.State state) { |
| 167 | setTileVisibility(r.tileView, state.visible); |
| 168 | r.tileView.onStateChanged(state); |
| 169 | } |
| 170 | @Override |
| 171 | public void onShowDetail(boolean show) { |
| 172 | QSPanel.this.showDetail(show, r); |
| 173 | } |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 174 | @Override |
| 175 | public void onToggleStateChanged(boolean state) { |
| 176 | if (mDetailRecord == r) { |
| 177 | fireToggleStateChanged(state); |
| 178 | } |
| 179 | } |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 180 | @Override |
| 181 | public void onScanStateChanged(boolean state) { |
| 182 | if (mDetailRecord == r) { |
| 183 | fireScanStateChanged(state); |
| 184 | } |
| 185 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 186 | }); |
| 187 | final View.OnClickListener click = new View.OnClickListener() { |
| 188 | @Override |
| 189 | public void onClick(View v) { |
| 190 | r.tile.click(); |
| 191 | } |
| 192 | }; |
| 193 | final View.OnClickListener clickSecondary = new View.OnClickListener() { |
| 194 | @Override |
| 195 | public void onClick(View v) { |
| 196 | r.tile.secondaryClick(); |
| 197 | } |
| 198 | }; |
| 199 | r.tileView.init(click, clickSecondary); |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 200 | r.tile.refreshState(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 201 | mRecords.add(r); |
| 202 | |
| 203 | addView(r.tileView); |
| 204 | } |
| 205 | |
| 206 | private void handleShowDetail(TileRecord r, boolean show) { |
John Spurlock | 9dcfe06 | 2014-05-31 12:54:58 -0400 | [diff] [blame] | 207 | if (r == null) return; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 208 | AnimatorListener listener = null; |
| 209 | if (show) { |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 210 | if (mDetailRecord != null) return; // already showing something in detail |
| 211 | r.detailAdapter = r.tile.getDetailAdapter(); |
| 212 | if (r.detailAdapter == null) return; |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 213 | mDetailRecord = r; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 214 | r.detailView = r.detailAdapter.createDetailView(mContext, r.detailView, mDetailContent); |
| 215 | if (r.detailView == null) throw new IllegalStateException("Must return detail view"); |
| 216 | mDetailDoneButton.setOnClickListener(new OnClickListener() { |
| 217 | @Override |
| 218 | public void onClick(View v) { |
| 219 | showDetail(false, mDetailRecord); |
| 220 | } |
| 221 | }); |
| 222 | final Intent settingsIntent = r.detailAdapter.getSettingsIntent(); |
| 223 | mDetailSettingsButton.setVisibility(settingsIntent != null ? VISIBLE : GONE); |
| 224 | mDetailSettingsButton.setOnClickListener(new OnClickListener() { |
| 225 | @Override |
| 226 | public void onClick(View v) { |
| 227 | mDetailRecord.tile.mHost.startSettingsActivity(settingsIntent); |
| 228 | } |
| 229 | }); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 230 | mDetailContent.removeAllViews(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 231 | mDetail.bringToFront(); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 232 | mDetailContent.addView(r.detailView); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 233 | } else { |
| 234 | if (mDetailRecord == null) return; |
| 235 | listener = mTeardownDetailWhenDone; |
| 236 | } |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 237 | fireShowingDetail(show ? r.detailAdapter : null); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 238 | int x = r.tileView.getLeft() + r.tileView.getWidth() / 2; |
| 239 | int y = r.tileView.getTop() + r.tileView.getHeight() / 2; |
| 240 | mClipper.animateCircularClip(x, y, show, listener); |
| 241 | } |
| 242 | |
| 243 | @Override |
| 244 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 245 | final int width = MeasureSpec.getSize(widthMeasureSpec); |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 246 | mBrightnessView.measure(exactly(width), MeasureSpec.UNSPECIFIED); |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 247 | int r = -1; |
| 248 | int c = -1; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 249 | int rows = 0; |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 250 | boolean rowIsDual = false; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 251 | for (TileRecord record : mRecords) { |
| 252 | if (record.tileView.getVisibility() == GONE) continue; |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 253 | // wrap to next column if we've reached the max # of columns |
| 254 | // also don't allow dual + single tiles on the same row |
| 255 | if (r == -1 || c == (mColumns - 1) || rowIsDual != record.tile.supportsDualTargets()) { |
| 256 | r++; |
| 257 | c = 0; |
| 258 | rowIsDual = record.tile.supportsDualTargets(); |
| 259 | } else { |
| 260 | c++; |
| 261 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 262 | record.row = r; |
| 263 | record.col = c; |
| 264 | rows = r + 1; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | for (TileRecord record : mRecords) { |
| 268 | if (record.tileView.getVisibility() == GONE) continue; |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 269 | record.tileView.setDual(record.tile.supportsDualTargets()); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 270 | final int cw = record.row == 0 ? mLargeCellWidth : mCellWidth; |
| 271 | final int ch = record.row == 0 ? mLargeCellHeight : mCellHeight; |
| 272 | record.tileView.measure(exactly(cw), exactly(ch)); |
| 273 | } |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 274 | int h = rows == 0 ? mBrightnessView.getHeight() : (getRowTop(rows) + mPanelPaddingBottom); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 275 | mDetail.measure(exactly(width), exactly(h)); |
John Spurlock | 2684d5e | 2014-05-28 20:27:44 -0400 | [diff] [blame] | 276 | setMeasuredDimension(width, h); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | private static int exactly(int size) { |
| 280 | return MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY); |
| 281 | } |
| 282 | |
| 283 | @Override |
| 284 | protected void onLayout(boolean changed, int l, int t, int r, int b) { |
John Spurlock | 4bf3198 | 2014-05-21 13:04:22 -0400 | [diff] [blame] | 285 | final int w = getWidth(); |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 286 | mBrightnessView.layout(0, 0, |
| 287 | mBrightnessView.getMeasuredWidth(), mBrightnessView.getMeasuredHeight()); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 288 | for (TileRecord record : mRecords) { |
| 289 | if (record.tileView.getVisibility() == GONE) continue; |
| 290 | final int cols = getColumnCount(record.row); |
| 291 | final int cw = record.row == 0 ? mLargeCellWidth : mCellWidth; |
| 292 | final int extra = (w - cw * cols) / (cols + 1); |
| 293 | final int left = record.col * cw + (record.col + 1) * extra; |
| 294 | final int top = getRowTop(record.row); |
| 295 | record.tileView.layout(left, top, |
| 296 | left + record.tileView.getMeasuredWidth(), |
| 297 | top + record.tileView.getMeasuredHeight()); |
| 298 | } |
John Spurlock | 3e04cc8 | 2014-05-30 12:34:03 -0400 | [diff] [blame] | 299 | final int dh = Math.max(mDetail.getMeasuredHeight(), getMeasuredHeight()); |
| 300 | mDetail.layout(0, 0, mDetail.getMeasuredWidth(), dh); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | private int getRowTop(int row) { |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 304 | if (row <= 0) return mBrightnessView.getHeight(); |
| 305 | return mBrightnessView.getHeight() |
| 306 | + mLargeCellHeight - mDualTileUnderlap + (row - 1) * mCellHeight; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | private int getColumnCount(int row) { |
| 310 | int cols = 0; |
| 311 | for (TileRecord record : mRecords) { |
| 312 | if (record.tileView.getVisibility() == GONE) continue; |
| 313 | if (record.row == row) cols++; |
| 314 | } |
| 315 | return cols; |
| 316 | } |
| 317 | |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 318 | private void fireShowingDetail(QSTile.DetailAdapter detail) { |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 319 | if (mCallback != null) { |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 320 | mCallback.onShowingDetail(detail); |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | private void fireToggleStateChanged(boolean state) { |
| 325 | if (mCallback != null) { |
| 326 | mCallback.onToggleStateChanged(state); |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 327 | } |
| 328 | } |
| 329 | |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 330 | private void fireScanStateChanged(boolean state) { |
| 331 | if (mCallback != null) { |
| 332 | mCallback.onScanStateChanged(state); |
| 333 | } |
| 334 | } |
| 335 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 336 | private class H extends Handler { |
| 337 | private static final int SHOW_DETAIL = 1; |
| 338 | private static final int SET_TILE_VISIBILITY = 2; |
| 339 | @Override |
| 340 | public void handleMessage(Message msg) { |
| 341 | if (msg.what == SHOW_DETAIL) { |
| 342 | handleShowDetail((TileRecord)msg.obj, msg.arg1 != 0); |
| 343 | } else if (msg.what == SET_TILE_VISIBILITY) { |
| 344 | handleSetTileVisibility((View)msg.obj, msg.arg1 != 0); |
| 345 | } |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | private static final class TileRecord { |
| 350 | QSTile<?> tile; |
| 351 | QSTileView tileView; |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 352 | View detailView; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 353 | DetailAdapter detailAdapter; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 354 | int row; |
| 355 | int col; |
| 356 | } |
| 357 | |
| 358 | private final AnimatorListenerAdapter mTeardownDetailWhenDone = new AnimatorListenerAdapter() { |
| 359 | public void onAnimationEnd(Animator animation) { |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 360 | mDetailContent.removeAllViews(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 361 | mDetailRecord = null; |
| 362 | }; |
| 363 | }; |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 364 | |
| 365 | public interface Callback { |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 366 | void onShowingDetail(QSTile.DetailAdapter detail); |
| 367 | void onToggleStateChanged(boolean state); |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 368 | void onScanStateChanged(boolean state); |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 369 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 370 | } |