From: Marius Gavrilescu Date: Tue, 28 May 2013 21:09:41 +0000 (+0300) Subject: Rewrite the Event class and make displayEventActivity work with it X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=39f0cac1576f119c2fe8c01f3527d21aa2564b46;p=unical.git Rewrite the Event class and make displayEventActivity work with it --- diff --git a/src/ro/ieval/unical/Event.java b/src/ro/ieval/unical/Event.java index 14f2c43..4c6abba 100644 --- a/src/ro/ieval/unical/Event.java +++ b/src/ro/ieval/unical/Event.java @@ -1,28 +1,93 @@ package ro.ieval.unical; +import android.content.ContentResolver; +import android.content.Context; import android.database.Cursor; +import android.os.Parcel; +import android.os.Parcelable; +import android.provider.CalendarContract.Events; -public class Event { - public String _id; - public int date,duration; - public boolean repeat; - public int repeatInterval; - public String location; - public String description; - public String tags[]; - public String title; - Event(Cursor cursor) { - _id=cursor.getString(0); - title=cursor.getString(1); - description=cursor.getString(2); - date=cursor.getInt(3); - duration=cursor.getInt(4); - if(cursor.getInt(5)==1) repeat=true; - else repeat=false; - repeatInterval=cursor.getInt(6); - location=cursor.getString(7); - } - Event () { +final class Event implements Parcelable{ + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + @Override + public Event createFromParcel(Parcel source) { + return new Event(source.readInt(), source.readString(), source.readString(), source.readString(), source.readString(), source.readInt(), source.readLong(), source.readLong()); + } + + @Override + public Event[] newArray(int size) { + return new Event[size]; + } + }; + + private static final String[] PROJECTION = { + Events._ID, + Events.ORGANIZER, + Events.TITLE, + Events.EVENT_LOCATION, + Events.DESCRIPTION, + Events.EVENT_COLOR, + Events.DTSTART, + Events.DTEND, + }; + + /** Event ID */ + public final int _id; + /** Event owner */ + public final String organizer; + /** Event title */ + public final String title; + /** Event location */ + public final String eventLocation; + /** Event description */ + public final String description; + /** Event colour */ + public final int eventColour; + /** Event start time (UTC milliseconds since epoch) */ + public final long dtstart; + /** Event end time (UTC milliseconds since epoch) */ + public final long dtend; + + private Event(final int _id, final String organizer, final String title, final String eventLocation, final String description, final int eventColor, final long dtstart, final long dtend) { + this._id=_id; + this.organizer=organizer; + this.title=title; + this.eventLocation=eventLocation; + this.description=description; + this.eventColour=eventColor; + this.dtstart=dtstart; + this.dtend=dtend; + } + + public static Event[] getEventsByCalendar(final Context context, final int calendarID){ + final ContentResolver cr=context.getContentResolver(); + final Cursor cursor = cr.query(Events.CONTENT_URI, + PROJECTION, + Events.CALENDAR_ID+" = ?", + new String[]{Integer.toString(calendarID)}, + null); + cursor.moveToFirst(); + final Event[] events = new Event[cursor.getCount()]; + for(int i=0;i