diff options
author | 2025-02-19 14:43:13 -0800 | |
---|---|---|
committer | 2025-02-24 11:36:49 -0800 | |
commit | e6a9f21e66371f6234f916345233a8f65871e80e (patch) | |
tree | cd83467c81c80804747dc9871b21157111f0d351 /java | |
parent | fd34abc34ce07dbe6a740592a42bf7822d0f903e (diff) |
Update the text preview UI copy button content description
Update the text preview UI copy button content description from "copy"
to either "Copy text" or "Copy link" depending whether the shared text
is a link.
Fix: 395683735
Test: atest IntentResolver-tests-unit
Test: manual testing: share a text and a link and check TalkBack
announcement for the button.
Flag: EXEMPT bug fix
Change-Id: I668c2fd7e7f0a025c75e43a8a49541ebf3a94730
Diffstat (limited to 'java')
4 files changed, 27 insertions, 13 deletions
diff --git a/java/res/values/strings.xml b/java/res/values/strings.xml index 52b27304..c9ee9d80 100644 --- a/java/res/values/strings.xml +++ b/java/res/values/strings.xml @@ -353,4 +353,11 @@ <!-- Accessibility announcement for the all-applications group in the list of targets. [CHAR LIMIT=NONE] --> <string name="all_apps_group_a11y_title">App list</string> + + <!-- Content description for an action chip button in the content preview UI when a text is + shared. The button is used to copy the text into the clipboard. [CHAR_LIMIT=NONE] --> + <string name="copy_text">Copy text</string> + <!-- Content description for an action chip button in the content preview UI when a link is + shared. The button is used to copy the text into the clipboard. [CHAR_LIMIT=NONE] --> + <string name="copy_link">Copy link</string> </resources> diff --git a/java/src/com/android/intentresolver/contentpreview/HeadlineGenerator.kt b/java/src/com/android/intentresolver/contentpreview/HeadlineGenerator.kt index 059ee083..9c4122bb 100644 --- a/java/src/com/android/intentresolver/contentpreview/HeadlineGenerator.kt +++ b/java/src/com/android/intentresolver/contentpreview/HeadlineGenerator.kt @@ -38,4 +38,6 @@ interface HeadlineGenerator { fun getFilesHeadline(count: Int): String fun getNotItemsSelectedHeadline(): String + + fun getCopyButtonContentDescription(sharedText: CharSequence): String } diff --git a/java/src/com/android/intentresolver/contentpreview/HeadlineGeneratorImpl.kt b/java/src/com/android/intentresolver/contentpreview/HeadlineGeneratorImpl.kt index 822d3097..ca01875b 100644 --- a/java/src/com/android/intentresolver/contentpreview/HeadlineGeneratorImpl.kt +++ b/java/src/com/android/intentresolver/contentpreview/HeadlineGeneratorImpl.kt @@ -33,11 +33,8 @@ private const val PLURALS_COUNT = "count" * HeadlineGenerator generates the text to show at the top of the sharesheet as a brief description * of the content being shared. */ -class HeadlineGeneratorImpl -@Inject -constructor( - @ApplicationContext private val context: Context, -) : HeadlineGenerator { +class HeadlineGeneratorImpl @Inject constructor(@ApplicationContext private val context: Context) : + HeadlineGenerator { override fun getTextHeadline(text: CharSequence): String { return context.getString( getTemplateResource(text, R.string.sharing_link, R.string.sharing_text) @@ -53,9 +50,9 @@ constructor( getTemplateResource( text, R.string.sharing_images_with_link, - R.string.sharing_images_with_text + R.string.sharing_images_with_text, ), - count + count, ) } @@ -64,9 +61,9 @@ constructor( getTemplateResource( text, R.string.sharing_videos_with_link, - R.string.sharing_videos_with_text + R.string.sharing_videos_with_text, ), - count + count, ) } @@ -75,9 +72,9 @@ constructor( getTemplateResource( text, R.string.sharing_files_with_link, - R.string.sharing_files_with_text + R.string.sharing_files_with_text, ), - count + count, ) } @@ -96,11 +93,17 @@ constructor( override fun getNotItemsSelectedHeadline(): String = context.getString(R.string.select_items_to_share) + override fun getCopyButtonContentDescription(sharedText: CharSequence): String { + return context.getString( + getTemplateResource(sharedText, R.string.copy_link, R.string.copy_text) + ) + } + private fun getPluralString(@StringRes templateResource: Int, count: Int): String { return PluralsMessageFormatter.format( context.resources, mapOf(PLURALS_COUNT to count), - templateResource + templateResource, ) } @@ -108,7 +111,7 @@ constructor( private fun getTemplateResource( text: CharSequence, @StringRes linkResource: Int, - @StringRes nonLinkResource: Int + @StringRes nonLinkResource: Int, ): Int { return if (text.toString().isHttpUri()) linkResource else nonLinkResource } diff --git a/java/src/com/android/intentresolver/contentpreview/TextContentPreviewUi.java b/java/src/com/android/intentresolver/contentpreview/TextContentPreviewUi.java index 45a0130d..8592e6ae 100644 --- a/java/src/com/android/intentresolver/contentpreview/TextContentPreviewUi.java +++ b/java/src/com/android/intentresolver/contentpreview/TextContentPreviewUi.java @@ -142,6 +142,8 @@ class TextContentPreviewUi extends ContentPreviewUi { View copyButton = contentPreviewLayout.findViewById(R.id.copy); if (copyButton != null) { if (onCopy != null) { + copyButton.setContentDescription( + mHeadlineGenerator.getCopyButtonContentDescription(mSharingText)); copyButton.setOnClickListener((v) -> onCopy.run()); ViewCompat.setAccessibilityDelegate( copyButton, |