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