Search in sources :

Example 1 with AlarmId

use of com.android.calendar.alerts.GlobalDismissManager.AlarmId in project Etar-Calendar by Etar-Group.

the class DismissAlarmsService method onHandleIntent.

@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);
    long[] eventStarts = intent.getLongArrayExtra(AlertUtils.EVENT_STARTS_KEY);
    int notificationId = intent.getIntExtra(AlertUtils.NOTIFICATION_ID_KEY, -1);
    List<AlarmId> alarmIds = new LinkedList<AlarmId>();
    Uri uri = CalendarAlerts.CONTENT_URI;
    String selection;
    // Dismiss a specific fired alarm if id is present, otherwise, dismiss all alarms
    if (eventId != -1) {
        alarmIds.add(new AlarmId(eventId, eventStart));
        selection = CalendarAlerts.STATE + "=" + CalendarAlerts.STATE_FIRED + " AND " + CalendarAlerts.EVENT_ID + "=" + eventId;
    } else if (eventIds != null && eventIds.length > 0 && eventStarts != null && eventIds.length == eventStarts.length) {
        selection = buildMultipleEventsQuery(eventIds);
        for (int i = 0; i < eventIds.length; i++) {
            alarmIds.add(new AlarmId(eventIds[i], eventStarts[i]));
        }
    } else {
        // NOTE: I don't believe that this ever happens.
        selection = CalendarAlerts.STATE + "=" + CalendarAlerts.STATE_FIRED;
    }
    GlobalDismissManager.dismissGlobally(getApplicationContext(), alarmIds);
    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();
    }
}
Also used : AlarmId(com.android.calendar.alerts.GlobalDismissManager.AlarmId) ContentValues(android.content.ContentValues) NotificationManager(android.app.NotificationManager) Intent(android.content.Intent) Uri(android.net.Uri) LinkedList(java.util.LinkedList) ContentResolver(android.content.ContentResolver)

Example 2 with AlarmId

use of com.android.calendar.alerts.GlobalDismissManager.AlarmId in project Etar-Calendar by Etar-Group.

the class AlertActivity method dismissFiredAlarms.

private void dismissFiredAlarms() {
    ContentValues values = new ContentValues(1);
    values.put(PROJECTION[INDEX_STATE], CalendarAlerts.STATE_DISMISSED);
    String selection = CalendarAlerts.STATE + "=" + CalendarAlerts.STATE_FIRED;
    mQueryHandler.startUpdate(0, null, CalendarAlerts.CONTENT_URI, values, selection, null, /* selectionArgs */
    Utils.UNDO_DELAY);
    if (mCursor == null) {
        Log.e(TAG, "Unable to globally dismiss all notifications because cursor was null.");
        return;
    }
    if (mCursor.isClosed()) {
        Log.e(TAG, "Unable to globally dismiss all notifications because cursor was closed.");
        return;
    }
    if (!mCursor.moveToFirst()) {
        Log.e(TAG, "Unable to globally dismiss all notifications because cursor was empty.");
        return;
    }
    List<AlarmId> alarmIds = new LinkedList<AlarmId>();
    do {
        long eventId = mCursor.getLong(INDEX_EVENT_ID);
        long eventStart = mCursor.getLong(INDEX_BEGIN);
        alarmIds.add(new AlarmId(eventId, eventStart));
    } while (mCursor.moveToNext());
    initiateGlobalDismiss(alarmIds);
}
Also used : ContentValues(android.content.ContentValues) AlarmId(com.android.calendar.alerts.GlobalDismissManager.AlarmId) LinkedList(java.util.LinkedList)

Example 3 with AlarmId

use of com.android.calendar.alerts.GlobalDismissManager.AlarmId in project Etar-Calendar by Etar-Group.

the class AlertActivity method dismissAlarm.

private void dismissAlarm(long id, long eventId, long startTime) {
    ContentValues values = new ContentValues(1);
    values.put(PROJECTION[INDEX_STATE], CalendarAlerts.STATE_DISMISSED);
    String selection = CalendarAlerts._ID + "=" + id;
    mQueryHandler.startUpdate(0, null, CalendarAlerts.CONTENT_URI, values, selection, null, /* selectionArgs */
    Utils.UNDO_DELAY);
    List<AlarmId> alarmIds = new LinkedList<AlarmId>();
    alarmIds.add(new AlarmId(eventId, startTime));
    initiateGlobalDismiss(alarmIds);
}
Also used : ContentValues(android.content.ContentValues) AlarmId(com.android.calendar.alerts.GlobalDismissManager.AlarmId) LinkedList(java.util.LinkedList)

Aggregations

ContentValues (android.content.ContentValues)3 AlarmId (com.android.calendar.alerts.GlobalDismissManager.AlarmId)3 LinkedList (java.util.LinkedList)3 NotificationManager (android.app.NotificationManager)1 ContentResolver (android.content.ContentResolver)1 Intent (android.content.Intent)1 Uri (android.net.Uri)1