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;
}
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);
}
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;
}
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;
}
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();
}
Aggregations