diff options
Diffstat (limited to 'java')
3 files changed, 77 insertions, 9 deletions
diff --git a/java/res/values/strings.xml b/java/res/values/strings.xml index 8a24b349..360e2bc6 100644 --- a/java/res/values/strings.xml +++ b/java/res/values/strings.xml @@ -155,48 +155,85 @@ } </string> <!-- Title atop a sharing UI indicating that some number of files are being shared - (for example: sharing a mixture of photos and videos [CHAR_LIMIT=50] --> + (for example: sharing a mixture of photos and videos) [CHAR_LIMIT=50] --> <string name="sharing_files">{count, plural, =1 {Sharing # file} other {Sharing # files} } </string> + + <!-- Title atop a sharing UI indicating that some number of images are being shared + along with text [CHAR_LIMIT=50] --> <string name="sharing_images_with_text">{count, plural, =1 {Sharing image with text} other {Sharing # images with text} } </string> + <!-- Title atop a sharing UI indicating that some number of images are being shared + along with a web link [CHAR_LIMIT=50] --> <string name="sharing_images_with_link">{count, plural, =1 {Sharing image with link} other {Sharing # images with link} } </string> + <!-- Title atop a sharing UI indicating that some number of videos are being shared + along with text [CHAR_LIMIT=50] --> <string name="sharing_videos_with_text">{count, plural, =1 {Sharing video with text} other {Sharing # videos with text} } </string> + <!-- Title atop a sharing UI indicating that some number of videos are being shared + along with a web link [CHAR_LIMIT=50] --> <string name="sharing_videos_with_link">{count, plural, =1 {Sharing video with link} other {Sharing # videos with link} } </string> + <!-- Title atop a sharing UI indicating that some number of files are being shared + along with text [CHAR_LIMIT=50] --> <string name="sharing_files_with_text">{count, plural, =1 {Sharing file with text} other {Sharing # files with text} } </string> + <!-- Title atop a sharing UI indicating that some number of files are being shared + along with a web link [CHAR_LIMIT=50] --> <string name="sharing_files_with_link">{count, plural, =1 {Sharing file with link} other {Sharing # files with link} } </string> + <!-- Message indicating that the attached text has been removed from this share and only the + images are being shared. [CHAR LIMIT=none] --> + <string name="sharing_images_only">{count, plural, + =1 {Image only} + other {Images only} + } + </string> + + <!-- Message indicating that the attached text has been removed from this share and only the + videos are being shared. [CHAR LIMIT=none] --> + <string name="sharing_videos_only">{count, plural, + =1 {Video only} + other {Videos only} + } + </string> + + <!-- Message indicating that the attached text has been removed from this share and only the + files are being shared. [CHAR LIMIT=none] --> + <string name="sharing_files_only">{count, plural, + =1 {File only} + other {Files only} + } + </string> + <!-- ChooserActivity - No direct share targets are available. [CHAR LIMIT=NONE] --> <string name="chooser_no_direct_share_targets">No recommended people to share with</string> diff --git a/java/src/com/android/intentresolver/contentpreview/FilesPlusTextContentPreviewUi.java b/java/src/com/android/intentresolver/contentpreview/FilesPlusTextContentPreviewUi.java index e15d53c4..5c42b4b7 100644 --- a/java/src/com/android/intentresolver/contentpreview/FilesPlusTextContentPreviewUi.java +++ b/java/src/com/android/intentresolver/contentpreview/FilesPlusTextContentPreviewUi.java @@ -21,6 +21,7 @@ import static com.android.intentresolver.contentpreview.ContentPreviewType.CONTE import android.content.res.Resources; import android.text.util.Linkify; +import android.util.PluralsMessageFormatter; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -33,6 +34,7 @@ import com.android.intentresolver.widget.ActionRow; import com.android.intentresolver.widget.ScrollableImagePreviewView; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.function.Consumer; @@ -175,9 +177,35 @@ class FilesPlusTextContentPreviewUi extends ContentPreviewUi { shareTextAction.accept(false); includeText.setOnCheckedChangeListener((view, isChecked) -> { textView.setEnabled(isChecked); + if (isChecked) { + textView.setText(mText); + } else { + textView.setText(getNoTextString(contentPreview.getResources())); + } shareTextAction.accept(!isChecked); updateHeadline(contentPreview); }); includeText.setVisibility(View.VISIBLE); } + + private String getNoTextString(Resources resources) { + int stringResource; + + if (mAllImages) { + stringResource = R.string.sharing_images_only; + } else if (mAllVideos) { + stringResource = R.string.sharing_videos_only; + } else { + stringResource = R.string.sharing_files_only; + } + + HashMap<String, Object> params = new HashMap<>(); + params.put("count", mFiles.size()); + + return PluralsMessageFormatter.format( + resources, + params, + stringResource + ); + } } diff --git a/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java b/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java index 6c659133..7c4838a2 100644 --- a/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java +++ b/java/tests/src/com/android/intentresolver/UnbundledChooserActivityTest.java @@ -694,14 +694,13 @@ public class UnbundledChooserActivityTest { } @Test - public void testImagePlusTextSharing_ExcludeText() { + public void testFilePlusTextSharing_ExcludeText() { Uri uri = Uri.parse( "android.resource://com.android.frameworks.coretests/" + R.drawable.test320x240); Intent sendIntent = createSendImageIntent(uri); ChooserActivityOverrideData.getInstance().imageLoader = createImageLoader(uri, createBitmap()); - ChooserActivityOverrideData.getInstance().isImageType = true; sendIntent.putExtra(Intent.EXTRA_TEXT, "https://google.com/search?q=google"); List<ResolvedComponentInfo> resolvedComponentInfos = Arrays.asList( @@ -723,6 +722,8 @@ public class UnbundledChooserActivityTest { .perform(click()); waitForIdle(); + onView(withId(R.id.content_preview_text)).check(matches(withText("File only"))); + AtomicReference<Intent> launchedIntentRef = new AtomicReference<>(); ChooserActivityOverrideData.getInstance().onSafelyStartInternalCallback = targetInfo -> { launchedIntentRef.set(targetInfo.getTargetIntent()); @@ -736,14 +737,13 @@ public class UnbundledChooserActivityTest { } @Test - public void testImagePlusTextSharing_RemoveAndAddBackText() { + public void testFilePlusTextSharing_RemoveAndAddBackText() { Uri uri = Uri.parse( "android.resource://com.android.frameworks.coretests/" + R.drawable.test320x240); Intent sendIntent = createSendImageIntent(uri); ChooserActivityOverrideData.getInstance().imageLoader = createImageLoader(uri, createBitmap()); - ChooserActivityOverrideData.getInstance().isImageType = true; final String text = "https://google.com/search?q=google"; sendIntent.putExtra(Intent.EXTRA_TEXT, text); @@ -765,10 +765,14 @@ public class UnbundledChooserActivityTest { .check(matches(isDisplayed())) .perform(click()); waitForIdle(); + onView(withId(R.id.content_preview_text)).check(matches(withText("File only"))); + onView(withId(R.id.include_text_action)) .perform(click()); waitForIdle(); + onView(withId(R.id.content_preview_text)).check(matches(withText(text))); + AtomicReference<Intent> launchedIntentRef = new AtomicReference<>(); ChooserActivityOverrideData.getInstance().onSafelyStartInternalCallback = targetInfo -> { launchedIntentRef.set(targetInfo.getTargetIntent()); @@ -782,14 +786,13 @@ public class UnbundledChooserActivityTest { } @Test - public void testImagePlusTextSharing_TextExclusionDoesNotAffectAlternativeIntent() { + public void testFilePlusTextSharing_TextExclusionDoesNotAffectAlternativeIntent() { Uri uri = Uri.parse( "android.resource://com.android.frameworks.coretests/" + R.drawable.test320x240); Intent sendIntent = createSendImageIntent(uri); ChooserActivityOverrideData.getInstance().imageLoader = createImageLoader(uri, createBitmap()); - ChooserActivityOverrideData.getInstance().isImageType = true; sendIntent.putExtra(Intent.EXTRA_TEXT, "https://google.com/search?q=google"); Intent alternativeIntent = createSendTextIntent(); @@ -828,7 +831,7 @@ public class UnbundledChooserActivityTest { } @Test - public void testImagePlusTextSharing_failedThumbnailAndExcludedText_textRemainsVisible() { + public void testImagePlusTextSharing_failedThumbnailAndExcludedText_textChanges() { Uri uri = Uri.parse( "android.resource://com.android.frameworks.coretests/" + R.drawable.test320x240); @@ -860,7 +863,7 @@ public class UnbundledChooserActivityTest { onView(withId(R.id.image_view)) .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); onView(withId(R.id.content_preview_text)) - .check(matches(allOf(isDisplayed(), not(isEnabled())))); + .check(matches(allOf(isDisplayed(), not(isEnabled()), withText("File only")))); } @Test |