X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=src%2Fro%2Fieval%2Funical%2FEvent.java;h=97ce822f498e97a6478be516df68889c83a055e4;hb=810f5287ab8b7f0065303bde41706890e550c3cd;hp=85ad215edd6e8d75c464873932623e55c488a914;hpb=d003a6ce087a52c95f514d4e5ecad0312125f965;p=unical.git diff --git a/src/ro/ieval/unical/Event.java b/src/ro/ieval/unical/Event.java index 85ad215..97ce822 100644 --- a/src/ro/ieval/unical/Event.java +++ b/src/ro/ieval/unical/Event.java @@ -1,28 +1,31 @@ package ro.ieval.unical; +import java.util.ArrayList; + import android.content.ContentResolver; import android.content.Context; import android.database.Cursor; import android.net.Uri; import android.os.Parcel; import android.os.Parcelable; +import android.provider.BaseColumns; import android.provider.CalendarContract.Events; final class Event implements Parcelable{ public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { @Override - public Event createFromParcel(Parcel source) { + public Event createFromParcel(final Parcel source) { return new Event(source.readLong(), source.readString(), source.readString(), source.readString(), source.readString(), source.readInt(), source.readLong(), source.readLong(), source.readLong()); } @Override - public Event[] newArray(int size) { + public Event[] newArray(final int size) { return new Event[size]; } }; private static final String[] PROJECTION = { - Events._ID, + BaseColumns._ID, Events.ORGANIZER, Events.TITLE, Events.EVENT_LOCATION, @@ -64,19 +67,32 @@ final class Event implements Parcelable{ this.calendarID=calendarID; } - public static Event[] getEventsByCalendar(final Context context, final int calendarID){ + public static Event[] getEventsByCalendar(final Context context, final Calendar calendar, final String sort){ final ContentResolver cr=context.getContentResolver(); final Cursor cursor = cr.query(Events.CONTENT_URI, PROJECTION, Events.CALENDAR_ID+" = ?", - new String[]{Integer.toString(calendarID)}, - null); + new String[]{Long.toString(calendar._id)}, + sort); cursor.moveToFirst(); final Event[] events = new Event[cursor.getCount()]; - for(int i=0;i r = new ArrayList(); + for(final Calendar calendar : Calendar.getAllCalendars(context)) + for(final Event event : getEventsByCalendar(context, calendar, null)) + r.add(event); + return r.toArray(new Event[r.size()]); + } public void delete(final Context context){ final ContentResolver cr=context.getContentResolver(); @@ -89,7 +105,7 @@ final class Event implements Parcelable{ } @Override - public void writeToParcel(Parcel dest, int flags) { + public void writeToParcel(final Parcel dest, final int flags) { dest.writeLong(_id); dest.writeString(organizer); dest.writeString(title);