Exemplo n.º 1
0
        public void Beep(int count)
        {
            Android.Net.Uri ringtone     = RingtoneManager.GetActualDefaultRingtoneUri(Context, RingtoneType.Notification);
            Ringtone        notification = RingtoneManager.GetRingtone(Context, ringtone);

            // If phone is not set to silent mode
            if (notification != null)
            {
                for (int i = 0; i < count; ++i)
                {
                    notification.Play();
                    long timeout = 5000;
                    while (notification.IsPlaying && (timeout > 0))
                    {
                        timeout = timeout - 100;
                        try
                        {
                            Thread.Sleep(100);
                        }
                        catch (InterruptedException e)
                        {
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public override void OnReceive(Context context, Intent intent)
        {
            var message = intent.GetStringExtra("message");
            var title   = intent.GetStringExtra("title");

            var notIntent     = new Intent(context, typeof(MainActivity));
            var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.CancelCurrent);

            Uri      ring_uri = RingtoneManager.GetActualDefaultRingtoneUri(context, RingtoneType.Ringtone);
            Ringtone r        = RingtoneManager.GetRingtone(context, ring_uri);

            //r.Play();

            mytts = new TextToSpeech_Android();
            Intent checkttsIntent = new Intent();

            checkttsIntent.SetAction(TextToSpeech.Engine.ActionCheckTtsData);
            mytts.Speak(message);


            //var manager = NotificationManagerCompat.From(context);

            //var style = new NotificationCompat.BigTextStyle();
            //style.BigText(message);
        }
Exemplo n.º 3
0
        public override void OnReceive(Context context, Intent intent)
        {
            switch (ResultCode)
            {
            case Result.Ok:
            {
                try
                {
                    Android.Net.Uri notification = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
                    Ringtone        r            = RingtoneManager.GetRingtone(context, notification);
                    r.Play();
                }
                catch (Exception e)
                {
                }

                Toast.MakeText(Application.Context, "SMS delivered", ToastLength.Long).Show();
                break;
            }

            case Result.Canceled:
            {
                Toast.MakeText(Application.Context, "SMS not delivered", ToastLength.Long).Show();
                break;
            }
            }
        }
Exemplo n.º 4
0
 public Ringer(Context ApplicationContext)
 {
     if (ringtone == null)
     {
         ringtone = RingtoneManager.GetRingtone(ApplicationContext, RingtoneManager.GetDefaultUri(RingtoneType.Ringtone));
     }
 }
Exemplo n.º 5
0
        private void SetBinding()
        {
            var bindingSet = this.CreateBindingSet <SettingsView, SettingsViewModel>();

            bindingSet.Bind(HoursList)
            .For(v => v.ItemsSource)
            .To(vm => vm.HoursList);

            bindingSet.Bind(addHour)
            .For(nameof(View.Click))
            .To(vm => vm.AddHour);

            bindingSet.Bind(soundLabel)
            .For(v => v.Text)
            .To(vm => vm.RingUri)
            .WithConversion(new InlineValueConverter <string, string>((arg) =>
            {
                var uri           = Android.Net.Uri.Parse(arg);
                Ringtone ringtone = RingtoneManager.GetRingtone(this, uri);
                return(RingtoneManager.IsDefault(uri) ? "Default" : ringtone.GetTitle(this));
            }));

            bindingSet.Bind(this.snooze)
            .For(v => v.Text)
            .To(vm => vm.SnoozeMinutes)
            .WithConversion(new InlineValueConverter <int, string>(arg => Humanizer.TimeSpanHumanizeExtensions.Humanize(TimeSpan.FromMinutes(arg), maxUnit: Humanizer.Localisation.TimeUnit.Minute, minUnit: Humanizer.Localisation.TimeUnit.Minute)));

            bindingSet.Bind(this.window)
            .For(v => v.Text)
            .To(vm => vm.WindowHours)
            .WithConversion(new InlineValueConverter <int, string>(arg => $"+/- {Humanizer.TimeSpanHumanizeExtensions.Humanize(TimeSpan.FromHours(arg), maxUnit: Humanizer.Localisation.TimeUnit.Hour, minUnit: Humanizer.Localisation.TimeUnit.Hour)}"));


            bindingSet.Apply();
        }
Exemplo n.º 6
0
        public void startRingTone()
        {
            if (mRingtonePlayer != null && mRingtonePlayer.IsPlaying)
            {
                ringRef++;
                return;
            }

            if (mRingtonePlayer == null && mContext != null)
            {
                try
                {
                    mRingtonePlayer = RingtoneManager.GetRingtone(mContext, RingtoneManager.GetDefaultUri(RingtoneType.Ringtone));
                }
                catch (Java.Lang.Exception e)
                {
                    Console.WriteLine("startRingTone: {0} ", e.ToString());
                    return;
                }
            }

            if (mRingtonePlayer != null)
            {
                lock (mRingtonePlayer)
                {
                    ringRef++;
                    mRingtonePlayer.Play();
                }
            }
        }
        public async Task PlayNotificationDefaultSound()
        {
            await Task.Run(() =>
            {
                // Music enabled?
                if (!MusicOn)
                {
                    return;
                }

                if (Interlocked.Read(ref _estoySonando) != 0)
                {
                    return;
                }

                Interlocked.Increment(ref _estoySonando);

                if (_ringtone == null)
                {
                    Uri urlToNotification = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
                    _ringtone             = RingtoneManager.GetRingtone(MainApplication.CurrentContext, urlToNotification);
                }

                _ringtone.Play();

                Interlocked.Decrement(ref _estoySonando);
            });
        }
Exemplo n.º 8
0
 public void PlayAudio(bool play)
 {
     if (_Alarm == null)
     {
         var uri = RingtoneManager.GetDefaultUri(RingtoneType.Alarm);
         _Alarm           = RingtoneManager.GetRingtone(global::Android.App.Application.Context, uri);
         _Timer           = new System.Timers.Timer();
         _Timer.Interval  = 2000;
         _Timer.AutoReset = false;
         _Timer.Elapsed  += _Timer_Elapsed;
     }
     if (play && !_Alarm.IsPlaying)
     {
         AccelerometerOld = null;
         GyroscopeMin     = null;
         GyroscopeMax     = null;
         OrientationMin   = null;
         OrientationMax   = null;
         _Alarm.Play();
         _Timer.Start();
     }
     else if (!play && _Alarm.IsPlaying)
     {
         _Alarm.Stop();
     }
 }
Exemplo n.º 9
0
        public override void OnReceive(Context context, Intent intent)
        {
            Vibrator vibrator = (Vibrator)context.GetSystemService(Context.VibratorService);

            vibrator.Vibrate(2000);

            Notification notification = new Notification.Builder(context)
                                        .SetContentTitle("Будильник!!")
                                        .SetSmallIcon(Resource.Drawable.IcDialogAlert)
                                        .SetContentText("Вставай!").Build();

            NotificationManager manager = (NotificationManager)context.GetSystemService(Context.NotificationService);

            notification.Flags = NotificationFlags.AutoCancel;
            manager.Notify(0, notification);

            Android.Net.Uri uri = RingtoneManager.GetDefaultUri(RingtoneType.Alarm);

            Ringtone r = RingtoneManager.GetRingtone(context, uri);

            r.Play();
            var Page     = (App)Xamarin.Forms.Application.Current;
            var MainPage = (MainPage)Page.MainPage;

            MainPage.UpdateToogles();
        }
Exemplo n.º 10
0
        public void PlayExclusiveNativeSound(NativeSoundData nativeSoundData, float volume = 1.0F)
        {
            StopExclusiveNativeSound();
            Android.Net.Uri uri = Android.Net.Uri.Parse((nativeSoundData.Intern ?
                                                         MediaStore.Audio.Media.InternalContentUri :
                                                         MediaStore.Audio.Media.ExternalContentUri).ToString() + "/" + nativeSoundData.ID);

            if (nativeSoundData.ID == "")
            {
                uri = Android.Net.Uri.Parse(nativeSoundData.Data);
            }


            Ringtone rt = RingtoneManager.GetRingtone(global::Android.App.Application.Context, uri);

            if (rt != null)
            {
                rt.AudioAttributes = new AudioAttributes.Builder()
                                     .SetUsage(AudioUsageKind.Alarm)
                                     .SetContentType(AudioContentType.Music)
                                     .Build();
                rt.Looping = true;
                rt.Volume  = volume;
                rt.Play();
                exclusiveRingtone = rt;
            }
        }
Exemplo n.º 11
0
        public void PlayNitificationTone()
        {
            Android.Net.Uri notification = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
            Ringtone        r            = RingtoneManager.GetRingtone(this, notification);

            r.Play();
        }
Exemplo n.º 12
0
 public RingTone()
 {
     Android.Net.Uri alert = RingtoneManager.GetDefaultUri(RingtoneType.Alarm);
     context      = Android.App.Application.Context;
     ringTone     = RingtoneManager.GetRingtone(context, alert);
     vibrator     = (Vibrator)context.GetSystemService(Context.VibratorService);
     audiomanager = (AudioManager)context.GetSystemService(Context.AudioService);
 }
Exemplo n.º 13
0
        private void StartSound(String audio_path)
        {
            // Play as a system sound
            Ringtone swingRing = RingtoneManager.GetRingtone(ApplicationContext, Android.Net.Uri.Parse(audio_path));

            swingRing.AudioAttributes = new AudioAttributes.Builder().SetFlags(AudioFlags.None).SetLegacyStreamType(Android.Media.Stream.System).Build();
            swingRing.Play();
        }
Exemplo n.º 14
0
        public override void OnFinish()
        {
            inputField.Text = "0:00";
            Android.Net.Uri notificationUri = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
            Ringtone        tone            = RingtoneManager.GetRingtone(context, notificationUri);

            tone.Play();
        }
Exemplo n.º 15
0
        public DisplayAlarmPage(string title, string msg, Ringtone r)
        {
            InitializeComponent();

            //lblTitle.Text = title;
            //lblMsg.Text = msg;
            //this.r = r;
        }
Exemplo n.º 16
0
        public void Play()
        {
            //TODO: Implement some form of enum.

            var      notification = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
            Ringtone r            = RingtoneManager.GetRingtone(CurrentActivity, notification);

            r.Play();
        }
        //protected override void OnCreate(Bundle savedInstanceState)  -  Original VS code
        //Xamarin.Essentials.Platform.Init(this, bundle);  - code from MS documentation

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);  // -  Original VS code
            //Xamarin.Essentials.Platform.Init(this, bundle);


            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            btnVB_On     = FindViewById <Button>(Resource.Id.btnVB_On);
            btnVB_Off    = FindViewById <Button>(Resource.Id.btnVB_Off);
            btnScreen2   = FindViewById <Button>(Resource.Id.btnScreen2);
            btnAlarm_On  = FindViewById <Button>(Resource.Id.btnAlarm_On);
            btnAlarm_Off = FindViewById <Button>(Resource.Id.btnAlarm_Off);

            btnVB_On.Click     += BtnVB_On_Click;
            btnVB_Off.Click    += BtnVB_Off_Click;
            btnScreen2.Click   += BtnScreen2_Click;
            btnAlarm_On.Click  += btnAlarm_On_Click;
            btnAlarm_Off.Click += BtnAlarm_Off_Click;

            ringer = RingtoneManager.GetRingtone(ApplicationContext, RingtoneManager.GetDefaultUri(RingtoneType.Alarm));



            Intent intent = new Intent(this, typeof(Screen2Activity));

            const int     pendindingIntentId = 0;
            PendingIntent pendingIntent      =
                PendingIntent.GetActivity(this, pendindingIntentId, intent, PendingIntentFlags.OneShot);

            // instantiate builder and set notification elements
            NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                                                 //Notification.Builder builder = new Notification.Builder(this)
                                                 .SetContentIntent(pendingIntent)
                                                 .SetContentTitle("My 1st Notification")
                                                 .SetContentText("Here is the content from my new notification.")
                                                 .SetSmallIcon(Resource.Drawable.ic_home_black_24dp)
                                                 .SetVisibility(NotificationCompat.VisibilityPublic)
                                                 .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Alarm)) // ? not obsolete in NotificationCompat !!
                                                 .SetPriority(NotificationCompat.PriorityMax)
            ;



            // build notification
            Notification notification = builder.Build();

            // get the notification manager
            NotificationManager notificationManager =
                GetSystemService(Context.NotificationService) as NotificationManager;

            // publish the notification
            const int notificationId = 0;

            notificationManager.Notify(notificationId, notification);
        }
 private void BtnAlarm_Click(object sender, System.EventArgs e)
 {
     try
     {
         Android.Net.Uri alarm = RingtoneManager.GetDefaultUri(RingtoneType.Alarm);
         Ringtone        r     = RingtoneManager.GetRingtone(this, alarm);
         r.Play();
     }
     catch (Exception ex) { Toast.MakeText(this, ex.Message, ToastLength.Long).Show(); }
 }
Exemplo n.º 19
0
 public static void Play()
 {
     try {
         Android.Net.Uri notification = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
         Ringtone        r            = RingtoneManager.GetRingtone(Application.Context, notification);
         r.Play();
     } catch (Exception ex) {
         Console.WriteLine(ex.ToString());
     }
 }
Exemplo n.º 20
0
 static void stopNotifyRingtone()
 {
     if (alarmRingtone != null)
     {
         if (alarmRingtone.IsPlaying)
         {
             alarmRingtone.Stop();
         }
         alarmRingtone.Dispose();
         alarmRingtone = null;
     }
 }
Exemplo n.º 21
0
 public void StopExclusiveNativeSound()
 {
     if (exclusiveRingtone != null && exclusiveRingtone.IsPlaying)
     {
         exclusiveRingtone.Stop();
     }
     if (exclusiveRingtone != null)
     {
         exclusiveRingtone.Dispose();
     }
     exclusiveRingtone = null;
 }
Exemplo n.º 22
0
        private void DeclareSwitchEvents()
        {
            Switch swTabNDOptionsVibration = FindViewById <Switch>(Resource.Id.swTabNDOptionsVibration);

            swTabNDOptionsVibration.CheckedChange += delegate(object sender, CompoundButton.CheckedChangeEventArgs e)
            {
                bool boolchecked = e.IsChecked;
                // Store Global Value
                prefs = PreferenceManager.GetDefaultSharedPreferences(this);
                ISharedPreferencesEditor editor = prefs.Edit();

                if (boolchecked)
                {
                    Vibrator v = (Vibrator)this.GetSystemService(Context.VibratorService); // Make phone vibrate
                    v.Vibrate(1000);

                    editor.PutInt("AlertVibrate", 1);
                }
                else
                {
                    editor.PutInt("AlertVibrate", 0);
                }

                editor.Commit();
                editor.Apply();
            };

            Switch swTabNDOptionsAlert = FindViewById <Switch>(Resource.Id.swTabNDOptionsAlert);

            swTabNDOptionsAlert.CheckedChange += delegate(object sender, CompoundButton.CheckedChangeEventArgs e)
            {
                bool boolchecked = e.IsChecked;
                // Store Global Value
                prefs = PreferenceManager.GetDefaultSharedPreferences(this);
                ISharedPreferencesEditor editor = prefs.Edit();

                if (boolchecked)
                {
                    Android.Net.Uri notification = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
                    Ringtone        r            = RingtoneManager.GetRingtone(this, notification);
                    r.Play();

                    editor.PutInt("AlertTone", 1);
                }
                else
                {
                    editor.PutInt("AlertTone", 0);
                }

                editor.Commit();
                editor.Apply();
            };
        }
 public void SetNotificationSound()
 {
     try
     {
         Uri      defaultSoundUri = Uri.Parse("android.resource://" + Android.App.Application.Context.PackageName + "/" + Resource.Raw.notifysound);
         Ringtone r = RingtoneManager.GetRingtone(Android.App.Application.Context, defaultSoundUri);
         r.Play();
     }
     catch (System.Exception e)
     {
     }
 }
Exemplo n.º 24
0
 public void stopRingTone()
 {
     if (mRingtonePlayer != null)
     {
         lock (mRingtonePlayer)
         {
             if (--ringRef <= 0)
             {
                 mRingtonePlayer.Stop();
                 mRingtonePlayer = null;
             }
         }
     }
 }
 public override void OnReceive(Context context, Intent intent)
 {
     Toast.MakeText(context, "Running", ToastLength.Short).Show();
     System.Diagnostics.Debug.WriteLine("Running...");
     try
     {
         Uri      notification = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
         Ringtone tone         = RingtoneManager.GetRingtone(Application.Context, notification);
         tone.Play();
     }
     catch (Error e)
     {
         System.Diagnostics.Debug.WriteLine(e.Message);
     }
 }
Exemplo n.º 26
0
        public void PlaySystemSound()
        {
            //If the ringer mode is different than "Normal" (2), enables the normal mode.
            AudioManager am = (AudioManager)Application.Context.GetSystemService(Context.AudioService);

            if (!am.RingerMode.Equals(2))
            {
                am.RingerMode = RingerMode.Normal;
                //am.SetVibrateSetting(VibrateType.Ringer, VibrateSetting.On);
            }

            Android.Net.Uri uri = RingtoneManager.GetDefaultUri(RingtoneType.Ringtone);
            rt = RingtoneManager.GetRingtone(MainActivity.instance.ApplicationContext, uri);
            rt.Play();
        }
        public static bool OnPreferenceChange(Preference preference, object newValue)
        {
            var stringValue = newValue.ToString();

            if (preference is ListPreference)
            {
                // For list preferences, look up the correct display value in
                // the preference's 'entries' list.
                ListPreference listPreference = (ListPreference)preference;
                int            index          = listPreference.FindIndexOfValue(stringValue);

                // Set the summary to reflect the new value.
                preference.Summary = index >= 0 ? listPreference.GetEntries()[index] : null;
            }
            else if (preference is RingtonePreference)
            {
                // For ringtone preferences, look up the correct display value
                // using RingtoneManager.
                if (TextUtils.IsEmpty(stringValue))
                {
                    // Empty values correspond to 'silent' (no ringtone).
                    preference.Summary = Application.Context.Resources.GetString(Resource.String.pref_group_ringtone_silent);
                }
                else
                {
                    Ringtone ringtone = RingtoneManager.GetRingtone(preference.Context, Android.Net.Uri.Parse(stringValue));

                    if (ringtone == null)
                    {
                        // Clear the summary if there was a lookup error.
                        preference.Summary = null;
                    }
                    else
                    {
                        // Set the summary to reflect the new ringtone display
                        // name.
                        preference.Summary = ringtone.GetTitle(preference.Context);
                    }
                }
            }
            else
            {
                // For all other preferences, set the summary to the value's
                // simple string representation.
                preference.Summary = stringValue;
            }
            return(true);
        }
Exemplo n.º 28
0
 public static void playAlarm()
 {
     try
     {
         var n     = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
         var last_ = getContextLast();
         if (last_ != null)
         {
             Ringtone r = RingtoneManager.GetRingtone(last_, n);
             r.Play();
         }
     }
     catch (Exception e)
     {
         setExceptionInner(e);
     }
 }
Exemplo n.º 29
0
        public void EndAction()
        {
            try
            {
                Vibrator.Cancel();
                Ringtone.Stop();
                Ringtone.Dispose();

                TimerHelper = false;
                ChangeButtonsVisibility();
                ChangeStepVisibility();
            }
            catch (Exception ex)
            {
                UserDialogs.Instance.Alert("Bład!\r\n\r\n" + ex.ToString(), "Błąd", "OK");
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// spielt den Ton mit der URI ab
        /// </summary>
        /// <param name="uri"></param>
        /// <param name="volume">0.0 .. 1.0</param>
        static void playNotifyRingtone(Android.Net.Uri uri, float volume = 1.0F)
        {
            stopNotifyRingtone();
            Ringtone rt = RingtoneManager.GetRingtone(appcontext, uri);

            if (rt != null)
            {
                rt.AudioAttributes = new AudioAttributes.Builder()
                                     .SetUsage(AudioUsageKind.Alarm)
                                     .SetContentType(AudioContentType.Music)
                                     .Build();
                rt.Looping = false;
                rt.Volume  = volume;
                rt.Play();
                alarmRingtone = rt;
            }
        }