Back to project page silent-meeting.
The source code is released under:
GNU General Public License
If you think the Android project silent-meeting listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package uk.co.bensproule.silentmeeting.dao; /*w w w .ja v a 2 s.c om*/ import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.provider.CalendarContract; import android.util.Log; import uk.co.bensproule.silentmeeting.domain.Event; import java.util.ArrayList; import java.util.List; import static android.provider.CalendarContract.Events.*; import static uk.co.bensproule.silentmeeting.dao.SQLiteHelper.EVENTS_TABLE_NAME; public class EventDao { private SQLiteDatabase db; public EventDao(Context context) { SQLiteHelper sqLiteHelper = SQLiteHelper.instance(context); db = sqLiteHelper.getWritableDatabase(); assert db != null; } public List<Event> getAll() { Log.d("EventDao", "Getting all Events"); Cursor cursor = db.query(EVENTS_TABLE_NAME, null, null, null, null, null, null); List<Event> events = new ArrayList<>(); while (cursor.moveToNext()) { Event event = new Event(cursor.getInt(cursor.getColumnIndex(CalendarContract.Events._ID)), cursor.getInt(cursor.getColumnIndex(CalendarContract.Events.CALENDAR_ID)), cursor.getString(cursor.getColumnIndex(CalendarContract.Events.TITLE)), cursor.getLong(cursor.getColumnIndex(CalendarContract.Events.DTSTART)), cursor.getLong(cursor.getColumnIndex(CalendarContract.Events.DTEND)), cursor.getInt(cursor.getColumnIndex(CalendarContract.Events.AVAILABILITY)), cursor.getString(cursor.getColumnIndex(CalendarContract.Events.ORGANIZER))); events.add(event); } return events; } public void save(Event event) { Log.d("EventDao", "Saving " + event.toString()); ContentValues values = new ContentValues(); values.put(_ID, event.getId()); values.put(CALENDAR_ID, event.getCalendarID()); values.put(TITLE, event.getTitle()); values.put(DTSTART, event.getStartDate()); values.put(DTEND, event.getEndDate()); values.put(AVAILABILITY, event.getAvailability()); values.put(ORGANIZER, event.getOrganiser()); db.insert(EVENTS_TABLE_NAME, null, values); } public void delete(int id) { Log.d("EventDao", "Deleting " + id); String selection = _ID + " = ?"; String[] selectionArgs = {String.valueOf(id)}; db.delete(EVENTS_TABLE_NAME, selection, selectionArgs); } }