Java Code Examples for com.afollestad.materialdialogs.MaterialDialog#getActionButton()

The following examples show how to use com.afollestad.materialdialogs.MaterialDialog#getActionButton() . 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: FingerprintDialog.java    From fingerlock with MIT License 6 votes vote down vote up
public void notifyPasswordValidation(boolean valid) {
    final MaterialDialog dialog = (MaterialDialog) getDialog();
    final View positive = dialog.getActionButton(DialogAction.POSITIVE);
    final View negative = dialog.getActionButton(DialogAction.NEGATIVE);
    toggleButtonsEnabled(true);

    if (valid) {
        if (mStage == Stage.KEY_INVALIDATED &&
                mUseFingerprintFutureCheckBox.isChecked()) {
            // Re-create the key so that fingerprints including new ones are validated.
            mFingerLock.recreateKey(this);
            mStage = Stage.FINGERPRINT;
        }
        mPassword.setText("");
        mCallback.onFingerprintDialogAuthenticated();
        dismiss();
    } else {
        mPasswordDescriptionTextView.setText(R.string.invalid_password);
        final int red = ContextCompat.getColor(getActivity(), R.color.material_red_500);
        MDTintHelper.setTint(mPassword, red);
        ((TextView) positive).setTextColor(red);
        ((TextView) negative).setTextColor(red);
    }
}
 
Example 2
Source File: RuleListFragment.java    From SmsCode with GNU General Public License v3.0 5 votes vote down vote up
private void attemptExportRuleList() {
    if (mRuleAdapter.getItemCount() == 0) {
        SnackbarHelper.makeLong(mRecyclerView, R.string.rule_list_empty_snack_prompt).show();
        return;
    }

    final String defaultFilename = BackupManager.getDefaultBackupFilename();
    String hint = getString(R.string.backup_file_name);
    String content = getString(R.string.backup_file_dir, BackupManager.getBackupDir().getAbsolutePath());
    final MaterialDialog exportFilenameDialog = new MaterialDialog.Builder(mActivity)
            .title(R.string.backup_file_name)
            .content(content)
            .input(hint, defaultFilename, (dialog, input) -> {
                File file = new File(BackupManager.getBackupDir(), input.toString());
                new ExportAsyncTaskBelowQ(mActivity, RuleListFragment.this, mRuleAdapter, file, getString(R.string.exporting)).execute();
            })
            .inputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE)
            .negativeText(R.string.cancel)
            .build();

    final EditText editText = exportFilenameDialog.getInputEditText();
    if (editText != null) {
        exportFilenameDialog.setOnShowListener(dialog -> {
            int stop = defaultFilename.length() - BackupManager.getBackupFileExtension().length();
            editText.setSelection(0, stop);
        });
        final MDButton positiveBtn =
                exportFilenameDialog.getActionButton(DialogAction.POSITIVE);
        editText.addTextChangedListener(new TextWatcherAdapter() {
            @Override
            public void afterTextChanged(Editable s) {
                positiveBtn.setEnabled(Utils.isValidFilename(s.toString()));
            }
        });
    }
    exportFilenameDialog.show();
}
 
Example 3
Source File: RuleListFragment.java    From XposedSmsCode with GNU General Public License v3.0 4 votes vote down vote up
private void attemptExportRuleList() {
    if (mRuleAdapter.getItemCount() == 0) {
        SnackbarHelper.makeLong(mRecyclerView, R.string.rule_list_empty_snack_prompt).show();
        return;
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
        // Android Q 及以后,使用 SAF (Storage Access Framework) 来导入导出文档文件
        Intent exportIntent = BackupManager.getExportRuleListSAFIntent();
        try {
            startActivityForResult(exportIntent, REQUEST_CODE_EXPORT_RULES);
        } catch (Exception e) {
            // 防止某些 Rom 将 DocumentUI 阉割掉
            SnackbarHelper.makeLong(mRecyclerView, R.string.documents_ui_not_found).show();
        }
    } else {
        // 考虑到在低版本的 Android 系统中,不少 Rom 将 DocumentUI 阉割掉了,无法使用 SAF
        // Android P 及以前,使用原有方式进行文件导入导出
        String perm = Manifest.permission.WRITE_EXTERNAL_STORAGE;
        if (ContextCompat.checkSelfPermission(mActivity, perm) != PackageManager.PERMISSION_GRANTED) {
            showNoPermissionInfo();
            return;
        }

        final String defaultFilename = BackupManager.getDefaultBackupFilename();
        String hint = getString(R.string.backup_file_name);
        String content = getString(R.string.backup_file_dir, BackupManager.getBackupDir().getAbsolutePath());
        final MaterialDialog exportFilenameDialog = new MaterialDialog.Builder(mActivity)
                .title(R.string.backup_file_name)
                .content(content)
                .input(hint, defaultFilename, (dialog, input) -> {
                    File file = new File(BackupManager.getBackupDir(), input.toString());
                    mPresenter.exportRulesBelowQ(mRuleAdapter.getRuleList(), file, getString(R.string.exporting));
                })
                .inputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE)
                .negativeText(R.string.cancel)
                .build();

        final EditText editText = exportFilenameDialog.getInputEditText();
        if (editText != null) {
            exportFilenameDialog.setOnShowListener(dialog -> {
                int stop = defaultFilename.length() - BackupManager.getBackupFileExtension().length();
                editText.setSelection(0, stop);
            });

            final MDButton positiveBtn = exportFilenameDialog.getActionButton(DialogAction.POSITIVE);

            editText.addTextChangedListener(new TextWatcherAdapter() {
                @Override
                public void afterTextChanged(Editable s) {
                    positiveBtn.setEnabled(Utils.isValidFilename(s.toString()));
                }
            });
        }
        exportFilenameDialog.show();
    }
}