1 /* 2 * Copyright (C) 2024 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 package com.android.systemui.car.notification; 17 18 import android.view.View; 19 20 import com.android.systemui.car.systembar.ButtonSelectionStateController; 21 import com.android.systemui.car.systembar.CarSystemBarButton; 22 import com.android.systemui.car.systembar.CarSystemBarButtonController; 23 import com.android.systemui.car.systembar.element.CarSystemBarElementController; 24 import com.android.systemui.car.systembar.element.CarSystemBarElementStateController; 25 import com.android.systemui.car.systembar.element.CarSystemBarElementStatusBarDisableController; 26 import com.android.systemui.car.wm.scalableui.EventDispatcher; 27 import com.android.systemui.settings.UserTracker; 28 29 import dagger.assisted.Assisted; 30 import dagger.assisted.AssistedFactory; 31 import dagger.assisted.AssistedInject; 32 33 /** 34 * A CarSystemBarElementController for handling notification button interactions. 35 */ 36 public class NotificationButtonController extends CarSystemBarButtonController { 37 38 private final NotificationPanelViewController mNotificationPanelViewController; 39 40 @AssistedInject NotificationButtonController(@ssisted CarSystemBarButton notificationsButton, CarSystemBarElementStatusBarDisableController disableController, CarSystemBarElementStateController stateController, NotificationPanelViewController notificationPanelViewController, UserTracker userTracker, EventDispatcher eventDispatcher, ButtonSelectionStateController buttonSelectionStateController)41 public NotificationButtonController(@Assisted CarSystemBarButton notificationsButton, 42 CarSystemBarElementStatusBarDisableController disableController, 43 CarSystemBarElementStateController stateController, 44 NotificationPanelViewController notificationPanelViewController, 45 UserTracker userTracker, EventDispatcher eventDispatcher, 46 ButtonSelectionStateController buttonSelectionStateController) { 47 super(notificationsButton, disableController, stateController, userTracker, 48 eventDispatcher, buttonSelectionStateController); 49 50 mNotificationPanelViewController = notificationPanelViewController; 51 mNotificationPanelViewController.registerViewStateListener(notificationsButton); 52 mNotificationPanelViewController.setOnUnseenCountUpdateListener(unseenNotificationCount -> { 53 toggleNotificationUnseenIndicator(unseenNotificationCount > 0); 54 }); 55 notificationsButton.setOnClickListener(this::onNotificationsClick); 56 } 57 58 /** 59 * Toggles the notification unseen indicator on/off. 60 * 61 * @param hasUnseen true if the unseen notification count is great than 0. 62 */ toggleNotificationUnseenIndicator(boolean hasUnseen)63 private void toggleNotificationUnseenIndicator(boolean hasUnseen) { 64 mView.setUnseen(hasUnseen); 65 } 66 67 @AssistedFactory 68 public interface Factory extends 69 CarSystemBarElementController.Factory<CarSystemBarButton, 70 NotificationButtonController> { 71 } 72 onNotificationsClick(View v)73 private void onNotificationsClick(View v) { 74 if (mView.getDisabled()) { 75 mView.runOnClickWhileDisabled(); 76 return; 77 } 78 mNotificationPanelViewController.toggle(); 79 } 80 } 81