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 | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 114 | |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 115 | // QSCustomizer will always be the height of the screen, but do this after |
| 116 | // other measuring to avoid changing the height of the QS. |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 117 | mQSCustomizer.measure(widthMeasureSpec, |
Amin Shaikh | 375b8dd | 2018-04-10 10:50:22 -0400 | [diff] [blame] | 118 | MeasureSpec.makeMeasureSpec(getDisplayHeight(), MeasureSpec.EXACTLY)); |
Jason Monk | 83e431f | 2016-02-19 19:32:13 -0500 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | @Override |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 122 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 123 | super.onLayout(changed, left, top, right, bottom); |
Jason Monk | 4de5d3c | 2017-05-24 14:57:10 -0400 | [diff] [blame] | 124 | updateExpansion(); |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 125 | } |
| 126 | |
Amin Shaikh | f09450b | 2018-04-06 17:32:45 -0400 | [diff] [blame] | 127 | public void disable(int state1, int state2, boolean animate) { |
| 128 | final boolean disabled = (state2 & DISABLE2_QUICK_SETTINGS) != 0; |
| 129 | if (disabled == mQsDisabled) return; |
| 130 | mQsDisabled = disabled; |
Bill Lin | be9d20a | 2018-06-07 16:25:46 +0800 | [diff] [blame] | 131 | setBackgroundGradientVisibility(getResources().getConfiguration()); |
Amin Shaikh | e04505e | 2018-04-18 10:45:13 -0400 | [diff] [blame] | 132 | mBackground.setVisibility(mQsDisabled ? View.GONE : View.VISIBLE); |
Amin Shaikh | f09450b | 2018-04-06 17:32:45 -0400 | [diff] [blame] | 133 | } |
| 134 | |
Rohan Shah | cc3d1d8 | 2018-03-30 21:24:17 +0000 | [diff] [blame] | 135 | private void updateResources() { |
| 136 | LayoutParams layoutParams = (LayoutParams) mQSPanel.getLayoutParams(); |
| 137 | layoutParams.topMargin = mContext.getResources().getDimensionPixelSize( |
| 138 | com.android.internal.R.dimen.quick_qs_offset_height); |
| 139 | |
| 140 | mQSPanel.setLayoutParams(layoutParams); |
| 141 | } |
| 142 | |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 143 | /** |
| 144 | * Overrides the height of this view (post-layout), so that the content is clipped to that |
| 145 | * height and the background is set to that height. |
| 146 | * |
| 147 | * @param heightOverride the overridden height |
| 148 | */ |
| 149 | public void setHeightOverride(int heightOverride) { |
| 150 | mHeightOverride = heightOverride; |
Jason Monk | 4de5d3c | 2017-05-24 14:57:10 -0400 | [diff] [blame] | 151 | updateExpansion(); |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 152 | } |
| 153 | |
Jason Monk | 4de5d3c | 2017-05-24 14:57:10 -0400 | [diff] [blame] | 154 | public void updateExpansion() { |
Muyuan Li | 4fe4a40 | 2016-03-30 16:50:11 -0700 | [diff] [blame] | 155 | int height = calculateContainerHeight(); |
Jason Monk | 232ac2b | 2017-06-02 12:50:24 -0400 | [diff] [blame] | 156 | setBottom(getTop() + height); |
Jason Monk | 377e7ad | 2016-02-16 14:03:21 -0500 | [diff] [blame] | 157 | mQSDetail.setBottom(getTop() + height); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 158 | // Pin QS Footer to the bottom of the panel. |
| 159 | mQSFooter.setTranslationY(height - mQSFooter.getHeight()); |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame] | 160 | mBackground.setTop(mQSPanel.getTop()); |
| 161 | mBackground.setBottom(height); |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 162 | } |
Jason Monk | e1be342 | 2016-02-09 10:51:40 -0500 | [diff] [blame] | 163 | |
Muyuan Li | 4fe4a40 | 2016-03-30 16:50:11 -0700 | [diff] [blame] | 164 | protected int calculateContainerHeight() { |
| 165 | int heightOverride = mHeightOverride != -1 ? mHeightOverride : getMeasuredHeight(); |
| 166 | return mQSCustomizer.isCustomizing() ? mQSCustomizer.getHeight() |
Jason Monk | 4de5d3c | 2017-05-24 14:57:10 -0400 | [diff] [blame] | 167 | : Math.round(mQsExpansion * (heightOverride - mHeader.getHeight())) |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 168 | + mHeader.getHeight(); |
Muyuan Li | 4fe4a40 | 2016-03-30 16:50:11 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Bill Lin | be9d20a | 2018-06-07 16:25:46 +0800 | [diff] [blame] | 171 | private void setBackgroundGradientVisibility(Configuration newConfig) { |
| 172 | if (newConfig.orientation == ORIENTATION_LANDSCAPE) { |
| 173 | mBackgroundGradient.setVisibility(View.INVISIBLE); |
| 174 | mStatusBarBackground.setVisibility(View.INVISIBLE); |
| 175 | } else { |
| 176 | mBackgroundGradient.setVisibility(mQsDisabled ? View.INVISIBLE : View.VISIBLE); |
| 177 | mStatusBarBackground.setVisibility(View.VISIBLE); |
| 178 | } |
| 179 | } |
| 180 | |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 181 | public void setExpansion(float expansion) { |
Jason Monk | e1be342 | 2016-02-09 10:51:40 -0500 | [diff] [blame] | 182 | mQsExpansion = expansion; |
Jason Monk | 4de5d3c | 2017-05-24 14:57:10 -0400 | [diff] [blame] | 183 | updateExpansion(); |
| 184 | } |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame] | 185 | |
| 186 | private void setMargins() { |
| 187 | setMargins(mQSDetail); |
| 188 | setMargins(mBackground); |
| 189 | setMargins(mQSFooter); |
Amin Shaikh | bc1a4e8 | 2018-04-16 12:14:35 -0400 | [diff] [blame] | 190 | mQSPanel.setMargins(mSideMargins); |
Amin Shaikh | 50d2d1e | 2018-04-25 14:48:13 -0400 | [diff] [blame] | 191 | mHeader.setMargins(mSideMargins); |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | private void setMargins(View view) { |
| 195 | FrameLayout.LayoutParams lp = (LayoutParams) view.getLayoutParams(); |
| 196 | lp.rightMargin = mSideMargins; |
| 197 | lp.leftMargin = mSideMargins; |
| 198 | } |
Amin Shaikh | 375b8dd | 2018-04-10 10:50:22 -0400 | [diff] [blame] | 199 | |
| 200 | private int getDisplayHeight() { |
| 201 | if (mSizePoint.y == 0) { |
| 202 | getDisplay().getRealSize(mSizePoint); |
| 203 | } |
| 204 | return mSizePoint.y; |
| 205 | } |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 206 | } |