Пример #1
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();
     }
 }
Пример #2
0
 static void stopNotifyRingtone()
 {
     if (alarmRingtone != null)
     {
         if (alarmRingtone.IsPlaying)
         {
             alarmRingtone.Stop();
         }
         alarmRingtone.Dispose();
         alarmRingtone = null;
     }
 }
 public void ReproducirAlerta()
 {
     if (RingTono2.IsPlaying)
     {
         RingTono2.Stop();
         RingTono2.Play();
     }
     else
     {
         RingTono2.Play();
     }
 }
 public void ReproducirAlertaError()
 {
     if (RingTono3.IsPlaying)
     {
         RingTono3.Stop();
         RingTono3.Play();
     }
     else
     {
         RingTono3.Play();
     }
 }
Пример #5
0
 public void StopExclusiveNativeSound()
 {
     if (exclusiveRingtone != null && exclusiveRingtone.IsPlaying)
     {
         exclusiveRingtone.Stop();
     }
     if (exclusiveRingtone != null)
     {
         exclusiveRingtone.Dispose();
     }
     exclusiveRingtone = null;
 }
Пример #6
0
 public void stopRingTone()
 {
     if (mRingtonePlayer != null)
     {
         lock (mRingtonePlayer)
         {
             if (--ringRef <= 0)
             {
                 mRingtonePlayer.Stop();
                 mRingtonePlayer = null;
             }
         }
     }
 }
Пример #7
0
        public void PlayRingtone(string uri)
        {
            RingtoneManager ringtoneManager = new RingtoneManager(context);

            Android.Net.Uri _uri = Android.Net.Uri.Parse(uri);

            AudioManager audioManager = (AudioManager)context.GetSystemService(Context.AudioService);

            audioManager.SetStreamVolume(Stream.Alarm, audioManager.GetStreamMaxVolume(Stream.Alarm), 0);

            if (ringtone != null)
            {
                if (ringtone.IsPlaying)
                {
                    ringtone.Stop();
                }
            }

            ringtone = ringtoneManager.GetRingtone(ringtoneManager.GetRingtonePosition(_uri));

            ringtone.StreamType = Stream.Alarm;

            ringtone.Play();
        }
Пример #8
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");
            }
        }
Пример #9
0
        private void Btn3_Click(object sender, EventArgs e)
        {
            Log.Info(TAG, "btn3 was clicked!");

            //using (r = RingtoneManager.GetRingtone(this, RingtoneManager.GetDefaultUri(RingtoneType.Ringtone)))
            //{ r.Play(); }

            if (r != null && r.IsPlaying)
            {
                r.Stop();
            }

            //r = RingtoneManager.GetRingtone(this, RingtoneManager.GetDefaultUri(RingtoneType.Ringtone));
            Android.Net.Uri uri = RingtoneManager.GetDefaultUri(RingtoneType.Ringtone);
            r = RingtoneManager.GetRingtone(this, uri);
            r.Play();

            Console.WriteLine("+++++ default ring attributes ==================== " + r.AudioAttributes);
            Console.WriteLine("+++++ default ring URI ==================== " + uri.Path);
        }
Пример #10
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            // Set our view from the "main" layout resource//设置界面来源
            SetContentView(Resource.Layout.activity_main);

            //打开UDP连接
            udp.UDP_Open(et.GetLocalIp(), 11067);

            //读取设置参数
            config.Open();
            GlobalData.v_min     = Convert.ToDouble(config.Read("Parameters/Calibration/V_min"));
            GlobalData.t_min     = Convert.ToDouble(config.Read("Parameters/Calibration/T_min"));
            GlobalData.v_max     = Convert.ToDouble(config.Read("Parameters/Calibration/V_max"));
            GlobalData.t_max     = Convert.ToDouble(config.Read("Parameters/Calibration/T_max"));
            GlobalData.warn_temp = Convert.ToDouble(config.Read("Parameters/Warn/Warn_Temp"));

            //初始化铃声
            Android.Net.Uri notification = RingtoneManager.GetDefaultUri(RingtoneType.Alarm);//使用闹钟声音
            Ringtone        r            = RingtoneManager.GetRingtone(this, notification);

            //关联控件
            TextView     view     = FindViewById <TextView>(Resource.Id.Receive);
            PlotView     plotview = FindViewById <PlotView>(Resource.Id.Chart_View);
            ToggleButton start    = FindViewById <ToggleButton>(Resource.Id.Start_Stop);
            ToggleButton connect  = FindViewById <ToggleButton>(Resource.Id.connect);
            Button       set      = FindViewById <Button>(Resource.Id.set);
            TextView     msg      = FindViewById <TextView>(Resource.Id.msg);
            Button       sleep    = FindViewById <Button>(Resource.Id.sleep);

            //设置
            set.Click += (e, t) =>
            {
                var intent = new Intent(this, typeof(SetActivity));
                //设置意图传递的参数
                //intent.PutStringArrayListExtra("phone_numbers", phoneNumbers);
                StartActivity(intent);
            };
            //休眠
            sleep.Click += (e, t) =>
            {
                try
                {
                    client.TCP_Write("slp");
                }
                catch
                {
                }
            };

            plotview.Model = CreatePlotModel();
            plotview.SetCursorType(CursorType.ZoomRectangle);

            new Thread(new ThreadStart(() =>
            {
                string data = "";
                bool run    = true;
                int state   = 0;

                DateTime time_start = DateTime.Now;
                var series          = plotview.Model.Series[0] as LineSeries;
                double y            = 0.0;
                string ESP_IP       = "";//ESP-32的IP
                while (run)
                {
                    switch (state)
                    {
                    case 0:                                             //获取服务器IP

                        udp.UDP_Write("app", "255.255.255.255", 11068); //向ESP广播数据
                        udp.UDP_Read(out ESP_IP);
                        if (ESP_IP != "")
                        {
                            RunOnUiThread(() => { msg.Text = "发现设备:" + ESP_IP; });
                            state = 1;
                        }
                        break;

                    case 1:    //尝试连接服务器
                        try
                        {
                            //RunOnUiThread(() => { start.Checked=false; });//取消自动停止采集,防止断线重连无法报警
                            RunOnUiThread(() => { connect.Checked = false; });

                            //client.TCP_Close_Client();
                            //client.TCP_Close_Stream();


                            client.TCP_Connect(ESP_IP, 11066, 11060);

                            RunOnUiThread(() => { msg.Text = "连接设备:" + ESP_IP; });
                            RunOnUiThread(() => { connect.Checked = true; });
                            state = 2;
                        }
                        catch
                        {
                            Thread.Sleep(500);
                        }
                        break;

                    case 2:    //读取数据
                        try
                        {
                            TimeSpan ts = DateTime.Now - time_start;
                            if (ts.TotalSeconds >= 3)    //每隔3秒查看一次
                            {
                                client.TCP_Write("app"); //发送数据验证服务器是否在线
                                time_start = DateTime.Now;
                            }
                        }
                        catch
                        {
                            RunOnUiThread(() => { msg.Text = "与服务器断开"; });
                            state = 0;    //通讯有错误重新连接服务器
                        }
                        try
                        {
                            data = client.TCP_Read(4, 10);    //10ms内接收4字节,字节内容为“XX.X”
                            if (data != "" && start.Checked)
                            {
                                y = Calibration(Convert.ToDouble(data), GlobalData.v_min, GlobalData.t_min, GlobalData.v_max, GlobalData.t_max);
                                RunOnUiThread(() => { view.Text = y.ToString("f1"); });    //文本显示温度值,一位小数点
                                try
                                {
                                    series.Points.Add(new DataPoint(DateTimeAxis.ToDouble(DateTime.Now), y));
                                    plotview.Model.InvalidatePlot(true);
                                }
                                catch
                                {
                                }
                                if (y >= GlobalData.warn_temp)
                                {
                                    try
                                    {
                                        var duration = TimeSpan.FromSeconds(0.5);
                                        Vibration.Vibrate(duration); //打开震动
                                        r.Play();                    //打开铃声
                                    }
                                    catch
                                    {
                                        // Feature not supported on device
                                    }
                                }
                                else
                                {
                                    try
                                    {
                                        Vibration.Cancel(); //关闭震动
                                        r.Stop();           //关闭铃声
                                    }
                                    catch
                                    {
                                        // Feature not supported on device
                                    }
                                }
                            }
                        }
                        catch
                        {
                            //RunOnUiThread(() => { msg.Text = e.Message; });
                        }
                        break;

                    default:
                        break;
                    }
                    Thread.Sleep(20);
                }
            })).Start();
        }
Пример #11
0
 public void StopAlarm()
 {
     _ringtone.Stop();
     IsAlarmGoingOf         = false;
     Settings.IsAlarmActive = false;
 }
Пример #12
0
 public void Stop()
 {
     ringtone.Stop();
 }
Пример #13
0
 void StopAlarm(object sender, System.EventArgs e)
 {
     r.Stop();
     btnCloseAlarm.Opacity = .5;
 }
Пример #14
0
 public void Stop()
 {
     ringTone.Stop();
     vibrator.Cancel();
 }
Пример #15
0
 public void StopSystemSound()
 {
     rt.Stop();
 }
        private void BtnAlarm_Off_Click(object sender, EventArgs e)
        {
            Toast.MakeText(this, $"Alarm OFF", ToastLength.Short).Show();

            ringer.Stop();
        }
Пример #17
0
 /// <inheritdoc />
 public void Stop() => mSound.Stop();
Пример #18
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            RequestWindowFeature(Android.Views.WindowFeatures.NoTitle);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);

            SetControlsRef();

            // set events
            addHour.Click           += (sender, e) => { millSeconds += 60 * 60 * 1000; lock (refreshLock) needRefresh = true; };
            addMinute.Click         += (sender, e) => { millSeconds += 60 * 1000; lock (refreshLock) needRefresh = true; };
            addSecond.Click         += (sender, e) => { millSeconds += 1000; lock (refreshLock) needRefresh = true; };
            addMillsecond.Click     += (sender, e) => { millSeconds += 1; lock (refreshLock) needRefresh = true; };
            addMillsecond.LongClick += (sender, e) => { millSeconds += 50; lock (refreshLock) needRefresh = true; };

            minusHour.Click           += (sender, e) => { millSeconds -= 60 * 60 * 1000; lock (refreshLock) needRefresh = true; };
            minusMinute.Click         += (sender, e) => { millSeconds -= 60 * 1000; lock (refreshLock) needRefresh = true; };
            minusSecond.Click         += (sender, e) => { millSeconds -= 1000; lock (refreshLock) needRefresh = true; };
            minusMillsecond.Click     += (sender, e) => { millSeconds -= 1; lock (refreshLock) needRefresh = true; };
            minusMillsecond.LongClick += (sender, e) => { millSeconds -= 50; lock (refreshLock) needRefresh = true; };

            //addHour.Touch += (sender, e) => SwitchPressAdd((Button)sender, e);
            //addMinute.Touch += (sender, e) => SwitchPressAdd((Button)sender, e);
            //addSecond.Touch += (sender, e) => SwitchPressAdd((Button)sender, e);
            //addMillsecond.Touch += (sender, e) => SwitchPressAdd((Button)sender, e);

            start.Click += (sender, e) =>
            {
                if (running)
                {
                    timeWalk.Suspend();
                    start.Background = Resources.GetDrawable(Resource.Drawable.StartButton);
                    pauseBegin       = System.DateTime.UtcNow.Ticks;
                    braking          = true;
                }
                else
                {
                    r       = RingtoneManager.GetRingtone(ApplicationContext, RingtoneManager.GetDefaultUri(RingtoneType.Ringtone));
                    braking = false;
                    if (timeWalk == null)
                    {
                        timeWalk   = new Thread(new ThreadStart(TimeWalk));
                        pauseTicks = 0;
                        timeWalk.Start();
                    }
                    else
                    {
                        pauseTicks += System.DateTime.UtcNow.Ticks - pauseBegin;
                        timeWalk.Resume();
                        braking = false;
                    }
                    start.Background = Resources.GetDrawable(Resource.Drawable.PauseButton);
                    clear.Background = Resources.GetDrawable(Resource.Drawable.StopButton);

                    SetAddMinusButtonEnable(false);
                }
                running = !running;
                RefreshTextView();
            };

            clear.Click += (sender, e) =>
            {
                clear.Enabled = false;
                try
                {
                    if (timeWalk != null && braking)
                    {
                        timeWalk.Resume();
                    }
                }
                catch (Exception) { }

                try
                {
                    if (timeWalk != null)
                    {
                        timeWalk.Abort();
                    }
                }
                catch (Exception) { }

                SetAddMinusButtonEnable(true);

                start.Enabled = true;
                if (r != null && r.IsPlaying)
                {
                    r.Stop();
                }
                running          = false;
                timeWalk         = null;
                millSeconds      = 0;
                start.Background = Resources.GetDrawable(Resource.Drawable.StartButton);
                clear.Background = Resources.GetDrawable(Resource.Drawable.ClearButton);
                milSecLock       = new object();
                lock (refreshLock) needRefresh = true;
                clear.Enabled = true;
            };

            timer           = new System.Timers.Timer(10);
            timer.Elapsed  += (source, e) => refreshTextHandler.Post(RefreshTextView);
            timer.AutoReset = true;
            timer.Enabled   = true;
        }