@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 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(); }
/** * 获取剪贴板的意图 * * @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; }
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(); }
@Override public boolean onLongClick(View v) { if (v == mCloseButton) { return showAccessibilityToast(v, getResources().getString(R.string.close_tab)); } else if (v == mCustomActionButton) { return showAccessibilityToast(v, mCustomActionButton.getContentDescription()); } else if (v == mTitleUrlContainer) { ClipboardManager clipboard = (ClipboardManager) getContext() .getSystemService(Context.CLIPBOARD_SERVICE); Tab tab = getCurrentTab(); if (tab == null) return false; String url = tab.getOriginalUrl(); ClipData clip = ClipData.newPlainText("url", url); clipboard.setPrimaryClip(clip); Toast.makeText(getContext(), R.string.url_copied, Toast.LENGTH_SHORT).show(); return true; } return false; }
@Override public void onBindViewHolder(CodigoDeBarraAdapter.ViewHolder holder, final int position) { holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ClipboardManager clipboard = (ClipboardManager) v.getContext().getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("Codigo de barras copiado", extractList.get(position).getCodigoDeBarras()); clipboard.setPrimaryClip(clip); Toast.makeText(v.getContext(), "Codigo de barras copiado", Toast.LENGTH_LONG).show(); } }); holder.bindExtractViewModel(extractList.get(position)); }
public TerminalLinesAdapter(Activity a, List<TerminalPrintedLine> lines) { this.activity = a; this.lines = lines; inflater = (LayoutInflater) activity .getSystemService(Context.LAYOUT_INFLATER_SERVICE); uiHandler = new Handler(); copyRunnable = new Runnable() { @Override public void run() { clipboardManager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { if (!copyLine.equals("")) { clipboardManager.setPrimaryClip(ClipData.newPlainText("OneSheeldClipboard", copyLine)); Toast.makeText(activity.getApplicationContext(), R.string.terminal_line_copied_toast, Toast.LENGTH_SHORT).show(); }else Toast.makeText(activity.getApplicationContext(), R.string.terminal_couldnt_copy_empty_line_toast, Toast.LENGTH_SHORT).show(); } } }; }
@Override public void onCreate() { super.onCreate(); context=getApplicationContext(); mClipboard = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE); notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); createNotificationChannel(); listener = new ClipboardManager.OnPrimaryClipChangedListener() { public void onPrimaryClipChanged() { performClipboardCheck(); } }; }
@Override @JSMethod public void getString(@Nullable JSCallback callback) { Context context = mWXSDKInstance.getContext(); ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); Map<String, Object> map = new HashMap<>(2); ClipData clip = clipboard.getPrimaryClip(); if (clip != null && clip.getItemCount() > 0) { ClipData.Item item = clip.getItemAt(0); CharSequence text = coerceToText(context, item); map.put(RESULT, text != null ? RESULT_OK : RESULT_FAILED); map.put(DATA, text != null ? text : ""); } else { map.put(RESULT, RESULT_FAILED); map.put(DATA, ""); } if (null != callback) { callback.invoke(map); } }
private void setPrimaryClip(final ClipData clipData) { try { mUiThreadRule.runOnUiThread(new Runnable() { @Override public void run() { ClipboardManager clipboardManager = (ClipboardManager) InstrumentationRegistry.getTargetContext().getSystemService(CLIPBOARD_SERVICE); clipboardManager.setPrimaryClip(clipData); } }); // ensure clipboard listener has time to react to the changes // so that subsequent calls can verify what the listener has done. delay(90); } catch (Throwable t) { fail("Unexpected error in setting clipboard. " + t.getMessage()); } }
@SuppressWarnings("deprecation") @Override public void paste() { ClipboardManager clipboard = ( ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); //noinspection StatementWithEmptyBody if (clipboard.getText() == null || clipboard.getText() == "") { //nothing to paste } if (!clipboard.hasText()) { return; } if (getSelectionEnd() > getSelectionStart()) { getText().replace(getSelectionStart(), getSelectionEnd(), clipboard.getText()); } else { getText().replace(getSelectionEnd(), getSelectionStart(), clipboard.getText()); } }
public void ua() { EditText et=(EditText) findViewById(R.id.mainEditText1); String os =et.getText().toString(); char[] a = os.toCharArray(); StringBuffer b = new StringBuffer(""); String mo ="妮̶"; for (int i=0;i < a.length;i++) { b.append(mo.replace('妮', a[i])) ; ClipboardManager manager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); manager.setText(b); } TextView t=(TextView) findViewById(R.id.mainTextView1); t.setText(b); }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.fenlei_share: Intent intent = new Intent(); intent.setAction(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, url); startActivity(Intent.createChooser(intent, getTitle())); break; case R.id.fenlei_web_open: Intent intent1 = new Intent(); intent1.setAction(Intent.ACTION_VIEW); intent1.setData(Uri.parse(url)); startActivity(intent1); break; case R.id.fenlei_copy_link: ClipboardManager clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); ClipData clipData = ClipData.newRawUri("label", Uri.parse(url)); clipboardManager.setPrimaryClip(clipData); Snackbar.make(mWebView, "已复制到黏贴版", Snackbar.LENGTH_SHORT).show(); break; } return true; }
/** * 实现文本复制功能 */ public static void copy(String content, Context context) { if (context == null || content == null) { return; } // 得到剪贴板管理器 ClipboardManager cmb = (ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); if (cmb == null) { return; } try { cmb.setPrimaryClip(ClipData.newPlainText(null, content.trim())); } catch (Exception e) { LogUtils.e(e); } }
@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; }
public void clicksvip() { EditText et=(EditText) findViewById(R.id.mainEditText1); String os =et.getText().toString(); char[] a = os.toCharArray(); StringBuffer b = new StringBuffer(""); String mo ="❦H❧"; for (int i=0;i < a.length;i++) { b.append(mo.replace('H', a[i])) ; ClipboardManager manager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); manager.setText(b); } TextView t=(TextView) findViewById(R.id.mainTextView1); t.setText(b); }
public void cclick() { EditText et=(EditText) findViewById(R.id.mainEditText1); String os =et.getText().toString(); char[] a = os.toCharArray(); StringBuffer b = new StringBuffer(""); String mo ="敏ۣۖ"; for (int i=0;i < a.length;i++) { b.append(mo.replace('敏', a[i])) ; ClipboardManager manager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); manager.setText(b); } TextView t=(TextView) findViewById(R.id.mainTextView1); t.setText(b); }
public void dclick() { EditText et=(EditText) findViewById(R.id.mainEditText1); String os =et.getText().toString(); char[] a = os.toCharArray(); StringBuffer b = new StringBuffer(""); String mo ="爱\n"; for (int i=0;i < a.length;i++) { b.append(mo.replace('爱', a[i])) ; ClipboardManager manager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); manager.setText(b); } TextView t=(TextView) findViewById(R.id.mainTextView1); t.setText(b); }
public void eclick() { EditText et=(EditText) findViewById(R.id.mainEditText1); String os =et.getText().toString(); char[] a = os.toCharArray(); StringBuffer b = new StringBuffer(""); String mo =" 爱"; for (int i=0;i < a.length;i++) { b.append(mo.replace('爱', a[i])) ; ClipboardManager manager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); manager.setText(b); } TextView t=(TextView) findViewById(R.id.mainTextView1); t.setText(b);}
private String getClipboardText() { ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); String text = ""; try { if (clipboard != null && clipboard.hasText()) { CharSequence tmpText = clipboard.getText(); clipboard.setText(tmpText); if (tmpText != null && tmpText.length() > 0) { text = tmpText.toString().trim(); } } } catch (Exception e) { e.printStackTrace(); text = ""; } return text; }
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(); } }; }
@Override public void onResponse(String response) { if (!mUploadFragment.isAdded()) { return; } mUploadFragment.progressEnd(); String resultString = mUploadFragment.genShareText(response); mUploadFragment.setResultText(resultString); mUploadFragment.setMainInfo(R.string.share_success); ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context .CLIPBOARD_SERVICE); ClipData data = ClipData.newPlainText(CLIP_LABEL, resultString); clipboardManager.setPrimaryClip(data); mUploadFragment.setBackgroundClickListener(null); mUploadFragment.setListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(); intent.setAction(INTENT_START_CAMERA_ACTIVITY); intent.putExtra(BITMAP_FILE, saveFilePath); LocalBroadcastManager.getInstance(EditImageActivity.this).sendBroadcast(intent); finish(); } }); Log.d(TAG, String.valueOf(response)); }
/** * 解析成功的文本信息 * * @param text */ private void handleText(String text) { // 获取到扫描的到text信息,可以根据正则表达式判断进行哪种处理 /* 1. url -> (1) contains('scan_login') 使用okhttp GET request ; (2) contains('oschina.net') webView跳转 * 2. text -> (1) matches("^\\{.*")) 说明是Json格式, 解析json为JavaBean,根据JavaBean的类型调用okhttp处理请求如: 签到; (2) 复制普通文本 */ ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); ClipData mClipData = ClipData.newPlainText("myLabel", text); // 复制到剪切板 clipboardManager.setPrimaryClip(mClipData); // 剪贴板的数据改变监听器 clipboardManager.addPrimaryClipChangedListener(new ClipboardManager.OnPrimaryClipChangedListener() { @Override public void onPrimaryClipChanged() { System.out.println("======> 剪切板数据改变 <====== "); } }); // 移除指定的剪贴板数据改变监听器 // cbm.removePrimaryClipChangedListener(listener); Toast.makeText(this, text, Toast.LENGTH_SHORT).show(); // 处理完之后, 要么finish Activity, 要么 handler.sendEmptyMessage(R.id.restart_preview); restartPreviewAfterDelay(3000); }
public String loadFromClipboard(Context context) { ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE); if (clipboardManager.hasPrimaryClip() == false) { return null; } ClipData clipData = clipboardManager.getPrimaryClip(); ClipData.Item item = null; if (clipData.getItemCount() >= 1) { item = clipData.getItemAt(0); } if (item == null || item.getText() == null) { return null; } String clipText = (String) item.getText().toString(); if (TextUtils.isEmpty(clipText)) { return null; } return clipText; }
/** * 返回 {@link ClipboardManager} */ public static ClipboardManager getClipboardManager() { if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { throw new ClipboardUnsupportedException(); } return (ClipboardManager) get(CLIPBOARD_SERVICE); }
private void copyContent() { final String text = getText(); ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(ClipData.newPlainText(null, text)); String toastText = String.format(getResources().getString(R.string.text_copied_toast), text); Toast.makeText(getContext(), toastText, Toast.LENGTH_SHORT).show(); }
private void copyDeviceInfoToClipBoard() { ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText(getString(R.string.device_info), deviceInfo.toMarkdown()); clipboard.setPrimaryClip(clip); Toast.makeText(BugReportActivity.this, R.string.copied_device_info_to_clipboard, Toast.LENGTH_LONG).show(); }
public static void copyText(InputConnection inputConnection) { try { ClipData myClip = ClipData.newPlainText("SwiftBraille Copied", getAllInputText(inputConnection)); ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); clipboardManager.setPrimaryClip(myClip); defaultTextSpeech.speechText(context.getString(R.string.text_copied)); } catch (Exception e) { e.printStackTrace(); } }
@Override public void onAttach(final Activity activity) { super.onAttach(activity); this.activity = (AddressBookActivity) activity; this.application = (WalletApplication) activity.getApplication(); this.config = application.getConfiguration(); this.wallet = application.getWallet(); this.clipboardManager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); this.contentResolver = activity.getContentResolver(); }
/**复制文字 * @param context * @param value */ public static void copyText(Context context, String value) { if (context == null || StringUtil.isNotEmpty(value, true) == false) { Log.e(TAG, "copyText context == null || StringUtil.isNotEmpty(value, true) == false >> return;"); return; } ClipData cD = ClipData.newPlainText("simple text", value); ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); clipboardManager.setPrimaryClip(cD); showShortToast(context, "已复制\n" + value); }
@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(); }
/** * 开始监听剪贴板 */ 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()); } } } } }); }
@SuppressWarnings("deprecation") public static void copyTextToBoard(Context context, String string) { if (TextUtils.isEmpty(string)) return; ClipboardManager clip = (ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); clip.setText(string); }
/** * 从剪切板获取文本 * * @return 切板获取文本 ,未获取到时返回"" */ public static String getTextFromClipboar() { ClipboardManager clipboardManager = (ClipboardManager) UtilManager.getContext() .getSystemService(Context.CLIPBOARD_SERVICE); if (clipboardManager.hasPrimaryClip()) { return clipboardManager.getPrimaryClip().getItemAt(0).getText().toString(); } return ""; }
private void copy() { if (null == shortUrl || shortUrl.equals("")) return; ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); if (null == clipboard) return; ClipData clip = ClipData.newPlainText(getString(R.string.app_name), shortUrl); clipboard.setPrimaryClip(clip); Toast.makeText(this, R.string.copied, Toast.LENGTH_LONG).show(); }
@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; }
public static void copyToClipBoard(Context context, String text, String success) { ClipData clipData = ClipData.newPlainText("meizhi_copy", text); ClipboardManager manager = (ClipboardManager) context.getSystemService( Context.CLIPBOARD_SERVICE); manager.setPrimaryClip(clipData); Toast.makeText(context, success, Toast.LENGTH_SHORT).show(); }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) public static String getText(Context context, int index) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = clipboard.getPrimaryClip(); if (clip != null && clip.getItemCount() > index) { return String.valueOf(clip.getItemAt(0).coerceToText(context)); } return null; }