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.druk.bonjour.browser.ui.adapter.TxtRecordsAdapter.java

public void onItemClick(View view, int position) {
    Context context = view.getContext();

    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText(getKey(position), getValue(position));
    clipboard.setPrimaryClip(clip);

    Snackbar snackbar = Snackbar.make(view,
            context.getResources().getString(R.string.copy_toast_message, getKey(position)),
            Snackbar.LENGTH_LONG);//  ww  w. ja va  2 s.  c  o m
    snackbar.getView().setBackgroundResource(R.color.accent);
    snackbar.show();
}

From source file:com.google.android.gcm.demo.ui.AbstractFragment.java

@Override
public boolean onLongClick(View v) {
    // Copy in the clipboard the value of the selected widget.
    String value = getValue(v.getId());
    if (value.length() > 0) {
        ClipboardManager clipboard = (ClipboardManager) getActivity()
                .getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setPrimaryClip(ClipData.newPlainText("GcmTestApp clipboard", value));
        Toast.makeText(getActivity(), value + "\nhas been copied in the clipboard", Toast.LENGTH_SHORT).show();
        return true;
    }//from   w ww.j  a v  a2s  .co m
    return false;
}

From source file:com.espian.library.about.AbsAboutActivity.java

public void copy(String type, Uri uri, String backup) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {

        ClipboardManager newCm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        newCm.setPrimaryClip(ClipData.newUri(getContentResolver(), type, uri));

    } else {/*from   ww w . ja  v a2 s .  c  o m*/

        android.text.ClipboardManager oldCm = (android.text.ClipboardManager) getSystemService(
                Context.CLIPBOARD_SERVICE);
        oldCm.setText(backup);

    }
    Toast.makeText(this, getString(R.string.copy_to_clip, backup), Toast.LENGTH_SHORT).show();

}

From source file:com.amaze.carbonfilemanager.utils.files.Futils.java

public static boolean copyToClipboard(Context context, String text) {
    try {//from www.  j a  v a  2  s  .c  o m
        android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context
                .getSystemService(context.CLIPBOARD_SERVICE);
        android.content.ClipData clip = android.content.ClipData
                .newPlainText(context.getString(R.string.clipboard_path_copy), text);
        clipboard.setPrimaryClip(clip);
        return true;
    } catch (Exception e) {
        return false;
    }
}

From source file:arun.com.chromer.webheads.ui.context.WebHeadContextActivity.java

private void copyToClipboard(String label, String url) {
    final ClipData clip = ClipData.newPlainText(label, url);
    final ClipboardManager cm = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    cm.setPrimaryClip(clip);
    Toast.makeText(this, getString(R.string.copied) + " " + url, LENGTH_SHORT).show();
}

From source file:at.alladin.rmbt.android.sync.RMBTSyncRequestCodeFragment.java

@Override
public boolean onContextItemSelected(MenuItem mi) {
    if (mi.getItemId() == codeText.getId()) {
        ClipboardManager clipboard = (ClipboardManager) getActivity()
                .getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText("sync_code", codeText.getText());
        clipboard.setPrimaryClip(clip);
        return true;
    }/*w  w  w .  ja  va  2s .  com*/
    return super.onContextItemSelected(mi);
}

From source file:com.microsoft.azure.engagement.fragment.GetDeviceIdFragment.java

/**
 * Method that copies the device id/*  w  ww  .ja  v a 2 s.  c o m*/
 */
private final void copyDeviceID() {
    if (deviceId != null) {
        final ClipboardManager clipboard = (ClipboardManager) getActivity()
                .getSystemService(Activity.CLIPBOARD_SERVICE);
        final ClipData clip = ClipData.newPlainText("label", deviceId);
        clipboard.setPrimaryClip(clip);
        Toast.makeText(getActivity(), getString(R.string.get_the_device_id_copy_success_message, deviceId),
                Toast.LENGTH_LONG).show();

        Log.d(GetDeviceIdFragment.TAG, "String Device ID copied " + deviceId);
    } else {
        Log.w(GetDeviceIdFragment.TAG, "Device ID is null");
    }

    AzmeTracker.sendEvent(getActivity(), "copy_device_id");
}

From source file:com.amaze.filemanager.utils.files.FileUtils.java

public static boolean copyToClipboard(Context context, String text) {
    try {//from  www.j a v a2s .  co  m
        android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context
                .getSystemService(Context.CLIPBOARD_SERVICE);
        android.content.ClipData clip = android.content.ClipData
                .newPlainText(context.getString(R.string.clipboard_path_copy), text);
        clipboard.setPrimaryClip(clip);
        return true;
    } catch (Exception e) {
        return false;
    }
}

From source file:de.dknapps.pswgendroid.ServiceDetailFragment.java

/**
 * Kopiert die Login-Informationen in die Zwischenablage.
 * /*from   w  ww.jav  a 2s .c  om*/
 * 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:com.coloreight.plugin.clipboard.Clipboard.java

public void copy(final String text, final CallbackContext callbackContext) {
    cordova.getActivity().runOnUiThread(new Runnable() {
        public void run() {
            ClipboardManager clipboard = (ClipboardManager) cordova.getActivity()
                    .getSystemService(Context.CLIPBOARD_SERVICE);

            try {
                ClipData clip = ClipData.newPlainText("Public.Text", text);

                clipboard.setPrimaryClip(clip);

                callbackContext.success(text);
            } catch (Exception e) {
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, e.toString()));
            }//w  ww .  j  a v  a 2  s . c  om
        }
    });
}