List of usage examples for android.content ClipData getItemCount
public int getItemCount()
From source file:Main.java
/** * /*from ww w .j a v a2s. com*/ * @param context * @return */ public static CharSequence pasteToResult(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { ClipData clipData = ((android.content.ClipboardManager) context .getSystemService(Context.CLIPBOARD_SERVICE)).getPrimaryClip(); if ((clipData == null) || (clipData.getItemCount() <= 0)) { return null; } ClipData.Item item = clipData.getItemAt(0); if (item == null) { return null; } return item.getText(); } return ((android.text.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE)).getText(); }
From source file:Main.java
/** * Convert {@link ClipData} to String for storing. * @param clip//from w ww .j a v a 2 s . c o m * @return String for specifed clipdata */ public static CharSequence stringFromClipData(ClipData clip) { StringBuilder sb = new StringBuilder(); if (clip != null) { append(sb, "clip"); appendClipDescription(sb, clip.getDescription()); int n = clip.getItemCount(); appendInt(sb, n); for (int i = 0; i < n; i++) { appendItem(sb, clip.getItemAt(i)); } } else { append(sb, (String) null); } return sb; }
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 ww.ja v a2 s. c o m*/ 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:com.pavlospt.rxfile.RxFile.java
public static Observable<List<File>> createFilesFromClipData(final Context context, final ClipData clipData) { return Observable.defer(new Func0<Observable<List<File>>>() { @Override/* w w w . j av a 2 s. co m*/ public Observable<List<File>> call() { int numOfUris = clipData.getItemCount(); List<File> filesRetrieved = new ArrayList<>(numOfUris); for (int i = 0; i < numOfUris; i++) { Uri data = clipData.getItemAt(i).getUri(); if (data != null) { try { filesRetrieved.add(fileFromUri(context, data)); } catch (Exception e) { logError("Exception:" + e.getMessage() + " line: 117"); e.printStackTrace(); return Observable.error(e); } } } return Observable.just(filesRetrieved); } }); }
From source file:com.xxxifan.devbox.library.rxfile.RxFile.java
public static Observable<List<File>> createFilesFromClipData(final Context context, final ClipData clipData) { return Observable.defer(new Func0<Observable<List<File>>>() { @Override/* w w w .ja v a 2s . c om*/ public Observable<List<File>> call() { int numOfUris = clipData.getItemCount(); List<File> filesRetrieved = new ArrayList<>(numOfUris); for (int i = 0; i < numOfUris; i++) { Uri data = clipData.getItemAt(i).getUri(); if (data != null) { try { filesRetrieved.add(fileFromUri(context, data)); } catch (Exception e) { Log.e(TAG, "Exception: " + e.getMessage()); e.printStackTrace(); return Observable.error(e); } } } return Observable.just(filesRetrieved); } }); }
From source file:com.commonsware.android.tte.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_OPEN: if (resultCode == Activity.RESULT_OK) { if (data.getData() == null) { ClipData clip = data.getClipData(); for (int i = 0; i < clip.getItemCount(); i++) { openEditor(clip.getItemAt(i).getUri()); }//from w w w . j av a 2 s .c om } else { openEditor(data.getData()); } } break; case REQUEST_CREATE: if (resultCode == Activity.RESULT_OK) { openEditor(data.getData()); } break; } }
From source file:com.actionbarsherlock.sample.hcgallery.ContentFragment.java
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; }//from w w w . java 2 s .co m 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.frag_title); titlesFrag.selectPosition(entryId); return true; } } } return false; }
From source file:im.neon.util.VectorUtils.java
/** * Return a selected bitmap from an intent. * * @param intent the intent/*from w w w .j av a 2 s. c o m*/ * @return the bitmap uri */ @SuppressLint("NewApi") public static Uri getThumbnailUriFromIntent(Context context, final Intent intent, MXMediasCache mediasCache) { // sanity check if ((null != intent) && (null != context) && (null != mediasCache)) { Uri thumbnailUri = null; ClipData clipData = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { clipData = intent.getClipData(); } // multiple data if (null != clipData) { if (clipData.getItemCount() > 0) { thumbnailUri = clipData.getItemAt(0).getUri(); } } else if (null != intent.getData()) { thumbnailUri = intent.getData(); } if (null != thumbnailUri) { try { ResourceUtils.Resource resource = ResourceUtils.openResource(context, thumbnailUri, null); // sanity check if ((null != resource) && resource.isJpegResource()) { InputStream stream = resource.mContentStream; int rotationAngle = ImageUtils.getRotationAngleForBitmap(context, thumbnailUri); String mediaUrl = ImageUtils.scaleAndRotateImage(context, stream, resource.mMimeType, 1024, rotationAngle, mediasCache); thumbnailUri = Uri.parse(mediaUrl); } return thumbnailUri; } catch (Exception e) { Log.e(LOG_TAG, "## etThumbnailUriFromIntent failed " + e.getMessage()); } } } return null; }
From source file:com.commonsware.cwac.cam2.support.CameraActivity.java
private Uri getOutputUri() { Uri output = null;/* ww w. j a v a2 s . c o m*/ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { ClipData clipData = getIntent().getClipData(); if (clipData != null && clipData.getItemCount() > 0) { output = clipData.getItemAt(0).getUri(); } } if (output == null) { output = getIntent().getParcelableExtra(MediaStore.EXTRA_OUTPUT); } return (output); }
From source file:com.Jsu.framework.image.imageChooser.ImageChooserManager.java
@SuppressLint("NewApi") private void processImageFromGallery(Intent data) { if (data != null && data.getDataString() != null) { String uri = data.getData().toString(); sanitizeURI(uri);/* w w w . j a v a2 s.c om*/ if (filePathOriginal == null || TextUtils.isEmpty(filePathOriginal)) { onError("File path was null"); } else { if (BuildConfig.DEBUG) { Log.i(TAG, "File: " + filePathOriginal); } String path = filePathOriginal; ImageProcessorThread thread = new ImageProcessorThread(path, foldername, shouldCreateThumbnails); thread.clearOldFiles(clearOldFiles); thread.setListener(this); thread.setContext(getContext()); thread.start(); } } else if (data.getClipData() != null || data.hasExtra("uris")) { // Multiple Images String[] filePaths; if (data.hasExtra("uris")) { ArrayList<Uri> uris = data.getParcelableArrayListExtra("uris"); filePaths = new String[uris.size()]; for (int i = 0; i < uris.size(); i++) { filePaths[i] = uris.get(i).toString(); } } else { ClipData clipData = data.getClipData(); int count = clipData.getItemCount(); filePaths = new String[count]; for (int i = 0; i < count; i++) { ClipData.Item item = clipData.getItemAt(i); Log.i(TAG, "processImageFromGallery: Item: " + item.getUri()); filePaths[i] = item.getUri().toString(); } } ImageProcessorThread thread = new ImageProcessorThread(filePaths, foldername, shouldCreateThumbnails); thread.clearOldFiles(clearOldFiles); thread.setListener(this); thread.setContext(getContext()); thread.start(); // } else if () { } else { onError("Image Uri was null!"); } }