Search in sources :

Example 6 with NonNull

use of androidx.annotation.NonNull 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 7 with NonNull

use of androidx.annotation.NonNull in project android by nextcloud.

the class SetupEncryptionDialogFragment method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    int primaryColor = ThemeColorUtils.primaryColor(getContext());
    user = getArguments().getParcelable(ARG_USER);
    arbitraryDataProvider = new ArbitraryDataProvider(getContext().getContentResolver());
    // Inflate the layout for the dialog
    LayoutInflater inflater = getActivity().getLayoutInflater();
    // Setup layout
    View v = inflater.inflate(R.layout.setup_encryption_dialog, null);
    textView = v.findViewById(R.id.encryption_status);
    passphraseTextView = v.findViewById(R.id.encryption_passphrase);
    passwordField = v.findViewById(R.id.encryption_passwordInput);
    passwordField.getBackground().setColorFilter(primaryColor, PorterDuff.Mode.SRC_ATOP);
    Drawable wrappedDrawable = DrawableCompat.wrap(passwordField.getBackground());
    DrawableCompat.setTint(wrappedDrawable, primaryColor);
    passwordField.setBackgroundDrawable(wrappedDrawable);
    return createDialog(v);
}
Also used : LayoutInflater(android.view.LayoutInflater) Drawable(android.graphics.drawable.Drawable) ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider) View(android.view.View) TextView(android.widget.TextView) NonNull(androidx.annotation.NonNull)

Example 8 with NonNull

use of androidx.annotation.NonNull in project android by nextcloud.

the class PreviewImagePagerAdapter method getItem.

@NonNull
public Fragment getItem(int i) {
    OCFile file = getFileAt(i);
    Fragment fragment;
    if (file == null) {
        fragment = PreviewImageErrorFragment.newInstance();
    } else if (file.isDown()) {
        fragment = PreviewImageFragment.newInstance(file, mObsoletePositions.contains(i), false);
    } else {
        if (mDownloadErrors.remove(i)) {
            fragment = FileDownloadFragment.newInstance(file, user, true);
            ((FileDownloadFragment) fragment).setError(true);
        } else {
            if (file.isEncrypted()) {
                fragment = FileDownloadFragment.newInstance(file, user, mObsoletePositions.contains(i));
            } else {
                fragment = PreviewImageFragment.newInstance(file, mObsoletePositions.contains(i), true);
            }
        }
    }
    mObsoletePositions.remove(i);
    return fragment;
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) FileFragment(com.owncloud.android.ui.fragment.FileFragment) Fragment(androidx.fragment.app.Fragment) NonNull(androidx.annotation.NonNull)

Example 9 with NonNull

use of androidx.annotation.NonNull in project android by nextcloud.

the class ChooseTemplateDialogFragment method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Bundle arguments = getArguments();
    if (arguments == null) {
        throw new IllegalArgumentException("Arguments may not be null");
    }
    Activity activity = getActivity();
    if (activity == null) {
        throw new IllegalArgumentException("Activity may not be null");
    }
    parentFolder = arguments.getParcelable(ARG_PARENT_FOLDER);
    creator = arguments.getParcelable(ARG_CREATOR);
    title = arguments.getString(ARG_HEADLINE, getString(R.string.select_template));
    if (savedInstanceState == null) {
        title = arguments.getString(ARG_HEADLINE);
    } else {
        title = savedInstanceState.getString(ARG_HEADLINE);
    }
    // Inflate the layout for the dialog
    LayoutInflater inflater = requireActivity().getLayoutInflater();
    binding = ChooseTemplateBinding.inflate(inflater, null, false);
    View view = binding.getRoot();
    binding.filename.requestFocus();
    ThemeTextInputUtils.colorTextInput(binding.filenameContainer, binding.filename, ThemeColorUtils.primaryColor(getContext()));
    binding.filename.setOnKeyListener((v, keyCode, event) -> {
        checkEnablingCreateButton();
        return false;
    });
    binding.filename.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        // generated method stub
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        // generated method stub
        }

        @Override
        public void afterTextChanged(Editable s) {
            checkEnablingCreateButton();
        }
    });
    try {
        User user = currentAccount.getUser();
        new FetchTemplateTask(this, clientFactory, user, creator).execute();
    } catch (Exception e) {
        Log_OC.e(TAG, "Loading stream url not possible: " + e);
    }
    binding.list.setHasFixedSize(true);
    binding.list.setLayoutManager(new GridLayoutManager(activity, 2));
    adapter = new TemplateAdapter(creator.getMimetype(), this, getContext(), currentAccount, clientFactory);
    binding.list.setAdapter(adapter);
    // Build the dialog
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setView(view).setPositiveButton(R.string.create, null).setNeutralButton(R.string.common_cancel, null).setTitle(title);
    Dialog dialog = builder.create();
    Window window = dialog.getWindow();
    if (window != null) {
        window.setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    }
    return dialog;
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Window(android.view.Window) User(com.nextcloud.client.account.User) Bundle(android.os.Bundle) Activity(android.app.Activity) View(android.view.View) ExternalSiteWebView(com.owncloud.android.ui.activity.ExternalSiteWebView) TextEditorWebView(com.owncloud.android.ui.activity.TextEditorWebView) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) AlertDialog(androidx.appcompat.app.AlertDialog) Dialog(android.app.Dialog) LayoutInflater(android.view.LayoutInflater) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TemplateAdapter(com.owncloud.android.ui.adapter.TemplateAdapter) NonNull(androidx.annotation.NonNull)

Example 10 with NonNull

use of androidx.annotation.NonNull in project android by nextcloud.

the class ConflictsResolveDialog method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Inflate the layout for the dialog
    binding = ConflictResolveDialogBinding.inflate(requireActivity().getLayoutInflater());
    ThemeCheckableUtils.tintCheckbox(ThemeColorUtils.primaryColor(getContext()), binding.newCheckbox, binding.existingCheckbox);
    // Build the dialog
    AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity());
    builder.setView(binding.getRoot()).setPositiveButton(R.string.common_ok, (dialog, which) -> {
        if (listener != null) {
            if (binding.newCheckbox.isChecked() && binding.existingCheckbox.isChecked()) {
                listener.conflictDecisionMade(Decision.KEEP_BOTH);
            } else if (binding.newCheckbox.isChecked()) {
                listener.conflictDecisionMade(Decision.KEEP_LOCAL);
            } else if (binding.existingCheckbox.isChecked()) {
                listener.conflictDecisionMade(Decision.KEEP_SERVER);
            }
        // else do nothing
        }
    }).setNeutralButton(R.string.common_cancel, (dialog, which) -> {
        if (listener != null) {
            listener.conflictDecisionMade(Decision.CANCEL);
        }
    }).setTitle(String.format(getString(R.string.conflict_file_headline), existingFile.getFileName()));
    File parentFile = new File(existingFile.getRemotePath()).getParentFile();
    if (parentFile != null) {
        binding.in.setText(String.format(getString(R.string.in_folder), parentFile.getAbsolutePath()));
    } else {
        binding.in.setVisibility(View.GONE);
    }
    // set info for new file
    binding.newSize.setText(DisplayUtils.bytesToHumanReadable(newFile.length()));
    binding.newTimestamp.setText(DisplayUtils.getRelativeTimestamp(getContext(), newFile.lastModified()));
    binding.newThumbnail.setTag(newFile.hashCode());
    LocalFileListAdapter.setThumbnail(newFile, binding.newThumbnail, getContext());
    // set info for existing file
    binding.existingSize.setText(DisplayUtils.bytesToHumanReadable(existingFile.getFileLength()));
    binding.existingTimestamp.setText(DisplayUtils.getRelativeTimestamp(getContext(), existingFile.getModificationTimestamp()));
    binding.existingThumbnail.setTag(existingFile.getFileId());
    OCFileListAdapter.setThumbnail(existingFile, binding.existingThumbnail, user, new FileDataStorageManager(user, requireContext().getContentResolver()), asyncTasks, false, getContext());
    View.OnClickListener checkBoxClickListener = v -> {
        positiveButton.setEnabled(binding.newCheckbox.isChecked() || binding.existingCheckbox.isChecked());
    };
    binding.newCheckbox.setOnClickListener(checkBoxClickListener);
    binding.existingCheckbox.setOnClickListener(checkBoxClickListener);
    binding.newFileContainer.setOnClickListener(v -> {
        binding.newCheckbox.setChecked(!binding.newCheckbox.isChecked());
        positiveButton.setEnabled(binding.newCheckbox.isChecked() || binding.existingCheckbox.isChecked());
    });
    binding.existingFileContainer.setOnClickListener(v -> {
        binding.existingCheckbox.setChecked(!binding.existingCheckbox.isChecked());
        positiveButton.setEnabled(binding.newCheckbox.isChecked() || binding.existingCheckbox.isChecked());
    });
    return builder.create();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Context(android.content.Context) User(com.nextcloud.client.account.User) ThumbnailsCacheManager(com.owncloud.android.datamodel.ThumbnailsCacheManager) Bundle(android.os.Bundle) AlertDialog(androidx.appcompat.app.AlertDialog) NonNull(androidx.annotation.NonNull) OCFile(com.owncloud.android.datamodel.OCFile) Dialog(android.app.Dialog) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) ThemeCheckableUtils(com.owncloud.android.utils.theme.ThemeCheckableUtils) ArrayList(java.util.ArrayList) LocalFileListAdapter(com.owncloud.android.ui.adapter.LocalFileListAdapter) ConflictResolveDialogBinding(com.owncloud.android.databinding.ConflictResolveDialogBinding) Toast(android.widget.Toast) OCFileListAdapter(com.owncloud.android.ui.adapter.OCFileListAdapter) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Button(android.widget.Button) DisplayUtils(com.owncloud.android.utils.DisplayUtils) DialogInterface(android.content.DialogInterface) FragmentTransaction(androidx.fragment.app.FragmentTransaction) File(java.io.File) Log_OC(com.owncloud.android.lib.common.utils.Log_OC) List(java.util.List) ThemeColorUtils(com.owncloud.android.utils.theme.ThemeColorUtils) Nullable(androidx.annotation.Nullable) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) R(com.owncloud.android.R) ThemeButtonUtils(com.owncloud.android.utils.theme.ThemeButtonUtils) DialogFragment(androidx.fragment.app.DialogFragment) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) OCFile(com.owncloud.android.datamodel.OCFile) File(java.io.File) View(android.view.View) NonNull(androidx.annotation.NonNull)

Aggregations

NonNull (androidx.annotation.NonNull)1200 View (android.view.View)192 ArrayList (java.util.ArrayList)154 Context (android.content.Context)128 Nullable (androidx.annotation.Nullable)128 TextView (android.widget.TextView)118 Intent (android.content.Intent)115 List (java.util.List)110 Recipient (org.thoughtcrime.securesms.recipients.Recipient)109 IOException (java.io.IOException)103 Bundle (android.os.Bundle)102 WorkerThread (androidx.annotation.WorkerThread)94 LayoutInflater (android.view.LayoutInflater)89 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)82 AlertDialog (androidx.appcompat.app.AlertDialog)77 Log (org.signal.core.util.logging.Log)76 Cursor (android.database.Cursor)68 ViewGroup (android.view.ViewGroup)65 LinkedList (java.util.LinkedList)64 Stream (com.annimon.stream.Stream)62