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