private void CreateButton_Click(object sender, EventArgs e)
        {
            // Prepare the AlarmManager and new Intent for creating the alarm service
            AlarmManager manager = (AlarmManager)GetSystemService(AlarmService);

            // Generate the new ringtime object
            RingTimeObject rto;
            var            timeText = FindViewById <TextView>(Resource.Id.ringTimeText);
            var            runTime  = DateTime.Parse(timeText.Text);

            BuildDaysOfWeekList(runTime.TimeOfDay);

            Intent ringTimeIntent = new Intent(this, typeof(RingTimeReceiver));

            // Set the run date & time
            var runDateTime = new DateTime();

            if (specificDateButton.Checked)
            {
                runDateTime = DateTime.Parse(FindViewById <TextView>(Resource.Id.specificDateText).Text);
                runDateTime = new DateTime(runDateTime.Year, runDateTime.Month, runDateTime.Day,
                                           runTime.TimeOfDay.Hours, runTime.TimeOfDay.Minutes, runTime.TimeOfDay.Seconds);
            }
            else
            {
                runDateTime = nextRunDateTime(dow[0], runTime.TimeOfDay);
            }

            // Create the RingTimeObject and send it to the service
            rto = new RingTimeObject(runDateTime, ringerVolume.Progress, notificationVolume.Progress, specificDateButton.Checked);
            ringTimeIntent.PutExtra("ringtime", rto.ToBundle());
            PendingIntent pendingIntent = PendingIntent.GetBroadcast(this, 0, ringTimeIntent, PendingIntentFlags.UpdateCurrent);

            manager.Set(AlarmType.ElapsedRealtime, SystemClock.ElapsedRealtime() + 5 * 1000, pendingIntent);

            /*
             * // Default to EveryDay for now
             * int interval = 5 * 1000; // 1000 * 60 * 60 * 24;
             * var ringTimeText = FindViewById<TextView>(Resource.Id.ringTimeText);
             * DateTime ringTime = DateTime.Parse(ringTimeText.Text);
             *
             * // Create the calendar object to schedule the alarm
             * Calendar calendar = Calendar.GetInstance(Java.Util.TimeZone.Default);
             * calendar.TimeInMillis = JavaSystem.CurrentTimeMillis();
             * calendar.Set(CalendarField.HourOfDay, ringTime.Hour);
             * calendar.Set(CalendarField.Minute, ringTime.Minute);
             *
             * // Set the repeater
             * //manager.Set(AlarmType.ElapsedRealtime, SystemClock.ElapsedRealtime() + 5 * 1000, pendingIntent);
             * manager.SetRepeating(AlarmType.RtcWakeup, calendar.TimeInMillis, interval, pendingIntent);
             */
        }
Beispiel #2
0
        public override void OnReceive(Context context, Intent intent)
        {
            var rto = new RingTimeObject(intent.GetBundleExtra("ringtime"));

            Toast.MakeText(context, "RingTime " + rto.GetName() + " activated.\n" +
                           "RingTime: " + rto.GetRunDate() + ", " +
                           rto.GetRunTime() + "\n" +
                           "Ringer Volume: " + rto.GetNewRingerVolume().ToString() + "\n" +
                           "Notification Volume: " + rto.GetNewNotificationVolume().ToString(),
                           ToastLength.Long).Show();

            /*
             * AudioManager mgr = (AudioManager)context.GetSystemService(Context.AudioService);
             * mgr.SetStreamVolume(Stream.Ring, intent.GetIntExtra("ringer_volume", 0), 0);
             * mgr.SetStreamVolume(Stream.Notification, intent.GetIntExtra("notification_volume", 0), 0);
             */
        }