List of usage examples for android.text ClipboardManager setText
public abstract void setText(CharSequence text);
From source file:de.electricdynamite.pasty.ClipboardItem.java
public void copyToClipboard(ClipboardManager clipboard) { clipboard.setText(this.getText()); }
From source file:com.hivewallet.androidclient.wallet.ui.WalletAddressDialogFragment.java
private void handleCopy() { ClipboardManager clipboardManager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); clipboardManager.setText(address); activity.toast(R.string.wallet_address_dialog_copy_address); }
From source file:org.jboss.aerogear.crypto.android.demo.fragments.DetailFragment.java
private void copyToClipboard(String password) { if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getActivity() .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(password); } else {//ww w. ja va 2 s.c om android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getActivity() .getSystemService(Context.CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData.newPlainText(getString(R.string.password), password); clipboard.setPrimaryClip(clip); } }
From source file:es.glasspixel.wlanaudit.activities.KeyListActivity.java
/** * Handles the event of clicking on a list element. *///from w w w. j a v a2 s. com protected void onListItemClick(ListView l, View v, int position, long id) { // Clipboard copy ClipboardManager clipBoard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipBoard.setText(mKeyList.get(position)); // Copy notification Toast notificationToast = Toast.makeText(this, getResources().getString(R.string.key_copy_success), Toast.LENGTH_SHORT); notificationToast.setGravity(Gravity.CENTER, 0, 0); notificationToast.show(); }
From source file:org.emergent.android.weave.PasswordListFragment.java
@Override public void onListItemClick(ListView l, View v, int position, long id) { Activity activity = getActivity();//w w w.j a v a 2s. c o m if (activity == null) { Log.w(TAG, "onListItemClick: Activity was null!"); return; } ListAdapter listAdapter = getListAdapter(); Cursor cursor = (Cursor) listAdapter.getItem(position); String pword = cursor.getString(cursor.getColumnIndex(Passwords.Columns.PASSWORD)); ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(pword); String msg = "Password copied to clipboard."; Toast toast = Toast.makeText(activity, msg, Toast.LENGTH_SHORT); toast.show(); }
From source file:com.ryan.ryanreader.reddit.prepared.RedditPreparedPost.java
public static void onActionMenuItemSelected(final RedditPreparedPost post, final Fragment fragmentParent, final Action action) { final Activity activity = fragmentParent.getSupportActivity(); switch (action) { case UPVOTE:/* ww w. j a v a 2s. c o m*/ post.action(activity, RedditAPI.RedditAction.UPVOTE); break; case DOWNVOTE: post.action(activity, RedditAPI.RedditAction.DOWNVOTE); break; case UNVOTE: post.action(activity, RedditAPI.RedditAction.UNVOTE); break; case SAVE: post.action(activity, RedditAPI.RedditAction.SAVE); break; case UNSAVE: post.action(activity, RedditAPI.RedditAction.UNSAVE); break; case HIDE: post.action(activity, RedditAPI.RedditAction.HIDE); break; case UNHIDE: post.action(activity, RedditAPI.RedditAction.UNHIDE); break; case REPORT: new AlertDialog.Builder(activity).setTitle(R.string.action_report) .setMessage(R.string.action_report_sure) .setPositiveButton(R.string.action_report, new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int which) { post.action(activity, RedditAPI.RedditAction.REPORT); // TODO update the view to show the result // TODO don't forget, this also hides } }).setNegativeButton(R.string.dialog_cancel, null).show(); break; case EXTERNAL: { final Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(post.url)); activity.startActivity(intent); break; } case SELFTEXT_LINKS: { final HashSet<String> linksInComment = LinkHandler .computeAllLinks(StringEscapeUtils.unescapeHtml4(post.src.selftext)); if (linksInComment.isEmpty()) { General.quickToast(activity, R.string.error_toast_no_urls_in_self); } else { final String[] linksArr = linksInComment.toArray(new String[linksInComment.size()]); final AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setItems(linksArr, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { LinkHandler.onLinkClicked(activity, linksArr[which], false, post.src); dialog.dismiss(); } }); final AlertDialog alert = builder.create(); alert.setTitle(R.string.action_selftext_links); alert.setCanceledOnTouchOutside(true); alert.show(); } break; } case SAVE_IMAGE: { final RedditAccount anon = RedditAccountManager.getAnon(); CacheManager.getInstance(activity) .makeRequest(new CacheRequest(General.uriFromString(post.imageUrl), anon, null, Constants.Priority.IMAGE_VIEW, 0, CacheRequest.DownloadType.IF_NECESSARY, Constants.FileType.IMAGE, false, false, false, activity) { @Override protected void onCallbackException(Throwable t) { BugReportActivity.handleGlobalError(context, t); } @Override protected void onDownloadNecessary() { General.quickToast(context, R.string.download_downloading); } @Override protected void onDownloadStarted() { } @Override protected void onFailure(RequestFailureType type, Throwable t, StatusLine status, String readableMessage) { final RRError error = General.getGeneralErrorForFailure(context, type, t, status); General.showResultDialog(activity, error); } @Override protected void onProgress(long bytesRead, long totalBytes) { } @Override protected void onSuccess(CacheManager.ReadableCacheFile cacheFile, long timestamp, UUID session, boolean fromCache, String mimetype) { File dst = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), General.uriFromString(post.imageUrl).getPath()); if (dst.exists()) { int count = 0; while (dst.exists()) { count++; dst = new File( Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES), count + "_" + General.uriFromString(post.imageUrl).getPath().substring(1)); } } try { General.copyFile(cacheFile.getInputStream(), dst); } catch (IOException e) { notifyFailure(RequestFailureType.STORAGE, e, null, "Could not copy file"); return; } activity.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + dst.getAbsolutePath()))); General.quickToast(context, context.getString(R.string.action_save_image_success) + " " + dst.getAbsolutePath()); } }); break; } case SHARE: { final Intent mailer = new Intent(Intent.ACTION_SEND); mailer.setType("text/plain"); mailer.putExtra(Intent.EXTRA_SUBJECT, post.title); mailer.putExtra(Intent.EXTRA_TEXT, post.url); activity.startActivity(Intent.createChooser(mailer, activity.getString(R.string.action_share))); break; } case SHARE_COMMENTS: { final Intent mailer = new Intent(Intent.ACTION_SEND); mailer.setType("text/plain"); mailer.putExtra(Intent.EXTRA_SUBJECT, "Comments for " + post.title); mailer.putExtra(Intent.EXTRA_TEXT, Constants.Reddit.getUri(Constants.Reddit.PATH_COMMENTS + post.idAlone).toString()); activity.startActivity( Intent.createChooser(mailer, activity.getString(R.string.action_share_comments))); break; } case COPY: { ClipboardManager manager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); manager.setText(post.url); break; } case GOTO_SUBREDDIT: { final RedditSubreddit subreddit = new RedditSubreddit("/r/" + post.src.subreddit, "/r/" + post.src.subreddit, true); final Intent intent = new Intent(activity, PostListingActivity.class); intent.putExtra("subreddit", subreddit); activity.startActivityForResult(intent, 1); break; } case USER_PROFILE: UserProfileDialog.newInstance(post.src.author).show(activity); break; case PROPERTIES: PostPropertiesDialog.newInstance(post.src).show(activity); break; case COMMENTS: ((RedditPostView.PostSelectionListener) fragmentParent).onPostCommentsSelected(post); break; case LINK: ((RedditPostView.PostSelectionListener) fragmentParent).onPostSelected(post); break; case COMMENTS_SWITCH: if (!(activity instanceof MainActivity)) activity.finish(); ((RedditPostView.PostSelectionListener) fragmentParent).onPostCommentsSelected(post); break; case LINK_SWITCH: if (!(activity instanceof MainActivity)) activity.finish(); ((RedditPostView.PostSelectionListener) fragmentParent).onPostSelected(post); break; case ACTION_MENU: showActionMenu(activity, fragmentParent, post); break; case REPLY: final Intent intent = new Intent(activity, CommentReplyActivity.class); intent.putExtra("parentIdAndType", post.idAndType); activity.startActivity(intent); break; } }
From source file:piuk.blockchain.android.ui.SendingAddressesFragment.java
private void handleCopyToClipboard(final String address) { ClipboardManager clipboardManager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); clipboardManager.setText(address); ((AbstractWalletActivity) activity).toast(R.string.wallet_address_fragment_clipboard_msg); }
From source file:com.google.android.apps.chrometophone.C2DMReceiver.java
private Intent getLaunchIntent(Context context, String url, String title, String sel) { Intent intent = null;/*from w w w .j a v a2 s.com*/ String number = parseTelephoneNumber(sel); if (number != null) { intent = new Intent("android.intent.action.DIAL", Uri.parse("tel:" + number)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); ClipboardManager cm = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE); cm.setText(number); } else if (sel != null && sel.length() > 0) { // No intent for selection - just copy to clipboard ClipboardManager cm = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE); cm.setText(sel); } else { final String GMM_PACKAGE_NAME = "com.google.android.apps.maps"; final String GMM_CLASS_NAME = "com.google.android.maps.MapsActivity"; intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (isMapsURL(url)) { intent.setClassName(GMM_PACKAGE_NAME, GMM_CLASS_NAME); } // Fall back if we can't resolve intent (i.e. app missing) PackageManager pm = context.getPackageManager(); if (null == intent.resolveActivity(pm)) { intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } } return intent; }
From source file:devsoftprog.java.file.manager.android.fm_f_and.WebActivity.java
public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.clip: try {//from w ww .java 2 s. c o m ClipboardManager clipboard = (ClipboardManager) WebActivity.this .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(app.html); } catch (Exception e) { Toast.makeText(WebActivity.this, "error: " + e.getMessage(), Toast.LENGTH_LONG).show(); e = null; } return true; default: return true; } }
From source file:devsoftprog.java.file.manager.android.fm_f_and.WebActivity2.java
public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.clip: try {//from w w w . j a v a 2 s.c o m ClipboardManager clipboard = (ClipboardManager) WebActivity2.this .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(app.html); } catch (Exception e) { Toast.makeText(WebActivity2.this, "error: " + e.getMessage(), Toast.LENGTH_LONG).show(); e = null; } return true; default: return true; } }