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.statusbar.phone;
18
19import android.content.Context;
20import android.graphics.Canvas;
21import android.graphics.Rect;
22import android.util.AttributeSet;
23import android.view.View;
24import android.view.ViewStub;
25import android.view.WindowInsets;
26import android.widget.FrameLayout;
27
28import com.android.systemui.R;
29
30/**
31 * The container with notification stack scroller and quick settings inside.
32 */
33public class NotificationsQuickSettingsContainer extends FrameLayout
34        implements ViewStub.OnInflateListener {
35
36    private View mScrollView;
37    private View mUserSwitcher;
38    private View mStackScroller;
39    private View mKeyguardStatusBar;
40    private boolean mInflated;
41
42    public NotificationsQuickSettingsContainer(Context context, AttributeSet attrs) {
43        super(context, attrs);
44    }
45
46    @Override
47    protected void onFinishInflate() {
48        super.onFinishInflate();
49        mScrollView = findViewById(R.id.scroll_view);
50        mStackScroller = findViewById(R.id.notification_stack_scroller);
51        mKeyguardStatusBar = findViewById(R.id.keyguard_header);
52        ViewStub userSwitcher = (ViewStub) findViewById(R.id.keyguard_user_switcher);
53        userSwitcher.setOnInflateListener(this);
54        mUserSwitcher = userSwitcher;
55    }
56
57    @Override
58    public WindowInsets onApplyWindowInsets(WindowInsets insets) {
59        setPadding(0, 0, 0, insets.getSystemWindowInsetBottom());
60        return insets;
61    }
62
63    @Override
64    protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
65        boolean userSwitcherVisible = mInflated && mUserSwitcher.getVisibility() == View.VISIBLE;
66        boolean statusBarVisible = mKeyguardStatusBar.getVisibility() == View.VISIBLE;
67
68        // Invert the order of the scroll view and user switcher such that the notifications receive
69        // touches first but the panel gets drawn above.
70        if (child == mScrollView) {
71            return super.drawChild(canvas, mStackScroller, drawingTime);
72        } else if (child == mStackScroller) {
73            return super.drawChild(canvas,
74                    userSwitcherVisible && statusBarVisible ? mUserSwitcher
75                    : statusBarVisible ? mKeyguardStatusBar
76                    : userSwitcherVisible ? mUserSwitcher
77                    : mScrollView,
78                    drawingTime);
79        } else if (child == mUserSwitcher) {
80            return super.drawChild(canvas,
81                    userSwitcherVisible && statusBarVisible ? mKeyguardStatusBar
82                    : mScrollView,
83                    drawingTime);
84        } else if (child == mKeyguardStatusBar) {
85            return super.drawChild(canvas,
86                    userSwitcherVisible && statusBarVisible ? mScrollView
87                    : mScrollView,
88                    drawingTime);
89        }else {
90            return super.drawChild(canvas, child, drawingTime);
91        }
92    }
93
94    @Override
95    public void onInflate(ViewStub stub, View inflated) {
96        if (stub == mUserSwitcher) {
97            mUserSwitcher = inflated;
98            mInflated = true;
99        }
100    }
101}
102