use of com.instructure.parentapp.database.DatabaseHandler in project instructure-android by instructure.
the class AssignmentFragment method cancelAlarm.
private void cancelAlarm() {
// cancel the alarm
AlarmReceiver alarmReceiver = new AlarmReceiver();
String subTitle = "";
if (mAssignment.getDueAt() != null) {
subTitle = getContext().getResources().getString(R.string.due) + " " + DateHelper.getDateTimeString(getContext(), mAssignment.getDueAt());
}
alarmReceiver.cancelAlarm(getContext(), mAssignment.getId(), mAssignment.getName(), subTitle);
// remove it from the database
if (mDatabaseHandler == null) {
mDatabaseHandler = new DatabaseHandler(getActivity());
}
try {
mDatabaseHandler.open();
int id = mDatabaseHandler.getRowIdByAssignmentId(mAssignment.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.
}
}
use of com.instructure.parentapp.database.DatabaseHandler in project instructure-android by instructure.
the class EventFragment method setupAlarmInfo.
private void setupAlarmInfo() {
mDatabaseHandler = new DatabaseHandler(getActivity());
try {
mDatabaseHandler.open();
Calendar alarm = mDatabaseHandler.getAlarmByAssignmentId(mScheduleItem.getId());
if (alarm != null) {
mAlarmId = mDatabaseHandler.getRowIdByAssignmentId(mScheduleItem.getId());
mAlarmDetails.setVisibility(View.VISIBLE);
mAlarmDetails.setText(DateHelper.getShortDateTimeStringUniversal(getContext(), alarm.getTime()));
// set the listener to null so we don't trigger the onCheckChangedListener when we set the value
mAlarmSwitch.setOnCheckedChangeListener(null);
mAlarmSwitch.setChecked(true);
mAlarmSwitch.setOnCheckedChangeListener(mCheckedChangeListener);
} else {
mAlarmSwitch.setChecked(false);
mAlarmSwitch.setOnCheckedChangeListener(mCheckedChangeListener);
}
mDatabaseHandler.close();
} catch (SQLException e) {
// couldn't find the alarm in the database, so don't show that there is an alarm
mAlarmSwitch.setChecked(false);
mAlarmSwitch.setOnCheckedChangeListener(mCheckedChangeListener);
}
}
use of com.instructure.parentapp.database.DatabaseHandler in project instructure-android by instructure.
the class AlarmReceiver method setAlarm.
public void setAlarm(Context context, Calendar calendar, long assignmentId, String title, String subTitle) {
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, AlarmReceiver.class);
i.putExtra(Const.TITLE_TEXT, title);
i.putExtra(Const.SUBTITLE_TEXT, subTitle);
// set alarms here
// get the row id and set it as the request code so it will be unique
int alarmId = -1;
DatabaseHandler mDatabaseHandler = new DatabaseHandler(context);
try {
mDatabaseHandler.open();
alarmId = mDatabaseHandler.getRowIdByAssignmentId(assignmentId);
mDatabaseHandler.close();
} catch (SQLException e) {
// can't find the alarmId
}
// verify that we have a valid alarm id
if (alarmId != -1) {
PendingIntent pi = PendingIntent.getBroadcast(context, alarmId, i, PendingIntent.FLAG_UPDATE_CURRENT);
am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pi);
}
}
use of com.instructure.parentapp.database.DatabaseHandler in project instructure-android by instructure.
the class BootReceiver method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
// set alarms here
DatabaseHandler mDatabaseHandler = new DatabaseHandler(context);
try {
mDatabaseHandler.open();
ArrayList<CalendarWrapper> calendars = mDatabaseHandler.getAllAlarms();
if (calendars != null) {
for (CalendarWrapper wrapper : calendars) {
alarm.setAlarm(context, wrapper.getCalendar(), wrapper.getAssignmentId(), wrapper.getTitle(), wrapper.getSubTitle());
}
}
mDatabaseHandler.close();
} catch (SQLException e) {
// do nothing
}
}
}
use of com.instructure.parentapp.database.DatabaseHandler in project instructure-android by instructure.
the class AssignmentFragment method setupAlarmInfo.
private void setupAlarmInfo() {
mDatabaseHandler = new DatabaseHandler(getActivity());
try {
mDatabaseHandler.open();
Calendar alarm = mDatabaseHandler.getAlarmByAssignmentId(mAssignment.getId());
if (alarm != null) {
mAlarmId = mDatabaseHandler.getRowIdByAssignmentId(mAssignment.getId());
mAlarmDetails.setVisibility(View.VISIBLE);
mAlarmDetails.setText(DateHelper.getShortDateTimeStringUniversal(getContext(), alarm.getTime()));
// set the listener to null so we don't trigger the onCheckChangedListener when we set the value
mAlarmSwitch.setOnCheckedChangeListener(null);
mAlarmSwitch.setChecked(true);
mAlarmSwitch.setOnCheckedChangeListener(mCheckedChangeListener);
} else {
mAlarmSwitch.setChecked(false);
mAlarmSwitch.setOnCheckedChangeListener(mCheckedChangeListener);
}
mDatabaseHandler.close();
} catch (SQLException e) {
// couldn't find the alarm in the database, so don't show that there is an alarm
mAlarmSwitch.setChecked(false);
mAlarmSwitch.setOnCheckedChangeListener(mCheckedChangeListener);
}
}
Aggregations