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