use of android.net.MailTo in project cyborg-core by nu-art.
the class CyborgWebView method sendMailUrl.
private void sendMailUrl(String url) {
MailTo mailTo = MailTo.parse(url);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { mailTo.getTo() });
intent.putExtra(Intent.EXTRA_TEXT, mailTo.getBody());
intent.putExtra(Intent.EXTRA_SUBJECT, mailTo.getSubject());
intent.putExtra(Intent.EXTRA_CC, mailTo.getCc());
intent.setType("message/rfc822");
getContext().startActivity(intent);
}
use of android.net.MailTo in project android by nextcloud.
the class ProcessVEvent method convertToDB.
// Munge a VEvent so Android won't reject it, then convert to ContentValues for inserting
private ContentValues convertToDB(VEvent e, Options options, List<Integer> reminders, long calendarId) {
reminders.clear();
boolean allDay = false;
boolean startIsDate = !(e.getStartDate().getDate() instanceof DateTime);
boolean isRecurring = hasProperty(e, Property.RRULE) || hasProperty(e, Property.RDATE);
if (startIsDate) {
// If the start date is a DATE we expect the end date to be a date too and the
// event is all-day, midnight to midnight (RFC 2445).
allDay = true;
}
if (!hasProperty(e, Property.DTEND) && !hasProperty(e, Property.DURATION)) {
// No end date or duration given.
// Since we added a duration above when the start date is a DATE:
// - The start date is a DATETIME, the event lasts no time at all (RFC 2445).
e.getProperties().add(ZERO_SECONDS);
// Zero time events are always free (RFC 2445), so override/set TRANSP accordingly.
removeProperty(e, Property.TRANSP);
e.getProperties().add(Transp.TRANSPARENT);
}
if (isRecurring) {
// Recurring event. Android insists on a duration.
if (!hasProperty(e, Property.DURATION)) {
// Calculate duration from start to end date
Duration d = new Duration(e.getStartDate().getDate(), e.getEndDate().getDate());
e.getProperties().add(d);
}
removeProperty(e, Property.DTEND);
} else {
// Non-recurring event. Android insists on an end date.
if (!hasProperty(e, Property.DTEND)) {
// Calculate end date from duration, set it and remove the duration.
e.getProperties().add(e.getEndDate());
}
removeProperty(e, Property.DURATION);
}
// Now calculate the db values for the event
ContentValues c = new ContentValues();
c.put(Events.CALENDAR_ID, calendarId);
copyProperty(c, Events.TITLE, e, Property.SUMMARY);
copyProperty(c, Events.DESCRIPTION, e, Property.DESCRIPTION);
if (e.getOrganizer() != null) {
URI uri = e.getOrganizer().getCalAddress();
try {
MailTo mailTo = MailTo.parse(uri.toString());
c.put(Events.ORGANIZER, mailTo.getTo());
// Ensure we can edit if not the organiser
c.put(Events.GUESTS_CAN_MODIFY, 1);
} catch (ParseException ignored) {
Log_OC.e(TAG, "Failed to parse Organiser URI " + uri.toString());
}
}
copyProperty(c, Events.EVENT_LOCATION, e, Property.LOCATION);
if (hasProperty(e, Property.STATUS)) {
String status = e.getProperty(Property.STATUS).getValue();
switch(status) {
case "TENTATIVE":
c.put(Events.STATUS, Events.STATUS_TENTATIVE);
break;
case "CONFIRMED":
c.put(Events.STATUS, Events.STATUS_CONFIRMED);
break;
case // NOTE: In ical4j it is CANCELLED with two L
"CANCELLED":
c.put(Events.STATUS, Events.STATUS_CANCELED);
break;
}
}
copyProperty(c, Events.DURATION, e, Property.DURATION);
if (allDay) {
c.put(Events.ALL_DAY, 1);
}
copyDateProperty(c, Events.DTSTART, Events.EVENT_TIMEZONE, e.getStartDate());
if (hasProperty(e, Property.DTEND)) {
copyDateProperty(c, Events.DTEND, Events.EVENT_END_TIMEZONE, e.getEndDate());
}
if (hasProperty(e, Property.CLASS)) {
String access = e.getProperty(Property.CLASS).getValue();
int accessLevel = Events.ACCESS_DEFAULT;
switch(access) {
case "CONFIDENTIAL":
accessLevel = Events.ACCESS_CONFIDENTIAL;
break;
case "PRIVATE":
accessLevel = Events.ACCESS_PRIVATE;
break;
case "PUBLIC":
accessLevel = Events.ACCESS_PUBLIC;
break;
}
c.put(Events.ACCESS_LEVEL, accessLevel);
}
// Work out availability. This is confusing as FREEBUSY and TRANSP overlap.
if (Events.AVAILABILITY != null) {
int availability = Events.AVAILABILITY_BUSY;
if (hasProperty(e, Property.TRANSP)) {
if (e.getTransparency() == Transp.TRANSPARENT) {
availability = Events.AVAILABILITY_FREE;
}
} else if (hasProperty(e, Property.FREEBUSY)) {
FreeBusy fb = (FreeBusy) e.getProperty(Property.FREEBUSY);
FbType fbType = (FbType) fb.getParameter(Parameter.FBTYPE);
if (fbType != null && fbType == FbType.FREE) {
availability = Events.AVAILABILITY_FREE;
} else if (fbType != null && fbType == FbType.BUSY_TENTATIVE) {
availability = Events.AVAILABILITY_TENTATIVE;
}
}
c.put(Events.AVAILABILITY, availability);
}
copyProperty(c, Events.RRULE, e, Property.RRULE);
copyProperty(c, Events.RDATE, e, Property.RDATE);
copyProperty(c, Events.EXRULE, e, Property.EXRULE);
copyProperty(c, Events.EXDATE, e, Property.EXDATE);
copyProperty(c, Events.CUSTOM_APP_URI, e, Property.URL);
copyProperty(c, Events.UID_2445, e, Property.UID);
if (c.containsKey(Events.UID_2445) && TextUtils.isEmpty(c.getAsString(Events.UID_2445))) {
// Remove null/empty UIDs
c.remove(Events.UID_2445);
}
for (Object alarm : e.getAlarms()) {
VAlarm a = (VAlarm) alarm;
if (a.getAction() != Action.AUDIO && a.getAction() != Action.DISPLAY) {
// Ignore email and procedure alarms
continue;
}
Trigger t = a.getTrigger();
final long startMs = e.getStartDate().getDate().getTime();
long alarmStartMs = startMs;
long alarmMs;
// - Check the calendars max number of alarms
if (t.getDateTime() != null) {
// Absolute
alarmMs = t.getDateTime().getTime();
} else if (t.getDuration() != null && t.getDuration().isNegative()) {
Related rel = (Related) t.getParameter(Parameter.RELATED);
if (rel != null && rel == Related.END) {
alarmStartMs = e.getEndDate().getDate().getTime();
}
// Relative
alarmMs = alarmStartMs - durationToMs(t.getDuration());
} else {
continue;
}
int reminder = (int) ((startMs - alarmMs) / DateUtils.MINUTE_IN_MILLIS);
if (reminder >= 0 && !reminders.contains(reminder)) {
reminders.add(reminder);
}
}
if (options.getReminders(reminders).size() > 0) {
c.put(Events.HAS_ALARM, 1);
}
// FIXME: Attendees, SELF_ATTENDEE_STATUS
return c;
}
use of android.net.MailTo in project Lightning-Browser by anthonycr.
the class LightningWebClient method isMailOrIntent.
private boolean isMailOrIntent(@NonNull String url, @NonNull WebView view) {
if (url.startsWith("mailto:")) {
MailTo mailTo = MailTo.parse(url);
Intent i = Utils.newEmailIntent(mailTo.getTo(), mailTo.getSubject(), mailTo.getBody(), mailTo.getCc());
mActivity.startActivity(i);
view.reload();
return true;
} else if (url.startsWith("intent://")) {
Intent intent;
try {
intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
} catch (URISyntaxException ignored) {
intent = null;
}
if (intent != null) {
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setComponent(null);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
intent.setSelector(null);
}
try {
mActivity.startActivity(intent);
} catch (ActivityNotFoundException e) {
Log.e(TAG, "ActivityNotFoundException");
}
return true;
}
} else if (url.startsWith(Constants.FILE)) {
File file = new File(url.replace(Constants.FILE, ""));
if (file.exists()) {
String newMimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(Utils.guessFileExtension(file.toString()));
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Uri contentUri = FileProvider.getUriForFile(mActivity, BuildConfig.APPLICATION_ID + ".fileprovider", file);
intent.setDataAndType(contentUri, newMimeType);
try {
mActivity.startActivity(intent);
} catch (Exception e) {
System.out.println("LightningWebClient: cannot open downloaded file");
}
return true;
}
}
return false;
}
Aggregations