com.afollestad.materialdialogs.folderselector.FileChooserDialog Java Examples

The following examples show how to use com.afollestad.materialdialogs.folderselector.FileChooserDialog. 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
Source File: OPMLReadHelper.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
public void run(){
    String[] perms = {Manifest.permission.READ_EXTERNAL_STORAGE};
    if (EasyPermissions.hasPermissions(activity, perms)) {
        //有权限
        new FileChooserDialog.Builder(activity)
                .initialPath(GlobalConfig.appDirPath)  //初始显示了目录
                .extensionsFilter(".opml",".xml") //选择的文件类型
                .tag("optional-identifier")
                .goUpLabel("上一级")
                .show((FeedManageActivity)activity);


    } else {
        //没有权限 1. 申请权限
        EasyPermissions.requestPermissions(
                new PermissionRequest.Builder(activity, RQUEST_STORAGE_READ, perms)
                        .setRationale("必须读存储器才能解析OPML文件")
                        .setPositiveButtonText("确定")
                        .setNegativeButtonText("取消")
                        .build());
    }


}
 
Example #2
Source File: OPMLReadHelper_backup.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
public void run(){
    String[] perms = {Manifest.permission.READ_EXTERNAL_STORAGE};
    if (EasyPermissions.hasPermissions(activity, perms)) {
        //有权限
        new FileChooserDialog.Builder(activity)
                .initialPath(GlobalConfig.appDirPath)  //初始显示了目录
                .extensionsFilter(".opml",".xml") //选择的文件类型
                .tag("optional-identifier")
                .goUpLabel("上一级")
                .show((FeedManageActivity)activity);


    } else {
        //没有权限 1. 申请权限
        EasyPermissions.requestPermissions(
                new PermissionRequest.Builder(activity, RQUEST_STORAGE_READ, perms)
                        .setRationale("必须读存储器才能解析OPML文件")
                        .setPositiveButtonText("确定")
                        .setNegativeButtonText("取消")
                        .build());
    }


}
 
Example #3
Source File: OPMLReadHelper.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
public void run(){
    String[] perms = {Manifest.permission.READ_EXTERNAL_STORAGE};
    if (EasyPermissions.hasPermissions(activity, perms)) {
        //有权限
        new FileChooserDialog.Builder(activity)
                .initialPath(GlobalConfig.appDirPath)  //初始显示了目录
                .extensionsFilter(".opml",".xml") //选择的文件类型
                .tag("optional-identifier")
                .goUpLabel("上一级")
                .show((FeedManageActivity)activity);


    } else {
        //没有权限 1. 申请权限
        EasyPermissions.requestPermissions(
                new PermissionRequest.Builder(activity, RQUEST_STORAGE_READ, perms)
                        .setRationale("必须读存储器才能解析OPML文件")
                        .setPositiveButtonText("确定")
                        .setNegativeButtonText("取消")
                        .build());
    }


}
 
Example #4
Source File: OPMLReadHelper_backup.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
public void run(){
    String[] perms = {Manifest.permission.READ_EXTERNAL_STORAGE};
    if (EasyPermissions.hasPermissions(activity, perms)) {
        //有权限
        new FileChooserDialog.Builder(activity)
                .initialPath(GlobalConfig.appDirPath)  //初始显示了目录
                .extensionsFilter(".opml",".xml") //选择的文件类型
                .tag("optional-identifier")
                .goUpLabel("上一级")
                .show((FeedManageActivity)activity);


    } else {
        //没有权限 1. 申请权限
        EasyPermissions.requestPermissions(
                new PermissionRequest.Builder(activity, RQUEST_STORAGE_READ, perms)
                        .setRationale("必须读存储器才能解析OPML文件")
                        .setPositiveButtonText("确定")
                        .setNegativeButtonText("取消")
                        .build());
    }


}
 
Example #5
Source File: MainActivity.java    From TwistyTimer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Handles the call-back from a file chooser dialog when a file is selected. This is used for
 * communication between the {@code FileChooserDialog} and the export/import fragments. The
 * originating fragment that opened the file chooser dialog should set the "tag" of the file
 * chooser dialog to the value of the fragment tag that this activity uses to identify that
 * originating fragment. This activity will then forward this notification to that fragment,
 * which is expected to implement this same interface method.
 *
 * @param dialog
 *     The file chooser dialog that has reported the file selection.
 * @param file
 *     The file that was chosen.
 */
@Override
public void onFileSelection(@NonNull FileChooserDialog dialog, @NonNull File file) {
    // This "relay" scheme ensures that this activity is not embroiled in the gory details of
    // what the "destinationFrag" wanted with the file.
    final Fragment destinationFrag = fragmentManager.findFragmentByTag(FRAG_TAG_EXIM_DIALOG);

    if (destinationFrag instanceof FileChooserDialog.FileCallback) {
        ((FileChooserDialog.FileCallback) destinationFrag).onFileSelection(dialog, file);
    } else {
        // This is not expected unless there is a bug to be fixed.
        Log.e(TAG, "onFileSelection(): Unknown or incompatible fragment: " + destinationFrag.getTag());
    }
}
 
Example #6
Source File: ExportImportDialog.java    From TwistyTimer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Handles the selection of a file when solve times are being imported. If the "external" file
 * format is chosen, the user must be further prompted to select the puzzle type and category
 * to assign to the imported solve times. If the chosen file does not end with the expected
 * file extension
 *
 * @param dialog The file chooser dialog that reported the selection.
 * @param file   The file that was chosen.
 */
@Override
public void onFileSelection(@NonNull FileChooserDialog dialog, @NonNull File file) {
    if (ExportImportUtils.isFileExtensionOK(file)) {
        mImportFile = file;

        if (mFileFormat == EXIM_FORMAT_EXTERNAL) {
            // Need to get the puzzle type and category before importing the data. There will
            // be a call-back to "onPuzzleSelected" before returning to the activity.
            PuzzleChooserDialog.newInstance(
                    R.string.action_import, ExportImportDialog.this.getTag())
                    .show(getActivity().getSupportFragmentManager(), null);
        } else {
            // Importing from a back-up file. There is no need to know the puzzle type and
            // category, as those are in the file. Hand back to the activity to do the import.
            getExImActivity().onImportSolveTimes(mImportFile, mFileFormat, null, null);
            dismiss();
        }
    } else {
        // TODO: ADD HELP
        ThemeUtils.roundAndShowDialog(mContext, new MaterialDialog.Builder(getActivity())
            .title(R.string.file_selection_error_title)
            .content(R.string.file_selection_error_content, ".txt")
            .positiveText(R.string.action_ok)
            .build());
        dismiss();
    }
}
 
Example #7
Source File: ImportSpreadsheetDialog.java    From call_manage with MIT License 5 votes vote down vote up
/**
 * Shows a file chooser for the excel file
 */
private void showFileChooser() {
    if (!checkPermissionsGranted(getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE)) {
        askForPermissions(getActivity(), new String[]{Manifest.permission.READ_EXTERNAL_STORAGE});
        return;
    }

    new FileChooserDialog.Builder(getFragmentManager())
            .onFileSelected(this)
            .extensionsFilter(".xls")
            .goUpLabel("...")
            .show(new FileChooserDialog());
}
 
Example #8
Source File: FeedManageActivity.java    From Focus with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onFileSelection(@NonNull FileChooserDialog dialog, @NonNull File file) {
    //选择了某个文件
    opmlReadHelper.add(file.getAbsolutePath());
}
 
Example #9
Source File: FeedManageActivity.java    From Focus with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onFileSelection(@NonNull FileChooserDialog dialog, @NonNull File file) {
    //选择了某个文件
    opmlReadHelper.add(file.getAbsolutePath());
}
 
Example #10
Source File: ImportSpreadsheetDialog.java    From call_manage with MIT License 4 votes vote down vote up
@Override
public void onFileSelection(FileChooserDialog dialog, File file) {
    mEditPath.setText(file.getPath());
}
 
Example #11
Source File: ExportImportDialog.java    From TwistyTimer with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onClick(View view) {
    // NOTE: The call-backs from the "FileChooserDialog" and "PuzzleChooserDialog"
    //
    switch (view.getId()) {
        case R.id.export_backup:
            // All puzzle types and categories are exported to a single back-up file.
            // There is no need to identify the export file or the puzzle type/category.
            // Just invoke the activity and dismiss this dialog.
            getExImActivity().onExportSolveTimes(EXIM_FORMAT_BACKUP, null, null);
            dismiss();
            break;

        case R.id.export_external:
            mFileFormat = EXIM_FORMAT_EXTERNAL;
            // Select the single puzzle type and category that will be exported. When the
            // call-back from this puzzle chooser is received ("onPuzzleTypeSelected"),
            // this dialog will exit and hand control back to the activity to perform the
            // export. The call-back uses "getTag()" to tell the chooser to tell the
            // activity that the chosen puzzle type/category should be relayed back to this
            // dialog fragment.
            PuzzleChooserDialog.newInstance(
                    R.string.action_export, ExportImportDialog.this.getTag())
                    .show(getActivity().getSupportFragmentManager(), null);
            break;

        case R.id.import_backup:
            mFileFormat = EXIM_FORMAT_BACKUP;
            // Select the file to import. When the call-back from this file chooser is
            // received ("onFileSelection"), this dialog will exit and hand control back
            // to the activity to perform the export. The call-back uses "getTag()" to tell
            // the chooser to tell the activity that the chosen puzzle type/category should
            // be relayed back to this dialog fragment.
            new FileChooserDialog.Builder(getExImActivity())
                    //.chooseButton(R.string.action_choose)
                    .tag(FRAG_TAG_EXIM_FILECHOOSER)
                    .extensionsFilter(".txt")
                    .build().show(getFragmentManager());
            break;

        case R.id.import_external:
            // Show a dialog that explains the required text format, then, when that is
            // closed, select the file to import. When the call-back from this file chooser
            // is received ("onFileSelection"), this dialog will check that the file name
            // is valid. If valid, the puzzle chooser will be shown.  When the call-back
            // from that puzzle chooser is received ("onPuzzleTypeSelected"), this dialog
            // will exit and hand control back to the activity to perform the import.
            mFileFormat = EXIM_FORMAT_EXTERNAL;
            ThemeUtils.roundAndShowDialog(mContext, new MaterialDialog.Builder(mContext)
                    .title(R.string.import_external_title)
                    .content(R.string.import_external_content_first)
                    .positiveText(R.string.action_ok)
                    .onPositive((dialog, which) -> new FileChooserDialog.Builder(getExImActivity())
                            .tag(FRAG_TAG_EXIM_FILECHOOSER)
                            .extensionsFilter(".txt")
                            .build().show(getFragmentManager()))
                    .build());
            break;

        case R.id.export_button:
            AnimUtils.toggleContentVisibility(exportBackup, exportExternal);
            break;

        case R.id.import_button:
            AnimUtils.toggleContentVisibility(importBackup, importExternal);
            break;

        //case R.id.help_button:
        //    break;
    }
}
 
Example #12
Source File: MainActivity.java    From TwistyTimer with GNU General Public License v3.0 2 votes vote down vote up
@Override
public void onFileChooserDismissed(@NonNull FileChooserDialog dialog) {

}
 
Example #13
Source File: ExportImportDialog.java    From TwistyTimer with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Gets the activity reference type cast to support the required interfaces and base classes
 * for export/import operations.
 *
 * @return The attached activity, or {@code null} if no activity is attached.
 */
private <A extends AppCompatActivity & FileChooserDialog.FileCallback & ExportImportCallbacks>
A getExImActivity() {
    //noinspection unchecked
    return (A) getActivity();
}
 
Example #14
Source File: ExportImportDialog.java    From TwistyTimer with GNU General Public License v3.0 2 votes vote down vote up
@Override
public void onFileChooserDismissed(@NonNull FileChooserDialog dialog) {

}
 
Example #15
Source File: ImportSpreadsheetDialog.java    From call_manage with MIT License 2 votes vote down vote up
@Override
public void onFileChooserDismissed(FileChooserDialog dialog) {

}
 
Example #16
Source File: FeedManageActivity.java    From Focus with GNU General Public License v3.0 2 votes vote down vote up
@Override
public void onFileChooserDismissed(@NonNull FileChooserDialog dialog) {

}
 
Example #17
Source File: FeedManageActivity.java    From Focus with GNU General Public License v3.0 2 votes vote down vote up
@Override
public void onFileChooserDismissed(@NonNull FileChooserDialog dialog) {

}