Java Code Examples for android.content.ClipData#getDescription()

The following examples show how to use android.content.ClipData#getDescription() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SelectionPopupController.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
public boolean canPasteAsPlainText() {
    // String resource "paste_as_plain_text" only exist in O.
    // Also this is an O feature, we need to make it consistant with TextView.
    if (!BuildInfo.isAtLeastO()) return false;
    if (!mCanEditRichlyForPastePopup) return false;
    ClipboardManager clipMgr =
            (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
    if (!clipMgr.hasPrimaryClip()) return false;

    ClipData clipData = clipMgr.getPrimaryClip();
    ClipDescription description = clipData.getDescription();
    CharSequence text = clipData.getItemAt(0).getText();
    boolean isPlainType = description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN);
    // On Android, Spanned could be copied to Clipboard as plain_text MIME type, but in some
    // cases, Spanned could have text format, we need to show "paste as plain text" when
    // that happens.
    if (isPlainType && (text instanceof Spanned)) {
        Spanned spanned = (Spanned) text;
        if (hasStyleSpan(spanned)) return true;
    }
    return description.hasMimeType(ClipDescription.MIMETYPE_TEXT_HTML);
}
 
Example 2
Source File: Clipboard.java    From 365browser with Apache License 2.0 6 votes vote down vote up
public String clipDataToHtmlText(ClipData clipData) {
    ClipDescription description = clipData.getDescription();
    if (description.hasMimeType(ClipDescription.MIMETYPE_TEXT_HTML)) {
        return clipData.getItemAt(0).getHtmlText();
    }

    if (description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
        CharSequence text = clipData.getItemAt(0).getText();
        if (!(text instanceof Spanned)) return null;
        Spanned spanned = (Spanned) text;
        if (hasStyleSpan(spanned)) {
            return ApiCompatibilityUtils.toHtml(
                    spanned, Html.TO_HTML_PARAGRAPH_LINES_CONSECUTIVE);
        }
    }
    return null;
}
 
Example 3
Source File: RemoteInput.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static Intent getClipDataIntentFromIntent(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 null;
    }
    return clipData.getItemAt(0).getIntent();
}
 
Example 4
Source File: RemoteInputCompatJellybean.java    From adt-leanback-support with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 5
Source File: ClipboardService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
void setPrimaryClipInternal(PerUserClipboard clipboard, @Nullable ClipData clip,
        int callingUid) {
    revokeUris(clipboard);
    clipboard.activePermissionOwners.clear();
    if (clip == null && clipboard.primaryClip == null) {
        return;
    }
    clipboard.primaryClip = clip;
    if (clip != null) {
        clipboard.primaryClipUid = callingUid;
    } else {
        clipboard.primaryClipUid = android.os.Process.NOBODY_UID;
    }
    if (clip != null) {
        final ClipDescription description = clip.getDescription();
        if (description != null) {
            description.setTimestamp(System.currentTimeMillis());
        }
    }
    final long ident = Binder.clearCallingIdentity();
    final int n = clipboard.primaryClipListeners.beginBroadcast();
    try {
        for (int i = 0; i < n; i++) {
            try {
                ListenerInfo li = (ListenerInfo)
                        clipboard.primaryClipListeners.getBroadcastCookie(i);

                if (clipboardAccessAllowed(AppOpsManager.OP_READ_CLIPBOARD, li.mPackageName,
                            li.mUid)) {
                    clipboard.primaryClipListeners.getBroadcastItem(i)
                            .dispatchPrimaryClipChanged();
                }
            } catch (RemoteException e) {
                // The RemoteCallbackList will take care of removing
                // the dead object for us.
            }
        }
    } finally {
        clipboard.primaryClipListeners.finishBroadcast();
        Binder.restoreCallingIdentity(ident);
    }
}