blob: 646f3d8b8232b6a148fc72b3b9c82e183fc1f565 [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;
Jason Monk7ebba0b2017-04-20 14:10:20 -040026import android.view.ViewStub.OnInflateListener;
Jorim Jaggie0700182014-08-21 01:12:37 +020027import android.view.WindowInsets;
Jorim Jaggid7daab72014-05-06 22:22:20 +020028import android.widget.FrameLayout;
Jason Monk46767b72016-08-18 10:58:04 -040029
Jorim Jaggibc976e32014-07-25 16:42:34 +020030import com.android.systemui.R;
Jason Monk7ebba0b2017-04-20 14:10:20 -040031import com.android.systemui.SysUiServiceProvider;
Jason Monk0ceef212016-11-02 14:05:23 -040032import com.android.systemui.fragments.FragmentHostManager;
Jason Monk7ebba0b2017-04-20 14:10:20 -040033import com.android.systemui.fragments.FragmentHostManager.FragmentListener;
Jason Monk0ceef212016-11-02 14:05:23 -040034import com.android.systemui.plugins.qs.QS;
Jason Monk7ebba0b2017-04-20 14:10:20 -040035import com.android.systemui.recents.misc.SystemServicesProxy;
36import 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);
Jason Monk0ceef212016-11-02 14:05:23 -040094 reloadWidth(mQsFrame);
Jason Monkbef6de82016-02-03 11:26:07 -050095 reloadWidth(mStackScroller);
96 }
97
98 private void reloadWidth(View view) {
99 LayoutParams params = (LayoutParams) view.getLayoutParams();
100 params.width = getContext().getResources().getDimensionPixelSize(
101 R.dimen.notification_panel_width);
102 view.setLayoutParams(params);
103 }
104
105 @Override
Jorim Jaggie0700182014-08-21 01:12:37 +0200106 public WindowInsets onApplyWindowInsets(WindowInsets insets) {
Jason Monk428914d2016-03-30 09:35:36 -0400107 mBottomPadding = insets.getStableInsetBottom();
108 setPadding(0, 0, 0, mBottomPadding);
Jorim Jaggie0700182014-08-21 01:12:37 +0200109 return insets;
Jorim Jaggid7daab72014-05-06 22:22:20 +0200110 }
Jorim Jaggibc976e32014-07-25 16:42:34 +0200111
112 @Override
113 protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
114 boolean userSwitcherVisible = mInflated && mUserSwitcher.getVisibility() == View.VISIBLE;
Jorim Jaggibf1899e2014-08-07 02:04:18 +0200115 boolean statusBarVisible = mKeyguardStatusBar.getVisibility() == View.VISIBLE;
Jorim Jaggibc976e32014-07-25 16:42:34 +0200116
Jason Monk7ebba0b2017-04-20 14:10:20 -0400117 final boolean qsBottom = mHeadsUp;
Jason Monk0ceef212016-11-02 14:05:23 -0400118 View stackQsTop = qsBottom ? mStackScroller : mQsFrame;
119 View stackQsBottom = !qsBottom ? mStackScroller : mQsFrame;
Jorim Jaggibc976e32014-07-25 16:42:34 +0200120 // Invert the order of the scroll view and user switcher such that the notifications receive
121 // touches first but the panel gets drawn above.
Jason Monk0ceef212016-11-02 14:05:23 -0400122 if (child == mQsFrame) {
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700123 return super.drawChild(canvas, userSwitcherVisible && statusBarVisible ? mUserSwitcher
Jorim Jaggibf1899e2014-08-07 02:04:18 +0200124 : statusBarVisible ? mKeyguardStatusBar
125 : userSwitcherVisible ? mUserSwitcher
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700126 : stackQsBottom, drawingTime);
127 } else if (child == mStackScroller) {
128 return super.drawChild(canvas,
129 userSwitcherVisible && statusBarVisible ? mKeyguardStatusBar
130 : statusBarVisible || userSwitcherVisible ? stackQsBottom
131 : stackQsTop,
Jorim Jaggibc976e32014-07-25 16:42:34 +0200132 drawingTime);
133 } else if (child == mUserSwitcher) {
Jorim Jaggibf1899e2014-08-07 02:04:18 +0200134 return super.drawChild(canvas,
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700135 userSwitcherVisible && statusBarVisible ? stackQsBottom
136 : stackQsTop,
Jorim Jaggibc976e32014-07-25 16:42:34 +0200137 drawingTime);
Jorim Jaggibf1899e2014-08-07 02:04:18 +0200138 } else if (child == mKeyguardStatusBar) {
139 return super.drawChild(canvas,
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700140 stackQsTop,
Jorim Jaggibf1899e2014-08-07 02:04:18 +0200141 drawingTime);
Jason Monk16ac3772016-02-10 15:39:21 -0500142 } else {
Jorim Jaggibc976e32014-07-25 16:42:34 +0200143 return super.drawChild(canvas, child, drawingTime);
144 }
145 }
146
147 @Override
148 public void onInflate(ViewStub stub, View inflated) {
149 if (stub == mUserSwitcher) {
150 mUserSwitcher = inflated;
151 mInflated = true;
152 }
153 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700154
Jason Monk8b9d67f2016-03-02 08:59:08 -0500155 @Override
Jason Monk0ceef212016-11-02 14:05:23 -0400156 public void onFragmentViewCreated(String tag, Fragment fragment) {
157 QS container = (QS) fragment;
Jason Monk46767b72016-08-18 10:58:04 -0400158 container.setContainer(this);
Jason Monk8b9d67f2016-03-02 08:59:08 -0500159 }
160
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700161 public void setQsExpanded(boolean expanded) {
162 if (mQsExpanded != expanded) {
163 mQsExpanded = expanded;
164 invalidate();
165 }
166 }
Jason Monk8b9d67f2016-03-02 08:59:08 -0500167
168 public void setCustomizerAnimating(boolean isAnimating) {
169 if (mCustomizerAnimating != isAnimating) {
170 mCustomizerAnimating = isAnimating;
171 invalidate();
172 }
173 }
Jason Monk428914d2016-03-30 09:35:36 -0400174
175 public void setCustomizerShowing(boolean isShowing) {
176 if (isShowing) {
177 // Clear out bottom paddings/margins so the qs customization can be full height.
178 setPadding(0, 0, 0, 0);
179 setBottomMargin(mStackScroller, 0);
180 } else {
181 setPadding(0, 0, 0, mBottomPadding);
182 setBottomMargin(mStackScroller, mStackScrollerMargin);
183 }
184
185 }
186
187 private void setBottomMargin(View v, int bottomMargin) {
188 LayoutParams params = (LayoutParams) v.getLayoutParams();
189 params.bottomMargin = bottomMargin;
190 v.setLayoutParams(params);
191 }
Jason Monk7ebba0b2017-04-20 14:10:20 -0400192
193 @Override
194 public void onHeadsUpStateChanged(Entry entry, boolean isHeadsUp) {
195 boolean hasHeadsUp = mHeadsUpManager.getAllEntries().size() != 0;
196 if (mHeadsUp == hasHeadsUp) {
197 return;
198 }
199 mHeadsUp = hasHeadsUp;
200 invalidate();
201 }
Jorim Jaggid7daab72014-05-06 22:22:20 +0200202}