]> iEval git - unical.git/blame - src/ro/ieval/unical/Event.java
Clean up
[unical.git] / src / ro / ieval / unical / Event.java
CommitLineData
bdd8f09c 1package ro.ieval.unical;
7be52756 2
92086ce7
PT
3import java.util.ArrayList;
4
39f0cac1
MG
5import android.content.ContentResolver;
6import android.content.Context;
7be52756 7import android.database.Cursor;
4b8bd2f8 8import android.net.Uri;
39f0cac1
MG
9import android.os.Parcel;
10import android.os.Parcelable;
8a817995 11import android.provider.BaseColumns;
39f0cac1 12import android.provider.CalendarContract.Events;
7be52756 13
39f0cac1
MG
14final class Event implements Parcelable{
15 public static final Parcelable.Creator<Event> CREATOR = new Parcelable.Creator<Event>() {
16 @Override
5cf4714f 17 public Event createFromParcel(final Parcel source) {
b7fd90e9 18 return new Event(source.readLong(), source.readString(), source.readString(), source.readString(), source.readString(), source.readInt(), source.readLong(), source.readLong(), source.readLong());
39f0cac1
MG
19 }
20
21 @Override
5cf4714f 22 public Event[] newArray(final int size) {
39f0cac1
MG
23 return new Event[size];
24 }
25 };
26
27 private static final String[] PROJECTION = {
8a817995 28 BaseColumns._ID,
39f0cac1
MG
29 Events.ORGANIZER,
30 Events.TITLE,
31 Events.EVENT_LOCATION,
32 Events.DESCRIPTION,
33 Events.EVENT_COLOR,
34 Events.DTSTART,
35 Events.DTEND,
b7fd90e9 36 Events.CALENDAR_ID,
39f0cac1
MG
37 };
38
39 /** Event ID */
d022ee49 40 public final long _id;
39f0cac1
MG
41 /** Event owner */
42 public final String organizer;
43 /** Event title */
44 public final String title;
45 /** Event location */
46 public final String eventLocation;
47 /** Event description */
48 public final String description;
49 /** Event colour */
50 public final int eventColour;
070d3ab2 51 /** Event start time (UTC milliseconds since epoch) */
39f0cac1
MG
52 public final long dtstart;
53 /** Event end time (UTC milliseconds since epoch) */
54 public final long dtend;
b7fd90e9
MG
55 /** Calendar ID */
56 public final long calendarID;
39f0cac1 57
b7fd90e9 58 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
59 this._id=_id;
60 this.organizer=organizer;
61 this.title=title;
62 this.eventLocation=eventLocation;
63 this.description=description;
64 this.eventColour=eventColor;
65 this.dtstart=dtstart;
66 this.dtend=dtend;
b7fd90e9 67 this.calendarID=calendarID;
39f0cac1
MG
68 }
69
810f5287 70 public static Event[] getEventsByCalendar(final Context context, final Calendar calendar, final String sort){
39f0cac1
MG
71 final ContentResolver cr=context.getContentResolver();
72 final Cursor cursor = cr.query(Events.CONTENT_URI,
73 PROJECTION,
74 Events.CALENDAR_ID+" = ?",
810f5287 75 new String[]{Long.toString(calendar._id)},
fc891ea8 76 sort);
39f0cac1
MG
77 cursor.moveToFirst();
78 final Event[] events = new Event[cursor.getCount()];
16e2550c 79 for(int i=0;i<events.length;i++){
810f5287
MG
80 int colour=cursor.getInt(5);
81 colour=colour == 0 ? calendar.colour : colour;
82 events[i]=new Event(cursor.getLong(0), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4), colour, cursor.getLong(6), cursor.getLong(7), cursor.getLong(8));
16e2550c
MG
83 cursor.moveToNext();
84 }
8a817995 85 cursor.close();
39f0cac1
MG
86 return events;
87 }
070d3ab2 88
92086ce7 89 public static Event[] getAllEvents(final Context context) {
c1da3e5d 90 final ArrayList<Event> r = new ArrayList<Event>();
bc3c4273 91 for(final Calendar calendar : Calendar.getAllCalendars(context))
810f5287 92 for(final Event event : getEventsByCalendar(context, calendar, null))
c1da3e5d 93 r.add(event);
92086ce7
PT
94 return r.toArray(new Event[r.size()]);
95 }
39f0cac1 96
4b8bd2f8
MG
97 public void delete(final Context context){
98 final ContentResolver cr=context.getContentResolver();
99 cr.delete(Uri.withAppendedPath(Events.CONTENT_URI, Long.toString(_id)), null, null);
100 }
070d3ab2 101
39f0cac1
MG
102 @Override
103 public int describeContents() {
104 return 0;
105 }
106
107 @Override
5cf4714f 108 public void writeToParcel(final Parcel dest, final int flags) {
d022ee49 109 dest.writeLong(_id);
39f0cac1
MG
110 dest.writeString(organizer);
111 dest.writeString(title);
112 dest.writeString(eventLocation);
113 dest.writeString(description);
114 dest.writeInt(eventColour);
115 dest.writeLong(dtstart);
116 dest.writeLong(dtend);
b7fd90e9 117 dest.writeLong(calendarID);
bdd8f09c
PT
118 }
119}
This page took 0.057541 seconds and 4 git commands to generate.