List of usage examples for android.content ClipDescription MIMETYPE_TEXT_URILIST
String MIMETYPE_TEXT_URILIST
To view the source code for android.content ClipDescription MIMETYPE_TEXT_URILIST.
Click Source Link
From source file:Main.java
/** * Get uri from Clipboard//ww w . j a v a 2 s .c o m * * @param context * @return */ public static Uri getUri(Context context) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); if (clipboard.hasPrimaryClip() && clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_URILIST)) { ClipData clip = clipboard.getPrimaryClip(); if (clip != null && clip.getItemCount() > 0) { return clip.getItemAt(0).getUri(); } } return null; }
From source file:io.soramitsu.iroha.presenter.AssetReceivePresenter.java
public View.OnClickListener onPublicKeyTextClicked() { return new View.OnClickListener() { private static final String CLIP_DATA_LABEL_TEXT_DATA = "text_data"; @Override/*w ww . j ava 2 s. c o m*/ public void onClick(View view) { final Context context = assetReceiveView.getContext(); ClipData.Item item = new ClipData.Item(assetReceiveView.getPublicKey()); String[] mimeType = new String[1]; mimeType[0] = ClipDescription.MIMETYPE_TEXT_URILIST; ClipData cd = new ClipData(new ClipDescription(CLIP_DATA_LABEL_TEXT_DATA, mimeType), item); ClipboardManager cm = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE); cm.setPrimaryClip(cd); Toast.makeText(context, R.string.message_copy_to_clipboard, Toast.LENGTH_SHORT).show(); } }; }
From source file:click.kobaken.rxirohaandroid_sample.presenter.AssetReceivePresenter.java
public View.OnClickListener onPublicKeyTextClicked() { return view -> { final String CLIP_DATA_LABEL_TEXT_DATA = "text_data"; final Context context = assetReceiveView.getContext(); ClipData.Item item = new ClipData.Item(assetReceiveView.getPublicKey()); String[] mimeType = new String[1]; mimeType[0] = ClipDescription.MIMETYPE_TEXT_URILIST; ClipData cd = new ClipData(new ClipDescription(CLIP_DATA_LABEL_TEXT_DATA, mimeType), item); ClipboardManager cm = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE); cm.setPrimaryClip(cd);//w ww .j a v a 2 s.co m Toast.makeText(context, R.string.message_copy_to_clipboard, Toast.LENGTH_SHORT).show(); }; }
From source file:com.android.mail.compose.ComposeActivity.java
protected void sendOrSave(final boolean save, final boolean showToast) { // Check if user is a monkey. Monkeys can compose and hit send // button but are not allowed to send anything off the device. if (ActivityManager.isUserAMonkey()) { return;/*from ww w .j a va 2s . co m*/ } final SendOrSaveCallback callback = new SendOrSaveCallback() { @Override public void initializeSendOrSave() { final Intent i = new Intent(ComposeActivity.this, EmptyService.class); // API 16+ allows for setClipData. For pre-16 we are going to open the fds // on the main thread. if (Utils.isRunningJellybeanOrLater()) { // Grant the READ permission for the attachments to the service so that // as long as the service stays alive we won't hit PermissionExceptions. final ClipDescription desc = new ClipDescription("attachment_uris", new String[] { ClipDescription.MIMETYPE_TEXT_URILIST }); ClipData clipData = null; for (Attachment a : mAttachmentsView.getAttachments()) { if (a != null && !Utils.isEmpty(a.contentUri)) { final ClipData.Item uriItem = new ClipData.Item(a.contentUri); if (clipData == null) { clipData = new ClipData(desc, uriItem); } else { clipData.addItem(uriItem); } } } i.setClipData(clipData); i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } synchronized (PENDING_SEND_OR_SAVE_TASKS_NUM) { if (PENDING_SEND_OR_SAVE_TASKS_NUM.getAndAdd(1) == 0) { // Start service so we won't be killed if this app is // put in the background. startService(i); } } if (sTestSendOrSaveCallback != null) { sTestSendOrSaveCallback.initializeSendOrSave(); } } @Override public void notifyMessageIdAllocated(SendOrSaveMessage sendOrSaveMessage, Message message) { synchronized (mDraftLock) { mDraftId = message.id; mDraft = message; if (sRequestMessageIdMap != null) { sRequestMessageIdMap.put(sendOrSaveMessage.mRequestId, mDraftId); } // Cache request message map, in case the process is killed saveRequestMap(); } if (sTestSendOrSaveCallback != null) { sTestSendOrSaveCallback.notifyMessageIdAllocated(sendOrSaveMessage, message); } } @Override public long getMessageId() { synchronized (mDraftLock) { return mDraftId; } } @Override public void sendOrSaveFinished(SendOrSaveMessage message, boolean success) { // Update the last sent from account. if (mAccount != null) { MailAppProvider.getInstance().setLastSentFromAccount(mAccount.uri.toString()); } if (success) { // Successfully sent or saved so reset change markers discardChanges(); } else { // A failure happened with saving/sending the draft // TODO(pwestbro): add a better string that should be used // when failing to send or save Toast.makeText(ComposeActivity.this, R.string.send_failed, Toast.LENGTH_SHORT).show(); } synchronized (PENDING_SEND_OR_SAVE_TASKS_NUM) { if (PENDING_SEND_OR_SAVE_TASKS_NUM.addAndGet(-1) == 0) { // Stop service so we can be killed. stopService(new Intent(ComposeActivity.this, EmptyService.class)); } } if (sTestSendOrSaveCallback != null) { sTestSendOrSaveCallback.sendOrSaveFinished(message, success); } } }; setAccount(mReplyFromAccount.account); final Spanned body = removeComposingSpans(mBodyView.getText()); callback.initializeSendOrSave(); // For pre-JB we need to open the fds on the main thread final Bundle attachmentFds; if (!Utils.isRunningJellybeanOrLater()) { attachmentFds = initializeAttachmentFds(this, mAttachmentsView.getAttachments()); } else { attachmentFds = null; } // Generate a unique message id for this request mRequestId = sRandom.nextInt(); SEND_SAVE_TASK_HANDLER.post(new Runnable() { @Override public void run() { final Message msg = createMessage(mReplyFromAccount, mRefMessage, getMode(), body); sendOrSaveInternal(ComposeActivity.this, mRequestId, mReplyFromAccount, mDraftAccount, msg, mRefMessage, mQuotedTextView.getQuotedTextIfIncluded(), callback, save, mComposeMode, mExtraValues, attachmentFds); } }); // Don't display the toast if the user is just changing the orientation, // but we still need to save the draft to the cursor because this is how we restore // the attachments when the configuration change completes. if (showToast && (getChangingConfigurations() & ActivityInfo.CONFIG_ORIENTATION) == 0) { Toast.makeText(this, save ? R.string.message_saved : R.string.sending_message, Toast.LENGTH_LONG) .show(); } // Need to update variables here because the send or save completes // asynchronously even though the toast shows right away. discardChanges(); updateSaveUi(); // If we are sending, finish the activity if (!save) { finish(); } }