1 package ro
.ieval
.unical
;
3 import java
.util
.ArrayList
;
4 import java
.util
.TimeZone
;
6 import android
.content
.ContentResolver
;
7 import android
.content
.ContentValues
;
8 import android
.content
.Context
;
9 import android
.database
.Cursor
;
10 import android
.graphics
.Color
;
11 import android
.net
.Uri
;
12 import android
.os
.Parcel
;
13 import android
.os
.Parcelable
;
14 import android
.provider
.BaseColumns
;
15 import android
.provider
.CalendarContract
;
16 import android
.provider
.CalendarContract
.Events
;
18 final class Event
implements Parcelable
{
19 public static final Parcelable
.Creator
<Event
> CREATOR
= new Parcelable
.Creator
<Event
>() {
21 public Event
createFromParcel(final Parcel source
) {
22 return new Event(source
.readLong(), source
.readString(), source
.readString(), source
.readString(), source
.readString(), source
.readInt(), source
.readLong(), source
.readLong(), source
.readLong());
26 public Event
[] newArray(final int size
) {
27 return new Event
[size
];
31 private static final String
[] PROJECTION
= {
35 Events
.EVENT_LOCATION
,
46 public String organizer
;
50 public String eventLocation
;
51 /** Event description */
52 public String description
;
54 public int eventColour
;
55 /** Event start time (UTC milliseconds since epoch) */
57 /** Event end time (UTC milliseconds since epoch) */
60 public long calendarID
;
62 public static Boolean calendarCreated
=false;
65 dtstart
= System
.currentTimeMillis();
66 dtend
= dtstart
+ 60*60*1000;
69 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
) {
71 this.organizer
=organizer
;
73 this.eventLocation
=eventLocation
;
74 this.description
=description
;
75 this.eventColour
=eventColor
;
78 this.calendarID
=calendarID
;
81 public static Event
[] getEventsByCalendar(final Context context
, final Calendar calendar
, final String sort
){
82 final ContentResolver cr
=context
.getContentResolver();
83 final Cursor cursor
= cr
.query(Events
.CONTENT_URI
,
85 Events
.CALENDAR_ID
+" = ?",
86 new String
[]{Long
.toString(calendar
._id
)},
89 final Event
[] events
= new Event
[cursor
.getCount()];
90 for(int i
=0;i
<events
.length
;i
++){
91 int colour
=cursor
.getInt(5);
92 colour
=colour
== 0 ? calendar
.colour
: colour
;
93 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));
100 public static Event
[] getAllEvents(final Context context
) {
101 final ArrayList
<Event
> r
= new ArrayList
<Event
>();
102 for(final Calendar calendar
: Calendar
.getAllCalendars(context
)) {
103 if(calendar
.name
.equals("unical")) calendarCreated
=true;
104 for(final Event event
: getEventsByCalendar(context
, calendar
, null))
107 return r
.toArray(new Event
[r
.size()]);
110 public static long getUnicalId(final Context context
) {
111 for(final Calendar calendar
: Calendar
.getAllCalendars(context
))
112 if(calendar
.name
.equals("unical")) return calendar
._id
;
118 public void insert(final Context context
) {
119 ContentValues cv
= new ContentValues();
120 cv
.put("calendar_id",calendarID
);
121 cv
.put("title",title
);
122 cv
.put("description",description
);
123 cv
.put("dtstart",dtstart
);
124 cv
.put("dtend",dtend
);
125 cv
.put("eventTimezone", TimeZone
.getDefault().getID());
127 Uri url
= context
.getContentResolver().insert(Events
.CONTENT_URI
, cv
);
130 public void delete(final Context context
){
131 final ContentResolver cr
=context
.getContentResolver();
132 cr
.delete(Uri
.withAppendedPath(Events
.CONTENT_URI
, Long
.toString(_id
)), null, null);
136 public int describeContents() {
141 public void writeToParcel(final Parcel dest
, final int flags
) {
143 dest
.writeString(organizer
);
144 dest
.writeString(title
);
145 dest
.writeString(eventLocation
);
146 dest
.writeString(description
);
147 dest
.writeInt(eventColour
);
148 dest
.writeLong(dtstart
);
149 dest
.writeLong(dtend
);
150 dest
.writeLong(calendarID
);
This page took 0.02499 seconds and 4 git commands to generate.