List of usage examples for android.content ClipData getItemCount
public int getItemCount()
From source file:org.kontalk.ui.ComposeMessageFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { // image from storage/picture from camera // since there are like up to 3 different ways of doing this... if (requestCode == SELECT_ATTACHMENT_OPENABLE || requestCode == SELECT_ATTACHMENT_PHOTO) { if (resultCode == Activity.RESULT_OK) { Uri[] uris = null;// www . j av a 2 s. c om String[] mimes = null; // returning from camera if (data == null) { if (mCurrentPhoto != null) { Uri uri = Uri.fromFile(mCurrentPhoto); // notify media scanner Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); mediaScanIntent.setData(uri); getActivity().sendBroadcast(mediaScanIntent); mCurrentPhoto = null; uris = new Uri[] { uri }; } } else { if (mCurrentPhoto != null) { mCurrentPhoto.delete(); mCurrentPhoto = null; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && data.getClipData() != null) { ClipData cdata = data.getClipData(); uris = new Uri[cdata.getItemCount()]; for (int i = 0; i < uris.length; i++) { ClipData.Item item = cdata.getItemAt(i); uris[i] = item.getUri(); } } else { uris = new Uri[] { data.getData() }; mimes = new String[] { data.getType() }; } // SAF available, request persistable permissions if (MediaStorage.isStorageAccessFrameworkAvailable()) { for (Uri uri : uris) { if (uri != null && !"file".equals(uri.getScheme())) { MediaStorage.requestPersistablePermissions(getActivity(), uri); } } } } for (int i = 0; uris != null && i < uris.length; i++) { Uri uri = uris[i]; String mime = (mimes != null && mimes.length >= uris.length) ? mimes[i] : null; if (mime == null || mime.startsWith("*/") || mime.endsWith("/*")) { mime = MediaStorage.getType(getActivity(), uri); Log.v(TAG, "using detected mime type " + mime); } if (ImageComponent.supportsMimeType(mime)) sendBinaryMessage(uri, mime, true, ImageComponent.class); else if (VCardComponent.supportsMimeType(mime)) sendBinaryMessage(uri, VCardComponent.MIME_TYPE, false, VCardComponent.class); else Toast.makeText(getActivity(), R.string.send_mime_not_supported, Toast.LENGTH_LONG).show(); } } // operation aborted else { // delete photo :) if (mCurrentPhoto != null) { mCurrentPhoto.delete(); mCurrentPhoto = null; } } } // contact card (vCard) else if (requestCode == SELECT_ATTACHMENT_CONTACT) { if (resultCode == Activity.RESULT_OK) { Uri uri = data.getData(); if (uri != null) { // get lookup key final Cursor c = getActivity().getContentResolver().query(uri, new String[] { Contacts.LOOKUP_KEY }, null, null, null); if (c != null) { try { c.moveToFirst(); String lookupKey = c.getString(0); Uri vcardUri = Uri.withAppendedPath(Contacts.CONTENT_VCARD_URI, lookupKey); sendBinaryMessage(vcardUri, VCardComponent.MIME_TYPE, false, VCardComponent.class); } finally { c.close(); } } } } } }
From source file:org.mdc.chess.MDChess.java
private void clipBoardDialog() { final int COPY_GAME = 0; final int COPY_POSITION = 1; final int PASTE = 2; setAutoMode(AutoMode.OFF);//from w w w . ja v a 2s . c o m List<CharSequence> lst = new ArrayList<>(); List<Integer> actions = new ArrayList<>(); lst.add(getString(R.string.copy_game)); actions.add(COPY_GAME); lst.add(getString(R.string.copy_position)); actions.add(COPY_POSITION); lst.add(getString(R.string.paste)); actions.add(PASTE); final List<Integer> finalActions = actions; new MaterialDialog.Builder(this).title(R.string.tools_menu).items(lst) .itemsCallback(new MaterialDialog.ListCallback() { @Override public void onSelection(MaterialDialog dialog, View view, int which, CharSequence text) { switch (finalActions.get(which)) { case COPY_GAME: { String pgn = ctrl.getPGN(); ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboard.setPrimaryClip(new ClipData("MD Chess game", new String[] { "application/x-chess-pgn", ClipDescription.MIMETYPE_TEXT_PLAIN }, new ClipData.Item(pgn))); break; } case COPY_POSITION: { String fen = ctrl.getFEN() + "\n"; ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboard.setPrimaryClip(new ClipData(fen, new String[] { "application/x-chess-fen", ClipDescription.MIMETYPE_TEXT_PLAIN }, new ClipData.Item(fen))); break; } case PASTE: { ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); if (clipboard.hasPrimaryClip()) { ClipData clip = clipboard.getPrimaryClip(); StringBuilder fenPgn = new StringBuilder(); for (int i = 0; i < clip.getItemCount(); i++) { fenPgn.append(clip.getItemAt(i).coerceToText(getApplicationContext())); } try { ctrl.setFENOrPGN(fenPgn.toString()); setBoardFlip(true); } catch (ChessParseError e) { Toast.makeText(getApplicationContext(), getParseErrString(e), Toast.LENGTH_SHORT).show(); } } break; } } } }).show(); }
From source file:com.android.mail.compose.ComposeActivity.java
/** * Add attachment and update the compose area appropriately. *///from ww w .j a va 2 s. com private void addAttachmentAndUpdateView(Intent data) { if (data == null) { return; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { final ClipData clipData = data.getClipData(); if (clipData != null) { for (int i = 0, size = clipData.getItemCount(); i < size; i++) { addAttachmentAndUpdateView(clipData.getItemAt(i).getUri()); } return; } } addAttachmentAndUpdateView(data.getData()); }