]> iEval git - unical.git/blame - src/ro/ieval/unical/Event.java
Edit event. work in progress[3]
[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 */
5835912b 40 public long _id;
39f0cac1 41 /** Event owner */
5835912b 42 public String organizer;
39f0cac1 43 /** Event title */
5835912b 44 public String title;
39f0cac1 45 /** Event location */
5835912b 46 public String eventLocation;
39f0cac1 47 /** Event description */
5835912b 48 public String description;
39f0cac1 49 /** Event colour */
5835912b 50 public int eventColour;
070d3ab2 51 /** Event start time (UTC milliseconds since epoch) */
5835912b 52 public long dtstart;
39f0cac1 53 /** Event end time (UTC milliseconds since epoch) */
5835912b 54 public long dtend;
b7fd90e9 55 /** Calendar ID */
5835912b 56 public long calendarID;
39f0cac1 57
c32befcc
P
58 public Event() {}
59
412b2d69 60 public 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
61 this._id=_id;
62 this.organizer=organizer;
63 this.title=title;
64 this.eventLocation=eventLocation;
65 this.description=description;
66 this.eventColour=eventColor;
67 this.dtstart=dtstart;
68 this.dtend=dtend;
b7fd90e9 69 this.calendarID=calendarID;
39f0cac1
MG
70 }
71
810f5287 72 public static Event[] getEventsByCalendar(final Context context, final Calendar calendar, final String sort){
39f0cac1
MG
73 final ContentResolver cr=context.getContentResolver();
74 final Cursor cursor = cr.query(Events.CONTENT_URI,
75 PROJECTION,
76 Events.CALENDAR_ID+" = ?",
810f5287 77 new String[]{Long.toString(calendar._id)},
fc891ea8 78 sort);
39f0cac1
MG
79 cursor.moveToFirst();
80 final Event[] events = new Event[cursor.getCount()];
16e2550c 81 for(int i=0;i<events.length;i++){
810f5287
MG
82 int colour=cursor.getInt(5);
83 colour=colour == 0 ? calendar.colour : colour;
84 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
85 cursor.moveToNext();
86 }
8a817995 87 cursor.close();
39f0cac1
MG
88 return events;
89 }
070d3ab2 90
92086ce7 91 public static Event[] getAllEvents(final Context context) {
c1da3e5d 92 final ArrayList<Event> r = new ArrayList<Event>();
bc3c4273 93 for(final Calendar calendar : Calendar.getAllCalendars(context))
810f5287 94 for(final Event event : getEventsByCalendar(context, calendar, null))
c1da3e5d 95 r.add(event);
92086ce7
PT
96 return r.toArray(new Event[r.size()]);
97 }
39f0cac1 98
ad349897
P
99 public void insert(final Context context) {
100 final ContentResolver cr=context.getContentResolver();
101 //cr.insert(Uri.withAppendedPath(Events.CONTENT_URI));
102 //cr.notifyChange();
103 }
104
4b8bd2f8
MG
105 public void delete(final Context context){
106 final ContentResolver cr=context.getContentResolver();
107 cr.delete(Uri.withAppendedPath(Events.CONTENT_URI, Long.toString(_id)), null, null);
108 }
070d3ab2 109
39f0cac1
MG
110 @Override
111 public int describeContents() {
112 return 0;
113 }
114
115 @Override
5cf4714f 116 public void writeToParcel(final Parcel dest, final int flags) {
d022ee49 117 dest.writeLong(_id);
39f0cac1
MG
118 dest.writeString(organizer);
119 dest.writeString(title);
120 dest.writeString(eventLocation);
121 dest.writeString(description);
122 dest.writeInt(eventColour);
123 dest.writeLong(dtstart);
124 dest.writeLong(dtend);
b7fd90e9 125 dest.writeLong(calendarID);
bdd8f09c
PT
126 }
127}
This page took 0.051301 seconds and 4 git commands to generate.