Search in sources :

Example 6 with AlertDialog

use of androidx.appcompat.app.AlertDialog in project android by nextcloud.

the class LocalStoragePathPickerDialogFragment method onStart.

@Override
public void onStart() {
    super.onStart();
    AlertDialog alertDialog = (AlertDialog) getDialog();
    if (alertDialog != null) {
        ThemeButtonUtils.themeBorderlessButton(alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE));
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog)

Example 7 with AlertDialog

use of androidx.appcompat.app.AlertDialog in project android by nextcloud.

the class SetupEncryptionDialogFragment method createDialog.

@NonNull
private Dialog createDialog(View v) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(v).setPositiveButton(R.string.common_ok, null).setNeutralButton(R.string.common_cancel, null).setTitle(R.string.end_to_end_encryption_title);
    Dialog dialog = builder.create();
    dialog.setCanceledOnTouchOutside(false);
    dialog.setOnShowListener(new DialogInterface.OnShowListener() {

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

                @Override
                public void onClick(View view) {
                    switch(keyResult) {
                        case KEY_CREATED:
                            Log_OC.d(TAG, "New keys generated and stored.");
                            dialog.dismiss();
                            Intent intentCreated = new Intent();
                            intentCreated.putExtra(SUCCESS, true);
                            intentCreated.putExtra(ARG_POSITION, getArguments().getInt(ARG_POSITION));
                            getTargetFragment().onActivityResult(getTargetRequestCode(), SETUP_ENCRYPTION_RESULT_CODE, intentCreated);
                            break;
                        case KEY_EXISTING_USED:
                            Log_OC.d(TAG, "Decrypt private key");
                            textView.setText(R.string.end_to_end_encryption_decrypting);
                            try {
                                String privateKey = task.get();
                                String mnemonicUnchanged = passwordField.getText().toString();
                                String mnemonic = passwordField.getText().toString().replaceAll("\\s", "").toLowerCase(Locale.ROOT);
                                String decryptedPrivateKey = EncryptionUtils.decryptPrivateKey(privateKey, mnemonic);
                                arbitraryDataProvider.storeOrUpdateKeyValue(user.getAccountName(), EncryptionUtils.PRIVATE_KEY, decryptedPrivateKey);
                                dialog.dismiss();
                                Log_OC.d(TAG, "Private key successfully decrypted and stored");
                                arbitraryDataProvider.storeOrUpdateKeyValue(user.getAccountName(), EncryptionUtils.MNEMONIC, mnemonicUnchanged);
                                // check if private key and public key match
                                String publicKey = arbitraryDataProvider.getValue(user.getAccountName(), EncryptionUtils.PUBLIC_KEY);
                                byte[] key1 = generateKey();
                                String base64encodedKey = encodeBytesToBase64String(key1);
                                String encryptedString = EncryptionUtils.encryptStringAsymmetric(base64encodedKey, publicKey);
                                String decryptedString = decryptStringAsymmetric(encryptedString, decryptedPrivateKey);
                                byte[] key2 = decodeStringToBase64Bytes(decryptedString);
                                if (!Arrays.equals(key1, key2)) {
                                    throw new Exception("Keys do not match");
                                }
                                Intent intentExisting = new Intent();
                                intentExisting.putExtra(SUCCESS, true);
                                intentExisting.putExtra(ARG_POSITION, getArguments().getInt(ARG_POSITION));
                                getTargetFragment().onActivityResult(getTargetRequestCode(), SETUP_ENCRYPTION_RESULT_CODE, intentExisting);
                            } catch (Exception e) {
                                textView.setText(R.string.end_to_end_encryption_wrong_password);
                                Log_OC.d(TAG, "Error while decrypting private key: " + e.getMessage());
                            }
                            break;
                        case KEY_GENERATE:
                            passphraseTextView.setVisibility(View.GONE);
                            positiveButton.setVisibility(View.GONE);
                            neutralButton.setVisibility(View.GONE);
                            getDialog().setTitle(R.string.end_to_end_encryption_storing_keys);
                            GenerateNewKeysAsyncTask newKeysTask = new GenerateNewKeysAsyncTask();
                            newKeysTask.execute();
                            break;
                        default:
                            dialog.dismiss();
                            break;
                    }
                }
            });
        }
    });
    return dialog;
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) EncryptionUtils.encodeBytesToBase64String(com.owncloud.android.utils.EncryptionUtils.encodeBytesToBase64String) View(android.view.View) TextView(android.widget.TextView) IOException(java.io.IOException) Button(android.widget.Button) AlertDialog(androidx.appcompat.app.AlertDialog) Dialog(android.app.Dialog) NonNull(androidx.annotation.NonNull)

Example 8 with AlertDialog

use of androidx.appcompat.app.AlertDialog in project android by nextcloud.

the class AccountRemovalConfirmationDialog method onStart.

@Override
public void onStart() {
    super.onStart();
    AlertDialog alertDialog = (AlertDialog) getDialog();
    ThemeButtonUtils.themeBorderlessButton(alertDialog.getButton(AlertDialog.BUTTON_POSITIVE), alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL));
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog)

Example 9 with AlertDialog

use of androidx.appcompat.app.AlertDialog in project android by nextcloud.

the class ChooseTemplateDialogFragment method onStart.

@Override
public void onStart() {
    super.onStart();
    AlertDialog alertDialog = (AlertDialog) getDialog();
    positiveButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
    ThemeButtonUtils.themeBorderlessButton(positiveButton, alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL));
    positiveButton.setOnClickListener(this);
    positiveButton.setEnabled(false);
    checkEnablingCreateButton();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog)

Example 10 with AlertDialog

use of androidx.appcompat.app.AlertDialog in project android by nextcloud.

the class ShareLinkToDialog method createSelector.

private AlertDialog createSelector(final boolean sendAction) {
    int titleId;
    if (sendAction) {
        titleId = R.string.activity_chooser_send_file_title;
    } else {
        titleId = R.string.activity_chooser_title;
    }
    return new AlertDialog.Builder(getActivity()).setTitle(titleId).setAdapter(mAdapter, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // Add the information of the chosen activity to the intent to send
            ResolveInfo chosen = mAdapter.getItem(which);
            ActivityInfo actInfo = chosen.activityInfo;
            ComponentName name = new ComponentName(actInfo.applicationInfo.packageName, actInfo.name);
            mIntent.setComponent(name);
            // Send the file
            getActivity().startActivity(mIntent);
        }
    }).create();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) ResolveInfo(android.content.pm.ResolveInfo) ActivityInfo(android.content.pm.ActivityInfo) DialogInterface(android.content.DialogInterface) ComponentName(android.content.ComponentName)

Aggregations

AlertDialog (androidx.appcompat.app.AlertDialog)261 Test (org.junit.Test)89 View (android.view.View)49 DialogInterface (android.content.DialogInterface)42 TextView (android.widget.TextView)40 Button (android.widget.Button)39 Intent (android.content.Intent)30 ShadowAlertDialogCompat (com.android.settings.testutils.shadow.ShadowAlertDialogCompat)30 NonNull (androidx.annotation.NonNull)28 Context (android.content.Context)26 Bundle (android.os.Bundle)20 EditText (android.widget.EditText)18 MaterialAlertDialogBuilder (com.google.android.material.dialog.MaterialAlertDialogBuilder)18 SuppressLint (android.annotation.SuppressLint)17 ArrayList (java.util.ArrayList)17 List (java.util.List)12 Activity (android.app.Activity)11 Uri (android.net.Uri)11 LayoutInflater (android.view.LayoutInflater)11 ListView (android.widget.ListView)10