コード例 #1
0
        public void UpdateAlarmManager()
        {
            Alarm newAlarm = alarmService.GetNextEnabledAlarm();

            if (newAlarm != null && (pendingAlarm == null || !newAlarm.Equals(pendingAlarm)) && !AlarmMngr.SnoozeMode)
            {
                if (pendingAlarm != null)
                {
                    AlarmMngr.StopAlarm(this);
                }
                pendingAlarm = newAlarm;
                AlarmMngr.StartAlarm(newAlarm, this);
            }
            else if (newAlarm == null && pendingAlarm != null)
            {
                AlarmMngr.StopAlarm(this);
                pendingAlarm = null;
            }
            Console.WriteLine("AlarmManager updated...");
        }
コード例 #2
0
 public override void OnReceive(Context context, Intent intent)
 {
     try {
         data = context.GetSharedPreferences("project_alarm", FileCreationMode.Private);
         if (data != null)
         {
             ICollection <string> alarmStrings = data.GetStringSet("alarms", null);
             alarmService = new AlarmService();
             if (alarmStrings != null)
             {
                 foreach (string a in alarmStrings)
                 {
                     alarmService.Alarms.Add(AlarmFactory.StringToAlarm(a));
                 }
                 alarmService.Alarms.Sort();
                 AlarmMngr.StartAlarm(alarmService.GetNextEnabledAlarm(), context);
             }
         }
     } catch (Exception ex) {
         Console.WriteLine(ex.Message);
     }
 }
コード例 #3
0
 private void setNewAlarm()
 {
     try {
         ISharedPreferences data = GetSharedPreferences("project_alarm", FileCreationMode.Private);
         if (data != null)
         {
             ICollection <string> alarmStrings = data.GetStringSet("alarms", null);
             AlarmService         alarmService = new AlarmService();
             if (alarmStrings != null)
             {
                 foreach (string a in alarmStrings)
                 {
                     string timeString    = Regex.Match(a, @"Time=([^(,|\])]*)").Groups [1].Value;
                     string enabledString = Regex.Match(a, @"Enabled=([^(,|\])]*)").Groups [1].Value;
                     char[] daysCharArray = (Regex.Match(a, @"Days=([^(,|\])]*)").Groups [1].Value).ToCharArray();
                     Console.WriteLine("alarms: " + a + "regexstring: " + timeString + ", " + enabledString.ToLower());
                     bool[] days = new bool[7];
                     for (int i = 0; i < 7; i++)
                     {
                         if (daysCharArray[i].Equals('1'))
                         {
                             days [i] = true;
                         }
                     }
                     alarmService.Alarms.Add(new Alarm(TimeSpan.Parse(timeString), Convert.ToBoolean(enabledString))
                     {
                         Days = days
                     });
                 }
                 alarmService.Alarms.Sort();
                 AlarmMngr.StartAlarm(alarmService.GetNextEnabledAlarm(), this);
             }
         }
     } catch (Exception ex) {
         Console.WriteLine(ex.Message);
     }
 }