1 /* 2 * Copyright (C) 2023 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.shade 18 19 import com.android.keyguard.KeyguardViewController 20 import com.android.systemui.assist.AssistManager 21 import com.android.systemui.statusbar.CommandQueue 22 import com.android.systemui.statusbar.NotificationPresenter 23 import com.android.systemui.statusbar.NotificationShadeWindowController 24 import dagger.Lazy 25 26 /** A base class for non-empty implementations of ShadeController. */ 27 abstract class BaseShadeControllerImpl( 28 protected val commandQueue: CommandQueue, 29 protected val keyguardViewController: KeyguardViewController, 30 protected val notificationShadeWindowController: NotificationShadeWindowController, 31 protected val assistManagerLazy: Lazy<AssistManager>, 32 ) : ShadeController { 33 protected lateinit var notifPresenter: NotificationPresenter 34 /** Runnables to run after completing a collapse of the shade. */ 35 private val postCollapseActions = ArrayList<Runnable>() 36 startnull37 override fun start() { 38 // Do nothing by default 39 } 40 animateExpandShadenull41 final override fun animateExpandShade() { 42 if (isShadeEnabled) { 43 expandToNotifications() 44 } 45 } 46 47 /** Expand the shade with notifications visible. */ expandToNotificationsnull48 protected abstract fun expandToNotifications() 49 50 final override fun animateExpandQs() { 51 if (isShadeEnabled) { 52 expandToQs() 53 } 54 } 55 56 /** Expand the shade showing only quick settings. */ expandToQsnull57 protected abstract fun expandToQs() 58 59 final override fun addPostCollapseAction(action: Runnable) { 60 postCollapseActions.add(action) 61 } 62 runPostCollapseActionsnull63 protected fun runPostCollapseActions() { 64 val clonedList: ArrayList<Runnable> = ArrayList(postCollapseActions) 65 postCollapseActions.clear() 66 for (r in clonedList) { 67 r.run() 68 } 69 keyguardViewController.readyForKeyguardDone() 70 } 71 onLaunchAnimationEndnull72 final override fun onLaunchAnimationEnd(launchIsFullScreen: Boolean) { 73 if (!this.notifPresenter.isCollapsing()) { 74 onClosingFinished() 75 } 76 if (launchIsFullScreen) { 77 instantCollapseShade() 78 } 79 } 80 onLaunchAnimationCancellednull81 final override fun onLaunchAnimationCancelled(isLaunchForActivity: Boolean) { 82 if ( 83 notifPresenter.isPresenterFullyCollapsed() && 84 !notifPresenter.isCollapsing() && 85 isLaunchForActivity 86 ) { 87 onClosingFinished() 88 } else { 89 collapseShade(true /* animate */) 90 } 91 } 92 onClosingFinishednull93 protected fun onClosingFinished() { 94 runPostCollapseActions() 95 if (!this.notifPresenter.isPresenterFullyCollapsed()) { 96 // if we set it not to be focusable when collapsing, we have to undo it when we aborted 97 // the closing 98 notificationShadeWindowController.setNotificationShadeFocusable(true) 99 } 100 } 101 setNotificationPresenternull102 override fun setNotificationPresenter(presenter: NotificationPresenter) { 103 notifPresenter = presenter 104 } 105 } 106