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