From aefab7a73e41f0581bcd47285188b8ec1ee2efa9 Mon Sep 17 00:00:00 2001 From: Abbasali Date: Wed, 12 Sep 2018 17:03:46 +0430 Subject: [PATCH] Update README.md --- README.md | 43 ++++++++++++++----------------------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 04012b0..39ba3c7 100644 --- a/README.md +++ b/README.md @@ -22,39 +22,24 @@ dependencies { Open file picker: ```java -new MaterialFilePicker() - .withActivity(this) - .withRequestCode(1) - .withFilter(Pattern.compile(".*\\.txt$")) // Filtering files and directories by file name using regexp - .withFilterDirectories(true) // Set directories filterable (false by default) - .withHiddenFiles(true) // Show hidden files and folders - .start(); +DirectoryFragment instance = new DirectoryFragment(); + Bundle args = new Bundle(); + args.putString(DirectoryFragment.ARG_FILE_PATH, Environment.getExternalStorageDirectory().getAbsolutePath()); + args.putSerializable(DirectoryFragment.ARG_FILTER, new CompositeFilter(new ArrayList())); + args.putBoolean(DirectoryFragment.ARG_SHOW_HIDDEN, false); + instance.setArguments(args); + instance.show(getSupportFragmentManager(), "AnyTag"); + DirectoryFragment.FileClickListener f = new DirectoryFragment.FileClickListener() { + @Override + public void onFileClicked(File clickedFile) { + Toast.makeText(MainActivity.this, "فایل انتخاب شد", Toast.LENGTH_SHORT).show(); + } + }; + instance.setInterFace(f); ``` -or -```java -Intent intent = new Intent(this, FilePickerActivity.class); -intent.putExtra(FilePickerActivity.ARG_FILE_FILTER, Pattern.compile(".*\\.txt$")); -intent.putExtra(FilePickerActivity.ARG_DIRECTORIES_FILTER, true); -intent.putExtra(FilePickerActivity.ARG_SHOW_HIDDEN, true); -startActivityForResult(intent, 1); -``` - -Override on activity result: - -```java -@Override -protected void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - if (requestCode == 1 && resultCode == RESULT_OK) { - String filePath = data.getStringExtra(FilePickerActivity.RESULT_FILE_PATH); - // Do anything with file - } -} -``` Runtime permissions: You should handle runtime permissions in activity, from what you called Material File Picker. -Look [here](https://github.com/nbsp-team/MaterialFilePicker/blob/master/app/src/main/java/com/dimorinny/sample/MainActivity.java#L38-L69) for example code.