/** * Commodity method for the building of the ContentValues object starting from the EventInfo representation. * The method will return a ContentValues that will be utilised for the insert of an event * * @param context application's context * @return ContentValues representation of the CalendarInfo object */ private ContentValues toInsertContentValues(Context context) { final ContentValues contentValues = toContentValues(); if (contentValues.containsKey(Events._ID) || contentValues.containsKey(Events.CALENDAR_DISPLAY_NAME)) { Log.w(EventInfo.class.getSimpleName(), "TThe EventInfo to insert shouldn't have id and calendarDisplayName defined, they are automatically removed"); contentValues.remove(Events._ID); id = null; contentValues.remove(Events.CALENDAR_DISPLAY_NAME); calendarDisplayName = null; } if (isRecurrentEvent()) { contentValues.remove(Events.DTEND); if (endDate != null) { contentValues.put(Events.DURATION, "P" + ((endDate.getTime() - startDate.getTime()) / 1000) + "S"); } } if (!contentValues.containsKey(Events.EVENT_TIMEZONE)) { String timezone = CalendarInfo.getCompleteInformation(context, calendarId).getAsString(Calendars.CALENDAR_TIME_ZONE); if (timezone == null) { timezone = TimeZone.getDefault().getDisplayName(); } contentValues.put(Events.EVENT_TIMEZONE, timezone); } return contentValues; }
/** * Commodity method for the building of the ContentValues object starting from the RecurrenceRule representation * * @return ContentValues representation of the RecurrenceRule object */ public ContentValues toContentValues() { ContentValues contentValues = new ContentValues(4); if (rrule != null) { contentValues.put(Events.RRULE, rrule); } if (rdate != null) { contentValues.put(Events.RDATE, rdate); } if (exrule != null) { contentValues.put(Events.EXRULE, exrule); } if (exdate != null) { contentValues.put(Events.EXDATE, exdate); } return contentValues; }
public static void insertEvent(Context context, long startTime, long endTime, String title) { ContentResolver resolver = context.getContentResolver(); if (queryHandler == null) queryHandler = new QueryHandler(resolver); ContentValues values = new ContentValues(); values.put(Events.DTSTART, startTime); values.put(Events.DTEND, endTime); values.put(Events.TITLE, title); if (BuildConfig.DEBUG) Log.d(TAG, "Calendar query start"); queryHandler.startQuery(CALENDAR, values, Calendars.CONTENT_URI, CALENDAR_PROJECTION, null, null, null); }
@Override public void onQueryComplete(int token, Object object, Cursor cursor) { // Use the cursor to move through the returned records cursor.moveToFirst(); // Get the field values long calendarID = cursor.getLong(CALENDAR_ID_INDEX); if (BuildConfig.DEBUG) Log.d(TAG, "Calendar query complete " + calendarID); ContentValues values = (ContentValues) object; values.put(Events.CALENDAR_ID, calendarID); values.put(Events.EVENT_TIMEZONE, TimeZone.getDefault().getDisplayName()); startInsert(EVENT, null, Events.CONTENT_URI, values); }
/** * This method will add the event to the user's calendar * without the use of an intent. However, this requires * you to set the READ_CALENDAR, and WRITE_CALENDAR * permissions. * * @param event * * @return The ID for the new event that was added. */ public String addEvent(CalendarEvent event) { if (calId == 0) { getCalendarId(); } ContentResolver cr = container.$context().getContentResolver(); ContentValues values = new ContentValues(); values.put(CalendarContract.Events.DTSTART, event.startTime()); values.put(CalendarContract.Events.DTEND, event.endTime()); values.put(CalendarContract.Events.TITLE, event.Title()); values.put(CalendarContract.Events.DESCRIPTION, event.Description()); values.put(CalendarContract.Events.CALENDAR_ID, calId); Uri uri = cr.insert(CalendarContract.Events.CONTENT_URI, values); return uri.getLastPathSegment(); }
/** * Deletes all Events from a given CalendarID * * @param account * @param calendarId * @return returns true if deletion was scussessful */ public boolean deleteAllEvents(Account account, long calendarId) { Log.d(TAG, "delte all Events from CalendarId = " + calendarId); ContentResolver cr = mContext.getContentResolver(); Uri uri = asSyncAdapter(Events.CONTENT_URI, account.name, account.type); String where = "( ( " + Events.CALENDAR_ID + " = ? ))"; String[] selectionArgs = new String[] { Long.toString(calendarId) }; int del = cr.delete(uri, where, selectionArgs); Log.d(TAG, "deleted " + del + " Events"); if (del > 0) { return true; } else { return false; } }
/** * Deletes an event from the db identified by calendar-ID and the events * Hash-String * * @param account * @param calendarId * @param hash * @return */ private boolean deleteEventByHash(Account account, long calendarId, String hash) { if (hash == null) { return false; } ContentResolver cr = mContext.getContentResolver(); Uri uri = asSyncAdapter(Events.CONTENT_URI, account.name, account.type); String where = "( ( " + Events.CALENDAR_ID + " = ? ) AND ( " + EVENTS_DB_HASH_COLUMN + " = ? ))"; String[] selectionArgs = new String[] { Long.toString(calendarId), hash }; int del = cr.delete(uri, where, selectionArgs); if (del > 0) { return true; } else { return false; } }
private ArrayList<String> getHashOfEventsInDb(Account account, long calendarID) { Cursor cur = null; ArrayList<String> listOfEventHashes = new ArrayList<String>(); ContentResolver cr = mContext.getContentResolver(); String[] projection = new String[] { EVENTS_DB_HASH_COLUMN }; String selection = "((" + Events.CALENDAR_ID + " = ?))"; String[] selectionArgs = new String[] { Long.toString(calendarID) }; cur = cr.query(Events.CONTENT_URI, projection, selection, selectionArgs, null); if (cur.getCount() > 0 && cur.moveToFirst()) { do { listOfEventHashes.add(cur.getString(0)); } while (cur.moveToNext()); } else { Log.d(TAG, "FATAL ERROR"); } cur.close(); return listOfEventHashes; }
/** * Inserts a whole List of VEvents * * @param account * @param calendarId * @param list * of VEvents * @param tz * @return true if successful */ private boolean insertEvents(Account account, long calendarId, ArrayList<VEvent> list, TimeZone tz) { ContentResolver cr = mContext.getContentResolver(); Uri uri = asSyncAdapter(Events.CONTENT_URI, account.name, account.type); ContentValues[] cv = new ContentValues[list.size()]; for (int i = 0; i < list.size(); i++) { cv[i] = perpareValues(calendarId, list.get(i), tz); } int ret = cr.bulkInsert(uri, cv); if (ret <= 0) { Log.e(TAG, "insertEvents() did't insert anything"); return false; } else { Log.i(TAG, "insertEvents() inserted " + ret + " events"); return true; } }
/** * Inserts a single Event into the Databses * * @param account * @param calendarId * @param e * @return keep it for test purpose */ @SuppressWarnings("unused") private long insertEvent(Account account, long calendarId, VEvent e, TimeZone tz) { ContentResolver cr = mContext.getContentResolver(); Uri uri = asSyncAdapter(Events.CONTENT_URI, account.name, account.type); ContentValues values = perpareValues(calendarId, e, tz); Uri ret = cr.insert(uri, values); if (ret == null) { Log.e(TAG, " INERT ERROR return URI is null"); return 0; } else { // Log.d(TAG, " INSERT event with hash " + hash); } return ContentUris.parseId(ret); }
/** * Register a new Calendar Event * * @param context * the current {@link Context} * @param title * title of your event * @param location * location of your event * @param description * description of your event * @param startTime * the time when you event start * @param endTime * the time when you event end */ public static void registerCalendarEvent(Context context, String title, String location, String description, long startTime, long endTime) { try { final Intent calIntent = new Intent(Intent.ACTION_INSERT); calIntent.setType("vnd.android.cursor.item/event"); calIntent.putExtra(Events.TITLE, title); calIntent.putExtra(Events.EVENT_LOCATION, location); calIntent.putExtra(Events.DESCRIPTION, description); calIntent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, false); calIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, startTime); calIntent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endTime); context.startActivity(calIntent); } catch (Throwable e) { e.printStackTrace(); } }
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private void addToCalendar(List<Task> checkedTasks) { Intent intent; String calendarTitle = getString(R.string.calendar_title); String calendarDescription = ""; if (checkedTasks.size() == 1) { // Set the task as title calendarTitle = checkedTasks.get(0).getText(); } else { // Set the tasks as description calendarDescription = selectedTasksAsString(checkedTasks); } intent = new Intent(android.content.Intent.ACTION_EDIT) .setType(Constants.ANDROID_EVENT) .putExtra(Events.TITLE, calendarTitle) .putExtra(Events.DESCRIPTION, calendarDescription); startActivity(intent); }
/** * Creates a new calendar event * <p> * Uses the Book title and dueDate information from the UI views to set up the event * @return Event ID of created event */ private long createCalendarEvent() { // Set up the event data and insert it Resources res = getResources(); ContentResolver cr = getContentResolver(); ContentValues values = new ContentValues(); TimeZone timeZone = TimeZone.getDefault(); values.put(Events.DTSTART, dueDate.getTimeInMillis()); values.put(Events.DTEND, dueDate.getTimeInMillis()); values.put(Events.EVENT_TIMEZONE, timeZone.getID()); values.put(Events.TITLE, res.getString(R.string.cal_event_title)); TextView view = (TextView) findViewById(R.id.editBookTitle); values.put(Events.DESCRIPTION, res.getString(R.string.cal_event_body, (view != null ? view.getText() : "(view object is null"))); values.put(Events.CALENDAR_ID, 3); // The calendar ID 3 is from the API examples itself but no explanation given. Uri uri = cr.insert(Events.CONTENT_URI, values); long eventID = Long.parseLong(uri.getLastPathSegment()); return eventID; }
/** * Deletes a calendar event * <p> * Finds the the event ID associated with the book where row IS _ID and * deletes this event. * @param row row whose associated event is to be deleted. */ private void deleteCalendarEvent(int row) { int column; long eventID; Cursor cursor = MainView.BooksProvider.query(BooksStorage.BOOKS_TABLE_NAME, new String[] { BooksStorage.COLUMN_NAME_CALENDAREVENTID }, BooksStorage.COLUMN_NAME__ID + " IS ?", new String[] { new String(Integer.toString(row)) }, null); if(cursor == null || !cursor.moveToFirst()) { // Something went wrong Log.e(TAG, "Received empty cursor."); return; } column = cursor.getColumnIndex(BooksStorage.COLUMN_NAME_CALENDAREVENTID); eventID = cursor.getLong(column); cursor.close(); ContentResolver cr = getContentResolver(); Uri deleteUri = null; deleteUri = ContentUris.withAppendedId(Events.CONTENT_URI, eventID); int rows = cr.delete(deleteUri, null, null); Log.d(TAG, "Rows deleted: " + rows); }
/** Deletes calendar event associated with the db row where _id IS {@link row}. * * @param row the _id of the db entry whose calendar event is to be deleted. */ private void deleteCalendarEvent(int row) { int column; long eventID; Cursor cursor = MainView.BooksProvider.query(BooksStorage.BOOKS_TABLE_NAME, new String[] { BooksStorage.COLUMN_NAME_CALENDAREVENTID }, BooksStorage.COLUMN_NAME__ID + " IS ?", new String[] { new String(Integer.toString(row)) }, null); if(!cursor.moveToFirst()) { // Something went wrong Log.e(TAG, "Received empty cursor."); return; } column = cursor.getColumnIndex(BooksStorage.COLUMN_NAME_CALENDAREVENTID); eventID = cursor.getLong(column); ContentResolver cr = getContentResolver(); Uri deleteUri = null; deleteUri = ContentUris.withAppendedId(Events.CONTENT_URI, eventID); int rows = cr.delete(deleteUri, null, null); Log.d(TAG, "Rows deleted: " + rows); }
public void addEventCorrect(String title, Calendar start, Calendar end, String description, String rrule, String location) { ContentResolver contentResolver = this.getActivity() .getContentResolver(); ContentValues calEvent = new ContentValues(); calEvent.put(CalendarContract.Events.CALENDAR_ID, Long.toString(SelectedCalendarId)); calEvent.put(CalendarContract.Events.TITLE, title); calEvent.put(CalendarContract.Events.DTSTART, start.getTimeInMillis()); calEvent.put(CalendarContract.Events.DTEND, end.getTimeInMillis()); calEvent.put(CalendarContract.Events.EVENT_TIMEZONE, "Europe/Madrid"); calEvent.put(CalendarContract.Events.RRULE, rrule); calEvent.put(CalendarContract.Events.DESCRIPTION, description); calEvent.put(CalendarContract.Events.EVENT_LOCATION, location); Uri uri = contentResolver.insert( CalendarContract.Events.CONTENT_URI, calEvent); // The returned Uri contains the content-retriever URI for // the newly-inserted event, including its id createdEventId = Long.valueOf(uri.getLastPathSegment()); Toast.makeText(this.getActivity(), "Created Calendar Event " + createdEventId, Toast.LENGTH_SHORT).show(); }
private static PendingIntent createDismissAlarmsIntent(Context context, long eventId, long startMillis, long endMillis, int notificationId, String action, boolean showEvent) { Intent intent = new Intent(); intent.setClass(context, DismissAlarmsService.class); intent.putExtra(AlertUtils.EVENT_ID_KEY, eventId); intent.putExtra(AlertUtils.EVENT_START_KEY, startMillis); intent.putExtra(AlertUtils.EVENT_END_KEY, endMillis); intent.putExtra(AlertUtils.SHOW_EVENT_KEY, showEvent); intent.putExtra(AlertUtils.NOTIFICATION_ID_KEY, notificationId); // Must set a field that affects Intent.filterEquals so that the resulting // PendingIntent will be a unique instance (the 'extras' don't achieve this). // This must be unique for the click event across all reminders (so using // event ID + startTime should be unique). This also must be unique from // the delete event (which also uses DismissAlarmsService). Uri.Builder builder = Events.CONTENT_URI.buildUpon(); ContentUris.appendId(builder, eventId); ContentUris.appendId(builder, startMillis); intent.setData(builder.build()); intent.setAction(action); return PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); }
private void saveReminders() { ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(3); boolean changed = EditEventHelper.saveReminders(ops, mModel.mId, mModel.mReminders, mOriginalModel.mReminders, false /* no force save */); if (!changed) { return; } AsyncQueryService service = new AsyncQueryService(getActivity()); service.startBatch(0, null, Calendars.CONTENT_URI.getAuthority(), ops, 0); // Update the "hasAlarm" field for the event Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, mModel.mId); int len = mModel.mReminders.size(); boolean hasAlarm = len > 0; if (hasAlarm != mOriginalModel.mHasAlarm) { ContentValues values = new ContentValues(); values.put(Events.HAS_ALARM, hasAlarm ? 1 : 0); service.startUpdate(0, null, uri, values, null, null, 0); } Toast.makeText(mContext, R.string.saving_event, Toast.LENGTH_SHORT).show(); }
private void showEventInfo(EventInfo event) { if (mShowEventDetailsWithAgenda) { FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction ft = fragmentManager.beginTransaction(); mEventInfoFragment = new EventInfoFragment(this, event.id, event.startTime.toMillis(false), event.endTime.toMillis(false), event.getResponse(), false, EventInfoFragment.DIALOG_WINDOW_STYLE); ft.replace(R.id.agenda_event_info, mEventInfoFragment); ft.commit(); mController.registerEventHandler(R.id.agenda_event_info, mEventInfoFragment); } else { Intent intent = new Intent(Intent.ACTION_VIEW); Uri eventUri = ContentUris.withAppendedId(Events.CONTENT_URI, event.id); intent.setData(eventUri); intent.setClass(this, EventInfoActivity.class); intent.putExtra(EXTRA_EVENT_BEGIN_TIME, event.startTime != null ? event.startTime.toMillis(true) : -1); intent.putExtra( EXTRA_EVENT_END_TIME, event.endTime != null ? event.endTime.toMillis(true) : -1); startActivity(intent); } mCurrentEventId = event.id; }
/** * Creates an exception to a recurring event. The only change we're making * is to the "self attendee status" value. The provider will take care of * updating the corresponding Attendees.attendeeStatus entry. * * @param eventId * The recurring event. * @param status * The new value for selfAttendeeStatus. */ private void createExceptionResponse(long eventId, int status) { ContentValues values = new ContentValues(); values.put(Events.ORIGINAL_INSTANCE_TIME, mStartMillis); values.put(Events.SELF_ATTENDEE_STATUS, status); values.put(Events.STATUS, Events.STATUS_CONFIRMED); ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); Uri exceptionUri = Uri.withAppendedPath(Events.CONTENT_EXCEPTION_URI, String.valueOf(eventId)); ops.add(ContentProviderOperation.newInsert(exceptionUri) .withValues(values).build()); mHandler.startBatch(mHandler.getNextToken(), null, CalendarContract.AUTHORITY, ops, Utils.UNDO_DELAY); }
private boolean verifySaveEventNewEvent(ArrayList<ContentProviderOperation> ops) { ArrayList<ContentProviderOperation> expectedOps = new ArrayList<ContentProviderOperation>(); int br_id = 0; mExpectedValues = buildTestValues(); mExpectedValues.put(Events.HAS_ALARM, 0); mExpectedValues.put(Events.HAS_ATTENDEE_DATA, 1); ContentProviderOperation.Builder b = ContentProviderOperation .newInsert(Events.CONTENT_URI) .withValues(mExpectedValues); expectedOps.add(b.build()); // This call has a separate unit test so we'll use it to simplify making the expected vals mHelper.saveRemindersWithBackRef(expectedOps, br_id, mModel1.mReminders, new ArrayList<ReminderEntry>(), true); addOwnerAttendeeToOps(expectedOps, br_id); addTestAttendees(expectedOps, true, br_id); assertEquals(ops, expectedOps); return true; }
private boolean verifySaveEventModifyRecurring(ArrayList<ContentProviderOperation> ops) { ArrayList<ContentProviderOperation> expectedOps = new ArrayList<ContentProviderOperation>(); int br_id = 0; mExpectedValues = buildTestValues(); mExpectedValues.put(Events.HAS_ALARM, 0); // This is tested elsewhere, used for convenience here mHelper.checkTimeDependentFields(mModel2, mModel1, mExpectedValues, EditEventHelper.MODIFY_ALL); expectedOps.add(ContentProviderOperation.newUpdate(Uri.parse(mModel1.mUri)).withValues( mExpectedValues).build()); // This call has a separate unit test so we'll use it to simplify making the expected vals mHelper.saveReminders(expectedOps, TEST_EVENT_ID, mModel1.mReminders, mModel2.mReminders, false); addAttendeeChangesOps(expectedOps); assertEquals(ops, expectedOps); return true; }
private boolean verifySaveEventUpdateNonRecurring(ArrayList<ContentProviderOperation> ops) { ArrayList<ContentProviderOperation> expectedOps = new ArrayList<ContentProviderOperation>(); int id = TEST_EVENT_ID; mExpectedValues = buildNonRecurringTestValues(); mExpectedValues.put(Events.HAS_ALARM, 0); // This is tested elsewhere, used for convenience here mHelper.checkTimeDependentFields(mModel1, mModel1, mExpectedValues, EditEventHelper.MODIFY_ALL); expectedOps.add(ContentProviderOperation.newUpdate(Uri.parse(mModel1.mUri)).withValues( mExpectedValues).build()); // This call has a separate unit test so we'll use it to simplify making the expected vals mHelper.saveReminders(expectedOps, TEST_EVENT_ID, mModel1.mReminders, mModel2.mReminders, false); addAttendeeChangesOps(expectedOps); assertEquals(ops, expectedOps); return true; }
private boolean verifySaveEventModifyAllFollowingWithNonRecurring( ArrayList<ContentProviderOperation> ops) { ArrayList<ContentProviderOperation> expectedOps = new ArrayList<ContentProviderOperation>(); int id = 0; mExpectedValues = buildNonRecurringTestValues(); mExpectedValues.put(Events.HAS_ALARM, 0); moveExpectedTimeValuesForwardOneDay(); // This has a separate test mHelper.updatePastEvents(expectedOps, mModel2, mModel1.mOriginalStart); id = expectedOps.size(); expectedOps.add(ContentProviderOperation .newInsert(Events.CONTENT_URI) .withValues(mExpectedValues) .build()); mHelper.saveRemindersWithBackRef(expectedOps, id, mModel1.mReminders, mModel2.mReminders, true); addOwnerAttendeeToOps(expectedOps, id); addTestAttendees(expectedOps, true, id); assertEquals(ops, expectedOps); return true; }
private boolean verifySaveEventModifyAllFollowingFirstWithNonRecurring( ArrayList<ContentProviderOperation> ops) { ArrayList<ContentProviderOperation> expectedOps = new ArrayList<ContentProviderOperation>(); int id = 0; mExpectedValues = buildNonRecurringTestValues(); mExpectedValues.put(Events.HAS_ALARM, 0); moveExpectedTimeValuesForwardOneDay(); expectedOps.add(ContentProviderOperation.newDelete(Uri.parse(mModel1.mUri)).build()); id = expectedOps.size(); expectedOps.add(ContentProviderOperation .newInsert(Events.CONTENT_URI) .withValues(mExpectedValues) .build()); mHelper.saveRemindersWithBackRef(expectedOps, id, mModel1.mReminders, mModel2.mReminders, true); addOwnerAttendeeToOps(expectedOps, id); addTestAttendees(expectedOps, true, id); assertEquals(ops, expectedOps); return true; }
private boolean verifySaveEventModifyAllFollowingFirstWithRecurring( ArrayList<ContentProviderOperation> ops) { ArrayList<ContentProviderOperation> expectedOps = new ArrayList<ContentProviderOperation>(); int br_id = 0; mExpectedValues = buildTestValues(); mExpectedValues.put(Events.HAS_ALARM, 0); moveExpectedTimeValuesForwardOneDay(); mExpectedValues.put(Events.DTEND, (Long)null); // This is tested elsewhere, used for convenience here mHelper.checkTimeDependentFields(mModel2, mModel1, mExpectedValues, EditEventHelper.MODIFY_ALL_FOLLOWING); expectedOps.add(ContentProviderOperation.newUpdate(Uri.parse(mModel1.mUri)).withValues( mExpectedValues).build()); // This call has a separate unit test so we'll use it to simplify making the expected vals mHelper.saveReminders(expectedOps, TEST_EVENT_ID, mModel1.mReminders, mModel2.mReminders, true); addAttendeeChangesOps(expectedOps); assertEquals(ops, expectedOps); return true; }
private ContentValues buildTestValues() { ContentValues values = new ContentValues(); values.put(Events.CALENDAR_ID, 2L); values.put(Events.EVENT_TIMEZONE, "UTC"); // Allday events are converted // to UTC for the db values.put(Events.TITLE, "The Question"); values.put(Events.ALL_DAY, 1); values.put(Events.DTSTART, TEST_START); // Monday, May 3rd, midnight UTC time values.put(Events.HAS_ATTENDEE_DATA, 1); values.put(Events.RRULE, "FREQ=DAILY;WKST=SU"); values.put(Events.DURATION, "P3652421990D"); values.put(Events.DTEND, (Long) null); values.put(Events.DESCRIPTION, "Evaluating Life, the Universe, and Everything"); values.put(Events.EVENT_LOCATION, "Earth Mk2"); values.put(Events.AVAILABILITY, 0); values.put(Events.STATUS, Events.STATUS_CONFIRMED); values.put(Events.ACCESS_LEVEL, 3); // This is one more than the model if // >0 return values; }
private void addLaunchToCalendar() { if( m_launchItem != null ) { final String title = getString( R.string.CALENDAR_event_title, m_launchItem.name ); final String description = getString( R.string.CALENDAR_event_description, m_launchItem.rocket.name, m_launchItem.rocket.configuration ); Pad pad = m_launchItem.location.pads.iterator().next(); Intent intent = new Intent( Intent.ACTION_INSERT ) .setData( Events.CONTENT_URI ) .putExtra( CalendarContract.EXTRA_EVENT_BEGIN_TIME, m_launchItem.net.getMillis() ) .putExtra( CalendarContract.EXTRA_EVENT_END_TIME, m_launchItem.windowend.getMillis() ) .putExtra( Events.TITLE, title ) .putExtra( Events.DESCRIPTION, description ) .putExtra( Events.EVENT_LOCATION, pad.name ) .putExtra( Events.AVAILABILITY, Events.AVAILABILITY_BUSY ); startActivity( intent ); } }
@Override protected EnumMap<KeyIndex, String> initContentProviderKeys() { EnumMap<KeyIndex, String> keys = new EnumMap<KeyIndex, String>( KeyIndex.class); keys.put(KeyIndex.CALENDARS_ID, Calendars._ID); keys.put(KeyIndex.CALENDARS_NAME, Calendars.NAME); keys.put(KeyIndex.CALENDARS_DISPLAY_NAME, Calendars.CALENDAR_DISPLAY_NAME); keys.put(KeyIndex.CALENDARS_VISIBLE, Calendars.VISIBLE); keys.put(KeyIndex.EVENTS_ID, Events._ID); keys.put(KeyIndex.EVENTS_CALENDAR_ID, Events.CALENDAR_ID); keys.put(KeyIndex.EVENTS_DESCRIPTION, Events.DESCRIPTION); keys.put(KeyIndex.EVENTS_LOCATION, Events.EVENT_LOCATION); keys.put(KeyIndex.EVENTS_SUMMARY, Events.TITLE); keys.put(KeyIndex.EVENTS_START, Events.DTSTART); keys.put(KeyIndex.EVENTS_END, Events.DTEND); keys.put(KeyIndex.EVENTS_RRULE, Events.RRULE); keys.put(KeyIndex.EVENTS_ALL_DAY, Events.ALL_DAY); keys.put(KeyIndex.INSTANCES_ID, Instances._ID); keys.put(KeyIndex.INSTANCES_EVENT_ID, Instances.EVENT_ID); keys.put(KeyIndex.INSTANCES_BEGIN, Instances.BEGIN); keys.put(KeyIndex.INSTANCES_END, Instances.END); keys.put(KeyIndex.ATTENDEES_ID, Attendees._ID); keys.put(KeyIndex.ATTENDEES_EVENT_ID, Attendees.EVENT_ID); keys.put(KeyIndex.ATTENDEES_NAME, Attendees.ATTENDEE_NAME); keys.put(KeyIndex.ATTENDEES_EMAIL, Attendees.ATTENDEE_EMAIL); keys.put(KeyIndex.ATTENDEES_STATUS, Attendees.ATTENDEE_STATUS); return keys; }
/** * @param event {Event} - a new event * @param recurringRule {String} - a rule for recurring events, e.g. "FREQ=DAILY;COUNT=20;BYDAY=MO,TU,WE,TH,FR;WKST=MO" * @return {long} - the created event it */ public long createEvent(String calendarName, Event event, String recurringRule) { ContentValues values = new ContentValues(); values.put(Events.DTSTART, event.start); values.put(Events.DTEND, event.end); values.put(Events.TITLE, event.title); values.put(Events.DESCRIPTION, event.summary); values.put(Events.CALENDAR_ID, getCalendarIdForName(calendarName)); values.put(Events.EVENT_TIMEZONE, "Germany/Berlin"); values.put(Events.UID_2445, event._id); if (recurringRule != null) { values.put(Events.RRULE, recurringRule); } if (ActivityCompat.checkSelfPermission(this.context, Manifest.permission.WRITE_CALENDAR) != PackageManager.PERMISSION_GRANTED) { PermissionsUtil.checkPermissions(CALENDAR_PERMISSION_CALLBACK_ID, (Activity) this.context, Manifest.permission.READ_CALENDAR, Manifest.permission.WRITE_CALENDAR); return -1; } Uri uri = this.contentResolver.insert(Events.CONTENT_URI, values); // get the event ID that is the last element in the Uri return Long.parseLong(uri.getLastPathSegment()); }
/** * deletes a event in the local android event db for a given uid (the _id property of the event-model) * * @param uid {String} - a uid of a event which will be deleted * @return {Integer} - the id of the deleted event */ public Integer deleteEventByUid(String uid) { if (ActivityCompat.checkSelfPermission(this.context, Manifest.permission.WRITE_CALENDAR) != PackageManager.PERMISSION_GRANTED) { PermissionsUtil.checkPermissions(CALENDAR_PERMISSION_CALLBACK_ID, (Activity) this.context, Manifest.permission.READ_CALENDAR, Manifest.permission.WRITE_CALENDAR); return -1; } Uri uri = Events.CONTENT_URI; String whereQuery = "(" + Events.UID_2445 + " = \'" + uid + "\')"; return this.contentResolver.delete(uri, whereQuery, null); }
public static boolean add(Context context, Event event){ NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); // Make a big notification NotificationCompat.Builder notifyBuilder = new NotificationCompat.Builder(context) .setContentTitle(context.getString(R.string.notify_title)) .setContentText(event.getFormattedText(context)) .setSmallIcon(R.drawable.ic_stat_icon) .setAutoCancel(true) .setStyle(new NotificationCompat.BigTextStyle() .bigText(event.getFormattedText(context))); Bitmap bm = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher); notifyBuilder.setLargeIcon(bm); // Add event intent Intent addEvent = new Intent(Intent.ACTION_INSERT) .setData(Events.CONTENT_URI) .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, event.getBeginTime().getTimeInMillis()) .putExtra(Events.TITLE, event.getTitle()) .putExtra(Events.DESCRIPTION, event.getText()) .putExtra(Events.EVENT_LOCATION, event.getLocation()); if (event.getEndTime() != null) { addEvent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, event.getEndTime().getTimeInMillis()); } // An unique id int uniqueId = (int) System.currentTimeMillis(); PendingIntent pendingIntent = PendingIntent.getActivity(context, uniqueId, addEvent, PendingIntent.FLAG_UPDATE_CURRENT); notifyBuilder.setContentIntent(pendingIntent); // NotificationCompat.Builder builder = notifyBuilder.addAction(R.drawable.ic_stat_add, context.getString(R.string.add), pendingIntent); notificationManager.notify( uniqueId, // So no notifications have the same id notifyBuilder.build()); return true; }