Example usage for android.content ClipData getItemCount

List of usage examples for android.content ClipData getItemCount

Introduction

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

Prototype

public int getItemCount() 

Source Link

Document

Return the number of items in the clip data.

Usage

From source file:Main.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static int getItemCount(Context context) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData data = clipboard.getPrimaryClip();
    return data.getItemCount();
}

From source file:Main.java

public static CharSequence getText(Context context) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = clipboard.getPrimaryClip();
    if (clip != null && clip.getItemCount() > 0) {
        return clip.getItemAt(0).coerceToText(context);
    }/*ww w  .  j a  v a  2s.  c  o m*/
    return null;
}

From source file:Main.java

public static Uri getUri(Context context) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = clipboard.getPrimaryClip();
    if (clip != null && clip.getItemCount() > 0) {
        return clip.getItemAt(0).getUri();
    }/*from   w  w w  .j a va  2s.  com*/
    return null;
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static String getText(Context context, int index) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = clipboard.getPrimaryClip();
    if (clip != null && clip.getItemCount() > index) {
        return String.valueOf(clip.getItemAt(0).coerceToText(context));
    }/*from   w ww .j  ava 2  s .  com*/
    return null;
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static String getLatestText(Context context) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = clipboard.getPrimaryClip();
    if (clip != null && clip.getItemCount() > 0) {
        return String.valueOf(clip.getItemAt(0).coerceToText(context));
    }//from  w w  w.j a v a 2  s  .c om
    return null;
}

From source file:Main.java

private static String getClipText(Context context) {
    String text = "";
    ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clipData = cm.getPrimaryClip();
    if (clipData != null) {
        if (clipData.getItemCount() > 0) {
            ClipData.Item item = clipData.getItemAt(0);
            text = item.getText().toString();
        }/*from w  w  w  .j  a v a 2  s . c om*/
    }

    return text;
}

From source file:Main.java

/**
 * Get text from Clipboard/*ww w. j a  v  a 2  s.c  om*/
 *
 * @param context
 * @return
 */
public static String getText(Context context) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    if (clipboard.hasPrimaryClip()
            && clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
        ClipData clip = clipboard.getPrimaryClip();
        if (clip != null && clip.getItemCount() > 0) {
            return String.valueOf(clip.getItemAt(0).coerceToText(context));
        }
    }
    return null;
}

From source file:Main.java

/**
 * Get intent from Clipboard//from  ww w  .java2  s  .  c  om
 *
 * @param context
 * @return
 */
public static Intent getIntent(Context context) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    if (clipboard.hasPrimaryClip()
            && clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_INTENT)) {
        ClipData clip = clipboard.getPrimaryClip();
        if (clip != null && clip.getItemCount() > 0) {
            return clip.getItemAt(0).getIntent();
        }
    }
    return null;
}

From source file:Main.java

/**
 * Get uri from Clipboard//ww w .jav a2  s .co  m
 *
 * @param context
 * @return
 */
public static Uri getUri(Context context) {
    ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    if (clipboard.hasPrimaryClip()
            && clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_URILIST)) {
        ClipData clip = clipboard.getPrimaryClip();
        if (clip != null && clip.getItemCount() > 0) {
            return clip.getItemAt(0).getUri();
        }
    }
    return null;
}

From source file:Main.java

public static CharSequence getText(Context context) {
    StringBuilder sb = new StringBuilder();
    if (isNew()) {
        instance(context);/*from ww  w .  j a  va  2 s.c om*/
        if (!mNewCliboardManager.hasPrimaryClip()) {
            return sb.toString();
        } else {
            ClipData clipData = (mNewCliboardManager).getPrimaryClip();
            int count = clipData.getItemCount();

            for (int i = 0; i < count; ++i) {

                ClipData.Item item = clipData.getItemAt(i);
                CharSequence str = item.coerceToText(context);
                sb.append(str);
            }
        }

    } else {
        instance(context);
        sb.append(mClipboardManager.getText());
    }
    return sb.toString();
}