List of usage examples for android.content ClipboardManager hasPrimaryClip
public boolean hasPrimaryClip()
From source file:Main.java
private static boolean hasText(Context c) { ClipboardManager clipboard = (ClipboardManager) c.getSystemService(Context.CLIPBOARD_SERVICE); return clipboard.hasPrimaryClip() && clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN); }
From source file:Main.java
/** * Get text from Clipboard/*from w w w . j av 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// w ww . j a v a 2 s .c o m * * @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/*from w ww.j av a 2 s .c o 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
@SuppressWarnings("ConstantConditions") @TargetApi(Build.VERSION_CODES.HONEYCOMB) private static String getClipboardTextNew(Context ctx) { String txt = null;/*from w w w. j a v a2 s . co m*/ android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ctx .getSystemService(Context.CLIPBOARD_SERVICE); if (clipboard != null) { if (clipboard.hasPrimaryClip()) { txt = clipboard.getPrimaryClip().getItemAt(0).getText().toString(); } } return txt; }
From source file:org.proninyaroslav.libretorrent.core.utils.Utils.java
@Nullable public static String getClipboard(Context context) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE); if (!clipboard.hasPrimaryClip()) { return null; }/*w w w. java2s .c om*/ ClipData clip = clipboard.getPrimaryClip(); if (clip == null || clip.getItemCount() == 0) { return null; } CharSequence text = clip.getItemAt(0).getText(); if (text == null) { return null; } return text.toString(); }
From source file:org.ttrssreader.utils.Utils.java
public static String getTextFromClipboard(Context context) { // New Clipboard API ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); if (clipboard.hasPrimaryClip()) { if (!clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) return null; ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0); CharSequence chars = item.getText(); if (chars != null && chars.length() > 0) { return chars.toString(); } else {/*from w ww .j a v a 2s .c om*/ Uri pasteUri = item.getUri(); if (pasteUri != null) { return pasteUri.toString(); } } } return null; }
From source file:com.softminds.matrixcalculator.OperationFragments.TraceFragment.java
private void RunToGetTrace(int position, ProgressDialog progressDialog) { double result = ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(position).getTrace(); final String formatted = GetText(result); progressDialog.dismiss();/*from ww w . java 2s .c om*/ String formatted2 = getString(R.string.trace_is) + " " + formatted; new AlertDialog.Builder(getContext()).setCancelable(true).setMessage(formatted2) .setTitle(R.string.trace_text) .setPositiveButton(R.string.copy, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ClipboardManager manager = (ClipboardManager) getContext() .getSystemService(Context.CLIPBOARD_SERVICE); ClipData data = ClipData.newPlainText("TRACE_RES", formatted); manager.setPrimaryClip(data); if (manager.hasPrimaryClip()) Toast.makeText(getContext(), R.string.CopyToClip, Toast.LENGTH_SHORT).show(); else Log.e(TAG, "Cannot Put Data to Clip"); dialog.dismiss(); } }).setNeutralButton(R.string.Done, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).show(); }
From source file:com.eng.arab.translator.androidtranslator.translate.TranslateViewActivity.java
public String readFromClipboard() { ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); if (clipboard.hasPrimaryClip()) { android.content.ClipDescription description = clipboard.getPrimaryClipDescription(); android.content.ClipData data = clipboard.getPrimaryClip(); if (data != null && description != null && description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) return String.valueOf(data.getItemAt(0).getText()); }//from w ww .ja v a 2 s.c o m return null; }
From source file:com.timrae.rikaidroid.MainActivity.java
private void loadContentFromClipboard() { if (mWebView == null) { Log.e(TAG, "Webview is null"); return;//from w w w .j ava 2 s . c o m } // Get clipboard ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); if (!(clipboard.hasPrimaryClip())) { Log.w(TAG, "Clipboard is empty"); return; } // Get string from clipboard ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0); String pasteData = item.getText().toString(); //pasteData = "??????????"; if (pasteData == null) { Log.w(TAG, "Clipboard doesn't contain text"); return; } mEditText.setText(pasteData); }