Example usage for android.content ClipboardManager setPrimaryClip

List of usage examples for android.content ClipboardManager setPrimaryClip

Introduction

In this page you can find the example usage for android.content ClipboardManager setPrimaryClip.

Prototype

public void setPrimaryClip(@NonNull ClipData clip) 

Source Link

Document

Sets the current primary clip on the clipboard.

Usage

From source file:com.dnielfe.manager.utils.SimpleUtils.java

public static void savetoClipBoard(final Context co, String dir1) {
    android.content.ClipboardManager clipboard = (android.content.ClipboardManager) co
            .getSystemService(Context.CLIPBOARD_SERVICE);
    android.content.ClipData clip = android.content.ClipData.newPlainText("Copied Text", dir1);
    clipboard.setPrimaryClip(clip);
    Toast.makeText(co, "'" + dir1 + "' " + co.getString(R.string.copiedtoclipboard), Toast.LENGTH_SHORT).show();
}

From source file:syncthing.android.service.SyncthingUtils.java

public static void copyToClipboard(Context context, CharSequence label, String id) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText(label, id);
    clipboard.setPrimaryClip(clip);
    Toast.makeText(context, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
}

From source file:de.grobox.liberario.utils.TransportrUtils.java

static public void copyToClipboard(Context context, String text) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText("label", text);
    clipboard.setPrimaryClip(clip);
}

From source file:info.papdt.blacklight.support.Utility.java

public static void copyToClipboard(Context context, String data) {
    ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData cd = ClipData.newPlainText("msg", data);
    cm.setPrimaryClip(cd);

    // Inform the user
    Toast.makeText(context, R.string.copied, Toast.LENGTH_SHORT).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  w w w  . j a v a  2s. c o m*/
}

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:im.neon.util.VectorUtils.java

/**
 * Copy a text to the clipboard./* w  w w .  j a va  2  s . c  om*/
 *
 * @param context the context
 * @param text    the text to copy
 */
public static void copyToClipboard(Context context, CharSequence text) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    clipboard.setPrimaryClip(ClipData.newPlainText("", text));
    Toast.makeText(context, context.getString(R.string.copied_to_clipboard), Toast.LENGTH_SHORT).show();
}

From source file:net.eledge.android.europeana.gui.fragment.RecordDetailsFragment.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupClipboardAction(ListView mListView) {
    mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override//from w w w .  j  a v a2  s .co  m
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            RecordView record = mRecordViewAdapter.getItem(position);
            Activity activity = RecordDetailsFragment.this.getActivity();
            ClipboardManager clipboard = (ClipboardManager) activity
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            clipboard
                    .setPrimaryClip(
                            ClipData.newPlainText(GuiUtils.getString(getActivity(), record.getLabel()),
                                    StringUtils.join(
                                            record.getValues(recordController.record,
                                                    (EuropeanaApplication) getActivity().getApplication()),
                                            ";")));
            GuiUtils.toast(activity, R.string.msg_copied2clipboard);
            return true;
        }
    });
}

From source file:com.xw.project.gracefulmovies.view.activity.AboutActivity.java

@OnClick({ R.id.about_gmail_img, R.id.about_github_img, R.id.about_license_text })
public void onClick(View view) {
    switch (view.getId()) {
    case R.id.about_gmail_img:
        String s1 = "";
        String s2 = getString(R.string.gmail_address);

        ClipboardManager cmb = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clipData = ClipData.newPlainText("content", s2);
        cmb.setPrimaryClip(clipData);

        showToast(getString(R.string.hint_clipboard, s1, s2));
        break;// www.j  av a2 s.  com
    case R.id.about_github_img:
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setData(Uri.parse(getString(R.string.github_page)));
        startActivity(Intent.createChooser(intent, "?"));
        break;
    case R.id.about_license_text:
        navigateTo(OpenLicenseActivity.class);
        break;
    }
}

From source file:com.zephyrteam.costituzione.DetailedActivity.java

@SuppressWarnings("static-access")
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.copy_entry:
        String toCopy = mEntry.getTitle() + ": \n" + mEntry.getBody().replace("\n\n", "\n");

        ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setPrimaryClip(ClipData.newPlainText("Costituzione", toCopy));
        new Toast(this).makeText(this, R.string.text_copied_to_clipboard, 2000).show();

        break;/*w ww . j  a v a 2s . com*/

    case R.id.favourite_status:
        DatabaseHandler dbh = new DatabaseHandler(this);
        dbh.open(true);
        mEntry.setIsFavourite(!mEntry.isFavourite());
        dbh.updateFavoriteStatus(mEntry);
        dbh.close();

        new Toast(this)
                .makeText(this, mEntry.isFavourite() ? R.string.added_to_fav : R.string.removed_from_fav, 2000)
                .show();
        updateFavoriteButton(item);
    }
    return true;
}