18bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi/*
28bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi * Copyright (C) 2014 The Android Open Source Project
38bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi *
48bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi * Licensed under the Apache License, Version 2.0 (the "License");
58bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi * you may not use this file except in compliance with the License.
68bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi * You may obtain a copy of the License at
78bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi *
88bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi *      http://www.apache.org/licenses/LICENSE-2.0
98bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi *
108bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi * Unless required by applicable law or agreed to in writing, software
118bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi * distributed under the License is distributed on an "AS IS" BASIS,
128bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
138bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi * See the License for the specific language governing permissions and
148bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi * limitations under the License
158bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi */
168bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi
178bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggipackage com.android.systemui.qs;
188bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi
198bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggiimport android.content.Context;
208bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggiimport android.util.AttributeSet;
218bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggiimport android.widget.FrameLayout;
228bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi
238bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggiimport com.android.systemui.R;
248bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi
258bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi/**
268bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi * Wrapper view with background which contains {@link QSPanel}
278bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi */
288bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggipublic class QSContainer extends FrameLayout {
298bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi
308bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi    private int mHeightOverride = -1;
318bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi    private QSPanel mQSPanel;
328bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi
338bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi    public QSContainer(Context context, AttributeSet attrs) {
348bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi        super(context, attrs);
358bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi    }
368bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi
378bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi    @Override
388bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi    protected void onFinishInflate() {
398bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi        super.onFinishInflate();
408bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi        mQSPanel = (QSPanel) findViewById(R.id.quick_settings_panel);
418bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi    }
428bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi
438bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi    @Override
448bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
458bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi        super.onLayout(changed, left, top, right, bottom);
468bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi        updateBottom();
478bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi    }
488bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi
498bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi    /**
508bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi     * Overrides the height of this view (post-layout), so that the content is clipped to that
518bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi     * height and the background is set to that height.
528bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi     *
538bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi     * @param heightOverride the overridden height
548bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi     */
558bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi    public void setHeightOverride(int heightOverride) {
568bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi        mHeightOverride = heightOverride;
578bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi        updateBottom();
588bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi    }
598bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi
608bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi    /**
618bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi     * The height this view wants to be. This is different from {@link #getMeasuredHeight} such that
628bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi     * during closing the detail panel, this already returns the smaller height.
638bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi     */
648bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi    public int getDesiredHeight() {
658bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi        if (mQSPanel.isClosingDetail()) {
668bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi            return mQSPanel.getGridHeight() + getPaddingTop() + getPaddingBottom();
678bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi        } else {
688bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi            return getMeasuredHeight();
698bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi        }
708bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi    }
718bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi
728bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi    private void updateBottom() {
738bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi        int height = mHeightOverride != -1 ? mHeightOverride : getMeasuredHeight();
748bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi        setBottom(getTop() + height);
758bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi    }
768bc983efc439c321c8f548d384d807c31daf9180Jorim Jaggi}
77