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.bluetooth; 18 19 import android.view.View; 20 21 import com.android.systemui.animation.DialogTransitionAnimator; 22 import com.android.systemui.dagger.SysUISingleton; 23 import com.android.systemui.statusbar.phone.SystemUIDialog; 24 25 import javax.inject.Inject; 26 27 /** 28 * Controller to create BroadcastDialog objects. 29 */ 30 @SysUISingleton 31 public class BroadcastDialogController { 32 33 private final DialogTransitionAnimator mDialogTransitionAnimator; 34 private final BroadcastDialogDelegate.Factory mBroadcastDialogFactory; 35 36 @Inject BroadcastDialogController( DialogTransitionAnimator dialogTransitionAnimator, BroadcastDialogDelegate.Factory broadcastDialogFactory)37 public BroadcastDialogController( 38 DialogTransitionAnimator dialogTransitionAnimator, 39 BroadcastDialogDelegate.Factory broadcastDialogFactory) { 40 mDialogTransitionAnimator = dialogTransitionAnimator; 41 mBroadcastDialogFactory = broadcastDialogFactory; 42 } 43 44 /** Creates a [BroadcastDialog] for the user to switch broadcast or change the output device 45 * 46 * @param currentBroadcastAppName Indicates the APP name currently broadcasting 47 * @param outputPkgName Indicates the output media package name to be switched 48 */ createBroadcastDialog( String currentBroadcastAppName, String outputPkgName, View view)49 public void createBroadcastDialog( 50 String currentBroadcastAppName, String outputPkgName, View view) { 51 SystemUIDialog broadcastDialog = mBroadcastDialogFactory.create( 52 currentBroadcastAppName, outputPkgName).createDialog(); 53 if (view != null) { 54 mDialogTransitionAnimator.showFromView(broadcastDialog, view); 55 } else { 56 broadcastDialog.show(); 57 } 58 } 59 60 /** Creates a [BroadcastDialog] for the user to switch broadcast or change the output device 61 * 62 * @param currentBroadcastAppName Indicates the APP name currently broadcasting 63 * @param outputPkgName Indicates the output media package name to be switched 64 * @param controller Indicates the dialog controller of the source view. 65 */ createBroadcastDialogWithController( String currentBroadcastAppName, String outputPkgName, DialogTransitionAnimator.Controller controller)66 public void createBroadcastDialogWithController( 67 String currentBroadcastAppName, String outputPkgName, 68 DialogTransitionAnimator.Controller controller) { 69 SystemUIDialog broadcastDialog = mBroadcastDialogFactory.create( 70 currentBroadcastAppName, outputPkgName).createDialog(); 71 if (controller != null) { 72 mDialogTransitionAnimator.show(broadcastDialog, controller); 73 } else { 74 broadcastDialog.show(); 75 } 76 } 77 } 78