From ebdf56f706e4d4eaa399e011d33383d49e6efa61 Mon Sep 17 00:00:00 2001 From: Caitlin Shkuratov Date: Mon, 22 Jul 2024 20:05:15 +0000 Subject: [Screen share] Make start button text be option-specific. With the new dialog UX, the start button text is different depending on whether "single app" or "entire screen" is selected. This CL makes that text be set when an option is created, and also updates the cast dialog to use different text in the two cases. (Record and share updates will be in a future CL.) Bug: 352327853 Flag: NONE string changes Test: Cast screen to other device -> verify start button text is "Next" when selecting single app option, but "Cast screen" when selecting entire screen option Test: Screen record -> verify start button text stays the same Test: Share to app -> verify start button text stays the same Test: atest SystemCastPermissionDialogDelegateTest Change-Id: Ie4bbe23826f0862beda73d69536f9a74e84e1983 --- packages/SystemUI/res/values/strings.xml | 4 ++- .../BaseMediaProjectionPermissionDialogDelegate.kt | 15 ++++++--- .../permission/ScreenShareOption.kt | 3 +- .../ShareToAppPermissionDialogDelegate.kt | 5 ++- .../SystemCastPermissionDialogDelegate.kt | 7 +++- .../ScreenRecordPermissionDialogDelegate.kt | 7 ++-- .../SystemCastPermissionDialogDelegateTest.kt | 37 ++++++++++++++++++++++ 7 files changed, 66 insertions(+), 12 deletions(-) diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index 19eebf53c03e..dd4ede4022fc 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -1389,7 +1389,7 @@ When you’re casting an app, anything shown or played in that app is visible. So be careful with things like passwords, payment details, messages, photos, and audio and video. - Start casting + Cast screen @@ -1400,6 +1400,8 @@ When you’re sharing, recording, or casting an app, Android has access to anything shown or played on that app. So be careful with things like passwords, payment details, messages, photos, and audio and video. Start + + Next diff --git a/packages/SystemUI/src/com/android/systemui/mediaprojection/permission/BaseMediaProjectionPermissionDialogDelegate.kt b/packages/SystemUI/src/com/android/systemui/mediaprojection/permission/BaseMediaProjectionPermissionDialogDelegate.kt index 83f694bb1980..cdf8f06b5a23 100644 --- a/packages/SystemUI/src/com/android/systemui/mediaprojection/permission/BaseMediaProjectionPermissionDialogDelegate.kt +++ b/packages/SystemUI/src/com/android/systemui/mediaprojection/permission/BaseMediaProjectionPermissionDialogDelegate.kt @@ -95,13 +95,16 @@ abstract class BaseMediaProjectionPermissionDialogDelegate( private fun initScreenShareOptions() { selectedScreenShareOption = screenShareOptions.first { it.mode == defaultSelectedMode } - warning.text = warningText + setOptionSpecificFields() initScreenShareSpinner() } private val warningText: String get() = dialog.context.getString(selectedScreenShareOption.warningText, appName) + private val startButtonText: String + get() = dialog.context.getString(selectedScreenShareOption.startButtonText) + private fun initScreenShareSpinner() { val adapter = OptionsAdapter(dialog.context.applicationContext, screenShareOptions) screenShareModeSpinner = dialog.requireViewById(R.id.screen_share_mode_options) @@ -126,7 +129,13 @@ abstract class BaseMediaProjectionPermissionDialogDelegate( override fun onItemSelected(adapterView: AdapterView<*>?, view: View, pos: Int, id: Long) { selectedScreenShareOption = screenShareOptions[pos] + setOptionSpecificFields() + } + + /** Sets fields on the dialog that change based on which option is selected. */ + private fun setOptionSpecificFields() { warning.text = warningText + startButton.text = startButtonText } override fun onNothingSelected(parent: AdapterView<*>?) {} @@ -137,10 +146,6 @@ abstract class BaseMediaProjectionPermissionDialogDelegate( dialogTitle.text = title } - protected fun setStartButtonText(@StringRes stringId: Int) { - startButton.setText(stringId) - } - protected fun setStartButtonOnClickListener(listener: View.OnClickListener?) { startButton.setOnClickListener { view -> shouldLogCancel = false diff --git a/packages/SystemUI/src/com/android/systemui/mediaprojection/permission/ScreenShareOption.kt b/packages/SystemUI/src/com/android/systemui/mediaprojection/permission/ScreenShareOption.kt index 9bd57832c4df..ab921732ebf9 100644 --- a/packages/SystemUI/src/com/android/systemui/mediaprojection/permission/ScreenShareOption.kt +++ b/packages/SystemUI/src/com/android/systemui/mediaprojection/permission/ScreenShareOption.kt @@ -26,9 +26,10 @@ annotation class ScreenShareMode const val SINGLE_APP = 0 const val ENTIRE_SCREEN = 1 -class ScreenShareOption( +data class ScreenShareOption( @ScreenShareMode val mode: Int, @StringRes val spinnerText: Int, @StringRes val warningText: Int, + @StringRes val startButtonText: Int, val spinnerDisabledText: String? = null, ) diff --git a/packages/SystemUI/src/com/android/systemui/mediaprojection/permission/ShareToAppPermissionDialogDelegate.kt b/packages/SystemUI/src/com/android/systemui/mediaprojection/permission/ShareToAppPermissionDialogDelegate.kt index 5a2d88cf1466..8bf220277c12 100644 --- a/packages/SystemUI/src/com/android/systemui/mediaprojection/permission/ShareToAppPermissionDialogDelegate.kt +++ b/packages/SystemUI/src/com/android/systemui/mediaprojection/permission/ShareToAppPermissionDialogDelegate.kt @@ -53,7 +53,6 @@ class ShareToAppPermissionDialogDelegate( super.onCreate(dialog, savedInstanceState) // TODO(b/270018943): Handle the case of System sharing (not recording nor casting) setDialogTitle(R.string.media_projection_entry_app_permission_dialog_title) - setStartButtonText(R.string.media_projection_entry_app_permission_dialog_continue) setStartButtonOnClickListener { // Note that it is important to run this callback before dismissing, so that the // callback can disable the dialog exit animation if it wants to. @@ -88,6 +87,8 @@ class ShareToAppPermissionDialogDelegate( warningText = R.string .media_projection_entry_app_permission_dialog_warning_single_app, + startButtonText = + R.string.media_projection_entry_app_permission_dialog_continue, spinnerDisabledText = singleAppDisabledText, ), ScreenShareOption( @@ -96,6 +97,8 @@ class ShareToAppPermissionDialogDelegate( warningText = R.string .media_projection_entry_app_permission_dialog_warning_entire_screen, + startButtonText = + R.string.media_projection_entry_app_permission_dialog_continue, ) ) return if (singleAppDisabledText != null) { diff --git a/packages/SystemUI/src/com/android/systemui/mediaprojection/permission/SystemCastPermissionDialogDelegate.kt b/packages/SystemUI/src/com/android/systemui/mediaprojection/permission/SystemCastPermissionDialogDelegate.kt index 1ac3ccd19cf4..a19fb9630280 100644 --- a/packages/SystemUI/src/com/android/systemui/mediaprojection/permission/SystemCastPermissionDialogDelegate.kt +++ b/packages/SystemUI/src/com/android/systemui/mediaprojection/permission/SystemCastPermissionDialogDelegate.kt @@ -52,7 +52,6 @@ class SystemCastPermissionDialogDelegate( super.onCreate(dialog, savedInstanceState) // TODO(b/270018943): Handle the case of System sharing (not recording nor casting) setDialogTitle(R.string.media_projection_entry_cast_permission_dialog_title) - setStartButtonText(R.string.media_projection_entry_cast_permission_dialog_continue) setStartButtonOnClickListener { // Note that it is important to run this callback before dismissing, so that the // callback can disable the dialog exit animation if it wants to. @@ -89,6 +88,9 @@ class SystemCastPermissionDialogDelegate( warningText = R.string .media_projection_entry_cast_permission_dialog_warning_single_app, + startButtonText = + R.string + .media_projection_entry_generic_permission_dialog_continue_single_app, spinnerDisabledText = singleAppDisabledText, ), ScreenShareOption( @@ -99,6 +101,9 @@ class SystemCastPermissionDialogDelegate( warningText = R.string .media_projection_entry_cast_permission_dialog_warning_entire_screen, + startButtonText = + R.string + .media_projection_entry_cast_permission_dialog_continue_entire_screen, ) ) return if (singleAppDisabledText != null) { diff --git a/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenRecordPermissionDialogDelegate.kt b/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenRecordPermissionDialogDelegate.kt index ab6067c9ec0c..b54bf6ca9ef8 100644 --- a/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenRecordPermissionDialogDelegate.kt +++ b/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenRecordPermissionDialogDelegate.kt @@ -125,7 +125,6 @@ class ScreenRecordPermissionDialogDelegate( super.onCreate(dialog, savedInstanceState) setDialogTitle(R.string.screenrecord_permission_dialog_title) dialog.setTitle(R.string.screenrecord_title) - setStartButtonText(R.string.screenrecord_permission_dialog_continue) setStartButtonOnClickListener { v: View? -> onStartRecordingClicked?.run() if (selectedScreenShareOption.mode == ENTIRE_SCREEN) { @@ -272,12 +271,14 @@ class ScreenRecordPermissionDialogDelegate( ScreenShareOption( SINGLE_APP, R.string.screen_share_permission_dialog_option_single_app, - R.string.screenrecord_permission_dialog_warning_single_app + R.string.screenrecord_permission_dialog_warning_single_app, + startButtonText = R.string.screenrecord_permission_dialog_continue, ), ScreenShareOption( ENTIRE_SCREEN, R.string.screen_share_permission_dialog_option_entire_screen, - R.string.screenrecord_permission_dialog_warning_entire_screen + R.string.screenrecord_permission_dialog_warning_entire_screen, + startButtonText = R.string.screenrecord_permission_dialog_continue, ) ) } diff --git a/packages/SystemUI/tests/src/com/android/systemui/mediaprojection/permission/SystemCastPermissionDialogDelegateTest.kt b/packages/SystemUI/tests/src/com/android/systemui/mediaprojection/permission/SystemCastPermissionDialogDelegateTest.kt index 59602dcca091..6495b66cc148 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/mediaprojection/permission/SystemCastPermissionDialogDelegateTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/mediaprojection/permission/SystemCastPermissionDialogDelegateTest.kt @@ -29,6 +29,7 @@ import com.android.systemui.mediaprojection.MediaProjectionMetricsLogger import com.android.systemui.res.R import com.android.systemui.statusbar.phone.AlertDialogWithDelegate import com.android.systemui.statusbar.phone.SystemUIDialog +import com.google.common.truth.Truth.assertThat import kotlin.test.assertEquals import org.junit.After import org.junit.Test @@ -117,6 +118,36 @@ class SystemCastPermissionDialogDelegateTest : SysuiTestCase() { assertEquals(context.getString(resIdFullScreen), secondOptionText) } + @Test + fun startButtonText_entireScreenSelected() { + setUpAndShowDialog() + onSpinnerItemSelected(ENTIRE_SCREEN) + + val startButtonText = dialog.requireViewById(android.R.id.button1).text + + assertThat(startButtonText) + .isEqualTo( + context.getString( + R.string.media_projection_entry_cast_permission_dialog_continue_entire_screen + ) + ) + } + + @Test + fun startButtonText_singleAppSelected() { + setUpAndShowDialog() + onSpinnerItemSelected(SINGLE_APP) + + val startButtonText = dialog.requireViewById(android.R.id.button1).text + + assertThat(startButtonText) + .isEqualTo( + context.getString( + R.string.media_projection_entry_generic_permission_dialog_continue_single_app + ) + ) + } + private fun setUpAndShowDialog( mediaProjectionConfig: MediaProjectionConfig? = null, overrideDisableSingleAppOption: Boolean = false, @@ -144,4 +175,10 @@ class SystemCastPermissionDialogDelegateTest : SysuiTestCase() { delegate.onCreate(dialog, savedInstanceState = null) dialog.show() } + + private fun onSpinnerItemSelected(position: Int) { + val spinner = dialog.requireViewById(R.id.screen_share_mode_options) + checkNotNull(spinner.onItemSelectedListener) + .onItemSelected(spinner, mock(), position, /* id= */ 0) + } } -- cgit v1.2.3-59-g8ed1b