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 | |
Jason Monk | 7e53f20 | 2016-01-28 10:40:20 -0500 | [diff] [blame] | 19 | import android.content.ComponentName; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 20 | import android.content.Context; |
Jorim Jaggi | e17c4b4 | 2014-08-26 17:27:31 +0200 | [diff] [blame] | 21 | import android.content.res.Configuration; |
John Spurlock | 4bf3198 | 2014-05-21 13:04:22 -0400 | [diff] [blame] | 22 | import android.content.res.Resources; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 23 | import android.os.Handler; |
| 24 | import android.os.Message; |
| 25 | import android.util.AttributeSet; |
Xiaohui Chen | 6644893 | 2016-04-18 12:53:28 -0700 | [diff] [blame] | 26 | import android.util.Log; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 27 | import android.view.LayoutInflater; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 28 | import android.view.View; |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 29 | import android.widget.ImageView; |
Jason Monk | 520ea06 | 2015-08-18 14:53:06 -0400 | [diff] [blame] | 30 | import android.widget.LinearLayout; |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 31 | import com.android.internal.logging.MetricsLogger; |
Chris Wren | 77781d3 | 2016-01-11 14:49:26 -0500 | [diff] [blame] | 32 | import com.android.internal.logging.MetricsProto.MetricsEvent; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 33 | import com.android.systemui.R; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 34 | import com.android.systemui.qs.QSTile.DetailAdapter; |
Jason Monk | 46dbfb4 | 2016-02-25 14:59:20 -0500 | [diff] [blame] | 35 | import com.android.systemui.qs.QSTile.Host.Callback; |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 36 | import com.android.systemui.qs.customize.QSCustomizer; |
Jason Monk | 7e53f20 | 2016-01-28 10:40:20 -0500 | [diff] [blame] | 37 | import com.android.systemui.qs.external.CustomTile; |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 38 | import com.android.systemui.settings.BrightnessController; |
| 39 | import com.android.systemui.settings.ToggleSlider; |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 40 | import com.android.systemui.statusbar.phone.QSTileHost; |
Adrian Roos | 5fd872e | 2014-08-12 17:28:58 +0200 | [diff] [blame] | 41 | import com.android.systemui.statusbar.policy.BrightnessMirrorController; |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 42 | import com.android.systemui.tuner.TunerService; |
| 43 | import com.android.systemui.tuner.TunerService.Tunable; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 44 | |
| 45 | import java.util.ArrayList; |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 46 | import java.util.Collection; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 47 | |
| 48 | /** View that represents the quick settings tile panel. **/ |
Jason Monk | 46dbfb4 | 2016-02-25 14:59:20 -0500 | [diff] [blame] | 49 | public class QSPanel extends LinearLayout implements Tunable, Callback { |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 50 | |
| 51 | public static final String QS_SHOW_BRIGHTNESS = "qs_show_brightness"; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 52 | |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 53 | protected final Context mContext; |
Jason Monk | 11a7744 | 2015-05-12 19:29:02 -0400 | [diff] [blame] | 54 | protected final ArrayList<TileRecord> mRecords = new ArrayList<TileRecord>(); |
Jason Monk | 11a7744 | 2015-05-12 19:29:02 -0400 | [diff] [blame] | 55 | protected final View mBrightnessView; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 56 | private final H mHandler = new H(); |
| 57 | |
John Spurlock | 92d9b19 | 2014-06-29 12:54:24 -0400 | [diff] [blame] | 58 | private int mPanelPaddingBottom; |
Adrian Roos | cd542b8 | 2014-08-12 22:25:35 +0200 | [diff] [blame] | 59 | private int mBrightnessPaddingTop; |
Xiaohui Chen | 6644893 | 2016-04-18 12:53:28 -0700 | [diff] [blame] | 60 | protected boolean mExpanded; |
Jason Monk | e5107a3 | 2016-05-31 15:40:58 -0400 | [diff] [blame] | 61 | protected boolean mListening; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 62 | |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 63 | private Callback mCallback; |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 64 | private BrightnessController mBrightnessController; |
Jason Monk | bbadff8 | 2015-11-06 15:47:26 -0500 | [diff] [blame] | 65 | protected QSTileHost mHost; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 66 | |
Jason Monk | bbadff8 | 2015-11-06 15:47:26 -0500 | [diff] [blame] | 67 | protected QSFooter mFooter; |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 68 | private boolean mGridContentVisible = true; |
Jason Monk | 3d5f551 | 2014-07-25 11:17:28 -0400 | [diff] [blame] | 69 | |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 70 | protected QSTileLayout mTileLayout; |
| 71 | |
| 72 | private QSCustomizer mCustomizePanel; |
Jason Monk | 377e7ad | 2016-02-16 14:03:21 -0500 | [diff] [blame] | 73 | private Record mDetailRecord; |
Jason Monk | 520ea06 | 2015-08-18 14:53:06 -0400 | [diff] [blame] | 74 | |
Adrian Roos | 429c962 | 2016-06-15 13:02:17 -0700 | [diff] [blame] | 75 | private BrightnessMirrorController mBrightnessMirrorController; |
| 76 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 77 | public QSPanel(Context context) { |
| 78 | this(context, null); |
| 79 | } |
| 80 | |
| 81 | public QSPanel(Context context, AttributeSet attrs) { |
| 82 | super(context, attrs); |
| 83 | mContext = context; |
| 84 | |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 85 | setOrientation(VERTICAL); |
Jason Monk | 520ea06 | 2015-08-18 14:53:06 -0400 | [diff] [blame] | 86 | |
Jason Monk | deba7a4 | 2015-12-08 16:14:10 -0500 | [diff] [blame] | 87 | mBrightnessView = LayoutInflater.from(context).inflate( |
| 88 | R.layout.quick_settings_brightness_dialog, this, false); |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 89 | addView(mBrightnessView); |
Jason Monk | deba7a4 | 2015-12-08 16:14:10 -0500 | [diff] [blame] | 90 | |
Xiaohui Chen | 2f3551b | 2016-04-07 10:37:25 -0700 | [diff] [blame] | 91 | setupTileLayout(); |
Jason Monk | deba7a4 | 2015-12-08 16:14:10 -0500 | [diff] [blame] | 92 | |
| 93 | mFooter = new QSFooter(this, context); |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 94 | addView(mFooter.getView()); |
Jason Monk | deba7a4 | 2015-12-08 16:14:10 -0500 | [diff] [blame] | 95 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 96 | updateResources(); |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 97 | |
| 98 | mBrightnessController = new BrightnessController(getContext(), |
| 99 | (ImageView) findViewById(R.id.brightness_icon), |
| 100 | (ToggleSlider) findViewById(R.id.brightness_slider)); |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 101 | |
Jason Monk | 377e7ad | 2016-02-16 14:03:21 -0500 | [diff] [blame] | 102 | } |
| 103 | |
Xiaohui Chen | 2f3551b | 2016-04-07 10:37:25 -0700 | [diff] [blame] | 104 | protected void setupTileLayout() { |
| 105 | mTileLayout = (QSTileLayout) LayoutInflater.from(mContext).inflate( |
| 106 | R.layout.qs_paged_tile_layout, this, false); |
Jason Monk | e5107a3 | 2016-05-31 15:40:58 -0400 | [diff] [blame] | 107 | mTileLayout.setListening(mListening); |
Xiaohui Chen | 2f3551b | 2016-04-07 10:37:25 -0700 | [diff] [blame] | 108 | addView((View) mTileLayout); |
| 109 | findViewById(android.R.id.edit).setOnClickListener(view -> |
| 110 | mHost.startRunnableDismissingKeyguard(() -> showEdit(view))); |
| 111 | } |
| 112 | |
Jason Monk | 377e7ad | 2016-02-16 14:03:21 -0500 | [diff] [blame] | 113 | public boolean isShowingCustomize() { |
| 114 | return mCustomizePanel != null && mCustomizePanel.isCustomizing(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 115 | } |
| 116 | |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 117 | @Override |
| 118 | protected void onAttachedToWindow() { |
| 119 | super.onAttachedToWindow(); |
Jason Monk | deba7a4 | 2015-12-08 16:14:10 -0500 | [diff] [blame] | 120 | TunerService.get(mContext).addTunable(this, QS_SHOW_BRIGHTNESS); |
Jason Monk | f160edca | 2016-03-30 13:48:56 -0400 | [diff] [blame] | 121 | if (mHost != null) { |
| 122 | setTiles(mHost.getTiles()); |
| 123 | } |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | @Override |
| 127 | protected void onDetachedFromWindow() { |
| 128 | TunerService.get(mContext).removeTunable(this); |
Jason Monk | 46dbfb4 | 2016-02-25 14:59:20 -0500 | [diff] [blame] | 129 | mHost.removeCallback(this); |
Jason Monk | f160edca | 2016-03-30 13:48:56 -0400 | [diff] [blame] | 130 | for (TileRecord record : mRecords) { |
| 131 | record.tile.removeCallbacks(); |
| 132 | } |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 133 | super.onDetachedFromWindow(); |
| 134 | } |
| 135 | |
| 136 | @Override |
Jason Monk | 46dbfb4 | 2016-02-25 14:59:20 -0500 | [diff] [blame] | 137 | public void onTilesChanged() { |
| 138 | setTiles(mHost.getTiles()); |
| 139 | } |
| 140 | |
| 141 | @Override |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 142 | public void onTuningChanged(String key, String newValue) { |
| 143 | if (QS_SHOW_BRIGHTNESS.equals(key)) { |
| 144 | mBrightnessView.setVisibility(newValue == null || Integer.parseInt(newValue) != 0 |
| 145 | ? VISIBLE : GONE); |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | |
Jason Monk | a992732 | 2015-12-13 16:22:37 -0500 | [diff] [blame] | 149 | public void openDetails(String subPanel) { |
| 150 | QSTile<?> tile = getTile(subPanel); |
| 151 | showDetailAdapter(true, tile.getDetailAdapter(), new int[] {getWidth() / 2, 0}); |
| 152 | } |
| 153 | |
| 154 | private QSTile<?> getTile(String subPanel) { |
| 155 | for (int i = 0; i < mRecords.size(); i++) { |
| 156 | if (subPanel.equals(mRecords.get(i).tile.getTileSpec())) { |
| 157 | return mRecords.get(i).tile; |
| 158 | } |
| 159 | } |
| 160 | return mHost.createTile(subPanel); |
| 161 | } |
| 162 | |
Adrian Roos | 5fd872e | 2014-08-12 17:28:58 +0200 | [diff] [blame] | 163 | public void setBrightnessMirror(BrightnessMirrorController c) { |
Adrian Roos | 429c962 | 2016-06-15 13:02:17 -0700 | [diff] [blame] | 164 | mBrightnessMirrorController = c; |
Adrian Roos | 5fd872e | 2014-08-12 17:28:58 +0200 | [diff] [blame] | 165 | ToggleSlider brightnessSlider = (ToggleSlider) findViewById(R.id.brightness_slider); |
| 166 | ToggleSlider mirror = (ToggleSlider) c.getMirror().findViewById(R.id.brightness_slider); |
| 167 | brightnessSlider.setMirror(mirror); |
| 168 | brightnessSlider.setMirrorController(c); |
| 169 | } |
| 170 | |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 171 | public void setCallback(Callback callback) { |
| 172 | mCallback = callback; |
| 173 | } |
| 174 | |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 175 | public void setHost(QSTileHost host, QSCustomizer customizer) { |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 176 | mHost = host; |
Jason Monk | 46dbfb4 | 2016-02-25 14:59:20 -0500 | [diff] [blame] | 177 | mHost.addCallback(this); |
| 178 | setTiles(mHost.getTiles()); |
Jason Monk | 3d5f551 | 2014-07-25 11:17:28 -0400 | [diff] [blame] | 179 | mFooter.setHost(host); |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 180 | mCustomizePanel = customizer; |
| 181 | if (mCustomizePanel != null) { |
| 182 | mCustomizePanel.setHost(mHost); |
| 183 | } |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 184 | } |
| 185 | |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 186 | public QSTileHost getHost() { |
| 187 | return mHost; |
| 188 | } |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 189 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 190 | public void updateResources() { |
John Spurlock | 4bf3198 | 2014-05-21 13:04:22 -0400 | [diff] [blame] | 191 | final Resources res = mContext.getResources(); |
John Spurlock | 92d9b19 | 2014-06-29 12:54:24 -0400 | [diff] [blame] | 192 | mPanelPaddingBottom = res.getDimensionPixelSize(R.dimen.qs_panel_padding_bottom); |
Adrian Roos | cd542b8 | 2014-08-12 22:25:35 +0200 | [diff] [blame] | 193 | mBrightnessPaddingTop = res.getDimensionPixelSize(R.dimen.qs_brightness_padding_top); |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 194 | setPadding(0, mBrightnessPaddingTop, 0, mPanelPaddingBottom); |
Jason Monk | a758ba6 | 2015-07-14 12:29:28 -0400 | [diff] [blame] | 195 | for (TileRecord r : mRecords) { |
| 196 | r.tile.clearState(); |
| 197 | } |
John Spurlock | 1a462c1 | 2014-07-14 10:52:01 -0400 | [diff] [blame] | 198 | if (mListening) { |
| 199 | refreshAllTiles(); |
| 200 | } |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 201 | if (mTileLayout != null) { |
| 202 | mTileLayout.updateResources(); |
| 203 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 204 | } |
| 205 | |
Jorim Jaggi | e17c4b4 | 2014-08-26 17:27:31 +0200 | [diff] [blame] | 206 | @Override |
| 207 | protected void onConfigurationChanged(Configuration newConfig) { |
| 208 | super.onConfigurationChanged(newConfig); |
Jorim Jaggi | e17c4b4 | 2014-08-26 17:27:31 +0200 | [diff] [blame] | 209 | mFooter.onConfigurationChanged(); |
Adrian Roos | 429c962 | 2016-06-15 13:02:17 -0700 | [diff] [blame] | 210 | |
| 211 | if (mBrightnessMirrorController != null) { |
| 212 | // Reload the mirror in case it got reinflated but we didn't. |
| 213 | setBrightnessMirror(mBrightnessMirrorController); |
| 214 | } |
Jorim Jaggi | e17c4b4 | 2014-08-26 17:27:31 +0200 | [diff] [blame] | 215 | } |
| 216 | |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 217 | public void onCollapse() { |
Yoshinori Hirano | 1dd7d07 | 2016-09-05 16:11:59 +0900 | [diff] [blame^] | 218 | if (mCustomizePanel != null && mCustomizePanel.isShown()) { |
Jason Monk | b9c0019 | 2015-10-07 11:45:33 -0400 | [diff] [blame] | 219 | mCustomizePanel.hide(mCustomizePanel.getWidth() / 2, mCustomizePanel.getHeight() / 2); |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 220 | } |
| 221 | } |
| 222 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 223 | public void setExpanded(boolean expanded) { |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 224 | if (mExpanded == expanded) return; |
| 225 | mExpanded = expanded; |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 226 | if (!mExpanded && mTileLayout instanceof PagedTileLayout) { |
| 227 | ((PagedTileLayout) mTileLayout).setCurrentItem(0, false); |
| 228 | } |
Chris Wren | 77781d3 | 2016-01-11 14:49:26 -0500 | [diff] [blame] | 229 | MetricsLogger.visibility(mContext, MetricsEvent.QS_PANEL, mExpanded); |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 230 | if (!mExpanded) { |
John Spurlock | f7ae442 | 2014-08-01 12:45:18 -0400 | [diff] [blame] | 231 | closeDetail(); |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 232 | } else { |
| 233 | logTiles(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 234 | } |
Jorim Jaggi | e65e310 | 2014-07-01 22:00:50 +0200 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | public void setListening(boolean listening) { |
| 238 | if (mListening == listening) return; |
| 239 | mListening = listening; |
Jason Monk | e5107a3 | 2016-05-31 15:40:58 -0400 | [diff] [blame] | 240 | if (mTileLayout != null) { |
| 241 | mTileLayout.setListening(listening); |
John Spurlock | 1a462c1 | 2014-07-14 10:52:01 -0400 | [diff] [blame] | 242 | } |
Jason Monk | 3d5f551 | 2014-07-25 11:17:28 -0400 | [diff] [blame] | 243 | mFooter.setListening(mListening); |
John Spurlock | 1a462c1 | 2014-07-14 10:52:01 -0400 | [diff] [blame] | 244 | if (mListening) { |
| 245 | refreshAllTiles(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 246 | } |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 247 | if (listening) { |
| 248 | mBrightnessController.registerCallbacks(); |
| 249 | } else { |
| 250 | mBrightnessController.unregisterCallbacks(); |
| 251 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 252 | } |
| 253 | |
Jorim Jaggi | 1ecd7cd | 2014-11-03 16:18:03 +0100 | [diff] [blame] | 254 | public void refreshAllTiles() { |
John Spurlock | 1a462c1 | 2014-07-14 10:52:01 -0400 | [diff] [blame] | 255 | for (TileRecord r : mRecords) { |
| 256 | r.tile.refreshState(); |
| 257 | } |
Jason Monk | 3d5f551 | 2014-07-25 11:17:28 -0400 | [diff] [blame] | 258 | mFooter.refreshState(); |
John Spurlock | 1a462c1 | 2014-07-14 10:52:01 -0400 | [diff] [blame] | 259 | } |
| 260 | |
Adrian Roos | 970be53 | 2014-11-21 15:50:16 +0100 | [diff] [blame] | 261 | public void showDetailAdapter(boolean show, DetailAdapter adapter, int[] locationInWindow) { |
| 262 | int xInWindow = locationInWindow[0]; |
| 263 | int yInWindow = locationInWindow[1]; |
Jason Monk | 377e7ad | 2016-02-16 14:03:21 -0500 | [diff] [blame] | 264 | ((View) getParent()).getLocationInWindow(locationInWindow); |
Adrian Roos | 970be53 | 2014-11-21 15:50:16 +0100 | [diff] [blame] | 265 | |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 266 | Record r = new Record(); |
| 267 | r.detailAdapter = adapter; |
Adrian Roos | 970be53 | 2014-11-21 15:50:16 +0100 | [diff] [blame] | 268 | r.x = xInWindow - locationInWindow[0]; |
| 269 | r.y = yInWindow - locationInWindow[1]; |
| 270 | |
| 271 | locationInWindow[0] = xInWindow; |
| 272 | locationInWindow[1] = yInWindow; |
| 273 | |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 274 | showDetail(show, r); |
| 275 | } |
| 276 | |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 277 | protected void showDetail(boolean show, Record r) { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 278 | mHandler.obtainMessage(H.SHOW_DETAIL, show ? 1 : 0, 0, r).sendToTarget(); |
| 279 | } |
| 280 | |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 281 | public void setTiles(Collection<QSTile<?>> tiles) { |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 282 | setTiles(tiles, false); |
| 283 | } |
| 284 | |
| 285 | public void setTiles(Collection<QSTile<?>> tiles, boolean collapsedView) { |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 286 | for (TileRecord record : mRecords) { |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 287 | mTileLayout.removeTile(record); |
Xiaohui Chen | 6644893 | 2016-04-18 12:53:28 -0700 | [diff] [blame] | 288 | record.tile.removeCallback(record.callback); |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 289 | } |
| 290 | mRecords.clear(); |
| 291 | for (QSTile<?> tile : tiles) { |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 292 | addTile(tile, collapsedView); |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 293 | } |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 294 | } |
| 295 | |
Jason Monk | ec87a87 | 2016-03-01 15:00:16 -0500 | [diff] [blame] | 296 | protected void drawTile(TileRecord r, QSTile.State state) { |
John Spurlock | 20c8905 | 2015-05-11 13:11:24 -0400 | [diff] [blame] | 297 | r.tileView.onStateChanged(state); |
| 298 | } |
| 299 | |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 300 | protected QSTileBaseView createTileView(QSTile<?> tile, boolean collapsedView) { |
| 301 | return new QSTileView(mContext, tile.createTileView(mContext), collapsedView); |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 302 | } |
| 303 | |
Xiaohui Chen | 6644893 | 2016-04-18 12:53:28 -0700 | [diff] [blame] | 304 | protected boolean shouldShowDetail() { |
| 305 | return mExpanded; |
| 306 | } |
| 307 | |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 308 | protected void addTile(final QSTile<?> tile, boolean collapsedView) { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 309 | final TileRecord r = new TileRecord(); |
| 310 | r.tile = tile; |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 311 | r.tileView = createTileView(tile, collapsedView); |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 312 | final QSTile.Callback callback = new QSTile.Callback() { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 313 | @Override |
| 314 | public void onStateChanged(QSTile.State state) { |
Jason Monk | 377e7ad | 2016-02-16 14:03:21 -0500 | [diff] [blame] | 315 | drawTile(r, state); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 316 | } |
Jason Monk | ca894a0 | 2016-01-12 15:30:22 -0500 | [diff] [blame] | 317 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 318 | @Override |
| 319 | public void onShowDetail(boolean show) { |
Xiaohui Chen | 6644893 | 2016-04-18 12:53:28 -0700 | [diff] [blame] | 320 | // Both the collapsed and full QS panels get this callback, this check determines |
| 321 | // which one should handle showing the detail. |
| 322 | if (shouldShowDetail()) { |
| 323 | QSPanel.this.showDetail(show, r); |
| 324 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 325 | } |
Jason Monk | ca894a0 | 2016-01-12 15:30:22 -0500 | [diff] [blame] | 326 | |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 327 | @Override |
| 328 | public void onToggleStateChanged(boolean state) { |
| 329 | if (mDetailRecord == r) { |
| 330 | fireToggleStateChanged(state); |
| 331 | } |
| 332 | } |
Jason Monk | ca894a0 | 2016-01-12 15:30:22 -0500 | [diff] [blame] | 333 | |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 334 | @Override |
| 335 | public void onScanStateChanged(boolean state) { |
John Spurlock | 465cefa | 2014-08-16 10:39:33 -0400 | [diff] [blame] | 336 | r.scanState = state; |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 337 | if (mDetailRecord == r) { |
John Spurlock | 465cefa | 2014-08-16 10:39:33 -0400 | [diff] [blame] | 338 | fireScanStateChanged(r.scanState); |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 339 | } |
| 340 | } |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 341 | |
| 342 | @Override |
| 343 | public void onAnnouncementRequested(CharSequence announcement) { |
| 344 | announceForAccessibility(announcement); |
| 345 | } |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 346 | }; |
Jason Monk | ca894a0 | 2016-01-12 15:30:22 -0500 | [diff] [blame] | 347 | r.tile.addCallback(callback); |
Xiaohui Chen | 6644893 | 2016-04-18 12:53:28 -0700 | [diff] [blame] | 348 | r.callback = callback; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 349 | final View.OnClickListener click = new View.OnClickListener() { |
| 350 | @Override |
| 351 | public void onClick(View v) { |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 352 | onTileClick(r.tile); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 353 | } |
| 354 | }; |
John Spurlock | c247b8f | 2014-11-06 23:06:25 -0500 | [diff] [blame] | 355 | final View.OnLongClickListener longClick = new View.OnLongClickListener() { |
| 356 | @Override |
| 357 | public boolean onLongClick(View v) { |
Jason Monk | 76c67aa | 2016-02-19 14:49:42 -0500 | [diff] [blame] | 358 | r.tile.longClick(); |
| 359 | return true; |
John Spurlock | c247b8f | 2014-11-06 23:06:25 -0500 | [diff] [blame] | 360 | } |
| 361 | }; |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 362 | r.tileView.init(click, longClick); |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 363 | r.tile.refreshState(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 364 | mRecords.add(r); |
| 365 | |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 366 | if (mTileLayout != null) { |
| 367 | mTileLayout.addTile(r); |
| 368 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 369 | } |
| 370 | |
Jason Monk | 2142843 | 2016-02-10 16:42:38 -0500 | [diff] [blame] | 371 | |
| 372 | private void showEdit(final View v) { |
| 373 | v.post(new Runnable() { |
| 374 | @Override |
| 375 | public void run() { |
| 376 | if (mCustomizePanel != null) { |
| 377 | if (!mCustomizePanel.isCustomizing()) { |
| 378 | int[] loc = new int[2]; |
| 379 | v.getLocationInWindow(loc); |
| 380 | int x = loc[0]; |
| 381 | int y = loc[1]; |
| 382 | mCustomizePanel.show(x, y); |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | } |
| 387 | }); |
| 388 | } |
| 389 | |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 390 | protected void onTileClick(QSTile<?> tile) { |
| 391 | tile.click(); |
| 392 | } |
| 393 | |
John Spurlock | f7ae442 | 2014-08-01 12:45:18 -0400 | [diff] [blame] | 394 | public void closeDetail() { |
Yoshinori Hirano | 1dd7d07 | 2016-09-05 16:11:59 +0900 | [diff] [blame^] | 395 | if (mCustomizePanel != null && mCustomizePanel.isShown()) { |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 396 | // Treat this as a detail panel for now, to make things easy. |
Jason Monk | b9c0019 | 2015-10-07 11:45:33 -0400 | [diff] [blame] | 397 | mCustomizePanel.hide(mCustomizePanel.getWidth() / 2, mCustomizePanel.getHeight() / 2); |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 398 | return; |
| 399 | } |
John Spurlock | f7ae442 | 2014-08-01 12:45:18 -0400 | [diff] [blame] | 400 | showDetail(false, mDetailRecord); |
| 401 | } |
| 402 | |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 403 | public int getGridHeight() { |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 404 | return getMeasuredHeight(); |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 405 | } |
| 406 | |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 407 | protected void handleShowDetail(Record r, boolean show) { |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 408 | if (r instanceof TileRecord) { |
| 409 | handleShowDetailTile((TileRecord) r, show); |
| 410 | } else { |
Adrian Roos | 970be53 | 2014-11-21 15:50:16 +0100 | [diff] [blame] | 411 | int x = 0; |
| 412 | int y = 0; |
| 413 | if (r != null) { |
| 414 | x = r.x; |
| 415 | y = r.y; |
| 416 | } |
| 417 | handleShowDetailImpl(r, show, x, y); |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 418 | } |
| 419 | } |
| 420 | |
| 421 | private void handleShowDetailTile(TileRecord r, boolean show) { |
Jason Monk | efe3d3f | 2015-06-10 16:48:03 -0400 | [diff] [blame] | 422 | if ((mDetailRecord != null) == show && mDetailRecord == r) return; |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 423 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 424 | if (show) { |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 425 | r.detailAdapter = r.tile.getDetailAdapter(); |
| 426 | if (r.detailAdapter == null) return; |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 427 | } |
Jason Monk | 0d6a1c4 | 2015-04-20 16:38:51 -0400 | [diff] [blame] | 428 | r.tile.setDetailListening(show); |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 429 | int x = r.tileView.getLeft() + r.tileView.getWidth() / 2; |
Jason Monk | 377e7ad | 2016-02-16 14:03:21 -0500 | [diff] [blame] | 430 | int y = r.tileView.getTop() + mTileLayout.getOffsetTop(r) + r.tileView.getHeight() / 2 |
| 431 | + getTop(); |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 432 | handleShowDetailImpl(r, show, x, y); |
| 433 | } |
| 434 | |
| 435 | private void handleShowDetailImpl(Record r, boolean show, int x, int y) { |
Jason Monk | 377e7ad | 2016-02-16 14:03:21 -0500 | [diff] [blame] | 436 | setDetailRecord(show ? r : null); |
| 437 | fireShowingDetail(show ? r.detailAdapter : null, x, y); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 438 | } |
| 439 | |
Jason Monk | 377e7ad | 2016-02-16 14:03:21 -0500 | [diff] [blame] | 440 | private void setDetailRecord(Record r) { |
| 441 | if (r == mDetailRecord) return; |
| 442 | mDetailRecord = r; |
| 443 | final boolean scanState = mDetailRecord instanceof TileRecord |
| 444 | && ((TileRecord) mDetailRecord).scanState; |
| 445 | fireScanStateChanged(scanState); |
| 446 | } |
| 447 | |
| 448 | void setGridContentVisibility(boolean visible) { |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 449 | int newVis = visible ? VISIBLE : INVISIBLE; |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 450 | setVisibility(newVis); |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 451 | if (mGridContentVisible != visible) { |
Chris Wren | 77781d3 | 2016-01-11 14:49:26 -0500 | [diff] [blame] | 452 | MetricsLogger.visibility(mContext, MetricsEvent.QS_PANEL, newVis); |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 453 | } |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 454 | mGridContentVisible = visible; |
| 455 | } |
| 456 | |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 457 | private void logTiles() { |
| 458 | for (int i = 0; i < mRecords.size(); i++) { |
| 459 | TileRecord tileRecord = mRecords.get(i); |
Jason Monk | ba2318e | 2015-12-08 09:04:23 -0500 | [diff] [blame] | 460 | MetricsLogger.visible(mContext, tileRecord.tile.getMetricsCategory()); |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 461 | } |
| 462 | } |
| 463 | |
Jason Monk | 377e7ad | 2016-02-16 14:03:21 -0500 | [diff] [blame] | 464 | private void fireShowingDetail(DetailAdapter detail, int x, int y) { |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 465 | if (mCallback != null) { |
Jason Monk | 377e7ad | 2016-02-16 14:03:21 -0500 | [diff] [blame] | 466 | mCallback.onShowingDetail(detail, x, y); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 467 | } |
| 468 | } |
| 469 | |
| 470 | private void fireToggleStateChanged(boolean state) { |
| 471 | if (mCallback != null) { |
| 472 | mCallback.onToggleStateChanged(state); |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 473 | } |
| 474 | } |
| 475 | |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 476 | private void fireScanStateChanged(boolean state) { |
| 477 | if (mCallback != null) { |
| 478 | mCallback.onScanStateChanged(state); |
| 479 | } |
| 480 | } |
| 481 | |
Jason Monk | 7e53f20 | 2016-01-28 10:40:20 -0500 | [diff] [blame] | 482 | public void clickTile(ComponentName tile) { |
| 483 | final String spec = CustomTile.toSpec(tile); |
| 484 | final int N = mRecords.size(); |
| 485 | for (int i = 0; i < N; i++) { |
| 486 | if (mRecords.get(i).tile.getTileSpec().equals(spec)) { |
| 487 | mRecords.get(i).tile.click(); |
| 488 | break; |
| 489 | } |
| 490 | } |
| 491 | } |
| 492 | |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 493 | QSTileLayout getTileLayout() { |
| 494 | return mTileLayout; |
| 495 | } |
| 496 | |
| 497 | QSTileBaseView getTileView(QSTile<?> tile) { |
| 498 | for (TileRecord r : mRecords) { |
| 499 | if (r.tile == tile) { |
| 500 | return r.tileView; |
| 501 | } |
| 502 | } |
| 503 | return null; |
| 504 | } |
| 505 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 506 | private class H extends Handler { |
| 507 | private static final int SHOW_DETAIL = 1; |
| 508 | private static final int SET_TILE_VISIBILITY = 2; |
| 509 | @Override |
| 510 | public void handleMessage(Message msg) { |
| 511 | if (msg.what == SHOW_DETAIL) { |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 512 | handleShowDetail((Record)msg.obj, msg.arg1 != 0); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 513 | } |
| 514 | } |
| 515 | } |
| 516 | |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 517 | protected static class Record { |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 518 | DetailAdapter detailAdapter; |
Adrian Roos | 970be53 | 2014-11-21 15:50:16 +0100 | [diff] [blame] | 519 | int x; |
| 520 | int y; |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 521 | } |
| 522 | |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 523 | public static final class TileRecord extends Record { |
Jason Monk | 11a7744 | 2015-05-12 19:29:02 -0400 | [diff] [blame] | 524 | public QSTile<?> tile; |
Jason Monk | c133d26 | 2015-10-27 12:32:45 -0400 | [diff] [blame] | 525 | public QSTileBaseView tileView; |
Jason Monk | 11a7744 | 2015-05-12 19:29:02 -0400 | [diff] [blame] | 526 | public boolean scanState; |
Xiaohui Chen | 6644893 | 2016-04-18 12:53:28 -0700 | [diff] [blame] | 527 | public QSTile.Callback callback; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 528 | } |
| 529 | |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 530 | public interface Callback { |
Jason Monk | 377e7ad | 2016-02-16 14:03:21 -0500 | [diff] [blame] | 531 | void onShowingDetail(DetailAdapter detail, int x, int y); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 532 | void onToggleStateChanged(boolean state); |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 533 | void onScanStateChanged(boolean state); |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 534 | } |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 535 | |
| 536 | public interface QSTileLayout { |
| 537 | void addTile(TileRecord tile); |
| 538 | void removeTile(TileRecord tile); |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 539 | int getOffsetTop(TileRecord tile); |
Jason Monk | 9d02a43 | 2016-01-20 16:33:46 -0500 | [diff] [blame] | 540 | boolean updateResources(); |
Jason Monk | e5107a3 | 2016-05-31 15:40:58 -0400 | [diff] [blame] | 541 | |
| 542 | void setListening(boolean listening); |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 543 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 544 | } |