Search in sources :

Example 1 with KeyFileHelper

use of com.keepassdroid.fileselect.KeyFileHelper in project KeePassDX by Kunzisoft.

the class PasswordActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    prefs = PreferenceManager.getDefaultSharedPreferences(this);
    prefsNoBackup = PreferencesUtil.getNoBackupSharedPreferences(getApplicationContext());
    mRememberKeyfile = prefs.getBoolean(getString(R.string.keyfile_key), getResources().getBoolean(R.bool.keyfile_default));
    setContentView(R.layout.password);
    Toolbar toolbar = findViewById(R.id.toolbar);
    toolbar.setTitle(getString(R.string.app_name));
    setSupportActionBar(toolbar);
    assert getSupportActionBar() != null;
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    confirmButtonView = findViewById(R.id.pass_ok);
    filenameView = findViewById(R.id.filename);
    passwordView = findViewById(R.id.password);
    keyFileView = findViewById(R.id.pass_keyfile);
    checkboxPasswordView = findViewById(R.id.password_checkbox);
    checkboxKeyfileView = findViewById(R.id.keyfile_checkox);
    checkboxDefaultDatabaseView = findViewById(R.id.default_database);
    View browseView = findViewById(R.id.browse_button);
    keyFileHelper = new KeyFileHelper(PasswordActivity.this);
    browseView.setOnClickListener(keyFileHelper.getOpenFileOnClickViewListener());
    passwordView.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (!editable.toString().isEmpty() && !checkboxPasswordView.isChecked())
                checkboxPasswordView.setChecked(true);
        }
    });
    keyFileView.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (!editable.toString().isEmpty() && !checkboxKeyfileView.isChecked())
                checkboxKeyfileView.setChecked(true);
        }
    });
    defaultCheckChange = new DefaultCheckChange();
    validateButtonViewClickListener = new ValidateButtonViewClickListener();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        fingerprintContainerView = findViewById(R.id.fingerprint_container);
        fingerprintTextView = findViewById(R.id.fingerprint_label);
        initForFingerprint();
        fingerPrintAnimatedVector = new FingerPrintAnimatedVector(this, findViewById(R.id.fingerprint_image));
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        autofillHelper = new AutofillHelper();
        autofillHelper.retrieveAssistStructure(getIntent());
    }
}
Also used : KeyFileHelper(com.keepassdroid.fileselect.KeyFileHelper) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) FingerPrintAnimatedVector(com.keepassdroid.fingerprint.FingerPrintAnimatedVector) View(android.view.View) TextView(android.widget.TextView) AutofillHelper(com.keepassdroid.autofill.AutofillHelper) Toolbar(android.support.v7.widget.Toolbar)

Example 2 with KeyFileHelper

use of com.keepassdroid.fileselect.KeyFileHelper in project KeePassDX by Kunzisoft.

the class AssignMasterKeyDialogFragment method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = getActivity().getLayoutInflater();
    rootView = inflater.inflate(R.layout.set_password, null);
    builder.setView(rootView).setTitle(R.string.assign_master_key).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int id) {
        }
    }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int id) {
        }
    });
    passwordCheckBox = (CompoundButton) rootView.findViewById(R.id.password_checkbox);
    passView = (TextView) rootView.findViewById(R.id.pass_password);
    passView.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            passwordCheckBox.setChecked(true);
        }
    });
    passConfView = (TextView) rootView.findViewById(R.id.pass_conf_password);
    keyfileCheckBox = (CompoundButton) rootView.findViewById(R.id.keyfile_checkox);
    keyfileView = (TextView) rootView.findViewById(R.id.pass_keyfile);
    keyfileView.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            keyfileCheckBox.setChecked(true);
        }
    });
    keyFileHelper = new KeyFileHelper(this);
    rootView.findViewById(R.id.browse_button).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            keyFileHelper.getOpenFileOnClickViewListener().onClick(view);
        }
    });
    AlertDialog dialog = builder.create();
    dialog.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(final DialogInterface dialog) {
            Button positiveButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE);
            positiveButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(final View v) {
                    masterPassword = "";
                    mKeyfile = null;
                    boolean error = verifyPassword() || verifyFile();
                    if (!passwordCheckBox.isChecked() && !keyfileCheckBox.isChecked()) {
                        error = true;
                        showNoKeyConfirmationDialog();
                    }
                    if (!error) {
                        mListener.onAssignKeyDialogPositiveClick(passwordCheckBox.isChecked(), masterPassword, keyfileCheckBox.isChecked(), mKeyfile);
                        dismiss();
                    }
                }
            });
            Button negativeButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_NEGATIVE);
            negativeButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(final View v) {
                    mListener.onAssignKeyDialogNegativeClick(passwordCheckBox.isChecked(), masterPassword, keyfileCheckBox.isChecked(), mKeyfile);
                    dismiss();
                }
            });
        }
    });
    return dialog;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) KeyFileHelper(com.keepassdroid.fileselect.KeyFileHelper) DialogInterface(android.content.DialogInterface) TextView(android.widget.TextView) View(android.view.View) CompoundButton(android.widget.CompoundButton) Button(android.widget.Button) LayoutInflater(android.view.LayoutInflater) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) NonNull(android.support.annotation.NonNull)

Aggregations

Editable (android.text.Editable)2 TextWatcher (android.text.TextWatcher)2 View (android.view.View)2 TextView (android.widget.TextView)2 KeyFileHelper (com.keepassdroid.fileselect.KeyFileHelper)2 DialogInterface (android.content.DialogInterface)1 NonNull (android.support.annotation.NonNull)1 AlertDialog (android.support.v7.app.AlertDialog)1 Toolbar (android.support.v7.widget.Toolbar)1 LayoutInflater (android.view.LayoutInflater)1 Button (android.widget.Button)1 CompoundButton (android.widget.CompoundButton)1 AutofillHelper (com.keepassdroid.autofill.AutofillHelper)1 FingerPrintAnimatedVector (com.keepassdroid.fingerprint.FingerPrintAnimatedVector)1