Example #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Make this page show evenw hen the phone is locked
            Window.AddFlags(WindowManagerFlags.ShowWhenLocked);
            //Window.AddFlags(WindowManagerFlags.KeepScreenOn);
            Window.AddFlags(WindowManagerFlags.TurnScreenOn);

            Settings.AddLogMessage(this, "Stop screen started: {0}", DateTime.Now.ToString(ApplicationState.DATE_TIME_TIME_OF_DAY_FORMAT_STRING));

            // If we have location constraints, make sure we're near them
            if (Settings.GetConstrainByCellTower(this))
            {
                HashSet <int> validIDs           = Settings.GetValidCellTowerIDs(this);
                HashSet <int> cellTowerIDsNearby = ApplicationState.GetInstance(this).GetNearbyCellTowerIDs();

                if (!validIDs.Overlaps(cellTowerIDsNearby))
                {
                    // Cancel this activity
                    stopAlarm();
                    Finish();
                    Settings.AddLogMessage(this, "Not near any valid cell towers. {0}", string.Join(", ", cellTowerIDsNearby));
                    return;
                }
            }

            Vibrator vb = this.GetSystemService(Java.Lang.Class.FromType(typeof(Vibrator))) as Vibrator;

#pragma warning disable 618
            if (vb != null && vb.HasVibrator)
            {
                vb.Vibrate(VIBRATION_PATTERN, -1);
            }
#pragma warning restore 618

            SetContentView(Resource.Layout.StopAlarmView);

            ButtonStopAlarm.Click += ButtonStopAlarm_Click;

            // Set the alarm volume to a constant loud volume
            VolumeControlStream = Stream.Alarm;
            audioManager        = (AudioManager)GetSystemService(Context.AudioService);
            originalMediaVolume = audioManager.GetStreamVolume(VolumeControlStream);
            audioManager.SetStreamVolume(VolumeControlStream, audioManager.GetStreamMaxVolume(VolumeControlStream), VolumeNotificationFlags.AllowRingerModes);

            this.speechEngine = new TextToSpeech(this, this);

            TextStartTimeDisplay.Text = ApplicationState.SHUT_OFF_WARNING_TIME.TotalSeconds.ToString(TIME_FORMAT_STRING);

            timer = new StartAlarmTimer((long)ApplicationState.SHUT_OFF_WARNING_TIME.TotalMilliseconds, (long)TimeSpan.FromMilliseconds(7).TotalMilliseconds, this);
            timer.Start();
        }
Example #2
0
        private void stopAlarm()
        {
            if (!wasStopped)
            {
                wasStopped = true;

                if (speechEngine != null && speechEngine.IsSpeaking)
                {
                    this.speechEngine.Stop();
                }
                if (timer != null)
                {
                    timer.Cancel();
                }
                if (currentMessenger != null)
                {
                    currentMessenger.Stop();
                }
                ApplicationState.GetInstance(this).SyncNextAlarm();
            }
        }
Example #3
0
        private void TextSkippedDate_FocusChange(object sender, Android.Views.View.FocusChangeEventArgs e)
        {
            if (!e.HasFocus)
            {
                return;
            }

            EventHandler <DatePickerDialog.DateSetEventArgs> dateChangedCallback = (s, args) =>
            {
                HashSet <DayOfWeek> weekdays = new HashSet <DayOfWeek> {
                    DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday
                };
                string   dateText = TextSkippedDate.Text;
                DateTime newDate  = args.Date;
                if (weekdays.Contains(newDate.DayOfWeek))
                {
                    Settings.SetSkippedDate(newDate, this);
                    Toast.MakeText(this, "Date changed", ToastLength.Short).Show();
                    syncSkippedDate();

                    ApplicationState.GetInstance(this).ResetAlarms();
                    syncAlarmTimeView();
                }
                else
                {
                    Toast.MakeText(this, string.Format("{0} is not a valid weekday", dateText), ToastLength.Short).Show();
                }

                TextSkippedDate.ClearFocus();
            };

            DateTime now = DateTime.Now;

            DatePickerDialog theD = new DatePickerDialog(this, dateChangedCallback, now.Year, now.Month - 1, now.Day);

            theD.CancelEvent += (s, eve) => TextSkippedDate.ClearFocus();
            theD.Show();
        }
Example #4
0
        private void ButtonCancelPendingAlarms_Click(object sender, EventArgs e)
        {
            ApplicationState.GetInstance(this).ResetAlarms();

            syncAlarmTimeView();
        }