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 | |
Rohan Shah | 3090e79 | 2018-04-12 00:01:00 -0400 | [diff] [blame] | 19 | import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 20 | import static com.android.systemui.qs.tileimpl.QSTileImpl.getColorForState; |
| 21 | |
Rohan Shah | db2cfa3 | 2018-02-20 11:27:22 -0800 | [diff] [blame] | 22 | import android.annotation.Nullable; |
Jason Monk | 7e53f20 | 2016-01-28 10:40:20 -0500 | [diff] [blame] | 23 | import android.content.ComponentName; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 24 | import android.content.Context; |
Jorim Jaggi | e17c4b4 | 2014-08-26 17:27:31 +0200 | [diff] [blame] | 25 | import android.content.res.Configuration; |
John Spurlock | 4bf3198 | 2014-05-21 13:04:22 -0400 | [diff] [blame] | 26 | import android.content.res.Resources; |
Jason Monk | cb4b31d | 2017-05-03 10:37:34 -0400 | [diff] [blame] | 27 | import android.metrics.LogMaker; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 28 | import android.os.Handler; |
| 29 | import android.os.Message; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 30 | import android.service.quicksettings.Tile; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 31 | import android.util.AttributeSet; |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 32 | import android.view.LayoutInflater; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 33 | import android.view.View; |
Jason Monk | 520ea06 | 2015-08-18 14:53:06 -0400 | [diff] [blame] | 34 | import android.widget.LinearLayout; |
Jason Monk | cb4b31d | 2017-05-03 10:37:34 -0400 | [diff] [blame] | 35 | |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 36 | import com.android.internal.logging.MetricsLogger; |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 37 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Jason Monk | 824ffff | 2017-04-11 15:49:06 -0400 | [diff] [blame] | 38 | import com.android.settingslib.Utils; |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 39 | import com.android.systemui.Dependency; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 40 | import com.android.systemui.R; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 41 | import com.android.systemui.plugins.qs.DetailAdapter; |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 42 | import com.android.systemui.plugins.qs.QSTile; |
| 43 | import com.android.systemui.plugins.qs.QSTileView; |
| 44 | import com.android.systemui.qs.QSHost.Callback; |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 45 | import com.android.systemui.qs.customize.QSCustomizer; |
Jason Monk | 7e53f20 | 2016-01-28 10:40:20 -0500 | [diff] [blame] | 46 | import com.android.systemui.qs.external.CustomTile; |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 47 | import com.android.systemui.settings.BrightnessController; |
Muyuan Li | 3b0f892 | 2016-04-18 19:27:29 -0700 | [diff] [blame] | 48 | import com.android.systemui.settings.ToggleSliderView; |
Adrian Roos | 5fd872e | 2014-08-12 17:28:58 +0200 | [diff] [blame] | 49 | import com.android.systemui.statusbar.policy.BrightnessMirrorController; |
Adrian Roos | b01793f | 2017-08-09 14:34:55 +0200 | [diff] [blame] | 50 | import com.android.systemui.statusbar.policy.BrightnessMirrorController.BrightnessMirrorListener; |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 51 | import com.android.systemui.tuner.TunerService; |
| 52 | import com.android.systemui.tuner.TunerService.Tunable; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 53 | |
| 54 | import java.util.ArrayList; |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 55 | import java.util.Collection; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 56 | |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 57 | /** View that represents the quick settings tile panel (when expanded/pulled down). **/ |
Adrian Roos | b01793f | 2017-08-09 14:34:55 +0200 | [diff] [blame] | 58 | public class QSPanel extends LinearLayout implements Tunable, Callback, BrightnessMirrorListener { |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 59 | |
| 60 | public static final String QS_SHOW_BRIGHTNESS = "qs_show_brightness"; |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 61 | public static final String QS_SHOW_HEADER = "qs_show_header"; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 62 | |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 63 | protected final Context mContext; |
Amin Shaikh | a07a17b | 2018-02-23 16:02:52 -0500 | [diff] [blame] | 64 | protected final ArrayList<TileRecord> mRecords = new ArrayList<>(); |
Jason Monk | 11a7744 | 2015-05-12 19:29:02 -0400 | [diff] [blame] | 65 | protected final View mBrightnessView; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 66 | private final H mHandler = new H(); |
Jason Monk | 8c09ac7 | 2017-03-16 11:53:40 -0400 | [diff] [blame] | 67 | private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class); |
Amin Shaikh | a07a17b | 2018-02-23 16:02:52 -0500 | [diff] [blame] | 68 | private final QSTileRevealController mQsTileRevealController; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 69 | |
Muyuan Li | 0e9f538 | 2016-04-27 15:51:15 -0700 | [diff] [blame] | 70 | protected boolean mExpanded; |
Jason Monk | 1bec6af | 2016-05-31 15:40:58 -0400 | [diff] [blame] | 71 | protected boolean mListening; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 72 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 73 | private QSDetail.Callback mCallback; |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 74 | private BrightnessController mBrightnessController; |
Jason Monk | bbadff8 | 2015-11-06 15:47:26 -0500 | [diff] [blame] | 75 | protected QSTileHost mHost; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 76 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 77 | protected QSSecurityFooter mFooter; |
Rohan Shah | 3090e79 | 2018-04-12 00:01:00 -0400 | [diff] [blame] | 78 | private PageIndicator mPanelPageIndicator; |
| 79 | private PageIndicator mFooterPageIndicator; |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 80 | private boolean mGridContentVisible = true; |
Jason Monk | 3d5f551 | 2014-07-25 11:17:28 -0400 | [diff] [blame] | 81 | |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 82 | protected QSTileLayout mTileLayout; |
| 83 | |
| 84 | private QSCustomizer mCustomizePanel; |
Jason Monk | 377e7ad | 2016-02-16 14:03:21 -0500 | [diff] [blame] | 85 | private Record mDetailRecord; |
Jason Monk | 520ea06 | 2015-08-18 14:53:06 -0400 | [diff] [blame] | 86 | |
Adrian Roos | 429c962 | 2016-06-15 13:02:17 -0700 | [diff] [blame] | 87 | private BrightnessMirrorController mBrightnessMirrorController; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 88 | private View mDivider; |
Adrian Roos | 429c962 | 2016-06-15 13:02:17 -0700 | [diff] [blame] | 89 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 90 | public QSPanel(Context context) { |
| 91 | this(context, null); |
| 92 | } |
| 93 | |
| 94 | public QSPanel(Context context, AttributeSet attrs) { |
| 95 | super(context, attrs); |
| 96 | mContext = context; |
| 97 | |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 98 | setOrientation(VERTICAL); |
Jason Monk | 520ea06 | 2015-08-18 14:53:06 -0400 | [diff] [blame] | 99 | |
Jason Monk | 231b052 | 2018-01-04 10:49:55 -0500 | [diff] [blame] | 100 | mBrightnessView = LayoutInflater.from(mContext).inflate( |
| 101 | R.layout.quick_settings_brightness_dialog, this, false); |
Amin Shaikh | 15781d6 | 2018-02-16 16:00:13 -0500 | [diff] [blame] | 102 | addView(mBrightnessView); |
| 103 | |
| 104 | mTileLayout = (QSTileLayout) LayoutInflater.from(mContext).inflate( |
| 105 | R.layout.qs_paged_tile_layout, this, false); |
Jason Monk | 231b052 | 2018-01-04 10:49:55 -0500 | [diff] [blame] | 106 | mTileLayout.setListening(mListening); |
Amin Shaikh | 15781d6 | 2018-02-16 16:00:13 -0500 | [diff] [blame] | 107 | addView((View) mTileLayout); |
| 108 | |
Rohan Shah | 3090e79 | 2018-04-12 00:01:00 -0400 | [diff] [blame] | 109 | mPanelPageIndicator = (PageIndicator) LayoutInflater.from(context).inflate( |
Amin Shaikh | 15781d6 | 2018-02-16 16:00:13 -0500 | [diff] [blame] | 110 | R.layout.qs_page_indicator, this, false); |
Rohan Shah | 3090e79 | 2018-04-12 00:01:00 -0400 | [diff] [blame] | 111 | addView(mPanelPageIndicator); |
Amin Shaikh | 15781d6 | 2018-02-16 16:00:13 -0500 | [diff] [blame] | 112 | |
Rohan Shah | 3090e79 | 2018-04-12 00:01:00 -0400 | [diff] [blame] | 113 | ((PagedTileLayout) mTileLayout).setPageIndicator(mPanelPageIndicator); |
Amin Shaikh | a07a17b | 2018-02-23 16:02:52 -0500 | [diff] [blame] | 114 | mQsTileRevealController = new QSTileRevealController(mContext, this, |
Rohan Shah | 3090e79 | 2018-04-12 00:01:00 -0400 | [diff] [blame] | 115 | (PagedTileLayout) mTileLayout); |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 116 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 117 | addDivider(); |
| 118 | |
phweiss | 4f70f10 | 2017-04-12 19:32:55 +0200 | [diff] [blame] | 119 | mFooter = new QSSecurityFooter(this, context); |
| 120 | addView(mFooter.getView()); |
| 121 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 122 | updateResources(); |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 123 | |
| 124 | mBrightnessController = new BrightnessController(getContext(), |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 125 | findViewById(R.id.brightness_icon), |
| 126 | findViewById(R.id.brightness_slider)); |
| 127 | } |
| 128 | |
| 129 | protected void addDivider() { |
| 130 | mDivider = LayoutInflater.from(mContext).inflate(R.layout.qs_divider, this, false); |
Jason Monk | 824ffff | 2017-04-11 15:49:06 -0400 | [diff] [blame] | 131 | mDivider.setBackgroundColor(Utils.applyAlpha(mDivider.getAlpha(), |
| 132 | getColorForState(mContext, Tile.STATE_ACTIVE))); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 133 | addView(mDivider); |
| 134 | } |
| 135 | |
| 136 | public View getDivider() { |
| 137 | return mDivider; |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 138 | } |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 139 | |
Amin Shaikh | 15781d6 | 2018-02-16 16:00:13 -0500 | [diff] [blame] | 140 | public View getPageIndicator() { |
Rohan Shah | 3090e79 | 2018-04-12 00:01:00 -0400 | [diff] [blame] | 141 | return mPanelPageIndicator; |
Amin Shaikh | 15781d6 | 2018-02-16 16:00:13 -0500 | [diff] [blame] | 142 | } |
| 143 | |
Amin Shaikh | a07a17b | 2018-02-23 16:02:52 -0500 | [diff] [blame] | 144 | public QSTileRevealController getQsTileRevealController() { |
| 145 | return mQsTileRevealController; |
| 146 | } |
| 147 | |
Jason Monk | 377e7ad | 2016-02-16 14:03:21 -0500 | [diff] [blame] | 148 | public boolean isShowingCustomize() { |
| 149 | return mCustomizePanel != null && mCustomizePanel.isCustomizing(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 150 | } |
| 151 | |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 152 | @Override |
| 153 | protected void onAttachedToWindow() { |
| 154 | super.onAttachedToWindow(); |
Rohan Shah | db2cfa3 | 2018-02-20 11:27:22 -0800 | [diff] [blame] | 155 | final TunerService tunerService = Dependency.get(TunerService.class); |
| 156 | tunerService.addTunable(this, QS_SHOW_BRIGHTNESS); |
Rohan Shah | db2cfa3 | 2018-02-20 11:27:22 -0800 | [diff] [blame] | 157 | |
Jason Monk | f160edca | 2016-03-30 13:48:56 -0400 | [diff] [blame] | 158 | if (mHost != null) { |
| 159 | setTiles(mHost.getTiles()); |
| 160 | } |
Adrian Roos | b01793f | 2017-08-09 14:34:55 +0200 | [diff] [blame] | 161 | if (mBrightnessMirrorController != null) { |
| 162 | mBrightnessMirrorController.addCallback(this); |
| 163 | } |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | @Override |
| 167 | protected void onDetachedFromWindow() { |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 168 | Dependency.get(TunerService.class).removeTunable(this); |
| 169 | if (mHost != null) { |
| 170 | mHost.removeCallback(this); |
| 171 | } |
Jason Monk | f160edca | 2016-03-30 13:48:56 -0400 | [diff] [blame] | 172 | for (TileRecord record : mRecords) { |
| 173 | record.tile.removeCallbacks(); |
| 174 | } |
Adrian Roos | b01793f | 2017-08-09 14:34:55 +0200 | [diff] [blame] | 175 | if (mBrightnessMirrorController != null) { |
| 176 | mBrightnessMirrorController.removeCallback(this); |
| 177 | } |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 178 | super.onDetachedFromWindow(); |
| 179 | } |
| 180 | |
| 181 | @Override |
Jason Monk | 46dbfb4 | 2016-02-25 14:59:20 -0500 | [diff] [blame] | 182 | public void onTilesChanged() { |
| 183 | setTiles(mHost.getTiles()); |
| 184 | } |
| 185 | |
| 186 | @Override |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 187 | public void onTuningChanged(String key, String newValue) { |
| 188 | if (QS_SHOW_BRIGHTNESS.equals(key)) { |
Rohan Shah | db2cfa3 | 2018-02-20 11:27:22 -0800 | [diff] [blame] | 189 | updateViewVisibilityForTuningValue(mBrightnessView, newValue); |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | |
Rohan Shah | db2cfa3 | 2018-02-20 11:27:22 -0800 | [diff] [blame] | 193 | private void updateViewVisibilityForTuningValue(View view, @Nullable String newValue) { |
Henrik Baard | a2c86e8 | 2019-03-14 12:23:04 +0100 | [diff] [blame^] | 194 | view.setVisibility(TunerService.parseIntegerSwitch(newValue, true) ? VISIBLE : GONE); |
Rohan Shah | db2cfa3 | 2018-02-20 11:27:22 -0800 | [diff] [blame] | 195 | } |
| 196 | |
Jason Monk | a992732 | 2015-12-13 16:22:37 -0500 | [diff] [blame] | 197 | public void openDetails(String subPanel) { |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 198 | QSTile tile = getTile(subPanel); |
Jason Monk | cb4b31d | 2017-05-03 10:37:34 -0400 | [diff] [blame] | 199 | showDetailAdapter(true, tile.getDetailAdapter(), new int[]{getWidth() / 2, 0}); |
Jason Monk | a992732 | 2015-12-13 16:22:37 -0500 | [diff] [blame] | 200 | } |
| 201 | |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 202 | private QSTile getTile(String subPanel) { |
Jason Monk | a992732 | 2015-12-13 16:22:37 -0500 | [diff] [blame] | 203 | for (int i = 0; i < mRecords.size(); i++) { |
| 204 | if (subPanel.equals(mRecords.get(i).tile.getTileSpec())) { |
| 205 | return mRecords.get(i).tile; |
| 206 | } |
| 207 | } |
| 208 | return mHost.createTile(subPanel); |
| 209 | } |
| 210 | |
Adrian Roos | 5fd872e | 2014-08-12 17:28:58 +0200 | [diff] [blame] | 211 | public void setBrightnessMirror(BrightnessMirrorController c) { |
Adrian Roos | b01793f | 2017-08-09 14:34:55 +0200 | [diff] [blame] | 212 | if (mBrightnessMirrorController != null) { |
| 213 | mBrightnessMirrorController.removeCallback(this); |
| 214 | } |
Adrian Roos | 429c962 | 2016-06-15 13:02:17 -0700 | [diff] [blame] | 215 | mBrightnessMirrorController = c; |
Adrian Roos | b01793f | 2017-08-09 14:34:55 +0200 | [diff] [blame] | 216 | if (mBrightnessMirrorController != null) { |
| 217 | mBrightnessMirrorController.addCallback(this); |
| 218 | } |
| 219 | updateBrightnessMirror(); |
| 220 | } |
| 221 | |
| 222 | @Override |
| 223 | public void onBrightnessMirrorReinflated(View brightnessMirror) { |
| 224 | updateBrightnessMirror(); |
Adrian Roos | 5fd872e | 2014-08-12 17:28:58 +0200 | [diff] [blame] | 225 | } |
| 226 | |
Jason Monk | b46059a | 2016-06-30 14:22:42 -0400 | [diff] [blame] | 227 | View getBrightnessView() { |
| 228 | return mBrightnessView; |
| 229 | } |
| 230 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 231 | public void setCallback(QSDetail.Callback callback) { |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 232 | mCallback = callback; |
| 233 | } |
| 234 | |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 235 | public void setHost(QSTileHost host, QSCustomizer customizer) { |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 236 | mHost = host; |
Jason Monk | 46dbfb4 | 2016-02-25 14:59:20 -0500 | [diff] [blame] | 237 | mHost.addCallback(this); |
| 238 | setTiles(mHost.getTiles()); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 239 | mFooter.setHostEnvironment(host); |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 240 | mCustomizePanel = customizer; |
| 241 | if (mCustomizePanel != null) { |
| 242 | mCustomizePanel.setHost(mHost); |
| 243 | } |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 244 | } |
| 245 | |
Rohan Shah | 3090e79 | 2018-04-12 00:01:00 -0400 | [diff] [blame] | 246 | /** |
| 247 | * Links the footer's page indicator, which is used in landscape orientation to save space. |
| 248 | * |
| 249 | * @param pageIndicator indicator to use for page scrolling |
| 250 | */ |
| 251 | public void setFooterPageIndicator(PageIndicator pageIndicator) { |
| 252 | if (mTileLayout instanceof PagedTileLayout) { |
| 253 | mFooterPageIndicator = pageIndicator; |
| 254 | updatePageIndicator(); |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | private void updatePageIndicator() { |
| 259 | if (mTileLayout instanceof PagedTileLayout) { |
| 260 | // If we're in landscape, and we have the footer page indicator (which we should if the |
| 261 | // footer has been initialized & linked), then we'll show the footer page indicator to |
| 262 | // save space in the main QS tile area. Otherwise, we'll use the default one under the |
| 263 | // tiles/above the footer. |
| 264 | boolean shouldUseFooterPageIndicator = |
| 265 | getResources().getConfiguration().orientation == ORIENTATION_LANDSCAPE |
| 266 | && mFooterPageIndicator != null; |
| 267 | |
| 268 | mPanelPageIndicator.setVisibility(View.GONE); |
| 269 | if (mFooterPageIndicator != null) { |
| 270 | mFooterPageIndicator.setVisibility(View.GONE); |
| 271 | } |
| 272 | |
| 273 | ((PagedTileLayout) mTileLayout).setPageIndicator( |
| 274 | shouldUseFooterPageIndicator ? mFooterPageIndicator : mPanelPageIndicator); |
| 275 | } |
| 276 | } |
| 277 | |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 278 | public QSTileHost getHost() { |
| 279 | return mHost; |
| 280 | } |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 281 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 282 | public void updateResources() { |
John Spurlock | 4bf3198 | 2014-05-21 13:04:22 -0400 | [diff] [blame] | 283 | final Resources res = mContext.getResources(); |
Rohan Shah | d3cf756 | 2018-02-23 11:12:28 -0800 | [diff] [blame] | 284 | 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] | 285 | |
| 286 | updatePageIndicator(); |
| 287 | |
John Spurlock | 1a462c1 | 2014-07-14 10:52:01 -0400 | [diff] [blame] | 288 | if (mListening) { |
| 289 | refreshAllTiles(); |
| 290 | } |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 291 | if (mTileLayout != null) { |
| 292 | mTileLayout.updateResources(); |
| 293 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 294 | } |
| 295 | |
Jorim Jaggi | e17c4b4 | 2014-08-26 17:27:31 +0200 | [diff] [blame] | 296 | @Override |
| 297 | protected void onConfigurationChanged(Configuration newConfig) { |
| 298 | super.onConfigurationChanged(newConfig); |
Jorim Jaggi | e17c4b4 | 2014-08-26 17:27:31 +0200 | [diff] [blame] | 299 | mFooter.onConfigurationChanged(); |
Adrian Roos | 429c962 | 2016-06-15 13:02:17 -0700 | [diff] [blame] | 300 | |
Adrian Roos | b01793f | 2017-08-09 14:34:55 +0200 | [diff] [blame] | 301 | updateBrightnessMirror(); |
| 302 | } |
| 303 | |
| 304 | public void updateBrightnessMirror() { |
Adrian Roos | 429c962 | 2016-06-15 13:02:17 -0700 | [diff] [blame] | 305 | if (mBrightnessMirrorController != null) { |
Adrian Roos | b01793f | 2017-08-09 14:34:55 +0200 | [diff] [blame] | 306 | ToggleSliderView brightnessSlider = findViewById(R.id.brightness_slider); |
| 307 | ToggleSliderView mirrorSlider = mBrightnessMirrorController.getMirror() |
| 308 | .findViewById(R.id.brightness_slider); |
| 309 | brightnessSlider.setMirror(mirrorSlider); |
| 310 | brightnessSlider.setMirrorController(mBrightnessMirrorController); |
Adrian Roos | 429c962 | 2016-06-15 13:02:17 -0700 | [diff] [blame] | 311 | } |
Jorim Jaggi | e17c4b4 | 2014-08-26 17:27:31 +0200 | [diff] [blame] | 312 | } |
| 313 | |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 314 | public void onCollapse() { |
Yoshinori Hirano | 1dd7d07 | 2016-09-05 16:11:59 +0900 | [diff] [blame] | 315 | if (mCustomizePanel != null && mCustomizePanel.isShown()) { |
Jason Monk | b9c0019 | 2015-10-07 11:45:33 -0400 | [diff] [blame] | 316 | mCustomizePanel.hide(mCustomizePanel.getWidth() / 2, mCustomizePanel.getHeight() / 2); |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 320 | public void setExpanded(boolean expanded) { |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 321 | if (mExpanded == expanded) return; |
| 322 | mExpanded = expanded; |
Amin Shaikh | 15781d6 | 2018-02-16 16:00:13 -0500 | [diff] [blame] | 323 | if (!mExpanded && mTileLayout instanceof PagedTileLayout) { |
| 324 | ((PagedTileLayout) mTileLayout).setCurrentItem(0, false); |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 325 | } |
Jason Monk | 8c09ac7 | 2017-03-16 11:53:40 -0400 | [diff] [blame] | 326 | mMetricsLogger.visibility(MetricsEvent.QS_PANEL, mExpanded); |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 327 | if (!mExpanded) { |
John Spurlock | f7ae442 | 2014-08-01 12:45:18 -0400 | [diff] [blame] | 328 | closeDetail(); |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 329 | } else { |
| 330 | logTiles(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 331 | } |
Jorim Jaggi | e65e310 | 2014-07-01 22:00:50 +0200 | [diff] [blame] | 332 | } |
| 333 | |
Amin Shaikh | 5da602f | 2018-02-02 15:00:25 -0500 | [diff] [blame] | 334 | public void setPageListener(final PagedTileLayout.PageListener pageListener) { |
| 335 | if (mTileLayout instanceof PagedTileLayout) { |
| 336 | ((PagedTileLayout) mTileLayout).setPageListener(pageListener); |
Amin Shaikh | 5da602f | 2018-02-02 15:00:25 -0500 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | |
Muyuan Li | 0e9f538 | 2016-04-27 15:51:15 -0700 | [diff] [blame] | 340 | public boolean isExpanded() { |
| 341 | return mExpanded; |
| 342 | } |
| 343 | |
Jorim Jaggi | e65e310 | 2014-07-01 22:00:50 +0200 | [diff] [blame] | 344 | public void setListening(boolean listening) { |
| 345 | if (mListening == listening) return; |
| 346 | mListening = listening; |
Jason Monk | 1bec6af | 2016-05-31 15:40:58 -0400 | [diff] [blame] | 347 | if (mTileLayout != null) { |
| 348 | mTileLayout.setListening(listening); |
John Spurlock | 1a462c1 | 2014-07-14 10:52:01 -0400 | [diff] [blame] | 349 | } |
Jason Monk | 3d5f551 | 2014-07-25 11:17:28 -0400 | [diff] [blame] | 350 | mFooter.setListening(mListening); |
John Spurlock | 1a462c1 | 2014-07-14 10:52:01 -0400 | [diff] [blame] | 351 | if (mListening) { |
| 352 | refreshAllTiles(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 353 | } |
Jason Monk | b5ece9a | 2016-04-22 11:40:36 -0400 | [diff] [blame] | 354 | if (mBrightnessView.getVisibility() == View.VISIBLE) { |
| 355 | if (listening) { |
| 356 | mBrightnessController.registerCallbacks(); |
| 357 | } else { |
| 358 | mBrightnessController.unregisterCallbacks(); |
| 359 | } |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 360 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 361 | } |
| 362 | |
Jorim Jaggi | 1ecd7cd | 2014-11-03 16:18:03 +0100 | [diff] [blame] | 363 | public void refreshAllTiles() { |
yuemingw | eb2bf7d18 | 2018-01-23 16:05:08 +0000 | [diff] [blame] | 364 | mBrightnessController.checkRestrictionAndSetEnabled(); |
John Spurlock | 1a462c1 | 2014-07-14 10:52:01 -0400 | [diff] [blame] | 365 | for (TileRecord r : mRecords) { |
| 366 | r.tile.refreshState(); |
| 367 | } |
Jason Monk | 3d5f551 | 2014-07-25 11:17:28 -0400 | [diff] [blame] | 368 | mFooter.refreshState(); |
John Spurlock | 1a462c1 | 2014-07-14 10:52:01 -0400 | [diff] [blame] | 369 | } |
| 370 | |
Adrian Roos | 970be53 | 2014-11-21 15:50:16 +0100 | [diff] [blame] | 371 | public void showDetailAdapter(boolean show, DetailAdapter adapter, int[] locationInWindow) { |
| 372 | int xInWindow = locationInWindow[0]; |
| 373 | int yInWindow = locationInWindow[1]; |
Jason Monk | 377e7ad | 2016-02-16 14:03:21 -0500 | [diff] [blame] | 374 | ((View) getParent()).getLocationInWindow(locationInWindow); |
Adrian Roos | 970be53 | 2014-11-21 15:50:16 +0100 | [diff] [blame] | 375 | |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 376 | Record r = new Record(); |
| 377 | r.detailAdapter = adapter; |
Adrian Roos | 970be53 | 2014-11-21 15:50:16 +0100 | [diff] [blame] | 378 | r.x = xInWindow - locationInWindow[0]; |
| 379 | r.y = yInWindow - locationInWindow[1]; |
| 380 | |
| 381 | locationInWindow[0] = xInWindow; |
| 382 | locationInWindow[1] = yInWindow; |
| 383 | |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 384 | showDetail(show, r); |
| 385 | } |
| 386 | |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 387 | protected void showDetail(boolean show, Record r) { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 388 | mHandler.obtainMessage(H.SHOW_DETAIL, show ? 1 : 0, 0, r).sendToTarget(); |
| 389 | } |
| 390 | |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 391 | public void setTiles(Collection<QSTile> tiles) { |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 392 | setTiles(tiles, false); |
| 393 | } |
| 394 | |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 395 | public void setTiles(Collection<QSTile> tiles, boolean collapsedView) { |
Amin Shaikh | a07a17b | 2018-02-23 16:02:52 -0500 | [diff] [blame] | 396 | if (!collapsedView) { |
| 397 | mQsTileRevealController.updateRevealedTiles(tiles); |
| 398 | } |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 399 | for (TileRecord record : mRecords) { |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 400 | mTileLayout.removeTile(record); |
Xiaohui Chen | 08e266c | 2016-04-18 12:53:28 -0700 | [diff] [blame] | 401 | record.tile.removeCallback(record.callback); |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 402 | } |
| 403 | mRecords.clear(); |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 404 | for (QSTile tile : tiles) { |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 405 | addTile(tile, collapsedView); |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 406 | } |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 407 | } |
| 408 | |
Jason Monk | ec87a87 | 2016-03-01 15:00:16 -0500 | [diff] [blame] | 409 | protected void drawTile(TileRecord r, QSTile.State state) { |
John Spurlock | 20c8905 | 2015-05-11 13:11:24 -0400 | [diff] [blame] | 410 | r.tileView.onStateChanged(state); |
| 411 | } |
| 412 | |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 413 | protected QSTileView createTileView(QSTile tile, boolean collapsedView) { |
| 414 | return mHost.createTileView(tile, collapsedView); |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 415 | } |
| 416 | |
Xiaohui Chen | 6644893 | 2016-04-18 12:53:28 -0700 | [diff] [blame] | 417 | protected boolean shouldShowDetail() { |
| 418 | return mExpanded; |
| 419 | } |
| 420 | |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 421 | protected TileRecord addTile(final QSTile tile, boolean collapsedView) { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 422 | final TileRecord r = new TileRecord(); |
| 423 | r.tile = tile; |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 424 | r.tileView = createTileView(tile, collapsedView); |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 425 | final QSTile.Callback callback = new QSTile.Callback() { |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 426 | @Override |
| 427 | public void onStateChanged(QSTile.State state) { |
Jason Monk | 377e7ad | 2016-02-16 14:03:21 -0500 | [diff] [blame] | 428 | drawTile(r, state); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 429 | } |
Jason Monk | ca894a0 | 2016-01-12 15:30:22 -0500 | [diff] [blame] | 430 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 431 | @Override |
| 432 | public void onShowDetail(boolean show) { |
Xiaohui Chen | 6644893 | 2016-04-18 12:53:28 -0700 | [diff] [blame] | 433 | // Both the collapsed and full QS panels get this callback, this check determines |
| 434 | // which one should handle showing the detail. |
| 435 | if (shouldShowDetail()) { |
| 436 | QSPanel.this.showDetail(show, r); |
| 437 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 438 | } |
Jason Monk | ca894a0 | 2016-01-12 15:30:22 -0500 | [diff] [blame] | 439 | |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 440 | @Override |
| 441 | public void onToggleStateChanged(boolean state) { |
| 442 | if (mDetailRecord == r) { |
| 443 | fireToggleStateChanged(state); |
| 444 | } |
| 445 | } |
Jason Monk | ca894a0 | 2016-01-12 15:30:22 -0500 | [diff] [blame] | 446 | |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 447 | @Override |
| 448 | public void onScanStateChanged(boolean state) { |
John Spurlock | 465cefa | 2014-08-16 10:39:33 -0400 | [diff] [blame] | 449 | r.scanState = state; |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 450 | if (mDetailRecord == r) { |
John Spurlock | 465cefa | 2014-08-16 10:39:33 -0400 | [diff] [blame] | 451 | fireScanStateChanged(r.scanState); |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 452 | } |
| 453 | } |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 454 | |
| 455 | @Override |
| 456 | public void onAnnouncementRequested(CharSequence announcement) { |
dooyoung.hwang | 1b00662 | 2016-12-22 20:04:20 +0900 | [diff] [blame] | 457 | if (announcement != null) { |
| 458 | mHandler.obtainMessage(H.ANNOUNCE_FOR_ACCESSIBILITY, announcement) |
| 459 | .sendToTarget(); |
| 460 | } |
Selim Cinek | 4fda7b2 | 2014-08-18 22:07:25 +0200 | [diff] [blame] | 461 | } |
John Spurlock | bceed06 | 2014-08-10 18:04:16 -0400 | [diff] [blame] | 462 | }; |
Jason Monk | ca894a0 | 2016-01-12 15:30:22 -0500 | [diff] [blame] | 463 | r.tile.addCallback(callback); |
Xiaohui Chen | 08e266c | 2016-04-18 12:53:28 -0700 | [diff] [blame] | 464 | r.callback = callback; |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 465 | r.tileView.init(r.tile); |
John Spurlock | ccb6b9a | 2014-05-17 15:54:40 -0400 | [diff] [blame] | 466 | r.tile.refreshState(); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 467 | mRecords.add(r); |
| 468 | |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 469 | if (mTileLayout != null) { |
| 470 | mTileLayout.addTile(r); |
| 471 | } |
Muyuan Li | b40004b | 2016-05-11 14:47:29 -0700 | [diff] [blame] | 472 | |
| 473 | return r; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 474 | } |
| 475 | |
Jason Monk | 2142843 | 2016-02-10 16:42:38 -0500 | [diff] [blame] | 476 | |
Jason Monk | 4bb7b1a | 2016-05-27 15:19:15 -0400 | [diff] [blame] | 477 | public void showEdit(final View v) { |
Jason Monk | 2142843 | 2016-02-10 16:42:38 -0500 | [diff] [blame] | 478 | v.post(new Runnable() { |
| 479 | @Override |
| 480 | public void run() { |
| 481 | if (mCustomizePanel != null) { |
| 482 | if (!mCustomizePanel.isCustomizing()) { |
| 483 | int[] loc = new int[2]; |
| 484 | v.getLocationInWindow(loc); |
Jason Monk | 4bb7b1a | 2016-05-27 15:19:15 -0400 | [diff] [blame] | 485 | int x = loc[0] + v.getWidth() / 2; |
| 486 | int y = loc[1] + v.getHeight() / 2; |
Jason Monk | 2142843 | 2016-02-10 16:42:38 -0500 | [diff] [blame] | 487 | mCustomizePanel.show(x, y); |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | } |
| 492 | }); |
| 493 | } |
| 494 | |
John Spurlock | f7ae442 | 2014-08-01 12:45:18 -0400 | [diff] [blame] | 495 | public void closeDetail() { |
Yoshinori Hirano | 1dd7d07 | 2016-09-05 16:11:59 +0900 | [diff] [blame] | 496 | if (mCustomizePanel != null && mCustomizePanel.isShown()) { |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 497 | // Treat this as a detail panel for now, to make things easy. |
Jason Monk | b9c0019 | 2015-10-07 11:45:33 -0400 | [diff] [blame] | 498 | mCustomizePanel.hide(mCustomizePanel.getWidth() / 2, mCustomizePanel.getHeight() / 2); |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 499 | return; |
| 500 | } |
John Spurlock | f7ae442 | 2014-08-01 12:45:18 -0400 | [diff] [blame] | 501 | showDetail(false, mDetailRecord); |
| 502 | } |
| 503 | |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 504 | public int getGridHeight() { |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 505 | return getMeasuredHeight(); |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 506 | } |
| 507 | |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 508 | protected void handleShowDetail(Record r, boolean show) { |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 509 | if (r instanceof TileRecord) { |
| 510 | handleShowDetailTile((TileRecord) r, show); |
| 511 | } else { |
Adrian Roos | 970be53 | 2014-11-21 15:50:16 +0100 | [diff] [blame] | 512 | int x = 0; |
| 513 | int y = 0; |
| 514 | if (r != null) { |
| 515 | x = r.x; |
| 516 | y = r.y; |
| 517 | } |
| 518 | handleShowDetailImpl(r, show, x, y); |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 519 | } |
| 520 | } |
| 521 | |
| 522 | private void handleShowDetailTile(TileRecord r, boolean show) { |
Jason Monk | efe3d3f | 2015-06-10 16:48:03 -0400 | [diff] [blame] | 523 | if ((mDetailRecord != null) == show && mDetailRecord == r) return; |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 524 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 525 | if (show) { |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 526 | r.detailAdapter = r.tile.getDetailAdapter(); |
| 527 | if (r.detailAdapter == null) return; |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 528 | } |
Jason Monk | 0d6a1c4 | 2015-04-20 16:38:51 -0400 | [diff] [blame] | 529 | r.tile.setDetailListening(show); |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 530 | int x = r.tileView.getLeft() + r.tileView.getWidth() / 2; |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 531 | int y = r.tileView.getDetailY() + mTileLayout.getOffsetTop(r) + getTop(); |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 532 | handleShowDetailImpl(r, show, x, y); |
| 533 | } |
| 534 | |
| 535 | private void handleShowDetailImpl(Record r, boolean show, int x, int y) { |
Jason Monk | 377e7ad | 2016-02-16 14:03:21 -0500 | [diff] [blame] | 536 | setDetailRecord(show ? r : null); |
| 537 | fireShowingDetail(show ? r.detailAdapter : null, x, y); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 538 | } |
| 539 | |
Muyuan Li | 4074b46 | 2016-05-06 13:40:42 -0700 | [diff] [blame] | 540 | protected void setDetailRecord(Record r) { |
Jason Monk | 377e7ad | 2016-02-16 14:03:21 -0500 | [diff] [blame] | 541 | if (r == mDetailRecord) return; |
| 542 | mDetailRecord = r; |
| 543 | final boolean scanState = mDetailRecord instanceof TileRecord |
| 544 | && ((TileRecord) mDetailRecord).scanState; |
| 545 | fireScanStateChanged(scanState); |
| 546 | } |
| 547 | |
| 548 | void setGridContentVisibility(boolean visible) { |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 549 | int newVis = visible ? VISIBLE : INVISIBLE; |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 550 | setVisibility(newVis); |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 551 | if (mGridContentVisible != visible) { |
Jason Monk | 8c09ac7 | 2017-03-16 11:53:40 -0400 | [diff] [blame] | 552 | mMetricsLogger.visibility(MetricsEvent.QS_PANEL, newVis); |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 553 | } |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 554 | mGridContentVisible = visible; |
| 555 | } |
| 556 | |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 557 | private void logTiles() { |
| 558 | for (int i = 0; i < mRecords.size(); i++) { |
Jason Monk | cb4b31d | 2017-05-03 10:37:34 -0400 | [diff] [blame] | 559 | QSTile tile = mRecords.get(i).tile; |
| 560 | mMetricsLogger.write(tile.populate(new LogMaker(tile.getMetricsCategory()) |
| 561 | .setType(MetricsEvent.TYPE_OPEN))); |
Chris Wren | 457a21c | 2015-05-06 17:50:34 -0400 | [diff] [blame] | 562 | } |
| 563 | } |
| 564 | |
Jason Monk | 377e7ad | 2016-02-16 14:03:21 -0500 | [diff] [blame] | 565 | private void fireShowingDetail(DetailAdapter detail, int x, int y) { |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 566 | if (mCallback != null) { |
Jason Monk | 377e7ad | 2016-02-16 14:03:21 -0500 | [diff] [blame] | 567 | mCallback.onShowingDetail(detail, x, y); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 568 | } |
| 569 | } |
| 570 | |
| 571 | private void fireToggleStateChanged(boolean state) { |
| 572 | if (mCallback != null) { |
| 573 | mCallback.onToggleStateChanged(state); |
John Spurlock | 5729d09 | 2014-05-29 17:42:51 -0400 | [diff] [blame] | 574 | } |
| 575 | } |
| 576 | |
John Spurlock | 486b78e | 2014-07-07 08:37:56 -0400 | [diff] [blame] | 577 | private void fireScanStateChanged(boolean state) { |
| 578 | if (mCallback != null) { |
| 579 | mCallback.onScanStateChanged(state); |
| 580 | } |
| 581 | } |
| 582 | |
Jason Monk | 7e53f20 | 2016-01-28 10:40:20 -0500 | [diff] [blame] | 583 | public void clickTile(ComponentName tile) { |
| 584 | final String spec = CustomTile.toSpec(tile); |
| 585 | final int N = mRecords.size(); |
| 586 | for (int i = 0; i < N; i++) { |
| 587 | if (mRecords.get(i).tile.getTileSpec().equals(spec)) { |
| 588 | mRecords.get(i).tile.click(); |
| 589 | break; |
| 590 | } |
| 591 | } |
| 592 | } |
| 593 | |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 594 | QSTileLayout getTileLayout() { |
| 595 | return mTileLayout; |
| 596 | } |
| 597 | |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 598 | QSTileView getTileView(QSTile tile) { |
Jason Monk | 162011e | 2016-02-19 08:11:55 -0500 | [diff] [blame] | 599 | for (TileRecord r : mRecords) { |
| 600 | if (r.tile == tile) { |
| 601 | return r.tileView; |
| 602 | } |
| 603 | } |
| 604 | return null; |
| 605 | } |
| 606 | |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 607 | public QSSecurityFooter getFooter() { |
Jason Monk | df36aed | 2016-07-25 11:21:56 -0400 | [diff] [blame] | 608 | return mFooter; |
| 609 | } |
| 610 | |
phweiss | a0cb251 | 2016-12-14 21:37:48 +0100 | [diff] [blame] | 611 | public void showDeviceMonitoringDialog() { |
| 612 | mFooter.showDeviceMonitoringDialog(); |
| 613 | } |
| 614 | |
Amin Shaikh | bc1a4e8 | 2018-04-16 12:14:35 -0400 | [diff] [blame] | 615 | public void setMargins(int sideMargins) { |
| 616 | for (int i = 0; i < getChildCount(); i++) { |
| 617 | View view = getChildAt(i); |
| 618 | if (view != mTileLayout) { |
| 619 | LayoutParams lp = (LayoutParams) view.getLayoutParams(); |
| 620 | lp.leftMargin = sideMargins; |
| 621 | lp.rightMargin = sideMargins; |
| 622 | } |
| 623 | } |
| 624 | } |
| 625 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 626 | private class H extends Handler { |
| 627 | private static final int SHOW_DETAIL = 1; |
| 628 | private static final int SET_TILE_VISIBILITY = 2; |
dooyoung.hwang | 1b00662 | 2016-12-22 20:04:20 +0900 | [diff] [blame] | 629 | private static final int ANNOUNCE_FOR_ACCESSIBILITY = 3; |
Jason Monk | cb4b31d | 2017-05-03 10:37:34 -0400 | [diff] [blame] | 630 | |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 631 | @Override |
| 632 | public void handleMessage(Message msg) { |
| 633 | if (msg.what == SHOW_DETAIL) { |
Jason Monk | cb4b31d | 2017-05-03 10:37:34 -0400 | [diff] [blame] | 634 | handleShowDetail((Record) msg.obj, msg.arg1 != 0); |
dooyoung.hwang | 1b00662 | 2016-12-22 20:04:20 +0900 | [diff] [blame] | 635 | } else if (msg.what == ANNOUNCE_FOR_ACCESSIBILITY) { |
Jason Monk | cb4b31d | 2017-05-03 10:37:34 -0400 | [diff] [blame] | 636 | announceForAccessibility((CharSequence) msg.obj); |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 637 | } |
| 638 | } |
| 639 | } |
| 640 | |
Jason Monk | dc35dcb | 2015-12-04 16:36:15 -0500 | [diff] [blame] | 641 | protected static class Record { |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 642 | DetailAdapter detailAdapter; |
Adrian Roos | 970be53 | 2014-11-21 15:50:16 +0100 | [diff] [blame] | 643 | int x; |
| 644 | int y; |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 645 | } |
| 646 | |
Jason Monk | bd6dbb0 | 2015-09-03 15:46:25 -0400 | [diff] [blame] | 647 | public static final class TileRecord extends Record { |
Jason Monk | 702e2eb | 2017-03-03 16:53:44 -0500 | [diff] [blame] | 648 | public QSTile tile; |
| 649 | public com.android.systemui.plugins.qs.QSTileView tileView; |
Jason Monk | 11a7744 | 2015-05-12 19:29:02 -0400 | [diff] [blame] | 650 | public boolean scanState; |
Xiaohui Chen | 08e266c | 2016-04-18 12:53:28 -0700 | [diff] [blame] | 651 | public QSTile.Callback callback; |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 652 | } |
| 653 | |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 654 | public interface QSTileLayout { |
| 655 | void addTile(TileRecord tile); |
Jason Monk | cb4b31d | 2017-05-03 10:37:34 -0400 | [diff] [blame] | 656 | |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 657 | void removeTile(TileRecord tile); |
Jason Monk | cb4b31d | 2017-05-03 10:37:34 -0400 | [diff] [blame] | 658 | |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 659 | int getOffsetTop(TileRecord tile); |
Jason Monk | cb4b31d | 2017-05-03 10:37:34 -0400 | [diff] [blame] | 660 | |
Jason Monk | 9d02a43 | 2016-01-20 16:33:46 -0500 | [diff] [blame] | 661 | boolean updateResources(); |
Jason Monk | 1bec6af | 2016-05-31 15:40:58 -0400 | [diff] [blame] | 662 | |
| 663 | void setListening(boolean listening); |
Amin Shaikh | 0f8ea543 | 2018-03-27 11:09:27 -0400 | [diff] [blame] | 664 | |
| 665 | default void setExpansion(float expansion) {} |
Jason Monk | caf3762 | 2015-08-18 12:33:50 -0400 | [diff] [blame] | 666 | } |
John Spurlock | af8d6c4 | 2014-05-07 17:49:08 -0400 | [diff] [blame] | 667 | } |