Search in sources :

Example 31 with ClipData

use of android.content.ClipData in project android_frameworks_base by ResurrectionRemix.

the class Editor method startDragAndDrop.

private void startDragAndDrop() {
    // TODO: Fix drag and drop in full screen extracted mode.
    if (mTextView.isInExtractedMode()) {
        return;
    }
    final int start = mTextView.getSelectionStart();
    final int end = mTextView.getSelectionEnd();
    CharSequence selectedText = mTextView.getTransformedText(start, end);
    ClipData data = ClipData.newPlainText(null, selectedText);
    DragLocalState localState = new DragLocalState(mTextView, start, end);
    mTextView.startDragAndDrop(data, getTextThumbnailBuilder(start, end), localState, View.DRAG_FLAG_GLOBAL);
    stopTextActionMode();
    if (hasSelectionController()) {
        getSelectionController().resetTouchOffsets();
    }
}
Also used : ClipData(android.content.ClipData) Paint(android.graphics.Paint)

Example 32 with ClipData

use of android.content.ClipData in project android_frameworks_base by ResurrectionRemix.

the class VoiceInteractionSessionConnection method deliverSessionDataLocked.

private void deliverSessionDataLocked(AssistDataForActivity assistDataForActivity) {
    Bundle assistData = assistDataForActivity.data.getBundle(VoiceInteractionSession.KEY_DATA);
    AssistStructure structure = assistDataForActivity.data.getParcelable(VoiceInteractionSession.KEY_STRUCTURE);
    AssistContent content = assistDataForActivity.data.getParcelable(VoiceInteractionSession.KEY_CONTENT);
    int uid = assistDataForActivity.data.getInt(Intent.EXTRA_ASSIST_UID, -1);
    if (uid >= 0 && content != null) {
        Intent intent = content.getIntent();
        if (intent != null) {
            ClipData data = intent.getClipData();
            if (data != null && Intent.isAccessUriMode(intent.getFlags())) {
                grantClipDataPermissions(data, intent.getFlags(), uid, mCallingUid, mSessionComponentName.getPackageName());
            }
        }
        ClipData data = content.getClipData();
        if (data != null) {
            grantClipDataPermissions(data, Intent.FLAG_GRANT_READ_URI_PERMISSION, uid, mCallingUid, mSessionComponentName.getPackageName());
        }
    }
    try {
        mSession.handleAssist(assistData, structure, content, assistDataForActivity.activityIndex, assistDataForActivity.activityCount);
    } catch (RemoteException e) {
    }
}
Also used : AssistContent(android.app.assist.AssistContent) Bundle(android.os.Bundle) AssistStructure(android.app.assist.AssistStructure) Intent(android.content.Intent) RemoteException(android.os.RemoteException) ClipData(android.content.ClipData)

Example 33 with ClipData

use of android.content.ClipData in project android_frameworks_base by ResurrectionRemix.

the class QuickViewIntentBuilder method build.

/**
     * Builds the intent for quick viewing. Short circuits building if a handler cannot
     * be resolved; in this case {@code null} is returned.
     */
@Nullable
Intent build() {
    if (DEBUG)
        Log.d(TAG, "Preparing intent for doc:" + mDocument.documentId);
    String trustedPkg = getQuickViewPackage();
    if (!TextUtils.isEmpty(trustedPkg)) {
        Intent intent = new Intent(Intent.ACTION_QUICK_VIEW);
        intent.setDataAndType(mDocument.derivedUri, mDocument.mimeType);
        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.setPackage(trustedPkg);
        if (hasRegisteredHandler(intent)) {
            final ArrayList<Uri> uris = new ArrayList<Uri>();
            final int documentLocation = collectViewableUris(uris);
            final Range<Integer> range = computeSiblingsRange(uris, documentLocation);
            ClipData clipData = null;
            ClipData.Item item;
            Uri uri;
            for (int i = range.getLower(); i <= range.getUpper(); i++) {
                uri = uris.get(i);
                item = new ClipData.Item(uri);
                if (DEBUG)
                    Log.d(TAG, "Including file: " + uri);
                if (clipData == null) {
                    clipData = new ClipData("URIs", new String[] { ClipDescription.MIMETYPE_TEXT_URILIST }, item);
                } else {
                    clipData.addItem(item);
                }
            }
            // The documentLocation variable contains an index in "uris". However,
            // ClipData contains a slice of "uris", so we need to shift the location
            // so it points to the same Uri.
            intent.putExtra(Intent.EXTRA_INDEX, documentLocation - range.getLower());
            intent.setClipData(clipData);
            return intent;
        } else {
            Log.e(TAG, "Can't resolve trusted quick view package: " + trustedPkg);
        }
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) Intent(android.content.Intent) DocumentInfo.getCursorString(com.android.documentsui.model.DocumentInfo.getCursorString) Uri(android.net.Uri) ClipData(android.content.ClipData) Nullable(android.support.annotation.Nullable)

Example 34 with ClipData

use of android.content.ClipData in project android_frameworks_base by ResurrectionRemix.

the class FilesActivity method onTaskFinished.

@Override
void onTaskFinished(Uri... uris) {
    if (DEBUG)
        Log.d(TAG, "onFinished() " + Arrays.toString(uris));
    final Intent intent = new Intent();
    if (uris.length == 1) {
        intent.setData(uris[0]);
    } else if (uris.length > 1) {
        final ClipData clipData = new ClipData(null, mState.acceptMimes, new ClipData.Item(uris[0]));
        for (int i = 1; i < uris.length; i++) {
            clipData.addItem(new ClipData.Item(uris[i]));
        }
        intent.setClipData(clipData);
    }
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
    setResult(Activity.RESULT_OK, intent);
    finish();
}
Also used : MenuItem(android.view.MenuItem) Intent(android.content.Intent) ClipData(android.content.ClipData)

Example 35 with ClipData

use of android.content.ClipData in project android_frameworks_base by ResurrectionRemix.

the class ClipboardService method setPrimaryClip.

public void setPrimaryClip(ClipData clip, String callingPackage) {
    synchronized (this) {
        if (clip != null && clip.getItemCount() <= 0) {
            throw new IllegalArgumentException("No items");
        }
        final int callingUid = Binder.getCallingUid();
        if (mAppOps.noteOp(AppOpsManager.OP_WRITE_CLIPBOARD, callingUid, callingPackage) != AppOpsManager.MODE_ALLOWED) {
            return;
        }
        checkDataOwnerLocked(clip, callingUid);
        final int userId = UserHandle.getUserId(callingUid);
        PerUserClipboard clipboard = getClipboard(userId);
        revokeUris(clipboard);
        setPrimaryClipInternal(clipboard, clip);
        List<UserInfo> related = getRelatedProfiles(userId);
        if (related != null) {
            int size = related.size();
            if (size > 1) {
                // Related profiles list include the current profile.
                boolean canCopy = false;
                try {
                    canCopy = !mUm.getUserRestrictions(userId).getBoolean(UserManager.DISALLOW_CROSS_PROFILE_COPY_PASTE);
                } catch (RemoteException e) {
                    Slog.e(TAG, "Remote Exception calling UserManager: " + e);
                }
                // primary clip in related users to prevent pasting stale content.
                if (!canCopy) {
                    clip = null;
                } else {
                    // We want to fix the uris of the related user's clip without changing the
                    // uris of the current user's clip.
                    // So, copy the ClipData, and then copy all the items, so that nothing
                    // is shared in memmory.
                    clip = new ClipData(clip);
                    for (int i = clip.getItemCount() - 1; i >= 0; i--) {
                        clip.setItemAt(i, new ClipData.Item(clip.getItemAt(i)));
                    }
                    clip.fixUrisLight(userId);
                }
                for (int i = 0; i < size; i++) {
                    int id = related.get(i).id;
                    if (id != userId) {
                        setPrimaryClipInternal(getClipboard(id), clip);
                    }
                }
            }
        }
    }
}
Also used : UserInfo(android.content.pm.UserInfo) RemoteException(android.os.RemoteException) ClipData(android.content.ClipData)

Aggregations

ClipData (android.content.ClipData)193 ClipboardManager (android.content.ClipboardManager)81 Intent (android.content.Intent)48 Uri (android.net.Uri)41 Paint (android.graphics.Paint)24 MenuItem (android.view.MenuItem)20 View (android.view.View)16 ArrayList (java.util.ArrayList)15 TextView (android.widget.TextView)12 PendingIntent (android.app.PendingIntent)11 Bundle (android.os.Bundle)11 RemoteException (android.os.RemoteException)11 ContentResolver (android.content.ContentResolver)10 Nullable (android.support.annotation.Nullable)10 TextPaint (android.text.TextPaint)10 ImageView (android.widget.ImageView)10 DocumentInfo (com.android.documentsui.model.DocumentInfo)10 Item (android.content.ClipData.Item)9 Editable (android.text.Editable)9 DialogInterface (android.content.DialogInterface)8