import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
+import java.util.TimeZone;
import android.app.ActionBar;
import android.app.Activity;
private TextView dateTimeTextView;
public static final String EXTRA_EVENT = "event";
- private Event event;
+ private static Event event=new Event();
public static void editEvent(final Context c, final Event e) {
final Intent i = new Intent(c,AddEventActivity.class);
i.putExtra(AddEventActivity.EXTRA_EVENT,e);
+ event=e;
c.startActivity(i);
}
cv.put(CalendarContract.Calendars.OWNER_ACCOUNT, "unical");
cv.put(CalendarContract.Calendars.VISIBLE, 1);
cv.put(CalendarContract.Calendars.SYNC_EVENTS, 1);
+ cv.put(CalendarContract.Calendars.CALENDAR_TIME_ZONE, TimeZone.getDefault().getID());
calUri = calUri.buildUpon()
.appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
.appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, "unical")
.appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL)
.build();
+ this.getContentResolver().delete(calUri, CalendarContract.Calendars.ACCOUNT_NAME + " = 'unical'", new String[0]);
this.getContentResolver().insert(calUri, cv);
Event.calendarCreated=true;
}
return true;
case R.id.save:
- Event ev=new Event();
- ev.title=((EditText)findViewById(R.id.eventtitle)).getText().toString();
+ if(event.title!=null) event.delete(this);
+ event.title=((EditText)findViewById(R.id.eventtitle)).getText().toString();
String start=((TextView)findViewById(R.id.date_start)).getText().toString()+ " " +((TextView)findViewById(R.id.time_start)).getText().toString();
String end=((TextView)findViewById(R.id.date_end)).getText().toString()+ " "+((TextView)findViewById(R.id.time_end)).getText().toString();
try {
Date s=new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(start);
Date e=new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(end);
- ev.dtstart=s.getTime();
- ev.dtend=s.getTime();
+ event.dtstart=s.getTime();
+ event.dtend=s.getTime();
} catch (ParseException e) {
e.printStackTrace();
}
- ev.description=((EditText) findViewById(R.id.description)).getText().toString();
+ event.description=((EditText) findViewById(R.id.description)).getText().toString();
- if(!Event.calendarCreated) createCalendar();
+ if(!Event.calendarCreated)createCalendar();
+ event.calendarID=Event.getUnicalId(this);
+ event.insert(this);
Toast toast = Toast.makeText(getApplicationContext(),"Event saved!",Toast.LENGTH_LONG);
toast.show();
package ro.ieval.unical;
import java.util.ArrayList;
+import java.util.TimeZone;
import android.content.ContentResolver;
import android.content.ContentValues;
return r.toArray(new Event[r.size()]);
}
+ public static long getUnicalId(final Context context) {
+ for(final Calendar calendar : Calendar.getAllCalendars(context))
+ if(calendar.name.equals("unical")) return calendar._id;
+
+ return 0;
+ }
+
+
public void insert(final Context context) {
- final ContentResolver cr=context.getContentResolver();
- //cr.insert(Uri.withAppendedPath(Events.CONTENT_URI));
- //cr.notifyChange();
+ ContentValues cv = new ContentValues();
+ cv.put("calendar_id",calendarID);
+ cv.put("title",title);
+ cv.put("description",description);
+ cv.put("dtstart",dtstart);
+ cv.put("dtend",dtend);
+ cv.put("eventTimezone", TimeZone.getDefault().getID());
+
+ Uri url = context.getContentResolver().insert(Events.CONTENT_URI, cv);
}
public void delete(final Context context){