[Partial Screensharing] Hide 'show touches' in SysUI Recorder

Disable and hide 'Show Touches' Switch when Single App is selected as the screen share option.

Bug: 241366482
Test: com.android.systemui.screenrecord.ScreenRecordPermissionDialogTest
Change-Id: I7344669b0a08ea971c76950bac429152711f3fda
This commit is contained in:
yyalan
2022-11-09 14:21:22 +00:00
committed by Yalan Yiue
parent d825147525
commit e17b87946d
3 changed files with 128 additions and 7 deletions

View File

@@ -50,6 +50,7 @@
android:importantForAccessibility="yes"/>
</LinearLayout>
<LinearLayout
android:id="@+id/show_taps"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"

View File

@@ -24,8 +24,9 @@ import android.os.Handler
import android.os.Looper
import android.os.ResultReceiver
import android.view.View
import android.view.View.GONE
import android.view.View.VISIBLE
import android.widget.AdapterView
import android.widget.AdapterView.OnItemClickListener
import android.widget.ArrayAdapter
import android.widget.Spinner
import android.widget.Switch
@@ -47,6 +48,7 @@ class ScreenRecordPermissionDialog(
private val onStartRecordingClicked: Runnable?
) : BaseScreenSharePermissionDialog(context, createOptionList(), null) {
private lateinit var tapsSwitch: Switch
private lateinit var tapsView: View
private lateinit var audioSwitch: Switch
private lateinit var options: Spinner
override fun onCreate(savedInstanceState: Bundle?) {
@@ -84,16 +86,25 @@ class ScreenRecordPermissionDialog(
private fun initRecordOptionsView() {
audioSwitch = findViewById(R.id.screenrecord_audio_switch)
tapsSwitch = findViewById(R.id.screenrecord_taps_switch)
tapsView = findViewById(R.id.show_taps)
updateTapsViewVisibility()
options = findViewById(R.id.screen_recording_options)
val a: ArrayAdapter<*> =
ScreenRecordingAdapter(context, android.R.layout.simple_spinner_dropdown_item, MODES)
a.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
options.adapter = a
options.setOnItemClickListenerInt(
OnItemClickListener { _: AdapterView<*>?, _: View?, _: Int, _: Long ->
audioSwitch.isChecked = true
}
)
options.setOnItemClickListenerInt { _: AdapterView<*>?, _: View?, _: Int, _: Long ->
audioSwitch.isChecked = true
}
}
override fun onItemSelected(adapterView: AdapterView<*>?, view: View, pos: Int, id: Long) {
super.onItemSelected(adapterView, view, pos, id)
updateTapsViewVisibility()
}
private fun updateTapsViewVisibility() {
tapsView.visibility = if (selectedScreenShareOption.mode == SINGLE_APP) GONE else VISIBLE
}
/**
@@ -103,7 +114,7 @@ class ScreenRecordPermissionDialog(
*/
private fun requestScreenCapture(captureTarget: MediaProjectionCaptureTarget?) {
val userContext = userContextProvider.userContext
val showTaps = tapsSwitch.isChecked
val showTaps = selectedScreenShareOption.mode != SINGLE_APP && tapsSwitch.isChecked
val audioMode =
if (audioSwitch.isChecked) options.selectedItem as ScreenRecordingAudioSource
else ScreenRecordingAudioSource.NONE

View File

@@ -0,0 +1,109 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.systemui.screenrecord
import android.testing.AndroidTestingRunner
import android.testing.TestableLooper
import android.view.View
import android.widget.Spinner
import androidx.test.filters.SmallTest
import com.android.systemui.R
import com.android.systemui.SysuiTestCase
import com.android.systemui.animation.DialogLaunchAnimator
import com.android.systemui.flags.FeatureFlags
import com.android.systemui.flags.Flags
import com.android.systemui.plugins.ActivityStarter
import com.android.systemui.settings.UserContextProvider
import com.android.systemui.util.mockito.mock
import com.google.common.truth.Truth.assertThat
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.Mockito.`when` as whenever
import org.mockito.MockitoAnnotations
@SmallTest
@RunWith(AndroidTestingRunner::class)
@TestableLooper.RunWithLooper(setAsMainLooper = true)
class ScreenRecordPermissionDialogTest : SysuiTestCase() {
@Mock private lateinit var starter: ActivityStarter
@Mock private lateinit var controller: RecordingController
@Mock private lateinit var userContextProvider: UserContextProvider
@Mock private lateinit var flags: FeatureFlags
@Mock private lateinit var dialogLaunchAnimator: DialogLaunchAnimator
@Mock private lateinit var onStartRecordingClicked: Runnable
private lateinit var dialog: ScreenRecordPermissionDialog
@Before
fun setUp() {
MockitoAnnotations.initMocks(this)
dialog =
ScreenRecordPermissionDialog(
context,
controller,
starter,
dialogLaunchAnimator,
userContextProvider,
onStartRecordingClicked
)
dialog.onCreate(null)
whenever(flags.isEnabled(Flags.WM_ENABLE_PARTIAL_SCREEN_SHARING)).thenReturn(true)
}
@After
fun teardown() {
if (::dialog.isInitialized) {
dialog.dismiss()
}
}
@Test
fun testShowDialog_partialScreenSharingEnabled_optionsSpinnerIsVisible() {
dialog.show()
val visibility = dialog.requireViewById<Spinner>(R.id.screen_share_mode_spinner).visibility
assertThat(visibility).isEqualTo(View.VISIBLE)
}
@Test
fun testShowDialog_singleAppSelected_showTapsIsGone() {
dialog.show()
onSpinnerItemSelected(SINGLE_APP)
val visibility = dialog.requireViewById<View>(R.id.show_taps).visibility
assertThat(visibility).isEqualTo(View.GONE)
}
@Test
fun testShowDialog_entireScreenSelected_showTapsIsVisible() {
dialog.show()
onSpinnerItemSelected(ENTIRE_SCREEN)
val visibility = dialog.requireViewById<View>(R.id.show_taps).visibility
assertThat(visibility).isEqualTo(View.VISIBLE)
}
private fun onSpinnerItemSelected(position: Int) {
val spinner = dialog.requireViewById<Spinner>(R.id.screen_share_mode_spinner)
spinner.onItemSelectedListener.onItemSelected(spinner, mock(), position, /* id= */ 0)
}
}