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