Search in sources :

Example 6 with DatabaseHandler

use of com.instructure.parentapp.database.DatabaseHandler in project instructure-android by instructure.

the class EventFragment method cancelAlarm.

private void cancelAlarm() {
    // cancel the alarm
    AlarmReceiver alarmReceiver = new AlarmReceiver();
    String subTitle = "";
    if (mScheduleItem.getStartAt() != null) {
        subTitle = DateHelper.getDateTimeString(getContext(), mScheduleItem.getStartAt());
    }
    alarmReceiver.cancelAlarm(getContext(), mScheduleItem.getId(), mScheduleItem.getTitle(), subTitle);
    // remove it from the database
    if (mDatabaseHandler == null) {
        mDatabaseHandler = new DatabaseHandler(getActivity());
    }
    try {
        mDatabaseHandler.open();
        int id = mDatabaseHandler.getRowIdByAssignmentId(mScheduleItem.getId());
        int result = mDatabaseHandler.deleteAlarm(id);
        mDatabaseHandler.close();
    } catch (SQLException e) {
    // couldn't delete the alarm, so it will remain in the database. But the actual
    // alarm should have been canceled above.
    }
}
Also used : SQLException(java.sql.SQLException) DatabaseHandler(com.instructure.parentapp.database.DatabaseHandler) AlarmReceiver(com.instructure.parentapp.receivers.AlarmReceiver)

Example 7 with DatabaseHandler

use of com.instructure.parentapp.database.DatabaseHandler in project instructure-android by instructure.

the class AlarmReceiver method cancelAlarm.

public void cancelAlarm(Context context, long assignmentId, String title, String subTitle) {
    // need to create an intent that matches the one we want to cancel
    Intent intent = new Intent(context, AlarmReceiver.class);
    intent.putExtra(Const.TITLE_TEXT, title);
    intent.putExtra(Const.SUBTITLE_TEXT, subTitle);
    int alarmId = -1;
    DatabaseHandler mDatabaseHandler = new DatabaseHandler(context);
    try {
        mDatabaseHandler.open();
        alarmId = mDatabaseHandler.getRowIdByAssignmentId(assignmentId);
        mDatabaseHandler.close();
    } catch (SQLException e) {
    }
    PendingIntent sender = PendingIntent.getBroadcast(context, alarmId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    sender.cancel();
    alarmManager.cancel(sender);
}
Also used : SQLException(java.sql.SQLException) DatabaseHandler(com.instructure.parentapp.database.DatabaseHandler) AlarmManager(android.app.AlarmManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Aggregations

DatabaseHandler (com.instructure.parentapp.database.DatabaseHandler)7 SQLException (java.sql.SQLException)7 AlarmManager (android.app.AlarmManager)2 PendingIntent (android.app.PendingIntent)2 Intent (android.content.Intent)2 AlarmReceiver (com.instructure.parentapp.receivers.AlarmReceiver)2 Calendar (java.util.Calendar)2 CalendarWrapper (com.instructure.parentapp.models.CalendarWrapper)1