]>
iEval git - unical.git/blob - src/ro/ieval/unical/Event.java
1 package ro
. ieval
. unical
;
3 import java
. util
. ArrayList
;
5 import android
. content
. ContentResolver
;
6 import android
. content
. Context
;
7 import android
. database
. Cursor
;
8 import android
. net
. Uri
;
9 import android
. os
. Parcel
;
10 import android
. os
. Parcelable
;
11 import android
. provider
. BaseColumns
;
12 import android
. provider
. CalendarContract
. Events
;
14 final class Event
implements Parcelable
{
15 public static final Parcelable
. Creator
< Event
> CREATOR
= new Parcelable
. Creator
< Event
>() {
17 public Event
createFromParcel ( final Parcel source
) {
18 return new Event ( source
. readLong (), source
. readString (), source
. readString (), source
. readString (), source
. readString (), source
. readInt (), source
. readLong (), source
. readLong (), source
. readLong ());
22 public Event
[] newArray ( final int size
) {
23 return new Event
[ size
];
27 private static final String
[] PROJECTION
= {
31 Events
. EVENT_LOCATION
,
40 public final long _id
;
42 public final String organizer
;
44 public final String title
;
46 public final String eventLocation
;
47 /** Event description */
48 public final String description
;
50 public final int eventColour
;
51 /** Event start time (UTC milliseconds since epoch) */
52 public final long dtstart
;
53 /** Event end time (UTC milliseconds since epoch) */
54 public final long dtend
;
56 public final long calendarID
;
58 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
) {
60 this . organizer
= organizer
;
62 this . eventLocation
= eventLocation
;
63 this . description
= description
;
64 this . eventColour
= eventColor
;
67 this . calendarID
= calendarID
;
70 public static Event
[] getEventsByCalendar ( final Context context
, final Calendar calendar
, final String sort
){
71 final ContentResolver cr
= context
. getContentResolver ();
72 final Cursor cursor
= cr
. query ( Events
. CONTENT_URI
,
74 Events
. CALENDAR_ID
+ " = ?" ,
75 new String
[]{ Long
. toString ( calendar
. _id
)},
78 final Event
[] events
= new Event
[ cursor
. getCount ()];
79 for ( int i
= 0 ; i
< events
. length
; i
++){
80 int colour
= cursor
. getInt ( 5 );
81 colour
= colour
== 0 ? calendar
. colour
: colour
;
82 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 ));
89 public static Event
[] getAllEvents ( final Context context
) {
90 final ArrayList
< Event
> r
= new ArrayList
< Event
>();
91 for ( final Calendar calendar
: Calendar
. getAllCalendars ( context
))
92 for ( final Event event
: getEventsByCalendar ( context
, calendar
, null ))
94 return r
. toArray ( new Event
[ r
. size ()]);
97 public void delete ( final Context context
){
98 final ContentResolver cr
= context
. getContentResolver ();
99 cr
. delete ( Uri
. withAppendedPath ( Events
. CONTENT_URI
, Long
. toString ( _id
)), null , null );
103 public int describeContents () {
108 public void writeToParcel ( final Parcel dest
, final int flags
) {
110 dest
. writeString ( organizer
);
111 dest
. writeString ( title
);
112 dest
. writeString ( eventLocation
);
113 dest
. writeString ( description
);
114 dest
. writeInt ( eventColour
);
115 dest
. writeLong ( dtstart
);
116 dest
. writeLong ( dtend
);
117 dest
. writeLong ( calendarID
);
This page took 0.052476 seconds and 5 git commands to generate.