1 /* 2 * Copyright (C) 2022 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 android.view.MotionEvent; 20 21 import com.android.systemui.CoreStartable; 22 import com.android.systemui.statusbar.CommandQueue; 23 import com.android.systemui.statusbar.NotificationPresenter; 24 import com.android.systemui.statusbar.StatusBarState; 25 import com.android.systemui.statusbar.phone.CentralSurfaces; 26 import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; 27 28 /** 29 * {@link ShadeController} is an abstraction of the work that used to be hard-coded in 30 * {@link CentralSurfaces}. The shade itself represents the concept of the status bar window state, 31 * and can be in multiple states: dozing, locked, showing the bouncer, occluded, etc. All/some of 32 * these are coordinated with {@link StatusBarKeyguardViewManager} via 33 * {@link com.android.systemui.keyguard.KeyguardViewMediator} and others. 34 */ 35 public interface ShadeController extends CoreStartable { 36 37 /** Make our window larger and the shade expanded */ instantExpandShade()38 void instantExpandShade(); 39 40 /** Collapse the shade instantly with no animation. */ instantCollapseShade()41 void instantCollapseShade(); 42 43 /** See {@link #animateCollapseShade(int, boolean, boolean, float)}. */ animateCollapseShade()44 default void animateCollapseShade() { 45 animateCollapseShade(CommandQueue.FLAG_EXCLUDE_NONE); 46 } 47 48 /** See {@link #animateCollapseShade(int, boolean, boolean, float)}. */ animateCollapseShade(int flags)49 default void animateCollapseShade(int flags) { 50 animateCollapseShade(flags, false, false, 1.0f); 51 } 52 53 /** See {@link #animateCollapseShade(int, boolean, boolean, float)}. */ animateCollapseShadeForced()54 default void animateCollapseShadeForced() { 55 animateCollapseShade(CommandQueue.FLAG_EXCLUDE_NONE, true, false, 1.0f); 56 } 57 58 /** See {@link #animateCollapseShade(int, boolean, boolean, float)}. */ animateCollapseShadeForcedDelayed()59 default void animateCollapseShadeForcedDelayed() { 60 animateCollapseShade(CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL, true, true, 1.0f); 61 } 62 63 /** 64 * Collapse the shade animated, showing the bouncer when on {@link StatusBarState#KEYGUARD} or 65 * dismissing status bar when on {@link StatusBarState#SHADE}. 66 */ animateCollapseShade(int flags, boolean force, boolean delayed, float speedUpFactor)67 void animateCollapseShade(int flags, boolean force, boolean delayed, float speedUpFactor); 68 69 /** Expand the shade with an animation. */ animateExpandShade()70 void animateExpandShade(); 71 72 /** Expand the shade with quick settings expanded with an animation. */ animateExpandQs()73 void animateExpandQs(); 74 75 /** Posts a request to collapse the shade. */ postAnimateCollapseShade()76 void postAnimateCollapseShade(); 77 78 /** Posts a request to force collapse the shade. */ postAnimateForceCollapseShade()79 void postAnimateForceCollapseShade(); 80 81 /** Posts a request to expand the shade to quick settings. */ postAnimateExpandQs()82 void postAnimateExpandQs(); 83 84 /** Cancels any ongoing expansion touch handling and collapses the shade. */ cancelExpansionAndCollapseShade()85 void cancelExpansionAndCollapseShade(); 86 87 /** 88 * If the shade is not fully expanded, collapse it animated. 89 * 90 * @return Seems to always return false 91 */ closeShadeIfOpen()92 boolean closeShadeIfOpen(); 93 94 /** 95 * Returns whether the shade state is the keyguard or not. 96 */ isKeyguard()97 boolean isKeyguard(); 98 99 /** 100 * Returns whether the shade is currently open. 101 * Even though in the current implementation shade is in expanded state on keyguard, this 102 * method makes distinction between shade being truly open and plain keyguard state: 103 * - if QS and notifications are visible on the screen, return true 104 * - for any other state, including keyguard, return false 105 */ isShadeFullyOpen()106 boolean isShadeFullyOpen(); 107 108 /** 109 * Returns whether shade or QS are currently opening or collapsing. 110 */ isExpandingOrCollapsing()111 boolean isExpandingOrCollapsing(); 112 113 /** 114 * Add a runnable for NotificationPanelView to post when the panel is expanded. 115 * 116 * @param action the action to post 117 */ postOnShadeExpanded(Runnable action)118 void postOnShadeExpanded(Runnable action); 119 120 /** 121 * Add a runnable to be executed after the shade collapses. Post-collapse runnables are 122 * aggregated and run serially. 123 * 124 * @param action the action to execute 125 */ addPostCollapseAction(Runnable action)126 void addPostCollapseAction(Runnable action); 127 128 /** Run all of the runnables added by {@link #addPostCollapseAction}. */ runPostCollapseRunnables()129 void runPostCollapseRunnables(); 130 131 /** 132 * Close the shade if it was open 133 * 134 * @return true if the shade was open, else false 135 */ collapseShade()136 boolean collapseShade(); 137 138 /** 139 * If animate is true, does the same as {@link #collapseShade()}. Otherwise, instantly collapse 140 * the shade. Post collapse runnables will be executed 141 * 142 * @param animate true to animate the collapse, false for instantaneous collapse 143 */ collapseShade(boolean animate)144 void collapseShade(boolean animate); 145 146 /** Calls #collapseShade if already on the main thread. If not, posts a call to it. */ collapseOnMainThread()147 void collapseOnMainThread(); 148 149 /** Makes shade expanded but not visible. */ makeExpandedInvisible()150 void makeExpandedInvisible(); 151 152 /** Makes shade expanded and visible. */ makeExpandedVisible(boolean force)153 void makeExpandedVisible(boolean force); 154 155 /** Returns whether the shade is expanded and visible. */ isExpandedVisible()156 boolean isExpandedVisible(); 157 158 /** Handle status bar touch event. */ onStatusBarTouch(MotionEvent event)159 void onStatusBarTouch(MotionEvent event); 160 161 /** Called when a launch animation was cancelled. */ onLaunchAnimationCancelled(boolean isLaunchForActivity)162 void onLaunchAnimationCancelled(boolean isLaunchForActivity); 163 164 /** Called when a launch animation ends. */ onLaunchAnimationEnd(boolean launchIsFullScreen)165 void onLaunchAnimationEnd(boolean launchIsFullScreen); 166 167 /** Sets the listener for when the visibility of the shade changes. */ setVisibilityListener(ShadeVisibilityListener listener)168 default void setVisibilityListener(ShadeVisibilityListener listener) {} 169 170 /** */ setNotificationPresenter(NotificationPresenter presenter)171 default void setNotificationPresenter(NotificationPresenter presenter) {} 172 173 /** */ setNotificationShadeWindowViewController( NotificationShadeWindowViewController notificationShadeWindowViewController)174 default void setNotificationShadeWindowViewController( 175 NotificationShadeWindowViewController notificationShadeWindowViewController) {} 176 177 /** Listens for shade visibility changes. */ 178 interface ShadeVisibilityListener { 179 /** Called when the visibility of the shade changes. */ visibilityChanged(boolean visible)180 void visibilityChanged(boolean visible); 181 182 /** Called when shade expanded and visible state changed. */ expandedVisibleChanged(boolean expandedVisible)183 void expandedVisibleChanged(boolean expandedVisible); 184 } 185 } 186