Search in sources :

Example 16 with NonNull

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;
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) EditText(android.widget.EditText) DialogInterface(android.content.DialogInterface) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) TextView(android.widget.TextView) View(android.view.View) KeyEvent(android.view.KeyEvent) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) NonNull(androidx.annotation.NonNull)

Example 17 with NonNull

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);
}
Also used : Size(android.hardware.Camera.Size) NonNull(androidx.annotation.NonNull)

Example 18 with NonNull

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);
            }
        }
    };
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) InputStream(java.io.InputStream) EOLConvertingOutputStream(com.fsck.k9.mail.filter.EOLConvertingOutputStream) OutputStream(java.io.OutputStream) OpenPgpDataSource(org.openintents.openpgp.util.OpenPgpApi.OpenPgpDataSource) IOException(java.io.IOException) TextBody(com.fsck.k9.mail.internet.TextBody) Body(com.fsck.k9.mail.Body) BinaryMemoryBody(com.fsck.k9.mailstore.BinaryMemoryBody) BinaryTempFileBody(com.fsck.k9.mail.internet.BinaryTempFileBody) NonNull(androidx.annotation.NonNull)

Example 19 with NonNull

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;
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) NonNull(androidx.annotation.NonNull)

Example 20 with NonNull

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 "";
}
Also used : Part(com.fsck.k9.mail.Part) 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