From b1e18479da492723f143a6bcee61fb89137f318b Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Wed, 29 May 2013 00:07:41 +0300 Subject: [PATCH] Add Calendar class --- src/ro/ieval/unical/Calendar.java | 49 +++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/ro/ieval/unical/Calendar.java diff --git a/src/ro/ieval/unical/Calendar.java b/src/ro/ieval/unical/Calendar.java new file mode 100644 index 0000000..2827641 --- /dev/null +++ b/src/ro/ieval/unical/Calendar.java @@ -0,0 +1,49 @@ +package ro.ieval.unical; + +import android.content.ContentResolver; +import android.content.Context; +import android.database.Cursor; +import android.provider.CalendarContract.Calendars; + +final class Calendar { + private static final String[] PROJECTION = { + Calendars._ID, + Calendars.NAME, + Calendars.CALENDAR_DISPLAY_NAME, + Calendars.VISIBLE, + Calendars.ACCOUNT_NAME, + Calendars.ACCOUNT_TYPE, + }; + + /** Calendar ID */ + public final int _id; + /** Calendar name */ + public final String name; + /** Calendar display name */ + public final String displayName; + /** Calendar visibility (false - do not show events associated with this calendar, true - show events associated with this calendar) */ + public final boolean visible; + /** Name of the account used to sync this calendar */ + public final String accountName; + /** Type of the calendar used to sync this calendar */ + public final String accountType; + + private Calendar(final int _id, final String name, final String displayName, final boolean visible, final String accountName, final String accountType) { + this._id=_id; + this.name=name; + this.displayName=displayName; + this.visible=visible; + this.accountName=accountName; + this.accountType=accountType; + } + + public static Calendar[] getAllCalendars(final Context context){ + final ContentResolver cr=context.getContentResolver(); + final Cursor cursor = cr.query(Calendars.CONTENT_URI, PROJECTION, null, null, null); + cursor.moveToFirst(); + final Calendar[] calendars = new Calendar[cursor.getCount()]; + for(int i=0;i