package ro.ieval.unical;
+import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import android.app.DatePickerDialog.OnDateSetListener;
import android.app.Fragment;
import android.app.TimePickerDialog.OnTimeSetListener;
+import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
+import android.graphics.Color;
+import android.net.Uri;
import android.os.Bundle;
+import android.provider.CalendarContract;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
return true;
}
+ public void createCalendar() {
+ Uri calUri,result;
+ ContentValues cv;
+ calUri = CalendarContract.Calendars.CONTENT_URI;
+ cv = new ContentValues();
+ cv.put(CalendarContract.Calendars.ACCOUNT_NAME,"unical");
+ cv.put(CalendarContract.Calendars.ACCOUNT_TYPE,CalendarContract.ACCOUNT_TYPE_LOCAL);
+ cv.put(CalendarContract.Calendars.NAME,"unical");
+ cv.put(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, "Unical");
+ cv.put(CalendarContract.Calendars.CALENDAR_COLOR, Color.BLACK);
+ cv.put(CalendarContract.Calendars.CALENDAR_ACCESS_LEVEL, CalendarContract.Calendars.CAL_ACCESS_OWNER);
+ cv.put(CalendarContract.Calendars.OWNER_ACCOUNT, "unical");
+ cv.put(CalendarContract.Calendars.VISIBLE, 1);
+ cv.put(CalendarContract.Calendars.SYNC_EVENTS, 1);
+ 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().insert(calUri, cv);
+ Event.calendarCreated=true;
+ }
+
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
switch (item.getItemId()) {
finish();
return true;
case R.id.save:
- System.out.println("MuieLaComisie\n"+event.title);
+
+ Event ev=new Event();
+ ev.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();
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+
+ ev.description=((EditText) findViewById(R.id.description)).getText().toString();
+
+ if(!Event.calendarCreated) createCalendar();
Toast toast = Toast.makeText(getApplicationContext(),"Event saved!",Toast.LENGTH_LONG);
toast.show();
import java.util.ArrayList;
import android.content.ContentResolver;
+import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
+import android.graphics.Color;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.provider.BaseColumns;
+import android.provider.CalendarContract;
import android.provider.CalendarContract.Events;
final class Event implements Parcelable{
/** Calendar ID */
public long calendarID;
+ public static Boolean calendarCreated=false;
+
public Event() {
dtstart = System.currentTimeMillis();
dtend = dtstart + 60*60*1000;
public static Event[] getAllEvents(final Context context) {
final ArrayList<Event> r = new ArrayList<Event>();
- for(final Calendar calendar : Calendar.getAllCalendars(context))
+ for(final Calendar calendar : Calendar.getAllCalendars(context)) {
+ if(calendar.name.equals("unical")) calendarCreated=true;
for(final Event event : getEventsByCalendar(context, calendar, null))
r.add(event);
+ }
return r.toArray(new Event[r.size()]);
}