summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Garnes <matt@cyngn.com>2014-12-08 17:47:07 -0800
committerRohit Yengisetty <rohit@cyngn.com>2014-12-12 17:48:04 -0800
commit6f6b8878deba974e20effd00b922203cc9dda818 (patch)
tree40b1fe140cbc39f3b4ded90520ccc47ff0573eb9
parent7b8ac44fb9f5dfebb444e8ddf29c7d227ac0588c (diff)
downloadandroid_packages_apps_Calendar-6f6b8878deba974e20effd00b922203cc9dda818.tar.gz
android_packages_apps_Calendar-6f6b8878deba974e20effd00b922203cc9dda818.tar.bz2
android_packages_apps_Calendar-6f6b8878deba974e20effd00b922203cc9dda818.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
-rw-r--r--res/values/cm_strings.xml3
-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
4 files changed, 84 insertions, 9 deletions
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml
index ba9bb628..5652b3ef 100644
--- a/res/values/cm_strings.xml
+++ b/res/values/cm_strings.xml
@@ -47,4 +47,7 @@
<!-- This is a label on a menu item. Pressing this menu item allows the
user to go to the calendars to display [CHAR LIMIT=20] -->
<string name="go_to">"Go to"</string>
+
+ <!-- Sharing calendar event -->
+ <string name="cal_share_intent_title">Send event to:</string>
</resources>
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;
+ }
}