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