blob: cac90257cd4331cc59414a2b02dbbf6275935da3 [file] [log] [blame]
John Spurlockaf8d6c42014-05-07 17:49:08 -04001/*
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
17package com.android.systemui.qs;
18
Jason Monke5b770e2017-03-03 21:49:29 -050019import static com.android.systemui.qs.tileimpl.QSTileImpl.getColorForState;
Fabian Kozynski00d494d2019-04-04 09:53:50 -040020import static com.android.systemui.util.InjectionInflationController.VIEW_CONTEXT;
Matt Pietal5a19cb62019-10-30 12:31:07 -040021import static com.android.systemui.util.Utils.useQsMediaPlayer;
Jason Monke5b770e2017-03-03 21:49:29 -050022
Rohan Shahdb2cfa32018-02-20 11:27:22 -080023import android.annotation.Nullable;
Jason Monk7e53f202016-01-28 10:40:20 -050024import android.content.ComponentName;
John Spurlockaf8d6c42014-05-07 17:49:08 -040025import android.content.Context;
Jorim Jaggie17c4b42014-08-26 17:27:31 +020026import android.content.res.Configuration;
John Spurlock4bf31982014-05-21 13:04:22 -040027import android.content.res.Resources;
Beth Thibodeau07d20c32019-10-16 13:45:56 -040028import android.graphics.drawable.Icon;
29import android.media.session.MediaSession;
Jason Monkcb4b31d2017-05-03 10:37:34 -040030import android.metrics.LogMaker;
Fabian Kozynski407ddb22018-10-03 15:04:56 -040031import android.os.Bundle;
John Spurlockaf8d6c42014-05-07 17:49:08 -040032import android.os.Handler;
33import android.os.Message;
Fabian Kozynski2865ab02019-10-11 15:03:59 -040034import android.provider.Settings;
Beth Thibodeau07d20c32019-10-16 13:45:56 -040035import android.service.notification.StatusBarNotification;
Jason Monke5b770e2017-03-03 21:49:29 -050036import android.service.quicksettings.Tile;
John Spurlockaf8d6c42014-05-07 17:49:08 -040037import android.util.AttributeSet;
Beth Thibodeau07d20c32019-10-16 13:45:56 -040038import android.util.Log;
John Spurlock7f8f22a2014-07-02 18:54:17 -040039import android.view.LayoutInflater;
John Spurlockaf8d6c42014-05-07 17:49:08 -040040import android.view.View;
Beth Thibodeau07d20c32019-10-16 13:45:56 -040041import android.view.ViewGroup;
Fabian Kozynski2865ab02019-10-11 15:03:59 -040042import android.widget.FrameLayout;
Beth Thibodeau07d20c32019-10-16 13:45:56 -040043import android.widget.HorizontalScrollView;
Jason Monk520ea062015-08-18 14:53:06 -040044import android.widget.LinearLayout;
Jason Monkcb4b31d2017-05-03 10:37:34 -040045
Chris Wren457a21c2015-05-06 17:50:34 -040046import com.android.internal.logging.MetricsLogger;
Tamas Berghammer383db5eb2016-06-22 15:21:38 +010047import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Jason Monk824ffff2017-04-11 15:49:06 -040048import com.android.settingslib.Utils;
Jason Monkde850bb2017-02-01 19:26:30 -050049import com.android.systemui.Dependency;
Fabian Kozynski00d494d2019-04-04 09:53:50 -040050import com.android.systemui.DumpController;
51import com.android.systemui.Dumpable;
John Spurlockaf8d6c42014-05-07 17:49:08 -040052import com.android.systemui.R;
Fabian Kozynski5ca7a512019-10-16 19:56:11 +000053import com.android.systemui.broadcast.BroadcastDispatcher;
Jason Monke5b770e2017-03-03 21:49:29 -050054import com.android.systemui.plugins.qs.DetailAdapter;
Jason Monk702e2eb2017-03-03 16:53:44 -050055import com.android.systemui.plugins.qs.QSTile;
56import com.android.systemui.plugins.qs.QSTileView;
57import com.android.systemui.qs.QSHost.Callback;
Jason Monkbd6dbb02015-09-03 15:46:25 -040058import com.android.systemui.qs.customize.QSCustomizer;
Jason Monk7e53f202016-01-28 10:40:20 -050059import com.android.systemui.qs.external.CustomTile;
Jorim Jaggi3f48f462014-07-08 16:53:29 +020060import com.android.systemui.settings.BrightnessController;
Muyuan Li3b0f8922016-04-18 19:27:29 -070061import com.android.systemui.settings.ToggleSliderView;
Fabian Kozynski2865ab02019-10-11 15:03:59 -040062import com.android.systemui.shared.plugins.PluginManager;
63import com.android.systemui.statusbar.phone.NPVPluginManager;
Adrian Roos5fd872e2014-08-12 17:28:58 +020064import com.android.systemui.statusbar.policy.BrightnessMirrorController;
Adrian Roosb01793f2017-08-09 14:34:55 +020065import com.android.systemui.statusbar.policy.BrightnessMirrorController.BrightnessMirrorListener;
Jason Monkcaf37622015-08-18 12:33:50 -040066import com.android.systemui.tuner.TunerService;
67import com.android.systemui.tuner.TunerService.Tunable;
John Spurlockaf8d6c42014-05-07 17:49:08 -040068
Fabian Kozynski00d494d2019-04-04 09:53:50 -040069import java.io.FileDescriptor;
70import java.io.PrintWriter;
John Spurlockaf8d6c42014-05-07 17:49:08 -040071import java.util.ArrayList;
John Spurlockbceed062014-08-10 18:04:16 -040072import java.util.Collection;
John Spurlockaf8d6c42014-05-07 17:49:08 -040073
Fabian Kozynski00d494d2019-04-04 09:53:50 -040074import javax.inject.Inject;
75import javax.inject.Named;
76
Rohan Shahd3cf7562018-02-23 11:12:28 -080077/** View that represents the quick settings tile panel (when expanded/pulled down). **/
Fabian Kozynski00d494d2019-04-04 09:53:50 -040078public class QSPanel extends LinearLayout implements Tunable, Callback, BrightnessMirrorListener,
79 Dumpable {
Jason Monkcaf37622015-08-18 12:33:50 -040080
81 public static final String QS_SHOW_BRIGHTNESS = "qs_show_brightness";
Rohan Shahd3cf7562018-02-23 11:12:28 -080082 public static final String QS_SHOW_HEADER = "qs_show_header";
John Spurlockaf8d6c42014-05-07 17:49:08 -040083
Fabian Kozynski0db39af2018-08-31 15:56:45 -040084 private static final String TAG = "QSPanel";
85
Jason Monkbd6dbb02015-09-03 15:46:25 -040086 protected final Context mContext;
Amin Shaikha07a17b2018-02-23 16:02:52 -050087 protected final ArrayList<TileRecord> mRecords = new ArrayList<>();
Jason Monk11a77442015-05-12 19:29:02 -040088 protected final View mBrightnessView;
John Spurlockaf8d6c42014-05-07 17:49:08 -040089 private final H mHandler = new H();
Jason Monk8c09ac72017-03-16 11:53:40 -040090 private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class);
Amin Shaikha07a17b2018-02-23 16:02:52 -050091 private final QSTileRevealController mQsTileRevealController;
John Spurlockaf8d6c42014-05-07 17:49:08 -040092
Beth Thibodeau07d20c32019-10-16 13:45:56 -040093 private final LinearLayout mMediaCarousel;
94 private final ArrayList<QSMediaPlayer> mMediaPlayers = new ArrayList<>();
95
Muyuan Li0e9f5382016-04-27 15:51:15 -070096 protected boolean mExpanded;
Jason Monk1bec6af2016-05-31 15:40:58 -040097 protected boolean mListening;
John Spurlockaf8d6c42014-05-07 17:49:08 -040098
Jason Monke5b770e2017-03-03 21:49:29 -050099 private QSDetail.Callback mCallback;
Jorim Jaggi3f48f462014-07-08 16:53:29 +0200100 private BrightnessController mBrightnessController;
Fabian Kozynski00d494d2019-04-04 09:53:50 -0400101 private DumpController mDumpController;
Jason Monkbbadff82015-11-06 15:47:26 -0500102 protected QSTileHost mHost;
John Spurlockaf8d6c42014-05-07 17:49:08 -0400103
Jason Monke5b770e2017-03-03 21:49:29 -0500104 protected QSSecurityFooter mFooter;
Rohan Shah3090e792018-04-12 00:01:00 -0400105 private PageIndicator mFooterPageIndicator;
Selim Cineke32010a2014-08-20 23:50:41 +0200106 private boolean mGridContentVisible = true;
Jason Monk3d5f5512014-07-25 11:17:28 -0400107
Jason Monkbd6dbb02015-09-03 15:46:25 -0400108 protected QSTileLayout mTileLayout;
109
110 private QSCustomizer mCustomizePanel;
Jason Monk377e7ad2016-02-16 14:03:21 -0500111 private Record mDetailRecord;
Jason Monk520ea062015-08-18 14:53:06 -0400112
Adrian Roos429c9622016-06-15 13:02:17 -0700113 private BrightnessMirrorController mBrightnessMirrorController;
Jason Monke5b770e2017-03-03 21:49:29 -0500114 private View mDivider;
Adrian Roos429c9622016-06-15 13:02:17 -0700115
Fabian Kozynski2865ab02019-10-11 15:03:59 -0400116 private FrameLayout mPluginFrame;
117 private final PluginManager mPluginManager;
118 private NPVPluginManager mNPVPluginManager;
119
John Spurlockaf8d6c42014-05-07 17:49:08 -0400120 public QSPanel(Context context) {
121 this(context, null);
122 }
123
124 public QSPanel(Context context, AttributeSet attrs) {
Fabian Kozynski00d494d2019-04-04 09:53:50 -0400125 this(context, attrs, null);
126 }
127
Fabian Kozynski2865ab02019-10-11 15:03:59 -0400128 public QSPanel(Context context, AttributeSet attrs, DumpController dumpController) {
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000129 this(context, attrs, dumpController, null, Dependency.get(BroadcastDispatcher.class));
Fabian Kozynski2865ab02019-10-11 15:03:59 -0400130 }
131
Fabian Kozynski00d494d2019-04-04 09:53:50 -0400132 @Inject
133 public QSPanel(@Named(VIEW_CONTEXT) Context context, AttributeSet attrs,
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000134 DumpController dumpController, PluginManager pluginManager,
135 BroadcastDispatcher broadcastDispatcher) {
John Spurlockaf8d6c42014-05-07 17:49:08 -0400136 super(context, attrs);
137 mContext = context;
138
Jason Monk162011e2016-02-19 08:11:55 -0500139 setOrientation(VERTICAL);
Jason Monk520ea062015-08-18 14:53:06 -0400140
Jason Monk231b0522018-01-04 10:49:55 -0500141 mBrightnessView = LayoutInflater.from(mContext).inflate(
142 R.layout.quick_settings_brightness_dialog, this, false);
Amin Shaikh15781d62018-02-16 16:00:13 -0500143 addView(mBrightnessView);
144
145 mTileLayout = (QSTileLayout) LayoutInflater.from(mContext).inflate(
146 R.layout.qs_paged_tile_layout, this, false);
Jason Monk231b0522018-01-04 10:49:55 -0500147 mTileLayout.setListening(mListening);
Amin Shaikh15781d62018-02-16 16:00:13 -0500148 addView((View) mTileLayout);
149
Amin Shaikha07a17b2018-02-23 16:02:52 -0500150 mQsTileRevealController = new QSTileRevealController(mContext, this,
Rohan Shah3090e792018-04-12 00:01:00 -0400151 (PagedTileLayout) mTileLayout);
Jason Monk32508852017-01-18 09:17:13 -0500152
Jason Monke5b770e2017-03-03 21:49:29 -0500153 addDivider();
154
Beth Thibodeau07d20c32019-10-16 13:45:56 -0400155 // Add media carousel
Matt Pietal5a19cb62019-10-30 12:31:07 -0400156 if (useQsMediaPlayer(context)) {
Beth Thibodeau07d20c32019-10-16 13:45:56 -0400157 HorizontalScrollView mediaScrollView = new HorizontalScrollView(mContext);
158 mediaScrollView.setHorizontalScrollBarEnabled(false);
159 int playerHeight = (int) getResources().getDimension(R.dimen.qs_media_height);
160 int padding = (int) getResources().getDimension(R.dimen.qs_media_padding);
161 LayoutParams lpView = new LayoutParams(LayoutParams.MATCH_PARENT, playerHeight);
162 lpView.setMarginStart(padding);
163 lpView.setMarginEnd(padding);
164 addView(mediaScrollView, lpView);
165
166 LayoutParams lpCarousel = new LayoutParams(LayoutParams.MATCH_PARENT,
167 LayoutParams.WRAP_CONTENT);
168 mMediaCarousel = new LinearLayout(mContext);
169 mMediaCarousel.setOrientation(LinearLayout.HORIZONTAL);
170 mediaScrollView.addView(mMediaCarousel, lpCarousel);
Beth Thibodeau4e69f4c2019-10-24 14:13:49 -0400171 mediaScrollView.setVisibility(View.GONE);
Beth Thibodeau07d20c32019-10-16 13:45:56 -0400172 } else {
173 mMediaCarousel = null;
174 }
175
phweiss4f70f102017-04-12 19:32:55 +0200176 mFooter = new QSSecurityFooter(this, context);
177 addView(mFooter.getView());
178
John Spurlockaf8d6c42014-05-07 17:49:08 -0400179 updateResources();
Jorim Jaggi3f48f462014-07-08 16:53:29 +0200180
181 mBrightnessController = new BrightnessController(getContext(),
Fabian Kozynski5ca7a512019-10-16 19:56:11 +0000182 findViewById(R.id.brightness_slider), broadcastDispatcher);
Fabian Kozynski00d494d2019-04-04 09:53:50 -0400183 mDumpController = dumpController;
Fabian Kozynski2865ab02019-10-11 15:03:59 -0400184 mPluginManager = pluginManager;
185 if (mPluginManager != null && Settings.System.getInt(
186 mContext.getContentResolver(), "npv_plugin_flag", 0) == 2) {
187 mPluginFrame = (FrameLayout) LayoutInflater.from(mContext).inflate(
188 R.layout.status_bar_expanded_plugin_frame, this, false);
189 addView(mPluginFrame);
190 mNPVPluginManager = new NPVPluginManager(mPluginFrame, mPluginManager);
191 }
192
Jason Monke5b770e2017-03-03 21:49:29 -0500193 }
194
Beth Thibodeau07d20c32019-10-16 13:45:56 -0400195 /**
196 * Add or update a player for the associated media session
197 * @param token
198 * @param icon
199 * @param iconColor
200 * @param bgColor
201 * @param actionsContainer
202 * @param notif
203 */
204 public void addMediaSession(MediaSession.Token token, Icon icon, int iconColor, int bgColor,
205 View actionsContainer, StatusBarNotification notif) {
Matt Pietal5a19cb62019-10-30 12:31:07 -0400206 if (!useQsMediaPlayer(mContext)) {
Beth Thibodeau07d20c32019-10-16 13:45:56 -0400207 // Shouldn't happen, but just in case
208 Log.e(TAG, "Tried to add media session without player!");
209 return;
210 }
211 QSMediaPlayer player = null;
212 String packageName = notif.getPackageName();
213 for (QSMediaPlayer p : mMediaPlayers) {
214 if (p.getMediaSessionToken().equals(token)) {
215 Log.d(TAG, "a player for this session already exists");
216 player = p;
217 break;
218 }
219
220 if (packageName.equals(p.getMediaPlayerPackage())) {
221 Log.d(TAG, "found an old session for this app");
222 player = p;
223 break;
224 }
225 }
226
227 int playerHeight = (int) getResources().getDimension(R.dimen.qs_media_height);
228 int playerWidth = (int) getResources().getDimension(R.dimen.qs_media_width);
229 int padding = (int) getResources().getDimension(R.dimen.qs_media_padding);
230 LayoutParams lp = new LayoutParams(playerWidth, ViewGroup.LayoutParams.MATCH_PARENT);
231 lp.setMarginStart(padding);
232 lp.setMarginEnd(padding);
233
234 if (player == null) {
235 Log.d(TAG, "creating new player");
236
237 player = new QSMediaPlayer(mContext, this, playerWidth, playerHeight);
238
239 if (player.isPlaying()) {
240 mMediaCarousel.addView(player.getView(), 0, lp); // add in front
241 } else {
242 mMediaCarousel.addView(player.getView(), lp); // add at end
243 }
Beth Thibodeau4e69f4c2019-10-24 14:13:49 -0400244 mMediaPlayers.add(player);
Beth Thibodeau07d20c32019-10-16 13:45:56 -0400245 } else if (player.isPlaying()) {
246 // move it to the front
247 mMediaCarousel.removeView(player.getView());
248 mMediaCarousel.addView(player.getView(), 0, lp);
249 }
250
251 Log.d(TAG, "setting player session");
252 player.setMediaSession(token, icon, iconColor, bgColor, actionsContainer,
253 notif.getNotification());
Beth Thibodeau4e69f4c2019-10-24 14:13:49 -0400254
255 if (mMediaPlayers.size() > 0) {
256 ((View) mMediaCarousel.getParent()).setVisibility(View.VISIBLE);
257 }
Beth Thibodeau07d20c32019-10-16 13:45:56 -0400258 }
259
260 protected View getMediaPanel() {
261 return mMediaCarousel;
262 }
263
Jason Monke5b770e2017-03-03 21:49:29 -0500264 protected void addDivider() {
265 mDivider = LayoutInflater.from(mContext).inflate(R.layout.qs_divider, this, false);
Jason Monk824ffff2017-04-11 15:49:06 -0400266 mDivider.setBackgroundColor(Utils.applyAlpha(mDivider.getAlpha(),
267 getColorForState(mContext, Tile.STATE_ACTIVE)));
Jason Monke5b770e2017-03-03 21:49:29 -0500268 addView(mDivider);
269 }
270
Fabian Kozynski72cd84a92019-04-15 14:09:43 -0400271 @Override
272 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
273 // We want all the logic of LinearLayout#onMeasure, and for it to assign the excess space
274 // not used by the other children to PagedTileLayout. However, in this case, LinearLayout
275 // assumes that PagedTileLayout would use all the excess space. This is not the case as
276 // PagedTileLayout height is quantized (because it shows a certain number of rows).
277 // Therefore, after everything is measured, we need to make sure that we add up the correct
278 // total height
279 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
280 int height = getPaddingBottom() + getPaddingTop();
281 int numChildren = getChildCount();
282 for (int i = 0; i < numChildren; i++) {
283 View child = getChildAt(i);
284 if (child.getVisibility() != View.GONE) height += child.getMeasuredHeight();
285 }
286 setMeasuredDimension(getMeasuredWidth(), height);
287 }
288
Jason Monke5b770e2017-03-03 21:49:29 -0500289 public View getDivider() {
290 return mDivider;
Jason Monk32508852017-01-18 09:17:13 -0500291 }
Adrian Roos1ef80fe2014-07-14 22:53:54 +0200292
Amin Shaikha07a17b2018-02-23 16:02:52 -0500293 public QSTileRevealController getQsTileRevealController() {
294 return mQsTileRevealController;
295 }
296
Jason Monk377e7ad2016-02-16 14:03:21 -0500297 public boolean isShowingCustomize() {
298 return mCustomizePanel != null && mCustomizePanel.isCustomizing();
John Spurlockaf8d6c42014-05-07 17:49:08 -0400299 }
300
Jason Monkcaf37622015-08-18 12:33:50 -0400301 @Override
302 protected void onAttachedToWindow() {
303 super.onAttachedToWindow();
Rohan Shahdb2cfa32018-02-20 11:27:22 -0800304 final TunerService tunerService = Dependency.get(TunerService.class);
305 tunerService.addTunable(this, QS_SHOW_BRIGHTNESS);
Rohan Shahdb2cfa32018-02-20 11:27:22 -0800306
Jason Monkf160edca2016-03-30 13:48:56 -0400307 if (mHost != null) {
308 setTiles(mHost.getTiles());
309 }
Adrian Roosb01793f2017-08-09 14:34:55 +0200310 if (mBrightnessMirrorController != null) {
311 mBrightnessMirrorController.addCallback(this);
312 }
Ned Burns66b6e372019-07-26 13:45:42 -0400313 if (mDumpController != null) mDumpController.registerDumpable(getDumpableTag(), this);
Jason Monkcaf37622015-08-18 12:33:50 -0400314 }
315
316 @Override
317 protected void onDetachedFromWindow() {
Jason Monkde850bb2017-02-01 19:26:30 -0500318 Dependency.get(TunerService.class).removeTunable(this);
319 if (mHost != null) {
320 mHost.removeCallback(this);
321 }
Jason Monkf160edca2016-03-30 13:48:56 -0400322 for (TileRecord record : mRecords) {
323 record.tile.removeCallbacks();
324 }
Adrian Roosb01793f2017-08-09 14:34:55 +0200325 if (mBrightnessMirrorController != null) {
326 mBrightnessMirrorController.removeCallback(this);
327 }
Ned Burns66b6e372019-07-26 13:45:42 -0400328 if (mDumpController != null) mDumpController.unregisterDumpable(this);
Jason Monkcaf37622015-08-18 12:33:50 -0400329 super.onDetachedFromWindow();
330 }
331
Ned Burns66b6e372019-07-26 13:45:42 -0400332 protected String getDumpableTag() {
333 return TAG;
334 }
335
Jason Monkcaf37622015-08-18 12:33:50 -0400336 @Override
Jason Monk46dbfb42016-02-25 14:59:20 -0500337 public void onTilesChanged() {
338 setTiles(mHost.getTiles());
339 }
340
341 @Override
Jason Monkcaf37622015-08-18 12:33:50 -0400342 public void onTuningChanged(String key, String newValue) {
343 if (QS_SHOW_BRIGHTNESS.equals(key)) {
Rohan Shahdb2cfa32018-02-20 11:27:22 -0800344 updateViewVisibilityForTuningValue(mBrightnessView, newValue);
Jason Monkcaf37622015-08-18 12:33:50 -0400345 }
346 }
347
Rohan Shahdb2cfa32018-02-20 11:27:22 -0800348 private void updateViewVisibilityForTuningValue(View view, @Nullable String newValue) {
Henrik Baarda2c86e82019-03-14 12:23:04 +0100349 view.setVisibility(TunerService.parseIntegerSwitch(newValue, true) ? VISIBLE : GONE);
Rohan Shahdb2cfa32018-02-20 11:27:22 -0800350 }
351
Jason Monka9927322015-12-13 16:22:37 -0500352 public void openDetails(String subPanel) {
Jason Monk702e2eb2017-03-03 16:53:44 -0500353 QSTile tile = getTile(subPanel);
Fabian Kozynskie3137e32018-09-28 11:20:04 -0400354 // If there's no tile with that name (as defined in QSFactoryImpl or other QSFactory),
355 // QSFactory will not be able to create a tile and getTile will return null
356 if (tile != null) {
357 showDetailAdapter(true, tile.getDetailAdapter(), new int[]{getWidth() / 2, 0});
358 }
Jason Monka9927322015-12-13 16:22:37 -0500359 }
360
Jason Monk702e2eb2017-03-03 16:53:44 -0500361 private QSTile getTile(String subPanel) {
Jason Monka9927322015-12-13 16:22:37 -0500362 for (int i = 0; i < mRecords.size(); i++) {
363 if (subPanel.equals(mRecords.get(i).tile.getTileSpec())) {
364 return mRecords.get(i).tile;
365 }
366 }
367 return mHost.createTile(subPanel);
368 }
369
Adrian Roos5fd872e2014-08-12 17:28:58 +0200370 public void setBrightnessMirror(BrightnessMirrorController c) {
Adrian Roosb01793f2017-08-09 14:34:55 +0200371 if (mBrightnessMirrorController != null) {
372 mBrightnessMirrorController.removeCallback(this);
373 }
Adrian Roos429c9622016-06-15 13:02:17 -0700374 mBrightnessMirrorController = c;
Adrian Roosb01793f2017-08-09 14:34:55 +0200375 if (mBrightnessMirrorController != null) {
376 mBrightnessMirrorController.addCallback(this);
377 }
378 updateBrightnessMirror();
379 }
380
381 @Override
382 public void onBrightnessMirrorReinflated(View brightnessMirror) {
383 updateBrightnessMirror();
Adrian Roos5fd872e2014-08-12 17:28:58 +0200384 }
385
Jason Monkb46059a2016-06-30 14:22:42 -0400386 View getBrightnessView() {
387 return mBrightnessView;
388 }
389
Jason Monke5b770e2017-03-03 21:49:29 -0500390 public void setCallback(QSDetail.Callback callback) {
John Spurlock5729d092014-05-29 17:42:51 -0400391 mCallback = callback;
392 }
393
Jason Monk8b9d67f2016-03-02 08:59:08 -0500394 public void setHost(QSTileHost host, QSCustomizer customizer) {
Adrian Roos1ef80fe2014-07-14 22:53:54 +0200395 mHost = host;
Jason Monk46dbfb42016-02-25 14:59:20 -0500396 mHost.addCallback(this);
397 setTiles(mHost.getTiles());
Jason Monk9c7844c2017-01-18 15:21:53 -0500398 mFooter.setHostEnvironment(host);
Jason Monk8b9d67f2016-03-02 08:59:08 -0500399 mCustomizePanel = customizer;
400 if (mCustomizePanel != null) {
401 mCustomizePanel.setHost(mHost);
402 }
Adrian Roos1ef80fe2014-07-14 22:53:54 +0200403 }
404
Rohan Shah3090e792018-04-12 00:01:00 -0400405 /**
406 * Links the footer's page indicator, which is used in landscape orientation to save space.
407 *
408 * @param pageIndicator indicator to use for page scrolling
409 */
410 public void setFooterPageIndicator(PageIndicator pageIndicator) {
411 if (mTileLayout instanceof PagedTileLayout) {
412 mFooterPageIndicator = pageIndicator;
413 updatePageIndicator();
414 }
415 }
416
417 private void updatePageIndicator() {
418 if (mTileLayout instanceof PagedTileLayout) {
Rohan Shah3090e792018-04-12 00:01:00 -0400419 if (mFooterPageIndicator != null) {
420 mFooterPageIndicator.setVisibility(View.GONE);
Rohan Shah3090e792018-04-12 00:01:00 -0400421
Fabian Kozynski4e76d1f2019-02-25 16:30:04 -0500422 ((PagedTileLayout) mTileLayout).setPageIndicator(mFooterPageIndicator);
423 }
Rohan Shah3090e792018-04-12 00:01:00 -0400424 }
425 }
426
Adrian Roos00a0b1f2014-07-16 16:44:49 +0200427 public QSTileHost getHost() {
428 return mHost;
429 }
Adrian Roos1ef80fe2014-07-14 22:53:54 +0200430
John Spurlockaf8d6c42014-05-07 17:49:08 -0400431 public void updateResources() {
John Spurlock4bf31982014-05-21 13:04:22 -0400432 final Resources res = mContext.getResources();
Rohan Shahd3cf7562018-02-23 11:12:28 -0800433 setPadding(0, res.getDimensionPixelSize(R.dimen.qs_panel_padding_top), 0, res.getDimensionPixelSize(R.dimen.qs_panel_padding_bottom));
Rohan Shah3090e792018-04-12 00:01:00 -0400434
435 updatePageIndicator();
436
John Spurlock1a462c12014-07-14 10:52:01 -0400437 if (mListening) {
438 refreshAllTiles();
439 }
Jason Monkcaf37622015-08-18 12:33:50 -0400440 if (mTileLayout != null) {
441 mTileLayout.updateResources();
442 }
John Spurlockaf8d6c42014-05-07 17:49:08 -0400443 }
444
Jorim Jaggie17c4b42014-08-26 17:27:31 +0200445 @Override
446 protected void onConfigurationChanged(Configuration newConfig) {
447 super.onConfigurationChanged(newConfig);
Jorim Jaggie17c4b42014-08-26 17:27:31 +0200448 mFooter.onConfigurationChanged();
Fabian Kozynskib1aee812019-04-04 14:17:48 -0400449 updateResources();
Adrian Roos429c9622016-06-15 13:02:17 -0700450
Adrian Roosb01793f2017-08-09 14:34:55 +0200451 updateBrightnessMirror();
452 }
453
454 public void updateBrightnessMirror() {
Adrian Roos429c9622016-06-15 13:02:17 -0700455 if (mBrightnessMirrorController != null) {
Adrian Roosb01793f2017-08-09 14:34:55 +0200456 ToggleSliderView brightnessSlider = findViewById(R.id.brightness_slider);
457 ToggleSliderView mirrorSlider = mBrightnessMirrorController.getMirror()
458 .findViewById(R.id.brightness_slider);
459 brightnessSlider.setMirror(mirrorSlider);
460 brightnessSlider.setMirrorController(mBrightnessMirrorController);
Adrian Roos429c9622016-06-15 13:02:17 -0700461 }
Jorim Jaggie17c4b42014-08-26 17:27:31 +0200462 }
463
Jason Monkbd6dbb02015-09-03 15:46:25 -0400464 public void onCollapse() {
Yoshinori Hirano1dd7d072016-09-05 16:11:59 +0900465 if (mCustomizePanel != null && mCustomizePanel.isShown()) {
Fabian Kozynski0db39af2018-08-31 15:56:45 -0400466 mCustomizePanel.hide();
Jason Monkbd6dbb02015-09-03 15:46:25 -0400467 }
468 }
469
John Spurlockaf8d6c42014-05-07 17:49:08 -0400470 public void setExpanded(boolean expanded) {
John Spurlock5729d092014-05-29 17:42:51 -0400471 if (mExpanded == expanded) return;
472 mExpanded = expanded;
Amin Shaikh15781d62018-02-16 16:00:13 -0500473 if (!mExpanded && mTileLayout instanceof PagedTileLayout) {
474 ((PagedTileLayout) mTileLayout).setCurrentItem(0, false);
Jason Monk162011e2016-02-19 08:11:55 -0500475 }
Jason Monk8c09ac72017-03-16 11:53:40 -0400476 mMetricsLogger.visibility(MetricsEvent.QS_PANEL, mExpanded);
John Spurlock5729d092014-05-29 17:42:51 -0400477 if (!mExpanded) {
John Spurlockf7ae4422014-08-01 12:45:18 -0400478 closeDetail();
Chris Wren457a21c2015-05-06 17:50:34 -0400479 } else {
480 logTiles();
John Spurlockaf8d6c42014-05-07 17:49:08 -0400481 }
Jorim Jaggie65e3102014-07-01 22:00:50 +0200482 }
483
Amin Shaikh5da602f2018-02-02 15:00:25 -0500484 public void setPageListener(final PagedTileLayout.PageListener pageListener) {
485 if (mTileLayout instanceof PagedTileLayout) {
486 ((PagedTileLayout) mTileLayout).setPageListener(pageListener);
Amin Shaikh5da602f2018-02-02 15:00:25 -0500487 }
488 }
489
Muyuan Li0e9f5382016-04-27 15:51:15 -0700490 public boolean isExpanded() {
491 return mExpanded;
492 }
493
Jorim Jaggie65e3102014-07-01 22:00:50 +0200494 public void setListening(boolean listening) {
495 if (mListening == listening) return;
496 mListening = listening;
Jason Monk1bec6af2016-05-31 15:40:58 -0400497 if (mTileLayout != null) {
498 mTileLayout.setListening(listening);
John Spurlock1a462c12014-07-14 10:52:01 -0400499 }
500 if (mListening) {
501 refreshAllTiles();
John Spurlockaf8d6c42014-05-07 17:49:08 -0400502 }
Fabian Kozynski2865ab02019-10-11 15:03:59 -0400503 if (mNPVPluginManager != null) mNPVPluginManager.setListening(listening);
Fabian Kozynskib9dc0c72018-09-20 13:00:17 -0400504 }
505
506 public void setListening(boolean listening, boolean expanded) {
507 setListening(listening && expanded);
508 getFooter().setListening(listening);
509 // Set the listening as soon as the QS fragment starts listening regardless of the expansion,
510 // so it will update the current brightness before the slider is visible.
511 setBrightnessListening(listening);
512 }
513
514 public void setBrightnessListening(boolean listening) {
515 if (listening) {
516 mBrightnessController.registerCallbacks();
517 } else {
518 mBrightnessController.unregisterCallbacks();
Jorim Jaggi3f48f462014-07-08 16:53:29 +0200519 }
John Spurlockaf8d6c42014-05-07 17:49:08 -0400520 }
521
Jorim Jaggi1ecd7cd2014-11-03 16:18:03 +0100522 public void refreshAllTiles() {
yuemingweb2bf7d182018-01-23 16:05:08 +0000523 mBrightnessController.checkRestrictionAndSetEnabled();
John Spurlock1a462c12014-07-14 10:52:01 -0400524 for (TileRecord r : mRecords) {
525 r.tile.refreshState();
526 }
Jason Monk3d5f5512014-07-25 11:17:28 -0400527 mFooter.refreshState();
John Spurlock1a462c12014-07-14 10:52:01 -0400528 }
529
Adrian Roos970be532014-11-21 15:50:16 +0100530 public void showDetailAdapter(boolean show, DetailAdapter adapter, int[] locationInWindow) {
531 int xInWindow = locationInWindow[0];
532 int yInWindow = locationInWindow[1];
Jason Monk377e7ad2016-02-16 14:03:21 -0500533 ((View) getParent()).getLocationInWindow(locationInWindow);
Adrian Roos970be532014-11-21 15:50:16 +0100534
Adrian Roos1ef80fe2014-07-14 22:53:54 +0200535 Record r = new Record();
536 r.detailAdapter = adapter;
Adrian Roos970be532014-11-21 15:50:16 +0100537 r.x = xInWindow - locationInWindow[0];
538 r.y = yInWindow - locationInWindow[1];
539
540 locationInWindow[0] = xInWindow;
541 locationInWindow[1] = yInWindow;
542
Adrian Roos1ef80fe2014-07-14 22:53:54 +0200543 showDetail(show, r);
544 }
545
Jason Monkdc35dcb2015-12-04 16:36:15 -0500546 protected void showDetail(boolean show, Record r) {
John Spurlockaf8d6c42014-05-07 17:49:08 -0400547 mHandler.obtainMessage(H.SHOW_DETAIL, show ? 1 : 0, 0, r).sendToTarget();
548 }
549
Jason Monk702e2eb2017-03-03 16:53:44 -0500550 public void setTiles(Collection<QSTile> tiles) {
Julia Reynolds20aef8a2016-05-04 16:44:08 -0400551 setTiles(tiles, false);
552 }
553
Jason Monk702e2eb2017-03-03 16:53:44 -0500554 public void setTiles(Collection<QSTile> tiles, boolean collapsedView) {
Amin Shaikha07a17b2018-02-23 16:02:52 -0500555 if (!collapsedView) {
556 mQsTileRevealController.updateRevealedTiles(tiles);
557 }
John Spurlockbceed062014-08-10 18:04:16 -0400558 for (TileRecord record : mRecords) {
Jason Monkcaf37622015-08-18 12:33:50 -0400559 mTileLayout.removeTile(record);
Xiaohui Chen08e266c2016-04-18 12:53:28 -0700560 record.tile.removeCallback(record.callback);
John Spurlockbceed062014-08-10 18:04:16 -0400561 }
562 mRecords.clear();
Jason Monk702e2eb2017-03-03 16:53:44 -0500563 for (QSTile tile : tiles) {
Julia Reynolds20aef8a2016-05-04 16:44:08 -0400564 addTile(tile, collapsedView);
John Spurlockbceed062014-08-10 18:04:16 -0400565 }
John Spurlockbceed062014-08-10 18:04:16 -0400566 }
567
Jason Monkec87a872016-03-01 15:00:16 -0500568 protected void drawTile(TileRecord r, QSTile.State state) {
John Spurlock20c89052015-05-11 13:11:24 -0400569 r.tileView.onStateChanged(state);
570 }
571
Jason Monk702e2eb2017-03-03 16:53:44 -0500572 protected QSTileView createTileView(QSTile tile, boolean collapsedView) {
573 return mHost.createTileView(tile, collapsedView);
Jason Monkdc35dcb2015-12-04 16:36:15 -0500574 }
575
Xiaohui Chen66448932016-04-18 12:53:28 -0700576 protected boolean shouldShowDetail() {
577 return mExpanded;
578 }
579
Jason Monk702e2eb2017-03-03 16:53:44 -0500580 protected TileRecord addTile(final QSTile tile, boolean collapsedView) {
John Spurlockaf8d6c42014-05-07 17:49:08 -0400581 final TileRecord r = new TileRecord();
582 r.tile = tile;
Julia Reynolds20aef8a2016-05-04 16:44:08 -0400583 r.tileView = createTileView(tile, collapsedView);
John Spurlockbceed062014-08-10 18:04:16 -0400584 final QSTile.Callback callback = new QSTile.Callback() {
John Spurlockaf8d6c42014-05-07 17:49:08 -0400585 @Override
586 public void onStateChanged(QSTile.State state) {
Jason Monk377e7ad2016-02-16 14:03:21 -0500587 drawTile(r, state);
John Spurlockaf8d6c42014-05-07 17:49:08 -0400588 }
Jason Monkca894a02016-01-12 15:30:22 -0500589
John Spurlockaf8d6c42014-05-07 17:49:08 -0400590 @Override
591 public void onShowDetail(boolean show) {
Xiaohui Chen66448932016-04-18 12:53:28 -0700592 // Both the collapsed and full QS panels get this callback, this check determines
593 // which one should handle showing the detail.
594 if (shouldShowDetail()) {
595 QSPanel.this.showDetail(show, r);
596 }
John Spurlockaf8d6c42014-05-07 17:49:08 -0400597 }
Jason Monkca894a02016-01-12 15:30:22 -0500598
John Spurlock7f8f22a2014-07-02 18:54:17 -0400599 @Override
600 public void onToggleStateChanged(boolean state) {
601 if (mDetailRecord == r) {
602 fireToggleStateChanged(state);
603 }
604 }
Jason Monkca894a02016-01-12 15:30:22 -0500605
John Spurlock486b78e2014-07-07 08:37:56 -0400606 @Override
607 public void onScanStateChanged(boolean state) {
John Spurlock465cefa2014-08-16 10:39:33 -0400608 r.scanState = state;
John Spurlock486b78e2014-07-07 08:37:56 -0400609 if (mDetailRecord == r) {
John Spurlock465cefa2014-08-16 10:39:33 -0400610 fireScanStateChanged(r.scanState);
John Spurlock486b78e2014-07-07 08:37:56 -0400611 }
612 }
Selim Cinek4fda7b22014-08-18 22:07:25 +0200613
614 @Override
615 public void onAnnouncementRequested(CharSequence announcement) {
dooyoung.hwang1b006622016-12-22 20:04:20 +0900616 if (announcement != null) {
617 mHandler.obtainMessage(H.ANNOUNCE_FOR_ACCESSIBILITY, announcement)
618 .sendToTarget();
619 }
Selim Cinek4fda7b22014-08-18 22:07:25 +0200620 }
John Spurlockbceed062014-08-10 18:04:16 -0400621 };
Jason Monkca894a02016-01-12 15:30:22 -0500622 r.tile.addCallback(callback);
Xiaohui Chen08e266c2016-04-18 12:53:28 -0700623 r.callback = callback;
Jason Monk702e2eb2017-03-03 16:53:44 -0500624 r.tileView.init(r.tile);
John Spurlockccb6b9a2014-05-17 15:54:40 -0400625 r.tile.refreshState();
John Spurlockaf8d6c42014-05-07 17:49:08 -0400626 mRecords.add(r);
627
Jason Monkcaf37622015-08-18 12:33:50 -0400628 if (mTileLayout != null) {
629 mTileLayout.addTile(r);
630 }
Muyuan Lib40004b2016-05-11 14:47:29 -0700631
632 return r;
John Spurlockaf8d6c42014-05-07 17:49:08 -0400633 }
634
Jason Monk21428432016-02-10 16:42:38 -0500635
Jason Monk4bb7b1a2016-05-27 15:19:15 -0400636 public void showEdit(final View v) {
Jason Monk21428432016-02-10 16:42:38 -0500637 v.post(new Runnable() {
638 @Override
639 public void run() {
640 if (mCustomizePanel != null) {
641 if (!mCustomizePanel.isCustomizing()) {
Fabian Kozynski0db39af2018-08-31 15:56:45 -0400642 int[] loc = v.getLocationOnScreen();
Jason Monk4bb7b1a2016-05-27 15:19:15 -0400643 int x = loc[0] + v.getWidth() / 2;
644 int y = loc[1] + v.getHeight() / 2;
Jason Monk21428432016-02-10 16:42:38 -0500645 mCustomizePanel.show(x, y);
646 }
647 }
648
649 }
650 });
651 }
652
John Spurlockf7ae4422014-08-01 12:45:18 -0400653 public void closeDetail() {
Yoshinori Hirano1dd7d072016-09-05 16:11:59 +0900654 if (mCustomizePanel != null && mCustomizePanel.isShown()) {
Jason Monkbd6dbb02015-09-03 15:46:25 -0400655 // Treat this as a detail panel for now, to make things easy.
Fabian Kozynski0db39af2018-08-31 15:56:45 -0400656 mCustomizePanel.hide();
Jason Monkbd6dbb02015-09-03 15:46:25 -0400657 return;
658 }
John Spurlockf7ae4422014-08-01 12:45:18 -0400659 showDetail(false, mDetailRecord);
660 }
661
Jorim Jaggi8bc983e2014-12-10 17:45:50 +0100662 public int getGridHeight() {
Jason Monk162011e2016-02-19 08:11:55 -0500663 return getMeasuredHeight();
Jorim Jaggi8bc983e2014-12-10 17:45:50 +0100664 }
665
Jason Monkdc35dcb2015-12-04 16:36:15 -0500666 protected void handleShowDetail(Record r, boolean show) {
Adrian Roos1ef80fe2014-07-14 22:53:54 +0200667 if (r instanceof TileRecord) {
668 handleShowDetailTile((TileRecord) r, show);
669 } else {
Adrian Roos970be532014-11-21 15:50:16 +0100670 int x = 0;
671 int y = 0;
672 if (r != null) {
673 x = r.x;
674 y = r.y;
675 }
676 handleShowDetailImpl(r, show, x, y);
Adrian Roos1ef80fe2014-07-14 22:53:54 +0200677 }
678 }
679
680 private void handleShowDetailTile(TileRecord r, boolean show) {
Jason Monkefe3d3f2015-06-10 16:48:03 -0400681 if ((mDetailRecord != null) == show && mDetailRecord == r) return;
Adrian Roos1ef80fe2014-07-14 22:53:54 +0200682
John Spurlockaf8d6c42014-05-07 17:49:08 -0400683 if (show) {
John Spurlock7f8f22a2014-07-02 18:54:17 -0400684 r.detailAdapter = r.tile.getDetailAdapter();
685 if (r.detailAdapter == null) return;
Adrian Roos1ef80fe2014-07-14 22:53:54 +0200686 }
Jason Monk0d6a1c42015-04-20 16:38:51 -0400687 r.tile.setDetailListening(show);
Adrian Roos1ef80fe2014-07-14 22:53:54 +0200688 int x = r.tileView.getLeft() + r.tileView.getWidth() / 2;
Jason Monk702e2eb2017-03-03 16:53:44 -0500689 int y = r.tileView.getDetailY() + mTileLayout.getOffsetTop(r) + getTop();
Adrian Roos1ef80fe2014-07-14 22:53:54 +0200690 handleShowDetailImpl(r, show, x, y);
691 }
692
693 private void handleShowDetailImpl(Record r, boolean show, int x, int y) {
Jason Monk377e7ad2016-02-16 14:03:21 -0500694 setDetailRecord(show ? r : null);
695 fireShowingDetail(show ? r.detailAdapter : null, x, y);
John Spurlockaf8d6c42014-05-07 17:49:08 -0400696 }
697
Muyuan Li4074b462016-05-06 13:40:42 -0700698 protected void setDetailRecord(Record r) {
Jason Monk377e7ad2016-02-16 14:03:21 -0500699 if (r == mDetailRecord) return;
700 mDetailRecord = r;
701 final boolean scanState = mDetailRecord instanceof TileRecord
702 && ((TileRecord) mDetailRecord).scanState;
703 fireScanStateChanged(scanState);
704 }
705
706 void setGridContentVisibility(boolean visible) {
Selim Cineke32010a2014-08-20 23:50:41 +0200707 int newVis = visible ? VISIBLE : INVISIBLE;
Jason Monk162011e2016-02-19 08:11:55 -0500708 setVisibility(newVis);
Chris Wren457a21c2015-05-06 17:50:34 -0400709 if (mGridContentVisible != visible) {
Jason Monk8c09ac72017-03-16 11:53:40 -0400710 mMetricsLogger.visibility(MetricsEvent.QS_PANEL, newVis);
Chris Wren457a21c2015-05-06 17:50:34 -0400711 }
Selim Cineke32010a2014-08-20 23:50:41 +0200712 mGridContentVisible = visible;
713 }
714
Chris Wren457a21c2015-05-06 17:50:34 -0400715 private void logTiles() {
716 for (int i = 0; i < mRecords.size(); i++) {
Jason Monkcb4b31d2017-05-03 10:37:34 -0400717 QSTile tile = mRecords.get(i).tile;
718 mMetricsLogger.write(tile.populate(new LogMaker(tile.getMetricsCategory())
719 .setType(MetricsEvent.TYPE_OPEN)));
Chris Wren457a21c2015-05-06 17:50:34 -0400720 }
721 }
722
Jason Monk377e7ad2016-02-16 14:03:21 -0500723 private void fireShowingDetail(DetailAdapter detail, int x, int y) {
John Spurlock5729d092014-05-29 17:42:51 -0400724 if (mCallback != null) {
Jason Monk377e7ad2016-02-16 14:03:21 -0500725 mCallback.onShowingDetail(detail, x, y);
John Spurlock7f8f22a2014-07-02 18:54:17 -0400726 }
727 }
728
729 private void fireToggleStateChanged(boolean state) {
730 if (mCallback != null) {
731 mCallback.onToggleStateChanged(state);
John Spurlock5729d092014-05-29 17:42:51 -0400732 }
733 }
734
John Spurlock486b78e2014-07-07 08:37:56 -0400735 private void fireScanStateChanged(boolean state) {
736 if (mCallback != null) {
737 mCallback.onScanStateChanged(state);
738 }
739 }
740
Jason Monk7e53f202016-01-28 10:40:20 -0500741 public void clickTile(ComponentName tile) {
742 final String spec = CustomTile.toSpec(tile);
743 final int N = mRecords.size();
744 for (int i = 0; i < N; i++) {
745 if (mRecords.get(i).tile.getTileSpec().equals(spec)) {
746 mRecords.get(i).tile.click();
747 break;
748 }
749 }
750 }
751
Jason Monk162011e2016-02-19 08:11:55 -0500752 QSTileLayout getTileLayout() {
753 return mTileLayout;
754 }
755
Jason Monk702e2eb2017-03-03 16:53:44 -0500756 QSTileView getTileView(QSTile tile) {
Jason Monk162011e2016-02-19 08:11:55 -0500757 for (TileRecord r : mRecords) {
758 if (r.tile == tile) {
759 return r.tileView;
760 }
761 }
762 return null;
763 }
764
Jason Monke5b770e2017-03-03 21:49:29 -0500765 public QSSecurityFooter getFooter() {
Jason Monkdf36aed2016-07-25 11:21:56 -0400766 return mFooter;
767 }
768
phweissa0cb2512016-12-14 21:37:48 +0100769 public void showDeviceMonitoringDialog() {
770 mFooter.showDeviceMonitoringDialog();
771 }
772
Amin Shaikhbc1a4e82018-04-16 12:14:35 -0400773 public void setMargins(int sideMargins) {
774 for (int i = 0; i < getChildCount(); i++) {
775 View view = getChildAt(i);
776 if (view != mTileLayout) {
777 LayoutParams lp = (LayoutParams) view.getLayoutParams();
778 lp.leftMargin = sideMargins;
779 lp.rightMargin = sideMargins;
780 }
781 }
782 }
783
John Spurlockaf8d6c42014-05-07 17:49:08 -0400784 private class H extends Handler {
785 private static final int SHOW_DETAIL = 1;
786 private static final int SET_TILE_VISIBILITY = 2;
dooyoung.hwang1b006622016-12-22 20:04:20 +0900787 private static final int ANNOUNCE_FOR_ACCESSIBILITY = 3;
Jason Monkcb4b31d2017-05-03 10:37:34 -0400788
John Spurlockaf8d6c42014-05-07 17:49:08 -0400789 @Override
790 public void handleMessage(Message msg) {
791 if (msg.what == SHOW_DETAIL) {
Jason Monkcb4b31d2017-05-03 10:37:34 -0400792 handleShowDetail((Record) msg.obj, msg.arg1 != 0);
dooyoung.hwang1b006622016-12-22 20:04:20 +0900793 } else if (msg.what == ANNOUNCE_FOR_ACCESSIBILITY) {
Jason Monkcb4b31d2017-05-03 10:37:34 -0400794 announceForAccessibility((CharSequence) msg.obj);
John Spurlockaf8d6c42014-05-07 17:49:08 -0400795 }
796 }
797 }
798
Fabian Kozynski00d494d2019-04-04 09:53:50 -0400799 @Override
800 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
801 pw.println(getClass().getSimpleName() + ":");
802 pw.println(" Tile records:");
803 for (TileRecord record : mRecords) {
804 if (record.tile instanceof Dumpable) {
805 pw.print(" "); ((Dumpable) record.tile).dump(fd, pw, args);
806 pw.print(" "); pw.println(record.tileView.toString());
807 }
808 }
809 }
810
Jason Monkdc35dcb2015-12-04 16:36:15 -0500811 protected static class Record {
John Spurlock7f8f22a2014-07-02 18:54:17 -0400812 DetailAdapter detailAdapter;
Adrian Roos970be532014-11-21 15:50:16 +0100813 int x;
814 int y;
Adrian Roos1ef80fe2014-07-14 22:53:54 +0200815 }
816
Jason Monkbd6dbb02015-09-03 15:46:25 -0400817 public static final class TileRecord extends Record {
Jason Monk702e2eb2017-03-03 16:53:44 -0500818 public QSTile tile;
819 public com.android.systemui.plugins.qs.QSTileView tileView;
Jason Monk11a77442015-05-12 19:29:02 -0400820 public boolean scanState;
Xiaohui Chen08e266c2016-04-18 12:53:28 -0700821 public QSTile.Callback callback;
John Spurlockaf8d6c42014-05-07 17:49:08 -0400822 }
823
Jason Monkcaf37622015-08-18 12:33:50 -0400824 public interface QSTileLayout {
Fabian Kozynski407ddb22018-10-03 15:04:56 -0400825
826 default void saveInstanceState(Bundle outState) {}
827
828 default void restoreInstanceState(Bundle savedInstanceState) {}
829
Jason Monkcaf37622015-08-18 12:33:50 -0400830 void addTile(TileRecord tile);
Jason Monkcb4b31d2017-05-03 10:37:34 -0400831
Jason Monkcaf37622015-08-18 12:33:50 -0400832 void removeTile(TileRecord tile);
Jason Monkcb4b31d2017-05-03 10:37:34 -0400833
Jason Monkcaf37622015-08-18 12:33:50 -0400834 int getOffsetTop(TileRecord tile);
Jason Monkcb4b31d2017-05-03 10:37:34 -0400835
Jason Monk9d02a432016-01-20 16:33:46 -0500836 boolean updateResources();
Jason Monk1bec6af2016-05-31 15:40:58 -0400837
838 void setListening(boolean listening);
Amin Shaikh0f8ea5432018-03-27 11:09:27 -0400839
840 default void setExpansion(float expansion) {}
Fabian Kozynski802279f2018-09-07 13:44:54 -0400841
842 int getNumVisibleTiles();
Jason Monkcaf37622015-08-18 12:33:50 -0400843 }
John Spurlockaf8d6c42014-05-07 17:49:08 -0400844}