List of usage examples for android.content ClipData getItemAt
public Item getItemAt(int index)
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();//from w w w . jav a2s .co 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: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 . j a va 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: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;/* w w w . j a 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:org.puder.trs80.EmulatorActivity.java
private void paste() { if (!clipboardManager.hasPrimaryClip()) { return;// w w w. j av a 2 s . com } ClipData clip = clipboardManager.getPrimaryClip(); ClipData.Item item = clip.getItemAt(0); CharSequence text = item.getText(); if (text != null) { XTRS.paste(text.toString().replace('\n', '\015')); } }
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 w w . ja v a 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: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;//ww w . java 2 s .c o 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:org.puder.trs80.EmulatorActivity.java
private void updateMenuIcons() { if (muteMenuItem != null && unmuteMenuItem != null) { if (soundMuted) { muteMenuItem.setVisible(true); unmuteMenuItem.setVisible(false); } else {// w ww. jav a 2 s . c om muteMenuItem.setVisible(false); unmuteMenuItem.setVisible(true); } } if (pasteMenuItem != null) { boolean hasClip = false; if (clipboardManager.hasPrimaryClip()) { ClipData clip = clipboardManager.getPrimaryClip(); ClipData.Item item = clip.getItemAt(0); CharSequence text = item.getText(); hasClip = (text != null) && !text.equals(""); } pasteMenuItem.setEnabled(hasClip); } }
From source file:net.gsantner.opoc.util.ShareUtil.java
/** * Get clipboard contents, very failsafe and compat to older android versions *//* w ww. java 2s.c o m*/ 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 w w w . j a va2 s . c o 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); } } }
From source file:com.android.calculator2.Calculator.java
@Override public boolean onPaste(ClipData clip) { final ClipData.Item item = clip.getItemCount() == 0 ? null : clip.getItemAt(0); if (item == null) { // nothing to paste, bail early... return false; }/* w w w .j a v a2 s .c om*/ // Check if the item is a previously copied result, otherwise paste as raw text. final Uri uri = item.getUri(); if (uri != null && mEvaluator.isLastSaved(uri)) { if (mCurrentState == CalculatorState.ERROR || mCurrentState == CalculatorState.RESULT) { setState(CalculatorState.INPUT); mEvaluator.clear(); } mEvaluator.appendSaved(); redisplayAfterFormulaChange(); } else { addChars(item.coerceToText(this).toString(), false); } return true; }