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.volume 18 19 import android.content.Context 20 import android.util.Log 21 import android.view.View 22 import com.android.systemui.animation.DialogTransitionAnimator 23 import com.android.systemui.dagger.SysUISingleton 24 import com.android.systemui.plugins.ActivityStarter 25 import javax.inject.Inject 26 27 private const val TAG = "VolumePanelFactory" 28 private val DEBUG = Log.isLoggable(TAG, Log.DEBUG) 29 30 /** 31 * Factory to create [VolumePanelDialog] objects. This is the dialog that allows the user to adjust 32 * multiple streams with sliders. 33 */ 34 @SysUISingleton 35 class VolumePanelFactory @Inject constructor( 36 private val context: Context, 37 private val activityStarter: ActivityStarter, 38 private val dialogTransitionAnimator: DialogTransitionAnimator 39 ) { 40 companion object { 41 var volumePanelDialog: VolumePanelDialog? = null 42 } 43 44 /** Creates a [VolumePanelDialog]. The dialog will be animated from [view] if it is not null. */ createnull45 fun create(aboveStatusBar: Boolean, view: View? = null) { 46 if (volumePanelDialog?.isShowing == true) { 47 return 48 } 49 50 val dialog = VolumePanelDialog(context, activityStarter, aboveStatusBar) 51 volumePanelDialog = dialog 52 53 // Show the dialog. 54 if (view != null) { 55 dialogTransitionAnimator.showFromView( 56 dialog, 57 view, 58 animateBackgroundBoundsChange = true 59 ) 60 } else { 61 dialog.show() 62 } 63 } 64 65 /** Dismiss [VolumePanelDialog] if exist. */ dismissnull66 fun dismiss() { 67 if (DEBUG) { 68 Log.d(TAG, "dismiss dialog") 69 } 70 volumePanelDialog?.dismiss() 71 volumePanelDialog = null 72 } 73 } 74