Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [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 | |
Amin Shaikh | f09450b | 2018-04-06 17:32:45 -0400 | [diff] [blame] | 19 | import static android.app.StatusBarManager.DISABLE2_QUICK_SETTINGS; |
Bill Lin | be9d20a | 2018-06-07 16:25:46 +0800 | [diff] [blame] | 20 | import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; |
Amin Shaikh | f09450b | 2018-04-06 17:32:45 -0400 | [diff] [blame] | 21 | |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 22 | import android.content.Context; |
Jason Monk | 231b052 | 2018-01-04 10:49:55 -0500 | [diff] [blame] | 23 | import android.content.res.Configuration; |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 24 | import android.graphics.Point; |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 25 | import android.util.AttributeSet; |
Jason Monk | e1be342 | 2016-02-09 10:51:40 -0500 | [diff] [blame] | 26 | import android.view.View; |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 27 | import android.widget.FrameLayout; |
Jason Monk | 46767b7 | 2016-08-18 10:58:04 -0400 | [diff] [blame] | 28 | |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 29 | import com.android.systemui.R; |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 30 | import com.android.systemui.qs.customize.QSCustomizer; |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 31 | |
| 32 | /** |
Jason Monk | e1be342 | 2016-02-09 10:51:40 -0500 | [diff] [blame] | 33 | * Wrapper view with background which contains {@link QSPanel} and {@link BaseStatusBarHeader} |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 34 | */ |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 35 | public class QSContainerImpl extends FrameLayout { |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 36 | |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 37 | private final Point mSizePoint = new Point(); |
| 38 | |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 39 | private int mHeightOverride = -1; |
Amin Shaikh | bc1a4e8 | 2018-04-16 12:14:35 -0400 | [diff] [blame] | 40 | private QSPanel mQSPanel; |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 41 | private View mQSDetail; |
Amin Shaikh | 50d2d1e | 2018-04-25 14:48:13 -0400 | [diff] [blame] | 42 | private QuickStatusBarHeader mHeader; |
Amin Shaikh | bc1a4e8 | 2018-04-16 12:14:35 -0400 | [diff] [blame] | 43 | private float mQsExpansion; |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 44 | private QSCustomizer mQSCustomizer; |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 45 | private View mQSFooter; |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 46 | |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame] | 47 | private View mBackground; |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 48 | private View mBackgroundGradient; |
| 49 | private View mStatusBarBackground; |
| 50 | |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame] | 51 | private int mSideMargins; |
Amin Shaikh | f09450b | 2018-04-06 17:32:45 -0400 | [diff] [blame] | 52 | private boolean mQsDisabled; |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 53 | |
Jason Monk | 46767b7 | 2016-08-18 10:58:04 -0400 | [diff] [blame] | 54 | public QSContainerImpl(Context context, AttributeSet attrs) { |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 55 | super(context, attrs); |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | protected void onFinishInflate() { |
| 60 | super.onFinishInflate(); |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 61 | mQSPanel = findViewById(R.id.quick_settings_panel); |
| 62 | mQSDetail = findViewById(R.id.qs_detail); |
| 63 | mHeader = findViewById(R.id.header); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 64 | mQSCustomizer = findViewById(R.id.qs_customize); |
| 65 | mQSFooter = findViewById(R.id.qs_footer); |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame] | 66 | mBackground = findViewById(R.id.quick_settings_background); |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 67 | mStatusBarBackground = findViewById(R.id.quick_settings_status_bar_background); |
| 68 | mBackgroundGradient = findViewById(R.id.quick_settings_gradient_view); |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame] | 69 | mSideMargins = getResources().getDimensionPixelSize(R.dimen.notification_side_paddings); |
Jason Monk | 7b3d4e4 | 2017-05-30 12:47:10 -0400 | [diff] [blame] | 70 | |
Jason Monk | 7b3d4e4 | 2017-05-30 12:47:10 -0400 | [diff] [blame] | 71 | setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO); |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame] | 72 | setMargins(); |
Jason Monk | 7b3d4e4 | 2017-05-30 12:47:10 -0400 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | @Override |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 76 | protected void onConfigurationChanged(Configuration newConfig) { |
| 77 | super.onConfigurationChanged(newConfig); |
Bill Lin | be9d20a | 2018-06-07 16:25:46 +0800 | [diff] [blame] | 78 | setBackgroundGradientVisibility(newConfig); |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 79 | updateResources(); |
Amin Shaikh | 375b8dd | 2018-04-10 10:50:22 -0400 | [diff] [blame] | 80 | mSizePoint.set(0, 0); // Will be retrieved on next measure pass. |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | @Override |
Jason Monk | 7b3d4e4 | 2017-05-30 12:47:10 -0400 | [diff] [blame] | 84 | public boolean performClick() { |
| 85 | // Want to receive clicks so missing QQS tiles doesn't cause collapse, but |
| 86 | // don't want to do anything with them. |
| 87 | return true; |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 88 | } |
| 89 | |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 90 | @Override |
Jason Monk | 83e431f | 2016-02-19 19:32:13 -0500 | [diff] [blame] | 91 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
Fabian Kozynski | 712ae39 | 2018-09-12 09:11:16 -0400 | [diff] [blame] | 92 | // QSPanel will show as many rows as it can (up to TileLayout.MAX_ROWS) such that the |
| 93 | // bottom and footer are inside the screen. |
| 94 | Configuration config = getResources().getConfiguration(); |
| 95 | boolean navBelow = config.smallestScreenWidthDp >= 600 |
| 96 | || config.orientation != Configuration.ORIENTATION_LANDSCAPE; |
| 97 | MarginLayoutParams layoutParams = (MarginLayoutParams) mQSPanel.getLayoutParams(); |
| 98 | |
| 99 | // The footer is pinned to the bottom of QSPanel (same bottoms), therefore we don't need to |
| 100 | // subtract its height. We do not care if the collapsed notifications fit in the screen. |
| 101 | int maxQs = getDisplayHeight() - layoutParams.topMargin - layoutParams.bottomMargin |
| 102 | - getPaddingBottom(); |
| 103 | if (navBelow) { |
| 104 | maxQs -= getResources().getDimensionPixelSize(R.dimen.navigation_bar_height); |
| 105 | } |
Fabian Kozynski | 72cd84a9 | 2019-04-15 14:09:43 -0400 | [diff] [blame] | 106 | // Measure with EXACTLY. That way, PagedTileLayout will only use excess height and will be |
| 107 | // measured last, after other views and padding is accounted for. |
| 108 | mQSPanel.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(maxQs, MeasureSpec.EXACTLY)); |
Jason Monk | 6573ef2 | 2016-04-06 12:37:18 -0400 | [diff] [blame] | 109 | int width = mQSPanel.getMeasuredWidth(); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 110 | int height = layoutParams.topMargin + layoutParams.bottomMargin |
Fabian Kozynski | 712ae39 | 2018-09-12 09:11:16 -0400 | [diff] [blame] | 111 | + mQSPanel.getMeasuredHeight() + getPaddingBottom(); |
Jason Monk | 6573ef2 | 2016-04-06 12:37:18 -0400 | [diff] [blame] | 112 | super.onMeasure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), |
| 113 | MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)); |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 114 | // QSCustomizer will always be the height of the screen, but do this after |
| 115 | // other measuring to avoid changing the height of the QS. |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 116 | mQSCustomizer.measure(widthMeasureSpec, |
Amin Shaikh | 375b8dd | 2018-04-10 10:50:22 -0400 | [diff] [blame] | 117 | MeasureSpec.makeMeasureSpec(getDisplayHeight(), MeasureSpec.EXACTLY)); |
Jason Monk | 83e431f | 2016-02-19 19:32:13 -0500 | [diff] [blame] | 118 | } |
| 119 | |
Fabian Kozynski | 0b7d617 | 2019-08-08 15:53:34 -0400 | [diff] [blame] | 120 | |
| 121 | @Override |
| 122 | protected void measureChildWithMargins(View child, int parentWidthMeasureSpec, int widthUsed, |
| 123 | int parentHeightMeasureSpec, int heightUsed) { |
| 124 | // Do not measure QSPanel again when doing super.onMeasure. |
| 125 | // This prevents the pages in PagedTileLayout to be remeasured with a different (incorrect) |
| 126 | // size to the one used for determining the number of rows and then the number of pages. |
| 127 | if (child != mQSPanel) { |
| 128 | super.measureChildWithMargins(child, parentWidthMeasureSpec, widthUsed, |
| 129 | parentHeightMeasureSpec, heightUsed); |
| 130 | } |
| 131 | } |
| 132 | |
Jason Monk | 83e431f | 2016-02-19 19:32:13 -0500 | [diff] [blame] | 133 | @Override |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 134 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 135 | super.onLayout(changed, left, top, right, bottom); |
Jason Monk | 4de5d3c | 2017-05-24 14:57:10 -0400 | [diff] [blame] | 136 | updateExpansion(); |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 137 | } |
| 138 | |
Amin Shaikh | f09450b | 2018-04-06 17:32:45 -0400 | [diff] [blame] | 139 | public void disable(int state1, int state2, boolean animate) { |
| 140 | final boolean disabled = (state2 & DISABLE2_QUICK_SETTINGS) != 0; |
| 141 | if (disabled == mQsDisabled) return; |
| 142 | mQsDisabled = disabled; |
Bill Lin | be9d20a | 2018-06-07 16:25:46 +0800 | [diff] [blame] | 143 | setBackgroundGradientVisibility(getResources().getConfiguration()); |
Amin Shaikh | e04505e | 2018-04-18 10:45:13 -0400 | [diff] [blame] | 144 | mBackground.setVisibility(mQsDisabled ? View.GONE : View.VISIBLE); |
Amin Shaikh | f09450b | 2018-04-06 17:32:45 -0400 | [diff] [blame] | 145 | } |
| 146 | |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 147 | private void updateResources() { |
| 148 | LayoutParams layoutParams = (LayoutParams) mQSPanel.getLayoutParams(); |
| 149 | layoutParams.topMargin = mContext.getResources().getDimensionPixelSize( |
| 150 | com.android.internal.R.dimen.quick_qs_offset_height); |
| 151 | |
| 152 | mQSPanel.setLayoutParams(layoutParams); |
| 153 | } |
| 154 | |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 155 | /** |
| 156 | * Overrides the height of this view (post-layout), so that the content is clipped to that |
| 157 | * height and the background is set to that height. |
| 158 | * |
| 159 | * @param heightOverride the overridden height |
| 160 | */ |
| 161 | public void setHeightOverride(int heightOverride) { |
| 162 | mHeightOverride = heightOverride; |
Jason Monk | 4de5d3c | 2017-05-24 14:57:10 -0400 | [diff] [blame] | 163 | updateExpansion(); |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 164 | } |
| 165 | |
Jason Monk | 4de5d3c | 2017-05-24 14:57:10 -0400 | [diff] [blame] | 166 | public void updateExpansion() { |
Muyuan Li | 4fe4a40 | 2016-03-30 16:50:11 -0700 | [diff] [blame] | 167 | int height = calculateContainerHeight(); |
Jason Monk | 232ac2b | 2017-06-02 12:50:24 -0400 | [diff] [blame] | 168 | setBottom(getTop() + height); |
Jason Monk | 377e7ad | 2016-02-16 14:03:21 -0500 | [diff] [blame] | 169 | mQSDetail.setBottom(getTop() + height); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 170 | // Pin QS Footer to the bottom of the panel. |
| 171 | mQSFooter.setTranslationY(height - mQSFooter.getHeight()); |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame] | 172 | mBackground.setTop(mQSPanel.getTop()); |
| 173 | mBackground.setBottom(height); |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 174 | } |
Jason Monk | e1be342 | 2016-02-09 10:51:40 -0500 | [diff] [blame] | 175 | |
Muyuan Li | 4fe4a40 | 2016-03-30 16:50:11 -0700 | [diff] [blame] | 176 | protected int calculateContainerHeight() { |
| 177 | int heightOverride = mHeightOverride != -1 ? mHeightOverride : getMeasuredHeight(); |
| 178 | return mQSCustomizer.isCustomizing() ? mQSCustomizer.getHeight() |
Jason Monk | 4de5d3c | 2017-05-24 14:57:10 -0400 | [diff] [blame] | 179 | : Math.round(mQsExpansion * (heightOverride - mHeader.getHeight())) |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 180 | + mHeader.getHeight(); |
Muyuan Li | 4fe4a40 | 2016-03-30 16:50:11 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Bill Lin | be9d20a | 2018-06-07 16:25:46 +0800 | [diff] [blame] | 183 | private void setBackgroundGradientVisibility(Configuration newConfig) { |
| 184 | if (newConfig.orientation == ORIENTATION_LANDSCAPE) { |
| 185 | mBackgroundGradient.setVisibility(View.INVISIBLE); |
| 186 | mStatusBarBackground.setVisibility(View.INVISIBLE); |
| 187 | } else { |
| 188 | mBackgroundGradient.setVisibility(mQsDisabled ? View.INVISIBLE : View.VISIBLE); |
| 189 | mStatusBarBackground.setVisibility(View.VISIBLE); |
| 190 | } |
| 191 | } |
| 192 | |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 193 | public void setExpansion(float expansion) { |
Jason Monk | e1be342 | 2016-02-09 10:51:40 -0500 | [diff] [blame] | 194 | mQsExpansion = expansion; |
Jason Monk | 4de5d3c | 2017-05-24 14:57:10 -0400 | [diff] [blame] | 195 | updateExpansion(); |
| 196 | } |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame] | 197 | |
| 198 | private void setMargins() { |
| 199 | setMargins(mQSDetail); |
| 200 | setMargins(mBackground); |
| 201 | setMargins(mQSFooter); |
Amin Shaikh | bc1a4e8 | 2018-04-16 12:14:35 -0400 | [diff] [blame] | 202 | mQSPanel.setMargins(mSideMargins); |
Amin Shaikh | 50d2d1e | 2018-04-25 14:48:13 -0400 | [diff] [blame] | 203 | mHeader.setMargins(mSideMargins); |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | private void setMargins(View view) { |
| 207 | FrameLayout.LayoutParams lp = (LayoutParams) view.getLayoutParams(); |
| 208 | lp.rightMargin = mSideMargins; |
| 209 | lp.leftMargin = mSideMargins; |
| 210 | } |
Amin Shaikh | 375b8dd | 2018-04-10 10:50:22 -0400 | [diff] [blame] | 211 | |
| 212 | private int getDisplayHeight() { |
| 213 | if (mSizePoint.y == 0) { |
| 214 | getDisplay().getRealSize(mSizePoint); |
| 215 | } |
| 216 | return mSizePoint.y; |
| 217 | } |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 218 | } |