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