List of usage examples for android.content ClipData newPlainText
static public ClipData newPlainText(CharSequence label, CharSequence text)
From source file:de.baumann.browser.Browser_right.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); final WebView.HitTestResult result = mWebView.getHitTestResult(); final String url = result.getExtra(); if (result.getType() == WebView.HitTestResult.IMAGE_TYPE) { final CharSequence[] options = { getString(R.string.context_saveImage), getString(R.string.context_shareImage), getString(R.string.context_readLater), getString(R.string.context_left) }; new AlertDialog.Builder(Browser_right.this) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); }//from w ww . j a v a 2 s . c o m }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.context_saveImage))) { if (url != null) { try { Uri source = Uri.parse(url); DownloadManager.Request request = new DownloadManager.Request(source); request.addRequestHeader("Cookie", CookieManager.getInstance().getCookie(url)); request.allowScanningByMediaScanner(); request.setNotificationVisibility( DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed! request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, helper_main.newFileName()); DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); dm.enqueue(request); Snackbar.make(mWebView, getString(R.string.context_saveImage_toast) + " " + helper_main.newFileName(), Snackbar.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); Snackbar.make(mWebView, R.string.toast_perm, Snackbar.LENGTH_SHORT).show(); } } } if (options[item].equals(getString(R.string.context_shareImage))) { if (url != null) { shareString = helper_main.newFileName(); shareFile = helper_main.newFile(mWebView); try { Uri source = Uri.parse(url); DownloadManager.Request request = new DownloadManager.Request(source); request.addRequestHeader("Cookie", CookieManager.getInstance().getCookie(url)); request.allowScanningByMediaScanner(); request.setNotificationVisibility( DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed! request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, shareString); DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); dm.enqueue(request); Snackbar.make(mWebView, getString(R.string.context_saveImage_toast) + " " + helper_main.newFileName(), Snackbar.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); Snackbar.make(mWebView, R.string.toast_perm, Snackbar.LENGTH_SHORT).show(); } registerReceiver(onComplete2, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); } } if (options[item].equals(getString(R.string.context_readLater))) { if (url != null) { if (Uri.parse(url).getHost().length() == 0) { domain = getString(R.string.app_domain); } else { domain = Uri.parse(url).getHost(); } String domain2 = domain.substring(0, 1).toUpperCase() + domain.substring(1); DbAdapter_ReadLater db = new DbAdapter_ReadLater(Browser_right.this); db.open(); if (db.isExist(mWebView.getUrl())) { Snackbar.make(editText, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show(); } else { db.insert(domain2, url, "", "", helper_main.createDate()); Snackbar.make(mWebView, R.string.bookmark_added, Snackbar.LENGTH_LONG) .show(); } } } if (options[item].equals(getString(R.string.context_left))) { if (url != null) { helper_main.switchToActivity(Browser_right.this, Browser_left.class, url, false); } } } }).show(); } else if (result.getType() == WebView.HitTestResult.SRC_ANCHOR_TYPE) { final CharSequence[] options = { getString(R.string.menu_share_link_copy), getString(R.string.menu_share_link), getString(R.string.context_readLater), getString(R.string.context_left) }; new AlertDialog.Builder(Browser_right.this) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.menu_share_link_copy))) { if (url != null) { ClipboardManager clipboard = (ClipboardManager) Browser_right.this .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(ClipData.newPlainText("text", url)); Snackbar.make(mWebView, R.string.context_linkCopy_toast, Snackbar.LENGTH_SHORT) .show(); } } if (options[item].equals(getString(R.string.menu_share_link))) { if (url != null) { Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, url); sendIntent.setType("text/plain"); Browser_right.this.startActivity(Intent.createChooser(sendIntent, getResources().getString(R.string.app_share_link))); } } if (options[item].equals(getString(R.string.context_readLater))) { if (url != null) { if (Uri.parse(url).getHost().length() == 0) { domain = getString(R.string.app_domain); } else { domain = Uri.parse(url).getHost(); } String domain2 = domain.substring(0, 1).toUpperCase() + domain.substring(1); DbAdapter_ReadLater db = new DbAdapter_ReadLater(Browser_right.this); db.open(); if (db.isExist(mWebView.getUrl())) { Snackbar.make(editText, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show(); } else { db.insert(domain2, url, "", "", helper_main.createDate()); Snackbar.make(mWebView, R.string.bookmark_added, Snackbar.LENGTH_LONG) .show(); } } } if (options[item].equals(getString(R.string.context_left))) { if (url != null) { helper_main.switchToActivity(Browser_right.this, Browser_left.class, url, false); } } } }).show(); } }
From source file:com.linkbubble.MainApplication.java
public static void copyLinkToClipboard(Context context, String urlAsString, int string) { ClipboardManager clipboardManager = (android.content.ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); if (clipboardManager != null) { ClipData clipData = ClipData.newPlainText("url", urlAsString); clipboardManager.setPrimaryClip(clipData); Toast.makeText(context, string, Toast.LENGTH_SHORT).show(); }/*from www .jav a 2 s . co m*/ }
From source file:fr.shywim.antoinedaniel.ui.fragment.VideoDetailsFragment.java
private void bindSound(View view, Cursor cursor) { AppState appState = AppState.getInstance(); final View card = view; final View downloadFrame = view.findViewById(R.id.sound_download_frame); final TextView tv = (TextView) view.findViewById(R.id.grid_text); final SquareImageView siv = (SquareImageView) view.findViewById(R.id.grid_image); final ImageView star = (ImageView) view.findViewById(R.id.ic_sound_fav); final ImageView menu = (ImageView) view.findViewById(R.id.ic_sound_menu); final String soundName = cursor .getString(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_SOUND_NAME)); String imgId = cursor.getString(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_IMAGE_NAME)); final String description = cursor.getString(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_DESC)); final boolean favorite = appState.favSounds.contains(soundName) || cursor.getInt(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_FAVORITE)) == 1; final boolean widget = appState.widgetSounds.contains(soundName) || cursor.getInt(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_WIDGET)) == 1; final boolean downloaded = cursor .getInt(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_DOWNLOADED)) != 0; new Handler().post(new Runnable() { @Override// w w w . j a va2s .c o m public void run() { ContentValues cv = new ContentValues(); File sndFile = new File(mContext.getExternalFilesDir(null) + "/snd/" + soundName + ".ogg"); if (downloaded && !sndFile.exists()) { cv.put(ProviderContract.SoundEntry.COLUMN_DOWNLOADED, 0); mContext.getContentResolver().update( Uri.withAppendedPath(ProviderConstants.SOUND_DOWNLOAD_NOTIFY_URI, soundName), cv, null, null); } } }); final View.OnClickListener playSound = new View.OnClickListener() { @Override public void onClick(View v) { String category = mContext.getString(R.string.ana_cat_sound); String action = mContext.getString(R.string.ana_act_play); Bundle extras = new Bundle(); extras.putString(SoundFragment.SOUND_TO_PLAY, soundName); extras.putBoolean(SoundFragment.LOOP, SoundUtils.isLoopingSet()); Intent intent = new Intent(mContext, SoundService.class); intent.putExtras(extras); mContext.startService(intent); AnalyticsUtils.sendEvent(category, action, soundName); } }; final View.OnClickListener downloadSound = new View.OnClickListener() { @Override public void onClick(View v) { card.setOnClickListener(null); RotateAnimation animation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); animation.setInterpolator(new BounceInterpolator()); animation.setFillAfter(true); animation.setFillEnabled(true); animation.setDuration(1000); animation.setRepeatCount(Animation.INFINITE); animation.setRepeatMode(Animation.RESTART); downloadFrame.findViewById(R.id.sound_download_icon).startAnimation(animation); DownloadService.startActionDownloadSound(mContext, soundName, new SoundUtils.DownloadResultReceiver(new Handler(), downloadFrame, playSound, this)); } }; if (downloaded) { downloadFrame.setVisibility(View.GONE); downloadFrame.findViewById(R.id.sound_download_icon).clearAnimation(); card.setOnClickListener(playSound); } else { downloadFrame.setAlpha(1); downloadFrame.findViewById(R.id.sound_download_icon).setScaleX(1); downloadFrame.findViewById(R.id.sound_download_icon).setScaleY(1); downloadFrame.setVisibility(View.VISIBLE); card.setOnClickListener(downloadSound); } menu.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final ImageView menuIc = (ImageView) v; PopupMenu popup = new PopupMenu(mContext, menuIc); Menu menu = popup.getMenu(); popup.getMenuInflater().inflate(R.menu.sound_menu, menu); if (favorite) menu.findItem(R.id.action_sound_fav).setTitle("Retirer des favoris"); if (widget) menu.findItem(R.id.action_sound_wid).setTitle("Retirer du widget"); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.action_sound_fav: SoundUtils.addRemoveFavorite(mContext, soundName); return true; case R.id.action_sound_wid: SoundUtils.addRemoveWidget(mContext, soundName); return true; /*case R.id.action_sound_add: return true;*/ case R.id.action_sound_ring: SoundUtils.addRingtone(mContext, soundName, description); return true; case R.id.action_sound_share: AnalyticsUtils.sendEvent(mContext.getString(R.string.ana_cat_soundcontext), mContext.getString(R.string.ana_act_weblink), soundName); ClipboardManager clipboard = (ClipboardManager) mContext .getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("BAD link", "http://bad.shywim.fr/" + soundName); clipboard.setPrimaryClip(clip); Toast.makeText(mContext, R.string.toast_link_copied, Toast.LENGTH_LONG).show(); return true; case R.id.action_sound_delete: SoundUtils.delete(mContext, soundName); return true; default: return false; } } }); popup.setOnDismissListener(new PopupMenu.OnDismissListener() { @Override public void onDismiss(PopupMenu menu) { menuIc.setColorFilter(mContext.getResources().getColor(R.color.text_caption_dark)); } }); menuIc.setColorFilter(mContext.getResources().getColor(R.color.black)); popup.show(); } }); tv.setText(description); siv.setTag(imgId); if (appState.favSounds.contains(soundName)) { star.setVisibility(View.VISIBLE); } else if (favorite) { star.setVisibility(View.VISIBLE); appState.favSounds.add(soundName); } else { star.setVisibility(View.INVISIBLE); } File file = new File(mContext.getExternalFilesDir(null) + "/img/" + imgId + ".jpg"); Picasso.with(mContext).load(file).placeholder(R.drawable.noimg).fit().into(siv); }
From source file:tinygsn.gui.android.ActivityViewDataNew.java
@SuppressWarnings("deprecation") private void copyTextToClipboard(String text) { int sdk = android.os.Build.VERSION.SDK_INT; if (sdk < android.os.Build.VERSION_CODES.HONEYCOMB) { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) this .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(text);/*from ww w . j a va 2s. c om*/ } else { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) this .getSystemService(Context.CLIPBOARD_SERVICE); android.content.ClipData clip = ClipData.newPlainText("simple text", text); clipboard.setPrimaryClip(clip); } }
From source file:de.baumann.browser.Browser_left.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); final WebView.HitTestResult result = mWebView.getHitTestResult(); final String url = result.getExtra(); if (result.getType() == WebView.HitTestResult.IMAGE_TYPE) { final CharSequence[] options = { getString(R.string.context_saveImage), getString(R.string.context_shareImage), getString(R.string.context_readLater), getString(R.string.context_right) }; new AlertDialog.Builder(Browser_left.this) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); }/*from w w w . j ava2s . com*/ }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.context_saveImage))) { if (url != null) { try { Uri source = Uri.parse(url); DownloadManager.Request request = new DownloadManager.Request(source); request.addRequestHeader("Cookie", CookieManager.getInstance().getCookie(url)); request.allowScanningByMediaScanner(); request.setNotificationVisibility( DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed! request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, helper_main.newFileName()); DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); dm.enqueue(request); Snackbar.make(mWebView, getString(R.string.context_saveImage_toast) + " " + helper_main.newFileName(), Snackbar.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); Snackbar.make(mWebView, R.string.toast_perm, Snackbar.LENGTH_SHORT).show(); } } } if (options[item].equals(getString(R.string.context_shareImage))) { if (url != null) { shareString = helper_main.newFileName(); shareFile = helper_main.newFile(mWebView); try { Uri source = Uri.parse(url); DownloadManager.Request request = new DownloadManager.Request(source); request.addRequestHeader("Cookie", CookieManager.getInstance().getCookie(url)); request.allowScanningByMediaScanner(); request.setNotificationVisibility( DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed! request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, shareString); DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); dm.enqueue(request); Snackbar.make(mWebView, getString(R.string.context_saveImage_toast) + " " + helper_main.newFileName(), Snackbar.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); Snackbar.make(mWebView, R.string.toast_perm, Snackbar.LENGTH_SHORT).show(); } registerReceiver(onComplete2, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); } } if (options[item].equals(getString(R.string.context_readLater))) { if (url != null) { if (Uri.parse(url).getHost().length() == 0) { domain = getString(R.string.app_domain); } else { domain = Uri.parse(url).getHost(); } String domain2 = domain.substring(0, 1).toUpperCase() + domain.substring(1); DbAdapter_ReadLater db = new DbAdapter_ReadLater(Browser_left.this); db.open(); if (db.isExist(mWebView.getUrl())) { Snackbar.make(editText, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show(); } else { db.insert(domain2, url, "", "", helper_main.createDate()); Snackbar.make(mWebView, R.string.bookmark_added, Snackbar.LENGTH_LONG) .show(); } } } if (options[item].equals(getString(R.string.context_right))) { if (url != null) { helper_main.switchToActivity(Browser_left.this, Browser_right.class, url, false); } } } }).show(); } else if (result.getType() == WebView.HitTestResult.SRC_ANCHOR_TYPE) { final CharSequence[] options = { getString(R.string.menu_share_link_copy), getString(R.string.menu_share_link), getString(R.string.context_readLater), getString(R.string.context_right) }; new AlertDialog.Builder(Browser_left.this) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.menu_share_link_copy))) { if (url != null) { ClipboardManager clipboard = (ClipboardManager) Browser_left.this .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(ClipData.newPlainText("text", url)); Snackbar.make(mWebView, R.string.context_linkCopy_toast, Snackbar.LENGTH_SHORT) .show(); } } if (options[item].equals(getString(R.string.menu_share_link))) { if (url != null) { Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, url); sendIntent.setType("text/plain"); Browser_left.this.startActivity(Intent.createChooser(sendIntent, getResources().getString(R.string.app_share_link))); } } if (options[item].equals(getString(R.string.context_readLater))) { if (url != null) { if (Uri.parse(url).getHost().length() == 0) { domain = getString(R.string.app_domain); } else { domain = Uri.parse(url).getHost(); } String domain2 = domain.substring(0, 1).toUpperCase() + domain.substring(1); DbAdapter_ReadLater db = new DbAdapter_ReadLater(Browser_left.this); db.open(); if (db.isExist(mWebView.getUrl())) { Snackbar.make(editText, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show(); } else { db.insert(domain2, url, "", "", helper_main.createDate()); Snackbar.make(mWebView, R.string.bookmark_added, Snackbar.LENGTH_LONG) .show(); } } } if (options[item].equals(getString(R.string.context_right))) { if (url != null) { helper_main.switchToActivity(Browser_left.this, Browser_right.class, url, false); } } } }).show(); } }
From source file:com.google.blockly.android.ui.Dragger.java
/** * Handle motion events while starting to drag a block. This keeps track of whether the block * has been dragged more than {@code mTouchSlop} and starts a drag if necessary. Once the drag * has been started, all following events will be handled through the {@link * #mDragEventListener}.//w ww . ja va2 s. c om */ private boolean maybeStartDrag(DragHandler dragHandler) { // Check with the pending drag handler to select or create the dragged group. final PendingDrag pendingDrag = mPendingDrag; // Stash for async callback final Runnable dragGroupCreator = dragHandler.maybeGetDragGroupCreator(pendingDrag); final boolean foundDragGroup = (dragGroupCreator != null); if (foundDragGroup) { mMainHandler.post(new Runnable() { @Override public void run() { if (mPendingDrag != null && mPendingDrag.isDragging()) { return; // Ignore. Probably being handled by a child view. } dragGroupCreator.run(); boolean dragStarted = pendingDrag.isDragging(); if (dragStarted) { mPendingDrag = pendingDrag; final BlockGroup dragGroup = mPendingDrag.getDragGroup(); if (dragGroup.getParent() != mWorkspaceView) { throw new IllegalStateException("dragGroup is root in WorkspaceView"); } Block rootBlock = dragGroup.getFirstBlock(); removeDraggedConnectionsFromConnectionManager(rootBlock); ClipData clipData = ClipData.newPlainText(WorkspaceView.BLOCK_GROUP_CLIP_DATA_LABEL, ""); dragGroup.startDrag(clipData, new View.DragShadowBuilder(), null, 0); } else { mPendingDrag = null; } } }); } return foundDragGroup; }
From source file:org.godotengine.godot.Godot.java
public void setClipboard(String p_text) { ClipData clip = ClipData.newPlainText("myLabel", p_text); mClipboard.setPrimaryClip(clip); }
From source file:com.jungle.base.utils.MiscUtils.java
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB) public static void copyTextToClipboard(String data) { ClipboardManager clipboardManager = (ClipboardManager) AppCore.getApplicationContext() .getSystemService(Context.CLIPBOARD_SERVICE); ClipData clipData = ClipData.newPlainText("text", data); clipboardManager.setPrimaryClip(clipData); }
From source file:com.piusvelte.taplock.client.core.TapLockSettings.java
@Override protected void onListItemClick(ListView list, final View view, int position, final long id) { super.onListItemClick(list, view, position, id); mDialog = new AlertDialog.Builder(TapLockSettings.this) .setItems(R.array.actions_entries, new DialogInterface.OnClickListener() { @Override// w w w . j a v a 2s. com public void onClick(DialogInterface dialog, int which) { String action = getResources().getStringArray(R.array.actions_values)[which]; int deviceIdx = (int) id; JSONObject deviceJObj = mDevices.get(deviceIdx); dialog.cancel(); if (ACTION_UNLOCK.equals(action) || ACTION_LOCK.equals(action) || ACTION_TOGGLE.equals(action)) { String name = "uknown"; try { name = deviceJObj.getString(KEY_NAME); } catch (JSONException e) { e.printStackTrace(); } startActivity(TapLock.getPackageIntent(getApplicationContext(), TapLockToggle.class) .setAction(action).putExtra(EXTRA_DEVICE_NAME, name)); } else if (ACTION_TAG.equals(action)) { // write the device to a tag mInWriteMode = true; try { mNfcAdapter.enableForegroundDispatch(TapLockSettings.this, PendingIntent.getActivity(TapLockSettings.this, 0, new Intent(TapLockSettings.this, TapLockSettings.this.getClass()) .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP).putExtra( EXTRA_DEVICE_NAME, deviceJObj.getString(KEY_NAME)), 0), new IntentFilter[] { new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED) }, null); } catch (JSONException e) { Log.e(TAG, e.getMessage()); } Toast.makeText(TapLockSettings.this, "Touch tag", Toast.LENGTH_LONG).show(); } else if (ACTION_REMOVE.equals(action)) { mDevices.remove(deviceIdx); storeDevices(); } else if (ACTION_PASSPHRASE.equals(action)) setPassphrase(deviceIdx); else if (ACTION_COPY_DEVICE_URI.equals(action)) { ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); ClipData clip; try { clip = ClipData.newPlainText(getString(R.string.app_name), String .format(getString(R.string.device_uri), deviceJObj.get(EXTRA_DEVICE_NAME))); clipboard.setPrimaryClip(clip); Toast.makeText(TapLockSettings.this, "copied to clipboard!", Toast.LENGTH_SHORT) .show(); } catch (JSONException e) { Log.e(TAG, e.getMessage()); Toast.makeText(TapLockSettings.this, getString(R.string.msg_oops), Toast.LENGTH_SHORT).show(); } } } }).create(); mDialog.show(); }
From source file:com.forrestguice.suntimeswidget.LocationConfigView.java
public void copyLocationToClipboard(Context context, boolean silent) { WidgetSettings.Location location = getLocation(); String clipboardText = location.toString(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("lat, lon", clipboardText); clipboard.setPrimaryClip(clip);/*w ww. ja v a2 s.c o m*/ } else { @SuppressWarnings("deprecation") android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setText(clipboardText); } if (!silent) { Toast copiedMsg = Toast.makeText(context, Html.fromHtml(context.getString(R.string.location_dialog_toast_copied, clipboardText)), Toast.LENGTH_LONG); copiedMsg.show(); } }