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 
17 package com.android.systemui.statusbar.phone
18 
19 import android.app.Dialog
20 import android.content.res.Configuration
21 import android.os.Bundle
22 import android.util.DisplayMetrics
23 import android.view.ViewRootImpl
24 import com.android.systemui.animation.back.BackAnimationSpec
25 import com.android.systemui.animation.back.floatingSystemSurfacesForSysUi
26 
27 /**
28  * A delegate class that should be implemented in place of subclassing [Dialog].
29  *
30  * To use with [SystemUIDialog], implement this interface and then pass an instance of your
31  * implementation to [SystemUIDialog.Factory.create].
32  */
33 interface DialogDelegate<T : Dialog> {
34     /** Called before [Dialog.onCreate] is called. */
beforeCreatenull35     fun beforeCreate(dialog: T, savedInstanceState: Bundle?) {}
36 
37     /** Called after [Dialog.onCreate] is called. */
onCreatenull38     fun onCreate(dialog: T, savedInstanceState: Bundle?) {}
39 
40     /** Called after [Dialog.onStart] is called. */
onStartnull41     fun onStart(dialog: T) {}
42 
43     /** Called after [Dialog.onStop] is called. */
onStopnull44     fun onStop(dialog: T) {}
45 
46     /** Called after [Dialog.onWindowFocusChanged] is called. */
onWindowFocusChangednull47     fun onWindowFocusChanged(dialog: T, hasFocus: Boolean) {}
48 
49     /** Called as part of [ViewRootImpl.ConfigChangedCallback.onConfigurationChanged]. */
onConfigurationChangednull50     fun onConfigurationChanged(dialog: T, configuration: Configuration) {}
51 
getWidthnull52     fun getWidth(dialog: T): Int = SystemUIDialog.getDefaultDialogWidth(dialog)
53 
54     fun getHeight(dialog: T): Int = SystemUIDialog.getDefaultDialogHeight()
55 
56     fun getBackAnimationSpec(displayMetricsProvider: () -> DisplayMetrics): BackAnimationSpec =
57         BackAnimationSpec.floatingSystemSurfacesForSysUi(displayMetricsProvider)
58 }
59