List of usage examples for android.content Intent putParcelableArrayListExtra
public @NonNull Intent putParcelableArrayListExtra(String name, ArrayList<? extends Parcelable> value)
From source file:org.ozonecity.gpslogger2.GpsMainActivity.java
/** * Allows user to send a GPX/KML file along with location, or location only * using a provider. 'Provider' means any application that can accept such * an intent (Facebook, SMS, Twitter, Email, K-9, Bluetooth) *///from www. ja va 2 s .c om private void Share() { try { final String locationOnly = getString(R.string.sharing_location_only); final File gpxFolder = new File(AppSettings.getGpsLoggerFolder()); if (gpxFolder.exists()) { File[] enumeratedFiles = Utilities.GetFilesInFolder(gpxFolder); Arrays.sort(enumeratedFiles, new Comparator<File>() { public int compare(File f1, File f2) { return -1 * Long.valueOf(f1.lastModified()).compareTo(f2.lastModified()); } }); List<String> fileList = new ArrayList<String>(enumeratedFiles.length); for (File f : enumeratedFiles) { fileList.add(f.getName()); } fileList.add(0, locationOnly); final String[] files = fileList.toArray(new String[fileList.size()]); new MaterialDialog.Builder(this).title(R.string.osm_pick_file).items(files) .positiveText(R.string.ok) .itemsCallbackMultiChoice(null, new MaterialDialog.ListCallbackMultiChoice() { @Override public boolean onSelection(MaterialDialog materialDialog, Integer[] integers, CharSequence[] charSequences) { List<Integer> selectedItems = Arrays.asList(integers); final Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("*/*"); if (selectedItems.size() <= 0) { return false; } if (selectedItems.contains(0)) { intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.sharing_mylocation)); if (Session.hasValidLocation()) { String bodyText = getString(R.string.sharing_googlemaps_link, String.valueOf(Session.getCurrentLatitude()), String.valueOf(Session.getCurrentLongitude())); intent.putExtra(Intent.EXTRA_TEXT, bodyText); intent.putExtra("sms_body", bodyText); startActivity( Intent.createChooser(intent, getString(R.string.sharing_via))); } } else { intent.setAction(Intent.ACTION_SEND_MULTIPLE); intent.putExtra(Intent.EXTRA_SUBJECT, "Here are some files."); intent.setType("*/*"); ArrayList<Uri> chosenFiles = new ArrayList<Uri>(); for (Object path : selectedItems) { File file = new File(gpxFolder, files[Integer.valueOf(path.toString())]); Uri uri = Uri.fromFile(file); chosenFiles.add(uri); } intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, chosenFiles); startActivity(Intent.createChooser(intent, getString(R.string.sharing_via))); } return true; } }).show(); } else { Utilities.MsgBox(getString(R.string.sorry), getString(R.string.no_files_found), this); } } catch (Exception ex) { tracer.error("Sharing problem", ex); } }
From source file:com.geotrackin.gpslogger.GpsMainActivity.java
/** * Allows user to send a GPX/KML file along with location, or location only * using a provider. 'Provider' means any application that can accept such * an intent (Facebook, SMS, Twitter, Email, K-9, Bluetooth) *//*from ww w . j a v a 2 s . c o m*/ private void Share() { tracer.debug("GpsMainActivity.Share"); try { final String locationOnly = getString(R.string.sharing_location_only); final File gpxFolder = new File(AppSettings.getGpsLoggerFolder()); if (gpxFolder.exists()) { File[] enumeratedFiles = Utilities.GetFilesInFolder(gpxFolder); Arrays.sort(enumeratedFiles, new Comparator<File>() { public int compare(File f1, File f2) { return -1 * Long.valueOf(f1.lastModified()).compareTo(f2.lastModified()); } }); List<String> fileList = new ArrayList<String>(enumeratedFiles.length); for (File f : enumeratedFiles) { fileList.add(f.getName()); } fileList.add(0, locationOnly); final String[] files = fileList.toArray(new String[fileList.size()]); final ArrayList selectedItems = new ArrayList(); // Where we track the selected items AlertDialog.Builder builder = new AlertDialog.Builder(this); // Set the dialog title builder.setTitle(R.string.osm_pick_file) .setMultiChoiceItems(files, null, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { if (isChecked) { if (which == 0) { //Unselect all others ((AlertDialog) dialog).getListView().clearChoices(); ((AlertDialog) dialog).getListView().setItemChecked(which, isChecked); selectedItems.clear(); } else { //Unselect the settings item ((AlertDialog) dialog).getListView().setItemChecked(0, false); if (selectedItems.contains(0)) { selectedItems.remove(selectedItems.indexOf(0)); } } selectedItems.add(which); } else if (selectedItems.contains(which)) { // Else, if the item is already in the array, remove it selectedItems.remove(Integer.valueOf(which)); } } }).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { if (selectedItems.size() <= 0) { return; } final Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("*/*"); if (selectedItems.get(0).equals(0)) { tracer.debug("User selected location only"); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.sharing_mylocation)); if (Session.hasValidLocation()) { String bodyText = getString(R.string.sharing_googlemaps_link, String.valueOf(Session.getCurrentLatitude()), String.valueOf(Session.getCurrentLongitude())); intent.putExtra(Intent.EXTRA_TEXT, bodyText); intent.putExtra("sms_body", bodyText); startActivity( Intent.createChooser(intent, getString(R.string.sharing_via))); } } else { intent.setAction(Intent.ACTION_SEND_MULTIPLE); intent.putExtra(Intent.EXTRA_SUBJECT, "Geotrackin (Android app): Here are some files."); intent.setType("*/*"); ArrayList<Uri> chosenFiles = new ArrayList<Uri>(); for (Object path : selectedItems) { File file = new File(gpxFolder, files[Integer.valueOf(path.toString())]); Uri uri = Uri.fromFile(file); chosenFiles.add(uri); } intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, chosenFiles); startActivity(Intent.createChooser(intent, getString(R.string.sharing_via))); } } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { selectedItems.clear(); } }); builder.create(); builder.show(); } else { Utilities.MsgBox(getString(R.string.sorry), getString(R.string.no_files_found), this); } } catch (Exception ex) { tracer.error("Share", ex); } }
From source file:com.crearo.gpslogger.GpsMainActivity.java
/** * Allows user to send a GPX/KML file along with location, or location only * using a provider. 'Provider' means any application that can accept such * an intent (Facebook, SMS, Twitter, Email, K-9, Bluetooth) */// w w w . j a va 2s . co m private void share() { try { final String locationOnly = getString(R.string.sharing_location_only); final File gpxFolder = new File(preferenceHelper.getGpsLoggerFolder()); if (gpxFolder.exists()) { File[] enumeratedFiles = Files.fromFolder(gpxFolder); Arrays.sort(enumeratedFiles, new Comparator<File>() { public int compare(File f1, File f2) { return -1 * Long.valueOf(f1.lastModified()).compareTo(f2.lastModified()); } }); List<String> fileList = new ArrayList<>(enumeratedFiles.length); for (File f : enumeratedFiles) { fileList.add(f.getName()); } fileList.add(0, locationOnly); final String[] files = fileList.toArray(new String[fileList.size()]); new MaterialDialog.Builder(this).title(R.string.osm_pick_file).items(files) .positiveText(R.string.ok) .itemsCallbackMultiChoice(null, new MaterialDialog.ListCallbackMultiChoice() { @Override public boolean onSelection(MaterialDialog materialDialog, Integer[] integers, CharSequence[] charSequences) { List<Integer> selectedItems = Arrays.asList(integers); final Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("*/*"); if (selectedItems.size() <= 0) { return false; } if (selectedItems.contains(0)) { intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.sharing_mylocation)); if (Session.hasValidLocation()) { String bodyText = getString(R.string.sharing_googlemaps_link, String.valueOf(Session.getCurrentLatitude()), String.valueOf(Session.getCurrentLongitude())); intent.putExtra(Intent.EXTRA_TEXT, bodyText); intent.putExtra("sms_body", bodyText); startActivity( Intent.createChooser(intent, getString(R.string.sharing_via))); } } else { intent.setAction(Intent.ACTION_SEND_MULTIPLE); intent.putExtra(Intent.EXTRA_SUBJECT, "Here are some files."); intent.setType("*/*"); ArrayList<Uri> chosenFiles = new ArrayList<>(); for (Object path : selectedItems) { File file = new File(gpxFolder, files[Integer.valueOf(path.toString())]); Uri uri = Uri.fromFile(file); chosenFiles.add(uri); } intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, chosenFiles); startActivity(Intent.createChooser(intent, getString(R.string.sharing_via))); } return true; } }).show(); } else { Dialogs.alert(getString(R.string.sorry), getString(R.string.no_files_found), this); } } catch (Exception ex) { LOG.error("Sharing problem", ex); } }
From source file:net.alexjf.tmm.fragments.ImmedTransactionEditorFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_immedtransaction_editor, container, false); descriptionText = (EditText) v.findViewById(R.id.description_text); categoryButton = (SelectorButton) v.findViewById(R.id.category_button); executionDateButton = (Button) v.findViewById(R.id.executionDate_button); executionTimeButton = (Button) v.findViewById(R.id.executionTime_button); valueSignToggle = (SignToggleButton) v.findViewById(R.id.value_sign); valueText = (EditText) v.findViewById(R.id.value_text); currencyTextView = (TextView) v.findViewById(R.id.currency_label); transferCheck = (CheckBox) v.findViewById(R.id.transfer_check); transferPanel = (LinearLayout) v.findViewById(R.id.transfer_panel); transferMoneyNodeLabel = (TextView) v.findViewById(R.id.transfer_moneynode_label); transferMoneyNodeButton = (SelectorButton) v.findViewById(R.id.transfer_moneynode_button); transferConversionPanel = (LinearLayout) v.findViewById(R.id.transfer_conversion_panel); transferConversionAmountText = (EditText) v.findViewById(R.id.transfer_conversion_amount_value); transferConversionCurrencyLabel = (TextView) v.findViewById(R.id.transfer_conversion_amount_currency); addButton = (Button) v.findViewById(R.id.add_button); valueText.setRawInputType(InputType.TYPE_CLASS_NUMBER); FragmentManager fm = getFragmentManager(); timePicker = (TimePickerFragment) fm.findFragmentByTag(TAG_TIMEPICKER); datePicker = (DatePickerFragment) fm.findFragmentByTag(TAG_DATEPICKER); if (timePicker == null) { timePicker = new TimePickerFragment(); }// w ww. j a v a 2 s . co m if (datePicker == null) { datePicker = new DatePickerFragment(); } timePicker.setListener(this); datePicker.setListener(this); categoryButton.setOnClickListener(new OnClickListener() { public void onClick(View view) { Intent intent = new Intent(view.getContext(), CategoryListActivity.class); intent.putExtra(CategoryListActivity.KEY_INTENTION, CategoryListActivity.INTENTION_SELECT); startActivityForResult(intent, REQCODE_CATEGORYCHOOSE); } }); executionDateButton.setOnClickListener(new OnClickListener() { public void onClick(View view) { try { datePicker.setDate(dateFormat.parse(executionDateButton.getText().toString())); } catch (ParseException e) { } datePicker.show(getFragmentManager(), TAG_DATEPICKER); } }); executionTimeButton.setOnClickListener(new OnClickListener() { public void onClick(View view) { try { timePicker.setTime(timeFormat.parse(executionTimeButton.getText().toString())); } catch (ParseException e) { } timePicker.show(getFragmentManager(), TAG_TIMEPICKER); } }); valueSignToggle.setOnChangeListener(new SignToggleButton.SignToggleButtonListener() { @Override public void onChange(boolean isPositive) { if (isPositive) { transferMoneyNodeLabel.setText(getResources().getString(R.string.transfer_moneynode_from)); } else { transferMoneyNodeLabel.setText(getResources().getString(R.string.transfer_moneynode_to)); } } }); transferCheck.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton view, boolean checked) { if (checked) { transferPanel.setVisibility(View.VISIBLE); } else { transferPanel.setVisibility(View.GONE); } } ; }); transferMoneyNodeButton.setOnClickListener(new OnClickListener() { public void onClick(View view) { Intent intent = new Intent(view.getContext(), MoneyNodeListActivity.class); intent.putExtra(MoneyNodeListActivity.KEY_INTENTION, MoneyNodeListActivity.INTENTION_SELECT); ArrayList<MoneyNode> excludedMoneyNodes = new ArrayList<MoneyNode>(); excludedMoneyNodes.add(currentMoneyNode); intent.putParcelableArrayListExtra(MoneyNodeListActivity.KEY_EXCLUDE, excludedMoneyNodes); startActivityForResult(intent, REQCODE_MONEYNODECHOOSE); } }); addButton.setOnClickListener(new OnClickListener() { public void onClick(View view) { if (!validateInputFields()) { return; } String description = descriptionText.getText().toString().trim(); boolean isTransfer = transferCheck.isChecked(); Date executionDate; Date executionTime; Date executionDateTime; try { executionDate = dateFormat.parse(executionDateButton.getText().toString()); executionTime = timeFormat.parse(executionTimeButton.getText().toString()); } catch (ParseException e) { executionTime = executionDate = new Date(); } executionDateTime = Utils.combineDateTime(executionDate, executionTime); Money value; try { Calculable calc = new ExpressionBuilder(valueText.getText().toString()).build(); value = Money.of(currentMoneyNode.getCurrency(), calc.calculate(), RoundingMode.HALF_EVEN); } catch (Exception e) { Log.e("TMM", "Error calculating value expression: " + e.getMessage(), e); value = Money.zero(currentMoneyNode.getCurrency()); } if (valueSignToggle.isNegative()) { value = value.negated(); } Money currencyConversionValue = null; // If an amount was entered for conversion to other currency, set // value of transfer transaction to this amount if (isTransfer && !TextUtils.isEmpty(transferConversionAmountText.getText())) { try { Calculable calc = new ExpressionBuilder(transferConversionAmountText.getText().toString()) .build(); currencyConversionValue = Money.of(selectedTransferMoneyNode.getCurrency(), calc.calculate(), RoundingMode.HALF_EVEN); currencyConversionValue = currencyConversionValue.abs(); } catch (Exception e) { Log.e("TMM", "Error calculating conversion amount expression: " + e.getMessage(), e); currencyConversionValue = Money.zero(selectedTransferMoneyNode.getCurrency()); } if (!valueSignToggle.isNegative()) { currencyConversionValue = currencyConversionValue.negated(); } } // If we are creating a new transaction if (transaction == null) { ImmediateTransaction newTransaction = new ImmediateTransaction(currentMoneyNode, value, description, selectedCategory, executionDateTime); // If this new transaction is a transfer if (isTransfer && selectedTransferMoneyNode != null) { ImmediateTransaction otherTransaction = new ImmediateTransaction(newTransaction, selectedTransferMoneyNode); // If a value was specified for the conversion to other currency, // use that value instead of the negation of current one if (currencyConversionValue != null) { otherTransaction.setValue(currencyConversionValue); } newTransaction.setTransferTransaction(otherTransaction); otherTransaction.setTransferTransaction(newTransaction); } listener.onImmediateTransactionCreated(newTransaction); } // If we are updating an existing transaction else { ImmedTransactionEditOldInfo oldInfo = new ImmedTransactionEditOldInfo(transaction); transaction.setDescription(description); transaction.setCategory(selectedCategory); transaction.setExecutionDate(executionDateTime); transaction.setValue(value); if (isTransfer && selectedTransferMoneyNode != null) { ImmediateTransaction otherTransaction = null; // If edited transaction wasn't part of a transfer and // now is, create transfer transaction if (transaction.getTransferTransaction() == null) { otherTransaction = new ImmediateTransaction(transaction, selectedTransferMoneyNode); transaction.setTransferTransaction(otherTransaction); otherTransaction.setTransferTransaction(transaction); } // If edited transaction was already part of a // transfer, update transfer transaction else { otherTransaction = transaction.getTransferTransaction(); otherTransaction.setMoneyNode(selectedTransferMoneyNode); otherTransaction.setDescription(description); otherTransaction.setCategory(selectedCategory); otherTransaction.setExecutionDate(executionDateTime); otherTransaction.setValue(value.negated()); } // If a value was specified for the conversion to other currency, // use that value instead of the negation of current one if (currencyConversionValue != null) { otherTransaction.setValue(currencyConversionValue); } } // If edited transaction no longer is a transfer but // was a transfer before, we need to remove the opposite // transaction. else if (transaction.getTransferTransaction() != null) { transaction.setTransferTransaction(null); } listener.onImmediateTransactionEdited(transaction, oldInfo); } } }); this.savedInstanceState = savedInstanceState; return v; }
From source file:usbong.android.utils.UsbongUtils.java
public static Intent performSendToCloudBasedServiceProcess(String filepath, List<String> filePathsList) { // final Intent sendToCloudBasedServiceIntent = new Intent(android.content.Intent.ACTION_SEND); final Intent sendToCloudBasedServiceIntent; if (filePathsList != null) { sendToCloudBasedServiceIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE); } else {/*from w w w.j ava 2s . c o m*/ sendToCloudBasedServiceIntent = new Intent(android.content.Intent.ACTION_SEND); } try { InputStreamReader reader = UsbongUtils.getFileFromSDCardAsReader(filepath); BufferedReader br = new BufferedReader(reader); String currLineString; currLineString = br.readLine(); System.out.println(">>>>>>>>>> currLineString: " + currLineString); //Reference: http://blog.iangclifton.com/2010/05/17/sending-html-email-with-android-intent/ //last acccessed: 17 Jan. 2012 sendToCloudBasedServiceIntent.setType("text/plain"); sendToCloudBasedServiceIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "usbong;" + UsbongUtils.getDateTimeStamp()); sendToCloudBasedServiceIntent.putExtra(android.content.Intent.EXTRA_TEXT, currLineString); //body // sendToCloudBasedServiceIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"masarapmabuhay@gmail.com"});//"masarapmabuhay@gmail.com"); //only add path if it's not already in filePathsLists (i.e. attachmentFilePaths) if (!filePathsList.contains(filepath)) { filePathsList.add(filepath); } //Reference: http://stackoverflow.com/questions/2264622/android-multiple-email-attachments-using-intent //last accessed: 14 March 2012 //has to be an ArrayList ArrayList<Uri> uris = new ArrayList<Uri>(); //convert from paths to Android friendly Parcelable Uri's for (String file : filePathsList) { File fileIn = new File(file); if (fileIn.exists()) { //added by Mike, May 13, 2012 Uri u = Uri.fromFile(fileIn); uris.add(u); System.out.println(">>>>>>>>>>>>>>>>>> u: " + u); } } sendToCloudBasedServiceIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); } catch (Exception e) { e.printStackTrace(); } return sendToCloudBasedServiceIntent; }
From source file:com.nbplus.iotapp.bluetooth.BluetoothLeService.java
private void broadcastUpdate(final String address, final String action, final BluetoothGattCharacteristic characteristic) { final Intent intent = new Intent(action); intent.putExtra(EXTRA_DATA_SERVICE_UUID, characteristic.getService().getUuid().toString()); intent.putExtra(EXTRA_DATA_CHARACTERISTIC_UUID, characteristic.getUuid().toString()); String str = ""; byte[] values = characteristic.getValue(); Log.d(TAG,//from w w w . j ava 2 s. c om "onCharacteristicChanged: address : " + address + ", uuid:" + characteristic.getUuid().toString()); // This is special handling for the Heart Rate Measurement profile. Data parsing is // carried out as per profile specifications: // http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.heart_rate_measurement.xml if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) { int flag = characteristic.getProperties(); int format = -1; if ((flag & 0x01) != 0) { format = BluetoothGattCharacteristic.FORMAT_UINT16; Log.d(TAG, "Heart rate format UINT16."); } else { format = BluetoothGattCharacteristic.FORMAT_UINT8; Log.d(TAG, "Heart rate format UINT8."); } final int heartRate = characteristic.getIntValue(format, 1); Log.d(TAG, String.format("Received heart rate: %d", heartRate)); intent.putExtra(EXTRA_DATA, values); } else if (UUID_WEIGHT_MEASUREMENT.equals(characteristic.getUuid())) { // for weight scale int flag = values[0] & 0xff; Log.w(TAG, String.format("Measurement data received flag = %02x", flag)); /** * ? reserved field ? 2? ? ??. */ if (address != null && address.startsWith(GattAttributes.XIAOMI_MAC_ADDRESS_FILTER)) { if (values == null || values.length <= 0 || (values[0] & 0xf0) != 0x20) { Log.d(TAG, "ignore ... flag 4nibble 0x20 is not ... "); return; } } ArrayList<WeightMeasurement> measurements = WeightMeasurement.parseWeightMeasurement(address, characteristic.getUuid().toString(), values); intent.putParcelableArrayListExtra(EXTRA_DATA, measurements); } else if (UUID_GLUCOSE_MEASUREMENT.equals(characteristic.getUuid())) { GlucoseMeasurement measurement = GlucoseMeasurement.parseGlucoseMeasurement(values); intent.putExtra(EXTRA_DATA, measurement); } else if (UUID_GLUCOSE_MEASUREMENT_CONTEXT.equals(characteristic.getUuid())) { } else if (UUID_RECORD_ACCESS_CONTROL_POINT.equals(characteristic.getUuid())) { RecordAccessControlPoint recordAccessControlPoint = RecordAccessControlPoint .parseRecordAccessControlPoint(values); intent.putExtra(EXTRA_DATA, recordAccessControlPoint); } else if (UUID.fromString(GattAttributes.CURRENT_TIME).equals(characteristic.getUuid())) { if (values != null && values.length > 0) { intent.putExtra(EXTRA_DATA, values); } //intent.putExtra(EXTRA_DATA, characteristic.getValue()); } else { // For all other profiles, writes the data formatted in HEX. if (values != null && values.length > 0) { intent.putExtra(EXTRA_DATA, values); } } sendBroadcast(intent); }
From source file:it.feio.android.omninotes.DetailFragment.java
private void initViewAttachments() { // Attachments position based on preferences if (prefs.getBoolean(Constants.PREF_ATTANCHEMENTS_ON_BOTTOM, false)) { attachmentsBelow.inflate();//from w w w.ja v a2s .c o m } else { attachmentsAbove.inflate(); } mGridView = (ExpandableHeightGridView) root.findViewById(R.id.gridview); // Some fields can be filled by third party application and are always shown mAttachmentAdapter = new AttachmentAdapter(mainActivity, noteTmp.getAttachmentsList(), mGridView); // Initialzation of gridview for images mGridView.setAdapter(mAttachmentAdapter); mGridView.autoresize(); // Click events for images in gridview (zooms image) mGridView.setOnItemClickListener((parent, v, position, id) -> { Attachment attachment = (Attachment) parent.getAdapter().getItem(position); Uri uri = attachment.getUri(); Intent attachmentIntent; if (Constants.MIME_TYPE_FILES.equals(attachment.getMime_type())) { attachmentIntent = new Intent(Intent.ACTION_VIEW); attachmentIntent.setDataAndType(uri, StorageHelper.getMimeType(mainActivity, attachment.getUri())); attachmentIntent .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); if (IntentChecker.isAvailable(mainActivity.getApplicationContext(), attachmentIntent, null)) { startActivity(attachmentIntent); } else { mainActivity.showMessage(R.string.feature_not_available_on_this_device, ONStyle.WARN); } // Media files will be opened in internal gallery } else if (Constants.MIME_TYPE_IMAGE.equals(attachment.getMime_type()) || Constants.MIME_TYPE_SKETCH.equals(attachment.getMime_type()) || Constants.MIME_TYPE_VIDEO.equals(attachment.getMime_type())) { // Title noteTmp.setTitle(getNoteTitle()); noteTmp.setContent(getNoteContent()); String title1 = TextHelper.parseTitleAndContent(mainActivity, noteTmp)[0].toString(); // Images int clickedImage = 0; ArrayList<Attachment> images = new ArrayList<>(); for (Attachment mAttachment : noteTmp.getAttachmentsList()) { if (Constants.MIME_TYPE_IMAGE.equals(mAttachment.getMime_type()) || Constants.MIME_TYPE_SKETCH.equals(mAttachment.getMime_type()) || Constants.MIME_TYPE_VIDEO.equals(mAttachment.getMime_type())) { images.add(mAttachment); if (mAttachment.equals(attachment)) { clickedImage = images.size() - 1; } } } // Intent attachmentIntent = new Intent(mainActivity, GalleryActivity.class); attachmentIntent.putExtra(Constants.GALLERY_TITLE, title1); attachmentIntent.putParcelableArrayListExtra(Constants.GALLERY_IMAGES, images); attachmentIntent.putExtra(Constants.GALLERY_CLICKED_IMAGE, clickedImage); startActivity(attachmentIntent); } else if (Constants.MIME_TYPE_AUDIO.equals(attachment.getMime_type())) { playback(v, attachment.getUri()); } }); mGridView.setOnItemLongClickListener((parent, v, position, id) -> { // To avoid deleting audio attachment during playback if (mPlayer != null) return false; List<String> items = Arrays.asList(getResources().getStringArray(R.array.attachments_actions)); if (!Constants.MIME_TYPE_SKETCH.equals(mAttachmentAdapter.getItem(position).getMime_type())) { items = items.subList(0, items.size() - 1); } new MaterialDialog.Builder(mainActivity).title(mAttachmentAdapter.getItem(position).getName()) .items(items.toArray(new String[items.size()])) .itemsCallback((materialDialog, view, i, charSequence) -> performAttachmentAction(position, i)) .build().show(); return true; }); }
From source file:org.apache.cordova.EmailComposer.java
private void sendEmail(JSONObject parameters) { final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE); // String callback = parameters.getString("callback"); System.out.println(parameters.toString()); boolean isHTML = false; try {/*from w w w . ja v a2s . c om*/ isHTML = parameters.getBoolean("bIsHTML"); } catch (Exception e) { LOG.e("EmailComposer", "Error handling isHTML param: " + e.toString()); } if (isHTML) { emailIntent.setType("text/html"); } else { emailIntent.setType("text/plain"); } // setting subject try { String subject = parameters.getString("subject"); if (subject != null && subject.length() > 0) { emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject); } } catch (Exception e) { LOG.e("EmailComposer", "Error handling subject param: " + e.toString()); } // setting body try { String body = parameters.getString("body"); if (body != null && body.length() > 0) { if (isHTML) { emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(body)); } else { emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body); } } } catch (Exception e) { LOG.e("EmailComposer", "Error handling body param: " + e.toString()); } // setting TO recipients try { JSONArray toRecipients = parameters.getJSONArray("toRecipients"); if (toRecipients != null && toRecipients.length() > 0) { String[] to = new String[toRecipients.length()]; for (int i = 0; i < toRecipients.length(); i++) { to[i] = toRecipients.getString(i); } emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, to); } } catch (Exception e) { LOG.e("EmailComposer", "Error handling toRecipients param: " + e.toString()); } // setting CC recipients try { JSONArray ccRecipients = parameters.getJSONArray("ccRecipients"); if (ccRecipients != null && ccRecipients.length() > 0) { String[] cc = new String[ccRecipients.length()]; for (int i = 0; i < ccRecipients.length(); i++) { cc[i] = ccRecipients.getString(i); } emailIntent.putExtra(android.content.Intent.EXTRA_CC, cc); } } catch (Exception e) { LOG.e("EmailComposer", "Error handling ccRecipients param: " + e.toString()); } // setting BCC recipients try { JSONArray bccRecipients = parameters.getJSONArray("bccRecipients"); if (bccRecipients != null && bccRecipients.length() > 0) { String[] bcc = new String[bccRecipients.length()]; for (int i = 0; i < bccRecipients.length(); i++) { bcc[i] = bccRecipients.getString(i); } emailIntent.putExtra(android.content.Intent.EXTRA_BCC, bcc); } } catch (Exception e) { LOG.e("EmailComposer", "Error handling bccRecipients param: " + e.toString()); } // setting attachments try { JSONArray attachments = parameters.getJSONArray("attachments"); if (attachments != null && attachments.length() > 0) { ArrayList<Uri> uris = new ArrayList<Uri>(); // convert from paths to Android friendly Parcelable Uri's for (int i = 0; i < attachments.length(); i++) { try { File file = new File(attachments.getString(i)); if (file.exists()) { Uri uri = Uri.fromFile(file); uris.add(uri); } } catch (Exception e) { LOG.e("EmailComposer", "Error adding an attachment: " + e.toString()); } } if (uris.size() > 0) { emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); } } } catch (Exception e) { LOG.e("EmailComposer", "Error handling attachments param: " + e.toString()); } this.cordova.startActivityForResult(this, emailIntent, 0); }
From source file:com.dycode.jepretstory.mediachooser.fragment.ImageFragment.java
private void setAdapter(Cursor imagecursor) { if (imagecursor.getCount() > 0) { mGalleryModelList = new ArrayList<MediaModel>(); for (int i = 0; i < imagecursor.getCount(); i++) { imagecursor.moveToPosition(i); int dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.DATA); //int thumbnailColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Thumbnails.DATA); int idColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Media._ID); //int idColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Thumbnails.IMAGE_ID); int bucketColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.BUCKET_ID); int orientColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.ImageColumns.ORIENTATION); String imgUrl = imagecursor.getString(dataColumnIndex).toString(); // boolean selected = false; // if (mSelectedModels != null && mSelectedModels.size() > 0) { // for(String currImgUrl: mSelectedItems) { // if (currImgUrl.equalsIgnoreCase(imgUrl)) { // selected = true; // break; // } // } // } String id = imagecursor.getString(idColumnIndex); String thumbId = "";//imagecursor.getString(idColumnIndex); String bucketId = imagecursor.getString(bucketColumnIndex); String thumbUrl = "";//imagecursor.getString(thumbnailColumnIndex).toString(); int orientation = imagecursor.getInt(orientColumnIndex); MediaModel galleryModel = new MediaModel(bucketId, id, imgUrl, thumbId, thumbUrl, false, MediaType.IMAGE);// w w w .java 2 s . c o m if (mSelectedModels != null && mSelectedModels.size() > 0) { galleryModel.status = mSelectedModels.contains(galleryModel); } galleryModel.orientation = orientation; //processThumbnailImage(id, galleryModel, getActivity()); mGalleryModelList.add(galleryModel); } mImageAdapter = new GridViewAdapter(getActivity(), 0, mGalleryModelList, false); mImageGridView.setAdapter(mImageAdapter); } else { Toast.makeText(getActivity(), getActivity().getString(R.string.no_media_file_available), Toast.LENGTH_SHORT).show(); } mImageGridView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter(); MediaModel galleryModel = (MediaModel) adapter.getItem(position); File file = new File(galleryModel.url); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "image/*"); startActivity(intent); return true; } }); mImageGridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // update the mStatus of each category in the adapter GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter(); MediaModel galleryModel = (MediaModel) adapter.getItem(position); if (!galleryModel.status) { long size = MediaChooserConstants.ChekcMediaFileSize(new File(galleryModel.url.toString()), false); if (size != 0) { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.file_size_exeeded) + " " + MediaChooserConstants.SELECTED_IMAGE_SIZE_IN_MB + " " + getActivity().getResources().getString(R.string.mb), Toast.LENGTH_SHORT).show(); return; } if (MediaChooserConstants.MAX_MEDIA_LIMIT == 1) { //remove all first if (mSelectedModels.size() >= 1) { MediaModel selModel = (MediaModel) mSelectedModels.get(0); selModel.status = false; mSelectedModels.clear(); MediaChooserConstants.SELECTED_MEDIA_COUNT--; } } if ((MediaChooserConstants.MAX_MEDIA_LIMIT == MediaChooserConstants.SELECTED_MEDIA_COUNT)) { if (MediaChooserConstants.SELECTED_MEDIA_COUNT < 2) { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.max_limit_file) + " " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + getActivity().getResources().getString(R.string.file), Toast.LENGTH_SHORT).show(); return; } else { Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.max_limit_file) + " " + MediaChooserConstants.SELECTED_MEDIA_COUNT + " " + getActivity().getResources().getString(R.string.files), Toast.LENGTH_SHORT).show(); return; } } } // inverse the status galleryModel.status = !galleryModel.status; adapter.notifyDataSetChanged(); if (galleryModel.status) { //mSelectedItems.add(galleryModel.url.toString()); mSelectedModels.add(galleryModel); MediaChooserConstants.SELECTED_MEDIA_COUNT++; } else { //mSelectedItems.remove(galleryModel.url.toString().trim()); mSelectedModels.remove(galleryModel); MediaChooserConstants.SELECTED_MEDIA_COUNT--; } if (mCallback != null) { mCallback.onImageSelectedCount(mSelectedModels.size()); if (galleryModel.status) { mCallback.onImageSelected(galleryModel); } else { mCallback.onImageUnselected(galleryModel); } Intent intent = new Intent(); //intent.putStringArrayListExtra("list", mSelectedItems); intent.putParcelableArrayListExtra("selectedImages", mSelectedModels); getActivity().setResult(Activity.RESULT_OK, intent); } } }); }
From source file:com.dycody.android.idealnote.DetailFragment.java
private void initViewAttachments() { // Attachments position based on preferences if (prefs.getBoolean(Constants.PREF_ATTANCHEMENTS_ON_BOTTOM, false)) { attachmentsBelow.inflate();// w ww .j a v a2s . c o m } else { attachmentsAbove.inflate(); } mGridView = (ExpandableHeightGridView) root.findViewById(R.id.gridview); // Some fields can be filled by third party application and are always shown mAttachmentAdapter = new AttachmentAdapter(mainActivity, noteTmp.getAttachmentsList(), mGridView); // Initialzation of gridview for images mGridView.setAdapter(mAttachmentAdapter); mGridView.autoresize(); // Click events for images in gridview (zooms image) mGridView.setOnItemClickListener((parent, v, position, id) -> { Attachment attachment = (Attachment) parent.getAdapter().getItem(position); Uri uri = attachment.getUri(); Intent attachmentIntent; if (Constants.MIME_TYPE_FILES.equals(attachment.getMime_type())) { attachmentIntent = new Intent(Intent.ACTION_VIEW); attachmentIntent.setDataAndType(uri, StorageHelper.getMimeType(mainActivity, attachment.getUri())); attachmentIntent .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); if (IntentChecker.isAvailable(mainActivity.getApplicationContext(), attachmentIntent, null)) { startActivity(attachmentIntent); } else { Toast.makeText(getActivity(), R.string.feature_not_available_on_this_device, Toast.LENGTH_SHORT) .show(); //mainActivity.showMessage(R.string.feature_not_available_on_this_device, ONStyle.WARN); } // Media files will be opened in internal gallery } else if (Constants.MIME_TYPE_IMAGE.equals(attachment.getMime_type()) || Constants.MIME_TYPE_SKETCH.equals(attachment.getMime_type()) || Constants.MIME_TYPE_VIDEO.equals(attachment.getMime_type())) { // Title noteTmp.setTitle(getNoteTitle()); noteTmp.setContent(getNoteContent()); String title1 = TextHelper.parseTitleAndContent(mainActivity, noteTmp)[0].toString(); // Images int clickedImage = 0; ArrayList<Attachment> images = new ArrayList<>(); for (Attachment mAttachment : noteTmp.getAttachmentsList()) { if (Constants.MIME_TYPE_IMAGE.equals(mAttachment.getMime_type()) || Constants.MIME_TYPE_SKETCH.equals(mAttachment.getMime_type()) || Constants.MIME_TYPE_VIDEO.equals(mAttachment.getMime_type())) { images.add(mAttachment); if (mAttachment.equals(attachment)) { clickedImage = images.size() - 1; } } } // Intent attachmentIntent = new Intent(mainActivity, GalleryActivity.class); attachmentIntent.putExtra(Constants.GALLERY_TITLE, title1); attachmentIntent.putParcelableArrayListExtra(Constants.GALLERY_IMAGES, images); attachmentIntent.putExtra(Constants.GALLERY_CLICKED_IMAGE, clickedImage); startActivity(attachmentIntent); } else if (Constants.MIME_TYPE_AUDIO.equals(attachment.getMime_type())) { playback(v, attachment.getUri()); } }); mGridView.setOnItemLongClickListener((parent, v, position, id) -> { // To avoid deleting audio attachment during playback if (mPlayer != null) return false; List<String> items = Arrays.asList(getResources().getStringArray(R.array.attachments_actions)); if (!Constants.MIME_TYPE_SKETCH.equals(mAttachmentAdapter.getItem(position).getMime_type())) { items = items.subList(0, items.size() - 1); } Attachment attachment = mAttachmentAdapter.getItem(position); new MaterialDialog.Builder(mainActivity) .title(attachment.getName() + " (" + AttachmentsHelper.getSize(attachment) + ")") .items(items.toArray(new String[items.size()])) .itemsCallback((materialDialog, view, i, charSequence) -> performAttachmentAction(position, i)) .build().show(); return true; }); }