List of usage examples for android.content ClipData getItemCount
public int getItemCount()
From source file:com.codebutler.farebot.fragment.CardsFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { ClipboardManager clipboardManager = (ClipboardManager) getActivity() .getSystemService(Context.CLIPBOARD_SERVICE); try {//from w w w . j a va 2s . c o m int itemId = item.getItemId(); switch (itemId) { case R.id.import_file: Intent target = new Intent(Intent.ACTION_GET_CONTENT); target.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(Environment.getExternalStorageDirectory())); target.setType("*/*"); startActivityForResult(Intent.createChooser(target, getString(R.string.select_file)), REQUEST_SELECT_FILE); return true; case R.id.import_clipboard: ClipData clip = clipboardManager.getPrimaryClip(); if (clip != null && clip.getItemCount() > 0) { String text = clip.getItemAt(0).coerceToText(getActivity()).toString(); onCardsImported(mExportHelper.importCards(text)); } return true; case R.id.copy: clipboardManager.setPrimaryClip(ClipData.newPlainText(null, mExportHelper.exportCards())); Toast.makeText(getActivity(), R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show(); return true; case R.id.share: Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, mExportHelper.exportCards()); startActivity(intent); return true; case R.id.save: exportToFile(); return true; } } catch (Exception ex) { Utils.showError(getActivity(), ex); } return false; }
From source file:com.heneryh.aquanotes.ui.livestock.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; }/* w w w . ja v a2 s. c o 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.titles_frag); // titlesFrag.selectPosition(entryId); return true; } } } return false; }
From source file:org.alfresco.mobile.android.application.fragments.upload.UploadFormFragment.java
@Override public void onStart() { super.onStart(); Intent intent = getActivity().getIntent(); String action = intent.getAction(); String type = intent.getType(); if (files != null) { files.clear();//w w w. j a v a 2 s. c o m } try { if (Intent.ACTION_SEND_MULTIPLE.equals(action)) { if (AndroidVersion.isJBOrAbove()) { ClipData clipdata = intent.getClipData(); if (clipdata != null && clipdata.getItemCount() > 1) { Item item = null; for (int i = 0; i < clipdata.getItemCount(); i++) { item = clipdata.getItemAt(i); Uri uri = item.getUri(); if (uri != null) { retrieveIntentInfo(uri); } else { String timeStamp = new SimpleDateFormat("yyyyddMM_HHmmss").format(new Date()); File localParentFolder = StorageManager.getCacheDir(getActivity(), "AlfrescoMobile/import"); File f = createFile(localParentFolder, timeStamp + ".txt", item.getText().toString()); if (f.exists()) { retrieveIntentInfo(Uri.fromFile(f)); } } if (!files.contains(file)) { files.add(file); } } } } else { if (intent.getExtras() != null && intent.getExtras().get(Intent.EXTRA_STREAM) instanceof ArrayList) { @SuppressWarnings("unchecked") List<Object> attachments = (ArrayList<Object>) intent.getExtras().get(Intent.EXTRA_STREAM); for (Object object : attachments) { if (object instanceof Uri) { Uri uri = (Uri) object; if (uri != null) { retrieveIntentInfo(uri); } if (!files.contains(file)) { files.add(file); } } } } else if (file == null || fileName == null) { MessengerManager.showLongToast(getActivity(), getString(R.string.import_unsupported_intent)); getActivity().finish(); return; } } } else { // Manage only one clip data. If multiple we ignore. if (AndroidVersion.isJBOrAbove() && (!Intent.ACTION_SEND.equals(action) || type == null)) { ClipData clipdata = intent.getClipData(); if (clipdata != null && clipdata.getItemCount() == 1 && clipdata.getItemAt(0) != null && (clipdata.getItemAt(0).getText() != null || clipdata.getItemAt(0).getUri() != null)) { Item item = clipdata.getItemAt(0); Uri uri = item.getUri(); if (uri != null) { retrieveIntentInfo(uri); } else { String timeStamp = new SimpleDateFormat("yyyyddMM_HHmmss").format(new Date()); File localParentFolder = StorageManager.getCacheDir(getActivity(), "AlfrescoMobile/import"); File f = createFile(localParentFolder, timeStamp + ".txt", item.getText().toString()); if (f.exists()) { retrieveIntentInfo(Uri.fromFile(f)); } } } } if (file == null && Intent.ACTION_SEND.equals(action) && type != null) { Uri uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); retrieveIntentInfo(uri); } else if (action == null && intent.getData() != null) { retrieveIntentInfo(intent.getData()); } else if (file == null || fileName == null) { MessengerManager.showLongToast(getActivity(), getString(R.string.import_unsupported_intent)); getActivity().finish(); return; } if (!files.contains(file)) { files.add(file); } } } catch (AlfrescoAppException e) { org.alfresco.mobile.android.application.manager.ActionManager.actionDisplayError(this, e); getActivity().finish(); return; } if (adapter == null && files != null) { adapter = new FileExplorerAdapter(this, R.layout.app_list_progress_row, files); if (lv != null) { lv.setAdapter(adapter); } else if (spinnerDoc != null) { spinnerDoc.setAdapter(adapter); } } Button b = UIUtils.initCancel(rootView, R.string.cancel); b.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { getActivity().finish(); } }); b = UIUtils.initValidation(rootView, R.string.next); b.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { next(); } }); refreshImportFolder(); }
From source file:org.fs.galleon.presenters.ToolsFragmentPresenter.java
@Override public void activityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_PICK_GALLERY) { if (resultCode == Activity.RESULT_OK) { ClipData clipData = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { clipData = data.getClipData(); }/*from www.j a va2 s . c om*/ if (clipData != null) { //multi choice List<ImageEntity> items = IntStreams.range(0, clipData.getItemCount()) .mapToObj(clipData::getItemAt) .map(item -> Images.getPath(view.getContext(), item.getUri())) .map(xPath -> new ImageEntity.Builder().imageUri(Uri.fromFile(new File(xPath))).build()) .collect(Collectors.toList()); createIfImageListNotExists(); if (!Collections.isNullOrEmpty(items)) { images.addAll(items); } } else { //single choice Uri uri = data.getData(); if (uri != null) { String path = Images.getPath(view.getContext(), uri); ImageEntity entity = new ImageEntity.Builder().imageUri(Uri.fromFile(new File(path))) .build(); createIfImageListNotExists(); images.add(entity); } } } } else if (requestCode == REQUEST_TAKE_PHOTO) { if (resultCode == Activity.RESULT_OK) { if (tempTakenPhoto != null && tempTakenPhoto.exists()) { ImageEntity entity = new ImageEntity.Builder().imageUri(Uri.fromFile(tempTakenPhoto)).build(); //I might need to use orientation data and etc. createIfImageListNotExists();//create if its null if (view.isAvailable()) { images.add(entity); } tempTakenPhoto = null;//clear it now } } } }
From source file:ee.ria.DigiDoc.fragment.ContainerDetailsFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == CHOOSE_FILE_REQUEST_ID && resultCode == RESULT_OK && data != null) { ClipData clipData; Uri uriData;/* ww w. ja v a 2 s . c om*/ if ((clipData = data.getClipData()) != null) { for (int i = 0; i < clipData.getItemCount(); i++) { ClipData.Item item = clipData.getItemAt(i); Uri uri = item.getUri(); if (uri != null) { addToFileList(uri); } } } else if ((uriData = data.getData()) != null) { addToFileList(uriData); } } }
From source file:com.raspi.chatapp.ui.chatting.ChatActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // if the user chose a image to be sent to the current buddy switch (requestCode) { case SEND_CAMERA_IMAGE_REQUEST_CODE: if (resultCode == RESULT_OK && data != null) sendImages(data.getData());/* w w w .ja v a 2 s . c o m*/ break; case SEND_LIBRARY_IMAGE_REQUEST_CODE: if (resultCode == Activity.RESULT_OK) { if (data.getData() != null) // only one image was selected sendImages(data.getData()); else if (data.getClipData() != null) { // multiple images were selected ArrayList<Uri> uris = new ArrayList<>(); ClipData clipData = data.getClipData(); for (int i = 0; i < clipData.getItemCount(); i++) uris.add(clipData.getItemAt(i).getUri()); Uri[] array = new Uri[uris.size()]; sendImages(uris.toArray(array)); } } break; case PasswordActivity.ASK_PWD_REQUEST: // if the user has entered a password or exited the passwordActivity // otherwise. if (resultCode == Activity.RESULT_OK) { // if the pwd was correct do not request a new pwd. Yep this function // is called before onResume, therefore, this would end in an // infinity loop otherwise... getSharedPreferences(Constants.PREFERENCES, 0).edit().putBoolean(Constants.PWD_REQUEST, false) .apply(); // actually I am not sure, shouldn't the onResume function be called // which calls init? init(); } else { // if (PreferenceManager.getDefaultSharedPreferences(getApplication()) // .getBoolean( // getResources().getString(R.string.pref_key_enablepwd), // true)) // startActivityForResult(new Intent(this, PasswordActivity.class), // PasswordActivity.ASK_PWD_REQUEST); // I suppose I should finish the activity here as the user pressed // back. TODO: I am not sure whether on resume gets called and finish // will really finish if the passwordActivity is called... finish(); } break; } }
From source file:com.google.android.apps.muzei.gallery.GallerySettingsActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent result) { if (requestCode != REQUEST_CHOOSE_PHOTOS || resultCode != RESULT_OK) { super.onActivityResult(requestCode, resultCode, result); return;//from w w w.j a va2 s .co m } if (result == null) { return; } // Add chosen items final Set<Uri> uris = new HashSet<>(); if (result.getData() != null) { uris.add(result.getData()); } // When selecting multiple images, "Photos" returns the first URI in getData and all URIs // in getClipData. ClipData clipData = result.getClipData(); if (clipData != null) { int count = clipData.getItemCount(); for (int i = 0; i < count; i++) { uris.add(clipData.getItemAt(i).getUri()); } } // Update chosen URIs runOnHandlerThread(new Runnable() { @Override public void run() { ArrayList<ContentProviderOperation> operations = new ArrayList<>(); for (Uri uri : uris) { ContentValues values = new ContentValues(); values.put(GalleryContract.ChosenPhotos.COLUMN_NAME_URI, uri.toString()); operations.add(ContentProviderOperation.newInsert(GalleryContract.ChosenPhotos.CONTENT_URI) .withValues(values).build()); } try { getContentResolver().applyBatch(GalleryContract.AUTHORITY, operations); } catch (RemoteException | OperationApplicationException e) { Log.e(TAG, "Error writing uris to ContentProvider", e); } } }); }
From source file:com.raspi.chatapp.ui.chatting.SendImageFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // if the user chose a image to be sent to the current buddy if (requestCode == ADD_PHOTO_CLICKED && resultCode == Activity.RESULT_OK) { if (data.getData() != null) { // one image was selected Message msg = new Message(data.getData()); images.add(msg);/* w ww . j a va 2 s . c o m*/ current = images.size() - 1; } else if (data.getClipData() != null) { // multiple images were selected ClipData clipData = data.getClipData(); for (int i = 0; i < clipData.getItemCount(); i++) images.add(new Message(clipData.getItemAt(i).getUri())); current = images.size() - 1; } } }
From source file:net.gsantner.opoc.util.ShareUtil.java
/** * Get clipboard contents, very failsafe and compat to older android versions *///from w w w.j av a 2s .c om public List<String> getClipboard() { List<String> clipper = new ArrayList<>(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { android.text.ClipboardManager cm = ((android.text.ClipboardManager) _context .getSystemService(Context.CLIPBOARD_SERVICE)); if (cm != null && !TextUtils.isEmpty(cm.getText())) { clipper.add(cm.getText().toString()); } } else { android.content.ClipboardManager cm = ((android.content.ClipboardManager) _context .getSystemService(Context.CLIPBOARD_SERVICE)); if (cm != null && cm.hasPrimaryClip()) { ClipData data = cm.getPrimaryClip(); for (int i = 0; data != null && i < data.getItemCount() && i < data.getItemCount(); i++) { ClipData.Item item = data.getItemAt(i); if (item != null && !TextUtils.isEmpty(item.getText())) { clipper.add(data.getItemAt(i).getText().toString()); } } } } return clipper; }
From source file:com.anjalimacwan.MainActivity.java
@TargetApi(Build.VERSION_CODES.KITKAT) @Override/*from ww w. j av a2 s . co m*/ public void onActivityResult(int requestCode, int resultCode, Intent resultData) { if (resultCode == RESULT_OK && resultData != null) { successful = true; if (requestCode == IMPORT) { Uri uri = resultData.getData(); ClipData clipData = resultData.getClipData(); if (uri != null) successful = importNote(uri); else if (clipData != null) for (int i = 0; i < clipData.getItemCount(); i++) { successful = importNote(clipData.getItemAt(i).getUri()); } // Show toast notification showToast(successful ? (uri == null ? R.string.notes_imported_successfully : R.string.note_imported_successfully) : R.string.error_importing_notes); // Send broadcast to NoteListFragment to refresh list of notes Intent listNotesIntent = new Intent(); listNotesIntent.setAction("com.anjalimacwan.LIST_NOTES"); LocalBroadcastManager.getInstance(this).sendBroadcast(listNotesIntent); } else if (requestCode == EXPORT) { try { saveExportedNote(loadNote(filesToExport[fileBeingExported].toString()), resultData.getData()); } catch (IOException e) { successful = false; } fileBeingExported++; if (fileBeingExported < filesToExport.length) reallyExportNote(); else showToast(successful ? (fileBeingExported == 1 ? R.string.note_exported_to : R.string.notes_exported_to) : R.string.error_exporting_notes); } else if (requestCode == EXPORT_TREE) { DocumentFile tree = DocumentFile.fromTreeUri(this, resultData.getData()); for (Object exportFilename : filesToExport) { try { DocumentFile file = tree.createFile("text/plain", generateFilename(loadNoteTitle(exportFilename.toString()))); saveExportedNote(loadNote(exportFilename.toString()), file.getUri()); } catch (IOException e) { successful = false; } } showToast(successful ? R.string.notes_exported_to : R.string.error_exporting_notes); } } }