@SuppressLint("NewApi") @Override public boolean onTextContextMenuItem(int id) { if (id == android.R.id.paste) { ClipboardManager clip = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); if (clip == null || clip.getText() == null) { return false; } String text = clip.getText().toString(); if (text.startsWith(ChatActivity.COPY_IMAGE)) { // intent.setDataAndType(Uri.fromFile(new File("/sdcard/mn1.jpg")), // "image/*"); text = text.replace(ChatActivity.COPY_IMAGE, ""); Intent intent = new Intent(context, AlertDialog.class); String str = context.getResources().getString(R.string.Send_the_following_pictures); intent.putExtra("title", str); intent.putExtra("forwardImage", text); intent.putExtra("cancel", true); ((Activity) context) .startActivityForResult(intent, ChatActivity.REQUEST_CODE_COPY_AND_PASTE); // clip.setText(""); } } return super.onTextContextMenuItem(id); }
@Override protected void onPostExecute(String ayah) { Activity activity = getActivity(); if (ayah != null && activity != null) { ayah = "(" + ayah + ")" + " " + "[" + QuranInfo.getSuraName(activity, this.sura, true) + " : " + this.ayah + "]" + activity.getString(R.string.via_string); if (copy) { ClipboardManager cm = (ClipboardManager) activity.getSystemService(Activity.CLIPBOARD_SERVICE); cm.setText(ayah); Toast.makeText( activity, activity.getString(R.string.ayah_copied_popup), Toast.LENGTH_SHORT) .show(); } else { final Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, ayah); startActivity(Intent.createChooser(intent, activity.getString(R.string.share_ayah))); } } mCurrentTask = null; }
@SuppressWarnings("deprecation") @SuppressLint("NewApi") /* * Cancel clipboard content */ public void cancelClipBoardContent() { if (android.os.Build.VERSION.SDK_INT < 11) { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); if (clipboard != null) { clipboard.setText(""); } } else { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); if (clipboard != null && clipboard.getPrimaryClip() != null && clipboard.getPrimaryClip().getItemCount() > 0) { android.content.ClipData clip = android.content.ClipData.newPlainText("", ""); clipboard.setPrimaryClip(clip); } } }
private boolean canPaste() { ClipboardManager clip = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); if (clip.hasText()) { return true; } return false; }
public void onClick() { @SuppressWarnings("deprecation") ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(mRenderer.renderEventItem(getObject()).toString()); Toast.makeText(getActivity(), R.string.text_copied, Toast.LENGTH_SHORT).show(); }
@Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.service_back: pluginManagerView.closePlugin(); break; case R.id.service_copy_qq: // 从API11开始android推荐使用android.content.ClipboardManager // 为了兼容低版本我们这里使用旧版的android.text.ClipboardManager,虽然提示deprecated,但不影响使用。 ClipboardManager cm = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); // 将文本内容放到系统剪贴板里。 cm.setText(tvQQ.getText()); Toast.makeText(getContext(), "复制成功,可以联系我们了。", Toast.LENGTH_LONG).show(); break; case R.id.service_send: String url = "mqqwpa://im/chat?chat_type=wpa&uin=3508928085"; Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PluginEntry.getTargetGame().startActivity(intent); break; default: break; } }
@Override public boolean onContextItemSelected(MenuItem item) { String value = item.getIntent().getStringExtra(MENU_VALUE); switch (item.getItemId()) { case R.id.copy_ssid: { ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(value); Toast.makeText(getActivity(), getString(R.string.msg_copied, value), Toast.LENGTH_SHORT) .show(); return true; } case R.id.copy_mac: { ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(value); Toast.makeText(getActivity(), getString(R.string.msg_copied, value), Toast.LENGTH_SHORT) .show(); return true; } case R.id.use_mac: mCallbacks.onItemSelected(value); return true; } return super.onContextItemSelected(item); }
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { finish(); overridePendingTransition(R.anim.fade_in, R.anim.slide_out_right); return true; } else if (item.getItemId() == R.id.action_browser) { Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse( getIntent() .getDataString() .replace(getResources().getString(R.string.IMAGE_SCHEME), "http"))); startActivity(intent); finish(); return true; } else if (item.getItemId() == R.id.action_save) { DownloadManager d = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); if (d != null) { DownloadManager.Request r = new DownloadManager.Request( Uri.parse( getIntent() .getDataString() .replace(getResources().getString(R.string.IMAGE_SCHEME), "http"))); if (Build.VERSION.SDK_INT >= 11) { r.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); r.allowScanningByMediaScanner(); } d.enqueue(r); } return true; } else if (item.getItemId() == R.id.action_copy) { if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboard.setText( getIntent() .getDataString() .replace(getResources().getString(R.string.IMAGE_SCHEME), "http")); } else { @SuppressLint("ServiceCast") android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData.newRawUri( "IRCCloud Image URL", Uri.parse( getIntent() .getDataString() .replace(getResources().getString(R.string.IMAGE_SCHEME), "http"))); clipboard.setPrimaryClip(clip); } Toast.makeText(ImageViewerActivity.this, "Link copied to clipboard", Toast.LENGTH_SHORT) .show(); } return super.onOptionsItemSelected(item); }
public void onClick(View v) { ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); // Should always be true, because we grey out the clipboard button in onResume() if it's // empty if (clipboard.hasText()) { launchSearch(clipboard.getText().toString()); } }
public void copyHoroscopeToClipboard() { TextView textView = (TextView) findViewById(R.id.tvSagittariusToday); ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); clipboardManager.setText(textView.getText()); Toast toast = Toast.makeText(getApplicationContext(), "Successfully copied", 200); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); }
@Override public void handlePaste() { final ClipboardManager clipboardManager = (ClipboardManager) inputMethodService.getSystemService(Context.CLIPBOARD_SERVICE); final CharSequence text = clipboardManager.getText(); if (!Strings.isEmpty(text)) { commitText(text, 1); } }
private void processSelectionOption(int which, TLRPC.TL_messages_stickerSet stickerSet) { if (which == 0) { StickersQuery.removeStickersSet( getParentActivity(), stickerSet.set, (stickerSet.set.flags & 2) == 0 ? 1 : 2); } else if (which == 1) { StickersQuery.removeStickersSet(getParentActivity(), stickerSet.set, 0); } else if (which == 2) { try { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra( Intent.EXTRA_TEXT, String.format( Locale.US, "https://telegram.me/addstickers/%s", stickerSet.set.short_name)); getParentActivity() .startActivityForResult( Intent.createChooser( intent, LocaleController.getString("StickersShare", R.string.StickersShare)), 500); } catch (Exception e) { FileLog.e("tmessages", e); } } else if (which == 3) { try { if (Build.VERSION.SDK_INT < 11) { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) ApplicationLoader.applicationContext.getSystemService( Context.CLIPBOARD_SERVICE); clipboard.setText( String.format( Locale.US, "https://telegram.me/addstickers/%s", stickerSet.set.short_name)); } else { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext.getSystemService( Context.CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData.newPlainText( "label", String.format( Locale.US, "https://telegram.me/addstickers/%s", stickerSet.set.short_name)); clipboard.setPrimaryClip(clip); } Toast.makeText( getParentActivity(), LocaleController.getString("LinkCopied", R.string.LinkCopied), Toast.LENGTH_SHORT) .show(); } catch (Exception e) { FileLog.e("tmessages", e); } } }
public static void setClipboardString(String string, Context context) { try { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(string); } catch (Exception e) { // Ingore // todo insert uncaught error handler } }
public static String getClipboard(Context context) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); CharSequence csText = clipboard.getText(); if (csText == null) { return ""; } return csText.toString(); }
public static void clearClipboardString(Activity activity) { try { ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(""); } catch (Exception e) { // todo insert uncaught error handler // Ignore } }
public static void copy2Clipboard(String str2Copy, Context context) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) { android.content.ClipboardManager clipboardManager = (android.content.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); clipboardManager.setText(str2Copy); } else { android.text.ClipboardManager clipboardManager = (android.text.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); clipboardManager.setText(str2Copy); } }
public static void copyToClipboard(Context context, String text) throws SamsungClipboardException { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); try { clipboard.setText(text); } catch (NullPointerException e) { throw new SamsungClipboardException(e); } }
private void doPaste() { ClipboardManager clip = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); CharSequence paste = clip.getText(); byte[] utf8; try { utf8 = paste.toString().getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { Log.e(TermDebug.LOG_TAG, "UTF-8 encoding not found."); return; } getCurrentTermSession().write(paste.toString()); }
// Briefly show the contents of the barcode, then handle the result outside Barcode Scanner. private void handleDecodeExternally(Result rawResult, Bitmap barcode) { viewfinderView.drawResultBitmap(barcode); // Since this message will only be shown for a second, just tell the user what kind of // barcode was found (e.g. contact info) rather than the full contents, which they won't // have time to read. ResultHandler resultHandler = ResultHandlerFactory.makeResultHandler(this, rawResult); statusView.setText(getString(resultHandler.getDisplayTitle())); if (copyToClipboard) { ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboard.setText(resultHandler.getDisplayContents()); } if (source == Source.NATIVE_APP_INTENT) { // Hand back whatever action they requested - this can be changed to Intents.Scan.ACTION when // the deprecated intent is retired. Intent intent = new Intent(getIntent().getAction()); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); intent.putExtra(Intents.Scan.RESULT, rawResult.toString()); intent.putExtra(Intents.Scan.RESULT_FORMAT, rawResult.getBarcodeFormat().toString()); // crop barcode bitmap by 5pixels on each side barcode = Bitmap.createBitmap(barcode, 5, 5, barcode.getWidth() - 10, barcode.getHeight() - 10); ByteArrayOutputStream bitmapOutStream = new ByteArrayOutputStream(); barcode.compress(Bitmap.CompressFormat.JPEG, 35, bitmapOutStream); intent.putExtra(Intents.Scan.RESULT_BITMAP_BYTES, bitmapOutStream.toByteArray()); Message message = Message.obtain(handler, R.id.return_scan_result); message.obj = intent; handler.sendMessageDelayed(message, INTENT_RESULT_DURATION); } else if (source == Source.PRODUCT_SEARCH_LINK) { // Reformulate the URL which triggered us into a query, so that the request goes to the same // TLD as the scan URL. Message message = Message.obtain(handler, R.id.launch_product_query); int end = sourceUrl.lastIndexOf("/scan"); message.obj = sourceUrl.substring(0, end) + "?q=" + resultHandler.getDisplayContents().toString() + "&source=zxing"; handler.sendMessageDelayed(message, INTENT_RESULT_DURATION); } else if (source == Source.ZXING_LINK) { // Replace each occurrence of RETURN_CODE_PLACEHOLDER in the returnUrlTemplate // with the scanned code. This allows both queries and REST-style URLs to work. Message message = Message.obtain(handler, R.id.launch_product_query); message.obj = returnUrlTemplate.replace( RETURN_CODE_PLACEHOLDER, resultHandler.getDisplayContents().toString()); handler.sendMessageDelayed(message, INTENT_RESULT_DURATION); } }
// Briefly show the contents of the barcode, then handle the result outside Barcode Scanner. private void handleDecodeExternally( Result rawResult, ResultHandler resultHandler, Bitmap barcode) { viewfinderView.drawResultBitmap(barcode); // Since this message will only be shown for a second, just tell the user what kind of // barcode was found (e.g. contact info) rather than the full contents, which they won't // have time to read. // TODO // TODO statusView.setText(getString(resultHandler.getDisplayTitle())); if (copyToClipboard && !resultHandler.areContentsSecure()) { ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboard.setText(resultHandler.getDisplayContents()); } if (source == Source.NATIVE_APP_INTENT) { // Hand back whatever action they requested - this can be changed to Intents.Scan.ACTION when // the deprecated intent is retired. Intent intent = new Intent(getIntent().getAction()); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); intent.putExtra(Intents.Scan.RESULT, rawResult.toString()); intent.putExtra("RTN_CONTENT", resultHandler.getDisplayContents()); intent.putExtra(Intents.Scan.RESULT_FORMAT, rawResult.getBarcodeFormat().toString()); byte[] rawBytes = rawResult.getRawBytes(); if (rawBytes != null && rawBytes.length > 0) { intent.putExtra(Intents.Scan.RESULT_BYTES, rawBytes); } Message message = Message.obtain(handler, R.id.return_scan_result); message.obj = intent; handler.sendMessageDelayed(message, INTENT_RESULT_DURATION); } else if (source == Source.PRODUCT_SEARCH_LINK) { // Reformulate the URL which triggered us into a query, so that the request goes to the same // TLD as the scan URL. Message message = Message.obtain(handler, R.id.launch_product_query); int end = sourceUrl.lastIndexOf("/scan"); message.obj = sourceUrl.substring(0, end) + "?q=" + resultHandler.getDisplayContents().toString() + "&source=zxing"; handler.sendMessageDelayed(message, INTENT_RESULT_DURATION); } else if (source == Source.ZXING_LINK) { // Replace each occurrence of RETURN_CODE_PLACEHOLDER in the returnUrlTemplate // with the scanned code. This allows both queries and REST-style URLs to work. Message message = Message.obtain(handler, R.id.launch_product_query); message.obj = returnUrlTemplate.replace( RETURN_CODE_PLACEHOLDER, resultHandler.getDisplayContents().toString()); handler.sendMessageDelayed(message, INTENT_RESULT_DURATION); } }
/** * Copy debug information about the device to the clipboard * * @return debugInfo */ public String copyDebugInfo() { StringBuilder sb = new StringBuilder(); // KanjiDroid Version sb.append("KanjiDroid Version = ").append(VersionUtils.getPkgVersionName()).append("\n\n"); // Android SDK sb.append("Android Version = " + Build.VERSION.RELEASE).append("\n\n"); // ACRA install ID sb.append("ACRA UUID = ").append(Installation.id(this)).append("\n"); String debugInfo = sb.toString(); ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(debugInfo); return debugInfo; }
@Override protected void onResume() { super.onResume(); ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); if (clipboard.hasText()) { clipboardButton.setEnabled(true); clipboardButton.setText(R.string.button_share_clipboard); } else { clipboardButton.setEnabled(false); clipboardButton.setText(R.string.button_clipboard_empty); } }
/** * Copy given context to device clipboard * * @param context app context * @param title title/label of this clipboard * @param content text to be copied */ public static void copyToClipboard(@NonNull Context context, String title, String content) { if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) { @SuppressWarnings("deprecation") android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(content); } else { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData.newPlainText(title, content); clipboard.setPrimaryClip(clip); } }
public static String getClipboardString(Activity activity) { try { ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); CharSequence content = clipboard.getText(); if (content == null) { return ""; } return content.toString(); } catch (Exception e) { // todo insert uncaught error handler return ""; } }
public boolean onContextItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.chat_contextmenu_copy_text: ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); cm.setText(getMessageFromContextMenu(item)); return true; case R.id.chat_contextmenu_resend: sendMessage(getMessageFromContextMenu(item).toString()); Log.d(TAG, "resend!"); return true; default: return super.onContextItemSelected((android.view.MenuItem) item); } }
public void copyTextToClipboard(TextView txtView) { int sdk = android.os.Build.VERSION.SDK_INT; if (sdk < android.os.Build.VERSION_CODES.HONEYCOMB) { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(txtView.getText().toString()); } else { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData.newPlainText("text label", txtView.getText().toString()); clipboard.setPrimaryClip(clip); } }
@SuppressWarnings("deprecation") @SuppressLint("NewApi") protected void copyToClipboard() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { ClipData data = ClipData.newPlainText("feed_text", mFeedItem.text); android.content.ClipboardManager mClipboard = (android.content.ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); mClipboard.setPrimaryClip(data); } else { android.text.ClipboardManager mClipboard = (android.text.ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); mClipboard.setText(mFeedItem.text); } }
@SuppressLint("NewApi") @SuppressWarnings("deprecation") public void copyToClipboard(String str) { if (android.os.Build.VERSION.SDK_INT < 11) { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboard.setText(str); } else { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboard.setText(str); } Toast toast = Toast.makeText(this, R.string.text_copied_to_clipboard, Toast.LENGTH_SHORT); toast.show(); }
@Override public CharSequence getText() { if (mClipboardManager == null) { return null; } return mClipboardManager.getText(); }
@Override public boolean onContextItemSelected(MenuItem item) { int pos = ((AdapterContextMenuInfo) item.getMenuInfo()).position; LogItem log = (LogItem) getListView().getItemAtPosition(pos); if (log != null && log.getMsg() != null) { ClipboardManager cm = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); if (cm != null) { cm.setText(log.getMsg()); Util.shortToast(this, R.string.copied_hint); } } return true; }