summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatt Garnes <matt@cyngn.com>2014-12-08 17:47:07 -0800
committerSteve Kondik <steve@cyngn.com>2015-10-18 13:52:41 -0700
commite2f50583236c11ddf78866b32222824e658be444 (patch)
tree6db608e5eeba51ee6739f8a06f3123faf50117da /src
parent7b95358fdd3f9759a70fb4d27f2d2be4c5f796c6 (diff)
downloadandroid_packages_apps_Calendar-e2f50583236c11ddf78866b32222824e658be444.tar.gz
android_packages_apps_Calendar-e2f50583236c11ddf78866b32222824e658be444.tar.bz2
android_packages_apps_Calendar-e2f50583236c11ddf78866b32222824e658be444.zip
Support sharing calendar events as .vcs files to MMS.
- Export calendar events to a temporary .vcs file. Currently, the actual file format is still ical, this may need to be reformatted to actually contain only vCalendar content. - Share this specifically to the com.android.mms package when the share button is clicked. - Share the event as ical .ics to all other applications. Change-Id: If337360b17d4071d580087ecc97a2397d0563ff6
Diffstat (limited to 'src')
-rw-r--r--src/com/android/calendar/AllInOneActivity.java16
-rw-r--r--src/com/android/calendar/EventInfoFragment.java22
-rw-r--r--src/com/android/calendar/icalendar/IcalendarUtils.java52
3 files changed, 81 insertions, 9 deletions
diff --git a/src/com/android/calendar/AllInOneActivity.java b/src/com/android/calendar/AllInOneActivity.java
index 7bcb6772..3c869574 100644
--- a/src/com/android/calendar/AllInOneActivity.java
+++ b/src/com/android/calendar/AllInOneActivity.java
@@ -451,8 +451,8 @@ public class AllInOneActivity extends AbstractCalendarActivity implements EventH
getLoaderManager().initLoader(0, null, this);
}
- // clean up cached ics files - in case onDestroy() didn't run the last time
- cleanupCachedIcsFiles();
+ // clean up cached ics and vcs files - in case onDestroy() didn't run the last time
+ cleanupCachedEventFiles();
}
private long parseViewAction(final Intent intent) {
@@ -644,22 +644,22 @@ public class AllInOneActivity extends AbstractCalendarActivity implements EventH
CalendarController.removeInstance(this);
- // clean up cached ics files
- cleanupCachedIcsFiles();
+ // clean up cached ics and vcs files
+ cleanupCachedEventFiles();
}
/**
- * Cleans up the temporarily generated ics files in the cache directory
- * The files are of the format *.ics
+ * Cleans up the temporarily generated ics and vcs files in the cache directory
+ * The files are of the format *.ics and *.vcs
*/
- private void cleanupCachedIcsFiles() {
+ private void cleanupCachedEventFiles() {
if (!isExternalStorageWritable()) return;
File cacheDir = getExternalCacheDir();
File[] files = cacheDir.listFiles();
if (files == null) return;
for (File file : files) {
String filename = file.getName();
- if (filename.endsWith(".ics")) {
+ if (filename.endsWith(".ics") || filename.endsWith(".vcs")) {
file.delete();
}
}
diff --git a/src/com/android/calendar/EventInfoFragment.java b/src/com/android/calendar/EventInfoFragment.java
index 85be389d..90f73b02 100644
--- a/src/com/android/calendar/EventInfoFragment.java
+++ b/src/com/android/calendar/EventInfoFragment.java
@@ -1340,7 +1340,27 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
// the ics file is sent as an extra, the receiving application decides whether to
// parse the file to extract calendar events or treat it as a regular file
shareIntent.setType("application/octet-stream");
- startActivity(shareIntent);
+
+ Intent chooserIntent = Intent.createChooser(shareIntent,
+ getResources().getString(R.string.cal_share_intent_title));
+
+ // The MMS app only responds to "text/x-vcalendar" so we create a chooser intent
+ // that includes the targeted mms intent + any that respond to the above general
+ // purpose "application/octet-stream" intent.
+ File vcsInviteFile = File.createTempFile(filePrefix, ".vcs",
+ mActivity.getExternalCacheDir());
+ // for now , we are duplicating ics file and using that as the vcs file
+ // TODO: revisit above
+ if (IcalendarUtils.copyFile(inviteFile, vcsInviteFile)) {
+ Intent mmsShareIntent = new Intent();
+ mmsShareIntent.setAction(Intent.ACTION_SEND);
+ mmsShareIntent.setPackage("com.android.mms");
+ mmsShareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(vcsInviteFile));
+ mmsShareIntent.setType("text/x-vcalendar");
+ chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
+ new Intent[]{mmsShareIntent});
+ }
+ startActivity(chooserIntent);
isShareSuccessful = true;
} else {
diff --git a/src/com/android/calendar/icalendar/IcalendarUtils.java b/src/com/android/calendar/icalendar/IcalendarUtils.java
index ef96674b..e179926b 100644
--- a/src/com/android/calendar/icalendar/IcalendarUtils.java
+++ b/src/com/android/calendar/icalendar/IcalendarUtils.java
@@ -9,9 +9,12 @@ import android.util.Log;
import com.android.calendar.CalendarEventModel;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
@@ -180,4 +183,53 @@ public class IcalendarUtils {
// remove the local time zone's UTC offset
return millis - TimeZone.getTimeZone(localTimeZone).getRawOffset();
}
+
+ /**
+ * Copy the contents of a file into another
+ *
+ * @param src input / src file
+ * @param dst file to be copied into
+ */
+ public static boolean copyFile(File src, File dst) {
+ boolean isSuccessful = false;
+ InputStream in = null;
+ OutputStream out = null;
+ try {
+ in = new FileInputStream(src);
+ out = new FileOutputStream(dst);
+
+ byte[] buf = new byte[1024];
+
+ try {
+ for (int len; (len = in.read(buf)) > 0; ) {
+ out.write(buf, 0, len);
+ }
+ isSuccessful = true;
+ } catch (IOException e) {
+ // ignore
+ }
+
+ } catch (FileNotFoundException fnf) {
+ // ignore
+ } finally {
+
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+
+ if (out != null) {
+ try {
+ out.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+
+ return isSuccessful;
+ }
}