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
17package com.android.systemui.qs;
18
19import android.content.Context;
20import android.util.AttributeSet;
21import android.widget.FrameLayout;
22
23import com.android.systemui.R;
24
25/**
26 * Wrapper view with background which contains {@link QSPanel}
27 */
28public class QSContainer extends FrameLayout {
29
30    private int mHeightOverride = -1;
31    private QSPanel mQSPanel;
32
33    public QSContainer(Context context, AttributeSet attrs) {
34        super(context, attrs);
35    }
36
37    @Override
38    protected void onFinishInflate() {
39        super.onFinishInflate();
40        mQSPanel = (QSPanel) findViewById(R.id.quick_settings_panel);
41    }
42
43    @Override
44    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
45        super.onLayout(changed, left, top, right, bottom);
46        updateBottom();
47    }
48
49    /**
50     * Overrides the height of this view (post-layout), so that the content is clipped to that
51     * height and the background is set to that height.
52     *
53     * @param heightOverride the overridden height
54     */
55    public void setHeightOverride(int heightOverride) {
56        mHeightOverride = heightOverride;
57        updateBottom();
58    }
59
60    /**
61     * The height this view wants to be. This is different from {@link #getMeasuredHeight} such that
62     * during closing the detail panel, this already returns the smaller height.
63     */
64    public int getDesiredHeight() {
65        if (mQSPanel.isClosingDetail()) {
66            return mQSPanel.getGridHeight() + getPaddingTop() + getPaddingBottom();
67        } else {
68            return getMeasuredHeight();
69        }
70    }
71
72    private void updateBottom() {
73        int height = mHeightOverride != -1 ? mHeightOverride : getMeasuredHeight();
74        setBottom(getTop() + height);
75    }
76}
77