public MedicationReminderDialogFragment(Activity activity, MedicationListActivity fragment, ConstantsAndTypes.PRESCRIPTION_TYPE prescriptionType, ConstantsAndTypes.DAYS_OF_THE_WEEK dayOfWeek, int medicationSpreadID, DateTime reminderTime, string title) { _activity = activity; _fragment = fragment; _prescriptionType = prescriptionType; _dayOfWeek = dayOfWeek; _medicationSpreadID = medicationSpreadID; _reminderTime = reminderTime; Log.Info(TAG, "Constructor, dayOfWeek - " + StringHelper.DayStringForConstant(dayOfWeek) + ", medicationSpreadID - " + medicationSpreadID.ToString()); _dialogTitle = title; }
public void SetAlarm(Context context, int reminderID, DateTime alarmTime, string message, ConstantsAndTypes.ALARM_INTERVALS alarmInterval = _defaultAlarmInterval, ConstantsAndTypes.DAYS_OF_THE_WEEK dayOfWeek = ConstantsAndTypes.DAYS_OF_THE_WEEK.Undefined, bool repeating = false) { try { AlarmManager alarmManager = (AlarmManager)Application.Context.GetSystemService(Context.AlarmService); Log.Info(TAG, "SetAlarm: Created AlarmManager"); if (alarmManager != null) { Intent intent = new Intent(_activity, typeof(AlarmReceiver)); intent.PutExtra("message", message); Log.Info(TAG, "SetAlarm: Added to intent, message - " + message); intent.PutExtra("reminderID", reminderID); Log.Info(TAG, "SetAlarm: Added to intent, reminderID - " + reminderID.ToString()); Log.Info(TAG, "SetAlarm: Created Intent of type AlarmHelper (this)"); PendingIntent pendingIntent = PendingIntent.GetBroadcast(_activity, reminderID, intent, PendingIntentFlags.UpdateCurrent); Log.Info(TAG, "SetAlarm: Created PendingIntent with reminderID - " + reminderID.ToString()); Calendar calendar = Calendar.GetInstance(Locale.Default); calendar.TimeInMillis = JavaSystem.CurrentTimeMillis(); Log.Info(TAG, "SetAlarm: Set Calendar time in millis to current time - " + calendar.TimeInMillis.ToString()); calendar.Set(CalendarField.HourOfDay, alarmTime.Hour); Log.Info(TAG, "SetAlarm: Set calendar HourOfDay to " + alarmTime.Hour.ToString()); calendar.Set(CalendarField.Minute, alarmTime.Minute); Log.Info(TAG, "SetAlarm: Set calendar Minute to " + alarmTime.Minute.ToString()); if (alarmInterval == ConstantsAndTypes.ALARM_INTERVALS.Daily) { //most are going to be daily - however, currently, if you set a daily alarm for a time that has already passed //e.g it is currently 2.00pm when you set an alarm for 08.30am, then the alarm will sound immediately //this is not desirable behaviour, so we are going to take the current time and compare to the alarm time //and then add 1 day to the alarm time if it has already elapsed (effectively setting the NEXT scheduled alarm time) if (JavaSystem.CurrentTimeMillis() - calendar.TimeInMillis > 0) { Log.Info(TAG, "SetAlarm: Alarm set was in the past - adding 1 day to ensure NEXT scheduled alarm time!"); calendar.TimeInMillis += (long)ConstantsAndTypes.ALARM_INTERVALS.Daily; } Log.Info(TAG, "SetAlarm: Setting repeating alarm for (approx) time in millis - " + calendar.TimeInMillis.ToString() + ", alarm interval - " + (AlarmManager.IntervalDay).ToString()); alarmManager.SetRepeating(AlarmType.RtcWakeup, calendar.TimeInMillis, AlarmManager.IntervalDay, pendingIntent); } if (alarmInterval == ConstantsAndTypes.ALARM_INTERVALS.Weekly) { calendar.Set(CalendarField.DayOfWeek, (int)dayOfWeek); Log.Info(TAG, "SetAlarm: Set day of the week to " + StringHelper.DayStringForConstant(dayOfWeek)); Log.Info(TAG, "SetAlarm: Setting repeating alarm for (approx) time in millis - " + calendar.TimeInMillis.ToString() + ", alarm interval - " + (AlarmManager.IntervalDay * 7).ToString()); alarmManager.SetRepeating(AlarmType.RtcWakeup, calendar.TimeInMillis, AlarmManager.IntervalDay * 7, pendingIntent); } } else { Log.Error(TAG, "SetAlarm: AlarmManager is NULL!"); } } catch (System.Exception e) { Log.Error(TAG, "SetAlarm: Exception - " + e.Message); if (GlobalData.ShowErrorDialog) { ErrorDisplay.ShowErrorAlert(_activity, e, "Setting Alarm", "AlarmHelper.SetAlarm"); } } }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { try { if (Dialog != null) { Dialog.SetTitle(_dialogTitle); } View view = inflater.Inflate(Resource.Layout.MedicationReminderDialogFragmentLayout, container, false); if (view != null) { GetFieldComponents(view); Log.Info(TAG, "OnCreateView: Got field components"); SetupCallbacks(); Log.Info(TAG, "OnCreateView: Setup callbacks"); if (savedInstanceState != null) { _prescriptionType = (ConstantsAndTypes.PRESCRIPTION_TYPE)savedInstanceState.GetInt("prescriptionType", -1); _dayOfWeek = (ConstantsAndTypes.DAYS_OF_THE_WEEK)savedInstanceState.GetInt("dayOfWeek", (int)ConstantsAndTypes.DAYS_OF_THE_WEEK.Monday); _medicationSpreadID = savedInstanceState.GetInt("medicationSpreadID", -1); _reminderTime = Convert.ToDateTime(savedInstanceState.GetString("reminderTime")); _dialogTitle = savedInstanceState.GetString("dialogTitle"); } _timeText.Text = _reminderTime.ToShortTimeString(); SetupSpinner(); Log.Info(TAG, "OnCreateView: Set up spinner"); if (_firstTimeView) { switch (_prescriptionType) { case ConstantsAndTypes.PRESCRIPTION_TYPE.Weekly: if (_dayLabel != null) { _dayLabel.Visibility = ViewStates.Visible; } if (_daySpinner != null) { _daySpinner.Visibility = ViewStates.Visible; _daySpinner.SetSelection((int)_dayOfWeek); } if (_timeText != null) { _timeText.Text = _reminderTime.ToShortTimeString(); } break; default: if (_dayLabel != null) { _dayLabel.Visibility = ViewStates.Invisible; } if (_daySpinner != null) { _daySpinner.Visibility = ViewStates.Invisible; } if (_timeText != null) { _timeText.Text = _reminderTime.ToShortTimeString(); } break; } _firstTimeView = false; } } else { Log.Error(TAG, "OnCreateView: View is NULL!"); } return(view); } catch (Exception e) { Log.Error(TAG, "OnCreateView: Exception - " + e.Message); if (GlobalData.ShowErrorDialog) { ErrorDisplay.ShowErrorAlert(Activity, e, Activity.GetString(Resource.String.ErrorMedListFragCreateView), "MedicationreminderDialogFragment.OnCreateView"); } return(null); } }