blob: 76cc0ff2a2e1f9f5680f67945f1a2e87c5936311 [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;
Anthony Chen185b6f62017-05-25 10:58:23 -070023import android.support.annotation.DimenRes;
Jorim Jaggid7daab72014-05-06 22:22:20 +020024import android.util.AttributeSet;
Jorim Jaggibc976e32014-07-25 16:42:34 +020025import android.view.View;
26import android.view.ViewStub;
Jason Monk7ebba0b2017-04-20 14:10:20 -040027import android.view.ViewStub.OnInflateListener;
Jorim Jaggie0700182014-08-21 01:12:37 +020028import android.view.WindowInsets;
Jorim Jaggid7daab72014-05-06 22:22:20 +020029import android.widget.FrameLayout;
Jason Monk46767b72016-08-18 10:58:04 -040030
Jorim Jaggibc976e32014-07-25 16:42:34 +020031import com.android.systemui.R;
Jason Monk7ebba0b2017-04-20 14:10:20 -040032import com.android.systemui.SysUiServiceProvider;
Jason Monk0ceef212016-11-02 14:05:23 -040033import com.android.systemui.fragments.FragmentHostManager;
Jason Monk7ebba0b2017-04-20 14:10:20 -040034import com.android.systemui.fragments.FragmentHostManager.FragmentListener;
Jason Monk0ceef212016-11-02 14:05:23 -040035import com.android.systemui.plugins.qs.QS;
Jason Monk7ebba0b2017-04-20 14:10:20 -040036import com.android.systemui.statusbar.NotificationData.Entry;
Selim Cinek5cf1d052017-06-01 17:36:46 -070037import com.android.systemui.statusbar.notification.AboveShelfObserver;
38import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
Jorim Jaggibc976e32014-07-25 16:42:34 +020039
Jorim Jaggid7daab72014-05-06 22:22:20 +020040/**
41 * The container with notification stack scroller and quick settings inside.
42 */
Jorim Jaggibc976e32014-07-25 16:42:34 +020043public class NotificationsQuickSettingsContainer extends FrameLayout
Selim Cinek5cf1d052017-06-01 17:36:46 -070044 implements OnInflateListener, FragmentListener,
45 AboveShelfObserver.HasViewAboveShelfChangedListener {
Jorim Jaggibc976e32014-07-25 16:42:34 +020046
Jason Monk0ceef212016-11-02 14:05:23 -040047 private FrameLayout mQsFrame;
Jorim Jaggibc976e32014-07-25 16:42:34 +020048 private View mUserSwitcher;
Selim Cinek5cf1d052017-06-01 17:36:46 -070049 private NotificationStackScrollLayout mStackScroller;
Jorim Jaggibf1899e2014-08-07 02:04:18 +020050 private View mKeyguardStatusBar;
Jorim Jaggibc976e32014-07-25 16:42:34 +020051 private boolean mInflated;
Selim Cinekb8f09cf2015-03-16 17:09:28 -070052 private boolean mQsExpanded;
Jason Monk8b9d67f2016-03-02 08:59:08 -050053 private boolean mCustomizerAnimating;
Jorim Jaggid7daab72014-05-06 22:22:20 +020054
Jason Monk428914d2016-03-30 09:35:36 -040055 private int mBottomPadding;
56 private int mStackScrollerMargin;
Selim Cinek5cf1d052017-06-01 17:36:46 -070057 private boolean mHasViewsAboveShelf;
Jason Monk428914d2016-03-30 09:35:36 -040058
Jorim Jaggid7daab72014-05-06 22:22:20 +020059 public NotificationsQuickSettingsContainer(Context context, AttributeSet attrs) {
60 super(context, attrs);
61 }
62
63 @Override
Jorim Jaggibc976e32014-07-25 16:42:34 +020064 protected void onFinishInflate() {
65 super.onFinishInflate();
Jason Monk0ceef212016-11-02 14:05:23 -040066 mQsFrame = (FrameLayout) findViewById(R.id.qs_frame);
Jorim Jaggibc976e32014-07-25 16:42:34 +020067 mStackScroller = findViewById(R.id.notification_stack_scroller);
Jason Monk428914d2016-03-30 09:35:36 -040068 mStackScrollerMargin = ((LayoutParams) mStackScroller.getLayoutParams()).bottomMargin;
Jorim Jaggibf1899e2014-08-07 02:04:18 +020069 mKeyguardStatusBar = findViewById(R.id.keyguard_header);
Jorim Jaggibc976e32014-07-25 16:42:34 +020070 ViewStub userSwitcher = (ViewStub) findViewById(R.id.keyguard_user_switcher);
71 userSwitcher.setOnInflateListener(this);
72 mUserSwitcher = userSwitcher;
73 }
74
75 @Override
Jason Monk0ceef212016-11-02 14:05:23 -040076 protected void onAttachedToWindow() {
77 super.onAttachedToWindow();
78 FragmentHostManager.get(this).addTagListener(QS.TAG, this);
79 }
80
81 @Override
82 protected void onDetachedFromWindow() {
83 super.onDetachedFromWindow();
84 FragmentHostManager.get(this).removeTagListener(QS.TAG, this);
85 }
86
87 @Override
Jason Monkbef6de82016-02-03 11:26:07 -050088 protected void onConfigurationChanged(Configuration newConfig) {
89 super.onConfigurationChanged(newConfig);
Anthony Chen185b6f62017-05-25 10:58:23 -070090 reloadWidth(mQsFrame, R.dimen.qs_panel_width);
91 reloadWidth(mStackScroller, R.dimen.notification_panel_width);
Jason Monkbef6de82016-02-03 11:26:07 -050092 }
93
Anthony Chen185b6f62017-05-25 10:58:23 -070094 /**
95 * Loads the given width resource and sets it on the given View.
96 */
97 private void reloadWidth(View view, @DimenRes int width) {
Jason Monkbef6de82016-02-03 11:26:07 -050098 LayoutParams params = (LayoutParams) view.getLayoutParams();
Anthony Chen185b6f62017-05-25 10:58:23 -070099 params.width = getResources().getDimensionPixelSize(width);
Jason Monkbef6de82016-02-03 11:26:07 -0500100 view.setLayoutParams(params);
101 }
102
103 @Override
Jorim Jaggie0700182014-08-21 01:12:37 +0200104 public WindowInsets onApplyWindowInsets(WindowInsets insets) {
Jason Monk428914d2016-03-30 09:35:36 -0400105 mBottomPadding = insets.getStableInsetBottom();
106 setPadding(0, 0, 0, mBottomPadding);
Jorim Jaggie0700182014-08-21 01:12:37 +0200107 return insets;
Jorim Jaggid7daab72014-05-06 22:22:20 +0200108 }
Jorim Jaggibc976e32014-07-25 16:42:34 +0200109
110 @Override
111 protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
112 boolean userSwitcherVisible = mInflated && mUserSwitcher.getVisibility() == View.VISIBLE;
Jorim Jaggibf1899e2014-08-07 02:04:18 +0200113 boolean statusBarVisible = mKeyguardStatusBar.getVisibility() == View.VISIBLE;
Jorim Jaggibc976e32014-07-25 16:42:34 +0200114
Selim Cinek5cf1d052017-06-01 17:36:46 -0700115 final boolean qsBottom = mHasViewsAboveShelf;
Jason Monk0ceef212016-11-02 14:05:23 -0400116 View stackQsTop = qsBottom ? mStackScroller : mQsFrame;
117 View stackQsBottom = !qsBottom ? mStackScroller : mQsFrame;
Jorim Jaggibc976e32014-07-25 16:42:34 +0200118 // Invert the order of the scroll view and user switcher such that the notifications receive
119 // touches first but the panel gets drawn above.
Jason Monk0ceef212016-11-02 14:05:23 -0400120 if (child == mQsFrame) {
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700121 return super.drawChild(canvas, userSwitcherVisible && statusBarVisible ? mUserSwitcher
Jorim Jaggibf1899e2014-08-07 02:04:18 +0200122 : statusBarVisible ? mKeyguardStatusBar
123 : userSwitcherVisible ? mUserSwitcher
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700124 : stackQsBottom, drawingTime);
125 } else if (child == mStackScroller) {
126 return super.drawChild(canvas,
127 userSwitcherVisible && statusBarVisible ? mKeyguardStatusBar
128 : statusBarVisible || userSwitcherVisible ? stackQsBottom
129 : stackQsTop,
Jorim Jaggibc976e32014-07-25 16:42:34 +0200130 drawingTime);
131 } else if (child == mUserSwitcher) {
Jorim Jaggibf1899e2014-08-07 02:04:18 +0200132 return super.drawChild(canvas,
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700133 userSwitcherVisible && statusBarVisible ? stackQsBottom
134 : stackQsTop,
Jorim Jaggibc976e32014-07-25 16:42:34 +0200135 drawingTime);
Jorim Jaggibf1899e2014-08-07 02:04:18 +0200136 } else if (child == mKeyguardStatusBar) {
137 return super.drawChild(canvas,
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700138 stackQsTop,
Jorim Jaggibf1899e2014-08-07 02:04:18 +0200139 drawingTime);
Jason Monk16ac3772016-02-10 15:39:21 -0500140 } else {
Jorim Jaggibc976e32014-07-25 16:42:34 +0200141 return super.drawChild(canvas, child, drawingTime);
142 }
143 }
144
145 @Override
146 public void onInflate(ViewStub stub, View inflated) {
147 if (stub == mUserSwitcher) {
148 mUserSwitcher = inflated;
149 mInflated = true;
150 }
151 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700152
Jason Monk8b9d67f2016-03-02 08:59:08 -0500153 @Override
Jason Monk0ceef212016-11-02 14:05:23 -0400154 public void onFragmentViewCreated(String tag, Fragment fragment) {
155 QS container = (QS) fragment;
Jason Monk46767b72016-08-18 10:58:04 -0400156 container.setContainer(this);
Jason Monk8b9d67f2016-03-02 08:59:08 -0500157 }
158
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700159 public void setQsExpanded(boolean expanded) {
160 if (mQsExpanded != expanded) {
161 mQsExpanded = expanded;
162 invalidate();
163 }
164 }
Jason Monk8b9d67f2016-03-02 08:59:08 -0500165
166 public void setCustomizerAnimating(boolean isAnimating) {
167 if (mCustomizerAnimating != isAnimating) {
168 mCustomizerAnimating = isAnimating;
169 invalidate();
170 }
171 }
Jason Monk428914d2016-03-30 09:35:36 -0400172
173 public void setCustomizerShowing(boolean isShowing) {
174 if (isShowing) {
175 // Clear out bottom paddings/margins so the qs customization can be full height.
176 setPadding(0, 0, 0, 0);
177 setBottomMargin(mStackScroller, 0);
178 } else {
179 setPadding(0, 0, 0, mBottomPadding);
180 setBottomMargin(mStackScroller, mStackScrollerMargin);
181 }
Selim Cinek5cf1d052017-06-01 17:36:46 -0700182 mStackScroller.setQsCustomizerShowing(isShowing);
Jason Monk428914d2016-03-30 09:35:36 -0400183 }
184
185 private void setBottomMargin(View v, int bottomMargin) {
186 LayoutParams params = (LayoutParams) v.getLayoutParams();
187 params.bottomMargin = bottomMargin;
188 v.setLayoutParams(params);
189 }
Jason Monk7ebba0b2017-04-20 14:10:20 -0400190
191 @Override
Selim Cinek5cf1d052017-06-01 17:36:46 -0700192 public void onHasViewsAboveShelfChanged(boolean hasViewsAboveShelf) {
193 mHasViewsAboveShelf = hasViewsAboveShelf;
Jason Monk7ebba0b2017-04-20 14:10:20 -0400194 invalidate();
195 }
Jorim Jaggid7daab72014-05-06 22:22:20 +0200196}