List of usage examples for android.content ClipData newPlainText
static public ClipData newPlainText(CharSequence label, CharSequence text)
From source file:co.dilaver.quoter.fragments.QODFragment.java
@Override public void qodCopyClicked() { if (!qodString.equals("") && !authorString.equals("")) { ClipboardManager clipboard = (ClipboardManager) getActivity() .getSystemService(Activity.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("Copied Text", qodString + " - " + authorString); clipboard.setPrimaryClip(clip);// w w w. j av a 2 s .c om Snackbar.make(rootLayout, getString(R.string.str_QuoteCopied), Snackbar.LENGTH_SHORT).show(); } }
From source file:io.github.marktony.espresso.mvp.packagedetails.PackageDetailsFragment.java
/** * Copy the package number(id) to clipboard. * @param packageId The package number.// w w w . j av a 2s .c o m */ @Override public void copyPackageNumber(@NonNull String packageId) { ClipboardManager manager = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); ClipData data = ClipData.newPlainText("text", packageId); manager.setPrimaryClip(data); Snackbar.make(fab, R.string.package_number_copied, Snackbar.LENGTH_SHORT).show(); }
From source file:rosmi.acagild.alarmclock.ringing.AlarmRingingFragment.java
@Nullable @Override/*from w w w .ja va 2 s . c o m*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Logger.init(getActivity()); Bundle args = getArguments(); UUID alarmId = UUID.fromString(args.getString(ARGS_ALARM_ID)); mAlarm = AlarmList.get(getContext()).getAlarm(alarmId); View view = inflater.inflate(R.layout.fragment_alarm_ringing, container, false); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN) { TextView timeField = (TextView) view.findViewById(R.id.alarm_ringing_time); timeField.setText(DateTimeUtilities.getUserTimeString(getContext(), mAlarm.getTimeHour(), mAlarm.getTimeMinute())); } TextView dateField = (TextView) view.findViewById(R.id.alarm_ringing_date); dateField.setText(DateTimeUtilities.getFullDateStringForNow()); String name = mAlarm.getTitle(); TextView titleField = (TextView) view.findViewById(R.id.alarm_ringing_title); titleField.setText(name); ImageView dismissButton = (ImageView) view.findViewById(R.id.alarm_ringing_dismiss); dismissButton.setOnDragListener(new View.OnDragListener() { @Override public boolean onDrag(View v, DragEvent event) { switch (event.getAction()) { case DragEvent.ACTION_DROP: dismissAlarm(); break; case DragEvent.ACTION_DRAG_ENDED: if (mShowClockOnDragEnd) { mAlarmRingingClock.postDelayed(new Runnable() { @Override public void run() { mAlarmRingingClock.setVisibility(View.VISIBLE); } }, SHOW_CLOCK_AFTER_UNSUCCESSFUL_DRAG_DELAY); } break; default: break; } return true; } }); // Dismiss ringing if someone presses the dismiss button directly dismissButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dismissAlarm(); } }); ImageView snoozeButton = (ImageView) view.findViewById(R.id.alarm_ringing_snooze); snoozeButton.setOnDragListener(new View.OnDragListener() { @Override public boolean onDrag(View v, DragEvent event) { switch (event.getAction()) { case DragEvent.ACTION_DROP: mCallback.onRingingSnooze(); break; default: break; } return true; } }); // Snooze ringing if someone presses the snooze button directly snoozeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mCallback.onRingingSnooze(); } }); // Allow the view to listen to the drag event to update arrow animations accordingly view.setOnDragListener(new View.OnDragListener() { @Override public boolean onDrag(View v, DragEvent event) { switch (event.getAction()) { case DragEvent.ACTION_DRAG_LOCATION: // Update the left/right arrow visibility based on the current drag location. onClockDragLocation(event.getX(), event.getY(), v.getWidth() / 2); break; case DragEvent.ACTION_DROP: // The user has dropped the drag, but it is dropped within the view, instead of the target // drop zones to dismiss or snooze. // Restore to show both left arrow and right arrow animations. mDragZone = DragZone.NEAR_MIDDLE_OF_VIEW; updateArrowsBasedOnDragZone(mDragZone); break; default: break; } return true; } }); mAlarmRingingClock = (ImageView) view.findViewById(R.id.alarm_ringing_clock); mAlarmRingingClock.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { ClipData dragData = ClipData.newPlainText("", ""); View.DragShadowBuilder shadow = new View.DragShadowBuilder(mAlarmRingingClock); mAlarmRingingClock.startDrag(dragData, shadow, null, 0); mAlarmRingingClock.setVisibility(View.INVISIBLE); return true; } else { return false; } } }); initializeClockAnimation(view); Loggable.AppAction appAction = new Loggable.AppAction(Loggable.Key.APP_ALARM_RINGING); appAction.putJSON(mAlarm.toJSON()); Logger.track(appAction); return view; }
From source file:com.microsoft.mimickeralarm.ringing.AlarmRingingFragment.java
@Nullable @Override//from w ww .j a va2 s. c o m public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Logger.init(getActivity()); Bundle args = getArguments(); UUID alarmId = UUID.fromString(args.getString(ARGS_ALARM_ID)); mAlarm = AlarmList.get(getContext()).getAlarm(alarmId); View view = inflater.inflate(R.layout.fragment_alarm_ringing, container, false); if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN) { TextView timeField = (TextView) view.findViewById(R.id.alarm_ringing_time); timeField.setText(DateTimeUtilities.getUserTimeString(getContext(), mAlarm.getTimeHour(), mAlarm.getTimeMinute())); } TextView dateField = (TextView) view.findViewById(R.id.alarm_ringing_date); dateField.setText(DateTimeUtilities.getFullDateStringForNow()); String name = mAlarm.getTitle(); TextView titleField = (TextView) view.findViewById(R.id.alarm_ringing_title); titleField.setText(name); ImageView dismissButton = (ImageView) view.findViewById(R.id.alarm_ringing_dismiss); dismissButton.setOnDragListener(new View.OnDragListener() { @Override public boolean onDrag(View v, DragEvent event) { switch (event.getAction()) { case DragEvent.ACTION_DROP: dismissAlarm(); break; case DragEvent.ACTION_DRAG_ENDED: if (mShowClockOnDragEnd) { mAlarmRingingClock.postDelayed(new Runnable() { @Override public void run() { mAlarmRingingClock.setVisibility(View.VISIBLE); } }, SHOW_CLOCK_AFTER_UNSUCCESSFUL_DRAG_DELAY); } break; default: break; } return true; } }); // Dismiss ringing if someone presses the dismiss button directly dismissButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dismissAlarm(); } }); ImageView snoozeButton = (ImageView) view.findViewById(R.id.alarm_ringing_snooze); snoozeButton.setOnDragListener(new View.OnDragListener() { @Override public boolean onDrag(View v, DragEvent event) { switch (event.getAction()) { case DragEvent.ACTION_DROP: mCallback.onRingingSnooze(); break; default: break; } return true; } }); // Snooze ringing if someone presses the snooze button directly snoozeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mCallback.onRingingSnooze(); } }); // Allow the view to listen to the drag event to update arrow animations accordingly view.setOnDragListener(new View.OnDragListener() { @Override public boolean onDrag(View v, DragEvent event) { switch (event.getAction()) { case DragEvent.ACTION_DRAG_LOCATION: // Update the left/right arrow visibility based on the current drag location. onClockDragLocation(event.getX(), event.getY(), v.getWidth() / 2); break; case DragEvent.ACTION_DROP: // The user has dropped the drag, but it is dropped within the view, instead of the target // drop zones to dismiss or snooze. // Restore to show both left arrow and right arrow animations. mDragZone = DragZone.NEAR_MIDDLE_OF_VIEW; updateArrowsBasedOnDragZone(mDragZone); break; default: break; } return true; } }); mAlarmRingingClock = (ImageView) view.findViewById(R.id.alarm_ringing_clock); mAlarmRingingClock.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { ClipData dragData = ClipData.newPlainText("", ""); View.DragShadowBuilder shadow = new View.DragShadowBuilder(mAlarmRingingClock); mAlarmRingingClock.startDrag(dragData, shadow, null, 0); mAlarmRingingClock.setVisibility(View.INVISIBLE); return true; } else { return false; } } }); initializeClockAnimation(view); Loggable.AppAction appAction = new Loggable.AppAction(Loggable.Key.APP_ALARM_RINGING); appAction.putJSON(mAlarm.toJSON()); Logger.track(appAction); return view; }
From source file:net.oremland.rss.reader.fragments.BrowserFragment.java
private void copyUrlToClipboard() { ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("Feed Item Url", getFeedItem().getUrl()); clipboard.setPrimaryClip(clip);/*from ww w . j av a 2s . c o m*/ Toast.makeText(getContext(), "Url Copied To Clipboard", Toast.LENGTH_SHORT).show(); }
From source file:de.dknapps.pswgendroid.ServiceDetailFragment.java
/** * Kopiert die Login-Informationen in die Zwischenablage. * //from ww w.j a v a 2s .c o m * FIXME dkn Die callingActivity kann durch getActivity() ersetzt werden. */ private void copyLoginInfo(final Activity callingActivity) { ClipboardManager clipboard = (ClipboardManager) callingActivity.getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(ClipData.newPlainText(null, currentServiceInfo.getLoginInfo())); }
From source file:org.mozilla.gecko.toolbar.SiteIdentityPopup.java
private void addSelectLoginDoorhanger(Tab tab) throws JSONException { final SiteLogins siteLogins = tab.getSiteLogins(); if (siteLogins == null) { return;// ww w .j a v a2s. c om } final JSONArray logins = siteLogins.getLogins(); if (logins.length() == 0) { return; } final JSONObject login = (JSONObject) logins.get(0); // Create button click listener for copying a password to the clipboard. final OnButtonClickListener buttonClickListener = new OnButtonClickListener() { @Override public void onButtonClick(JSONObject response, DoorHanger doorhanger) { try { final int buttonId = response.getInt("callback"); if (buttonId == ButtonType.COPY.ordinal()) { final ClipboardManager manager = (ClipboardManager) mContext .getSystemService(Context.CLIPBOARD_SERVICE); String password; if (response.has("password")) { // Click listener being called from List Dialog. password = response.optString("password"); } else { password = login.getString("password"); } if (AppConstants.Versions.feature11Plus) { manager.setPrimaryClip(ClipData.newPlainText("password", password)); } else { manager.setText(password); } Toast.makeText(mContext, R.string.doorhanger_login_select_toast_copy, Toast.LENGTH_SHORT) .show(); } dismiss(); } catch (JSONException e) { Log.e(LOGTAG, "Error handling Select login button click", e); Toast.makeText(mContext, R.string.doorhanger_login_select_toast_copy_error, Toast.LENGTH_SHORT) .show(); } } }; final DoorhangerConfig config = new DoorhangerConfig(DoorHanger.Type.LOGIN, buttonClickListener); // Set buttons. config.setButton(mContext.getString(R.string.button_cancel), ButtonType.CANCEL.ordinal(), false); config.setButton(mContext.getString(R.string.button_copy), ButtonType.COPY.ordinal(), true); // Set message. String username = ((JSONObject) logins.get(0)).getString("username"); if (TextUtils.isEmpty(username)) { username = mContext.getString(R.string.doorhanger_login_no_username); } final String message = mContext.getString(R.string.doorhanger_login_select_message).replace(FORMAT_S, username); config.setMessage(message); // Set options. final JSONObject options = new JSONObject(); // Add action text only if there are other logins to select. if (logins.length() > 1) { final JSONObject actionText = new JSONObject(); actionText.put("type", "SELECT"); final JSONObject bundle = new JSONObject(); bundle.put("logins", logins); actionText.put("bundle", bundle); options.put("actionText", actionText); } config.setOptions(options); ThreadUtils.postToUiThread(new Runnable() { @Override public void run() { if (!mInflated) { init(); } removeSelectLoginDoorhanger(); mSelectLoginDoorhanger = DoorHanger.Get(mContext, config); mContent.addView(mSelectLoginDoorhanger); mDivider.setVisibility(View.VISIBLE); } }); }
From source file:org.secuso.privacyfriendlypasswordgenerator.dialogs.GeneratePasswordDialog.java
public void passwordToClipboard(boolean clipboardEnabled, String password) { if (clipboardEnabled) { ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("Password", password); clipboard.setPrimaryClip(clip);/*from ww w. j av a 2 s . co m*/ Toast.makeText(getActivity(), getActivity().getString(R.string.password_copied), Toast.LENGTH_SHORT) .show(); } }
From source file:com.krayzk9s.imgurholo.ui.ImagesFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // handle item selection final Activity activity = getActivity(); switch (item.getItemId()) { case R.id.action_download: Toast.makeText(activity,/*from ww w . j a va2s . com*/ String.format(getActivity().getResources().getString(R.string.toast_downloading), urls.size()), Toast.LENGTH_SHORT).show(); Intent serviceIntent = new Intent(activity, DownloadService.class); serviceIntent.putParcelableArrayListExtra("ids", ids); if (albumId != null) serviceIntent.putExtra("albumName", albumId); else serviceIntent.putExtra("albumName", imageCall); activity.startService(serviceIntent); return true; case R.id.action_refresh: urls = new ArrayList<String>(); ids = new ArrayList<JSONParcelable>(); page = 0; makeGallery(); return true; case R.id.action_copy: ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("imgur Link", "http://imgur.com/a/" + albumId); clipboard.setPrimaryClip(clip); Toast.makeText(activity, R.string.toast_copied, Toast.LENGTH_SHORT).show(); return true; case R.id.action_share: Intent intent = new Intent(android.content.Intent.ACTION_SEND); intent.setType("text/plain"); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); intent.putExtra(Intent.EXTRA_TEXT, "http://imgur.com/a/" + albumId); startActivity(intent); return true; case R.id.action_new: Intent i = new Intent(this.getActivity().getApplicationContext(), ImageSelectActivity.class); startActivityForResult(i, 1); //select image return true; case R.id.action_comments: if (galleryAlbumData != null) { CommentsAsync commentsAsync = new CommentsAsync(((ImgurHoloActivity) getActivity()), galleryAlbumData); commentsAsync.execute(); return true; } else return super.onOptionsItemSelected(item); default: return super.onOptionsItemSelected(item); } }
From source file:com.microsoft.office365.msgraphsnippetapp.SnippetDetailFragment.java
@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); }