]> iEval git - unical.git/commitdiff
Rewrite the Event class and make displayEventActivity work with it
authorMarius Gavrilescu <marius@ieval.ro>
Tue, 28 May 2013 21:09:41 +0000 (00:09 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Tue, 28 May 2013 21:09:41 +0000 (00:09 +0300)
src/ro/ieval/unical/Event.java
src/ro/ieval/unical/displayEventActivity.java

index 14f2c43b7a6236291958a7d36cadae20e2ed485d..4c6abba0bf22b4d91c1163148eca03069573aa1a 100644 (file)
@@ -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<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);
        }
 }
index b6ded5dab82fded73105e2c3a7b1020d39d8460f..fb76934a7411bc4ed37c79a703ef6148a291cce9 100644 (file)
@@ -9,21 +9,21 @@ import android.view.MenuInflater;
 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
This page took 0.032756 seconds and 4 git commands to generate.