blob: ed57c043a10964b513922582748e5cb0b948ccaa [file] [log] [blame]
Jorim Jaggi8bc983e2014-12-10 17:45:50 +01001/*
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
17package com.android.systemui.qs;
18
19import android.content.Context;
Jason Monk8b9d67f2016-03-02 08:59:08 -050020import android.graphics.Point;
Jorim Jaggi8bc983e2014-12-10 17:45:50 +010021import android.util.AttributeSet;
Jason Monke1be3422016-02-09 10:51:40 -050022import android.view.View;
Jason Monk0ceef212016-11-02 14:05:23 -040023import android.widget.FrameLayout;
Jason Monk46767b72016-08-18 10:58:04 -040024
Jorim Jaggi8bc983e2014-12-10 17:45:50 +010025import com.android.systemui.R;
Jason Monk8b9d67f2016-03-02 08:59:08 -050026import com.android.systemui.qs.customize.QSCustomizer;
Jorim Jaggi8bc983e2014-12-10 17:45:50 +010027
28/**
Jason Monke1be3422016-02-09 10:51:40 -050029 * Wrapper view with background which contains {@link QSPanel} and {@link BaseStatusBarHeader}
Jorim Jaggi8bc983e2014-12-10 17:45:50 +010030 */
Jason Monk0ceef212016-11-02 14:05:23 -040031public class QSContainerImpl extends FrameLayout {
Jorim Jaggi8bc983e2014-12-10 17:45:50 +010032
Jason Monk8b9d67f2016-03-02 08:59:08 -050033 private final Point mSizePoint = new Point();
34
Jorim Jaggi8bc983e2014-12-10 17:45:50 +010035 private int mHeightOverride = -1;
Jason Monk0ceef212016-11-02 14:05:23 -040036 protected View mQSPanel;
37 private View mQSDetail;
38 protected View mHeader;
Muyuan Li4fe4a402016-03-30 16:50:11 -070039 protected float mQsExpansion;
Jason Monk8b9d67f2016-03-02 08:59:08 -050040 private QSCustomizer mQSCustomizer;
Jason Monke5b770e2017-03-03 21:49:29 -050041 private QSFooter mQSFooter;
Jason Monk4de5d3c2017-05-24 14:57:10 -040042 private float mFullElevation;
Jorim Jaggi8bc983e2014-12-10 17:45:50 +010043
Jason Monk46767b72016-08-18 10:58:04 -040044 public QSContainerImpl(Context context, AttributeSet attrs) {
Jorim Jaggi8bc983e2014-12-10 17:45:50 +010045 super(context, attrs);
46 }
47
48 @Override
49 protected void onFinishInflate() {
50 super.onFinishInflate();
Jason Monk0ceef212016-11-02 14:05:23 -040051 mQSPanel = findViewById(R.id.quick_settings_panel);
52 mQSDetail = findViewById(R.id.qs_detail);
53 mHeader = findViewById(R.id.header);
Jason Monke5b770e2017-03-03 21:49:29 -050054 mQSCustomizer = findViewById(R.id.qs_customize);
55 mQSFooter = findViewById(R.id.qs_footer);
Jason Monk4de5d3c2017-05-24 14:57:10 -040056 mFullElevation = mQSPanel.getElevation();
Jason Monk7b3d4e42017-05-30 12:47:10 -040057
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 Monk8b9d67f2016-03-02 08:59:08 -050067 }
68
Jorim Jaggi8bc983e2014-12-10 17:45:50 +010069 @Override
Jason Monk83e431f2016-02-19 19:32:13 -050070 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 Monk6573ef22016-04-06 12:37:18 -040074 mQSPanel.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(
75 MeasureSpec.getSize(heightMeasureSpec), MeasureSpec.UNSPECIFIED));
76 int width = mQSPanel.getMeasuredWidth();
Jason Monke5b770e2017-03-03 21:49:29 -050077 LayoutParams layoutParams = (LayoutParams) mQSPanel.getLayoutParams();
78 int height = layoutParams.topMargin + layoutParams.bottomMargin
Jason Monk6573ef22016-04-06 12:37:18 -040079 + mQSPanel.getMeasuredHeight();
80 super.onMeasure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
81 MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
Jason Monk8b9d67f2016-03-02 08:59:08 -050082
Jason Monk0ceef212016-11-02 14:05:23 -040083 // 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 Monk8b9d67f2016-03-02 08:59:08 -050085 getDisplay().getRealSize(mSizePoint);
86 mQSCustomizer.measure(widthMeasureSpec,
87 MeasureSpec.makeMeasureSpec(mSizePoint.y, MeasureSpec.EXACTLY));
Jason Monk83e431f2016-02-19 19:32:13 -050088 }
89
90 @Override
Jorim Jaggi8bc983e2014-12-10 17:45:50 +010091 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
92 super.onLayout(changed, left, top, right, bottom);
Jason Monk4de5d3c2017-05-24 14:57:10 -040093 updateExpansion();
Jorim Jaggi8bc983e2014-12-10 17:45:50 +010094 }
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 Monk4de5d3c2017-05-24 14:57:10 -0400104 updateExpansion();
Jorim Jaggi8bc983e2014-12-10 17:45:50 +0100105 }
106
Jason Monk4de5d3c2017-05-24 14:57:10 -0400107 public void updateExpansion() {
Muyuan Li4fe4a402016-03-30 16:50:11 -0700108 int height = calculateContainerHeight();
Jason Monk232ac2b2017-06-02 12:50:24 -0400109 setBottom(getTop() + height);
Jason Monk377e7ad2016-02-16 14:03:21 -0500110 mQSDetail.setBottom(getTop() + height);
Jason Monke5b770e2017-03-03 21:49:29 -0500111 // Pin QS Footer to the bottom of the panel.
112 mQSFooter.setTranslationY(height - mQSFooter.getHeight());
Jorim Jaggi8bc983e2014-12-10 17:45:50 +0100113 }
Jason Monke1be3422016-02-09 10:51:40 -0500114
Muyuan Li4fe4a402016-03-30 16:50:11 -0700115 protected int calculateContainerHeight() {
116 int heightOverride = mHeightOverride != -1 ? mHeightOverride : getMeasuredHeight();
117 return mQSCustomizer.isCustomizing() ? mQSCustomizer.getHeight()
Jason Monk4de5d3c2017-05-24 14:57:10 -0400118 : Math.round(mQsExpansion * (heightOverride - mHeader.getHeight()))
Jason Monk0ceef212016-11-02 14:05:23 -0400119 + mHeader.getHeight();
Muyuan Li4fe4a402016-03-30 16:50:11 -0700120 }
121
Jason Monk0ceef212016-11-02 14:05:23 -0400122 public void setExpansion(float expansion) {
Jason Monke1be3422016-02-09 10:51:40 -0500123 mQsExpansion = expansion;
Jason Monk4de5d3c2017-05-24 14:57:10 -0400124 updateExpansion();
125 }
Jorim Jaggi8bc983e2014-12-10 17:45:50 +0100126}