]> iEval git - unical.git/blame - src/ro/ieval/unical/Event.java
Fix the three get functions
[unical.git] / src / ro / ieval / unical / Event.java
CommitLineData
bdd8f09c 1package ro.ieval.unical;
7be52756 2
39f0cac1
MG
3import android.content.ContentResolver;
4import android.content.Context;
7be52756 5import android.database.Cursor;
4b8bd2f8 6import android.net.Uri;
39f0cac1
MG
7import android.os.Parcel;
8import android.os.Parcelable;
9import android.provider.CalendarContract.Events;
7be52756 10
39f0cac1
MG
11final class Event implements Parcelable{
12 public static final Parcelable.Creator<Event> CREATOR = new Parcelable.Creator<Event>() {
13 @Override
5cf4714f 14 public Event createFromParcel(final 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
5cf4714f 19 public Event[] newArray(final int size) {
39f0cac1
MG
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
452aaab6 67 public static Event[] getEventsByCalendar(final Context context, final long calendarID, final String sort){
39f0cac1
MG
68 final ContentResolver cr=context.getContentResolver();
69 final Cursor cursor = cr.query(Events.CONTENT_URI,
70 PROJECTION,
71 Events.CALENDAR_ID+" = ?",
452aaab6 72 new String[]{Long.toString(calendarID)},
fc891ea8 73 sort);
39f0cac1
MG
74 cursor.moveToFirst();
75 final Event[] events = new Event[cursor.getCount()];
16e2550c 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));
16e2550c
MG
78 cursor.moveToNext();
79 }
39f0cac1
MG
80 return events;
81 }
82
4b8bd2f8
MG
83 public void delete(final Context context){
84 final ContentResolver cr=context.getContentResolver();
85 cr.delete(Uri.withAppendedPath(Events.CONTENT_URI, Long.toString(_id)), null, null);
86 }
87
39f0cac1
MG
88 @Override
89 public int describeContents() {
90 return 0;
91 }
92
93 @Override
5cf4714f 94 public void writeToParcel(final Parcel dest, final int flags) {
d022ee49 95 dest.writeLong(_id);
39f0cac1
MG
96 dest.writeString(organizer);
97 dest.writeString(title);
98 dest.writeString(eventLocation);
99 dest.writeString(description);
100 dest.writeInt(eventColour);
101 dest.writeLong(dtstart);
102 dest.writeLong(dtend);
b7fd90e9 103 dest.writeLong(calendarID);
bdd8f09c
PT
104 }
105}
This page took 0.031012 seconds and 4 git commands to generate.