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 | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 20 | import android.graphics.Point; |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 21 | import android.util.AttributeSet; |
Jason Monk | e1be342 | 2016-02-09 10:51:40 -0500 | [diff] [blame] | 22 | import android.view.View; |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 23 | import android.widget.FrameLayout; |
Jason Monk | 46767b7 | 2016-08-18 10:58:04 -0400 | [diff] [blame] | 24 | |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 25 | import com.android.systemui.R; |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 26 | import com.android.systemui.qs.customize.QSCustomizer; |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 27 | |
| 28 | /** |
Jason Monk | e1be342 | 2016-02-09 10:51:40 -0500 | [diff] [blame] | 29 | * Wrapper view with background which contains {@link QSPanel} and {@link BaseStatusBarHeader} |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 30 | */ |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 31 | public class QSContainerImpl extends FrameLayout { |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 32 | |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 33 | private final Point mSizePoint = new Point(); |
| 34 | |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 35 | private int mHeightOverride = -1; |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 36 | protected View mQSPanel; |
| 37 | private View mQSDetail; |
| 38 | protected View mHeader; |
Muyuan Li | 4fe4a40 | 2016-03-30 16:50:11 -0700 | [diff] [blame] | 39 | protected float mQsExpansion; |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 40 | private QSCustomizer mQSCustomizer; |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 41 | private QSFooter mQSFooter; |
Jason Monk | 4de5d3c | 2017-05-24 14:57:10 -0400 | [diff] [blame] | 42 | private float mFullElevation; |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 43 | |
Jason Monk | 46767b7 | 2016-08-18 10:58:04 -0400 | [diff] [blame] | 44 | public QSContainerImpl(Context context, AttributeSet attrs) { |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 45 | super(context, attrs); |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | protected void onFinishInflate() { |
| 50 | super.onFinishInflate(); |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 51 | mQSPanel = findViewById(R.id.quick_settings_panel); |
| 52 | mQSDetail = findViewById(R.id.qs_detail); |
| 53 | mHeader = findViewById(R.id.header); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 54 | mQSCustomizer = findViewById(R.id.qs_customize); |
| 55 | mQSFooter = findViewById(R.id.qs_footer); |
Jason Monk | 4de5d3c | 2017-05-24 14:57:10 -0400 | [diff] [blame] | 56 | mFullElevation = mQSPanel.getElevation(); |
Jason Monk | 7b3d4e4 | 2017-05-30 12:47:10 -0400 | [diff] [blame] | 57 | |
| 58 | setClickable(true); |
| 59 | setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO); |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public boolean performClick() { |
| 64 | // Want to receive clicks so missing QQS tiles doesn't cause collapse, but |
| 65 | // don't want to do anything with them. |
| 66 | return true; |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 67 | } |
| 68 | |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 69 | @Override |
Jason Monk | 83e431f | 2016-02-19 19:32:13 -0500 | [diff] [blame] | 70 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 71 | // Since we control our own bottom, be whatever size we want. |
| 72 | // Otherwise the QSPanel ends up with 0 height when the window is only the |
| 73 | // size of the status bar. |
Jason Monk | 6573ef2 | 2016-04-06 12:37:18 -0400 | [diff] [blame] | 74 | mQSPanel.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec( |
| 75 | MeasureSpec.getSize(heightMeasureSpec), MeasureSpec.UNSPECIFIED)); |
| 76 | int width = mQSPanel.getMeasuredWidth(); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 77 | LayoutParams layoutParams = (LayoutParams) mQSPanel.getLayoutParams(); |
| 78 | int height = layoutParams.topMargin + layoutParams.bottomMargin |
Jason Monk | 6573ef2 | 2016-04-06 12:37:18 -0400 | [diff] [blame] | 79 | + mQSPanel.getMeasuredHeight(); |
| 80 | super.onMeasure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), |
| 81 | MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)); |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 82 | |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 83 | // QSCustomizer will always be the height of the screen, but do this after |
| 84 | // other measuring to avoid changing the height of the QS. |
Jason Monk | 8b9d67f | 2016-03-02 08:59:08 -0500 | [diff] [blame] | 85 | getDisplay().getRealSize(mSizePoint); |
| 86 | mQSCustomizer.measure(widthMeasureSpec, |
| 87 | MeasureSpec.makeMeasureSpec(mSizePoint.y, MeasureSpec.EXACTLY)); |
Jason Monk | 83e431f | 2016-02-19 19:32:13 -0500 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | @Override |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 91 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 92 | super.onLayout(changed, left, top, right, bottom); |
Jason Monk | 4de5d3c | 2017-05-24 14:57:10 -0400 | [diff] [blame] | 93 | updateExpansion(); |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Overrides the height of this view (post-layout), so that the content is clipped to that |
| 98 | * height and the background is set to that height. |
| 99 | * |
| 100 | * @param heightOverride the overridden height |
| 101 | */ |
| 102 | public void setHeightOverride(int heightOverride) { |
| 103 | mHeightOverride = heightOverride; |
Jason Monk | 4de5d3c | 2017-05-24 14:57:10 -0400 | [diff] [blame] | 104 | updateExpansion(); |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 105 | } |
| 106 | |
Jason Monk | 4de5d3c | 2017-05-24 14:57:10 -0400 | [diff] [blame] | 107 | public void updateExpansion() { |
Muyuan Li | 4fe4a40 | 2016-03-30 16:50:11 -0700 | [diff] [blame] | 108 | int height = calculateContainerHeight(); |
Jason Monk | 232ac2b | 2017-06-02 12:50:24 -0400 | [diff] [blame] | 109 | setBottom(getTop() + height); |
Jason Monk | 377e7ad | 2016-02-16 14:03:21 -0500 | [diff] [blame] | 110 | mQSDetail.setBottom(getTop() + height); |
Jason Monk | e5b770e | 2017-03-03 21:49:29 -0500 | [diff] [blame] | 111 | // Pin QS Footer to the bottom of the panel. |
| 112 | mQSFooter.setTranslationY(height - mQSFooter.getHeight()); |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 113 | } |
Jason Monk | e1be342 | 2016-02-09 10:51:40 -0500 | [diff] [blame] | 114 | |
Muyuan Li | 4fe4a40 | 2016-03-30 16:50:11 -0700 | [diff] [blame] | 115 | protected int calculateContainerHeight() { |
| 116 | int heightOverride = mHeightOverride != -1 ? mHeightOverride : getMeasuredHeight(); |
| 117 | return mQSCustomizer.isCustomizing() ? mQSCustomizer.getHeight() |
Jason Monk | 4de5d3c | 2017-05-24 14:57:10 -0400 | [diff] [blame] | 118 | : Math.round(mQsExpansion * (heightOverride - mHeader.getHeight())) |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 119 | + mHeader.getHeight(); |
Muyuan Li | 4fe4a40 | 2016-03-30 16:50:11 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 122 | public void setExpansion(float expansion) { |
Jason Monk | e1be342 | 2016-02-09 10:51:40 -0500 | [diff] [blame] | 123 | mQsExpansion = expansion; |
Jason Monk | 4de5d3c | 2017-05-24 14:57:10 -0400 | [diff] [blame] | 124 | updateExpansion(); |
| 125 | } |
Jorim Jaggi | 8bc983e | 2014-12-10 17:45:50 +0100 | [diff] [blame] | 126 | } |