Home | History | Annotate | Download | only in phone
      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 
     17 package com.android.systemui.statusbar.phone;
     18 
     19 import android.content.Context;
     20 import android.graphics.Canvas;
     21 import android.util.AttributeSet;
     22 import android.view.View;
     23 import android.view.ViewStub;
     24 import android.view.WindowInsets;
     25 import android.widget.FrameLayout;
     26 
     27 import com.android.systemui.R;
     28 
     29 /**
     30  * The container with notification stack scroller and quick settings inside.
     31  */
     32 public class NotificationsQuickSettingsContainer extends FrameLayout
     33         implements ViewStub.OnInflateListener {
     34 
     35     private View mScrollView;
     36     private View mUserSwitcher;
     37     private View mStackScroller;
     38     private View mKeyguardStatusBar;
     39     private boolean mInflated;
     40     private boolean mQsExpanded;
     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         View stackQsTop = mQsExpanded ? mStackScroller : mScrollView;
     69         View stackQsBottom = !mQsExpanded ? mStackScroller : mScrollView;
     70         // Invert the order of the scroll view and user switcher such that the notifications receive
     71         // touches first but the panel gets drawn above.
     72         if (child == mScrollView) {
     73             return super.drawChild(canvas, userSwitcherVisible && statusBarVisible ? mUserSwitcher
     74                     : statusBarVisible ? mKeyguardStatusBar
     75                     : userSwitcherVisible ? mUserSwitcher
     76                     : stackQsBottom, drawingTime);
     77         } else if (child == mStackScroller) {
     78             return super.drawChild(canvas,
     79                     userSwitcherVisible && statusBarVisible ? mKeyguardStatusBar
     80                     : statusBarVisible || userSwitcherVisible ? stackQsBottom
     81                     : stackQsTop,
     82                     drawingTime);
     83         } else if (child == mUserSwitcher) {
     84             return super.drawChild(canvas,
     85                     userSwitcherVisible && statusBarVisible ? stackQsBottom
     86                     : stackQsTop,
     87                     drawingTime);
     88         } else if (child == mKeyguardStatusBar) {
     89             return super.drawChild(canvas,
     90                     stackQsTop,
     91                     drawingTime);
     92         }else {
     93             return super.drawChild(canvas, child, drawingTime);
     94         }
     95     }
     96 
     97     @Override
     98     public void onInflate(ViewStub stub, View inflated) {
     99         if (stub == mUserSwitcher) {
    100             mUserSwitcher = inflated;
    101             mInflated = true;
    102         }
    103     }
    104 
    105     public void setQsExpanded(boolean expanded) {
    106         if (mQsExpanded != expanded) {
    107             mQsExpanded = expanded;
    108             invalidate();
    109         }
    110     }
    111 }
    112