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; |
Jorim Jaggi | e17c4b4 | 2014-08-26 17:27:31 +0200 | [diff] [blame] | 24 | import android.content.res.Configuration; |
John Spurlock | 4bf3198 | 2014-05-21 13:04:22 -0400 | [diff] [blame] | 25 | import android.content.res.Resources; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 26 | import android.os.Handler; |
| 27 | import android.os.Message; |
| 28 | import android.util.AttributeSet; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 29 | import android.view.LayoutInflater; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 30 | import android.view.View; |
| 31 | import android.view.ViewGroup; |
Jason Monk | 6783bef | 2014-09-22 13:50:05 -0400 | [diff] [blame] | 32 | import android.view.accessibility.AccessibilityEvent; |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 33 | import android.widget.ImageView; |
Jorim Jaggi | e17c4b4 | 2014-08-26 17:27:31 +0200 | [diff] [blame] | 34 | import android.widget.TextView; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 35 | |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 36 | import com.android.internal.logging.MetricsLogger; |
Jorim Jaggi | e17c4b4 | 2014-08-26 17:27:31 +0200 | [diff] [blame] | 37 | import com.android.systemui.FontSizeUtils; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 38 | import com.android.systemui.R; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 39 | import com.android.systemui.qs.QSTile.DetailAdapter; |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 40 | import com.android.systemui.settings.BrightnessController; |
| 41 | import com.android.systemui.settings.ToggleSlider; |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 42 | import com.android.systemui.statusbar.phone.QSTileHost; |
Adrian Roos | 5fd872e | 2014-08-12 17:28:58 +0200 | [diff] [blame] | 43 | import com.android.systemui.statusbar.policy.BrightnessMirrorController; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 44 | |
| 45 | import java.util.ArrayList; |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 46 | import java.util.Collection; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 47 | |
| 48 | /** View that represents the quick settings tile panel. **/ |
| 49 | public class QSPanel extends ViewGroup { |
John Spurlock | 4bf3198 | 2014-05-21 13:04:22 -0400 | [diff] [blame] | 50 | private static final float TILE_ASPECT = 1.2f; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 51 | |
| 52 | private final Context mContext; |
Jason Monk | 11a7744 | 2015-05-12 19:29:02 -0400 | [diff] [blame^] | 53 | protected final ArrayList<TileRecord> mRecords = new ArrayList<TileRecord>(); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 54 | private final View mDetail; |
| 55 | private final ViewGroup mDetailContent; |
Jorim Jaggi | e17c4b4 | 2014-08-26 17:27:31 +0200 | [diff] [blame] | 56 | private final TextView mDetailSettingsButton; |
| 57 | private final TextView mDetailDoneButton; |
Jason Monk | 11a7744 | 2015-05-12 19:29:02 -0400 | [diff] [blame^] | 58 | protected final View mBrightnessView; |
John Spurlock | 8af525d | 2014-08-02 10:56:05 -0400 | [diff] [blame] | 59 | private final QSDetailClipper mClipper; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 60 | private final H mHandler = new H(); |
| 61 | |
| 62 | private int mColumns; |
| 63 | private int mCellWidth; |
| 64 | private int mCellHeight; |
| 65 | private int mLargeCellWidth; |
| 66 | private int mLargeCellHeight; |
John Spurlock | 92d9b19 | 2014-06-29 12:54:24 -0400 | [diff] [blame] | 67 | private int mPanelPaddingBottom; |
John Spurlock | 39076ed | 2014-06-30 20:47:20 -0400 | [diff] [blame] | 68 | private int mDualTileUnderlap; |
Adrian Roos | cd542b8 | 2014-08-12 22:25:35 +0200 | [diff] [blame] | 69 | private int mBrightnessPaddingTop; |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 70 | private int mGridHeight; |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 71 | private boolean mExpanded; |
Jorim Jaggi | e65e310 | 2014-07-01 22:00:50 +0200 | [diff] [blame] | 72 | private boolean mListening; |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 73 | private boolean mClosingDetail; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 74 | |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 75 | private Record mDetailRecord; |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 76 | private Callback mCallback; |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 77 | private BrightnessController mBrightnessController; |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 78 | private QSTileHost mHost; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 79 | |
Jason Monk | 3d5f551 | 2014-07-25 11:17:28 -0400 | [diff] [blame] | 80 | private QSFooter mFooter; |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 81 | private boolean mGridContentVisible = true; |
Jason Monk | 3d5f551 | 2014-07-25 11:17:28 -0400 | [diff] [blame] | 82 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 83 | public QSPanel(Context context) { |
| 84 | this(context, null); |
| 85 | } |
| 86 | |
| 87 | public QSPanel(Context context, AttributeSet attrs) { |
| 88 | super(context, attrs); |
| 89 | mContext = context; |
| 90 | |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 91 | mDetail = LayoutInflater.from(context).inflate(R.layout.qs_detail, this, false); |
| 92 | mDetailContent = (ViewGroup) mDetail.findViewById(android.R.id.content); |
Jorim Jaggi | e17c4b4 | 2014-08-26 17:27:31 +0200 | [diff] [blame] | 93 | mDetailSettingsButton = (TextView) mDetail.findViewById(android.R.id.button2); |
| 94 | mDetailDoneButton = (TextView) mDetail.findViewById(android.R.id.button1); |
Jason Monk | e2f4771 | 2014-09-09 09:35:55 -0400 | [diff] [blame] | 95 | updateDetailText(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 96 | mDetail.setVisibility(GONE); |
| 97 | mDetail.setClickable(true); |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 98 | mBrightnessView = LayoutInflater.from(context).inflate( |
| 99 | R.layout.quick_settings_brightness_dialog, this, false); |
Jason Monk | 3d5f551 | 2014-07-25 11:17:28 -0400 | [diff] [blame] | 100 | mFooter = new QSFooter(this, context); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 101 | addView(mDetail); |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 102 | addView(mBrightnessView); |
Jason Monk | 3d5f551 | 2014-07-25 11:17:28 -0400 | [diff] [blame] | 103 | addView(mFooter.getView()); |
John Spurlock | 8af525d | 2014-08-02 10:56:05 -0400 | [diff] [blame] | 104 | mClipper = new QSDetailClipper(mDetail); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 105 | updateResources(); |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 106 | |
| 107 | mBrightnessController = new BrightnessController(getContext(), |
| 108 | (ImageView) findViewById(R.id.brightness_icon), |
| 109 | (ToggleSlider) findViewById(R.id.brightness_slider)); |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 110 | |
| 111 | mDetailDoneButton.setOnClickListener(new OnClickListener() { |
| 112 | @Override |
| 113 | public void onClick(View v) { |
John Spurlock | f7ae442 | 2014-08-01 12:45:18 -0400 | [diff] [blame] | 114 | closeDetail(); |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 115 | } |
| 116 | }); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 117 | } |
| 118 | |
Jason Monk | e2f4771 | 2014-09-09 09:35:55 -0400 | [diff] [blame] | 119 | private void updateDetailText() { |
| 120 | mDetailDoneButton.setText(R.string.quick_settings_done); |
| 121 | mDetailSettingsButton.setText(R.string.quick_settings_more_settings); |
| 122 | } |
| 123 | |
Adrian Roos | 5fd872e | 2014-08-12 17:28:58 +0200 | [diff] [blame] | 124 | public void setBrightnessMirror(BrightnessMirrorController c) { |
| 125 | super.onFinishInflate(); |
| 126 | ToggleSlider brightnessSlider = (ToggleSlider) findViewById(R.id.brightness_slider); |
| 127 | ToggleSlider mirror = (ToggleSlider) c.getMirror().findViewById(R.id.brightness_slider); |
| 128 | brightnessSlider.setMirror(mirror); |
| 129 | brightnessSlider.setMirrorController(c); |
| 130 | } |
| 131 | |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 132 | public void setCallback(Callback callback) { |
| 133 | mCallback = callback; |
| 134 | } |
| 135 | |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 136 | public void setHost(QSTileHost host) { |
| 137 | mHost = host; |
Jason Monk | 3d5f551 | 2014-07-25 11:17:28 -0400 | [diff] [blame] | 138 | mFooter.setHost(host); |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 139 | } |
| 140 | |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 141 | public QSTileHost getHost() { |
| 142 | return mHost; |
| 143 | } |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 144 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 145 | public void updateResources() { |
John Spurlock | 4bf3198 | 2014-05-21 13:04:22 -0400 | [diff] [blame] | 146 | final Resources res = mContext.getResources(); |
| 147 | final int columns = Math.max(1, res.getInteger(R.integer.quick_settings_num_columns)); |
| 148 | mCellHeight = res.getDimensionPixelSize(R.dimen.qs_tile_height); |
| 149 | mCellWidth = (int)(mCellHeight * TILE_ASPECT); |
| 150 | mLargeCellHeight = res.getDimensionPixelSize(R.dimen.qs_dual_tile_height); |
| 151 | mLargeCellWidth = (int)(mLargeCellHeight * TILE_ASPECT); |
John Spurlock | 92d9b19 | 2014-06-29 12:54:24 -0400 | [diff] [blame] | 152 | mPanelPaddingBottom = res.getDimensionPixelSize(R.dimen.qs_panel_padding_bottom); |
John Spurlock | 39076ed | 2014-06-30 20:47:20 -0400 | [diff] [blame] | 153 | mDualTileUnderlap = res.getDimensionPixelSize(R.dimen.qs_dual_tile_padding_vertical); |
Adrian Roos | cd542b8 | 2014-08-12 22:25:35 +0200 | [diff] [blame] | 154 | mBrightnessPaddingTop = res.getDimensionPixelSize(R.dimen.qs_brightness_padding_top); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 155 | if (mColumns != columns) { |
| 156 | mColumns = columns; |
| 157 | postInvalidate(); |
| 158 | } |
John Spurlock | 1a462c1 | 2014-07-14 10:52:01 -0400 | [diff] [blame] | 159 | if (mListening) { |
| 160 | refreshAllTiles(); |
| 161 | } |
Jason Monk | e2f4771 | 2014-09-09 09:35:55 -0400 | [diff] [blame] | 162 | updateDetailText(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 163 | } |
| 164 | |
Jorim Jaggi | e17c4b4 | 2014-08-26 17:27:31 +0200 | [diff] [blame] | 165 | @Override |
| 166 | protected void onConfigurationChanged(Configuration newConfig) { |
| 167 | super.onConfigurationChanged(newConfig); |
| 168 | FontSizeUtils.updateFontSize(mDetailDoneButton, R.dimen.qs_detail_button_text_size); |
| 169 | FontSizeUtils.updateFontSize(mDetailSettingsButton, R.dimen.qs_detail_button_text_size); |
| 170 | |
| 171 | // We need to poke the detail views as well as they might not be attached to the view |
| 172 | // hierarchy but reused at a later point. |
| 173 | int count = mRecords.size(); |
| 174 | for (int i = 0; i < count; i++) { |
| 175 | View detailView = mRecords.get(i).detailView; |
| 176 | if (detailView != null) { |
| 177 | detailView.dispatchConfigurationChanged(newConfig); |
| 178 | } |
| 179 | } |
| 180 | mFooter.onConfigurationChanged(); |
| 181 | } |
| 182 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 183 | public void setExpanded(boolean expanded) { |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 184 | if (mExpanded == expanded) return; |
| 185 | mExpanded = expanded; |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 186 | MetricsLogger.visibility(mContext, MetricsLogger.QS_PANEL, mExpanded); |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 187 | if (!mExpanded) { |
John Spurlock | f7ae442 | 2014-08-01 12:45:18 -0400 | [diff] [blame] | 188 | closeDetail(); |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 189 | } else { |
| 190 | logTiles(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 191 | } |
Jorim Jaggi | e65e310 | 2014-07-01 22:00:50 +0200 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | public void setListening(boolean listening) { |
| 195 | if (mListening == listening) return; |
| 196 | mListening = listening; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 197 | for (TileRecord r : mRecords) { |
Jorim Jaggi | e65e310 | 2014-07-01 22:00:50 +0200 | [diff] [blame] | 198 | r.tile.setListening(mListening); |
John Spurlock | 1a462c1 | 2014-07-14 10:52:01 -0400 | [diff] [blame] | 199 | } |
Jason Monk | 3d5f551 | 2014-07-25 11:17:28 -0400 | [diff] [blame] | 200 | mFooter.setListening(mListening); |
John Spurlock | 1a462c1 | 2014-07-14 10:52:01 -0400 | [diff] [blame] | 201 | if (mListening) { |
| 202 | refreshAllTiles(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 203 | } |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 204 | if (listening) { |
| 205 | mBrightnessController.registerCallbacks(); |
| 206 | } else { |
| 207 | mBrightnessController.unregisterCallbacks(); |
| 208 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 209 | } |
| 210 | |
Jorim Jaggi | 1ecd7cd | 2014-11-03 16:18:03 +0100 | [diff] [blame] | 211 | public void refreshAllTiles() { |
John Spurlock | 1a462c1 | 2014-07-14 10:52:01 -0400 | [diff] [blame] | 212 | for (TileRecord r : mRecords) { |
| 213 | r.tile.refreshState(); |
| 214 | } |
Jason Monk | 3d5f551 | 2014-07-25 11:17:28 -0400 | [diff] [blame] | 215 | mFooter.refreshState(); |
John Spurlock | 1a462c1 | 2014-07-14 10:52:01 -0400 | [diff] [blame] | 216 | } |
| 217 | |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 218 | public void showDetailAdapter(boolean show, DetailAdapter adapter) { |
| 219 | Record r = new Record(); |
| 220 | r.detailAdapter = adapter; |
| 221 | showDetail(show, r); |
| 222 | } |
| 223 | |
| 224 | private void showDetail(boolean show, Record r) { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 225 | mHandler.obtainMessage(H.SHOW_DETAIL, show ? 1 : 0, 0, r).sendToTarget(); |
| 226 | } |
| 227 | |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 228 | private void setTileVisibility(View v, int visibility) { |
| 229 | mHandler.obtainMessage(H.SET_TILE_VISIBILITY, visibility, 0, v).sendToTarget(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 230 | } |
| 231 | |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 232 | private void handleSetTileVisibility(View v, int visibility) { |
| 233 | if (visibility == v.getVisibility()) return; |
| 234 | v.setVisibility(visibility); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 235 | } |
| 236 | |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 237 | public void setTiles(Collection<QSTile<?>> tiles) { |
| 238 | for (TileRecord record : mRecords) { |
| 239 | removeView(record.tileView); |
| 240 | } |
| 241 | mRecords.clear(); |
| 242 | for (QSTile<?> tile : tiles) { |
| 243 | addTile(tile); |
| 244 | } |
| 245 | if (isShowingDetail()) { |
| 246 | mDetail.bringToFront(); |
| 247 | } |
| 248 | } |
| 249 | |
John Spurlock | 20c8905 | 2015-05-11 13:11:24 -0400 | [diff] [blame] | 250 | private void drawTile(TileRecord r, QSTile.State state) { |
| 251 | final int visibility = state.visible ? VISIBLE : GONE; |
| 252 | setTileVisibility(r.tileView, visibility); |
| 253 | r.tileView.onStateChanged(state); |
| 254 | } |
| 255 | |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 256 | private void addTile(final QSTile<?> tile) { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 257 | final TileRecord r = new TileRecord(); |
| 258 | r.tile = tile; |
| 259 | r.tileView = tile.createTileView(mContext); |
| 260 | r.tileView.setVisibility(View.GONE); |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 261 | final QSTile.Callback callback = new QSTile.Callback() { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 262 | @Override |
| 263 | public void onStateChanged(QSTile.State state) { |
John Spurlock | 20c8905 | 2015-05-11 13:11:24 -0400 | [diff] [blame] | 264 | if (!r.openingDetail) { |
| 265 | drawTile(r, state); |
| 266 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 267 | } |
| 268 | @Override |
| 269 | public void onShowDetail(boolean show) { |
| 270 | QSPanel.this.showDetail(show, r); |
| 271 | } |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 272 | @Override |
| 273 | public void onToggleStateChanged(boolean state) { |
| 274 | if (mDetailRecord == r) { |
| 275 | fireToggleStateChanged(state); |
| 276 | } |
| 277 | } |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 278 | @Override |
| 279 | public void onScanStateChanged(boolean state) { |
John Spurlock | 465cefa | 2014-08-16 10:39:33 -0400 | [diff] [blame] | 280 | r.scanState = state; |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 281 | if (mDetailRecord == r) { |
John Spurlock | 465cefa | 2014-08-16 10:39:33 -0400 | [diff] [blame] | 282 | fireScanStateChanged(r.scanState); |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 283 | } |
| 284 | } |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 285 | |
| 286 | @Override |
| 287 | public void onAnnouncementRequested(CharSequence announcement) { |
| 288 | announceForAccessibility(announcement); |
| 289 | } |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 290 | }; |
| 291 | r.tile.setCallback(callback); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 292 | final View.OnClickListener click = new View.OnClickListener() { |
| 293 | @Override |
| 294 | public void onClick(View v) { |
| 295 | r.tile.click(); |
| 296 | } |
| 297 | }; |
| 298 | final View.OnClickListener clickSecondary = new View.OnClickListener() { |
| 299 | @Override |
| 300 | public void onClick(View v) { |
| 301 | r.tile.secondaryClick(); |
| 302 | } |
| 303 | }; |
John Spurlock | c247b8f | 2014-11-06 23:06:25 -0500 | [diff] [blame] | 304 | final View.OnLongClickListener longClick = new View.OnLongClickListener() { |
| 305 | @Override |
| 306 | public boolean onLongClick(View v) { |
| 307 | r.tile.longClick(); |
| 308 | return true; |
| 309 | } |
| 310 | }; |
| 311 | r.tileView.init(click, clickSecondary, longClick); |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 312 | r.tile.setListening(mListening); |
| 313 | callback.onStateChanged(r.tile.getState()); |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 314 | r.tile.refreshState(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 315 | mRecords.add(r); |
| 316 | |
| 317 | addView(r.tileView); |
| 318 | } |
| 319 | |
John Spurlock | f7ae442 | 2014-08-01 12:45:18 -0400 | [diff] [blame] | 320 | public boolean isShowingDetail() { |
| 321 | return mDetailRecord != null; |
| 322 | } |
| 323 | |
| 324 | public void closeDetail() { |
| 325 | showDetail(false, mDetailRecord); |
| 326 | } |
| 327 | |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 328 | public boolean isClosingDetail() { |
| 329 | return mClosingDetail; |
| 330 | } |
| 331 | |
| 332 | public int getGridHeight() { |
| 333 | return mGridHeight; |
| 334 | } |
| 335 | |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 336 | private void handleShowDetail(Record r, boolean show) { |
| 337 | if (r instanceof TileRecord) { |
| 338 | handleShowDetailTile((TileRecord) r, show); |
| 339 | } else { |
| 340 | handleShowDetailImpl(r, show, getWidth() /* x */, 0/* y */); |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | private void handleShowDetailTile(TileRecord r, boolean show) { |
| 345 | if ((mDetailRecord != null) == show) return; |
| 346 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 347 | if (show) { |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 348 | r.detailAdapter = r.tile.getDetailAdapter(); |
| 349 | if (r.detailAdapter == null) return; |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 350 | } |
Jason Monk | 0d6a1c4 | 2015-04-20 16:38:51 -0400 | [diff] [blame] | 351 | r.tile.setDetailListening(show); |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 352 | int x = r.tileView.getLeft() + r.tileView.getWidth() / 2; |
| 353 | int y = r.tileView.getTop() + r.tileView.getHeight() / 2; |
| 354 | handleShowDetailImpl(r, show, x, y); |
| 355 | } |
| 356 | |
| 357 | private void handleShowDetailImpl(Record r, boolean show, int x, int y) { |
| 358 | if ((mDetailRecord != null) == show) return; // already in right state |
| 359 | DetailAdapter detailAdapter = null; |
| 360 | AnimatorListener listener = null; |
| 361 | if (show) { |
| 362 | detailAdapter = r.detailAdapter; |
| 363 | r.detailView = detailAdapter.createDetailView(mContext, r.detailView, mDetailContent); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 364 | if (r.detailView == null) throw new IllegalStateException("Must return detail view"); |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 365 | |
| 366 | final Intent settingsIntent = detailAdapter.getSettingsIntent(); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 367 | mDetailSettingsButton.setVisibility(settingsIntent != null ? VISIBLE : GONE); |
| 368 | mDetailSettingsButton.setOnClickListener(new OnClickListener() { |
| 369 | @Override |
| 370 | public void onClick(View v) { |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 371 | mHost.startSettingsActivity(settingsIntent); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 372 | } |
| 373 | }); |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 374 | |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 375 | mDetailContent.removeAllViews(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 376 | mDetail.bringToFront(); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 377 | mDetailContent.addView(r.detailView); |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 378 | MetricsLogger.visible(mContext, detailAdapter.getMetricsCategory()); |
John Spurlock | 465cefa | 2014-08-16 10:39:33 -0400 | [diff] [blame] | 379 | setDetailRecord(r); |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 380 | listener = mHideGridContentWhenDone; |
John Spurlock | 20c8905 | 2015-05-11 13:11:24 -0400 | [diff] [blame] | 381 | if (r instanceof TileRecord) { |
| 382 | ((TileRecord) r).openingDetail = true; |
| 383 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 384 | } else { |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 385 | MetricsLogger.hidden(mContext, mDetailRecord.detailAdapter.getMetricsCategory()); |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 386 | mClosingDetail = true; |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 387 | setGridContentVisibility(true); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 388 | listener = mTeardownDetailWhenDone; |
John Spurlock | 465cefa | 2014-08-16 10:39:33 -0400 | [diff] [blame] | 389 | fireScanStateChanged(false); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 390 | } |
Jason Monk | 6783bef | 2014-09-22 13:50:05 -0400 | [diff] [blame] | 391 | sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 392 | fireShowingDetail(show ? detailAdapter : null); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 393 | mClipper.animateCircularClip(x, y, show, listener); |
| 394 | } |
| 395 | |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 396 | private void setGridContentVisibility(boolean visible) { |
| 397 | int newVis = visible ? VISIBLE : INVISIBLE; |
| 398 | for (int i = 0; i < mRecords.size(); i++) { |
| 399 | TileRecord tileRecord = mRecords.get(i); |
| 400 | if (tileRecord.tileView.getVisibility() != GONE) { |
| 401 | tileRecord.tileView.setVisibility(newVis); |
| 402 | } |
| 403 | } |
| 404 | mBrightnessView.setVisibility(newVis); |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 405 | if (mGridContentVisible != visible) { |
| 406 | MetricsLogger.visibility(mContext, MetricsLogger.QS_PANEL, newVis); |
| 407 | } |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 408 | mGridContentVisible = visible; |
| 409 | } |
| 410 | |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 411 | private void logTiles() { |
| 412 | for (int i = 0; i < mRecords.size(); i++) { |
| 413 | TileRecord tileRecord = mRecords.get(i); |
| 414 | if (tileRecord.tile.getState().visible) { |
| 415 | MetricsLogger.visible(mContext, tileRecord.tile.getMetricsCategory()); |
| 416 | } |
| 417 | } |
| 418 | } |
| 419 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 420 | @Override |
| 421 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 422 | final int width = MeasureSpec.getSize(widthMeasureSpec); |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 423 | mBrightnessView.measure(exactly(width), MeasureSpec.UNSPECIFIED); |
Adrian Roos | cd542b8 | 2014-08-12 22:25:35 +0200 | [diff] [blame] | 424 | final int brightnessHeight = mBrightnessView.getMeasuredHeight() + mBrightnessPaddingTop; |
Jason Monk | 3d5f551 | 2014-07-25 11:17:28 -0400 | [diff] [blame] | 425 | mFooter.getView().measure(exactly(width), MeasureSpec.UNSPECIFIED); |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 426 | int r = -1; |
| 427 | int c = -1; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 428 | int rows = 0; |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 429 | boolean rowIsDual = false; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 430 | for (TileRecord record : mRecords) { |
| 431 | if (record.tileView.getVisibility() == GONE) continue; |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 432 | // wrap to next column if we've reached the max # of columns |
| 433 | // also don't allow dual + single tiles on the same row |
| 434 | if (r == -1 || c == (mColumns - 1) || rowIsDual != record.tile.supportsDualTargets()) { |
| 435 | r++; |
| 436 | c = 0; |
| 437 | rowIsDual = record.tile.supportsDualTargets(); |
| 438 | } else { |
| 439 | c++; |
| 440 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 441 | record.row = r; |
| 442 | record.col = c; |
| 443 | rows = r + 1; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | for (TileRecord record : mRecords) { |
Jason Monk | 8ba572a | 2015-01-30 13:02:27 -0500 | [diff] [blame] | 447 | if (record.tileView.setDual(record.tile.supportsDualTargets())) { |
| 448 | record.tileView.handleStateChanged(record.tile.getState()); |
| 449 | } |
Selim Cinek | e5557a9 | 2014-08-15 19:59:23 +0200 | [diff] [blame] | 450 | if (record.tileView.getVisibility() == GONE) continue; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 451 | final int cw = record.row == 0 ? mLargeCellWidth : mCellWidth; |
| 452 | final int ch = record.row == 0 ? mLargeCellHeight : mCellHeight; |
| 453 | record.tileView.measure(exactly(cw), exactly(ch)); |
| 454 | } |
Adrian Roos | cd542b8 | 2014-08-12 22:25:35 +0200 | [diff] [blame] | 455 | int h = rows == 0 ? brightnessHeight : (getRowTop(rows) + mPanelPaddingBottom); |
Jason Monk | 3d5f551 | 2014-07-25 11:17:28 -0400 | [diff] [blame] | 456 | if (mFooter.hasFooter()) { |
Adrian Roos | cd542b8 | 2014-08-12 22:25:35 +0200 | [diff] [blame] | 457 | h += mFooter.getView().getMeasuredHeight(); |
Jason Monk | 3d5f551 | 2014-07-25 11:17:28 -0400 | [diff] [blame] | 458 | } |
Adrian Roos | 1940892 | 2014-08-07 20:54:12 +0200 | [diff] [blame] | 459 | mDetail.measure(exactly(width), MeasureSpec.UNSPECIFIED); |
| 460 | if (mDetail.getMeasuredHeight() < h) { |
| 461 | mDetail.measure(exactly(width), exactly(h)); |
| 462 | } |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 463 | mGridHeight = h; |
Adrian Roos | 1940892 | 2014-08-07 20:54:12 +0200 | [diff] [blame] | 464 | setMeasuredDimension(width, Math.max(h, mDetail.getMeasuredHeight())); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | private static int exactly(int size) { |
| 468 | return MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY); |
| 469 | } |
| 470 | |
| 471 | @Override |
| 472 | 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] | 473 | final int w = getWidth(); |
Adrian Roos | cd542b8 | 2014-08-12 22:25:35 +0200 | [diff] [blame] | 474 | mBrightnessView.layout(0, mBrightnessPaddingTop, |
| 475 | mBrightnessView.getMeasuredWidth(), |
| 476 | mBrightnessPaddingTop + mBrightnessView.getMeasuredHeight()); |
Selim Cinek | 06d3bca | 2014-08-26 17:29:20 +0200 | [diff] [blame] | 477 | boolean isRtl = getLayoutDirection() == LAYOUT_DIRECTION_RTL; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 478 | for (TileRecord record : mRecords) { |
| 479 | if (record.tileView.getVisibility() == GONE) continue; |
| 480 | final int cols = getColumnCount(record.row); |
| 481 | final int cw = record.row == 0 ? mLargeCellWidth : mCellWidth; |
| 482 | final int extra = (w - cw * cols) / (cols + 1); |
Selim Cinek | 06d3bca | 2014-08-26 17:29:20 +0200 | [diff] [blame] | 483 | int left = record.col * cw + (record.col + 1) * extra; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 484 | final int top = getRowTop(record.row); |
Selim Cinek | 06d3bca | 2014-08-26 17:29:20 +0200 | [diff] [blame] | 485 | int right; |
| 486 | int tileWith = record.tileView.getMeasuredWidth(); |
| 487 | if (isRtl) { |
| 488 | right = w - left; |
| 489 | left = right - tileWith; |
| 490 | } else { |
| 491 | right = left + tileWith; |
| 492 | } |
| 493 | record.tileView.layout(left, top, right, top + record.tileView.getMeasuredHeight()); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 494 | } |
John Spurlock | 3e04cc8 | 2014-05-30 12:34:03 -0400 | [diff] [blame] | 495 | final int dh = Math.max(mDetail.getMeasuredHeight(), getMeasuredHeight()); |
| 496 | mDetail.layout(0, 0, mDetail.getMeasuredWidth(), dh); |
Jason Monk | 3d5f551 | 2014-07-25 11:17:28 -0400 | [diff] [blame] | 497 | if (mFooter.hasFooter()) { |
| 498 | View footer = mFooter.getView(); |
| 499 | footer.layout(0, getMeasuredHeight() - footer.getMeasuredHeight(), |
| 500 | footer.getMeasuredWidth(), getMeasuredHeight()); |
| 501 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | private int getRowTop(int row) { |
Adrian Roos | cd542b8 | 2014-08-12 22:25:35 +0200 | [diff] [blame] | 505 | if (row <= 0) return mBrightnessView.getMeasuredHeight() + mBrightnessPaddingTop; |
| 506 | return mBrightnessView.getMeasuredHeight() + mBrightnessPaddingTop |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 507 | + mLargeCellHeight - mDualTileUnderlap + (row - 1) * mCellHeight; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | private int getColumnCount(int row) { |
| 511 | int cols = 0; |
| 512 | for (TileRecord record : mRecords) { |
| 513 | if (record.tileView.getVisibility() == GONE) continue; |
| 514 | if (record.row == row) cols++; |
| 515 | } |
| 516 | return cols; |
| 517 | } |
| 518 | |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 519 | private void fireShowingDetail(QSTile.DetailAdapter detail) { |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 520 | if (mCallback != null) { |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 521 | mCallback.onShowingDetail(detail); |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | private void fireToggleStateChanged(boolean state) { |
| 526 | if (mCallback != null) { |
| 527 | mCallback.onToggleStateChanged(state); |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 528 | } |
| 529 | } |
| 530 | |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 531 | private void fireScanStateChanged(boolean state) { |
| 532 | if (mCallback != null) { |
| 533 | mCallback.onScanStateChanged(state); |
| 534 | } |
| 535 | } |
| 536 | |
John Spurlock | 465cefa | 2014-08-16 10:39:33 -0400 | [diff] [blame] | 537 | private void setDetailRecord(Record r) { |
| 538 | if (r == mDetailRecord) return; |
| 539 | mDetailRecord = r; |
| 540 | final boolean scanState = mDetailRecord instanceof TileRecord |
| 541 | && ((TileRecord) mDetailRecord).scanState; |
| 542 | fireScanStateChanged(scanState); |
| 543 | } |
| 544 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 545 | private class H extends Handler { |
| 546 | private static final int SHOW_DETAIL = 1; |
| 547 | private static final int SET_TILE_VISIBILITY = 2; |
| 548 | @Override |
| 549 | public void handleMessage(Message msg) { |
| 550 | if (msg.what == SHOW_DETAIL) { |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 551 | handleShowDetail((Record)msg.obj, msg.arg1 != 0); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 552 | } else if (msg.what == SET_TILE_VISIBILITY) { |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 553 | handleSetTileVisibility((View)msg.obj, msg.arg1); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 554 | } |
| 555 | } |
| 556 | } |
| 557 | |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 558 | private static class Record { |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 559 | View detailView; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 560 | DetailAdapter detailAdapter; |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 561 | } |
| 562 | |
Jason Monk | 11a7744 | 2015-05-12 19:29:02 -0400 | [diff] [blame^] | 563 | protected static final class TileRecord extends Record { |
| 564 | public QSTile<?> tile; |
| 565 | public QSTileView tileView; |
| 566 | public int row; |
| 567 | public int col; |
| 568 | public boolean scanState; |
| 569 | public boolean openingDetail; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | private final AnimatorListenerAdapter mTeardownDetailWhenDone = new AnimatorListenerAdapter() { |
| 573 | public void onAnimationEnd(Animator animation) { |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 574 | mDetailContent.removeAllViews(); |
John Spurlock | 465cefa | 2014-08-16 10:39:33 -0400 | [diff] [blame] | 575 | setDetailRecord(null); |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 576 | mClosingDetail = false; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 577 | }; |
| 578 | }; |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 579 | |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 580 | private final AnimatorListenerAdapter mHideGridContentWhenDone = new AnimatorListenerAdapter() { |
Jason Monk | 8a2d4fc | 2014-09-09 15:46:35 -0400 | [diff] [blame] | 581 | public void onAnimationCancel(Animator animation) { |
| 582 | // If we have been cancelled, remove the listener so that onAnimationEnd doesn't get |
| 583 | // called, this will avoid accidentally turning off the grid when we don't want to. |
| 584 | animation.removeListener(this); |
John Spurlock | 20c8905 | 2015-05-11 13:11:24 -0400 | [diff] [blame] | 585 | redrawTile(); |
Jason Monk | 8a2d4fc | 2014-09-09 15:46:35 -0400 | [diff] [blame] | 586 | }; |
| 587 | |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 588 | @Override |
| 589 | public void onAnimationEnd(Animator animation) { |
Jason Monk | 98fa70c | 2014-10-29 11:03:41 -0400 | [diff] [blame] | 590 | // Only hide content if still in detail state. |
| 591 | if (mDetailRecord != null) { |
| 592 | setGridContentVisibility(false); |
John Spurlock | 20c8905 | 2015-05-11 13:11:24 -0400 | [diff] [blame] | 593 | redrawTile(); |
| 594 | } |
| 595 | } |
| 596 | |
| 597 | private void redrawTile() { |
| 598 | if (mDetailRecord instanceof TileRecord) { |
| 599 | final TileRecord tileRecord = (TileRecord) mDetailRecord; |
| 600 | tileRecord.openingDetail = false; |
| 601 | drawTile(tileRecord, tileRecord.tile.getState()); |
Jason Monk | 98fa70c | 2014-10-29 11:03:41 -0400 | [diff] [blame] | 602 | } |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 603 | } |
| 604 | }; |
| 605 | |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 606 | public interface Callback { |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 607 | void onShowingDetail(QSTile.DetailAdapter detail); |
| 608 | void onToggleStateChanged(boolean state); |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 609 | void onScanStateChanged(boolean state); |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 610 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 611 | } |