Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 09b43cb8 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[A11y][Keyboard shortcuts] Update and flag Magnification dialog strings" into main

parents 0aba2927 112c4a99
Loading
Loading
Loading
Loading
+44 −5
Original line number Diff line number Diff line
@@ -24,12 +24,16 @@ import android.content.pm.ResolveInfo
import android.content.pm.ServiceInfo
import android.content.res.mainResources
import android.hardware.input.KeyGestureEvent
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.platform.test.flag.junit.SetFlagsRule
import android.text.Annotation
import android.text.Spanned
import android.view.KeyEvent
import android.view.accessibility.AccessibilityManager
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.hardware.input.Flags
import com.android.internal.accessibility.AccessibilityShortcutController.MAGNIFICATION_CONTROLLER_NAME
import com.android.internal.accessibility.common.ShortcutConstants
import com.android.systemui.SysuiTestCase
@@ -40,6 +44,7 @@ import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers.anyInt
@@ -60,6 +65,8 @@ class AccessibilityShortcutsRepositoryImplTest : SysuiTestCase() {
    private val resources = kosmos.mainResources
    private val testScope = kosmos.testScope

    @get:Rule val setFlagsRule = SetFlagsRule()

    // mocks
    private val accessibilityManager: AccessibilityManager = mock(AccessibilityManager::class.java)

@@ -94,8 +101,9 @@ class AccessibilityShortcutsRepositoryImplTest : SysuiTestCase() {
        }
    }

    @EnableFlags(Flags.FLAG_ENABLE_MAGNIFY_MAGNIFICATION_KEY_GESTURE_DIALOG)
    @Test
    fun getTitleToContentForKeyGestureDialog_onMagnificationTypeReceived_getExpectedInfo() {
    fun getTitleToContentForKeyGestureDialog_onMagnificationTypeReceived_doNotEnableShortcut_getExpectedInfo() {
        testScope.runTest {
            val metaState = KeyEvent.META_META_ON or KeyEvent.META_ALT_ON

@@ -115,9 +123,40 @@ class AccessibilityShortcutsRepositoryImplTest : SysuiTestCase() {
            // compare its value here.
            assertThat(contentText?.toString())
                .isEqualTo(
                    "Action icon + Alt + M is the keyboard shortcut to use Magnification. This" +
                            " allows you to quickly zoom in on the screen to make content larger." +
                            " Press Action icon + Alt and \"+\" or \"-\" to adjust zoom."
                    "Action icon + Alt + M is the keyboard shortcut to use Magnification, an" +
                        " accessibility feature. This allows you to quickly zoom in on the screen" +
                        " to make content larger. Once magnification is on, press Action icon +" +
                        " Alt and \"+\" or \"-\" to adjust zoom."
                )
        }
    }

    @DisableFlags(Flags.FLAG_ENABLE_MAGNIFY_MAGNIFICATION_KEY_GESTURE_DIALOG)
    @Test
    fun getTitleToContentForKeyGestureDialog_onMagnificationTypeReceived_enableShortcut_getExpectedInfo() {
        testScope.runTest {
            val metaState = KeyEvent.META_META_ON or KeyEvent.META_ALT_ON

            val titleToContent =
                underTest.getTitleToContentForKeyGestureDialog(
                    KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION,
                    metaState,
                    KeyEvent.KEYCODE_M,
                    getTargetNameByType(KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION),
                )

            assertThat(titleToContent).isNotNull()
            assertThat(titleToContent?.first).isEqualTo("Turn on Magnification keyboard shortcut?")
            val contentText = titleToContent?.second
            assertThat(hasExpectedAnnotation(contentText)).isTrue()
            // `contentText` here is an instance of SpannableStringBuilder, so we only need to
            // compare its value here.
            assertThat(contentText?.toString())
                .isEqualTo(
                    "Action icon + Alt + M is the keyboard shortcut to use Magnification, an" +
                        " accessibility feature. This allows you to quickly zoom in on the screen" +
                        " to make content larger. Once magnification is on, press Action icon +" +
                        " Alt and \"+\" or \"-\" to adjust zoom."
                )
        }
    }
+11 −10
Original line number Diff line number Diff line
@@ -2945,23 +2945,24 @@
    <!-- Positive button text for the dialog. [CHAR LIMIT=NONE] -->
    <string name="accessibility_key_gesture_dialog_positive_button_text">Turn on</string>

    <!-- Text for the Magnification dialog title. [CHAR LIMIT=NONE] -->
    <!-- Text for the dialog title when keyboard shortcut has not yet been enabled. [CHAR LIMIT=NONE] -->
    <string name="accessibility_key_gesture_shortcut_not_yet_enabled_dialog_title">Turn on <xliff:g name="feature_name" example="Voice Access">%1$s</xliff:g> keyboard shortcut?</string>
    <!-- Negative button text for dialog when the keyboard shortcut has not yet enabled. [CHAR LIMIT=NONE] -->
    <string name="accessibility_key_gesture_shortcut_not_yet_enabled_negative_button_text">Don\'t turn on</string>
    <!-- Positive button text for dialog when the keyboard shortcut has not yet enabled. [CHAR LIMIT=NONE] -->
    <string name="accessibility_key_gesture_shortcut_not_yet_enabled_positive_button_text">Turn on shortcut</string>

    <!-- Text for the Magnification dialog title when the keyboard shortcut is enabled and Magnification has been toggled on. [CHAR LIMIT=NONE] -->
    <string name="accessibility_key_gesture_magnification_dialog_title"><xliff:g name="feature_name" example="Magnification">%1$s</xliff:g> keyboard shortcut turned on</string>
    <!-- Text for showing inside the Magnification dialog. [CHAR LIMIT=NONE] -->
    <string name="accessibility_key_gesture_magnification_dialog_content">Action <annotation id="action_key_icon">icon</annotation> + <xliff:g name="secondary_key" example="Alt">^1</xliff:g> + <xliff:g name="key_code" example="M">^2</xliff:g> is the keyboard shortcut to use <xliff:g name="feature_name" example="Magnification">^3</xliff:g>. This allows you to quickly zoom in on the screen to make content larger. Press Action <annotation id="action_key_icon">icon</annotation> + <xliff:g name="secondary_key" example="Alt">^1</xliff:g> and \"+\" or \"-\" to adjust zoom.</string>
    <!-- Negative button text for the Magnification dialog. [CHAR LIMIT=NONE] -->
    <string name="accessibility_key_gesture_magnification_dialog_content">Action <annotation id="action_key_icon">icon</annotation> + <xliff:g name="secondary_key" example="Alt">^1</xliff:g> + <xliff:g name="key_code" example="M">^2</xliff:g> is the keyboard shortcut to use <xliff:g name="feature_name" example="Magnification">^3</xliff:g>, an accessibility feature. This allows you to quickly zoom in on the screen to make content larger. Once magnification is on, press Action <annotation id="action_key_icon">icon</annotation> + <xliff:g name="secondary_key" example="Alt">^1</xliff:g> and \"+\" or \"-\" to adjust zoom.</string>
    <!-- Negative button text for the Magnification dialog when the keyboard shortcut is enabled. [CHAR LIMIT=NONE] -->
    <string name="accessibility_key_gesture_magnification_dialog_negative_button_text">Turn off shortcut</string>
    <!-- Positive button text for the Magnification dialog. [CHAR LIMIT=NONE] -->
    <!-- Positive button text for the Magnification dialog when the keyboard shortcut is enabled. [CHAR LIMIT=NONE] -->
    <string name="accessibility_key_gesture_magnification_dialog_positive_button_text">Keep on</string>

    <!-- Text for the Voice Access dialog title. [CHAR LIMIT=NONE] -->
    <string name="accessibility_key_gesture_voice_access_dialog_title">Turn on <xliff:g name="feature_name" example="Voice Access">%1$s</xliff:g> keyboard shortcut?</string>
    <!-- Text for showing inside the Voice Access dialog. [CHAR LIMIT=NONE] -->
    <string name="accessibility_key_gesture_voice_access_dialog_content">Pressing Action <annotation id="action_key_icon">icon</annotation> + <xliff:g name="secondary_key" example="Alt">^1</xliff:g> + <xliff:g name="key_code" example="M">^2</xliff:g> turns on <xliff:g name="feature_name" example="Voice Access">^3</xliff:g>, an accessibility feature. This lets you control your device hands-free.</string>
    <!-- Negative button text for the Voice Access dialog. [CHAR LIMIT=NONE] -->
    <string name="accessibility_key_gesture_voice_access_dialog_negative_button_text">Don\'t turn on</string>
    <!-- Positive button text for the Voice Access dialog. [CHAR LIMIT=NONE] -->
    <string name="accessibility_key_gesture_voice_access_dialog_positive_button_text">Turn on shortcut</string>

    <!-- Plugin control section of the tuner. Non-translatable since it should
         not appear on production builds ever. -->
+17 −9
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.text.BidiFormatter
import android.text.TextUtils
import android.view.KeyEvent
import android.view.accessibility.AccessibilityManager
import com.android.hardware.input.Flags
import com.android.internal.accessibility.common.ShortcutConstants
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
@@ -88,9 +89,9 @@ constructor(
            KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION,
            KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_VOICE_ACCESS -> {
                val featureName = getFeatureName(keyGestureType, targetName) ?: return null
                val title = getFeatureTitle(keyGestureType, featureName) ?: return null
                val title = getDialogTitle(keyGestureType, featureName) ?: return null
                val content =
                    getFeatureContent(
                    getDialogContent(
                        keyGestureType,
                        secondaryModifierLabel.invoke(context),
                        keyCodeLabel,
@@ -156,17 +157,24 @@ constructor(
        }
    }

    private suspend fun getFeatureTitle(keyGestureType: Int, featureName: CharSequence): String? {
    private suspend fun getDialogTitle(keyGestureType: Int, featureName: CharSequence): String? {
        return when (keyGestureType) {
            KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION -> {
                if (Flags.enableMagnifyMagnificationKeyGestureDialog()) {
                    resources.getString(
                        R.string.accessibility_key_gesture_magnification_dialog_title,
                        featureName,
                    )
                } else {
                    resources.getString(
                        R.string.accessibility_key_gesture_shortcut_not_yet_enabled_dialog_title,
                        featureName,
                    )
                }
            }
            KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_VOICE_ACCESS -> {
                resources.getString(
                    R.string.accessibility_key_gesture_voice_access_dialog_title,
                    R.string.accessibility_key_gesture_shortcut_not_yet_enabled_dialog_title,
                    featureName,
                )
            }
@@ -174,7 +182,7 @@ constructor(
        }
    }

    private fun getFeatureContent(
    private fun getDialogContent(
        keyGestureType: Int,
        secondaryModifierLabel: String,
        keyCodeLabel: String,
+4 −4
Original line number Diff line number Diff line
@@ -115,9 +115,9 @@ constructor(
    private class VoiceAccessDialogDelegate(interactor: KeyGestureDialogInteractor) :
        BaseDialogDelegate(interactor) {
        override val negativeButtonTextId: Int =
            R.string.accessibility_key_gesture_voice_access_dialog_negative_button_text
            R.string.accessibility_key_gesture_shortcut_not_yet_enabled_negative_button_text
        override val positiveButtonTextId: Int =
            R.string.accessibility_key_gesture_voice_access_dialog_positive_button_text
            R.string.accessibility_key_gesture_shortcut_not_yet_enabled_positive_button_text
    }

    /**
@@ -141,9 +141,9 @@ constructor(
    private class MagnificationDialogDelegate(interactor: KeyGestureDialogInteractor) :
        BaseDialogDelegate(interactor) {
        override val negativeButtonTextId: Int =
            R.string.accessibility_key_gesture_magnification_dialog_negative_button_text
            R.string.accessibility_key_gesture_shortcut_not_yet_enabled_negative_button_text
        override val positiveButtonTextId: Int =
            R.string.accessibility_key_gesture_magnification_dialog_positive_button_text
            R.string.accessibility_key_gesture_shortcut_not_yet_enabled_positive_button_text
    }

    private fun getDialogDelegate(keyGestureType: Int): DialogBehaviorDelegate {