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