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