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