android.text.ClipboardManager Java Examples
The following examples show how to use
android.text.ClipboardManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChatFragment.java From jitsi-android with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @SuppressWarnings("deprecation") @Override public boolean onContextItemSelected(MenuItem item) { if(item.getItemId() == R.id.copy_to_clipboard) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); // Clicked position must be aligned to list headers count int position = info.position - chatListView.getHeaderViewsCount(); // Gets clicked message ChatMessage clickedMsg = chatListAdapter.getMessage(position); // Copy message content to clipboard ClipboardManager clipboardManager = (ClipboardManager) getActivity() .getSystemService(Context.CLIPBOARD_SERVICE); clipboardManager.setText(clickedMsg.getContentForClipboard()); return true; } return super.onContextItemSelected(item); }
Example #2
Source File: PasteEditText.java From school_shop with MIT License | 6 votes |
@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); }
Example #3
Source File: SubmitLogFragment.java From libpastelog with GNU General Public License v3.0 | 6 votes |
private TextView handleBuildSuccessTextView(final String logUrl) { TextView showText = new TextView(getActivity()); showText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); showText.setPadding(15, 30, 15, 30); showText.setText(getString(R.string.log_submit_activity__copy_this_url_and_add_it_to_your_issue, logUrl)); showText.setAutoLinkMask(Activity.RESULT_OK); showText.setMovementMethod(LinkMovementMethod.getInstance()); showText.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { @SuppressWarnings("deprecation") ClipboardManager manager = (ClipboardManager) getActivity().getSystemService(Activity.CLIPBOARD_SERVICE); manager.setText(logUrl); Toast.makeText(getActivity(), R.string.log_submit_activity__copied_to_clipboard, Toast.LENGTH_SHORT).show(); return true; } }); Linkify.addLinks(showText, Linkify.WEB_URLS); return showText; }
Example #4
Source File: ManageScriptsActivity.java From MCPELauncher with Apache License 2.0 | 6 votes |
private void reportError(final Throwable t) { this.runOnUiThread(new Runnable() { public void run() { final StringWriter strWriter = new StringWriter(); PrintWriter pWriter = new PrintWriter(strWriter); if (t instanceof RhinoException) { String lineSource = ((RhinoException) t).lineSource(); if (lineSource != null) pWriter.println(lineSource); } t.printStackTrace(pWriter); new AlertDialog.Builder(ManageScriptsActivity.this).setTitle(R.string.manage_patches_import_error).setMessage(strWriter.toString()). setPositiveButton(android.R.string.ok, null). setNeutralButton(android.R.string.copy, new DialogInterface.OnClickListener() { public void onClick(DialogInterface aDialog, int button) { ClipboardManager mgr = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); mgr.setText(strWriter.toString()); } }). show(); } }); }
Example #5
Source File: PasteEditText.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 6 votes |
@SuppressLint("NewApi") @Override public boolean onTextContextMenuItem(int id) { if(id == android.R.id.paste){ @SuppressWarnings("deprecation") ClipboardManager clip = (ClipboardManager)getContext().getSystemService(Context.CLIPBOARD_SERVICE); 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,FXAlertDialog.class); intent.putExtra("title", "发送以下图片?"); intent.putExtra("forwardImage", text); intent.putExtra("cancel", true); ((Activity)context).startActivityForResult(intent,ChatActivity.REQUEST_CODE_COPY_AND_PASTE); // clip.setText(""); } } return super.onTextContextMenuItem(id); }
Example #6
Source File: SearchResultFragment.java From MCPDict with MIT License | 6 votes |
@Override public boolean onContextItemSelected(MenuItem item) { if (selectedFragment != this) return false; if (COPY_MENU_ITEM_TO_MASK.containsKey(item.getItemId())) { // Generate the text to copy to the clipboard String text = getCopyText(selectedEntry, COPY_MENU_ITEM_TO_MASK.get(item.getItemId())); ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(text); String label = item.getTitle().toString().substring(2); // this is ugly String message = String.format(getString(R.string.copy_done), label); Boast.showText(getActivity(), message, Toast.LENGTH_SHORT); return true; } else if (item.getItemId() == R.id.menu_item_favorite) { selectedEntry.findViewById(R.id.button_favorite).performClick(); return true; } else { // Fall back to default behavior return false; } }
Example #7
Source File: CopyActivity.java From aedict with GNU General Public License v3.0 | 6 votes |
private void setup(final String intentkey, final int layoutid, boolean autoHide) { String content = getIntent().getStringExtra(intentkey); final View layout = findViewById(layoutid); if (MiscUtils.isBlank(content) && autoHide) { layout.setVisibility(View.GONE); } else { content = content == null ? "" : content; ((TextView) layout.findViewById(R.id.edit)).setText(content.trim()); layout.findViewById(R.id.copy).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { final String text = getSelection((TextView) layout.findViewById(R.id.edit)); final ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); cm.setText(text); final Toast toast = Toast.makeText(CopyActivity.this, AedictApp.format(R.string.copied, text), Toast.LENGTH_SHORT); toast.show(); MainActivity.launch(CopyActivity.this, text); } }); } }
Example #8
Source File: CopyActivity.java From aedict with GNU General Public License v3.0 | 5 votes |
public static void launch(Activity activity, String text1, String text2, String text3) { final Intent i = new Intent(activity, CopyActivity.class); i.putExtra(INTENTKEY_COPY1, text1); i.putExtra(INTENTKEY_COPY2, text2); i.putExtra(INTENTKEY_COPY3, text3); final ClipboardManager cm = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); i.putExtra(INTENTKEY_CLIPBOARD, cm.getText() + text1); activity.startActivity(i); }
Example #9
Source File: SnippetDetailFragment.java From android-java-snippets-rest-sample with MIT License | 5 votes |
@TargetApi(11) private void clipboard11(TextView tv) { android.content.ClipboardManager clipboardManager = (android.content.ClipboardManager) getActivity() .getSystemService(Context.CLIPBOARD_SERVICE); ClipData clipData = ClipData.newPlainText("RESTSnippets", tv.getText()); clipboardManager.setPrimaryClip(clipData); }
Example #10
Source File: MicroBlogShareClickListener.java From YiBo with Apache License 2.0 | 5 votes |
@Override public void onClick(View v) { if (status == null || status.getStatusId() == null) { return; } Intent intent = new Intent(Intent.ACTION_SEND); if (EntityUtil.hasPicture(status)) { intent.setType("image/*"); String imagePath = EntityUtil.getMaxLocalCachedPicture(status); if (StringUtil.isNotEmpty(imagePath)) { Uri uri = Uri.fromFile(new File(imagePath)); intent.putExtra(Intent.EXTRA_STREAM, uri); } else { intent.setType("text/plain"); Toast.makeText(context, context.getString(R.string.msg_blog_share_picture), Toast.LENGTH_LONG).show(); } } else { intent.setType("text/plain"); } ClipboardManager clip = (ClipboardManager)context .getSystemService(Context.CLIPBOARD_SERVICE); String statusText = extraStatus(context, status); clip.setText(statusText); intent.putExtra(Intent.EXTRA_TEXT, statusText); intent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.msg_extra_subject)); context.startActivity(intent); }
Example #11
Source File: UiHandler.java From bee with Apache License 2.0 | 5 votes |
private void initListView(ListView listView) { final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { ContentHolder contentHolder = (ContentHolder) parent.getItemAtPosition(position); clipboard.setText(contentHolder.getValue()); showToast(contentHolder.getValue() + " is copied to clipboard"); return true; } }); }
Example #12
Source File: ClipboardReadable.java From Readily with MIT License | 5 votes |
public void process(final Context context){ Looper.prepare(); //TODO: review it CAREFULLY if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){ clipboardNew = (android.content.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); processFailed = !clipboardNew.hasText(); processed = true; } else { clipboardOld = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); processFailed = !clipboardOld.hasText(); processed = true; } }
Example #13
Source File: ShareActivity.java From android-apps with MIT License | 5 votes |
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()); } }
Example #14
Source File: Toolbar.java From NFCard with GNU General Public License v3.0 | 5 votes |
public void copyPageContent(TextView textArea) { final CharSequence text = textArea.getText(); if (!TextUtils.isEmpty(text)) { ((ClipboardManager) textArea.getContext().getSystemService( Context.CLIPBOARD_SERVICE)).setText(text.toString()); ThisApplication.showMessage(R.string.info_main_copied); } }
Example #15
Source File: SearchUtils.java From aedict with GNU General Public License v3.0 | 5 votes |
/** * Configures given button to copy a text from given edit to the global * clipboard. * * @param copyButton * copies the text to the clipboard on this button press * @param textView * copies the text from this {@link TextView} */ public void setupCopyButton(final int copyButton, final int textView) { final Button btn = (Button) activity.findViewById(copyButton); final TextView text = (TextView) activity.findViewById(textView); btn.setOnClickListener(AndroidUtils.safe(activity, new View.OnClickListener() { public void onClick(View v) { final ClipboardManager cm = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); cm.setText(text.getText()); final Toast toast = Toast.makeText(activity, AedictApp.format(R.string.copied, text.getText()), Toast.LENGTH_SHORT); toast.show(); } })); }
Example #16
Source File: ScreenDimensionsFragment.java From java-android-developertools with Apache License 2.0 | 5 votes |
protected void copyscreenDimensions() { ClipboardManager clipboardManager = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); if (clipboardManager != null) { clipboardManager.setText(screenDimensions); Toast.makeText(getActivity().getApplicationContext(), "Screen dimensions copied to clipboard.", Toast.LENGTH_LONG).show(); } else { Toast.makeText(getActivity().getApplicationContext(), "Unable to get clipboard manager.", Toast.LENGTH_LONG).show(); } }
Example #17
Source File: AddActivity.java From save-for-offline with GNU General Public License v2.0 | 5 votes |
public void btn_paste(View view) { ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); if (edit_origurl.getText().length() == 0) { edit_origurl.append(clipboard.getText()); } else { edit_origurl.append(System.getProperty("line.separator") + clipboard.getText()); } }
Example #18
Source File: Toolbar.java From nfcard with GNU General Public License v3.0 | 5 votes |
public void copyPageContent(TextView textArea) { final CharSequence text = textArea.getText(); if (!TextUtils.isEmpty(text)) { ((ClipboardManager) textArea.getContext().getSystemService( Context.CLIPBOARD_SERVICE)).setText(text.toString()); ThisApplication.showMessage(R.string.info_main_copied); } }
Example #19
Source File: ClipboardUtils.java From BigApp_Discuz_Android with Apache License 2.0 | 5 votes |
/** * 实现文本复制功能 * add by wangqianzhou * * @param content */ public static void copy(Context context, String content) { // 得到剪贴板管理器 ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); if (!StringUtils.isEmptyOrNullOrNullStr(content)) { cmb.setText(content.trim()); } }
Example #20
Source File: Clipboard.java From Overchan-Android with GNU General Public License v3.0 | 5 votes |
/** * Скопировать текст в буфер обмена */ public static void copyText(Activity activity, String text) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(text); } else { CompatibilityImpl.copyToClipboardAPI11(activity, text, text); } }
Example #21
Source File: ActivityMain.java From nfcspy with GNU General Public License v3.0 | 5 votes |
private void copyLogs() { CharSequence logs = getAllLogs(); if (!TextUtils.isEmpty(logs)) { ((ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE)) .setText(logs); Toast.makeText(this, R.string.event_log_copy, Toast.LENGTH_LONG) .show(); } }
Example #22
Source File: ShareActivity.java From reacteu-app with MIT License | 5 votes |
@Override 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()); } }
Example #23
Source File: ConversationFragment.java From Silence with GNU General Public License v3.0 | 5 votes |
private void handleCopyMessage(final Set<MessageRecord> messageRecords) { List<MessageRecord> messageList = new LinkedList<>(messageRecords); Collections.sort(messageList, new Comparator<MessageRecord>() { @Override public int compare(MessageRecord lhs, MessageRecord rhs) { if (lhs.getDateReceived() < rhs.getDateReceived()) return -1; else if (lhs.getDateReceived() == rhs.getDateReceived()) return 0; else return 1; } }); StringBuilder bodyBuilder = new StringBuilder(); ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); boolean first = true; for (MessageRecord messageRecord : messageList) { String body = messageRecord.getDisplayBody().toString(); if (body != null) { if (!first) bodyBuilder.append('\n'); bodyBuilder.append(body); first = false; } } String result = bodyBuilder.toString(); if (!TextUtils.isEmpty(result)) clipboard.setText(result); }
Example #24
Source File: SnippetDetailFragment.java From Android-REST-API-Explorer with MIT License | 5 votes |
@TargetApi(11) private void clipboard11(TextView tv) { android.content.ClipboardManager clipboardManager = (android.content.ClipboardManager) getActivity() .getSystemService(Context.CLIPBOARD_SERVICE); ClipData clipData = ClipData.newPlainText("OneNote", tv.getText()); clipboardManager.setPrimaryClip(clipData); }
Example #25
Source File: SnippetDetailFragment.java From Android-REST-API-Explorer with MIT License | 5 votes |
private void clipboard(TextView tv) { int which; switch (tv.getId()) { case txt_request_url: which = req_url; break; case txt_response_headers: which = response_headers; break; case txt_response_body: which = response_body; break; default: which = UNSET; } String what = which == UNSET ? "" : getString(which) + " "; what += getString(clippy); Toast.makeText(getActivity(), what, Toast.LENGTH_SHORT).show(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { // old way ClipboardManager clipboardManager = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); clipboardManager.setText(tv.getText()); } else { clipboard11(tv); } }
Example #26
Source File: SnippetDetailFragment.java From android-java-snippets-sample with MIT License | 5 votes |
@TargetApi(11) private void clipboard11(TextView tv) { android.content.ClipboardManager clipboardManager = (android.content.ClipboardManager) getActivity() .getSystemService(Context.CLIPBOARD_SERVICE); ClipData clipData = ClipData.newPlainText("RESTSnippets", tv.getText()); clipboardManager.setPrimaryClip(clipData); }
Example #27
Source File: SnippetDetailFragment.java From android-java-snippets-sample with MIT License | 5 votes |
private void clipboard(TextView tv) { // which view are we copying to the clipboard? int which; switch (tv.getId()) { case txt_request_url: // the url field which = code_snippet; break; case txt_response_body: // the response body which = raw_object; break; default: which = UNSET; // don't assign a prefix } // if we know which view we're copying, prefix it with useful info String what = which == UNSET ? "" : getString(which) + " "; // concat the clipboard data to this String what += getString(clippy); // inform the user that data was added to the clipboard Toast.makeText( getActivity(), what, Toast.LENGTH_SHORT ).show(); // depending on our API, do it one way or another... if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { // old way ClipboardManager clipboardManager = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); clipboardManager.setText(tv.getText()); } else { clipboard11(tv); } }
Example #28
Source File: ConversationFragment.java From deltachat-android with GNU General Public License v3.0 | 5 votes |
private void handleCopyMessage(final Set<DcMsg> dcMsgsSet) { List<DcMsg> dcMsgsList = new LinkedList<>(dcMsgsSet); Collections.sort(dcMsgsList, (lhs, rhs) -> Long.compare(lhs.getDateReceived(), rhs.getDateReceived())); StringBuilder result = new StringBuilder(); DcMsg prevMsg = new DcMsg(dcContext, DcMsg.DC_MSG_TEXT); for (DcMsg msg : dcMsgsList) { if (result.length() > 0) { result.append("\n\n"); } if (msg.getFromId() != prevMsg.getFromId()) { DcContact contact = dcContext.getContact(msg.getFromId()); result.append(contact.getDisplayName()).append(":\n"); } if(msg.getType() == DcMsg.DC_MSG_TEXT) { result.append(msg.getText()); } else { result.append(msg.getSummarytext(10000000)); } prevMsg = msg; } if (result.length() > 0) { try { ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(result.toString()); Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.copied_to_clipboard), Toast.LENGTH_LONG).show(); } catch (Exception e) { e.printStackTrace(); } } }
Example #29
Source File: ClipboardHelper.java From GankMeizhi with Apache License 2.0 | 5 votes |
/** * 实现文本复制功能 * * @param content */ @SuppressWarnings("deprecation") public static void copy(Context context, @NonNull String content) { // 得到剪贴板管理器 ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); cmb.setText(content.trim()); }
Example #30
Source File: FreeScrollingTextField.java From CodeEditor with Apache License 2.0 | 5 votes |
private void initView() { _fieldController = this.new TextFieldController(); _clipboardManager = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); _brush = new Paint(); _brush.setAntiAlias(true); _brush.setTextSize(BASE_TEXT_SIZE_PIXELS); _brushLine = new Paint(); _brushLine.setAntiAlias(true); _brushLine.setTextSize(BASE_TEXT_SIZE_PIXELS); //setBackgroundColor(_colorScheme.getColor(Colorable.BACKGROUND)); setLongClickable(true); setFocusableInTouchMode(true); setHapticFeedbackEnabled(true); _rowLis = new OnRowChangedListener() { @Override public void onRowChanged(int newRowIndex) { // Do nothing } }; _selModeLis = new OnSelectionChangedListener() { @Override public void onSelectionChanged(boolean active, int selStart, int selEnd) { // TODO: Implement this method if (active) _clipboardPanel.show(); else _clipboardPanel.hide(); } }; resetView(); _clipboardPanel = new ClipboardPanel(this); _autoCompletePanel = new AutoCompletePanel(this); //TODO find out if this function works //setScrollContainer(true); invalidate(); }