@Override public void onHandleIntent(Intent intent) { long eventId = intent.getLongExtra(AlertUtils.EVENT_ID_KEY, -1); long eventStart = intent.getLongExtra(AlertUtils.EVENT_START_KEY, -1); long eventEnd = intent.getLongExtra(AlertUtils.EVENT_END_KEY, -1); long snoozeDelay = intent.getLongExtra(AlertUtils.SNOOZE_DELAY_KEY, Utils.getDefaultSnoozeDelayMs(this)); // The ID reserved for the expired notification digest should never be passed in // here, so use that as a default. int notificationId = intent.getIntExtra( AlertUtils.NOTIFICATION_ID_KEY, AlertUtils.EXPIRED_GROUP_NOTIFICATION_ID); if (eventId != -1) { ContentResolver resolver = getContentResolver(); // Remove notification if (notificationId != AlertUtils.EXPIRED_GROUP_NOTIFICATION_ID) { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.cancel(notificationId); } // Dismiss current alarm Uri uri = CalendarAlerts.CONTENT_URI; String selection = CalendarAlerts.STATE + "=" + CalendarAlerts.STATE_FIRED + " AND " + CalendarAlerts.EVENT_ID + "=" + eventId; ContentValues dismissValues = new ContentValues(); dismissValues.put(PROJECTION[COLUMN_INDEX_STATE], CalendarAlerts.STATE_DISMISSED); resolver.update(uri, dismissValues, selection, null); // Add a new alarm long alarmTime = System.currentTimeMillis() + snoozeDelay; ContentValues values = AlertUtils.makeContentValues(eventId, eventStart, eventEnd, alarmTime, 0); resolver.insert(uri, values); AlertUtils.scheduleAlarm( SnoozeAlarmsService.this, AlertUtils.createAlarmManager(this), alarmTime); } AlertService.updateAlertNotification(this); stopSelf(); }
/** * Schedules the nearest upcoming alarm, to refresh notifications. * * <p>This is historically done in the provider but we dupe this here so the unbundled app will * work on devices that have modified this portion of the provider. This has the limitation of * querying events within some interval from now (ie. looks at reminders for all events occurring * in the next week). This means for example, a 2 week notification will not fire on time. */ public static void scheduleNextAlarm(Context context) { scheduleNextAlarm( context, AlertUtils.createAlarmManager(context), REMINDER_QUERY_BATCH_SIZE, System.currentTimeMillis()); }
@SuppressLint("NewApi") @Override public void onItemClick(AdapterView<?> parent, View view, int position, long i) { AlertActivity alertActivity = AlertActivity.this; Cursor cursor = alertActivity.getItemForView(view); long alarmId = cursor.getLong(INDEX_ROW_ID); long eventId = cursor.getLong(AlertActivity.INDEX_EVENT_ID); long startMillis = cursor.getLong(AlertActivity.INDEX_BEGIN); // Mark this alarm as DISMISSED dismissAlarm(alarmId, eventId, startMillis); // build an intent and task stack to start EventInfoActivity with AllInOneActivity // as the parent activity rooted to home. long endMillis = cursor.getLong(AlertActivity.INDEX_END); Intent eventIntent = AlertUtils.buildEventViewIntent(AlertActivity.this, eventId, startMillis, endMillis); if (Utils.isJellybeanOrLater()) { TaskStackBuilder.create(AlertActivity.this) .addParentStack(EventInfoActivity.class) .addNextIntent(eventIntent) .startActivities(); } else { alertActivity.startActivity(eventIntent); } alertActivity.finish(); }
@Override public void onHandleIntent(Intent intent) { long eventId = intent.getLongExtra(AlertUtils.EVENT_ID_KEY, -1); long eventStart = intent.getLongExtra(AlertUtils.EVENT_START_KEY, -1); long eventEnd = intent.getLongExtra(AlertUtils.EVENT_END_KEY, -1); boolean showEvent = intent.getBooleanExtra(AlertUtils.SHOW_EVENT_KEY, false); long[] eventIds = intent.getLongArrayExtra(AlertUtils.EVENT_IDS_KEY); int notificationId = intent.getIntExtra(AlertUtils.NOTIFICATION_ID_KEY, -1); Uri uri = CalendarAlerts.CONTENT_URI; String selection; // Dismiss a specific fired alarm if id is present, otherwise, dismiss all alarms if (eventId != -1) { selection = CalendarAlerts.STATE + "=" + CalendarAlerts.STATE_FIRED + " AND " + CalendarAlerts.EVENT_ID + "=" + eventId; } else if (eventIds != null && eventIds.length > 0) { selection = buildMultipleEventsQuery(eventIds); } else { selection = CalendarAlerts.STATE + "=" + CalendarAlerts.STATE_FIRED; } ContentResolver resolver = getContentResolver(); ContentValues values = new ContentValues(); values.put(PROJECTION[COLUMN_INDEX_STATE], CalendarAlerts.STATE_DISMISSED); resolver.update(uri, values, selection, null); // Remove from notification bar. if (notificationId != -1) { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.cancel(notificationId); } if (showEvent) { // Show event on Calendar app by building an intent and task stack to start // EventInfoActivity with AllInOneActivity as the parent activity rooted to home. Intent i = AlertUtils.buildEventViewIntent(this, eventId, eventStart, eventEnd); TaskStackBuilder.create(this) .addParentStack(EventInfoActivity.class) .addNextIntent(i) .startActivities(); } // Stop this service stopSelf(); }