protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); RequestWindowFeature(WindowFeatures.NoTitle); data = this.GetSharedPreferences("project_alarm", FileCreationMode.Private); SetContentView(Resource.Layout.Main); alarmService = new AlarmService(); addAlarmButton = FindViewById <Button> (Resource.Id.add_alarm_button); alarmsListView = FindViewById <ListView> (Resource.Id.alarm_listview); alarmsToggleButton = FindViewById <ToggleButton> (Resource.Id.alarm_toggle); alarmsListViewAdapter = new AlarmListViewAdapter(this, alarmService.Alarms); alarmsListView.Adapter = alarmsListViewAdapter; alarmsListView.ChoiceMode = ChoiceMode.Single; addAlarmButton.Click += AddAlarmButton_Click; alarmsListView.ItemClick += AlarmsListView_ItemClick; }
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); } }
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); } }