private static void importVideoFromClipData(Intent data) { ClipData clipData = data.getClipData(); Log.d(TAG,"Video importFromClipData"); if (clipData.getItemCount() == 0) return; ArrayList<Uri> uris = new ArrayList(clipData.getItemCount()); for (int i = 0 ; i < clipData.getItemCount() ; i++ ){ Uri uri = clipData.getItemAt(i).getUri(); uris.add(resolveUri(uri)); } importVideoFromFileUri(uris); }
private static void importImageFromClipData(Intent data) { ClipData clipData = data.getClipData(); Log.d(TAG,"importFromClipData"); if (clipData.getItemCount() == 0) return; ArrayList<Uri> uris = new ArrayList(clipData.getItemCount()); for (int i = 0 ; i < clipData.getItemCount() ; i++ ){ Uri uri = clipData.getItemAt(i).getUri(); uris.add(resolveUri(uri)); } importImageFromFileUri(uris); }
@Override public boolean onMenuItemClick(MenuItem item, LogLine logLine) { if (logLine != null) { switch (item.getItemId()) { case CONTEXT_MENU_COPY_ID: ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(ClipData.newPlainText(null, logLine.getOriginalLine())); Toast.makeText(this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show(); return true; case CONTEXT_MENU_FILTER_ID: if (logLine.getProcessId() == -1) { // invalid line return false; } showSearchByDialog(logLine); return true; } } return false; }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.miCopySysInfo: ClipboardManager manager = (ClipboardManager)getSystemService(Activity.CLIPBOARD_SERVICE); if (manager == null) { Toast.makeText(this, "Couldn't access clipboard", Toast.LENGTH_LONG).show(); return true; } manager.setPrimaryClip(ClipData.newPlainText(CLIP_TITLE, debugOutput)); Toast.makeText(this, "Copied to clipboard", Toast.LENGTH_LONG).show(); return true; case R.id.miShareSysInfo: Intent i = new Intent(Intent.ACTION_SEND); i.setType("text/plain"); i.putExtra(Intent.EXTRA_TEXT, debugOutput); startActivity(i); return true; } return super.onOptionsItemSelected(item); }
@Override public void onBindViewHolder(GifViewHolder holder, int position) { final Api.GifResult result = results[position]; holder.gifView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("giphy_url", result.images.fixed_height.url); clipboard.setPrimaryClip(clip); Intent fullscreenIntent = FullscreenActivity.getIntent(activity, result); activity.startActivity(fullscreenIntent); } }); requestBuilder.load(result).into(holder.gifView); preloadSizeProvider.setView(holder.gifView); }
@Override public void copyLink() { if (checkNull()) { view.showCopyTextError(); return; } ClipboardManager manager = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE); ClipData clipData = null; switch (type) { case TYPE_ZHIHU: clipData = ClipData.newPlainText("text", Html.fromHtml(zhihuDailyStory.getShare_url()).toString()); break; case TYPE_GUOKR: clipData = ClipData.newPlainText("text", Html.fromHtml(Api.GUOKR_ARTICLE_LINK_V1 + id).toString()); break; case TYPE_DOUBAN: clipData = ClipData.newPlainText("text", Html.fromHtml(doubanMomentStory.getOriginal_url()).toString()); } manager.setPrimaryClip(clipData); view.showTextCopied(); }
@Override public void copyText() { if (checkNull()) { view.showCopyTextError(); return; } ClipboardManager manager = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE); ClipData clipData = null; switch (type) { case TYPE_ZHIHU: clipData = ClipData.newPlainText("text", Html.fromHtml(title + "\n" + zhihuDailyStory.getBody()).toString()); break; case TYPE_GUOKR: clipData = ClipData.newPlainText("text", Html.fromHtml(guokrStory).toString()); break; case TYPE_DOUBAN: clipData = ClipData.newPlainText("text", Html.fromHtml(title + "\n" + doubanMomentStory.getContent()).toString()); } manager.setPrimaryClip(clipData); view.showTextCopied(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listView = (ListView) findViewById(R.id.list_view); adapter = new PortListAdapter(MainActivity.this, ports); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { String item = ports.get(i); ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("copy port", item); clipboard.setPrimaryClip(clip); Toast.makeText(MainActivity.this, "port '" + item + "' copied", Toast.LENGTH_LONG).show(); } }); }
/** * 获取剪贴板的意图 * * @return 剪贴板的意图 */ public static Intent getIntent() { ClipboardManager clipboard = (ClipboardManager) Utils.getContext().getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = clipboard.getPrimaryClip(); if (clip != null && clip.getItemCount() > 0) { return clip.getItemAt(0).getIntent(); } return null; }
@Override public void onBindViewHolder(GifViewHolder holder, int position) { final Api.GifResult result = results[position]; holder.gifView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("giphy_url", result.images.fixed_height.url); Preconditions.checkNotNull(clipboard).setPrimaryClip(clip); Intent fullscreenIntent = FullscreenActivity.getIntent(activity, result); activity.startActivity(fullscreenIntent); } }); // clearOnDetach let's us stop animating GifDrawables that RecyclerView hasn't yet recycled // but that are currently off screen. requestBuilder.load(result).into(holder.gifView).clearOnDetach(); preloadSizeProvider.setView(holder.gifView); }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void onFinished(Uri... uris) { 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])); } if(Utils.hasJellyBean()){ intent.setClipData(clipData); } else{ intent.setData(uris[0]); } } if (mState.action == DocumentsActivity.State.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 { 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(); }
@SuppressLint("ClickableViewAccessibility") @Override public boolean onTouch(View v, MotionEvent event) { if (mSearch.getCompoundDrawables()[2] != null) { boolean tappedX = event.getX() > (mSearch.getWidth() - mSearch.getPaddingRight() - mIcon.getIntrinsicWidth()); if (tappedX) { if (event.getAction() == MotionEvent.ACTION_UP) { if (mSearch.hasFocus()) { ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("label", mSearch.getText() .toString()); clipboard.setPrimaryClip(clip); Utils.showToast( mActivity, mActivity.getResources().getString( R.string.message_text_copied)); } else { refreshOrStop(); } } return true; } } return false; }
private void onLinkMenuClicked(Dialog d, int position) { switch (position) { case 0: newTab(currentClickUrl, true); break; case 1: if(getCurrentWebView()!=null) { getCurrentWebView().loadUrl(currentClickUrl); } break; case 2: ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("label", currentClickUrl); clipboard.setPrimaryClip(clip); Utils.showToast(mActivity, mActivity.getResources().getString(R.string.message_link_copied)); break; } }
public void setEditText(@NonNull Context context, @NonNull String text) throws MyException { if (null == context) { throw new NullPointerException("context"); } if (null == text) { throw new NullPointerException("text"); } try { //清空内容 Bundle arguments = new Bundle(); arguments.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT, AccessibilityNodeInfo .MOVEMENT_GRANULARITY_LINE); arguments.putBoolean(AccessibilityNodeInfo.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN, true); mAccessibilityNodeInfo.performAction(AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY, arguments); //粘贴内容 ClipData clipData = ClipData.newPlainText(context.getPackageName(), text); ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); clipboardManager.setPrimaryClip(clipData); mAccessibilityNodeInfo.performAction(AccessibilityNodeInfo.ACTION_PASTE); } catch (Exception e) { throw new MyException(e); } }
private ArrayList<Uri> handleGallery(Intent data) { ArrayList<Uri> uris = new ArrayList<>(); if (data.getData() != null) { // Single select uris.add(data.getData()); } else { // Multi select if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { ClipData clipData = data.getClipData(); for (int i = 0; i < clipData.getItemCount(); i++) { uris.add(clipData.getItemAt(i).getUri()); } } } return uris; }
public View.OnClickListener onPublicKeyTextClicked() { return new View.OnClickListener() { private static final String CLIP_DATA_LABEL_TEXT_DATA = "text_data"; @Override 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(); } }; }
protected void onActionModeCopyClick(){ List<Message> selected = getSelected(getData(), true); if (safeIsEmpty(selected)) return; String result = ""; boolean firstTime = true; for (Message message : selected) { String body = TextUtils.isEmpty(message.getDecryptedBody()) ? message.getBody() : message.getDecryptedBody(); result = result + (!firstTime ? "\n" : "") + body; firstTime = false; } ClipboardManager clipboard = (ClipboardManager) getApplicationContext() .getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("messages", result); clipboard.setPrimaryClip(clip); safeShowLongToast(getView(), R.string.copied_to_clipboard); }
private void onTransaction(String hash) { hideDialog(); dialog = new AlertDialog.Builder(this) .setTitle(R.string.transaction_succeeded) .setMessage(hash) .setPositiveButton(R.string.button_ok, (dialog1, id) -> { finish(); }) .setNeutralButton(R.string.copy, (dialog1, id) -> { ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("transaction hash", hash); clipboard.setPrimaryClip(clip); finish(); }) .create(); dialog.show(); }
@OnClick({R.id.about_gmail_img, R.id.about_github_img, R.id.about_license_text}) public void onClick(View view) { switch (view.getId()) { case R.id.about_gmail_img: String s1 = "邮箱"; String s2 = getString(R.string.gmail_address); ClipboardManager cmb = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); ClipData clipData = ClipData.newPlainText("content", s2); cmb.setPrimaryClip(clipData); showToast(getString(R.string.hint_clipboard, s1, s2)); break; case R.id.about_github_img: Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setData(Uri.parse(getString(R.string.github_page))); startActivity(Intent.createChooser(intent, "请选择浏览器")); break; case R.id.about_license_text: navigate(OpenLicenseActivity.class); break; } }
/** * 获取剪切板的内容 */ public static CharSequence getText(Context context) { StringBuilder sb = new StringBuilder(); if (isNew()) { instance(context); if (!mNewCliboardManager.hasPrimaryClip()) { return sb.toString(); } else { ClipData clipData = (mNewCliboardManager).getPrimaryClip(); int count = clipData.getItemCount(); for (int i = 0; i < count; ++i) { ClipData.Item item = clipData.getItemAt(i); CharSequence str = item.coerceToText(context); sb.append(str); } } } else { instance(context); sb.append(mClipboardManager.getText()); } return sb.toString(); }
@Override public void onClick(View v) { switch (v.getId()) { case R.id.btnCopySegement: ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); String s = DecimalEdit.StringForMode(ComputedTotal(), DecimalEdit.DefaultHHMM ? DecimalEdit.EditMode.HHMM : DecimalEdit.EditMode.DECIMAL); if (clipboard != null) { clipboard.setPrimaryClip(ClipData.newPlainText("total", s)); } break; case R.id.btnAddSegment: addSpecifiedTime(); updateEquationString(); break; case R.id.btnAddAndUpdate: addSpecifiedTime(); returnValue(ComputedTotal()); super.onBackPressed(); break; } }
private Uri[] processData(Intent data) { Uri[] datas = null; if (data == null) { return datas; } String target = data.getDataString(); if (!TextUtils.isEmpty(target)) { return datas = new Uri[]{Uri.parse(target)}; } ClipData mClipData = null; if (mClipData != null && mClipData.getItemCount() > 0) { datas = new Uri[mClipData.getItemCount()]; for (int i = 0; i < mClipData.getItemCount(); i++) { ClipData.Item mItem = mClipData.getItemAt(i); datas[i] = mItem.getUri(); } } return datas; }
@Override public void onPrimaryClipChanged() { ClipData clipData = clipboardManager.getPrimaryClip(); if (!CLIP_LABEL.equals(clipData.getDescription().getLabel())) { String text = clipDataToString(clipData); if (isEncryptedString(text)) { Pair<String, Password> decryptResult = decrypt(text); if (decryptResult != null) { Password password = decryptResult.second; String decryptedString = decryptResult.first; databaseHelper.insertOrRefreshMessage(decryptedString); toast(String.format(getString(R.string.decrypted_by_password), password.name, password.value, decryptedString)); } else { toast(getString(R.string.decryption_failed)); } } } }
@Override public void onClickOptions(View v, final Update update, Button buttonView) { PopupMenu popupMenu = new PopupMenu(this, buttonView); popupMenu.getMenuInflater().inflate(R.menu.update_card, popupMenu.getMenu()); popupMenu.setOnMenuItemClickListener(item -> { switch (item.getItemId()) { case R.id.menu_card_copytext: ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboard.setPrimaryClip(ClipData.newPlainText("Update Text", update.getText())); showToast(getString(R.string.toast_card_copiedtext)); break; } return false; }); popupMenu.show(); }
public static void copy2Clipboard(Context context, String string) { ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clipData = ClipData.newPlainText("Tumblr", string); clipboardManager.setPrimaryClip(clipData); Toast.makeText(context, R.string.copy_to_clipboard, Toast.LENGTH_SHORT).show(); }
@Override public boolean onContextItemSelected(MenuItem mi) { if (mi.getItemId() == codeText.getId()) { ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("sync_code", codeText.getText()); clipboard.setPrimaryClip(clip); return true; } return super.onContextItemSelected(mi); }
@Override public void onLongPress(MotionEvent e) { super.onLongPress(e); ClipData data = ClipData.newPlainText("", ""); MyDragShadowBuilder shadowBuilder = new MyDragShadowBuilder(mDrapView); mDrapView.startDrag(data, shadowBuilder, mDrapView, 0); }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) public static String getLatestText(Context context) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = clipboard.getPrimaryClip(); if (clip != null && clip.getItemCount() > 0) { return String.valueOf(clip.getItemAt(0).coerceToText(context)); } return null; }
@Override public void onClick(View v) { ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText(KEY_ADDRESS, wallet.address); if (clipboard != null) { clipboard.setPrimaryClip(clip); } Toast.makeText(this, "Copied to clipboard", Toast.LENGTH_SHORT).show(); }
@Override public void onRefresh(List<BaseItem> items) { String content = ""; if (items != null && items.size() > 0) { content = items.get(0).getContent(); } else { content = ""; } ClipData clipData; clipData = ClipData.newPlainText("text", content); mClipboardManager.setPrimaryClip(clipData); mBuilder.setContentText(content); mNotification = mBuilder.build(); mNotificationManager.notify(NOTIFICATION_ID, mNotification); }
@JavascriptInterface public void getText(String text) { // put selected text into clipdata ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("simple text", text); clipboard.setPrimaryClip(clip); // gives the toast for selected text Toast.makeText(mContext, text, Toast.LENGTH_SHORT).show(); }
@Override public void onCopyAddress() { if (view != null) { ClipboardManager clipboard = (ClipboardManager) view.getContext().getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText(EXTRA_STRING.ADDRESS, CredentialHolder.getAddress()); clipboard.setPrimaryClip(clip); view.onKeyCopied(); } }
/** * Copy the package number to clipboard. */ @Override public void copyPackageNumber() { ClipboardManager manager = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); ClipData data = ClipData.newPlainText("text", getSelectedPackageNumber()); manager.setPrimaryClip(data); Snackbar.make(fab, R.string.package_number_copied, Snackbar.LENGTH_SHORT).show(); }
@TargetApi(android.os.Build.VERSION_CODES.HONEYCOMB) private void copyUriSdk11(Context context, String url) { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText(context.getString(R.string.app_name), url); clipboard.setPrimaryClip(clip); }
/** * 获取剪贴板的文本 * * @return 剪贴板的文本 */ public static CharSequence getText(Context context) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = clipboard.getPrimaryClip(); if (clip != null && clip.getItemCount() > 0) { return clip.getItemAt(0).coerceToText(context); } return null; }
/** * 开始监听剪贴板 */ public static void startListenClipboard(final Context context) { final ClipboardManager clipboard = (ClipboardManager) context. getSystemService(Context.CLIPBOARD_SERVICE); clipboard.addPrimaryClipChangedListener(new ClipboardManager.OnPrimaryClipChangedListener() { @Override public void onPrimaryClipChanged() { // XpLog.i("onPrimaryClipChanged"); //获取剪贴板内容,先判断该内容是否为空 if (clipboard.hasPrimaryClip()) { ClipData clipData = clipboard.getPrimaryClip(); int count = clipData.getItemCount(); for (int i = 0; i < count; ++i) { ClipData.Item item = clipData.getItemAt(i); CharSequence str = item .coerceToText(context); //因为复制历史记录里面某一条文字到剪贴板的时候,也会导致剪贴板内容变动,此处避免 添加重复内容到剪贴板历史 if (!clipboardData.contains(str.toString())) { clipboardData.add(str.toString()); } } } } }); }