Java Code Examples for android.content.ClipboardManager#getPrimaryClip()
The following examples show how to use
android.content.ClipboardManager#getPrimaryClip() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VerificationCodeLayout.java From SimpleProject with MIT License | 6 votes |
@Override public boolean onTextContextMenuItem(int id) { if (id == android.R.id.paste) { ClipboardManager cm = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); if (cm == null) { return super.onTextContextMenuItem(id); } ClipData clipData = cm.getPrimaryClip(); if (clipData != null && clipData.getItemCount() > 0) { String content = clipData.getItemAt(0).coerceToText(getContext()).toString(); if (listener != null) { listener.onPaste(content); } } } return super.onTextContextMenuItem(id); }
Example 2
Source File: CustomThemeListingActivity.java From Infinity-For-Reddit with GNU Affero General Public License v3.0 | 6 votes |
@Override public void importTheme() { ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); if (clipboard != null) { // If it does contain data, decide if you can handle the data. if (!clipboard.hasPrimaryClip()) { Snackbar.make(coordinatorLayout, R.string.no_data_in_clipboard, Snackbar.LENGTH_SHORT).show(); } else if (clipboard.getPrimaryClipDescription() != null && !clipboard.getPrimaryClipDescription().hasMimeType(MIMETYPE_TEXT_PLAIN)) { // since the clipboard has data but it is not plain text Snackbar.make(coordinatorLayout, R.string.no_data_in_clipboard, Snackbar.LENGTH_SHORT).show(); } else if (clipboard.getPrimaryClip() != null) { ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0); String json = item.getText().toString(); try { CustomTheme customTheme = new Gson().fromJson(json, CustomTheme.class); checkDuplicateAndImportTheme(customTheme, true); } catch (JsonSyntaxException e) { Snackbar.make(coordinatorLayout, R.string.parse_theme_failed, Snackbar.LENGTH_SHORT).show(); } } } }
Example 3
Source File: MainActivity.java From youtube-dl-android with GNU General Public License v3.0 | 6 votes |
public void pasteFromClipboard(View button) { ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); if (clipboard != null && clipboard.hasPrimaryClip()) { ClipData clipData = clipboard.getPrimaryClip(); Uri uri; CharSequence url; if ( clipData != null && clipData.getItemCount() > 0 ) { if ((uri = clipData.getItemAt(0).getUri()) != null) { urlEdit.setText(uri.toString()); } else if ((url = clipData.getItemAt(0).getText()) != null ) { urlEdit.setText(url.toString()); } startPoint(button); } } }
Example 4
Source File: SelectionPopupController.java From 365browser with Apache License 2.0 | 6 votes |
@VisibleForTesting public boolean canPasteAsPlainText() { // String resource "paste_as_plain_text" only exist in O. // Also this is an O feature, we need to make it consistant with TextView. if (!BuildInfo.isAtLeastO()) return false; if (!mCanEditRichlyForPastePopup) return false; ClipboardManager clipMgr = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE); if (!clipMgr.hasPrimaryClip()) return false; ClipData clipData = clipMgr.getPrimaryClip(); ClipDescription description = clipData.getDescription(); CharSequence text = clipData.getItemAt(0).getText(); boolean isPlainType = description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN); // On Android, Spanned could be copied to Clipboard as plain_text MIME type, but in some // cases, Spanned could have text format, we need to show "paste as plain text" when // that happens. if (isPlainType && (text instanceof Spanned)) { Spanned spanned = (Spanned) text; if (hasStyleSpan(spanned)) return true; } return description.hasMimeType(ClipDescription.MIMETYPE_TEXT_HTML); }
Example 5
Source File: ClipboardHelper.java From ProjectX with Apache License 2.0 | 6 votes |
/** * 粘贴 * * @param context Context * @return 数据,可能为空 */ public <T> T paste(Context context) { if (mMatcher == null) return null; final ClipboardManager manager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); if (manager == null) return null; final ClipData clip = manager.getPrimaryClip(); if (clip == null) return null; if (clip.getItemCount() <= 0) return null; final ClipData.Item item = clip.getItemAt(0); final Uri uri = item.getUri(); if (uri == null) return null; final int index = mMatcher.match(uri); final Adapter<?> adapter = getAdapter(index); if (adapter == null) return null; return onPaste(context, clip, adapter); }
Example 6
Source File: MainFragment.java From openinwa with GNU General Public License v3.0 | 5 votes |
private void setNumberFromClipBoard() { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { ClipboardManager clipboardManager = android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M ? (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE) : (ClipboardManager) getView().getContext().getSystemService(Context.CLIPBOARD_SERVICE); ClipData clipData = clipboardManager.getPrimaryClip(); if (clipData.getItemCount() > 0) { ClipData.Item item = clipData.getItemAt(0); String text = item.getText().toString(); //text='+'+text.replaceAll("/[^0-9]/", ""); mPhoneInput.setPhoneNumber(text); // isFromClipBoard = true; } } }
Example 7
Source File: ClipboardManagerUtil.java From PowerFileExplorer with GNU General Public License v3.0 | 5 votes |
public static boolean hasText() { android.text.ClipboardManager clipboardManager = ServiceUtil.getClipboardManager(); if (APILevel.require(11)) { ClipboardManager cm = (ClipboardManager) clipboardManager; ClipDescription description = cm.getPrimaryClipDescription(); ClipData clipData = cm.getPrimaryClip(); return clipData != null && description != null && (description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)); } else { return clipboardManager.hasText(); } }
Example 8
Source File: ClipboardUtils.java From Android-UtilCode with Apache License 2.0 | 5 votes |
/** * 获取剪贴板的uri * * @return 剪贴板的uri */ public static Uri getUri() { ClipboardManager clipboard = (ClipboardManager) Utils.getContext().getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = clipboard.getPrimaryClip(); if (clip != null && clip.getItemCount() > 0) { return clip.getItemAt(0).getUri(); } return null; }
Example 9
Source File: MongolEditText.java From mongol-library with MIT License | 5 votes |
public void pasteText() { Context context = getContext(); ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); if (clipboard == null) return; ClipData clip = clipboard.getPrimaryClip(); if (clip == null) return; ClipData.Item item = clip.getItemAt(0); if (item == null) return; CharSequence text = item.getText(); if (text == null) return; int start = getSelectionStart(); int end = getSelectionEnd(); mTextStorage.replace(start, end, text); }
Example 10
Source File: ClipboardUtils.java From QPM with Apache License 2.0 | 5 votes |
/** * 获取剪贴板的意图 * * @return 剪贴板的意图 */ public static Intent getIntent() { ClipboardManager cm = (ClipboardManager) Utils.getApp().getSystemService(Context.CLIPBOARD_SERVICE); //noinspection ConstantConditions ClipData clip = cm.getPrimaryClip(); if (clip != null && clip.getItemCount() > 0) { return clip.getItemAt(0).getIntent(); } return null; }
Example 11
Source File: RNClipboardAndroid.java From react-native-clipboard with MIT License | 5 votes |
@ReactMethod public void get(Callback cb) { try { ReactApplicationContext reactContext = getReactApplicationContext(); ClipboardManager clipboard = (ClipboardManager)reactContext.getSystemService(reactContext.CLIPBOARD_SERVICE); android.content.ClipData clipData = clipboard.getPrimaryClip(); if(clipData == null){ cb.invoke(""); return; } if (clipData.getItemCount() >= 1) { ClipData.Item clipDataItem = clipboard.getPrimaryClip().getItemAt(0); String data = "" + clipDataItem.getText(); cb.invoke(data); } else { cb.invoke(""); return; } } catch(Exception e) { Log.w("ClipboardAndroid", "Error in GET operation: " + e.getMessage()); } }
Example 12
Source File: SourceEditPresenterImpl.java From HaoReader with GNU General Public License v3.0 | 5 votes |
@Override public void pasteSource() { ClipboardManager clipboard = (ClipboardManager) mView.getContext().getSystemService(Context.CLIPBOARD_SERVICE); ClipData clipData = clipboard != null ? clipboard.getPrimaryClip() : null; if (clipData != null && clipData.getItemCount() > 0) { setText(String.valueOf(clipData.getItemAt(0).getText())); } }
Example 13
Source File: SystemUtils.java From Tok-Android with GNU General Public License v3.0 | 5 votes |
public static CharSequence getLastClipContent(Context context) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clipData = clipboard.getPrimaryClip(); if (clipData != null) { ClipData.Item item = clipData.getItemAt(0); if (item != null) { return item.coerceToText(context); } } return null; }
Example 14
Source File: ClipboardModule.java From clipboard with MIT License | 5 votes |
@ReactMethod public void getString(Promise promise) { try { ClipboardManager clipboard = getClipboardService(); ClipData clipData = clipboard.getPrimaryClip(); if (clipData != null && clipData.getItemCount() >= 1) { ClipData.Item firstItem = clipboard.getPrimaryClip().getItemAt(0); promise.resolve("" + firstItem.getText()); } else { promise.resolve(""); } } catch (Exception e) { promise.reject(e); } }
Example 15
Source File: LauncherActivity.java From Last-Launcher with GNU General Public License v3.0 | 5 votes |
public Map<String, Integer> clipboardData() { Map<String, Integer> result = null; // Log.d(TAG, "clipboardData: "); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { try { ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); ClipData clipData = clipboardManager.getPrimaryClip(); if (clipData.getItemCount() > 0) { ClipData.Item item = clipData.getItemAt(0); String tabSepratedData = item.getText().toString(); //Log.d(TAG, "clipboardData: " + tabSepratedData); //validate tabSepratedData and get its data //unique id bae73ae068dacc6cb659d1fb231e7b11 i.e LastLauncher-ColorSniffer MD5-128 String[] line = tabSepratedData.split("\n");//get each line Map<String, Integer> colorsAndId = new ArrayMap<>(); // map to put all values in key and values format // iterate over every line for (String entry : line) { String[] activityIdAndColor = entry.split("\t");// split line into id and color int color = Color.parseColor(activityIdAndColor[1]); colorsAndId.put(activityIdAndColor[0], color);// put id and color to map // Log.d(TAG, "clipboardData: app:" + activityIdAndColor[0] + " color==" + color); } setAppsColorFromClipboard(colorsAndId); result = colorsAndId;// return map } } catch (Exception e) { e.printStackTrace(); } } // return empty null/ return result; }
Example 16
Source File: ClipboardUtil.java From zone-sdk with MIT License | 5 votes |
@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)); } return null; }
Example 17
Source File: SourceEditPresenter.java From a with GNU General Public License v3.0 | 5 votes |
@Override public void pasteSource() { ClipboardManager clipboard = (ClipboardManager) mView.getContext().getSystemService(Context.CLIPBOARD_SERVICE); ClipData clipData = clipboard != null ? clipboard.getPrimaryClip() : null; if (clipData != null && clipData.getItemCount() > 0) { setText(String.valueOf(clipData.getItemAt(0).getText())); } }
Example 18
Source File: ClipboardUtil.java From android-common with Apache License 2.0 | 5 votes |
@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)); } return null; }
Example 19
Source File: ClipboardInterface.java From Study_Android_Demo with Apache License 2.0 | 4 votes |
public static CharSequence getText(Context context) { ClipboardManager clipboard = getManager(context); ClipData clip = clipboard.getPrimaryClip(); return hasText(context) ? clip.getItemAt(0).coerceToText(context) : null; }
Example 20
Source File: ClipboardInterface.java From Study_Android_Demo with Apache License 2.0 | 4 votes |
public static boolean hasText(Context context) { ClipboardManager clipboard = getManager(context); ClipData clip = clipboard.getPrimaryClip(); return clip != null && clip.getItemCount() > 0; }