1 /*
<lambda>null2  * 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.recordissue
18 
19 import android.os.Bundle
20 import android.view.Gravity
21 import android.view.WindowManager
22 import com.android.systemui.res.R
23 import com.android.systemui.statusbar.phone.SystemUIDialog
24 
25 class ScreenCapturePermissionDialogDelegate(
26     private val dialogFactory: SystemUIDialog.Factory,
27     private val state: IssueRecordingState,
28 ) : SystemUIDialog.Delegate {
29 
30     override fun beforeCreate(dialog: SystemUIDialog, savedInstanceState: Bundle?) {
31         dialog.apply {
32             setIcon(R.drawable.ic_screenrecord)
33             setTitle(R.string.screenrecord_permission_dialog_title)
34             setMessage(R.string.screenrecord_permission_dialog_warning_entire_screen)
35             setNegativeButton(R.string.slice_permission_deny) { _, _ -> cancel() }
36             setPositiveButton(R.string.slice_permission_allow) { _, _ ->
37                 state.markUserApprovalForScreenRecording()
38                 dismiss()
39             }
40             window?.addPrivateFlags(WindowManager.LayoutParams.SYSTEM_FLAG_SHOW_FOR_ALL_USERS)
41             window?.setGravity(Gravity.CENTER)
42         }
43     }
44 
45     override fun createDialog(): SystemUIDialog = dialogFactory.create(this)
46 }
47