| 1 | package ro.ieval.unical; |
| 2 | |
| 3 | import android.content.ContentResolver; |
| 4 | import android.content.Context; |
| 5 | import android.database.Cursor; |
| 6 | import android.provider.BaseColumns; |
| 7 | import android.provider.CalendarContract.Calendars; |
| 8 | |
| 9 | final class Calendar { |
| 10 | private static final String[] PROJECTION = { |
| 11 | BaseColumns._ID, |
| 12 | Calendars.NAME, |
| 13 | Calendars.CALENDAR_DISPLAY_NAME, |
| 14 | Calendars.VISIBLE, |
| 15 | Calendars.ACCOUNT_NAME, |
| 16 | Calendars.ACCOUNT_TYPE, |
| 17 | Calendars.CALENDAR_COLOR, |
| 18 | }; |
| 19 | |
| 20 | /** Calendar ID */ |
| 21 | public final long _id; |
| 22 | /** Calendar name */ |
| 23 | public final String name; |
| 24 | /** Calendar display name */ |
| 25 | public final String displayName; |
| 26 | /** Calendar visibility (false - do not show events associated with this calendar, true - show events associated with this calendar) */ |
| 27 | public final boolean visible; |
| 28 | /** Name of the account used to sync this calendar */ |
| 29 | public final String accountName; |
| 30 | /** Type of the calendar used to sync this calendar */ |
| 31 | public final String accountType; |
| 32 | /** Calendar colour */ |
| 33 | public final int colour; |
| 34 | |
| 35 | private Calendar(final long _id, final String name, final String displayName, final boolean visible, final String accountName, final String accountType, final int colour) { |
| 36 | this._id=_id; |
| 37 | this.name=name; |
| 38 | this.displayName=displayName; |
| 39 | this.visible=visible; |
| 40 | this.accountName=accountName; |
| 41 | this.accountType=accountType; |
| 42 | this.colour=colour; |
| 43 | } |
| 44 | |
| 45 | public static Calendar[] getAllCalendars(final Context context){ |
| 46 | final ContentResolver cr=context.getContentResolver(); |
| 47 | final Cursor cursor = cr.query(Calendars.CONTENT_URI, PROJECTION, null, null, null); |
| 48 | cursor.moveToFirst(); |
| 49 | final Calendar[] calendars = new Calendar[cursor.getCount()]; |
| 50 | for(int i=0;i<calendars.length;i++){ |
| 51 | calendars[i]=new Calendar(cursor.getLong(0), cursor.getString(1), cursor.getString(2), cursor.getInt(3)!=0, cursor.getString(4), cursor.getString(5), cursor.getInt(6)); |
| 52 | cursor.moveToNext(); |
| 53 | } |
| 54 | cursor.close(); |
| 55 | return calendars; |
| 56 | } |
| 57 | } |