From 464f6c43a9e20727ba02d629a49a42e92877eebd Mon Sep 17 00:00:00 2001 From: Jonas Kalderstam Date: Sat, 22 Oct 2016 17:39:00 +0200 Subject: [PATCH] Add test for multiple selection in StringExtras --- .../filepicker/sample/SelectMultipleFiles.java | 18 +++++++++++++++++- .../sample/NoNonsenseFilePicker.java | 9 +++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/sample/src/androidTestUitests/java/com/nononsenseapps/filepicker/sample/SelectMultipleFiles.java b/sample/src/androidTestUitests/java/com/nononsenseapps/filepicker/sample/SelectMultipleFiles.java index 8117e884..e078d9d8 100644 --- a/sample/src/androidTestUitests/java/com/nononsenseapps/filepicker/sample/SelectMultipleFiles.java +++ b/sample/src/androidTestUitests/java/com/nononsenseapps/filepicker/sample/SelectMultipleFiles.java @@ -46,7 +46,23 @@ public void allowPermissions() { * Should not throw on Android 24 */ @Test - public void selectTwoFilesDoesNotThrow() { + public void selectTwoFilesDoesNotThrowWithClipData() { + NoNonsenseFilePicker.useClipData = true; + + selectTwoFilesDoesNotThrow(); + } + + /** + * Should not throw on Android 24 + */ + @Test + public void selectTwoFilesDoesNotThrowWithStringExtras() { + NoNonsenseFilePicker.useClipData = false; + + selectTwoFilesDoesNotThrow(); + } + + private void selectTwoFilesDoesNotThrow() { ViewInteraction radioButton = onView( allOf(withId(R.id.radioFile), withText("Select file"), withParent(withId(R.id.radioGroup)), diff --git a/sample/src/main/java/com/nononsenseapps/filepicker/sample/NoNonsenseFilePicker.java b/sample/src/main/java/com/nononsenseapps/filepicker/sample/NoNonsenseFilePicker.java index 0cf09b19..fb33aa36 100644 --- a/sample/src/main/java/com/nononsenseapps/filepicker/sample/NoNonsenseFilePicker.java +++ b/sample/src/main/java/com/nononsenseapps/filepicker/sample/NoNonsenseFilePicker.java @@ -42,6 +42,9 @@ public class NoNonsenseFilePicker extends Activity { + // How to handle multiple return data + public static boolean useClipData = true; + static final int CODE_SD = 0; static final int CODE_DB = 1; static final int CODE_FTP = 2; @@ -226,7 +229,8 @@ protected void onActivityResult(int requestCode, int resultCode, // If we handled multiple files, we need to get the result differently if (data.getBooleanExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false)) { // This is the typical style on Android 4.2 and above - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + if (useClipData && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + Log.i("SAMPLEAPP", "onActivityResult: Using ClipData"); ClipData clip = data.getClipData(); StringBuilder sb = new StringBuilder(); @@ -245,6 +249,7 @@ protected void onActivityResult(int requestCode, int resultCode, binding.text.setText(sb.toString()); } else /* This style is available in all SDK versions */ { + Log.i("SAMPLEAPP", "onActivityResult: Using StringExtras"); ArrayList paths = data.getStringArrayListExtra( FilePickerActivity.EXTRA_PATHS); StringBuilder sb = new StringBuilder(); @@ -255,7 +260,7 @@ protected void onActivityResult(int requestCode, int resultCode, sb.append("\n"); } sb.append(CODE_SD == requestCode ? - Utils.getFileForUriString(path).toString() : + Utils.getFileForUri(Uri.parse(path)).toString() : path); } }