blob: 1952a21057caf1fdab629e9cc4a4602ad4bdf884 [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;
37import com.android.systemui.statusbar.policy.HeadsUpManager;
38import com.android.systemui.statusbar.policy.OnHeadsUpChangedListener;
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
Jason Monk7ebba0b2017-04-20 14:10:20 -040044 implements OnInflateListener, FragmentListener, OnHeadsUpChangedListener {
Jorim Jaggibc976e32014-07-25 16:42:34 +020045
Jason Monk0ceef212016-11-02 14:05:23 -040046 private FrameLayout mQsFrame;
Jorim Jaggibc976e32014-07-25 16:42:34 +020047 private View mUserSwitcher;
48 private View mStackScroller;
Jorim Jaggibf1899e2014-08-07 02:04:18 +020049 private View mKeyguardStatusBar;
Jorim Jaggibc976e32014-07-25 16:42:34 +020050 private boolean mInflated;
Selim Cinekb8f09cf2015-03-16 17:09:28 -070051 private boolean mQsExpanded;
Jason Monk8b9d67f2016-03-02 08:59:08 -050052 private boolean mCustomizerAnimating;
Jorim Jaggid7daab72014-05-06 22:22:20 +020053
Jason Monk428914d2016-03-30 09:35:36 -040054 private int mBottomPadding;
55 private int mStackScrollerMargin;
Jason Monk7ebba0b2017-04-20 14:10:20 -040056 private boolean mHeadsUp;
57 private HeadsUpManager mHeadsUpManager;
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);
Jason Monk7ebba0b2017-04-20 14:10:20 -040079 mHeadsUpManager = SysUiServiceProvider.getComponent(getContext(), StatusBar.class)
80 .mHeadsUpManager;
81 mHeadsUpManager.addListener(this);
Jason Monk0ceef212016-11-02 14:05:23 -040082 }
83
84 @Override
85 protected void onDetachedFromWindow() {
86 super.onDetachedFromWindow();
87 FragmentHostManager.get(this).removeTagListener(QS.TAG, this);
Jason Monk7ebba0b2017-04-20 14:10:20 -040088 mHeadsUpManager.removeListener(this);
Jason Monk0ceef212016-11-02 14:05:23 -040089 }
90
91 @Override
Jason Monkbef6de82016-02-03 11:26:07 -050092 protected void onConfigurationChanged(Configuration newConfig) {
93 super.onConfigurationChanged(newConfig);
Anthony Chen185b6f62017-05-25 10:58:23 -070094 reloadWidth(mQsFrame, R.dimen.qs_panel_width);
95 reloadWidth(mStackScroller, R.dimen.notification_panel_width);
Jason Monkbef6de82016-02-03 11:26:07 -050096 }
97
Anthony Chen185b6f62017-05-25 10:58:23 -070098 /**
99 * Loads the given width resource and sets it on the given View.
100 */
101 private void reloadWidth(View view, @DimenRes int width) {
Jason Monkbef6de82016-02-03 11:26:07 -0500102 LayoutParams params = (LayoutParams) view.getLayoutParams();
Anthony Chen185b6f62017-05-25 10:58:23 -0700103 params.width = getResources().getDimensionPixelSize(width);
Jason Monkbef6de82016-02-03 11:26:07 -0500104 view.setLayoutParams(params);
105 }
106
107 @Override
Jorim Jaggie0700182014-08-21 01:12:37 +0200108 public WindowInsets onApplyWindowInsets(WindowInsets insets) {
Jason Monk428914d2016-03-30 09:35:36 -0400109 mBottomPadding = insets.getStableInsetBottom();
110 setPadding(0, 0, 0, mBottomPadding);
Jorim Jaggie0700182014-08-21 01:12:37 +0200111 return insets;
Jorim Jaggid7daab72014-05-06 22:22:20 +0200112 }
Jorim Jaggibc976e32014-07-25 16:42:34 +0200113
114 @Override
115 protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
116 boolean userSwitcherVisible = mInflated && mUserSwitcher.getVisibility() == View.VISIBLE;
Jorim Jaggibf1899e2014-08-07 02:04:18 +0200117 boolean statusBarVisible = mKeyguardStatusBar.getVisibility() == View.VISIBLE;
Jorim Jaggibc976e32014-07-25 16:42:34 +0200118
Jason Monk7ebba0b2017-04-20 14:10:20 -0400119 final boolean qsBottom = mHeadsUp;
Jason Monk0ceef212016-11-02 14:05:23 -0400120 View stackQsTop = qsBottom ? mStackScroller : mQsFrame;
121 View stackQsBottom = !qsBottom ? mStackScroller : mQsFrame;
Jorim Jaggibc976e32014-07-25 16:42:34 +0200122 // Invert the order of the scroll view and user switcher such that the notifications receive
123 // touches first but the panel gets drawn above.
Jason Monk0ceef212016-11-02 14:05:23 -0400124 if (child == mQsFrame) {
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700125 return super.drawChild(canvas, userSwitcherVisible && statusBarVisible ? mUserSwitcher
Jorim Jaggibf1899e2014-08-07 02:04:18 +0200126 : statusBarVisible ? mKeyguardStatusBar
127 : userSwitcherVisible ? mUserSwitcher
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700128 : stackQsBottom, drawingTime);
129 } else if (child == mStackScroller) {
130 return super.drawChild(canvas,
131 userSwitcherVisible && statusBarVisible ? mKeyguardStatusBar
132 : statusBarVisible || userSwitcherVisible ? stackQsBottom
133 : stackQsTop,
Jorim Jaggibc976e32014-07-25 16:42:34 +0200134 drawingTime);
135 } else if (child == mUserSwitcher) {
Jorim Jaggibf1899e2014-08-07 02:04:18 +0200136 return super.drawChild(canvas,
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700137 userSwitcherVisible && statusBarVisible ? stackQsBottom
138 : stackQsTop,
Jorim Jaggibc976e32014-07-25 16:42:34 +0200139 drawingTime);
Jorim Jaggibf1899e2014-08-07 02:04:18 +0200140 } else if (child == mKeyguardStatusBar) {
141 return super.drawChild(canvas,
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700142 stackQsTop,
Jorim Jaggibf1899e2014-08-07 02:04:18 +0200143 drawingTime);
Jason Monk16ac3772016-02-10 15:39:21 -0500144 } else {
Jorim Jaggibc976e32014-07-25 16:42:34 +0200145 return super.drawChild(canvas, child, drawingTime);
146 }
147 }
148
149 @Override
150 public void onInflate(ViewStub stub, View inflated) {
151 if (stub == mUserSwitcher) {
152 mUserSwitcher = inflated;
153 mInflated = true;
154 }
155 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700156
Jason Monk8b9d67f2016-03-02 08:59:08 -0500157 @Override
Jason Monk0ceef212016-11-02 14:05:23 -0400158 public void onFragmentViewCreated(String tag, Fragment fragment) {
159 QS container = (QS) fragment;
Jason Monk46767b72016-08-18 10:58:04 -0400160 container.setContainer(this);
Jason Monk8b9d67f2016-03-02 08:59:08 -0500161 }
162
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700163 public void setQsExpanded(boolean expanded) {
164 if (mQsExpanded != expanded) {
165 mQsExpanded = expanded;
166 invalidate();
167 }
168 }
Jason Monk8b9d67f2016-03-02 08:59:08 -0500169
170 public void setCustomizerAnimating(boolean isAnimating) {
171 if (mCustomizerAnimating != isAnimating) {
172 mCustomizerAnimating = isAnimating;
173 invalidate();
174 }
175 }
Jason Monk428914d2016-03-30 09:35:36 -0400176
177 public void setCustomizerShowing(boolean isShowing) {
178 if (isShowing) {
179 // Clear out bottom paddings/margins so the qs customization can be full height.
180 setPadding(0, 0, 0, 0);
181 setBottomMargin(mStackScroller, 0);
182 } else {
183 setPadding(0, 0, 0, mBottomPadding);
184 setBottomMargin(mStackScroller, mStackScrollerMargin);
185 }
186
187 }
188
189 private void setBottomMargin(View v, int bottomMargin) {
190 LayoutParams params = (LayoutParams) v.getLayoutParams();
191 params.bottomMargin = bottomMargin;
192 v.setLayoutParams(params);
193 }
Jason Monk7ebba0b2017-04-20 14:10:20 -0400194
195 @Override
196 public void onHeadsUpStateChanged(Entry entry, boolean isHeadsUp) {
197 boolean hasHeadsUp = mHeadsUpManager.getAllEntries().size() != 0;
198 if (mHeadsUp == hasHeadsUp) {
199 return;
200 }
201 mHeadsUp = hasHeadsUp;
202 invalidate();
203 }
Jorim Jaggid7daab72014-05-06 22:22:20 +0200204}