Search in sources :

Example 1 with ClipDescription

use of android.content.ClipDescription in project android_frameworks_base by DirtyUnicorns.

the class RemoteInput method getResultsFromIntent.

/**
     * Get the remote input results bundle from an intent. The returned Bundle will
     * contain a key/value for every result key populated by remote input collector.
     * Use the {@link Bundle#getCharSequence(String)} method to retrieve a value.
     * @param intent The intent object that fired in response to an action or content intent
     *               which also had one or more remote input requested.
     */
public static Bundle getResultsFromIntent(Intent intent) {
    ClipData clipData = intent.getClipData();
    if (clipData == null) {
        return null;
    }
    ClipDescription clipDescription = clipData.getDescription();
    if (!clipDescription.hasMimeType(ClipDescription.MIMETYPE_TEXT_INTENT)) {
        return null;
    }
    if (clipDescription.getLabel().equals(RESULTS_CLIP_LABEL)) {
        return clipData.getItemAt(0).getIntent().getExtras().getParcelable(EXTRA_RESULTS_DATA);
    }
    return null;
}
Also used : ClipData(android.content.ClipData) ClipDescription(android.content.ClipDescription)

Example 2 with ClipDescription

use of android.content.ClipDescription in project bitcoin-wallet by bitcoin-wallet.

the class SendingAddressesFragment method getAddressFromPrimaryClip.

private Address getAddressFromPrimaryClip() {
    if (!clipboardManager.hasPrimaryClip())
        return null;
    final ClipData clip = clipboardManager.getPrimaryClip();
    final ClipDescription clipDescription = clip.getDescription();
    if (clipDescription.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
        final CharSequence clipText = clip.getItemAt(0).getText();
        if (clipText == null)
            return null;
        try {
            return Address.fromBase58(Constants.NETWORK_PARAMETERS, clipText.toString().trim());
        } catch (final AddressFormatException x) {
            return null;
        }
    } else if (clipDescription.hasMimeType(ClipDescription.MIMETYPE_TEXT_URILIST)) {
        final Uri clipUri = clip.getItemAt(0).getUri();
        if (clipUri == null)
            return null;
        try {
            return new BitcoinURI(clipUri.toString()).getAddress();
        } catch (final BitcoinURIParseException x) {
            return null;
        }
    } else {
        return null;
    }
}
Also used : AddressFormatException(org.bitcoinj.core.AddressFormatException) BitcoinURI(org.bitcoinj.uri.BitcoinURI) ClipData(android.content.ClipData) Uri(android.net.Uri) BitcoinURIParseException(org.bitcoinj.uri.BitcoinURIParseException) ClipDescription(android.content.ClipDescription)

Example 3 with ClipDescription

use of android.content.ClipDescription in project instructure-android by instructure.

the class RecipientEditTextView method handlePasteClip.

/**
 * Handles pasting a {@link android.content.ClipData} to this {@link com.android.ex.chips.RecipientEditTextView}.
 */
// TODO : allow users to paste?
// Visible for testing.
void handlePasteClip(ClipData clip) {
    if (clip == null) {
        // Do nothing.
        return;
    }
    final ClipDescription clipDesc = clip.getDescription();
    boolean containsSupportedType = clipDesc.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN) || clipDesc.hasMimeType(ClipDescription.MIMETYPE_TEXT_HTML);
    if (!containsSupportedType) {
        return;
    }
    removeTextChangedListener(mTextWatcher);
    final ClipDescription clipDescription = clip.getDescription();
    for (int i = 0; i < clip.getItemCount(); i++) {
        final String mimeType = clipDescription.getMimeType(i);
        final boolean supportedType = ClipDescription.MIMETYPE_TEXT_PLAIN.equals(mimeType) || ClipDescription.MIMETYPE_TEXT_HTML.equals(mimeType);
        if (!supportedType) {
            // Only plain text and html can be pasted.
            continue;
        }
        final CharSequence pastedItem = clip.getItemAt(i).getText();
        if (!TextUtils.isEmpty(pastedItem)) {
            final Editable editable = getText();
            final int start = getSelectionStart();
            final int end = getSelectionEnd();
            if (start < 0 || end < 1) {
                // No selection.
                editable.append(pastedItem);
            } else if (start == end) {
                // Insert at position.
                editable.insert(start, pastedItem);
            } else {
                editable.append(pastedItem, start, end);
            }
            handlePasteAndReplace();
        }
    }
    mHandler.post(mAddTextWatcher);
}
Also used : Editable(android.text.Editable) SpannableString(android.text.SpannableString) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) Point(android.graphics.Point) ClipDescription(android.content.ClipDescription)

Example 4 with ClipDescription

use of android.content.ClipDescription in project Conversations by siacs.

the class VerifyActivity method pastePinFromClipboard.

private void pastePinFromClipboard() {
    final ClipDescription description = clipboardManager != null ? clipboardManager.getPrimaryClipDescription() : null;
    if (description != null && description.hasMimeType(MIMETYPE_TEXT_PLAIN)) {
        final ClipData primaryClip = clipboardManager.getPrimaryClip();
        if (primaryClip != null && primaryClip.getItemCount() > 0) {
            final CharSequence clip = primaryClip.getItemAt(0).getText();
            if (PinEntryWrapper.isValidPin(clip) && !clip.toString().equals(this.pasted)) {
                this.pasted = clip.toString();
                pinEntryWrapper.setPin(clip.toString());
                final Snackbar snackbar = Snackbar.make(binding.coordinator, R.string.possible_pin, Snackbar.LENGTH_LONG);
                snackbar.setAction(R.string.undo, v -> pinEntryWrapper.clear());
                snackbar.show();
            }
        }
    }
}
Also used : ClipData(android.content.ClipData) ClipDescription(android.content.ClipDescription) Snackbar(com.google.android.material.snackbar.Snackbar)

Example 5 with ClipDescription

use of android.content.ClipDescription in project platform_frameworks_base by android.

the class RemoteInput method getResultsFromIntent.

/**
     * Get the remote input results bundle from an intent. The returned Bundle will
     * contain a key/value for every result key populated by remote input collector.
     * Use the {@link Bundle#getCharSequence(String)} method to retrieve a value.
     * @param intent The intent object that fired in response to an action or content intent
     *               which also had one or more remote input requested.
     */
public static Bundle getResultsFromIntent(Intent intent) {
    ClipData clipData = intent.getClipData();
    if (clipData == null) {
        return null;
    }
    ClipDescription clipDescription = clipData.getDescription();
    if (!clipDescription.hasMimeType(ClipDescription.MIMETYPE_TEXT_INTENT)) {
        return null;
    }
    if (clipDescription.getLabel().equals(RESULTS_CLIP_LABEL)) {
        return clipData.getItemAt(0).getIntent().getExtras().getParcelable(EXTRA_RESULTS_DATA);
    }
    return null;
}
Also used : ClipData(android.content.ClipData) ClipDescription(android.content.ClipDescription)

Aggregations

ClipDescription (android.content.ClipDescription)10 ClipData (android.content.ClipData)8 ClipboardManager (android.content.ClipboardManager)2 Uri (android.net.Uri)2 Intent (android.content.Intent)1 Paint (android.graphics.Paint)1 Point (android.graphics.Point)1 AlertDialog (android.support.v7.app.AlertDialog)1 Editable (android.text.Editable)1 SpannableString (android.text.SpannableString)1 TextPaint (android.text.TextPaint)1 Snackbar (com.google.android.material.snackbar.Snackbar)1 AddressFormatException (org.bitcoinj.core.AddressFormatException)1 BitcoinURI (org.bitcoinj.uri.BitcoinURI)1 BitcoinURIParseException (org.bitcoinj.uri.BitcoinURIParseException)1