1 /*
2  * Copyright (C) 2020 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;
18 
19 import android.view.View;
20 
21 import com.android.systemui.statusbar.notification.row.ActivatableNotificationViewController;
22 import com.android.systemui.statusbar.notification.row.dagger.NotificationRowScope;
23 import com.android.systemui.statusbar.notification.stack.AmbientState;
24 import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayoutController;
25 import com.android.systemui.statusbar.notification.stack.StackScrollAlgorithm;
26 import com.android.systemui.statusbar.phone.KeyguardBypassController;
27 import com.android.systemui.statusbar.phone.NotificationIconContainer;
28 import com.android.systemui.statusbar.phone.StatusBarNotificationPresenter;
29 
30 import javax.inject.Inject;
31 
32 /**
33  * Controller class for {@link NotificationShelf}.
34  */
35 @NotificationRowScope
36 public class NotificationShelfController {
37     private final NotificationShelf mView;
38     private final ActivatableNotificationViewController mActivatableNotificationViewController;
39     private final KeyguardBypassController mKeyguardBypassController;
40     private final SysuiStatusBarStateController mStatusBarStateController;
41     private final View.OnAttachStateChangeListener mOnAttachStateChangeListener;
42     private AmbientState mAmbientState;
43 
44     @Inject
NotificationShelfController(NotificationShelf notificationShelf, ActivatableNotificationViewController activatableNotificationViewController, KeyguardBypassController keyguardBypassController, SysuiStatusBarStateController statusBarStateController)45     public NotificationShelfController(NotificationShelf notificationShelf,
46             ActivatableNotificationViewController activatableNotificationViewController,
47             KeyguardBypassController keyguardBypassController,
48             SysuiStatusBarStateController statusBarStateController) {
49         mView = notificationShelf;
50         mActivatableNotificationViewController = activatableNotificationViewController;
51         mKeyguardBypassController = keyguardBypassController;
52         mStatusBarStateController = statusBarStateController;
53         mOnAttachStateChangeListener = new View.OnAttachStateChangeListener() {
54             @Override
55             public void onViewAttachedToWindow(View v) {
56                 mStatusBarStateController.addCallback(
57                         mView, SysuiStatusBarStateController.RANK_SHELF);
58             }
59 
60             @Override
61             public void onViewDetachedFromWindow(View v) {
62                 mStatusBarStateController.removeCallback(mView);
63             }
64         };
65     }
66 
init()67     public void init() {
68         mActivatableNotificationViewController.init();
69         mView.setController(this);
70         mView.addOnAttachStateChangeListener(mOnAttachStateChangeListener);
71         if (mView.isAttachedToWindow()) {
72             mOnAttachStateChangeListener.onViewAttachedToWindow(mView);
73         }
74     }
75 
getView()76     public NotificationShelf getView() {
77         return mView;
78     }
79 
canModifyColorOfNotifications()80     public boolean canModifyColorOfNotifications() {
81         return mAmbientState.isShadeExpanded()
82                 && !(mAmbientState.isOnKeyguard() && mKeyguardBypassController.getBypassEnabled());
83     }
84 
getShelfIcons()85     public NotificationIconContainer getShelfIcons() {
86         return mView.getShelfIcons();
87     }
88 
getVisibility()89     public @View.Visibility int getVisibility() {
90         return mView.getVisibility();
91     };
92 
setCollapsedIcons(NotificationIconContainer notificationIcons)93     public void setCollapsedIcons(NotificationIconContainer notificationIcons) {
94         mView.setCollapsedIcons(notificationIcons);
95     }
96 
bind(AmbientState ambientState, NotificationStackScrollLayoutController notificationStackScrollLayoutController)97     public void bind(AmbientState ambientState,
98             NotificationStackScrollLayoutController notificationStackScrollLayoutController) {
99         mView.bind(ambientState, notificationStackScrollLayoutController);
100         mAmbientState = ambientState;
101     }
102 
getHeight()103     public int getHeight() {
104         return mView.getHeight();
105     }
106 
updateState(StackScrollAlgorithm.StackScrollAlgorithmState algorithmState, AmbientState ambientState)107     public void updateState(StackScrollAlgorithm.StackScrollAlgorithmState algorithmState,
108             AmbientState ambientState) {
109         mAmbientState = ambientState;
110         mView.updateState(algorithmState, ambientState);
111     }
112 
getIntrinsicHeight()113     public int getIntrinsicHeight() {
114         return mView.getIntrinsicHeight();
115     }
116 
setOnActivatedListener(StatusBarNotificationPresenter presenter)117     public void setOnActivatedListener(StatusBarNotificationPresenter presenter) {
118         mView.setOnActivatedListener(presenter);
119     }
120 
setOnClickListener(View.OnClickListener onClickListener)121     public void setOnClickListener(View.OnClickListener onClickListener) {
122         mView.setOnClickListener(onClickListener);
123     }
124 
getNotGoneIndex()125     public int getNotGoneIndex() {
126         return mView.getNotGoneIndex();
127     }
128 }
129