Java Code Examples for android.content.ClipData#getItemAt()
The following examples show how to use
android.content.ClipData#getItemAt() .
These examples are extracted from open source projects.
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 Project: AgentWebX5 File: FileUpLoadChooserImpl.java License: Apache License 2.0 | 6 votes |
private Uri[] processData(Intent data) { Uri[] datas = null; if (data == null) { return datas; } String target = data.getDataString(); if (!TextUtils.isEmpty(target)) { return datas = new Uri[]{Uri.parse(target)}; } ClipData mClipData = null; if (mClipData != null && mClipData.getItemCount() > 0) { datas = new Uri[mClipData.getItemCount()]; for (int i = 0; i < mClipData.getItemCount(); i++) { ClipData.Item mItem = mClipData.getItemAt(i); datas[i] = mItem.getUri(); } } return datas; }
Example 2
Source Project: ProjectX File: ClipboardHelper.java License: 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 3
Source Project: Pixiv-Shaft File: ClipBoardUtils.java License: MIT License | 6 votes |
public static String getClipboardContent(Context context) { ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); if (cm != null) { ClipData data = cm.getPrimaryClip(); if (data != null && data.getItemCount() > 0) { ClipData.Item item = data.getItemAt(0); if (item != null) { CharSequence sequence = item.coerceToText(context); if (sequence != null) { return sequence.toString(); } } } } return null; }
Example 4
Source Project: AndroidProjects File: PassWordInputLayout.java License: MIT License | 6 votes |
private boolean handleWrapperLongClicked() { final ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); ClipData clipData = null; if (clipboard != null) { clipData = clipboard.getPrimaryClip(); } if (clipData == null || clipData.getItemCount() == 0) return false; final ClipData.Item clipItem = clipData.getItemAt(0); if (clipItem == null || clipItem.getText() == null) return false; final List<String> wordList = Arrays.asList(clipItem.getText().toString().split(" ")); if (wordList.size() > 12) { showErrorMessage(getContext().getString(R.string.paste_passphrase_error)); return false; } pastePassphrase(wordList); return true; }
Example 5
Source Project: belvedere File: MediaSource.java License: Apache License 2.0 | 6 votes |
/** * Extract {@link Uri} from an {@link Intent} that comes back from a gallery * or the android document picker. * * <p> * If the user selects multiple media files, it's necessary to check if * {@link Intent#getClipData()} contains data. Support for selecting multiple * files was introduced with Android Jelly Bean. * {@link android.os.Build.VERSION_CODES#JELLY_BEAN} * <br> * A single selected item is available by calling {@link Intent#getData()}. * <br> * Pretty messed up :/ * </p> * * @param intent The returned {@link Intent}, containing {@link Uri} to the selected * media * @return A list of {link Uri} */ @SuppressLint("NewApi") private List<Uri> extractUrisFromIntent(Intent intent){ final List<Uri> images = new ArrayList<>(); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && intent.getClipData() != null) { final ClipData clipData = intent.getClipData(); for (int i = 0, itemCount = clipData.getItemCount(); i < itemCount; i++) { final ClipData.Item itemAt = clipData.getItemAt(i); if (itemAt.getUri() != null) { images.add(itemAt.getUri()); } } } else if(intent.getData() != null){ images.add(intent.getData()); } return images; }
Example 6
Source Project: timecat File: ClipboardUtils.java License: Apache License 2.0 | 6 votes |
/** * 获取剪切板的内容 * * @param context * * @return */ public static CharSequence getText(Context context) { StringBuilder sb = new StringBuilder(); if (isNew()) { instance(context); if (!mNewClipboardManager.hasPrimaryClip()) { return sb.toString(); } else { ClipData clipData = (mNewClipboardManager).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(); }
Example 7
Source Project: aard2-android File: MainActivity.java License: GNU General Public License v3.0 | 6 votes |
@Override public void onWindowFocusChanged(boolean hasFocus) { ClipboardManager cm = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE); ClipData clipData = cm.getPrimaryClip(); if (clipData == null) { return; } int count = clipData.getItemCount(); for (int i = 0; i < count; i++) { ClipData.Item item = clipData.getItemAt(i); CharSequence text = item.getText(); if (text != null && text.length() > 0) { if (Patterns.WEB_URL.matcher(text).find()) { Log.d(TAG, "Text contains web url, not pasting: " + text); return; } viewPager.setCurrentItem(0); cm.setPrimaryClip(ClipData.newPlainText(null, "")); appSectionsPagerAdapter.tabLookup.setQuery(text.toString()); break; } } }
Example 8
Source Project: Tok-Android File: SystemUtils.java License: 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 9
Source Project: ShizuruNotes File: LogUtils.java License: Apache License 2.0 | 5 votes |
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN) private static void clipData2String(ClipData clipData, StringBuilder sb) { ClipData.Item item = clipData.getItemAt(0); if (item == null) { sb.append("ClipData.Item {}"); return; } sb.append("ClipData.Item { "); String mHtmlText = item.getHtmlText(); if (mHtmlText != null) { sb.append("H:"); sb.append(mHtmlText); sb.append("}"); return; } CharSequence mText = item.getText(); if (mText != null) { sb.append("T:"); sb.append(mText); sb.append("}"); return; } Uri uri = item.getUri(); if (uri != null) { sb.append("U:").append(uri); sb.append("}"); return; } Intent intent = item.getIntent(); if (intent != null) { sb.append("I:"); sb.append(intent2String(intent)); sb.append("}"); return; } sb.append("NULL"); sb.append("}"); }
Example 10
Source Project: Android-utils File: L.java License: Apache License 2.0 | 5 votes |
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN) private static void clipData2String(ClipData clipData, StringBuilder sb) { ClipData.Item item = clipData.getItemAt(0); if (item == null) { sb.append("ClipData.Item {}"); return; } sb.append("ClipData.Item { "); String mHtmlText = item.getHtmlText(); if (mHtmlText != null) { sb.append("H:"); sb.append(mHtmlText); sb.append("}"); return; } CharSequence mText = item.getText(); if (mText != null) { sb.append("T:"); sb.append(mText); sb.append("}"); return; } Uri uri = item.getUri(); if (uri != null) { sb.append("U:").append(uri); sb.append("}"); return; } Intent intent = item.getIntent(); if (intent != null) { sb.append("I:"); sb.append(intent2String(intent)); sb.append("}"); return; } sb.append("NULL"); sb.append("}"); }
Example 11
Source Project: talk-android File: ClipboardHelper.java License: MIT License | 5 votes |
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(); } } return text; }
Example 12
Source Project: user-interface-samples File: ImageDragListener.java License: Apache License 2.0 | 5 votes |
private boolean processDrop(View view, DragEvent event) { ClipData clipData = event.getClipData(); if (clipData == null || clipData.getItemCount() == 0) { return false; } ClipData.Item item = clipData.getItemAt(0); if (item == null) { return false; } Uri uri = item.getUri(); if (uri == null) { return false; } return setImageUri(view, event, uri); }
Example 13
Source Project: AndroidAnimationExercise File: MailActivity.java License: Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_mail); ButterKnife.bind(this); mContext = this; Intent receiveIntent = getIntent(); if (receiveIntent != null) { if (receiveIntent.getClipData() != null) { ClipData mClipData = receiveIntent.getClipData(); for (int i = 0; i < mClipData.getItemCount(); i++) { ClipData.Item mItem = mClipData.getItemAt(i); CharSequence text = mItem.getText(); String[] datas = text.toString().split("http"); if (datas.length > 1) { Log.e(TAG, "onCreate: " + datas[0]); Log.e(TAG, "onCreate: " + "http" + datas[1]); } } } } }
Example 14
Source Project: codeexamples-android File: ContentFragment.java License: Eclipse Public License 1.0 | 5 votes |
boolean processDrop(DragEvent event, ImageView imageView) { // Attempt to parse clip data with expected format: category||entry_id. // Ignore event if data does not conform to this format. ClipData data = event.getClipData(); if (data != null) { if (data.getItemCount() > 0) { Item item = data.getItemAt(0); String textData = (String) item.getText(); if (textData != null) { StringTokenizer tokenizer = new StringTokenizer(textData, "||"); if (tokenizer.countTokens() != 2) { return false; } int category = -1; int entryId = -1; try { category = Integer.parseInt(tokenizer.nextToken()); entryId = Integer.parseInt(tokenizer.nextToken()); } catch (NumberFormatException exception) { return false; } updateContentAndRecycleBitmap(category, entryId); // Update list fragment with selected entry. TitlesFragment titlesFrag = (TitlesFragment) getFragmentManager().findFragmentById(R.id.titles_frag); titlesFrag.selectPosition(entryId); return true; } } } return false; }
Example 15
Source Project: openinwa File: MainFragment.java License: 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 16
Source Project: quickimagepick File: QiPick.java License: Apache License 2.0 | 5 votes |
@SuppressLint("NewApi") private static void handleResultFromDocuments(final int pRequestType, @NonNull final PickCallback pCallback, @Nullable final Intent pData) { final Uri pictureUri = pData == null ? null : pData.getData(); if (pictureUri == null) { final ClipData clipData = API_18 ? pData != null ? pData.getClipData() : null : null; if (clipData != null) { final ArrayList<Uri> uris = new ArrayList<>(); for (int i = 0; i < clipData.getItemCount(); i++) { final ClipData.Item item = clipData.getItemAt(i); final Uri uri = item.getUri(); if (uri != null) { uris.add(uri); } } if (uris.isEmpty()) { pCallback.onError(PickSource.DOCUMENTS, pRequestType, ERR_DOCS_NULL_RESULT); } else { pCallback.onMultipleImagesPicked(pRequestType, uris); } } else { pCallback.onError(PickSource.DOCUMENTS, pRequestType, ERR_DOCS_NULL_RESULT); } } else { pCallback.onImagePicked(PickSource.DOCUMENTS, pRequestType, pictureUri); } }
Example 17
Source Project: Chimee File: CodeConverterActivity.java License: MIT License | 5 votes |
private String getClipboardText() { ClipboardManager clipboard = (ClipboardManager) 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 ""; return item.getText().toString(); }
Example 18
Source Project: mongol-library File: MongolEditText.java License: 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 19
Source Project: Spyglass File: MentionsEditText.java License: Apache License 2.0 | 4 votes |
/** * Paste clipboard content between min and max positions. * If clipboard content contain the MentionSpan, set the span in copied text. */ private void paste(@IntRange(from = 0) int min, @IntRange(from = 0) int max) { ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = clipboard.getPrimaryClip(); if (clip != null) { for (int i = 0; i < clip.getItemCount(); i++) { ClipData.Item item = clip.getItemAt(i); String selectedText = item.coerceToText(getContext()).toString(); MentionsEditable text = getMentionsText(); MentionSpan[] spans = text.getSpans(min, max, MentionSpan.class); /* * We need to remove the span between min and max. This is required because in * {@link SpannableStringBuilder#replace(int, int, CharSequence)} existing spans within * the Editable that entirely cover the replaced range are retained, but any that * were strictly within the range that was replaced are removed. In our case the existing * spans are retained if the selection entirely covers the span. So, we just remove * the existing span and replace the new text with that span. */ for (MentionSpan span : spans) { if (text.getSpanEnd(span) == min) { // We do not want to remove the span, when we want to paste anything just next // to the existing span. In this case "text.getSpanEnd(span)" will be equal // to min. continue; } text.removeSpan(span); } Intent intent = item.getIntent(); // Just set the plain text if we do not have mentions data in the intent/bundle if (intent == null) { text.replace(min, max, selectedText); continue; } Bundle bundle = intent.getExtras(); if (bundle == null) { text.replace(min, max, selectedText); continue; } bundle.setClassLoader(getContext().getClassLoader()); int[] spanStart = bundle.getIntArray(KEY_MENTION_SPAN_STARTS); Parcelable[] parcelables = bundle.getParcelableArray(KEY_MENTION_SPANS); if (parcelables == null || parcelables.length <= 0 || spanStart == null || spanStart.length <= 0) { text.replace(min, max, selectedText); continue; } // Set the MentionSpan in text. SpannableStringBuilder s = new SpannableStringBuilder(selectedText); for (int j = 0; j < parcelables.length; j++) { MentionSpan mentionSpan = (MentionSpan) parcelables[j]; s.setSpan(mentionSpan, spanStart[j], spanStart[j] + mentionSpan.getDisplayString().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } text.replace(min, max, s); } } }
Example 20
Source Project: 365browser File: ContentViewCore.java License: Apache License 2.0 | 4 votes |
/** * @see View#onDragEvent(DragEvent) */ @TargetApi(Build.VERSION_CODES.N) public boolean onDragEvent(DragEvent event) { if (mNativeContentViewCore == 0 || Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) { return false; } ClipDescription clipDescription = event.getClipDescription(); // text/* will match text/uri-list, text/html, text/plain. String[] mimeTypes = clipDescription == null ? new String[0] : clipDescription.filterMimeTypes("text/*"); if (event.getAction() == DragEvent.ACTION_DRAG_STARTED) { // TODO(hush): support dragging more than just text. return mimeTypes != null && mimeTypes.length > 0 && nativeIsTouchDragDropEnabled(mNativeContentViewCore); } StringBuilder content = new StringBuilder(""); if (event.getAction() == DragEvent.ACTION_DROP) { // TODO(hush): obtain dragdrop permissions, when dragging files into Chrome/WebView is // supported. Not necessary to do so for now, because only text dragging is supported. ClipData clipData = event.getClipData(); final int itemCount = clipData.getItemCount(); for (int i = 0; i < itemCount; i++) { ClipData.Item item = clipData.getItemAt(i); content.append(item.coerceToStyledText(mContainerView.getContext())); } } int[] locationOnScreen = new int[2]; mContainerView.getLocationOnScreen(locationOnScreen); float xPix = event.getX() + mCurrentTouchOffsetX; float yPix = event.getY() + mCurrentTouchOffsetY; int xCss = (int) mRenderCoordinates.fromPixToDip(xPix); int yCss = (int) mRenderCoordinates.fromPixToDip(yPix); int screenXCss = (int) mRenderCoordinates.fromPixToDip(xPix + locationOnScreen[0]); int screenYCss = (int) mRenderCoordinates.fromPixToDip(yPix + locationOnScreen[1]); nativeOnDragEvent(mNativeContentViewCore, event.getAction(), xCss, yCss, screenXCss, screenYCss, mimeTypes, content.toString()); return true; }