Search in sources :

Example 71 with ClipData

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

the class DocumentClipper method clipDocuments.

public void clipDocuments(List<DocumentInfo> docs) {
    ClipData data = getClipDataForDocuments(docs);
    mClipboard.setPrimaryClip(data);
}
Also used : ClipData(android.content.ClipData)

Example 72 with ClipData

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

the class DocumentClipper method hasItemsToPaste.

public boolean hasItemsToPaste() {
    if (mClipboard.hasPrimaryClip()) {
        ClipData clipData = mClipboard.getPrimaryClip();
        int count = clipData.getItemCount();
        if (count > 0) {
            for (int i = 0; i < count; ++i) {
                ClipData.Item item = clipData.getItemAt(i);
                Uri uri = item.getUri();
                if (isDocumentUri(uri)) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : ClipData(android.content.ClipData) Uri(android.net.Uri)

Example 73 with ClipData

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

the class DocumentsActivity 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);
    }
    if (mState.action == ACTION_GET_CONTENT) {
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    } else if (mState.action == ACTION_OPEN_TREE) {
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION | Intent.FLAG_GRANT_PREFIX_URI_PERMISSION);
    } else if (mState.action == ACTION_PICK_COPY_DESTINATION) {
        // Picking a copy destination is only used internally by us, so we
        // don't need to extend permissions to the caller.
        intent.putExtra(Shared.EXTRA_STACK, (Parcelable) mState.stack);
        intent.putExtra(FileOperationService.EXTRA_OPERATION, mState.copyOperationSubType);
    } else {
        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 74 with ClipData

use of android.content.ClipData 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 75 with ClipData

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

the class Editor method onDrop.

void onDrop(DragEvent event) {
    StringBuilder content = new StringBuilder("");
    final DragAndDropPermissions permissions = DragAndDropPermissions.obtain(event);
    if (permissions != null) {
        permissions.takeTransient();
    }
    try {
        ClipData clipData = event.getClipData();
        final int itemCount = clipData.getItemCount();
        for (int i = 0; i < itemCount; i++) {
            Item item = clipData.getItemAt(i);
            content.append(item.coerceToStyledText(mTextView.getContext()));
        }
    } finally {
        if (permissions != null) {
            permissions.release();
        }
    }
    final int offset = mTextView.getOffsetForPosition(event.getX(), event.getY());
    Object localState = event.getLocalState();
    DragLocalState dragLocalState = null;
    if (localState instanceof DragLocalState) {
        dragLocalState = (DragLocalState) localState;
    }
    boolean dragDropIntoItself = dragLocalState != null && dragLocalState.sourceTextView == mTextView;
    if (dragDropIntoItself) {
        if (offset >= dragLocalState.start && offset < dragLocalState.end) {
            // A drop inside the original selection discards the drop.
            return;
        }
    }
    final int originalLength = mTextView.getText().length();
    int min = offset;
    int max = offset;
    Selection.setSelection((Spannable) mTextView.getText(), max);
    mTextView.replaceText_internal(min, max, content);
    if (dragDropIntoItself) {
        int dragSourceStart = dragLocalState.start;
        int dragSourceEnd = dragLocalState.end;
        if (max <= dragSourceStart) {
            // Inserting text before selection has shifted positions
            final int shift = mTextView.getText().length() - originalLength;
            dragSourceStart += shift;
            dragSourceEnd += shift;
        }
        mUndoInputFilter.setForceMerge(true);
        try {
            // Delete original selection
            mTextView.deleteText_internal(dragSourceStart, dragSourceEnd);
            // Make sure we do not leave two adjacent spaces.
            final int prevCharIdx = Math.max(0, dragSourceStart - 1);
            final int nextCharIdx = Math.min(mTextView.getText().length(), dragSourceStart + 1);
            if (nextCharIdx > prevCharIdx + 1) {
                CharSequence t = mTextView.getTransformedText(prevCharIdx, nextCharIdx);
                if (Character.isSpaceChar(t.charAt(0)) && Character.isSpaceChar(t.charAt(1))) {
                    mTextView.deleteText_internal(prevCharIdx, prevCharIdx + 1);
                }
            }
        } finally {
            mUndoInputFilter.setForceMerge(false);
        }
    }
}
Also used : Item(android.content.ClipData.Item) MenuItem(android.view.MenuItem) SpannableStringBuilder(android.text.SpannableStringBuilder) DragAndDropPermissions(android.view.DragAndDropPermissions) ClipData(android.content.ClipData) Paint(android.graphics.Paint)

Aggregations

ClipData (android.content.ClipData)343 ClipboardManager (android.content.ClipboardManager)190 Intent (android.content.Intent)83 Uri (android.net.Uri)65 View (android.view.View)38 MenuItem (android.view.MenuItem)34 TextView (android.widget.TextView)34 ArrayList (java.util.ArrayList)29 Paint (android.graphics.Paint)24 ImageView (android.widget.ImageView)20 Context (android.content.Context)19 DialogInterface (android.content.DialogInterface)19 PendingIntent (android.app.PendingIntent)16 Bundle (android.os.Bundle)16 RemoteException (android.os.RemoteException)14 SpannableStringBuilder (android.text.SpannableStringBuilder)14 SuppressLint (android.annotation.SuppressLint)12 TargetApi (android.annotation.TargetApi)12 Drawable (android.graphics.drawable.Drawable)11 RecyclerView (android.support.v7.widget.RecyclerView)11