Search in sources :

Example 46 with ClipData

use of android.content.ClipData in project sharelock-android by auth0.

the class ComposeActivity method onEvent.

public void onEvent(RequestLinkEvent event) {
    final Secret secret = event.getSecret();
    final EventBus bus = this.bus;
    SharedPreferences preferences = getSharedPreferences(getPackageName(), MODE_PRIVATE);
    client = new LinkAPIClient(preferences.getString(LinkAPIClient.SHARELOCK_ENDPOINT_KEY, LinkAPIClient.DEFAULT_URL));
    client.generateLinkForSecret(secret, this, new LinkAPIClient.LinkCallback() {

        @Override
        public void onSuccess(final Uri link) {
            Log.d(TAG, "Obtained link path " + link);
            handler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    bus.postSticky(new NewLinkEvent(link));
                    final ClipboardManager clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
                    final ClipData clipData = ClipData.newRawUri("sharelocked-link", link);
                    clipboardManager.setPrimaryClip(clipData);
                    Snackbar snackbar = Snackbar.with(ComposeActivity.this).text(R.string.link_in_clipboard_message).duration(Snackbar.SnackbarDuration.LENGTH_SHORT);
                    SnackbarManager.show(snackbar);
                }
            }, DELAY_MILLIS);
        }

        @Override
        public void onError(Throwable reason) {
            Log.e(TAG, "Failed to generate link", reason);
            bus.post(new SharelockAPIErrorEvent());
            AlertDialog dialog = new AlertDialog.Builder(ComposeActivity.this).setTitle(R.string.link_generation_failed_title).setMessage(R.string.link_generation_failed).setCancelable(true).setPositiveButton(R.string.retry_button, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    bus.post(new RequestLinkEvent(secret));
                }
            }).setNegativeButton(R.string.cancel_button, null).create();
            dialog.show();
        }
    });
}
Also used : ClipboardManager(android.content.ClipboardManager) AlertDialog(android.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) DialogInterface(android.content.DialogInterface) EventBus(de.greenrobot.event.EventBus) Uri(android.net.Uri) RequestLinkEvent(com.auth0.sharelock.event.RequestLinkEvent) NewLinkEvent(com.auth0.sharelock.event.NewLinkEvent) ClipData(android.content.ClipData) SharelockAPIErrorEvent(com.auth0.sharelock.event.SharelockAPIErrorEvent) Snackbar(com.nispok.snackbar.Snackbar)

Example 47 with ClipData

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

the class ConversationActivity method extractUriFromIntent.

@SuppressLint("NewApi")
private static List<Uri> extractUriFromIntent(final Intent intent) {
    List<Uri> uris = new ArrayList<>();
    if (intent == null) {
        return uris;
    }
    Uri uri = intent.getData();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && uri == null) {
        final ClipData clipData = intent.getClipData();
        if (clipData != null) {
            for (int i = 0; i < clipData.getItemCount(); ++i) {
                uris.add(clipData.getItemAt(i).getUri());
            }
        }
    } else {
        uris.add(uri);
    }
    return uris;
}
Also used : ArrayList(java.util.ArrayList) Uri(android.net.Uri) ClipData(android.content.ClipData) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Example 48 with ClipData

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

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)

Example 49 with ClipData

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

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 50 with ClipData

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

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)

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