blob: c85584e9738690c80a00e461bbe39a5d5b276240 [file] [log] [blame]
Jorim Jaggid7daab72014-05-06 22:22:20 +02001/*
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
Jason Monk0ceef212016-11-02 14:05:23 -040019import android.app.Fragment;
Jorim Jaggid7daab72014-05-06 22:22:20 +020020import android.content.Context;
Jason Monkbef6de82016-02-03 11:26:07 -050021import android.content.res.Configuration;
Jorim Jaggibc976e32014-07-25 16:42:34 +020022import android.graphics.Canvas;
Jorim Jaggid7daab72014-05-06 22:22:20 +020023import android.util.AttributeSet;
Jorim Jaggibc976e32014-07-25 16:42:34 +020024import android.view.View;
25import android.view.ViewStub;
Jorim Jaggie0700182014-08-21 01:12:37 +020026import android.view.WindowInsets;
Jorim Jaggid7daab72014-05-06 22:22:20 +020027import android.widget.FrameLayout;
Jason Monk46767b72016-08-18 10:58:04 -040028
Jorim Jaggibc976e32014-07-25 16:42:34 +020029import com.android.systemui.R;
Jason Monk0ceef212016-11-02 14:05:23 -040030import com.android.systemui.fragments.FragmentHostManager;
31import com.android.systemui.plugins.qs.QS;
Jorim Jaggibc976e32014-07-25 16:42:34 +020032
Jorim Jaggid7daab72014-05-06 22:22:20 +020033/**
34 * The container with notification stack scroller and quick settings inside.
35 */
Jorim Jaggibc976e32014-07-25 16:42:34 +020036public class NotificationsQuickSettingsContainer extends FrameLayout
Jason Monk0ceef212016-11-02 14:05:23 -040037 implements ViewStub.OnInflateListener, FragmentHostManager.FragmentListener {
Jorim Jaggibc976e32014-07-25 16:42:34 +020038
Jason Monk0ceef212016-11-02 14:05:23 -040039 private FrameLayout mQsFrame;
Jorim Jaggibc976e32014-07-25 16:42:34 +020040 private View mUserSwitcher;
41 private View mStackScroller;
Jorim Jaggibf1899e2014-08-07 02:04:18 +020042 private View mKeyguardStatusBar;
Jorim Jaggibc976e32014-07-25 16:42:34 +020043 private boolean mInflated;
Selim Cinekb8f09cf2015-03-16 17:09:28 -070044 private boolean mQsExpanded;
Jason Monk8b9d67f2016-03-02 08:59:08 -050045 private boolean mCustomizerAnimating;
Jorim Jaggid7daab72014-05-06 22:22:20 +020046
Jason Monk428914d2016-03-30 09:35:36 -040047 private int mBottomPadding;
48 private int mStackScrollerMargin;
49
Jorim Jaggid7daab72014-05-06 22:22:20 +020050 public NotificationsQuickSettingsContainer(Context context, AttributeSet attrs) {
51 super(context, attrs);
52 }
53
54 @Override
Jorim Jaggibc976e32014-07-25 16:42:34 +020055 protected void onFinishInflate() {
56 super.onFinishInflate();
Jason Monk0ceef212016-11-02 14:05:23 -040057 mQsFrame = (FrameLayout) findViewById(R.id.qs_frame);
Jorim Jaggibc976e32014-07-25 16:42:34 +020058 mStackScroller = findViewById(R.id.notification_stack_scroller);
Jason Monk428914d2016-03-30 09:35:36 -040059 mStackScrollerMargin = ((LayoutParams) mStackScroller.getLayoutParams()).bottomMargin;
Jorim Jaggibf1899e2014-08-07 02:04:18 +020060 mKeyguardStatusBar = findViewById(R.id.keyguard_header);
Jorim Jaggibc976e32014-07-25 16:42:34 +020061 ViewStub userSwitcher = (ViewStub) findViewById(R.id.keyguard_user_switcher);
62 userSwitcher.setOnInflateListener(this);
63 mUserSwitcher = userSwitcher;
64 }
65
66 @Override
Jason Monk0ceef212016-11-02 14:05:23 -040067 protected void onAttachedToWindow() {
68 super.onAttachedToWindow();
69 FragmentHostManager.get(this).addTagListener(QS.TAG, this);
70 }
71
72 @Override
73 protected void onDetachedFromWindow() {
74 super.onDetachedFromWindow();
75 FragmentHostManager.get(this).removeTagListener(QS.TAG, this);
76 }
77
78 @Override
Jason Monkbef6de82016-02-03 11:26:07 -050079 protected void onConfigurationChanged(Configuration newConfig) {
80 super.onConfigurationChanged(newConfig);
Jason Monk0ceef212016-11-02 14:05:23 -040081 reloadWidth(mQsFrame);
Jason Monkbef6de82016-02-03 11:26:07 -050082 reloadWidth(mStackScroller);
83 }
84
85 private void reloadWidth(View view) {
86 LayoutParams params = (LayoutParams) view.getLayoutParams();
87 params.width = getContext().getResources().getDimensionPixelSize(
88 R.dimen.notification_panel_width);
89 view.setLayoutParams(params);
90 }
91
92 @Override
Jorim Jaggie0700182014-08-21 01:12:37 +020093 public WindowInsets onApplyWindowInsets(WindowInsets insets) {
Jason Monk428914d2016-03-30 09:35:36 -040094 mBottomPadding = insets.getStableInsetBottom();
95 setPadding(0, 0, 0, mBottomPadding);
Jorim Jaggie0700182014-08-21 01:12:37 +020096 return insets;
Jorim Jaggid7daab72014-05-06 22:22:20 +020097 }
Jorim Jaggibc976e32014-07-25 16:42:34 +020098
99 @Override
100 protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
101 boolean userSwitcherVisible = mInflated && mUserSwitcher.getVisibility() == View.VISIBLE;
Jorim Jaggibf1899e2014-08-07 02:04:18 +0200102 boolean statusBarVisible = mKeyguardStatusBar.getVisibility() == View.VISIBLE;
Jorim Jaggibc976e32014-07-25 16:42:34 +0200103
Jason Monk8b9d67f2016-03-02 08:59:08 -0500104 final boolean qsBottom = mQsExpanded && !mCustomizerAnimating;
Jason Monk0ceef212016-11-02 14:05:23 -0400105 View stackQsTop = qsBottom ? mStackScroller : mQsFrame;
106 View stackQsBottom = !qsBottom ? mStackScroller : mQsFrame;
Jorim Jaggibc976e32014-07-25 16:42:34 +0200107 // Invert the order of the scroll view and user switcher such that the notifications receive
108 // touches first but the panel gets drawn above.
Jason Monk0ceef212016-11-02 14:05:23 -0400109 if (child == mQsFrame) {
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700110 return super.drawChild(canvas, userSwitcherVisible && statusBarVisible ? mUserSwitcher
Jorim Jaggibf1899e2014-08-07 02:04:18 +0200111 : statusBarVisible ? mKeyguardStatusBar
112 : userSwitcherVisible ? mUserSwitcher
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700113 : stackQsBottom, drawingTime);
114 } else if (child == mStackScroller) {
115 return super.drawChild(canvas,
116 userSwitcherVisible && statusBarVisible ? mKeyguardStatusBar
117 : statusBarVisible || userSwitcherVisible ? stackQsBottom
118 : stackQsTop,
Jorim Jaggibc976e32014-07-25 16:42:34 +0200119 drawingTime);
120 } else if (child == mUserSwitcher) {
Jorim Jaggibf1899e2014-08-07 02:04:18 +0200121 return super.drawChild(canvas,
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700122 userSwitcherVisible && statusBarVisible ? stackQsBottom
123 : stackQsTop,
Jorim Jaggibc976e32014-07-25 16:42:34 +0200124 drawingTime);
Jorim Jaggibf1899e2014-08-07 02:04:18 +0200125 } else if (child == mKeyguardStatusBar) {
126 return super.drawChild(canvas,
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700127 stackQsTop,
Jorim Jaggibf1899e2014-08-07 02:04:18 +0200128 drawingTime);
Jason Monk16ac3772016-02-10 15:39:21 -0500129 } else {
Jorim Jaggibc976e32014-07-25 16:42:34 +0200130 return super.drawChild(canvas, child, drawingTime);
131 }
132 }
133
134 @Override
135 public void onInflate(ViewStub stub, View inflated) {
136 if (stub == mUserSwitcher) {
137 mUserSwitcher = inflated;
138 mInflated = true;
139 }
140 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700141
Jason Monk8b9d67f2016-03-02 08:59:08 -0500142 @Override
Jason Monk0ceef212016-11-02 14:05:23 -0400143 public void onFragmentViewCreated(String tag, Fragment fragment) {
144 QS container = (QS) fragment;
Jason Monk46767b72016-08-18 10:58:04 -0400145 container.setContainer(this);
Jason Monk8b9d67f2016-03-02 08:59:08 -0500146 }
147
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700148 public void setQsExpanded(boolean expanded) {
149 if (mQsExpanded != expanded) {
150 mQsExpanded = expanded;
151 invalidate();
152 }
153 }
Jason Monk8b9d67f2016-03-02 08:59:08 -0500154
155 public void setCustomizerAnimating(boolean isAnimating) {
156 if (mCustomizerAnimating != isAnimating) {
157 mCustomizerAnimating = isAnimating;
158 invalidate();
159 }
160 }
Jason Monk428914d2016-03-30 09:35:36 -0400161
162 public void setCustomizerShowing(boolean isShowing) {
163 if (isShowing) {
164 // Clear out bottom paddings/margins so the qs customization can be full height.
165 setPadding(0, 0, 0, 0);
166 setBottomMargin(mStackScroller, 0);
167 } else {
168 setPadding(0, 0, 0, mBottomPadding);
169 setBottomMargin(mStackScroller, mStackScrollerMargin);
170 }
171
172 }
173
174 private void setBottomMargin(View v, int bottomMargin) {
175 LayoutParams params = (LayoutParams) v.getLayoutParams();
176 params.bottomMargin = bottomMargin;
177 v.setLayoutParams(params);
178 }
Jorim Jaggid7daab72014-05-06 22:22:20 +0200179}