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<Event> CREATOR = new Parcelable.Creator<Event>() {
+ @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<events.length;i++)
+ events[i]=new Event(cursor.getInt(0), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4), cursor.getInt(5), cursor.getLong(6), cursor.getLong(7));
+ return events;
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(_id);
+ dest.writeString(organizer);
+ dest.writeString(title);
+ dest.writeString(eventLocation);
+ dest.writeString(description);
+ dest.writeInt(eventColour);
+ dest.writeLong(dtstart);
+ dest.writeLong(dtend);
}
}
import android.widget.TextView;
public class displayEventActivity extends Activity {
+ public static final String EXTRA_EVENT = "event";
+
@Override
protected void onCreate(Bundle savedInstanceState) {
- // TODO Auto-generated method stub
super.onCreate(savedInstanceState);
- //aici iei parametru
- Event e=new Event();
+ final Event e=getIntent().getParcelableExtra(EXTRA_EVENT);
setContentView(R.layout.eventview);
final TextView eventTitle= (TextView) findViewById(R.id.eventTitle);
final TextView date=(TextView) findViewById(R.id.date);
final TextView description=(TextView) findViewById(R.id.description);
final TextView location= (TextView) findViewById(R.id.location);
eventTitle.setText(e.title);
- date.setText((new Date(e.date)).toString());
+ date.setText((new Date(e.dtstart)).toString());
description.setText(e.description);
- location.setText(e.location);
+ location.setText(e.eventLocation);
}
@Override