]>
Commit | Line | Data |
---|---|---|
bdd8f09c | 1 | package ro.ieval.unical; |
7be52756 | 2 | |
39f0cac1 MG |
3 | import android.content.ContentResolver; |
4 | import android.content.Context; | |
7be52756 | 5 | import android.database.Cursor; |
4b8bd2f8 | 6 | import android.net.Uri; |
39f0cac1 MG |
7 | import android.os.Parcel; |
8 | import android.os.Parcelable; | |
9 | import android.provider.CalendarContract.Events; | |
7be52756 | 10 | |
39f0cac1 MG |
11 | final class Event implements Parcelable{ |
12 | public static final Parcelable.Creator<Event> CREATOR = new Parcelable.Creator<Event>() { | |
13 | @Override | |
14 | public Event createFromParcel(Parcel source) { | |
b7fd90e9 | 15 | return new Event(source.readLong(), source.readString(), source.readString(), source.readString(), source.readString(), source.readInt(), source.readLong(), source.readLong(), source.readLong()); |
39f0cac1 MG |
16 | } |
17 | ||
18 | @Override | |
19 | public Event[] newArray(int size) { | |
20 | return new Event[size]; | |
21 | } | |
22 | }; | |
23 | ||
24 | private static final String[] PROJECTION = { | |
25 | Events._ID, | |
26 | Events.ORGANIZER, | |
27 | Events.TITLE, | |
28 | Events.EVENT_LOCATION, | |
29 | Events.DESCRIPTION, | |
30 | Events.EVENT_COLOR, | |
31 | Events.DTSTART, | |
32 | Events.DTEND, | |
b7fd90e9 | 33 | Events.CALENDAR_ID, |
39f0cac1 MG |
34 | }; |
35 | ||
36 | /** Event ID */ | |
d022ee49 | 37 | public final long _id; |
39f0cac1 MG |
38 | /** Event owner */ |
39 | public final String organizer; | |
40 | /** Event title */ | |
41 | public final String title; | |
42 | /** Event location */ | |
43 | public final String eventLocation; | |
44 | /** Event description */ | |
45 | public final String description; | |
46 | /** Event colour */ | |
47 | public final int eventColour; | |
48 | /** Event start time (UTC milliseconds since epoch) */ | |
49 | public final long dtstart; | |
50 | /** Event end time (UTC milliseconds since epoch) */ | |
51 | public final long dtend; | |
b7fd90e9 MG |
52 | /** Calendar ID */ |
53 | public final long calendarID; | |
39f0cac1 | 54 | |
b7fd90e9 | 55 | private Event(final long _id, final String organizer, final String title, final String eventLocation, final String description, final int eventColor, final long dtstart, final long dtend, final long calendarID) { |
39f0cac1 MG |
56 | this._id=_id; |
57 | this.organizer=organizer; | |
58 | this.title=title; | |
59 | this.eventLocation=eventLocation; | |
60 | this.description=description; | |
61 | this.eventColour=eventColor; | |
62 | this.dtstart=dtstart; | |
63 | this.dtend=dtend; | |
b7fd90e9 | 64 | this.calendarID=calendarID; |
39f0cac1 MG |
65 | } |
66 | ||
67 | public static Event[] getEventsByCalendar(final Context context, final int calendarID){ | |
68 | final ContentResolver cr=context.getContentResolver(); | |
69 | final Cursor cursor = cr.query(Events.CONTENT_URI, | |
70 | PROJECTION, | |
71 | Events.CALENDAR_ID+" = ?", | |
72 | new String[]{Integer.toString(calendarID)}, | |
73 | null); | |
74 | cursor.moveToFirst(); | |
75 | final Event[] events = new Event[cursor.getCount()]; | |
76 | for(int i=0;i<events.length;i++) | |
d003a6ce | 77 | events[i]=new Event(cursor.getLong(0), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4), cursor.getInt(5), cursor.getLong(6), cursor.getLong(7), cursor.getLong(8)); |
39f0cac1 MG |
78 | return events; |
79 | } | |
80 | ||
4b8bd2f8 MG |
81 | public void delete(final Context context){ |
82 | final ContentResolver cr=context.getContentResolver(); | |
83 | cr.delete(Uri.withAppendedPath(Events.CONTENT_URI, Long.toString(_id)), null, null); | |
84 | } | |
85 | ||
39f0cac1 MG |
86 | @Override |
87 | public int describeContents() { | |
88 | return 0; | |
89 | } | |
90 | ||
91 | @Override | |
92 | public void writeToParcel(Parcel dest, int flags) { | |
d022ee49 | 93 | dest.writeLong(_id); |
39f0cac1 MG |
94 | dest.writeString(organizer); |
95 | dest.writeString(title); | |
96 | dest.writeString(eventLocation); | |
97 | dest.writeString(description); | |
98 | dest.writeInt(eventColour); | |
99 | dest.writeLong(dtstart); | |
100 | dest.writeLong(dtend); | |
b7fd90e9 | 101 | dest.writeLong(calendarID); |
bdd8f09c PT |
102 | } |
103 | } |