1 /* 2 * Copyright (C) 2024 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.systemui.accessibility.extradim 17 18 import android.os.Handler 19 import com.android.systemui.animation.DialogCuj 20 import com.android.systemui.animation.DialogTransitionAnimator 21 import com.android.systemui.animation.Expandable 22 import com.android.systemui.dagger.SysUISingleton 23 import com.android.systemui.dagger.qualifiers.Main 24 import com.android.systemui.plugins.ActivityStarter 25 import com.android.systemui.statusbar.phone.SystemUIDialog 26 import javax.inject.Inject 27 import javax.inject.Provider 28 29 /** Managing the Extra Dim Dialog behaviors. */ 30 @SysUISingleton 31 class ExtraDimDialogManager 32 @Inject 33 constructor( 34 private val extraDimDialogDelegateProvider: Provider<ExtraDimDialogDelegate>, 35 private val mActivityStarter: ActivityStarter, 36 private val dialogTransitionAnimator: DialogTransitionAnimator, 37 @Main private val mainHandler: Handler, 38 ) { 39 private var dialog: SystemUIDialog? = null 40 41 @JvmOverloads dismissKeyguardIfNeededAndShowDialognull42 fun dismissKeyguardIfNeededAndShowDialog(expandable: Expandable? = null) { 43 mainHandler.post { 44 mActivityStarter.executeRunnableDismissingKeyguard( 45 { showRemoveExtraDimShortcutsDialog(expandable) }, 46 /* cancelAction= */ null, 47 /* dismissShade= */ true, 48 /* afterKeyguardGone= */ true, 49 /* deferred= */ false, 50 ) 51 } 52 } 53 54 /** Show the dialog for removing all Extra Dim shortcuts. */ showRemoveExtraDimShortcutsDialognull55 private fun showRemoveExtraDimShortcutsDialog(expandable: Expandable?) { 56 dialog?.dismiss() 57 val dialog2 = extraDimDialogDelegateProvider.get().createDialog() 58 dialog = dialog2 59 60 val controller = 61 expandable?.dialogTransitionController( 62 DialogCuj(com.android.internal.jank.Cuj.CUJ_SHADE_DIALOG_OPEN) 63 ) 64 65 controller?.let { 66 dialogTransitionAnimator.show(dialog2, it, animateBackgroundBoundsChange = true) 67 } ?: dialog2.show() 68 } 69 } 70