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 | } |
Jason Monk | ca894a0 | 2016-01-12 15:30:22 -0500 | [diff] [blame] | 332 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 333 | @Override |
| 334 | public void onShowDetail(boolean show) { |
| 335 | QSPanel.this.showDetail(show, r); |
| 336 | } |
Jason Monk | ca894a0 | 2016-01-12 15:30:22 -0500 | [diff] [blame] | 337 | |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 338 | @Override |
| 339 | public void onToggleStateChanged(boolean state) { |
| 340 | if (mDetailRecord == r) { |
| 341 | fireToggleStateChanged(state); |
| 342 | } |
| 343 | } |
Jason Monk | ca894a0 | 2016-01-12 15:30:22 -0500 | [diff] [blame] | 344 | |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 345 | @Override |
| 346 | public void onScanStateChanged(boolean state) { |
John Spurlock | 465cefa | 2014-08-16 10:39:33 -0400 | [diff] [blame] | 347 | r.scanState = state; |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 348 | if (mDetailRecord == r) { |
John Spurlock | 465cefa | 2014-08-16 10:39:33 -0400 | [diff] [blame] | 349 | fireScanStateChanged(r.scanState); |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 350 | } |
| 351 | } |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 352 | |
| 353 | @Override |
| 354 | public void onAnnouncementRequested(CharSequence announcement) { |
| 355 | announceForAccessibility(announcement); |
| 356 | } |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 357 | }; |
Jason Monk | ca894a0 | 2016-01-12 15:30:22 -0500 | [diff] [blame] | 358 | r.tile.addCallback(callback); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 359 | final View.OnClickListener click = new View.OnClickListener() { |
| 360 | @Override |
| 361 | public void onClick(View v) { |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 362 | onTileClick(r.tile); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 363 | } |
| 364 | }; |
John Spurlock | c247b8f | 2014-11-06 23:06:25 -0500 | [diff] [blame] | 365 | final View.OnLongClickListener longClick = new View.OnLongClickListener() { |
| 366 | @Override |
| 367 | public boolean onLongClick(View v) { |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 368 | if (mCustomizePanel != null) { |
| 369 | if (!mCustomizePanel.isCustomizing()) { |
Jason Monk | b9c0019 | 2015-10-07 11:45:33 -0400 | [diff] [blame] | 370 | int[] loc = new int[2]; |
| 371 | getLocationInWindow(loc); |
| 372 | int x = r.tileView.getLeft() + r.tileView.getWidth() / 2 + loc[0]; |
| 373 | int y = r.tileView.getTop() + mTileLayout.getOffsetTop(r) |
| 374 | + r.tileView.getHeight() / 2 + loc[1]; |
| 375 | mCustomizePanel.show(x, y); |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 376 | } |
| 377 | } else { |
| 378 | r.tile.longClick(); |
| 379 | } |
John Spurlock | c247b8f | 2014-11-06 23:06:25 -0500 | [diff] [blame] | 380 | return true; |
| 381 | } |
| 382 | }; |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 383 | r.tileView.init(click, longClick); |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 384 | r.tile.setListening(mListening); |
| 385 | callback.onStateChanged(r.tile.getState()); |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 386 | r.tile.refreshState(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 387 | mRecords.add(r); |
| 388 | |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 389 | if (mTileLayout != null) { |
| 390 | mTileLayout.addTile(r); |
| 391 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 392 | } |
| 393 | |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 394 | protected void onTileClick(QSTile<?> tile) { |
| 395 | tile.click(); |
| 396 | } |
| 397 | |
John Spurlock | f7ae442 | 2014-08-01 12:45:18 -0400 | [diff] [blame] | 398 | public boolean isShowingDetail() { |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 399 | return mDetailRecord != null |
| 400 | || (mCustomizePanel != null && mCustomizePanel.isCustomizing()); |
John Spurlock | f7ae442 | 2014-08-01 12:45:18 -0400 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | public void closeDetail() { |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 404 | if (mCustomizePanel != null && mCustomizePanel.isCustomizing()) { |
| 405 | // Treat this as a detail panel for now, to make things easy. |
Jason Monk | b9c0019 | 2015-10-07 11:45:33 -0400 | [diff] [blame] | 406 | mCustomizePanel.hide(mCustomizePanel.getWidth() / 2, mCustomizePanel.getHeight() / 2); |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 407 | return; |
| 408 | } |
John Spurlock | f7ae442 | 2014-08-01 12:45:18 -0400 | [diff] [blame] | 409 | showDetail(false, mDetailRecord); |
| 410 | } |
| 411 | |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 412 | public boolean isClosingDetail() { |
| 413 | return mClosingDetail; |
| 414 | } |
| 415 | |
| 416 | public int getGridHeight() { |
Jason Monk | 520ea06 | 2015-08-18 14:53:06 -0400 | [diff] [blame] | 417 | return mQsContainer.getMeasuredHeight(); |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 418 | } |
| 419 | |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 420 | protected void handleShowDetail(Record r, boolean show) { |
Jason Monk | ca894a0 | 2016-01-12 15:30:22 -0500 | [diff] [blame] | 421 | if (show && !mExpanded) { |
| 422 | mHost.animateExpandQS(); |
| 423 | } |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 424 | if (r instanceof TileRecord) { |
| 425 | handleShowDetailTile((TileRecord) r, show); |
| 426 | } else { |
Adrian Roos | 970be53 | 2014-11-21 15:50:16 +0100 | [diff] [blame] | 427 | int x = 0; |
| 428 | int y = 0; |
| 429 | if (r != null) { |
| 430 | x = r.x; |
| 431 | y = r.y; |
| 432 | } |
| 433 | handleShowDetailImpl(r, show, x, y); |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 434 | } |
| 435 | } |
| 436 | |
| 437 | private void handleShowDetailTile(TileRecord r, boolean show) { |
Jason Monk | efe3d3f | 2015-06-10 16:48:03 -0400 | [diff] [blame] | 438 | if ((mDetailRecord != null) == show && mDetailRecord == r) return; |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 439 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 440 | if (show) { |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 441 | r.detailAdapter = r.tile.getDetailAdapter(); |
| 442 | if (r.detailAdapter == null) return; |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 443 | } |
Jason Monk | 0d6a1c4 | 2015-04-20 16:38:51 -0400 | [diff] [blame] | 444 | r.tile.setDetailListening(show); |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 445 | int x = r.tileView.getLeft() + r.tileView.getWidth() / 2; |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 446 | int y = r.tileView.getTop() + mTileLayout.getOffsetTop(r) + r.tileView.getHeight() / 2; |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 447 | handleShowDetailImpl(r, show, x, y); |
| 448 | } |
| 449 | |
| 450 | private void handleShowDetailImpl(Record r, boolean show, int x, int y) { |
Jason Monk | efe3d3f | 2015-06-10 16:48:03 -0400 | [diff] [blame] | 451 | boolean visibleDiff = (mDetailRecord != null) != show; |
| 452 | if (!visibleDiff && mDetailRecord == r) return; // already in right state |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 453 | DetailAdapter detailAdapter = null; |
| 454 | AnimatorListener listener = null; |
| 455 | if (show) { |
| 456 | detailAdapter = r.detailAdapter; |
| 457 | r.detailView = detailAdapter.createDetailView(mContext, r.detailView, mDetailContent); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 458 | if (r.detailView == null) throw new IllegalStateException("Must return detail view"); |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 459 | |
| 460 | final Intent settingsIntent = detailAdapter.getSettingsIntent(); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 461 | mDetailSettingsButton.setVisibility(settingsIntent != null ? VISIBLE : GONE); |
| 462 | mDetailSettingsButton.setOnClickListener(new OnClickListener() { |
| 463 | @Override |
| 464 | public void onClick(View v) { |
Jason Monk | ee43cdf | 2015-06-19 14:20:46 -0400 | [diff] [blame] | 465 | mHost.startActivityDismissingKeyguard(settingsIntent); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 466 | } |
| 467 | }); |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 468 | |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 469 | mDetailContent.removeAllViews(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 470 | mDetail.bringToFront(); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 471 | mDetailContent.addView(r.detailView); |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 472 | MetricsLogger.visible(mContext, detailAdapter.getMetricsCategory()); |
Jason Monk | 17b70a5 | 2015-06-09 13:40:05 -0400 | [diff] [blame] | 473 | announceForAccessibility(mContext.getString( |
| 474 | R.string.accessibility_quick_settings_detail, |
Jason Monk | c06fbb1 | 2016-01-08 14:12:18 -0500 | [diff] [blame] | 475 | detailAdapter.getTitle())); |
John Spurlock | 465cefa | 2014-08-16 10:39:33 -0400 | [diff] [blame] | 476 | setDetailRecord(r); |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 477 | listener = mHideGridContentWhenDone; |
Jason Monk | efe3d3f | 2015-06-10 16:48:03 -0400 | [diff] [blame] | 478 | if (r instanceof TileRecord && visibleDiff) { |
John Spurlock | 20c8905 | 2015-05-11 13:11:24 -0400 | [diff] [blame] | 479 | ((TileRecord) r).openingDetail = true; |
| 480 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 481 | } else { |
Jason Monk | 78dcee5 | 2015-06-11 15:57:41 -0400 | [diff] [blame] | 482 | if (mDetailRecord != null) { |
| 483 | MetricsLogger.hidden(mContext, mDetailRecord.detailAdapter.getMetricsCategory()); |
| 484 | } |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 485 | mClosingDetail = true; |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 486 | setGridContentVisibility(true); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 487 | listener = mTeardownDetailWhenDone; |
John Spurlock | 465cefa | 2014-08-16 10:39:33 -0400 | [diff] [blame] | 488 | fireScanStateChanged(false); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 489 | } |
Jason Monk | 6783bef | 2014-09-22 13:50:05 -0400 | [diff] [blame] | 490 | sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 491 | fireShowingDetail(show ? detailAdapter : null); |
Jason Monk | efe3d3f | 2015-06-10 16:48:03 -0400 | [diff] [blame] | 492 | if (visibleDiff) { |
| 493 | mClipper.animateCircularClip(x, y, show, listener); |
| 494 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 495 | } |
| 496 | |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 497 | private void setGridContentVisibility(boolean visible) { |
| 498 | int newVis = visible ? VISIBLE : INVISIBLE; |
Jason Monk | 520ea06 | 2015-08-18 14:53:06 -0400 | [diff] [blame] | 499 | mQsContainer.setVisibility(newVis); |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 500 | if (mGridContentVisible != visible) { |
| 501 | MetricsLogger.visibility(mContext, MetricsLogger.QS_PANEL, newVis); |
| 502 | } |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 503 | mGridContentVisible = visible; |
| 504 | } |
| 505 | |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 506 | private void logTiles() { |
| 507 | for (int i = 0; i < mRecords.size(); i++) { |
| 508 | TileRecord tileRecord = mRecords.get(i); |
Jason Monk | ba2318e | 2015-12-08 09:04:23 -0500 | [diff] [blame] | 509 | MetricsLogger.visible(mContext, tileRecord.tile.getMetricsCategory()); |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 510 | } |
| 511 | } |
| 512 | |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 513 | private void fireShowingDetail(QSTile.DetailAdapter detail) { |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 514 | if (mCallback != null) { |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 515 | mCallback.onShowingDetail(detail); |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | private void fireToggleStateChanged(boolean state) { |
| 520 | if (mCallback != null) { |
| 521 | mCallback.onToggleStateChanged(state); |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 522 | } |
| 523 | } |
| 524 | |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 525 | private void fireScanStateChanged(boolean state) { |
| 526 | if (mCallback != null) { |
| 527 | mCallback.onScanStateChanged(state); |
| 528 | } |
| 529 | } |
| 530 | |
John Spurlock | 465cefa | 2014-08-16 10:39:33 -0400 | [diff] [blame] | 531 | private void setDetailRecord(Record r) { |
| 532 | if (r == mDetailRecord) return; |
| 533 | mDetailRecord = r; |
| 534 | final boolean scanState = mDetailRecord instanceof TileRecord |
| 535 | && ((TileRecord) mDetailRecord).scanState; |
| 536 | fireScanStateChanged(scanState); |
| 537 | } |
| 538 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 539 | private class H extends Handler { |
| 540 | private static final int SHOW_DETAIL = 1; |
| 541 | private static final int SET_TILE_VISIBILITY = 2; |
| 542 | @Override |
| 543 | public void handleMessage(Message msg) { |
| 544 | if (msg.what == SHOW_DETAIL) { |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 545 | handleShowDetail((Record)msg.obj, msg.arg1 != 0); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 546 | } |
| 547 | } |
| 548 | } |
| 549 | |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 550 | protected static class Record { |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 551 | View detailView; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 552 | DetailAdapter detailAdapter; |
Adrian Roos | 970be53 | 2014-11-21 15:50:16 +0100 | [diff] [blame] | 553 | int x; |
| 554 | int y; |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 555 | } |
| 556 | |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 557 | public static final class TileRecord extends Record { |
Jason Monk | 11a7744 | 2015-05-12 19:29:02 -0400 | [diff] [blame] | 558 | public QSTile<?> tile; |
Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 559 | public QSTileBaseView tileView; |
Jason Monk | 11a7744 | 2015-05-12 19:29:02 -0400 | [diff] [blame] | 560 | public boolean scanState; |
| 561 | public boolean openingDetail; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | private final AnimatorListenerAdapter mTeardownDetailWhenDone = new AnimatorListenerAdapter() { |
| 565 | public void onAnimationEnd(Animator animation) { |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 566 | mDetailContent.removeAllViews(); |
John Spurlock | 465cefa | 2014-08-16 10:39:33 -0400 | [diff] [blame] | 567 | setDetailRecord(null); |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 568 | mClosingDetail = false; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 569 | }; |
| 570 | }; |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 571 | |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 572 | private final AnimatorListenerAdapter mHideGridContentWhenDone = new AnimatorListenerAdapter() { |
Jason Monk | 8a2d4fc | 2014-09-09 15:46:35 -0400 | [diff] [blame] | 573 | public void onAnimationCancel(Animator animation) { |
| 574 | // If we have been cancelled, remove the listener so that onAnimationEnd doesn't get |
| 575 | // called, this will avoid accidentally turning off the grid when we don't want to. |
| 576 | animation.removeListener(this); |
John Spurlock | 20c8905 | 2015-05-11 13:11:24 -0400 | [diff] [blame] | 577 | redrawTile(); |
Jason Monk | 8a2d4fc | 2014-09-09 15:46:35 -0400 | [diff] [blame] | 578 | }; |
| 579 | |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 580 | @Override |
| 581 | public void onAnimationEnd(Animator animation) { |
Jason Monk | 98fa70c | 2014-10-29 11:03:41 -0400 | [diff] [blame] | 582 | // Only hide content if still in detail state. |
| 583 | if (mDetailRecord != null) { |
| 584 | setGridContentVisibility(false); |
John Spurlock | 20c8905 | 2015-05-11 13:11:24 -0400 | [diff] [blame] | 585 | redrawTile(); |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | private void redrawTile() { |
| 590 | if (mDetailRecord instanceof TileRecord) { |
| 591 | final TileRecord tileRecord = (TileRecord) mDetailRecord; |
| 592 | tileRecord.openingDetail = false; |
| 593 | drawTile(tileRecord, tileRecord.tile.getState()); |
Jason Monk | 98fa70c | 2014-10-29 11:03:41 -0400 | [diff] [blame] | 594 | } |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 595 | } |
| 596 | }; |
| 597 | |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 598 | public interface Callback { |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 599 | void onShowingDetail(QSTile.DetailAdapter detail); |
| 600 | void onToggleStateChanged(boolean state); |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 601 | void onScanStateChanged(boolean state); |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 602 | } |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 603 | |
| 604 | public interface QSTileLayout { |
| 605 | void addTile(TileRecord tile); |
| 606 | void removeTile(TileRecord tile); |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 607 | int getOffsetTop(TileRecord tile); |
Jason Monk | 9d02a43 | 2016-01-20 16:33:46 -0500 | [diff] [blame^] | 608 | boolean updateResources(); |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 609 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 610 | } |