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.annotation.Nullable;
20 import android.content.Context;
21 import android.view.View;
22 
23 import com.android.internal.logging.UiEventLogger;
24 import com.android.settingslib.bluetooth.LocalBluetoothManager;
25 import com.android.systemui.animation.DialogLaunchAnimator;
26 import com.android.systemui.broadcast.BroadcastSender;
27 import com.android.systemui.dagger.SysUISingleton;
28 import com.android.systemui.media.dialog.MediaOutputDialogFactory;
29 
30 import javax.inject.Inject;
31 
32 /**
33  * Controller to create BroadcastDialog objects.
34  */
35 @SysUISingleton
36 public class BroadcastDialogController {
37 
38     private Context mContext;
39     private UiEventLogger mUiEventLogger;
40     private DialogLaunchAnimator mDialogLaunchAnimator;
41     private MediaOutputDialogFactory mMediaOutputDialogFactory;
42     private final LocalBluetoothManager mLocalBluetoothManager;
43     private BroadcastSender mBroadcastSender;
44 
45     @Inject
BroadcastDialogController(Context context, UiEventLogger uiEventLogger, DialogLaunchAnimator dialogLaunchAnimator, MediaOutputDialogFactory mediaOutputDialogFactory, @Nullable LocalBluetoothManager localBluetoothManager, BroadcastSender broadcastSender)46     public BroadcastDialogController(Context context, UiEventLogger uiEventLogger,
47             DialogLaunchAnimator dialogLaunchAnimator,
48             MediaOutputDialogFactory mediaOutputDialogFactory,
49             @Nullable LocalBluetoothManager localBluetoothManager,
50             BroadcastSender broadcastSender) {
51         mContext = context;
52         mUiEventLogger = uiEventLogger;
53         mDialogLaunchAnimator = dialogLaunchAnimator;
54         mMediaOutputDialogFactory = mediaOutputDialogFactory;
55         mLocalBluetoothManager = localBluetoothManager;
56         mBroadcastSender = broadcastSender;
57     }
58 
59     /** Creates a [BroadcastDialog] for the user to switch broadcast or change the output device
60      *
61      * @param currentBroadcastAppName Indicates the APP name currently broadcasting
62      * @param outputPkgName Indicates the output media package name to be switched
63      */
createBroadcastDialog(String currentBroadcastAppName, String outputPkgName, boolean aboveStatusBar, View view)64     public void createBroadcastDialog(String currentBroadcastAppName, String outputPkgName,
65             boolean aboveStatusBar, View view) {
66         BroadcastDialog broadcastDialog = new BroadcastDialog(mContext, mMediaOutputDialogFactory,
67                 mLocalBluetoothManager, currentBroadcastAppName, outputPkgName, mUiEventLogger,
68                 mBroadcastSender);
69         if (view != null) {
70             mDialogLaunchAnimator.showFromView(broadcastDialog, view);
71         } else {
72             broadcastDialog.show();
73         }
74     }
75 }
76