use of androidx.annotation.NonNull in project WordPress-Login-Flow-Android by wordpress-mobile.
the class LoginHttpAuthDialogFragment method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder alert = new MaterialAlertDialogBuilder(getActivity());
alert.setTitle(R.string.http_authorization_required);
if (!TextUtils.isEmpty(mMessage))
alert.setMessage(mMessage);
// noinspection InflateParams
View httpAuth = getActivity().getLayoutInflater().inflate(R.layout.login_alert_http_auth, null);
alert.setView(httpAuth);
final EditText usernameEditText = (EditText) httpAuth.findViewById(R.id.login_http_username);
final EditText passwordEditText = (EditText) httpAuth.findViewById(R.id.login_http_password);
passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
String username = EditTextUtils.getText(usernameEditText);
String password = EditTextUtils.getText(passwordEditText);
sendResult(username, password);
dismiss();
return true;
}
});
alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dismiss();
}
});
alert.setPositiveButton(R.string.next, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String username = EditTextUtils.getText(usernameEditText);
String password = EditTextUtils.getText(passwordEditText);
sendResult(username, password);
}
});
final AlertDialog alertDialog = alert.create();
// update the Next button when username edit box changes
usernameEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
updateButton(alertDialog, usernameEditText);
}
});
// update the Next button on first appearance
alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
updateButton(alertDialog, usernameEditText);
}
});
return alertDialog;
}
use of androidx.annotation.NonNull in project samourai-wallet-android by Samourai-Wallet.
the class Utils method findSuitableImageSize.
@NonNull
public static Point findSuitableImageSize(@NonNull final Parameters parameters, final int frameWidth, final int frameHeight) {
final List<Size> sizes = parameters.getSupportedPreviewSizes();
if (sizes != null && !sizes.isEmpty()) {
Collections.sort(sizes, new CameraSizeComparator());
final float frameRatio = (float) frameWidth / (float) frameHeight;
for (float distortion = MIN_DISTORTION; distortion <= MAX_DISTORTION; distortion += DISTORTION_STEP) {
for (final Size size : sizes) {
final int width = size.width;
final int height = size.height;
if (width * height >= MIN_PREVIEW_PIXELS && Math.abs(frameRatio - (float) width / (float) height) <= distortion) {
return new Point(width, height);
}
}
}
}
final Size defaultSize = parameters.getPreviewSize();
if (defaultSize == null) {
throw new CodeScannerException("Unable to configure camera preview size");
}
return new Point(defaultSize.width, defaultSize.height);
}
use of androidx.annotation.NonNull in project k-9 by k9mail.
the class PgpMessageBuilder method createOpenPgpDataSourceFromBodyPart.
@NonNull
private OpenPgpDataSource createOpenPgpDataSourceFromBodyPart(final MimeBodyPart bodyPart, final boolean writeBodyContentOnly) throws MessagingException {
return new OpenPgpDataSource() {
@Override
public void writeTo(OutputStream os) throws IOException {
try {
if (writeBodyContentOnly) {
Body body = bodyPart.getBody();
InputStream inputStream = body.getInputStream();
IOUtils.copy(inputStream, os);
} else {
bodyPart.writeTo(os);
}
} catch (MessagingException e) {
throw new IOException(e);
}
}
};
}
use of androidx.annotation.NonNull in project k-9 by k9mail.
the class PgpMessageBuilder method buildOpenPgpApiIntent.
@NonNull
private Intent buildOpenPgpApiIntent(boolean shouldSign, boolean shouldEncrypt, boolean encryptToSelfOnly, boolean isPgpInlineMode) {
Intent pgpApiIntent;
Long openPgpKeyId = cryptoStatus.getOpenPgpKeyId();
if (shouldEncrypt) {
pgpApiIntent = new Intent(shouldSign ? OpenPgpApi.ACTION_SIGN_AND_ENCRYPT : OpenPgpApi.ACTION_ENCRYPT);
long[] selfEncryptIds = { openPgpKeyId };
pgpApiIntent.putExtra(OpenPgpApi.EXTRA_KEY_IDS, selfEncryptIds);
if (!encryptToSelfOnly) {
pgpApiIntent.putExtra(OpenPgpApi.EXTRA_USER_IDS, cryptoStatus.getRecipientAddresses());
// pgpApiIntent.putExtra(OpenPgpApi.EXTRA_ENCRYPT_OPPORTUNISTIC, cryptoStatus.isEncryptionOpportunistic());
}
} else {
pgpApiIntent = new Intent(isPgpInlineMode ? OpenPgpApi.ACTION_SIGN : OpenPgpApi.ACTION_DETACHED_SIGN);
}
if (shouldSign) {
pgpApiIntent.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, openPgpKeyId);
}
pgpApiIntent.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
return pgpApiIntent;
}
use of androidx.annotation.NonNull in project k-9 by k9mail.
the class BodyTextExtractor method getBodyTextFromMessage.
/**
* Fetch the body text from a messagePart in the desired messagePart format. This method handles
* conversions between formats (html to text and vice versa) if necessary.
*/
@NonNull
public static String getBodyTextFromMessage(Part messagePart, SimpleMessageFormat format) {
Part part;
if (format == SimpleMessageFormat.HTML) {
// HTML takes precedence, then text.
part = MimeUtility.findFirstPartByMimeType(messagePart, "text/html");
if (part != null) {
Timber.d("getBodyTextFromMessage: HTML requested, HTML found.");
return getTextFromPartOrEmpty(part);
}
part = MimeUtility.findFirstPartByMimeType(messagePart, "text/plain");
if (part != null) {
Timber.d("getBodyTextFromMessage: HTML requested, text found.");
String text = getTextFromPartOrEmpty(part);
return HtmlConverter.textToHtml(text);
}
} else if (format == SimpleMessageFormat.TEXT) {
// Text takes precedence, then html.
part = MimeUtility.findFirstPartByMimeType(messagePart, "text/plain");
if (part != null) {
Timber.d("getBodyTextFromMessage: Text requested, text found.");
return getTextFromPartOrEmpty(part);
}
part = MimeUtility.findFirstPartByMimeType(messagePart, "text/html");
if (part != null) {
Timber.d("getBodyTextFromMessage: Text requested, HTML found.");
String text = getTextFromPartOrEmpty(part);
return HtmlConverter.htmlToText(text);
}
}
// If we had nothing interesting, return an empty string.
return "";
}
Aggregations