diff options
author | 2025-02-24 17:10:39 -0800 | |
---|---|---|
committer | 2025-02-24 17:10:39 -0800 | |
commit | aa36a2386976bc20729acc2febe5475c53522cdb (patch) | |
tree | fcfb014298b4dfb987b49cf598718520cda41985 /java | |
parent | 3834835c0078582c73795b8cf7a72d7d0458e275 (diff) | |
parent | e6a9f21e66371f6234f916345233a8f65871e80e (diff) |
Merge "Update the text preview UI copy button content description" into main
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, |