]>
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
. ContentValues
;
7 import android
. content
. Context
;
8 import android
. database
. Cursor
;
9 import android
. graphics
. Color
;
10 import android
. net
. Uri
;
11 import android
. os
. Parcel
;
12 import android
. os
. Parcelable
;
13 import android
. provider
. BaseColumns
;
14 import android
. provider
. CalendarContract
;
15 import android
. provider
. CalendarContract
. Events
;
17 final class Event
implements Parcelable
{
18 public static final Parcelable
. Creator
< Event
> CREATOR
= new Parcelable
. Creator
< Event
>() {
20 public Event
createFromParcel ( final Parcel source
) {
21 return new Event ( source
. readLong (), source
. readString (), source
. readString (), source
. readString (), source
. readString (), source
. readInt (), source
. readLong (), source
. readLong (), source
. readLong ());
25 public Event
[] newArray ( final int size
) {
26 return new Event
[ size
];
30 private static final String
[] PROJECTION
= {
34 Events
. EVENT_LOCATION
,
45 public String organizer
;
49 public String eventLocation
;
50 /** Event description */
51 public String description
;
53 public int eventColour
;
54 /** Event start time (UTC milliseconds since epoch) */
56 /** Event end time (UTC milliseconds since epoch) */
59 public long calendarID
;
61 public static Boolean calendarCreated
= false ;
64 dtstart
= System
. currentTimeMillis ();
65 dtend
= dtstart
+ 60 * 60 * 1000 ;
68 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
) {
70 this . organizer
= organizer
;
72 this . eventLocation
= eventLocation
;
73 this . description
= description
;
74 this . eventColour
= eventColor
;
77 this . calendarID
= calendarID
;
80 public static Event
[] getEventsByCalendar ( final Context context
, final Calendar calendar
, final String sort
){
81 final ContentResolver cr
= context
. getContentResolver ();
82 final Cursor cursor
= cr
. query ( Events
. CONTENT_URI
,
84 Events
. CALENDAR_ID
+ " = ?" ,
85 new String
[]{ Long
. toString ( calendar
. _id
)},
88 final Event
[] events
= new Event
[ cursor
. getCount ()];
89 for ( int i
= 0 ; i
< events
. length
; i
++){
90 int colour
= cursor
. getInt ( 5 );
91 colour
= colour
== 0 ? calendar
. colour
: colour
;
92 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 ));
99 public static Event
[] getAllEvents ( final Context context
) {
100 final ArrayList
< Event
> r
= new ArrayList
< Event
>();
101 for ( final Calendar calendar
: Calendar
. getAllCalendars ( context
)) {
102 if ( calendar
. name
. equals ( "unical" )) calendarCreated
= true ;
103 for ( final Event event
: getEventsByCalendar ( context
, calendar
, null ))
106 return r
. toArray ( new Event
[ r
. size ()]);
109 public void insert ( final Context context
) {
110 final ContentResolver cr
= context
. getContentResolver ();
111 //cr.insert(Uri.withAppendedPath(Events.CONTENT_URI));
115 public void delete ( final Context context
){
116 final ContentResolver cr
= context
. getContentResolver ();
117 cr
. delete ( Uri
. withAppendedPath ( Events
. CONTENT_URI
, Long
. toString ( _id
)), null , null );
121 public int describeContents () {
126 public void writeToParcel ( final Parcel dest
, final int flags
) {
128 dest
. writeString ( organizer
);
129 dest
. writeString ( title
);
130 dest
. writeString ( eventLocation
);
131 dest
. writeString ( description
);
132 dest
. writeInt ( eventColour
);
133 dest
. writeLong ( dtstart
);
134 dest
. writeLong ( dtend
);
135 dest
. writeLong ( calendarID
);
This page took 0.047568 seconds and 4 git commands to generate.