Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Commit

Permalink
Add test for multiple selection in StringExtras
Browse files Browse the repository at this point in the history
  • Loading branch information
spacecowboy committed Oct 22, 2016
1 parent 9133681 commit 464f6c4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand All @@ -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<String> paths = data.getStringArrayListExtra(
FilePickerActivity.EXTRA_PATHS);
StringBuilder sb = new StringBuilder();
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 464f6c4

Please sign in to comment.