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 | |
| 19 | import android.content.Context; |
Jason Monk | 8a514cb | 2018-01-15 15:24:09 -0500 | [diff] [blame] | 20 | import android.graphics.Canvas; |
| 21 | import android.graphics.Path; |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 22 | import android.graphics.Point; |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 23 | import android.util.AttributeSet; |
Jason Monk | 8a514cb | 2018-01-15 15:24:09 -0500 | [diff] [blame] | 24 | import android.util.Log; |
Jason Monk | e1be342 | 2016-02-09 10:51:40 -0500 | [diff] [blame] | 25 | import android.view.View; |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 26 | import android.widget.FrameLayout; |
Jason Monk | 46767b7 | 2016-08-18 10:58:04 -0400 | [diff] [blame] | 27 | |
Jason Monk | 8a514cb | 2018-01-15 15:24:09 -0500 | [diff] [blame] | 28 | import com.android.settingslib.Utils; |
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; |
Jason Monk | 8a514cb | 2018-01-15 15:24:09 -0500 | [diff] [blame] | 31 | import com.android.systemui.statusbar.ExpandableOutlineView; |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 32 | |
| 33 | /** |
Jason Monk | e1be342 | 2016-02-09 10:51:40 -0500 | [diff] [blame] | 34 | * Wrapper view with background which contains {@link QSPanel} and {@link BaseStatusBarHeader} |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 35 | */ |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 36 | public class QSContainerImpl extends FrameLayout { |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 37 | |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 38 | private final Point mSizePoint = new Point(); |
Jason Monk | 8a514cb | 2018-01-15 15:24:09 -0500 | [diff] [blame] | 39 | private final Path mClipPath = new Path(); |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 40 | |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 41 | private int mHeightOverride = -1; |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 42 | protected View mQSPanel; |
| 43 | private View mQSDetail; |
| 44 | protected View mHeader; |
Muyuan Li | 4fe4a40 | 2016-03-30 16:50:11 -0700 | [diff] [blame] | 45 | protected float mQsExpansion; |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 46 | private QSCustomizer mQSCustomizer; |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 47 | private View mQSFooter; |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame] | 48 | private View mBackground; |
Jason Monk | 8a514cb | 2018-01-15 15:24:09 -0500 | [diff] [blame] | 49 | private float mRadius; |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame] | 50 | private int mSideMargins; |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 51 | |
Jason Monk | 46767b7 | 2016-08-18 10:58:04 -0400 | [diff] [blame] | 52 | public QSContainerImpl(Context context, AttributeSet attrs) { |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 53 | super(context, attrs); |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | protected void onFinishInflate() { |
| 58 | super.onFinishInflate(); |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 59 | mQSPanel = findViewById(R.id.quick_settings_panel); |
| 60 | mQSDetail = findViewById(R.id.qs_detail); |
| 61 | mHeader = findViewById(R.id.header); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 62 | mQSCustomizer = findViewById(R.id.qs_customize); |
| 63 | mQSFooter = findViewById(R.id.qs_footer); |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame] | 64 | mBackground = findViewById(R.id.quick_settings_background); |
Jason Monk | 8a514cb | 2018-01-15 15:24:09 -0500 | [diff] [blame] | 65 | mRadius = getResources().getDimensionPixelSize( |
| 66 | Utils.getThemeAttr(mContext, android.R.attr.dialogCornerRadius)); |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame] | 67 | mSideMargins = getResources().getDimensionPixelSize(R.dimen.notification_side_paddings); |
Jason Monk | 7b3d4e4 | 2017-05-30 12:47:10 -0400 | [diff] [blame] | 68 | |
| 69 | setClickable(true); |
| 70 | setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO); |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame] | 71 | setMargins(); |
Jason Monk | 7b3d4e4 | 2017-05-30 12:47:10 -0400 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public boolean performClick() { |
| 76 | // Want to receive clicks so missing QQS tiles doesn't cause collapse, but |
| 77 | // don't want to do anything with them. |
| 78 | return true; |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 79 | } |
| 80 | |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 81 | @Override |
Jason Monk | 83e431f | 2016-02-19 19:32:13 -0500 | [diff] [blame] | 82 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 83 | // Since we control our own bottom, be whatever size we want. |
| 84 | // Otherwise the QSPanel ends up with 0 height when the window is only the |
| 85 | // size of the status bar. |
Jason Monk | 6573ef2 | 2016-04-06 12:37:18 -0400 | [diff] [blame] | 86 | mQSPanel.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec( |
| 87 | MeasureSpec.getSize(heightMeasureSpec), MeasureSpec.UNSPECIFIED)); |
| 88 | int width = mQSPanel.getMeasuredWidth(); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 89 | LayoutParams layoutParams = (LayoutParams) mQSPanel.getLayoutParams(); |
| 90 | int height = layoutParams.topMargin + layoutParams.bottomMargin |
Jason Monk | 6573ef2 | 2016-04-06 12:37:18 -0400 | [diff] [blame] | 91 | + mQSPanel.getMeasuredHeight(); |
| 92 | super.onMeasure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), |
| 93 | MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)); |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 94 | |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 95 | // QSCustomizer will always be the height of the screen, but do this after |
| 96 | // other measuring to avoid changing the height of the QS. |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 97 | getDisplay().getRealSize(mSizePoint); |
| 98 | mQSCustomizer.measure(widthMeasureSpec, |
| 99 | MeasureSpec.makeMeasureSpec(mSizePoint.y, MeasureSpec.EXACTLY)); |
Jason Monk | 83e431f | 2016-02-19 19:32:13 -0500 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | @Override |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 103 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 104 | super.onLayout(changed, left, top, right, bottom); |
Jason Monk | 4de5d3c | 2017-05-24 14:57:10 -0400 | [diff] [blame] | 105 | updateExpansion(); |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 106 | } |
| 107 | |
Jason Monk | 8a514cb | 2018-01-15 15:24:09 -0500 | [diff] [blame] | 108 | @Override |
| 109 | protected boolean drawChild(Canvas canvas, View child, long drawingTime) { |
| 110 | boolean ret; |
| 111 | canvas.save(); |
| 112 | if (child != mQSCustomizer) { |
| 113 | canvas.clipPath(mClipPath); |
| 114 | } |
| 115 | ret = super.drawChild(canvas, child, drawingTime); |
| 116 | canvas.restore(); |
| 117 | return ret; |
| 118 | } |
| 119 | |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 120 | /** |
| 121 | * Overrides the height of this view (post-layout), so that the content is clipped to that |
| 122 | * height and the background is set to that height. |
| 123 | * |
| 124 | * @param heightOverride the overridden height |
| 125 | */ |
| 126 | public void setHeightOverride(int heightOverride) { |
| 127 | mHeightOverride = heightOverride; |
Jason Monk | 4de5d3c | 2017-05-24 14:57:10 -0400 | [diff] [blame] | 128 | updateExpansion(); |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 129 | } |
| 130 | |
Jason Monk | 4de5d3c | 2017-05-24 14:57:10 -0400 | [diff] [blame] | 131 | public void updateExpansion() { |
Muyuan Li | 4fe4a40 | 2016-03-30 16:50:11 -0700 | [diff] [blame] | 132 | int height = calculateContainerHeight(); |
Jason Monk | 232ac2b | 2017-06-02 12:50:24 -0400 | [diff] [blame] | 133 | setBottom(getTop() + height); |
Jason Monk | 377e7ad | 2016-02-16 14:03:21 -0500 | [diff] [blame] | 134 | mQSDetail.setBottom(getTop() + height); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 135 | // Pin QS Footer to the bottom of the panel. |
| 136 | mQSFooter.setTranslationY(height - mQSFooter.getHeight()); |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame] | 137 | mBackground.setTop(mQSPanel.getTop()); |
| 138 | mBackground.setBottom(height); |
Jason Monk | 8a514cb | 2018-01-15 15:24:09 -0500 | [diff] [blame] | 139 | |
| 140 | ExpandableOutlineView.getRoundedRectPath(0, 0, getWidth(), height, mRadius, |
| 141 | mRadius, |
| 142 | mClipPath); |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 143 | } |
Jason Monk | e1be342 | 2016-02-09 10:51:40 -0500 | [diff] [blame] | 144 | |
Muyuan Li | 4fe4a40 | 2016-03-30 16:50:11 -0700 | [diff] [blame] | 145 | protected int calculateContainerHeight() { |
| 146 | int heightOverride = mHeightOverride != -1 ? mHeightOverride : getMeasuredHeight(); |
| 147 | return mQSCustomizer.isCustomizing() ? mQSCustomizer.getHeight() |
Jason Monk | 4de5d3c | 2017-05-24 14:57:10 -0400 | [diff] [blame] | 148 | : Math.round(mQsExpansion * (heightOverride - mHeader.getHeight())) |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 149 | + mHeader.getHeight(); |
Muyuan Li | 4fe4a40 | 2016-03-30 16:50:11 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 152 | public void setExpansion(float expansion) { |
Jason Monk | e1be342 | 2016-02-09 10:51:40 -0500 | [diff] [blame] | 153 | mQsExpansion = expansion; |
Jason Monk | 4de5d3c | 2017-05-24 14:57:10 -0400 | [diff] [blame] | 154 | updateExpansion(); |
| 155 | } |
Evan Laird | 39254d4 | 2018-01-18 16:05:30 -0500 | [diff] [blame] | 156 | |
| 157 | private void setMargins() { |
| 158 | setMargins(mQSDetail); |
| 159 | setMargins(mBackground); |
| 160 | setMargins(mQSFooter); |
| 161 | setMargins(mQSPanel); |
| 162 | setMargins(mHeader); |
| 163 | setMargins(mQSCustomizer); |
| 164 | } |
| 165 | |
| 166 | private void setMargins(View view) { |
| 167 | FrameLayout.LayoutParams lp = (LayoutParams) view.getLayoutParams(); |
| 168 | lp.rightMargin = mSideMargins; |
| 169 | lp.leftMargin = mSideMargins; |
| 170 | } |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 171 | } |