summaryrefslogtreecommitdiffstats
path: root/src/com/android/calendar/EventInfoFragment.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/calendar/EventInfoFragment.java')
-rw-r--r--src/com/android/calendar/EventInfoFragment.java99
1 files changed, 68 insertions, 31 deletions
diff --git a/src/com/android/calendar/EventInfoFragment.java b/src/com/android/calendar/EventInfoFragment.java
index 90f73b02..4374226e 100644
--- a/src/com/android/calendar/EventInfoFragment.java
+++ b/src/com/android/calendar/EventInfoFragment.java
@@ -48,6 +48,7 @@ import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
+import android.os.Environment;
import android.provider.CalendarContract;
import android.provider.CalendarContract.Attendees;
import android.provider.CalendarContract.Calendars;
@@ -185,6 +186,14 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
| TOKEN_QUERY_ATTENDEES | TOKEN_QUERY_CALENDARS | TOKEN_QUERY_EVENT
| TOKEN_QUERY_REMINDERS | TOKEN_QUERY_VISIBLE_CALENDARS | TOKEN_QUERY_COLORS;
+ public static final File EXPORT_SDCARD_DIRECTORY = new File(
+ Environment.getExternalStorageDirectory(), "CalendarEvents");
+
+ private enum ShareType {
+ SDCARD,
+ INTENT
+ }
+
private int mCurrentQuery = 0;
private static final String[] EVENT_PROJECTION = new String[] {
@@ -1258,7 +1267,9 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
} else if (itemId == R.id.info_action_change_color) {
showEventColorPickerDialog();
} else if (itemId == R.id.info_action_share_event) {
- shareEvent();
+ shareEvent(ShareType.INTENT);
+ } else if (itemId == R.id.info_action_export) {
+ shareEvent(ShareType.SDCARD);
}
return super.onOptionsItemSelected(item);
}
@@ -1267,7 +1278,7 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
* Generates an .ics formatted file with the event info and launches intent chooser to
* share said file
*/
- private void shareEvent() {
+ private void shareEvent(ShareType type) {
// Create the respective ICalendar objects from the event info
VCalendar calendar = new VCalendar();
calendar.addProperty(VCalendar.VERSION, "2.0");
@@ -1330,37 +1341,62 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
// prefix length constraint is imposed by File#createTempFile
filePrefix = "invite";
}
- File inviteFile = File.createTempFile(filePrefix, ".ics",
- mActivity.getExternalCacheDir());
+
+ filePrefix = filePrefix.replaceAll("\\W+", " ");
+
+ if (!filePrefix.endsWith(" ")) {
+ filePrefix += " ";
+ }
+
+ File dir;
+ if (type == ShareType.SDCARD) {
+ dir = EXPORT_SDCARD_DIRECTORY;
+ if (!dir.exists()) {
+ dir.mkdir();
+ }
+ } else {
+ dir = mActivity.getExternalCacheDir();
+ }
+
+ File inviteFile = IcalendarUtils.createTempFile(filePrefix, ".ics",
+ dir);
+
if (IcalendarUtils.writeCalendarToFile(calendar, inviteFile)) {
- inviteFile.setReadable(true,false); // set world-readable
- Intent shareIntent = new Intent();
- shareIntent.setAction(Intent.ACTION_SEND);
- shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(inviteFile));
- // 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");
-
- 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});
+ if (type == ShareType.INTENT) {
+ inviteFile.setReadable(true, false); // set world-readable
+ Intent shareIntent = new Intent();
+ shareIntent.setAction(Intent.ACTION_SEND);
+ shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(inviteFile));
+ // 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");
+
+ 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);
+ } else {
+ String msg = getString(R.string.cal_export_succ_msg);
+ Toast.makeText(mActivity, String.format(msg, inviteFile),
+ Toast.LENGTH_SHORT).show();
}
- startActivity(chooserIntent);
isShareSuccessful = true;
} else {
@@ -1368,6 +1404,7 @@ public class EventInfoFragment extends DialogFragment implements OnCheckedChange
isShareSuccessful = false;
}
} catch (IOException e) {
+ e.printStackTrace();
isShareSuccessful = false;
}