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 17 package com.android.systemui.statusbar.chips.sharetoapp.ui.view 18 19 import android.content.Context 20 import android.os.Bundle 21 import android.view.View 22 import com.android.systemui.mediaprojection.data.model.MediaProjectionState 23 import com.android.systemui.res.R 24 import com.android.systemui.statusbar.chips.mediaprojection.domain.model.ProjectionChipModel 25 import com.android.systemui.statusbar.chips.mediaprojection.ui.view.EndMediaProjectionDialogHelper 26 import com.android.systemui.statusbar.chips.sharetoapp.ui.viewmodel.ShareToAppChipViewModel.Companion.SHARE_TO_APP_ICON 27 import com.android.systemui.statusbar.phone.SystemUIDialog 28 29 /** A dialog that lets the user stop an ongoing share-screen-to-app event. */ 30 class EndShareScreenToAppDialogDelegate( 31 private val endMediaProjectionDialogHelper: EndMediaProjectionDialogHelper, 32 private val context: Context, 33 private val stopAction: () -> Unit, 34 private val state: ProjectionChipModel.Projecting, 35 ) : SystemUIDialog.Delegate { createDialognull36 override fun createDialog(): SystemUIDialog { 37 return endMediaProjectionDialogHelper.createDialog(this) 38 } 39 beforeCreatenull40 override fun beforeCreate(dialog: SystemUIDialog, savedInstanceState: Bundle?) { 41 with(dialog) { 42 setIcon(SHARE_TO_APP_ICON) 43 setTitle(R.string.share_to_app_stop_dialog_title) 44 setMessage(getMessage()) 45 // No custom on-click, because the dialog will automatically be dismissed when the 46 // button is clicked anyway. 47 setNegativeButton(R.string.close_dialog_button, /* onClick= */ null) 48 setPositiveButton( 49 R.string.share_to_app_stop_dialog_button, 50 endMediaProjectionDialogHelper.wrapStopAction(stopAction), 51 ) 52 if (com.android.media.projection.flags.Flags.showStopDialogPostCallEnd()) { 53 window 54 ?.decorView 55 ?.setAccessibilityDataSensitive(View.ACCESSIBILITY_DATA_SENSITIVE_YES) 56 } 57 } 58 } 59 getMessagenull60 private fun getMessage(): String { 61 return if (state.projectionState is MediaProjectionState.Projecting.SingleTask) { 62 // If a single app is being shared, use the name of the app being shared in the dialog 63 val appBeingSharedName = 64 endMediaProjectionDialogHelper.getAppName(state.projectionState) 65 if (appBeingSharedName != null) { 66 context.getString( 67 R.string.share_to_app_stop_dialog_message_single_app_specific, 68 appBeingSharedName, 69 ) 70 } else { 71 context.getString(R.string.share_to_app_stop_dialog_message_single_app_generic) 72 } 73 } else { 74 // Otherwise, use the name of the app *receiving* the share 75 val hostAppName = 76 endMediaProjectionDialogHelper.getAppName(state.projectionState.hostPackage) 77 if (hostAppName != null) { 78 context.getString( 79 R.string.share_to_app_stop_dialog_message_entire_screen_with_host_app, 80 hostAppName, 81 ) 82 } else { 83 context.getString(R.string.share_to_app_stop_dialog_message_entire_screen) 84 } 85 } 86 } 87 } 88