Java Code Examples for com.nononsenseapps.filepicker.Utils

The following examples show how to use com.nononsenseapps.filepicker.Utils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
protected void onActivityResult(int requestCode, int resultCode, Intent intent)
{
    if (requestCode == SELECT_FILE_REQUEST && resultCode == Activity.RESULT_OK)
    {
        // Use the provided utility method to parse the result
        List<Uri> files = Utils.getSelectedFilesFromResult(intent);

        // There should be at most once result
        if(files.size() > 0)
        {
            File file = Utils.getFileForUri(files.get(0));

            // Save the directory where the file was selected, so the next
            // file search will start in that directory.
            String parentDir = file.getParent();
            SharedPreferences prefs = getSharedPreferences(SHARED_PREFS_KEY, MODE_PRIVATE);
            prefs.edit().putString(PICKER_DIR_PREF, parentDir).apply();

            Log.i(TAG, "Selected file: " + file.getAbsolutePath());
            setSelectMediaFile(file.getAbsolutePath(), null);
        }
    }
}
 
Example 2
Source Project: openlauncher   Source File: SettingsActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        Setup.dataManager().close();
        List<Uri> files = Utils.getSelectedFilesFromResult(data);
        switch (requestCode) {
            case Definitions.INTENT_BACKUP:
                BackupHelper.backupConfig(this, new File(Utils.getFileForUri(files.get(0)).getAbsolutePath() + "/openlauncher.zip").toString());
                Setup.dataManager().open();
                break;
            case Definitions.INTENT_RESTORE:
                BackupHelper.restoreConfig(this, Utils.getFileForUri(files.get(0)).toString());
                System.exit(0);
                break;
        }
    }
}
 
Example 3
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // Always check the resultCode!
    // Checking for the requestCodes is a bit redundant but good style
    if (resultCode == Activity.RESULT_OK &&
            (CODE_SD == requestCode || CODE_DB == requestCode || CODE_FTP == requestCode)) {
        // Use the provided utility method to parse the result
        List<Uri> files = Utils.getSelectedFilesFromResult(data);

        // Do something with your list of files here
        StringBuilder sb = new StringBuilder();
        for (Uri uri : files) {
            if (sb.length() > 0) {
                sb.append("\n");
            }
            sb.append(CODE_SD == requestCode ?
                    Utils.getFileForUri(uri).toString() :
                    uri.toString());
        }
        binding.text.setText(sb.toString());
    }
}
 
Example 4
@Nullable
public static String getSelectedDirectory(Intent result)
{
  // Use the provided utility method to parse the result
  List<Uri> files = Utils.getSelectedFilesFromResult(result);
  if (!files.isEmpty())
  {
    File file = Utils.getFileForUri(files.get(0));
    return file.getAbsolutePath();
  }

  return null;
}
 
Example 5
Source Project: J2ME-Loader   Source File: AppsListFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
	if (requestCode == FILE_CODE && resultCode == Activity.RESULT_OK) {
		List<Uri> files = Utils.getSelectedFilesFromResult(data);
		for (Uri uri : files) {
			File file = Utils.getFileForUri(uri);
			convertJar(file.getAbsolutePath());
		}
	}
}
 
Example 6
private void selectTwoFilesDoesNotThrow() {
    ViewInteraction radioButton = onView(
            allOf(withId(R.id.radioFile), withText("Select file"),
                    withParent(withId(R.id.radioGroup)),
                    isDisplayed()));
    radioButton.perform(click());

    ViewInteraction checkBox = onView(
            allOf(withId(R.id.checkAllowMultiple), withText("Multiple items"), isDisplayed()));
    checkBox.perform(click());

    ViewInteraction button = onView(
            allOf(withId(R.id.button_sd), withText("Pick SD-card"), isDisplayed()));
    button.perform(click());

    ViewInteraction recyclerView = onView(
            allOf(withId(android.R.id.list), isDisplayed()));

    // Refresh view (into dir, and out again)
    recyclerView.perform(actionOnItemAtPosition(1, click()));
    recyclerView.perform(actionOnItemAtPosition(0, click()));

    // Click on test dir
    recyclerView.perform(actionOnItemAtPosition(1, click()));
    // sub dir
    recyclerView.perform(actionOnItemAtPosition(1, click()));
    // Select first two
    recyclerView.perform(actionOnItemAtPosition(1, click()));
    recyclerView.perform(actionOnItemAtPosition(2, click()));

    // Click OK
    ViewInteraction okButton = onView(
            allOf(withId(R.id.nnf_button_ok),
                    withParent(allOf(withId(R.id.nnf_button_container),
                            withParent(withId(R.id.nnf_buttons_container)))),
                    isDisplayed()));
    okButton.perform(click());

    ViewInteraction textView = onView(withId(R.id.text));
    textView.check(matches(
            withText("/storage/emulated/0/000000_nonsense-tests/A-dir/file-1.txt\n" +
                    "/storage/emulated/0/000000_nonsense-tests/A-dir/file-0.txt")));

    // Make sure we can read one
    File file =
            Utils.getFileForUri(
                    Uri.parse("content://com.nononsenseapps.filepicker.sample.provider/root/storage/emulated/0/000000_nonsense-tests/A-dir/file-1.txt"));
    assertEquals("/storage/emulated/0/000000_nonsense-tests/A-dir/file-1.txt", file.toString());
    assertTrue(file.isFile());
    assertTrue(file.canRead());
    assertTrue(file.canWrite());
}