summaryrefslogtreecommitdiffstats
path: root/src/com/android/calendar/icalendar/VCalendar.java
diff options
context:
space:
mode:
authorRohit Yengisetty <rohit@cyngn.com>2014-11-20 14:09:53 -0800
committerSteve Kondik <steve@cyngn.com>2015-10-18 13:52:41 -0700
commit990c61ad0a076a13598660b7fa477e6c30f7b783 (patch)
tree3c070a202f24337908eaa4f190e1b9f0bedb218d /src/com/android/calendar/icalendar/VCalendar.java
parent515ade24eaaff7e898392dc7a2784e64f0193723 (diff)
downloadandroid_packages_apps_Calendar-990c61ad0a076a13598660b7fa477e6c30f7b783.tar.gz
android_packages_apps_Calendar-990c61ad0a076a13598660b7fa477e6c30f7b783.tar.bz2
android_packages_apps_Calendar-990c61ad0a076a13598660b7fa477e6c30f7b783.zip
Calendar - Add the ability to share calendar events through an ics file.
iCal specification rescources: http://build.mnode.org/projects/ical4j/apidocs/index.html http://www.kanzaki.com/docs/ical/ iCal validators: http://icalvalid.cloudapp.net http://severinghaus.org/projects/icv/ Change-Id: I87b12fd37aa7e3ad29bea79d4dbb152f868ff4f8
Diffstat (limited to 'src/com/android/calendar/icalendar/VCalendar.java')
-rw-r--r--src/com/android/calendar/icalendar/VCalendar.java113
1 files changed, 113 insertions, 0 deletions
diff --git a/src/com/android/calendar/icalendar/VCalendar.java b/src/com/android/calendar/icalendar/VCalendar.java
new file mode 100644
index 00000000..00c7b81b
--- /dev/null
+++ b/src/com/android/calendar/icalendar/VCalendar.java
@@ -0,0 +1,113 @@
+/**
+ * Copyright (C) 2014 The CyanogenMod Project
+ */
+
+package com.android.calendar.icalendar;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+
+/**
+ * Models the Calendar/VCalendar component of the iCalendar format
+ */
+public class VCalendar {
+
+ // valid property identifiers of the component
+ // TODO: only a partial list of attributes have been implemented, implement the rest
+ public static String VERSION = "VERSION";
+ public static String PRODID = "PRODID";
+ public static String CALSCALE = "CALSCALE";
+ public static String METHOD = "METHOD";
+
+ public final static String PRODUCT_IDENTIFIER = "-//Cyanogen Inc//com.android.calendar";
+
+ // stores the -arity of the attributes that this component can have
+ private final static HashMap<String, Integer> sPropertyList = new HashMap<String, Integer>();
+
+ // initialize approved list of iCal Calendar properties
+ static {
+ sPropertyList.put(VERSION, 1);
+ sPropertyList.put(PRODID, 1);
+ sPropertyList.put(CALSCALE, 1);
+ sPropertyList.put(METHOD, 1);
+ }
+
+ // stores attributes and their corresponding values belonging to the Calendar object
+ public HashMap<String, String> mProperties;
+ public LinkedList<VEvent> mEvents; // events that belong to this Calendar object
+
+ /**
+ * Constructor
+ */
+ public VCalendar() {
+ mProperties = new HashMap<String, String>();
+ mEvents = new LinkedList<VEvent>();
+ }
+
+ /**
+ * Add specified property
+ * @param property
+ * @param value
+ * @return
+ */
+ public boolean addProperty(String property, String value) {
+ // since all the required mProperties are unary (only one can exist) , taking a shortcut here
+ // when multiples of a property can exist , enforce that here .. cleverly
+ if (sPropertyList.containsKey(property) && value != null) {
+ mProperties.put(property, IcalendarUtils.cleanseString(value));
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Add Event to calendar
+ * @param event
+ */
+ public void addEvent(VEvent event) {
+ if (event != null) mEvents.add(event);
+ }
+
+ /**
+ *
+ * @return
+ */
+ public LinkedList<VEvent> getAllEvents() {
+ return mEvents;
+ }
+
+ /**
+ * Returns the iCal representation of the calendar and all of its inherent components
+ * @return
+ */
+ public String getICalFormattedString() {
+ StringBuilder output = new StringBuilder();
+
+ // Add Event properties
+ // TODO: add the ability to specify the order in which to compose the properties
+ output.append("BEGIN:VCALENDAR\n");
+ for (String property : mProperties.keySet() ) {
+ output.append(property + ":" + mProperties.get(property) + "\n");
+ }
+
+ // enforce line length requirements
+ output = IcalendarUtils.enforceICalLineLength(output);
+ // add event
+ for (VEvent event : mEvents) {
+ output.append(event.getICalFormattedString());
+ }
+
+ output.append("END:VCALENDAR\n");
+
+ return output.toString();
+ }
+
+ /**
+ * TODO: Aggressive validation of VCalendar and all of its components to ensure they conform
+ * to the ical specification
+ * @return
+ */
+ private boolean validate() {
+ return false;
+ }
+} \ No newline at end of file