Example usage for android.content ClipData newPlainText

List of usage examples for android.content ClipData newPlainText

Introduction

In this page you can find the example usage for android.content ClipData newPlainText.

Prototype

static public ClipData newPlainText(CharSequence label, CharSequence text) 

Source Link

Document

Create a new ClipData holding data of the type ClipDescription#MIMETYPE_TEXT_PLAIN .

Usage

From source file:Main.java

public static void copy(Context context, String str) {
    ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    String lable = str;/*from  ww  w. j a v  a  2s . c o  m*/
    if (str.length() > 10)
        lable = str.substring(0, 10);
    clipboardManager.setPrimaryClip(ClipData.newPlainText(lable, str));
}

From source file:Main.java

public static void copyToClipboard(Context context, String label, String content) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText(label, content);
        clipboard.setPrimaryClip(clip);/*from  w  ww  . j  a  v  a  2s  . c  o  m*/
    } else {
        android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context
                .getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setText("text to clip");
    }
}

From source file:Main.java

public static void copyIntoClipboard(String label, String content, Context context) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText(label, content);
    clipboard.setPrimaryClip(clip);/*w  w w . j  a  va 2s  . co  m*/
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void copyText(Context context, String text) {
    ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        ClipData clip = ClipData.newPlainText("", text);
        cm.setPrimaryClip(clip);//ww  w.j  av a  2  s .  c  o m
    } else {
        //noinspection deprecation
        cm.setText(text);
    }
}

From source file:Main.java

public static void setText(Context context, CharSequence text) {
    if (isNew()) {
        instance(context);/* w w  w  . j ava  2s. c  o m*/
        // Creates a new text clip to put on the clipboard
        ClipData clip = ClipData.newPlainText("simple text", text);

        // Set the clipboard's primary clip.
        mNewCliboardManager.setPrimaryClip(clip);
    } else {
        instance(context);
        mClipboardManager.setText(text);
    }
}

From source file:Main.java

/**
 * A helper to copy the text to the clipboard.
 *
 * @param context/* www .  j  a  v  a  2 s .  c o  m*/
 * @param text A text to copy.
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void copyText(Context context, String text) {
    final ClipboardManager clipboard = getClipboard(context);
    clipboard.setPrimaryClip(ClipData.newPlainText("Copied Text", text));
}

From source file:Main.java

/**
 * copy plain text to clip board/*from  ww  w  . j  a  v a 2 s. c om*/
 *
 * @param context
 * @param tag
 * @param text
 * @param toastText may null, no toast at all
 */
public static void copy2ClipBoard(Context context, String tag, String text, String toastText) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText(tag, text);
    clipboard.setPrimaryClip(clip);
    if (toastText != null) {
        Toast.makeText(context, toastText, Toast.LENGTH_SHORT).show();
    }
}

From source file:Main.java

public static void clip(Context context, String text) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        android.text.ClipboardManager clipboardManager = (android.text.ClipboardManager) context
                .getSystemService(Context.CLIPBOARD_SERVICE);
        clipboardManager.setText(text);//www  .  j a  va2 s .  co m
    } else {
        ClipboardManager clipboardManager = (ClipboardManager) context
                .getSystemService(Context.CLIPBOARD_SERVICE);
        clipboardManager.setPrimaryClip(ClipData.newPlainText("mq_content", text));
    }
}

From source file:Main.java

@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void copyToClipboard(Context context, String text) {
    // if()/*from  www  .j a va 2  s .  co m*/
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context
                .getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setText(text);
    } else {
        android.content.ClipboardManager clipboard = (android.content.ClipboardManager) context
                .getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setPrimaryClip(ClipData.newPlainText(null, text));
    }
}

From source file:Main.java

public static void copyToClipBoard(Context context, String text) {
    ClipData clipData = ClipData.newPlainText("text_copy", text);
    ClipboardManager manager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    manager.setPrimaryClip(clipData);//from ww w.  j a  v a2s .c om
}