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 | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 19 | import static com.android.systemui.qs.tileimpl.QSTileImpl.getColorForState; |
Fabian Kozynski | 00d494d | 2019-04-04 09:53:50 -0400 | [diff] [blame] | 20 | import static com.android.systemui.util.InjectionInflationController.VIEW_CONTEXT; |
Matt Pietal | 5a19cb6 | 2019-10-30 12:31:07 -0400 | [diff] [blame] | 21 | import static com.android.systemui.util.Utils.useQsMediaPlayer; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 22 | |
Rohan Shah | db2cfa3 | 2018-02-20 11:27:22 -0800 | [diff] [blame] | 23 | import android.annotation.Nullable; |
Jason Monk | 7e53f20 | 2016-01-28 10:40:20 -0500 | [diff] [blame] | 24 | import android.content.ComponentName; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 25 | import android.content.Context; |
Jorim Jaggi | e17c4b4 | 2014-08-26 17:27:31 +0200 | [diff] [blame] | 26 | import android.content.res.Configuration; |
John Spurlock | 4bf3198 | 2014-05-21 13:04:22 -0400 | [diff] [blame] | 27 | import android.content.res.Resources; |
Beth Thibodeau | 07d20c3 | 2019-10-16 13:45:56 -0400 | [diff] [blame] | 28 | import android.graphics.drawable.Icon; |
| 29 | import android.media.session.MediaSession; |
Jason Monk | cb4b31d | 2017-05-03 10:37:34 -0400 | [diff] [blame] | 30 | import android.metrics.LogMaker; |
Fabian Kozynski | 407ddb2 | 2018-10-03 15:04:56 -0400 | [diff] [blame] | 31 | import android.os.Bundle; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 32 | import android.os.Handler; |
| 33 | import android.os.Message; |
Beth Thibodeau | 07d20c3 | 2019-10-16 13:45:56 -0400 | [diff] [blame] | 34 | import android.service.notification.StatusBarNotification; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 35 | import android.service.quicksettings.Tile; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 36 | import android.util.AttributeSet; |
Beth Thibodeau | 07d20c3 | 2019-10-16 13:45:56 -0400 | [diff] [blame] | 37 | import android.util.Log; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 38 | import android.view.LayoutInflater; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 39 | import android.view.View; |
Beth Thibodeau | 07d20c3 | 2019-10-16 13:45:56 -0400 | [diff] [blame] | 40 | import android.view.ViewGroup; |
Beth Thibodeau | 07d20c3 | 2019-10-16 13:45:56 -0400 | [diff] [blame] | 41 | import android.widget.HorizontalScrollView; |
Jason Monk | 520ea06 | 2015-08-18 14:53:06 -0400 | [diff] [blame] | 42 | import android.widget.LinearLayout; |
Jason Monk | cb4b31d | 2017-05-03 10:37:34 -0400 | [diff] [blame] | 43 | |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 44 | import com.android.internal.logging.MetricsLogger; |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 45 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Jason Monk | 824ffff | 2017-04-11 15:49:06 -0400 | [diff] [blame] | 46 | import com.android.settingslib.Utils; |
Fabian Kozynski | cc4c6c3 | 2020-03-09 15:11:33 -0400 | [diff] [blame] | 47 | import com.android.settingslib.bluetooth.LocalBluetoothManager; |
| 48 | import com.android.settingslib.media.InfoMediaManager; |
Beth Thibodeau | 69b1dfd | 2019-11-08 15:39:25 -0500 | [diff] [blame] | 49 | import com.android.settingslib.media.LocalMediaManager; |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 50 | import com.android.systemui.Dependency; |
Fabian Kozynski | 00d494d | 2019-04-04 09:53:50 -0400 | [diff] [blame] | 51 | import com.android.systemui.Dumpable; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 52 | import com.android.systemui.R; |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 53 | import com.android.systemui.broadcast.BroadcastDispatcher; |
Beth Thibodeau | 7b6c178 | 2020-03-05 11:43:51 -0500 | [diff] [blame] | 54 | import com.android.systemui.dagger.qualifiers.Background; |
Beth Thibodeau | a51c314 | 2020-03-17 17:27:04 -0400 | [diff] [blame] | 55 | import com.android.systemui.dagger.qualifiers.Main; |
Ned Burns | aaeb44b | 2020-02-12 23:48:26 -0500 | [diff] [blame] | 56 | import com.android.systemui.dump.DumpManager; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 57 | import com.android.systemui.plugins.qs.DetailAdapter; |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 58 | import com.android.systemui.plugins.qs.QSTile; |
| 59 | import com.android.systemui.plugins.qs.QSTileView; |
| 60 | import com.android.systemui.qs.QSHost.Callback; |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 61 | import com.android.systemui.qs.customize.QSCustomizer; |
Jason Monk | 7e53f20 | 2016-01-28 10:40:20 -0500 | [diff] [blame] | 62 | import com.android.systemui.qs.external.CustomTile; |
Fabian Kozynski | ca30f57 | 2019-10-24 10:01:04 -0400 | [diff] [blame] | 63 | import com.android.systemui.qs.logging.QSLogger; |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 64 | import com.android.systemui.settings.BrightnessController; |
Muyuan Li | 3b0f892 | 2016-04-18 19:27:29 -0700 | [diff] [blame] | 65 | import com.android.systemui.settings.ToggleSliderView; |
Beth Thibodeau | 7b6c178 | 2020-03-05 11:43:51 -0500 | [diff] [blame] | 66 | import com.android.systemui.statusbar.NotificationMediaManager; |
Adrian Roos | 5fd872e | 2014-08-12 17:28:58 +0200 | [diff] [blame] | 67 | import com.android.systemui.statusbar.policy.BrightnessMirrorController; |
Adrian Roos | b01793f | 2017-08-09 14:34:55 +0200 | [diff] [blame] | 68 | import com.android.systemui.statusbar.policy.BrightnessMirrorController.BrightnessMirrorListener; |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 69 | import com.android.systemui.tuner.TunerService; |
| 70 | import com.android.systemui.tuner.TunerService.Tunable; |
Robert Snoeberger | 7dffd37 | 2020-04-01 17:32:44 -0400 | [diff] [blame] | 71 | import com.android.systemui.util.concurrency.DelayableExecutor; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 72 | |
Fabian Kozynski | 00d494d | 2019-04-04 09:53:50 -0400 | [diff] [blame] | 73 | import java.io.FileDescriptor; |
| 74 | import java.io.PrintWriter; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 75 | import java.util.ArrayList; |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 76 | import java.util.Collection; |
Beth Thibodeau | 7b6c178 | 2020-03-05 11:43:51 -0500 | [diff] [blame] | 77 | import java.util.concurrent.Executor; |
Fabian Kozynski | ca30f57 | 2019-10-24 10:01:04 -0400 | [diff] [blame] | 78 | import java.util.stream.Collectors; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 79 | |
Fabian Kozynski | 00d494d | 2019-04-04 09:53:50 -0400 | [diff] [blame] | 80 | import javax.inject.Inject; |
| 81 | import javax.inject.Named; |
| 82 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 83 | /** View that represents the quick settings tile panel (when expanded/pulled down). **/ |
Fabian Kozynski | 00d494d | 2019-04-04 09:53:50 -0400 | [diff] [blame] | 84 | public class QSPanel extends LinearLayout implements Tunable, Callback, BrightnessMirrorListener, |
| 85 | Dumpable { |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 86 | |
| 87 | public static final String QS_SHOW_BRIGHTNESS = "qs_show_brightness"; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 88 | public static final String QS_SHOW_HEADER = "qs_show_header"; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 89 | |
Fabian Kozynski | 0db39af | 2018-08-31 15:56:45 -0400 | [diff] [blame] | 90 | private static final String TAG = "QSPanel"; |
| 91 | |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 92 | protected final Context mContext; |
Amin Shaikh | a07a17b | 2018-02-23 16:02:52 -0500 | [diff] [blame] | 93 | protected final ArrayList<TileRecord> mRecords = new ArrayList<>(); |
Fabian Kozynski | ca30f57 | 2019-10-24 10:01:04 -0400 | [diff] [blame] | 94 | private String mCachedSpecs = ""; |
Jason Monk | 11a7744 | 2015-05-12 19:29:02 -0400 | [diff] [blame] | 95 | protected final View mBrightnessView; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 96 | private final H mHandler = new H(); |
Jason Monk | 8c09ac7 | 2017-03-16 11:53:40 -0400 | [diff] [blame] | 97 | private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class); |
Amin Shaikh | a07a17b | 2018-02-23 16:02:52 -0500 | [diff] [blame] | 98 | private final QSTileRevealController mQsTileRevealController; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 99 | |
Beth Thibodeau | 07d20c3 | 2019-10-16 13:45:56 -0400 | [diff] [blame] | 100 | private final LinearLayout mMediaCarousel; |
| 101 | private final ArrayList<QSMediaPlayer> mMediaPlayers = new ArrayList<>(); |
Beth Thibodeau | 7b6c178 | 2020-03-05 11:43:51 -0500 | [diff] [blame] | 102 | private final NotificationMediaManager mNotificationMediaManager; |
Fabian Kozynski | cc4c6c3 | 2020-03-09 15:11:33 -0400 | [diff] [blame] | 103 | private final LocalBluetoothManager mLocalBluetoothManager; |
Beth Thibodeau | a51c314 | 2020-03-17 17:27:04 -0400 | [diff] [blame] | 104 | private final Executor mForegroundExecutor; |
Robert Snoeberger | 7dffd37 | 2020-04-01 17:32:44 -0400 | [diff] [blame] | 105 | private final DelayableExecutor mBackgroundExecutor; |
Beth Thibodeau | 8cb6d42 | 2020-01-31 14:57:09 -0500 | [diff] [blame] | 106 | private boolean mUpdateCarousel = false; |
Beth Thibodeau | 07d20c3 | 2019-10-16 13:45:56 -0400 | [diff] [blame] | 107 | |
Muyuan Li | 0e9f538 | 2016-04-27 15:51:15 -0700 | [diff] [blame] | 108 | protected boolean mExpanded; |
Jason Monk | 1bec6af | 2016-05-31 15:40:58 -0400 | [diff] [blame] | 109 | protected boolean mListening; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 110 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 111 | private QSDetail.Callback mCallback; |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 112 | private BrightnessController mBrightnessController; |
Ned Burns | aaeb44b | 2020-02-12 23:48:26 -0500 | [diff] [blame] | 113 | private final DumpManager mDumpManager; |
Fabian Kozynski | ca30f57 | 2019-10-24 10:01:04 -0400 | [diff] [blame] | 114 | private final QSLogger mQSLogger; |
Jason Monk | bbadff8 | 2015-11-06 15:47:26 -0500 | [diff] [blame] | 115 | protected QSTileHost mHost; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 116 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 117 | protected QSSecurityFooter mFooter; |
Rohan Shah | 3090e79 | 2018-04-12 00:01:00 -0400 | [diff] [blame] | 118 | private PageIndicator mFooterPageIndicator; |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 119 | private boolean mGridContentVisible = true; |
Jason Monk | 3d5f551 | 2014-07-25 11:17:28 -0400 | [diff] [blame] | 120 | |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 121 | protected QSTileLayout mTileLayout; |
| 122 | |
| 123 | private QSCustomizer mCustomizePanel; |
Jason Monk | 377e7ad | 2016-02-16 14:03:21 -0500 | [diff] [blame] | 124 | private Record mDetailRecord; |
Jason Monk | 520ea06 | 2015-08-18 14:53:06 -0400 | [diff] [blame] | 125 | |
Adrian Roos | 429c962 | 2016-06-15 13:02:17 -0700 | [diff] [blame] | 126 | private BrightnessMirrorController mBrightnessMirrorController; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 127 | private View mDivider; |
Adrian Roos | 429c962 | 2016-06-15 13:02:17 -0700 | [diff] [blame] | 128 | |
Fabian Kozynski | 00d494d | 2019-04-04 09:53:50 -0400 | [diff] [blame] | 129 | @Inject |
Fabian Kozynski | ca30f57 | 2019-10-24 10:01:04 -0400 | [diff] [blame] | 130 | public QSPanel( |
| 131 | @Named(VIEW_CONTEXT) Context context, |
| 132 | AttributeSet attrs, |
Ned Burns | aaeb44b | 2020-02-12 23:48:26 -0500 | [diff] [blame] | 133 | DumpManager dumpManager, |
Fabian Kozynski | ca30f57 | 2019-10-24 10:01:04 -0400 | [diff] [blame] | 134 | BroadcastDispatcher broadcastDispatcher, |
Beth Thibodeau | 7b6c178 | 2020-03-05 11:43:51 -0500 | [diff] [blame] | 135 | QSLogger qsLogger, |
| 136 | NotificationMediaManager notificationMediaManager, |
Beth Thibodeau | a51c314 | 2020-03-17 17:27:04 -0400 | [diff] [blame] | 137 | @Main Executor foregroundExecutor, |
Robert Snoeberger | 7dffd37 | 2020-04-01 17:32:44 -0400 | [diff] [blame] | 138 | @Background DelayableExecutor backgroundExecutor, |
Fabian Kozynski | cc4c6c3 | 2020-03-09 15:11:33 -0400 | [diff] [blame] | 139 | @Nullable LocalBluetoothManager localBluetoothManager |
Fabian Kozynski | ca30f57 | 2019-10-24 10:01:04 -0400 | [diff] [blame] | 140 | ) { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 141 | super(context, attrs); |
| 142 | mContext = context; |
Fabian Kozynski | ca30f57 | 2019-10-24 10:01:04 -0400 | [diff] [blame] | 143 | mQSLogger = qsLogger; |
Ned Burns | aaeb44b | 2020-02-12 23:48:26 -0500 | [diff] [blame] | 144 | mDumpManager = dumpManager; |
Beth Thibodeau | 7b6c178 | 2020-03-05 11:43:51 -0500 | [diff] [blame] | 145 | mNotificationMediaManager = notificationMediaManager; |
Beth Thibodeau | a51c314 | 2020-03-17 17:27:04 -0400 | [diff] [blame] | 146 | mForegroundExecutor = foregroundExecutor; |
Beth Thibodeau | 7b6c178 | 2020-03-05 11:43:51 -0500 | [diff] [blame] | 147 | mBackgroundExecutor = backgroundExecutor; |
Fabian Kozynski | cc4c6c3 | 2020-03-09 15:11:33 -0400 | [diff] [blame] | 148 | mLocalBluetoothManager = localBluetoothManager; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 149 | |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 150 | setOrientation(VERTICAL); |
Jason Monk | 520ea06 | 2015-08-18 14:53:06 -0400 | [diff] [blame] | 151 | |
Jason Monk | 231b052 | 2018-01-04 10:49:55 -0500 | [diff] [blame] | 152 | mBrightnessView = LayoutInflater.from(mContext).inflate( |
| 153 | R.layout.quick_settings_brightness_dialog, this, false); |
Amin Shaikh | 15781d6 | 2018-02-16 16:00:13 -0500 | [diff] [blame] | 154 | addView(mBrightnessView); |
| 155 | |
| 156 | mTileLayout = (QSTileLayout) LayoutInflater.from(mContext).inflate( |
| 157 | R.layout.qs_paged_tile_layout, this, false); |
Fabian Kozynski | ca30f57 | 2019-10-24 10:01:04 -0400 | [diff] [blame] | 158 | mQSLogger.logAllTilesChangeListening(mListening, getDumpableTag(), mCachedSpecs); |
Jason Monk | 231b052 | 2018-01-04 10:49:55 -0500 | [diff] [blame] | 159 | mTileLayout.setListening(mListening); |
Amin Shaikh | 15781d6 | 2018-02-16 16:00:13 -0500 | [diff] [blame] | 160 | addView((View) mTileLayout); |
| 161 | |
Amin Shaikh | a07a17b | 2018-02-23 16:02:52 -0500 | [diff] [blame] | 162 | mQsTileRevealController = new QSTileRevealController(mContext, this, |
Rohan Shah | 3090e79 | 2018-04-12 00:01:00 -0400 | [diff] [blame] | 163 | (PagedTileLayout) mTileLayout); |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 164 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 165 | addDivider(); |
| 166 | |
Beth Thibodeau | 07d20c3 | 2019-10-16 13:45:56 -0400 | [diff] [blame] | 167 | // Add media carousel |
Matt Pietal | 5a19cb6 | 2019-10-30 12:31:07 -0400 | [diff] [blame] | 168 | if (useQsMediaPlayer(context)) { |
Beth Thibodeau | 899b595 | 2020-01-07 17:50:07 -0500 | [diff] [blame] | 169 | HorizontalScrollView mediaScrollView = (HorizontalScrollView) LayoutInflater.from( |
| 170 | mContext).inflate(R.layout.media_carousel, this, false); |
| 171 | mMediaCarousel = mediaScrollView.findViewById(R.id.media_carousel); |
Beth Thibodeau | 8cb6d42 | 2020-01-31 14:57:09 -0500 | [diff] [blame] | 172 | addView(mediaScrollView, 0); |
Beth Thibodeau | 07d20c3 | 2019-10-16 13:45:56 -0400 | [diff] [blame] | 173 | } else { |
| 174 | mMediaCarousel = null; |
| 175 | } |
| 176 | |
phweiss | 4f70f10 | 2017-04-12 19:32:55 +0200 | [diff] [blame] | 177 | mFooter = new QSSecurityFooter(this, context); |
| 178 | addView(mFooter.getView()); |
| 179 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 180 | updateResources(); |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 181 | |
| 182 | mBrightnessController = new BrightnessController(getContext(), |
Fabian Kozynski | 5ca7a51 | 2019-10-16 19:56:11 +0000 | [diff] [blame] | 183 | findViewById(R.id.brightness_slider), broadcastDispatcher); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 184 | } |
| 185 | |
Beth Thibodeau | 8cb6d42 | 2020-01-31 14:57:09 -0500 | [diff] [blame] | 186 | @Override |
| 187 | public void onVisibilityAggregated(boolean isVisible) { |
| 188 | super.onVisibilityAggregated(isVisible); |
| 189 | if (!isVisible && mUpdateCarousel) { |
| 190 | for (QSMediaPlayer player : mMediaPlayers) { |
| 191 | if (player.isPlaying()) { |
| 192 | LayoutParams lp = (LayoutParams) player.getView().getLayoutParams(); |
| 193 | mMediaCarousel.removeView(player.getView()); |
| 194 | mMediaCarousel.addView(player.getView(), 0, lp); |
| 195 | ((HorizontalScrollView) mMediaCarousel.getParent()).fullScroll(View.FOCUS_LEFT); |
| 196 | mUpdateCarousel = false; |
| 197 | break; |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | |
Beth Thibodeau | 07d20c3 | 2019-10-16 13:45:56 -0400 | [diff] [blame] | 203 | /** |
| 204 | * Add or update a player for the associated media session |
| 205 | * @param token |
| 206 | * @param icon |
| 207 | * @param iconColor |
| 208 | * @param bgColor |
| 209 | * @param actionsContainer |
| 210 | * @param notif |
Beth Thibodeau | a3d9098 | 2020-04-13 23:42:48 -0400 | [diff] [blame] | 211 | * @param key |
Beth Thibodeau | 07d20c3 | 2019-10-16 13:45:56 -0400 | [diff] [blame] | 212 | */ |
| 213 | public void addMediaSession(MediaSession.Token token, Icon icon, int iconColor, int bgColor, |
Beth Thibodeau | a3d9098 | 2020-04-13 23:42:48 -0400 | [diff] [blame] | 214 | View actionsContainer, StatusBarNotification notif, String key) { |
Matt Pietal | 5a19cb6 | 2019-10-30 12:31:07 -0400 | [diff] [blame] | 215 | if (!useQsMediaPlayer(mContext)) { |
Beth Thibodeau | 07d20c3 | 2019-10-16 13:45:56 -0400 | [diff] [blame] | 216 | // Shouldn't happen, but just in case |
| 217 | Log.e(TAG, "Tried to add media session without player!"); |
| 218 | return; |
| 219 | } |
Beth Thibodeau | 69b1dfd | 2019-11-08 15:39:25 -0500 | [diff] [blame] | 220 | if (token == null) { |
| 221 | Log.e(TAG, "Media session token was null!"); |
| 222 | return; |
| 223 | } |
| 224 | |
Beth Thibodeau | 07d20c3 | 2019-10-16 13:45:56 -0400 | [diff] [blame] | 225 | QSMediaPlayer player = null; |
| 226 | String packageName = notif.getPackageName(); |
| 227 | for (QSMediaPlayer p : mMediaPlayers) { |
| 228 | if (p.getMediaSessionToken().equals(token)) { |
Beth Thibodeau | a3d9098 | 2020-04-13 23:42:48 -0400 | [diff] [blame] | 229 | Log.d(TAG, "Found matching player by token " + packageName); |
Beth Thibodeau | 07d20c3 | 2019-10-16 13:45:56 -0400 | [diff] [blame] | 230 | player = p; |
| 231 | break; |
Beth Thibodeau | a3d9098 | 2020-04-13 23:42:48 -0400 | [diff] [blame] | 232 | } else if (packageName.equals(p.getMediaPlayerPackage()) && key.equals(p.getKey())) { |
| 233 | // Also match if it's the same package and notification key |
| 234 | Log.d(TAG, "Found matching player by package " + packageName + ", " + key); |
Beth Thibodeau | 07d20c3 | 2019-10-16 13:45:56 -0400 | [diff] [blame] | 235 | player = p; |
| 236 | break; |
| 237 | } |
| 238 | } |
| 239 | |
Beth Thibodeau | 07d20c3 | 2019-10-16 13:45:56 -0400 | [diff] [blame] | 240 | int playerWidth = (int) getResources().getDimension(R.dimen.qs_media_width); |
| 241 | int padding = (int) getResources().getDimension(R.dimen.qs_media_padding); |
| 242 | LayoutParams lp = new LayoutParams(playerWidth, ViewGroup.LayoutParams.MATCH_PARENT); |
| 243 | lp.setMarginStart(padding); |
| 244 | lp.setMarginEnd(padding); |
| 245 | |
| 246 | if (player == null) { |
| 247 | Log.d(TAG, "creating new player"); |
Robert Snoeberger | 9a7409b | 2020-04-09 18:12:27 -0400 | [diff] [blame] | 248 | // Set up listener for device changes |
| 249 | // TODO: integrate with MediaTransferManager? |
| 250 | InfoMediaManager imm = new InfoMediaManager(mContext, notif.getPackageName(), |
| 251 | notif.getNotification(), mLocalBluetoothManager); |
| 252 | LocalMediaManager routeManager = new LocalMediaManager(mContext, mLocalBluetoothManager, |
| 253 | imm, notif.getPackageName()); |
| 254 | |
| 255 | player = new QSMediaPlayer(mContext, this, mNotificationMediaManager, routeManager, |
Beth Thibodeau | a51c314 | 2020-03-17 17:27:04 -0400 | [diff] [blame] | 256 | mForegroundExecutor, mBackgroundExecutor); |
Robert Snoeberger | 7dffd37 | 2020-04-01 17:32:44 -0400 | [diff] [blame] | 257 | player.setListening(mListening); |
Beth Thibodeau | 07d20c3 | 2019-10-16 13:45:56 -0400 | [diff] [blame] | 258 | if (player.isPlaying()) { |
| 259 | mMediaCarousel.addView(player.getView(), 0, lp); // add in front |
| 260 | } else { |
| 261 | mMediaCarousel.addView(player.getView(), lp); // add at end |
| 262 | } |
Beth Thibodeau | 4e69f4c | 2019-10-24 14:13:49 -0400 | [diff] [blame] | 263 | mMediaPlayers.add(player); |
Beth Thibodeau | 07d20c3 | 2019-10-16 13:45:56 -0400 | [diff] [blame] | 264 | } else if (player.isPlaying()) { |
Beth Thibodeau | 8cb6d42 | 2020-01-31 14:57:09 -0500 | [diff] [blame] | 265 | mUpdateCarousel = true; |
Beth Thibodeau | 07d20c3 | 2019-10-16 13:45:56 -0400 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | Log.d(TAG, "setting player session"); |
Beth Thibodeau | 7b6c178 | 2020-03-05 11:43:51 -0500 | [diff] [blame] | 269 | player.setMediaSession(token, icon, iconColor, bgColor, actionsContainer, |
Beth Thibodeau | a3d9098 | 2020-04-13 23:42:48 -0400 | [diff] [blame] | 270 | notif.getNotification(), key); |
Beth Thibodeau | 4e69f4c | 2019-10-24 14:13:49 -0400 | [diff] [blame] | 271 | |
| 272 | if (mMediaPlayers.size() > 0) { |
| 273 | ((View) mMediaCarousel.getParent()).setVisibility(View.VISIBLE); |
| 274 | } |
Beth Thibodeau | 07d20c3 | 2019-10-16 13:45:56 -0400 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | protected View getMediaPanel() { |
| 278 | return mMediaCarousel; |
| 279 | } |
| 280 | |
Beth Thibodeau | fd51bb2 | 2019-11-25 13:57:06 -0500 | [diff] [blame] | 281 | /** |
| 282 | * Remove the media player from the carousel |
| 283 | * @param player Player to remove |
| 284 | * @return true if removed, false if player was not found |
| 285 | */ |
| 286 | protected boolean removeMediaPlayer(QSMediaPlayer player) { |
| 287 | // Remove from list |
| 288 | if (!mMediaPlayers.remove(player)) { |
| 289 | return false; |
| 290 | } |
| 291 | |
| 292 | // Check if we need to collapse the carousel now |
| 293 | mMediaCarousel.removeView(player.getView()); |
| 294 | if (mMediaPlayers.size() == 0) { |
| 295 | ((View) mMediaCarousel.getParent()).setVisibility(View.GONE); |
Beth Thibodeau | fd51bb2 | 2019-11-25 13:57:06 -0500 | [diff] [blame] | 296 | } |
| 297 | return true; |
| 298 | } |
| 299 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 300 | protected void addDivider() { |
| 301 | mDivider = LayoutInflater.from(mContext).inflate(R.layout.qs_divider, this, false); |
Jason Monk | 824ffff | 2017-04-11 15:49:06 -0400 | [diff] [blame] | 302 | mDivider.setBackgroundColor(Utils.applyAlpha(mDivider.getAlpha(), |
| 303 | getColorForState(mContext, Tile.STATE_ACTIVE))); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 304 | addView(mDivider); |
| 305 | } |
| 306 | |
Fabian Kozynski | 72cd84a9 | 2019-04-15 14:09:43 -0400 | [diff] [blame] | 307 | @Override |
| 308 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 309 | // We want all the logic of LinearLayout#onMeasure, and for it to assign the excess space |
| 310 | // not used by the other children to PagedTileLayout. However, in this case, LinearLayout |
| 311 | // assumes that PagedTileLayout would use all the excess space. This is not the case as |
| 312 | // PagedTileLayout height is quantized (because it shows a certain number of rows). |
| 313 | // Therefore, after everything is measured, we need to make sure that we add up the correct |
| 314 | // total height |
| 315 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 316 | int height = getPaddingBottom() + getPaddingTop(); |
| 317 | int numChildren = getChildCount(); |
| 318 | for (int i = 0; i < numChildren; i++) { |
| 319 | View child = getChildAt(i); |
| 320 | if (child.getVisibility() != View.GONE) height += child.getMeasuredHeight(); |
| 321 | } |
| 322 | setMeasuredDimension(getMeasuredWidth(), height); |
| 323 | } |
| 324 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 325 | public View getDivider() { |
| 326 | return mDivider; |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 327 | } |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 328 | |
Amin Shaikh | a07a17b | 2018-02-23 16:02:52 -0500 | [diff] [blame] | 329 | public QSTileRevealController getQsTileRevealController() { |
| 330 | return mQsTileRevealController; |
| 331 | } |
| 332 | |
Jason Monk | 377e7ad | 2016-02-16 14:03:21 -0500 | [diff] [blame] | 333 | public boolean isShowingCustomize() { |
| 334 | return mCustomizePanel != null && mCustomizePanel.isCustomizing(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 335 | } |
| 336 | |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 337 | @Override |
| 338 | protected void onAttachedToWindow() { |
| 339 | super.onAttachedToWindow(); |
Rohan Shah | db2cfa3 | 2018-02-20 11:27:22 -0800 | [diff] [blame] | 340 | final TunerService tunerService = Dependency.get(TunerService.class); |
| 341 | tunerService.addTunable(this, QS_SHOW_BRIGHTNESS); |
Rohan Shah | db2cfa3 | 2018-02-20 11:27:22 -0800 | [diff] [blame] | 342 | |
Jason Monk | f160edca | 2016-03-30 13:48:56 -0400 | [diff] [blame] | 343 | if (mHost != null) { |
| 344 | setTiles(mHost.getTiles()); |
| 345 | } |
Adrian Roos | b01793f | 2017-08-09 14:34:55 +0200 | [diff] [blame] | 346 | if (mBrightnessMirrorController != null) { |
| 347 | mBrightnessMirrorController.addCallback(this); |
| 348 | } |
Ned Burns | aaeb44b | 2020-02-12 23:48:26 -0500 | [diff] [blame] | 349 | mDumpManager.registerDumpable(getDumpableTag(), this); |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | @Override |
| 353 | protected void onDetachedFromWindow() { |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 354 | Dependency.get(TunerService.class).removeTunable(this); |
| 355 | if (mHost != null) { |
| 356 | mHost.removeCallback(this); |
| 357 | } |
Jason Monk | f160edca | 2016-03-30 13:48:56 -0400 | [diff] [blame] | 358 | for (TileRecord record : mRecords) { |
| 359 | record.tile.removeCallbacks(); |
| 360 | } |
Adrian Roos | b01793f | 2017-08-09 14:34:55 +0200 | [diff] [blame] | 361 | if (mBrightnessMirrorController != null) { |
| 362 | mBrightnessMirrorController.removeCallback(this); |
| 363 | } |
Ned Burns | aaeb44b | 2020-02-12 23:48:26 -0500 | [diff] [blame] | 364 | mDumpManager.unregisterDumpable(getDumpableTag()); |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 365 | super.onDetachedFromWindow(); |
| 366 | } |
| 367 | |
Ned Burns | 66b6e37 | 2019-07-26 13:45:42 -0400 | [diff] [blame] | 368 | protected String getDumpableTag() { |
| 369 | return TAG; |
| 370 | } |
| 371 | |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 372 | @Override |
Jason Monk | 46dbfb4 | 2016-02-25 14:59:20 -0500 | [diff] [blame] | 373 | public void onTilesChanged() { |
| 374 | setTiles(mHost.getTiles()); |
| 375 | } |
| 376 | |
| 377 | @Override |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 378 | public void onTuningChanged(String key, String newValue) { |
| 379 | if (QS_SHOW_BRIGHTNESS.equals(key)) { |
Rohan Shah | db2cfa3 | 2018-02-20 11:27:22 -0800 | [diff] [blame] | 380 | updateViewVisibilityForTuningValue(mBrightnessView, newValue); |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 381 | } |
| 382 | } |
| 383 | |
Rohan Shah | db2cfa3 | 2018-02-20 11:27:22 -0800 | [diff] [blame] | 384 | private void updateViewVisibilityForTuningValue(View view, @Nullable String newValue) { |
Henrik Baard | a2c86e8 | 2019-03-14 12:23:04 +0100 | [diff] [blame] | 385 | view.setVisibility(TunerService.parseIntegerSwitch(newValue, true) ? VISIBLE : GONE); |
Rohan Shah | db2cfa3 | 2018-02-20 11:27:22 -0800 | [diff] [blame] | 386 | } |
| 387 | |
Jason Monk | a992732 | 2015-12-13 16:22:37 -0500 | [diff] [blame] | 388 | public void openDetails(String subPanel) { |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 389 | QSTile tile = getTile(subPanel); |
Fabian Kozynski | e3137e3 | 2018-09-28 11:20:04 -0400 | [diff] [blame] | 390 | // If there's no tile with that name (as defined in QSFactoryImpl or other QSFactory), |
| 391 | // QSFactory will not be able to create a tile and getTile will return null |
| 392 | if (tile != null) { |
| 393 | showDetailAdapter(true, tile.getDetailAdapter(), new int[]{getWidth() / 2, 0}); |
| 394 | } |
Jason Monk | a992732 | 2015-12-13 16:22:37 -0500 | [diff] [blame] | 395 | } |
| 396 | |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 397 | private QSTile getTile(String subPanel) { |
Jason Monk | a992732 | 2015-12-13 16:22:37 -0500 | [diff] [blame] | 398 | for (int i = 0; i < mRecords.size(); i++) { |
| 399 | if (subPanel.equals(mRecords.get(i).tile.getTileSpec())) { |
| 400 | return mRecords.get(i).tile; |
| 401 | } |
| 402 | } |
| 403 | return mHost.createTile(subPanel); |
| 404 | } |
| 405 | |
Adrian Roos | 5fd872e | 2014-08-12 17:28:58 +0200 | [diff] [blame] | 406 | public void setBrightnessMirror(BrightnessMirrorController c) { |
Adrian Roos | b01793f | 2017-08-09 14:34:55 +0200 | [diff] [blame] | 407 | if (mBrightnessMirrorController != null) { |
| 408 | mBrightnessMirrorController.removeCallback(this); |
| 409 | } |
Adrian Roos | 429c962 | 2016-06-15 13:02:17 -0700 | [diff] [blame] | 410 | mBrightnessMirrorController = c; |
Adrian Roos | b01793f | 2017-08-09 14:34:55 +0200 | [diff] [blame] | 411 | if (mBrightnessMirrorController != null) { |
| 412 | mBrightnessMirrorController.addCallback(this); |
| 413 | } |
| 414 | updateBrightnessMirror(); |
| 415 | } |
| 416 | |
| 417 | @Override |
| 418 | public void onBrightnessMirrorReinflated(View brightnessMirror) { |
| 419 | updateBrightnessMirror(); |
Adrian Roos | 5fd872e | 2014-08-12 17:28:58 +0200 | [diff] [blame] | 420 | } |
| 421 | |
Jason Monk | b46059a | 2016-06-30 14:22:42 -0400 | [diff] [blame] | 422 | View getBrightnessView() { |
| 423 | return mBrightnessView; |
| 424 | } |
| 425 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 426 | public void setCallback(QSDetail.Callback callback) { |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 427 | mCallback = callback; |
| 428 | } |
| 429 | |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 430 | public void setHost(QSTileHost host, QSCustomizer customizer) { |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 431 | mHost = host; |
Jason Monk | 46dbfb4 | 2016-02-25 14:59:20 -0500 | [diff] [blame] | 432 | mHost.addCallback(this); |
| 433 | setTiles(mHost.getTiles()); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 434 | mFooter.setHostEnvironment(host); |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 435 | mCustomizePanel = customizer; |
| 436 | if (mCustomizePanel != null) { |
| 437 | mCustomizePanel.setHost(mHost); |
| 438 | } |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 439 | } |
| 440 | |
Rohan Shah | 3090e79 | 2018-04-12 00:01:00 -0400 | [diff] [blame] | 441 | /** |
| 442 | * Links the footer's page indicator, which is used in landscape orientation to save space. |
| 443 | * |
| 444 | * @param pageIndicator indicator to use for page scrolling |
| 445 | */ |
| 446 | public void setFooterPageIndicator(PageIndicator pageIndicator) { |
| 447 | if (mTileLayout instanceof PagedTileLayout) { |
| 448 | mFooterPageIndicator = pageIndicator; |
| 449 | updatePageIndicator(); |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | private void updatePageIndicator() { |
| 454 | if (mTileLayout instanceof PagedTileLayout) { |
Rohan Shah | 3090e79 | 2018-04-12 00:01:00 -0400 | [diff] [blame] | 455 | if (mFooterPageIndicator != null) { |
| 456 | mFooterPageIndicator.setVisibility(View.GONE); |
Rohan Shah | 3090e79 | 2018-04-12 00:01:00 -0400 | [diff] [blame] | 457 | |
Fabian Kozynski | 4e76d1f | 2019-02-25 16:30:04 -0500 | [diff] [blame] | 458 | ((PagedTileLayout) mTileLayout).setPageIndicator(mFooterPageIndicator); |
| 459 | } |
Rohan Shah | 3090e79 | 2018-04-12 00:01:00 -0400 | [diff] [blame] | 460 | } |
| 461 | } |
| 462 | |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 463 | public QSTileHost getHost() { |
| 464 | return mHost; |
| 465 | } |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 466 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 467 | public void updateResources() { |
John Spurlock | 4bf3198 | 2014-05-21 13:04:22 -0400 | [diff] [blame] | 468 | final Resources res = mContext.getResources(); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 469 | setPadding(0, res.getDimensionPixelSize(R.dimen.qs_panel_padding_top), 0, res.getDimensionPixelSize(R.dimen.qs_panel_padding_bottom)); |
Rohan Shah | 3090e79 | 2018-04-12 00:01:00 -0400 | [diff] [blame] | 470 | |
| 471 | updatePageIndicator(); |
| 472 | |
John Spurlock | 1a462c1 | 2014-07-14 10:52:01 -0400 | [diff] [blame] | 473 | if (mListening) { |
| 474 | refreshAllTiles(); |
| 475 | } |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 476 | if (mTileLayout != null) { |
| 477 | mTileLayout.updateResources(); |
| 478 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 479 | } |
| 480 | |
Jorim Jaggi | e17c4b4 | 2014-08-26 17:27:31 +0200 | [diff] [blame] | 481 | @Override |
| 482 | protected void onConfigurationChanged(Configuration newConfig) { |
| 483 | super.onConfigurationChanged(newConfig); |
Jorim Jaggi | e17c4b4 | 2014-08-26 17:27:31 +0200 | [diff] [blame] | 484 | mFooter.onConfigurationChanged(); |
Fabian Kozynski | b1aee81 | 2019-04-04 14:17:48 -0400 | [diff] [blame] | 485 | updateResources(); |
Adrian Roos | 429c962 | 2016-06-15 13:02:17 -0700 | [diff] [blame] | 486 | |
Adrian Roos | b01793f | 2017-08-09 14:34:55 +0200 | [diff] [blame] | 487 | updateBrightnessMirror(); |
| 488 | } |
| 489 | |
| 490 | public void updateBrightnessMirror() { |
Adrian Roos | 429c962 | 2016-06-15 13:02:17 -0700 | [diff] [blame] | 491 | if (mBrightnessMirrorController != null) { |
Adrian Roos | b01793f | 2017-08-09 14:34:55 +0200 | [diff] [blame] | 492 | ToggleSliderView brightnessSlider = findViewById(R.id.brightness_slider); |
| 493 | ToggleSliderView mirrorSlider = mBrightnessMirrorController.getMirror() |
| 494 | .findViewById(R.id.brightness_slider); |
| 495 | brightnessSlider.setMirror(mirrorSlider); |
| 496 | brightnessSlider.setMirrorController(mBrightnessMirrorController); |
Adrian Roos | 429c962 | 2016-06-15 13:02:17 -0700 | [diff] [blame] | 497 | } |
Jorim Jaggi | e17c4b4 | 2014-08-26 17:27:31 +0200 | [diff] [blame] | 498 | } |
| 499 | |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 500 | public void onCollapse() { |
Yoshinori Hirano | 1dd7d07 | 2016-09-05 16:11:59 +0900 | [diff] [blame] | 501 | if (mCustomizePanel != null && mCustomizePanel.isShown()) { |
Fabian Kozynski | 0db39af | 2018-08-31 15:56:45 -0400 | [diff] [blame] | 502 | mCustomizePanel.hide(); |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 503 | } |
| 504 | } |
| 505 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 506 | public void setExpanded(boolean expanded) { |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 507 | if (mExpanded == expanded) return; |
Fabian Kozynski | ca30f57 | 2019-10-24 10:01:04 -0400 | [diff] [blame] | 508 | mQSLogger.logPanelExpanded(expanded, getDumpableTag()); |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 509 | mExpanded = expanded; |
Amin Shaikh | 15781d6 | 2018-02-16 16:00:13 -0500 | [diff] [blame] | 510 | if (!mExpanded && mTileLayout instanceof PagedTileLayout) { |
| 511 | ((PagedTileLayout) mTileLayout).setCurrentItem(0, false); |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 512 | } |
Jason Monk | 8c09ac7 | 2017-03-16 11:53:40 -0400 | [diff] [blame] | 513 | mMetricsLogger.visibility(MetricsEvent.QS_PANEL, mExpanded); |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 514 | if (!mExpanded) { |
John Spurlock | f7ae442 | 2014-08-01 12:45:18 -0400 | [diff] [blame] | 515 | closeDetail(); |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 516 | } else { |
| 517 | logTiles(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 518 | } |
Jorim Jaggi | e65e310 | 2014-07-01 22:00:50 +0200 | [diff] [blame] | 519 | } |
| 520 | |
Amin Shaikh | 5da602f | 2018-02-02 15:00:25 -0500 | [diff] [blame] | 521 | public void setPageListener(final PagedTileLayout.PageListener pageListener) { |
| 522 | if (mTileLayout instanceof PagedTileLayout) { |
| 523 | ((PagedTileLayout) mTileLayout).setPageListener(pageListener); |
Amin Shaikh | 5da602f | 2018-02-02 15:00:25 -0500 | [diff] [blame] | 524 | } |
| 525 | } |
| 526 | |
Muyuan Li | 0e9f538 | 2016-04-27 15:51:15 -0700 | [diff] [blame] | 527 | public boolean isExpanded() { |
| 528 | return mExpanded; |
| 529 | } |
| 530 | |
Jorim Jaggi | e65e310 | 2014-07-01 22:00:50 +0200 | [diff] [blame] | 531 | public void setListening(boolean listening) { |
| 532 | if (mListening == listening) return; |
| 533 | mListening = listening; |
Jason Monk | 1bec6af | 2016-05-31 15:40:58 -0400 | [diff] [blame] | 534 | if (mTileLayout != null) { |
Fabian Kozynski | ca30f57 | 2019-10-24 10:01:04 -0400 | [diff] [blame] | 535 | mQSLogger.logAllTilesChangeListening(listening, getDumpableTag(), mCachedSpecs); |
Jason Monk | 1bec6af | 2016-05-31 15:40:58 -0400 | [diff] [blame] | 536 | mTileLayout.setListening(listening); |
John Spurlock | 1a462c1 | 2014-07-14 10:52:01 -0400 | [diff] [blame] | 537 | } |
| 538 | if (mListening) { |
| 539 | refreshAllTiles(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 540 | } |
Robert Snoeberger | 7dffd37 | 2020-04-01 17:32:44 -0400 | [diff] [blame] | 541 | for (QSMediaPlayer player : mMediaPlayers) { |
| 542 | player.setListening(mListening); |
| 543 | } |
Fabian Kozynski | b9dc0c7 | 2018-09-20 13:00:17 -0400 | [diff] [blame] | 544 | } |
| 545 | |
Fabian Kozynski | ca30f57 | 2019-10-24 10:01:04 -0400 | [diff] [blame] | 546 | private String getTilesSpecs() { |
| 547 | return mRecords.stream() |
| 548 | .map(tileRecord -> tileRecord.tile.getTileSpec()) |
| 549 | .collect(Collectors.joining(",")); |
| 550 | } |
| 551 | |
Fabian Kozynski | b9dc0c7 | 2018-09-20 13:00:17 -0400 | [diff] [blame] | 552 | public void setListening(boolean listening, boolean expanded) { |
| 553 | setListening(listening && expanded); |
| 554 | getFooter().setListening(listening); |
| 555 | // Set the listening as soon as the QS fragment starts listening regardless of the expansion, |
| 556 | // so it will update the current brightness before the slider is visible. |
| 557 | setBrightnessListening(listening); |
| 558 | } |
| 559 | |
| 560 | public void setBrightnessListening(boolean listening) { |
| 561 | if (listening) { |
| 562 | mBrightnessController.registerCallbacks(); |
| 563 | } else { |
| 564 | mBrightnessController.unregisterCallbacks(); |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 565 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 566 | } |
| 567 | |
Jorim Jaggi | 1ecd7cd | 2014-11-03 16:18:03 +0100 | [diff] [blame] | 568 | public void refreshAllTiles() { |
yuemingw | eb2bf7d18 | 2018-01-23 16:05:08 +0000 | [diff] [blame] | 569 | mBrightnessController.checkRestrictionAndSetEnabled(); |
John Spurlock | 1a462c1 | 2014-07-14 10:52:01 -0400 | [diff] [blame] | 570 | for (TileRecord r : mRecords) { |
| 571 | r.tile.refreshState(); |
| 572 | } |
Jason Monk | 3d5f551 | 2014-07-25 11:17:28 -0400 | [diff] [blame] | 573 | mFooter.refreshState(); |
John Spurlock | 1a462c1 | 2014-07-14 10:52:01 -0400 | [diff] [blame] | 574 | } |
| 575 | |
Adrian Roos | 970be53 | 2014-11-21 15:50:16 +0100 | [diff] [blame] | 576 | public void showDetailAdapter(boolean show, DetailAdapter adapter, int[] locationInWindow) { |
| 577 | int xInWindow = locationInWindow[0]; |
| 578 | int yInWindow = locationInWindow[1]; |
Jason Monk | 377e7ad | 2016-02-16 14:03:21 -0500 | [diff] [blame] | 579 | ((View) getParent()).getLocationInWindow(locationInWindow); |
Adrian Roos | 970be53 | 2014-11-21 15:50:16 +0100 | [diff] [blame] | 580 | |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 581 | Record r = new Record(); |
| 582 | r.detailAdapter = adapter; |
Adrian Roos | 970be53 | 2014-11-21 15:50:16 +0100 | [diff] [blame] | 583 | r.x = xInWindow - locationInWindow[0]; |
| 584 | r.y = yInWindow - locationInWindow[1]; |
| 585 | |
| 586 | locationInWindow[0] = xInWindow; |
| 587 | locationInWindow[1] = yInWindow; |
| 588 | |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 589 | showDetail(show, r); |
| 590 | } |
| 591 | |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 592 | protected void showDetail(boolean show, Record r) { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 593 | mHandler.obtainMessage(H.SHOW_DETAIL, show ? 1 : 0, 0, r).sendToTarget(); |
| 594 | } |
| 595 | |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 596 | public void setTiles(Collection<QSTile> tiles) { |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 597 | setTiles(tiles, false); |
| 598 | } |
| 599 | |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 600 | public void setTiles(Collection<QSTile> tiles, boolean collapsedView) { |
Amin Shaikh | a07a17b | 2018-02-23 16:02:52 -0500 | [diff] [blame] | 601 | if (!collapsedView) { |
| 602 | mQsTileRevealController.updateRevealedTiles(tiles); |
| 603 | } |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 604 | for (TileRecord record : mRecords) { |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 605 | mTileLayout.removeTile(record); |
Xiaohui Chen | 08e266c | 2016-04-18 12:53:28 -0700 | [diff] [blame] | 606 | record.tile.removeCallback(record.callback); |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 607 | } |
| 608 | mRecords.clear(); |
Fabian Kozynski | ca30f57 | 2019-10-24 10:01:04 -0400 | [diff] [blame] | 609 | mCachedSpecs = ""; |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 610 | for (QSTile tile : tiles) { |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 611 | addTile(tile, collapsedView); |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 612 | } |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 613 | } |
| 614 | |
Jason Monk | ec87a87 | 2016-03-01 15:00:16 -0500 | [diff] [blame] | 615 | protected void drawTile(TileRecord r, QSTile.State state) { |
John Spurlock | 20c8905 | 2015-05-11 13:11:24 -0400 | [diff] [blame] | 616 | r.tileView.onStateChanged(state); |
| 617 | } |
| 618 | |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 619 | protected QSTileView createTileView(QSTile tile, boolean collapsedView) { |
| 620 | return mHost.createTileView(tile, collapsedView); |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 621 | } |
| 622 | |
Xiaohui Chen | 6644893 | 2016-04-18 12:53:28 -0700 | [diff] [blame] | 623 | protected boolean shouldShowDetail() { |
| 624 | return mExpanded; |
| 625 | } |
| 626 | |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 627 | protected TileRecord addTile(final QSTile tile, boolean collapsedView) { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 628 | final TileRecord r = new TileRecord(); |
| 629 | r.tile = tile; |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 630 | r.tileView = createTileView(tile, collapsedView); |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 631 | final QSTile.Callback callback = new QSTile.Callback() { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 632 | @Override |
| 633 | public void onStateChanged(QSTile.State state) { |
Jason Monk | 377e7ad | 2016-02-16 14:03:21 -0500 | [diff] [blame] | 634 | drawTile(r, state); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 635 | } |
Jason Monk | ca894a0 | 2016-01-12 15:30:22 -0500 | [diff] [blame] | 636 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 637 | @Override |
| 638 | public void onShowDetail(boolean show) { |
Xiaohui Chen | 6644893 | 2016-04-18 12:53:28 -0700 | [diff] [blame] | 639 | // Both the collapsed and full QS panels get this callback, this check determines |
| 640 | // which one should handle showing the detail. |
| 641 | if (shouldShowDetail()) { |
| 642 | QSPanel.this.showDetail(show, r); |
| 643 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 644 | } |
Jason Monk | ca894a0 | 2016-01-12 15:30:22 -0500 | [diff] [blame] | 645 | |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 646 | @Override |
| 647 | public void onToggleStateChanged(boolean state) { |
| 648 | if (mDetailRecord == r) { |
| 649 | fireToggleStateChanged(state); |
| 650 | } |
| 651 | } |
Jason Monk | ca894a0 | 2016-01-12 15:30:22 -0500 | [diff] [blame] | 652 | |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 653 | @Override |
| 654 | public void onScanStateChanged(boolean state) { |
John Spurlock | 465cefa | 2014-08-16 10:39:33 -0400 | [diff] [blame] | 655 | r.scanState = state; |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 656 | if (mDetailRecord == r) { |
John Spurlock | 465cefa | 2014-08-16 10:39:33 -0400 | [diff] [blame] | 657 | fireScanStateChanged(r.scanState); |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 658 | } |
| 659 | } |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 660 | |
| 661 | @Override |
| 662 | public void onAnnouncementRequested(CharSequence announcement) { |
dooyoung.hwang | 1b00662 | 2016-12-22 20:04:20 +0900 | [diff] [blame] | 663 | if (announcement != null) { |
| 664 | mHandler.obtainMessage(H.ANNOUNCE_FOR_ACCESSIBILITY, announcement) |
| 665 | .sendToTarget(); |
| 666 | } |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 667 | } |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 668 | }; |
Jason Monk | ca894a0 | 2016-01-12 15:30:22 -0500 | [diff] [blame] | 669 | r.tile.addCallback(callback); |
Xiaohui Chen | 08e266c | 2016-04-18 12:53:28 -0700 | [diff] [blame] | 670 | r.callback = callback; |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 671 | r.tileView.init(r.tile); |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 672 | r.tile.refreshState(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 673 | mRecords.add(r); |
Fabian Kozynski | ca30f57 | 2019-10-24 10:01:04 -0400 | [diff] [blame] | 674 | mCachedSpecs = getTilesSpecs(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 675 | |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 676 | if (mTileLayout != null) { |
| 677 | mTileLayout.addTile(r); |
| 678 | } |
Muyuan Li | b40004b | 2016-05-11 14:47:29 -0700 | [diff] [blame] | 679 | |
| 680 | return r; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 681 | } |
| 682 | |
Jason Monk | 2142843 | 2016-02-10 16:42:38 -0500 | [diff] [blame] | 683 | |
Jason Monk | 4bb7b1a | 2016-05-27 15:19:15 -0400 | [diff] [blame] | 684 | public void showEdit(final View v) { |
Jason Monk | 2142843 | 2016-02-10 16:42:38 -0500 | [diff] [blame] | 685 | v.post(new Runnable() { |
| 686 | @Override |
| 687 | public void run() { |
| 688 | if (mCustomizePanel != null) { |
| 689 | if (!mCustomizePanel.isCustomizing()) { |
Fabian Kozynski | 0db39af | 2018-08-31 15:56:45 -0400 | [diff] [blame] | 690 | int[] loc = v.getLocationOnScreen(); |
Jason Monk | 4bb7b1a | 2016-05-27 15:19:15 -0400 | [diff] [blame] | 691 | int x = loc[0] + v.getWidth() / 2; |
| 692 | int y = loc[1] + v.getHeight() / 2; |
Jason Monk | 2142843 | 2016-02-10 16:42:38 -0500 | [diff] [blame] | 693 | mCustomizePanel.show(x, y); |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | } |
| 698 | }); |
| 699 | } |
| 700 | |
John Spurlock | f7ae442 | 2014-08-01 12:45:18 -0400 | [diff] [blame] | 701 | public void closeDetail() { |
Yoshinori Hirano | 1dd7d07 | 2016-09-05 16:11:59 +0900 | [diff] [blame] | 702 | if (mCustomizePanel != null && mCustomizePanel.isShown()) { |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 703 | // Treat this as a detail panel for now, to make things easy. |
Fabian Kozynski | 0db39af | 2018-08-31 15:56:45 -0400 | [diff] [blame] | 704 | mCustomizePanel.hide(); |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 705 | return; |
| 706 | } |
John Spurlock | f7ae442 | 2014-08-01 12:45:18 -0400 | [diff] [blame] | 707 | showDetail(false, mDetailRecord); |
| 708 | } |
| 709 | |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 710 | public int getGridHeight() { |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 711 | return getMeasuredHeight(); |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 712 | } |
| 713 | |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 714 | protected void handleShowDetail(Record r, boolean show) { |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 715 | if (r instanceof TileRecord) { |
| 716 | handleShowDetailTile((TileRecord) r, show); |
| 717 | } else { |
Adrian Roos | 970be53 | 2014-11-21 15:50:16 +0100 | [diff] [blame] | 718 | int x = 0; |
| 719 | int y = 0; |
| 720 | if (r != null) { |
| 721 | x = r.x; |
| 722 | y = r.y; |
| 723 | } |
| 724 | handleShowDetailImpl(r, show, x, y); |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 725 | } |
| 726 | } |
| 727 | |
| 728 | private void handleShowDetailTile(TileRecord r, boolean show) { |
Jason Monk | efe3d3f | 2015-06-10 16:48:03 -0400 | [diff] [blame] | 729 | if ((mDetailRecord != null) == show && mDetailRecord == r) return; |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 730 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 731 | if (show) { |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 732 | r.detailAdapter = r.tile.getDetailAdapter(); |
| 733 | if (r.detailAdapter == null) return; |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 734 | } |
Jason Monk | 0d6a1c4 | 2015-04-20 16:38:51 -0400 | [diff] [blame] | 735 | r.tile.setDetailListening(show); |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 736 | int x = r.tileView.getLeft() + r.tileView.getWidth() / 2; |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 737 | int y = r.tileView.getDetailY() + mTileLayout.getOffsetTop(r) + getTop(); |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 738 | handleShowDetailImpl(r, show, x, y); |
| 739 | } |
| 740 | |
| 741 | private void handleShowDetailImpl(Record r, boolean show, int x, int y) { |
Jason Monk | 377e7ad | 2016-02-16 14:03:21 -0500 | [diff] [blame] | 742 | setDetailRecord(show ? r : null); |
| 743 | fireShowingDetail(show ? r.detailAdapter : null, x, y); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 744 | } |
| 745 | |
Muyuan Li | 4074b46 | 2016-05-06 13:40:42 -0700 | [diff] [blame] | 746 | protected void setDetailRecord(Record r) { |
Jason Monk | 377e7ad | 2016-02-16 14:03:21 -0500 | [diff] [blame] | 747 | if (r == mDetailRecord) return; |
| 748 | mDetailRecord = r; |
| 749 | final boolean scanState = mDetailRecord instanceof TileRecord |
| 750 | && ((TileRecord) mDetailRecord).scanState; |
| 751 | fireScanStateChanged(scanState); |
| 752 | } |
| 753 | |
| 754 | void setGridContentVisibility(boolean visible) { |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 755 | int newVis = visible ? VISIBLE : INVISIBLE; |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 756 | setVisibility(newVis); |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 757 | if (mGridContentVisible != visible) { |
Jason Monk | 8c09ac7 | 2017-03-16 11:53:40 -0400 | [diff] [blame] | 758 | mMetricsLogger.visibility(MetricsEvent.QS_PANEL, newVis); |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 759 | } |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 760 | mGridContentVisible = visible; |
| 761 | } |
| 762 | |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 763 | private void logTiles() { |
| 764 | for (int i = 0; i < mRecords.size(); i++) { |
Jason Monk | cb4b31d | 2017-05-03 10:37:34 -0400 | [diff] [blame] | 765 | QSTile tile = mRecords.get(i).tile; |
| 766 | mMetricsLogger.write(tile.populate(new LogMaker(tile.getMetricsCategory()) |
| 767 | .setType(MetricsEvent.TYPE_OPEN))); |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 768 | } |
| 769 | } |
| 770 | |
Jason Monk | 377e7ad | 2016-02-16 14:03:21 -0500 | [diff] [blame] | 771 | private void fireShowingDetail(DetailAdapter detail, int x, int y) { |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 772 | if (mCallback != null) { |
Jason Monk | 377e7ad | 2016-02-16 14:03:21 -0500 | [diff] [blame] | 773 | mCallback.onShowingDetail(detail, x, y); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 774 | } |
| 775 | } |
| 776 | |
| 777 | private void fireToggleStateChanged(boolean state) { |
| 778 | if (mCallback != null) { |
| 779 | mCallback.onToggleStateChanged(state); |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 780 | } |
| 781 | } |
| 782 | |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 783 | private void fireScanStateChanged(boolean state) { |
| 784 | if (mCallback != null) { |
| 785 | mCallback.onScanStateChanged(state); |
| 786 | } |
| 787 | } |
| 788 | |
Jason Monk | 7e53f20 | 2016-01-28 10:40:20 -0500 | [diff] [blame] | 789 | public void clickTile(ComponentName tile) { |
| 790 | final String spec = CustomTile.toSpec(tile); |
| 791 | final int N = mRecords.size(); |
| 792 | for (int i = 0; i < N; i++) { |
| 793 | if (mRecords.get(i).tile.getTileSpec().equals(spec)) { |
| 794 | mRecords.get(i).tile.click(); |
| 795 | break; |
| 796 | } |
| 797 | } |
| 798 | } |
| 799 | |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 800 | QSTileLayout getTileLayout() { |
| 801 | return mTileLayout; |
| 802 | } |
| 803 | |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 804 | QSTileView getTileView(QSTile tile) { |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 805 | for (TileRecord r : mRecords) { |
| 806 | if (r.tile == tile) { |
| 807 | return r.tileView; |
| 808 | } |
| 809 | } |
| 810 | return null; |
| 811 | } |
| 812 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 813 | public QSSecurityFooter getFooter() { |
Jason Monk | df36aed | 2016-07-25 11:21:56 -0400 | [diff] [blame] | 814 | return mFooter; |
| 815 | } |
| 816 | |
phweiss | a0cb251 | 2016-12-14 21:37:48 +0100 | [diff] [blame] | 817 | public void showDeviceMonitoringDialog() { |
| 818 | mFooter.showDeviceMonitoringDialog(); |
| 819 | } |
| 820 | |
Amin Shaikh | bc1a4e8 | 2018-04-16 12:14:35 -0400 | [diff] [blame] | 821 | public void setMargins(int sideMargins) { |
| 822 | for (int i = 0; i < getChildCount(); i++) { |
| 823 | View view = getChildAt(i); |
| 824 | if (view != mTileLayout) { |
| 825 | LayoutParams lp = (LayoutParams) view.getLayoutParams(); |
| 826 | lp.leftMargin = sideMargins; |
| 827 | lp.rightMargin = sideMargins; |
| 828 | } |
| 829 | } |
| 830 | } |
| 831 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 832 | private class H extends Handler { |
| 833 | private static final int SHOW_DETAIL = 1; |
| 834 | private static final int SET_TILE_VISIBILITY = 2; |
dooyoung.hwang | 1b00662 | 2016-12-22 20:04:20 +0900 | [diff] [blame] | 835 | private static final int ANNOUNCE_FOR_ACCESSIBILITY = 3; |
Jason Monk | cb4b31d | 2017-05-03 10:37:34 -0400 | [diff] [blame] | 836 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 837 | @Override |
| 838 | public void handleMessage(Message msg) { |
| 839 | if (msg.what == SHOW_DETAIL) { |
Jason Monk | cb4b31d | 2017-05-03 10:37:34 -0400 | [diff] [blame] | 840 | handleShowDetail((Record) msg.obj, msg.arg1 != 0); |
dooyoung.hwang | 1b00662 | 2016-12-22 20:04:20 +0900 | [diff] [blame] | 841 | } else if (msg.what == ANNOUNCE_FOR_ACCESSIBILITY) { |
Jason Monk | cb4b31d | 2017-05-03 10:37:34 -0400 | [diff] [blame] | 842 | announceForAccessibility((CharSequence) msg.obj); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 843 | } |
| 844 | } |
| 845 | } |
| 846 | |
Fabian Kozynski | 00d494d | 2019-04-04 09:53:50 -0400 | [diff] [blame] | 847 | @Override |
| 848 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 849 | pw.println(getClass().getSimpleName() + ":"); |
| 850 | pw.println(" Tile records:"); |
| 851 | for (TileRecord record : mRecords) { |
| 852 | if (record.tile instanceof Dumpable) { |
| 853 | pw.print(" "); ((Dumpable) record.tile).dump(fd, pw, args); |
| 854 | pw.print(" "); pw.println(record.tileView.toString()); |
| 855 | } |
| 856 | } |
| 857 | } |
| 858 | |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 859 | protected static class Record { |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 860 | DetailAdapter detailAdapter; |
Adrian Roos | 970be53 | 2014-11-21 15:50:16 +0100 | [diff] [blame] | 861 | int x; |
| 862 | int y; |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 863 | } |
| 864 | |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 865 | public static final class TileRecord extends Record { |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 866 | public QSTile tile; |
| 867 | public com.android.systemui.plugins.qs.QSTileView tileView; |
Jason Monk | 11a7744 | 2015-05-12 19:29:02 -0400 | [diff] [blame] | 868 | public boolean scanState; |
Xiaohui Chen | 08e266c | 2016-04-18 12:53:28 -0700 | [diff] [blame] | 869 | public QSTile.Callback callback; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 870 | } |
| 871 | |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 872 | public interface QSTileLayout { |
Fabian Kozynski | 407ddb2 | 2018-10-03 15:04:56 -0400 | [diff] [blame] | 873 | |
| 874 | default void saveInstanceState(Bundle outState) {} |
| 875 | |
| 876 | default void restoreInstanceState(Bundle savedInstanceState) {} |
| 877 | |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 878 | void addTile(TileRecord tile); |
Jason Monk | cb4b31d | 2017-05-03 10:37:34 -0400 | [diff] [blame] | 879 | |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 880 | void removeTile(TileRecord tile); |
Jason Monk | cb4b31d | 2017-05-03 10:37:34 -0400 | [diff] [blame] | 881 | |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 882 | int getOffsetTop(TileRecord tile); |
Jason Monk | cb4b31d | 2017-05-03 10:37:34 -0400 | [diff] [blame] | 883 | |
Jason Monk | 9d02a43 | 2016-01-20 16:33:46 -0500 | [diff] [blame] | 884 | boolean updateResources(); |
Jason Monk | 1bec6af | 2016-05-31 15:40:58 -0400 | [diff] [blame] | 885 | |
| 886 | void setListening(boolean listening); |
Amin Shaikh | 0f8ea543 | 2018-03-27 11:09:27 -0400 | [diff] [blame] | 887 | |
| 888 | default void setExpansion(float expansion) {} |
Fabian Kozynski | 802279f | 2018-09-07 13:44:54 -0400 | [diff] [blame] | 889 | |
| 890 | int getNumVisibleTiles(); |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 891 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 892 | } |