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 package com.android.launcher3.taskbar.bubbles; 17 18 import com.android.launcher3.taskbar.TaskbarControllers; 19 import com.android.launcher3.util.RunnableList; 20 21 /** 22 * Hosts various bubble controllers to facilitate passing between one another. 23 */ 24 public class BubbleControllers { 25 26 public final BubbleBarController bubbleBarController; 27 public final BubbleBarViewController bubbleBarViewController; 28 public final BubbleStashController bubbleStashController; 29 public final BubbleStashedHandleViewController bubbleStashedHandleViewController; 30 public final BubbleDragController bubbleDragController; 31 public final BubbleDismissController bubbleDismissController; 32 public final BubbleBarPinController bubbleBarPinController; 33 public final BubblePinController bubblePinController; 34 35 private final RunnableList mPostInitRunnables = new RunnableList(); 36 37 /** 38 * Want to add a new controller? Don't forget to: 39 * * Call init 40 * * Call onDestroy 41 */ BubbleControllers( BubbleBarController bubbleBarController, BubbleBarViewController bubbleBarViewController, BubbleStashController bubbleStashController, BubbleStashedHandleViewController bubbleStashedHandleViewController, BubbleDragController bubbleDragController, BubbleDismissController bubbleDismissController, BubbleBarPinController bubbleBarPinController, BubblePinController bubblePinController)42 public BubbleControllers( 43 BubbleBarController bubbleBarController, 44 BubbleBarViewController bubbleBarViewController, 45 BubbleStashController bubbleStashController, 46 BubbleStashedHandleViewController bubbleStashedHandleViewController, 47 BubbleDragController bubbleDragController, 48 BubbleDismissController bubbleDismissController, 49 BubbleBarPinController bubbleBarPinController, 50 BubblePinController bubblePinController) { 51 this.bubbleBarController = bubbleBarController; 52 this.bubbleBarViewController = bubbleBarViewController; 53 this.bubbleStashController = bubbleStashController; 54 this.bubbleStashedHandleViewController = bubbleStashedHandleViewController; 55 this.bubbleDragController = bubbleDragController; 56 this.bubbleDismissController = bubbleDismissController; 57 this.bubbleBarPinController = bubbleBarPinController; 58 this.bubblePinController = bubblePinController; 59 } 60 61 /** 62 * Initializes all controllers. Note that controllers can now reference each other through this 63 * BubbleControllers instance, but should be careful to only access things that were created 64 * in constructors for now, as some controllers may still be waiting for init(). 65 */ init(TaskbarControllers taskbarControllers)66 public void init(TaskbarControllers taskbarControllers) { 67 bubbleBarController.init(this, 68 taskbarControllers.navbarButtonsViewController::isImeVisible); 69 bubbleBarViewController.init(taskbarControllers, this); 70 bubbleStashedHandleViewController.init(taskbarControllers, this); 71 bubbleStashController.init(taskbarControllers, this); 72 bubbleDragController.init(/* bubbleControllers = */ this); 73 bubbleDismissController.init(/* bubbleControllers = */ this); 74 bubbleBarPinController.init(this); 75 bubblePinController.init(this); 76 77 mPostInitRunnables.executeAllAndDestroy(); 78 } 79 80 /** 81 * If all controllers are already initialized, runs the given callback immediately. Otherwise, 82 * queues it to run after calling init() on all controllers. This should likely be used in any 83 * case where one controller is telling another controller to do something inside init(). 84 */ runAfterInit(Runnable runnable)85 public void runAfterInit(Runnable runnable) { 86 // If this has been executed in init, it automatically runs adds to it. 87 mPostInitRunnables.add(runnable); 88 } 89 90 /** 91 * Cleans up all controllers. 92 */ onDestroy()93 public void onDestroy() { 94 bubbleStashedHandleViewController.onDestroy(); 95 bubbleBarController.onDestroy(); 96 } 97 } 98