Methods Summary |
---|
private static java.lang.String | convertLongToRFC2445DateTime(long mills)
Time time = new Time();
time.set(mills);
return time.format("%Y%m%dT%H%M%SZ");
|
public java.lang.String[] | getCalendars()
if (mCalendars == null) {
Cursor cursor = SqliteWrapper.query(mContext, mResolver, Calendars.CONTENT_URI,
new String[] {Calendars._ID, Calendars.DISPLAY_NAME},
null, null, null);
if (null == cursor) {
return null;
}
mCalendars = new HashMap<String, Long>();
try {
while (cursor.moveToNext()) {
long id = cursor.getLong(cursor.getColumnIndexOrThrow(Calendars._ID));
String name = cursor.getString(cursor.getColumnIndexOrThrow(Calendars.DISPLAY_NAME));
mCalendars.put(name, id);
}
} finally {
cursor.close();
}
}
Set<String> keySet = mCalendars.keySet();
int size = keySet.size();
if (size <= 0) {
return null;
}
String[] calendarArray = new String[size];
keySet.toArray(calendarArray);
return calendarArray;
|
public java.lang.String | getCompleted()Get the completed time of the calendar event.
Long complete = (Long) mVCalValues.get(Calendar.Events.LAST_DATE);
if (complete == null) {
return null;
}
Time time = new Time();
time.set(complete);
return time.format(TIME_FORMAT_STRING);
|
public java.lang.String | getData()Load the formatted data of the stored calendar event.
if (mUri == null) {
Log.e(TAG, "Bad content URI.");
return null;
}
Cursor c = SqliteWrapper.query(mContext, mResolver, mUri,
null, null, null, null);
String uid = mUri.toString();
if (c == null) {
Log.e(TAG, "Cannot query the content from " + mUri);
return null;
}
try {
c.moveToFirst();
CalendarStruct calStruct = new CalendarStruct();
calStruct.timezone = c.getString(c.getColumnIndexOrThrow(Calendar.Events.EVENT_TIMEZONE));
//event list:
CalendarStruct.EventStruct evtStruct = new CalendarStruct.EventStruct();
evtStruct.uid = uid;
evtStruct.description = c.getString(c.getColumnIndexOrThrow(
Calendar.Events.DESCRIPTION));
evtStruct.dtend = convertLongToRFC2445DateTime(c.getLong(c.getColumnIndexOrThrow(
Calendar.Events.DTEND)));
evtStruct.dtstart = convertLongToRFC2445DateTime(c.getLong(c.getColumnIndexOrThrow(
Calendar.Events.DTSTART)));
evtStruct.duration = c.getString(c.getColumnIndexOrThrow(
Calendar.Events.DURATION));
evtStruct.event_location = c.getString(c.getColumnIndexOrThrow(
Calendar.Events.EVENT_LOCATION));
evtStruct.has_alarm = c.getString(c.getColumnIndexOrThrow(
Calendar.Events.HAS_ALARM));
evtStruct.last_date = convertLongToRFC2445DateTime(c.getLong(c.getColumnIndexOrThrow(
Calendar.Events.LAST_DATE)));
evtStruct.rrule = c.getString(c.getColumnIndexOrThrow(
Calendar.Events.RRULE));
evtStruct.status = c.getString(c.getColumnIndexOrThrow(
Calendar.Events.STATUS));
evtStruct.title = c.getString(c.getColumnIndexOrThrow(
Calendar.Events.TITLE));
if (!isNull(evtStruct.has_alarm)) {
getReminders(evtStruct, Uri.parse(uid).getLastPathSegment());
}
calStruct.addEventList(evtStruct);
try{ //build vcalendar:
VCalComposer composer = new VCalComposer();
return composer.createVCal(calStruct, VCalComposer.VERSION_VCAL10_INT);
} catch (Exception e) {
return null;
}
} finally {
c.close();
}
|
public java.lang.String | getDateTimeEnd()Get the end time of the calendar event.
Long end = (Long) mVCalValues.get(Calendar.Events.DTEND);
if (end == null) {
return null;
}
Time time = new Time();
time.set(end);
return time.format(TIME_FORMAT_STRING);
|
public java.lang.String | getDateTimeStart()Get the start time of the calendar event.
Long start = (Long) mVCalValues.get(Calendar.Events.DTSTART);
if (start == null) {
return null;
}
Time time = new Time();
time.set(start);
return time.format(TIME_FORMAT_STRING);
|
public java.lang.String | getDescription()Get the description of the calendar event.
return (String) mVCalValues.get(Calendar.Events.DESCRIPTION);
|
public java.lang.String | getDuration()Get the duration of the calendar event.
return (String) mVCalValues.get(Calendar.Events.DURATION);
|
public java.lang.String | getEventLocation()Get the event location of the calendar event.
return (String) mVCalValues.get(Calendar.Events.EVENT_LOCATION);
|
private int | getFirstIDFromCalendar()
Cursor c = SqliteWrapper.query(mContext, mResolver, Calendar.Calendars.CONTENT_URI,
null, null, null, null);
if (c != null) {
while (c.moveToNext()) {
int id = c.getInt(c.getColumnIndexOrThrow("_id"));
c.close();
return id;
}
c.close();
}
return -1;
|
public java.lang.String | getName()Get the name of the calendar event with ".vcs" suffix.
if (mUri == null) {
Log.e(TAG, "Bad content URI.");
return null;
}
Cursor c = SqliteWrapper.query(mContext, mResolver, mUri,
null, null, null, null);
if (c == null) {
Log.e(TAG, "Cannot query the content from " + mUri);
return null;
}
try {
c.moveToFirst();
return c.getString(c.getColumnIndexOrThrow(Calendar.Events.TITLE)) + ".vcs";
} finally {
c.close();
}
|
private void | getReminders(CalendarStruct.EventStruct evtStruct, java.lang.String localid)
Cursor c = SqliteWrapper.query(mContext, mResolver, Calendar.Reminders.CONTENT_URI,
null, "event_id=" + localid, null, null);
String data = "";
while ((c != null) && c.moveToNext()) {
data = c.getString(c.getColumnIndexOrThrow(Calendar.Reminders.METHOD));
evtStruct.addReminderList(data);
}
if (c != null) {
c.close();
}
|
public java.lang.String | getRepeatRule()Get the rule of the calendar event.
return (String) mVCalValues.get(Calendar.Events.RRULE);
|
public java.lang.String | getTitle()Get the title of the calendar event.
return (String) mVCalValues.get(Calendar.Events.TITLE);
|
private static boolean | isNull(java.lang.String str)
if ((str == null) || str.trim().equals("")) {
return true;
}
return false;
|
private android.content.ContentValues | parseVCalendar(java.lang.String data)
VCalParser parser = new VCalParser();
VDataBuilder builder = new VDataBuilder();
if (null == data) {
return null;
}
try {
parser.parse(data, builder);
} catch (VCalException e) {
Log.e(TAG, "VCalException: ", e);
return null;
}
String curCalendarId = "";
for (VNode vnode : builder.vNodeList) {
// VCALENDAR field MUST present before VENENT and VTODO
if (vnode.VName.equalsIgnoreCase("VCALENDAR")) {
// If no Calendar, just set -1 as CalendarId, because user
// should view the content even if no calendar created.
curCalendarId = String.valueOf(getFirstIDFromCalendar());
} else if (vnode.VName.equalsIgnoreCase("VEVENT") ||
vnode.VName.equalsIgnoreCase("VTODO")) {
return setEventMap(vnode, curCalendarId);
}
}
return null;
|
public android.net.Uri | save(java.lang.String calendarName)Save the calendar data to local database.
Long id = mCalendars.get(calendarName);
if (null == id) {
return null;
}
mVCalValues.put(Calendar.Events.CALENDAR_ID, id);
return SqliteWrapper.insert(mContext, mResolver,
Calendar.Events.CONTENT_URI, mVCalValues);
|
private static android.content.ContentValues | setEventMap(android.syncml.pim.VNode vnode, java.lang.String calId)
ContentValues values = new ContentValues();
values.put(Calendar.Events.CALENDAR_ID, calId);
for (PropertyNode prop : vnode.propList) {
if (prop.propValue != null) {
Time time = new Time();
if (prop.propName.equalsIgnoreCase("DESCRIPTION")) {
values.put(Calendar.Events.DESCRIPTION, prop.propValue);
} else if (prop.propName.equalsIgnoreCase("DTEND")) {
time.parse(prop.propValue);
values.put(Calendar.Events.DTEND, time.toMillis(false /* use isDst */));
} else if (prop.propName.equalsIgnoreCase("DTSTART")) {
time.parse(prop.propValue);
values.put(Calendar.Events.DTSTART, time.toMillis(false /* use isDst */));
} else if (prop.propName.equalsIgnoreCase("SUMMARY")) {
values.put(Calendar.Events.TITLE, prop.propValue);
} else if (prop.propName.equalsIgnoreCase("LOCATION")) {
values.put(Calendar.Events.EVENT_LOCATION, prop.propValue);
} else if (prop.propName.equalsIgnoreCase("DUE")) {
values.put(Calendar.Events.DURATION, prop.propValue);
} else if (prop.propName.equalsIgnoreCase("RRULE")) {
values.put(Calendar.Events.RRULE, prop.propValue);
} else if (prop.propName.equalsIgnoreCase("COMPLETED")) {
time.parse(prop.propValue);
values.put(Calendar.Events.LAST_DATE, time.toMillis(false /* use isDst */));
}
}
}
return values;
|