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.flags.FeatureFlags;
22 import com.android.systemui.statusbar.notification.row.ActivatableNotificationViewController;
23 import com.android.systemui.statusbar.notification.row.dagger.NotificationRowScope;
24 import com.android.systemui.statusbar.notification.stack.AmbientState;
25 import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayoutController;
26 import com.android.systemui.statusbar.phone.KeyguardBypassController;
27 import com.android.systemui.statusbar.phone.NotificationIconContainer;
28 
29 import javax.inject.Inject;
30 
31 /**
32  * Controller class for {@link NotificationShelf}.
33  */
34 @NotificationRowScope
35 public class LegacyNotificationShelfControllerImpl implements NotificationShelfController {
36     private final NotificationShelf mView;
37     private final ActivatableNotificationViewController mActivatableNotificationViewController;
38     private final KeyguardBypassController mKeyguardBypassController;
39     private final SysuiStatusBarStateController mStatusBarStateController;
40     private final View.OnAttachStateChangeListener mOnAttachStateChangeListener;
41     private AmbientState mAmbientState;
42 
43     @Inject
LegacyNotificationShelfControllerImpl( NotificationShelf notificationShelf, ActivatableNotificationViewController activatableNotificationViewController, KeyguardBypassController keyguardBypassController, SysuiStatusBarStateController statusBarStateController, FeatureFlags featureFlags)44     public LegacyNotificationShelfControllerImpl(
45             NotificationShelf notificationShelf,
46             ActivatableNotificationViewController activatableNotificationViewController,
47             KeyguardBypassController keyguardBypassController,
48             SysuiStatusBarStateController statusBarStateController,
49             FeatureFlags featureFlags) {
50         mView = notificationShelf;
51         mActivatableNotificationViewController = activatableNotificationViewController;
52         mKeyguardBypassController = keyguardBypassController;
53         mStatusBarStateController = statusBarStateController;
54         mOnAttachStateChangeListener = new View.OnAttachStateChangeListener() {
55             @Override
56             public void onViewAttachedToWindow(View v) {
57                 mStatusBarStateController.addCallback(
58                         mView, SysuiStatusBarStateController.RANK_SHELF);
59             }
60 
61             @Override
62             public void onViewDetachedFromWindow(View v) {
63                 mStatusBarStateController.removeCallback(mView);
64             }
65         };
66     }
67 
init()68     public void init() {
69         mActivatableNotificationViewController.init();
70         mView.setController(this);
71         mView.addOnAttachStateChangeListener(mOnAttachStateChangeListener);
72         if (mView.isAttachedToWindow()) {
73             mOnAttachStateChangeListener.onViewAttachedToWindow(mView);
74         }
75     }
76 
77     @Override
getView()78     public NotificationShelf getView() {
79         return mView;
80     }
81 
82     @Override
canModifyColorOfNotifications()83     public boolean canModifyColorOfNotifications() {
84         return mAmbientState.isShadeExpanded()
85                 && !(mAmbientState.isOnKeyguard() && mKeyguardBypassController.getBypassEnabled());
86     }
87 
88     @Override
getShelfIcons()89     public NotificationIconContainer getShelfIcons() {
90         return mView.getShelfIcons();
91     }
92 
93     @Override
bind(AmbientState ambientState, NotificationStackScrollLayoutController notificationStackScrollLayoutController)94     public void bind(AmbientState ambientState,
95             NotificationStackScrollLayoutController notificationStackScrollLayoutController) {
96         mView.bind(ambientState, notificationStackScrollLayoutController);
97         mAmbientState = ambientState;
98     }
99 
100     @Override
getIntrinsicHeight()101     public int getIntrinsicHeight() {
102         return mView.getIntrinsicHeight();
103     }
104 
105     @Override
setOnClickListener(View.OnClickListener onClickListener)106     public void setOnClickListener(View.OnClickListener onClickListener) {
107         mView.setOnClickListener(onClickListener);
108     }
109 
110 }
111