]>
Commit | Line | Data |
---|---|---|
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 GCalendar { | |
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 | }; | |
18 | ||
19 | /** Calendar ID */ | |
20 | public final long _id; | |
21 | /** Calendar name */ | |
22 | public final String name; | |
23 | /** Calendar display name */ | |
24 | public final String displayName; | |
25 | /** Calendar visibility (false - do not show events associated with this calendar, true - show events associated with this calendar) */ | |
26 | public final boolean visible; | |
27 | /** Name of the account used to sync this calendar */ | |
28 | public final String accountName; | |
29 | /** Type of the calendar used to sync this calendar */ | |
30 | public final String accountType; | |
31 | ||
32 | private GCalendar(final long _id, final String name, final String displayName, final boolean visible, final String accountName, final String accountType) { | |
33 | this._id=_id; | |
34 | this.name=name; | |
35 | this.displayName=displayName; | |
36 | this.visible=visible; | |
37 | this.accountName=accountName; | |
38 | this.accountType=accountType; | |
39 | } | |
40 | ||
41 | public static GCalendar[] getAllCalendars(final Context context){ | |
42 | final ContentResolver cr=context.getContentResolver(); | |
43 | final Cursor cursor = cr.query(Calendars.CONTENT_URI, PROJECTION, null, null, null); | |
44 | cursor.moveToFirst(); | |
45 | final GCalendar[] calendars = new GCalendar[cursor.getCount()]; | |
46 | for(int i=0;i<calendars.length;i++){ | |
47 | calendars[i]=new GCalendar(cursor.getLong(0), cursor.getString(1), cursor.getString(2), cursor.getInt(3)!=0, cursor.getString(4), cursor.getString(5)); | |
48 | cursor.moveToNext(); | |
49 | } | |
50 | cursor.close(); | |
51 | return calendars; | |
52 | } | |
53 | } |