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