Esempio n. 1
0
        public override void OnReceive(Context context, Intent intent)
        {
            DAL    dal        = new DAL();
            var    pref_model = Global.GetAppPreferences(context);
            string label      = pref_model.Next_Schudle_Name;

            if (label != START_SERVICE_SCHUDLE)
            {
                var schudle         = dal.GetSchudleByName(label);
                var partitions_name = schudle.PartitionNames.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries).ToList();
                var partitions      = new List <Partition> ();
                partitions_name.ForEach(pn => { partitions.Add(dal.GetPartitionByName(pn)); });

                if (schudle.ActionId == Action.ACTION_ID_ACTIVATED)
                {
                    partitions.ForEach(p => {
                        dal.UpdatePartitionState(p.Id, true);
                        string message = "Tarea Programada:" + label;
                        var h          = new HistoryItem {
                            Time = DateTime.Now, State = Action.ACTION_ID_ACTIVATED, PartitionName = p.Name, Detail = message
                        };
                        dal.RegiterEvent(h);
                    });
                }
                else
                {
                    partitions.ForEach(p => {
                        dal.UpdatePartitionState(p.Id, false);
                        string message = "Tarea Programada:" + label;
                        var h          = new HistoryItem {
                            Time = DateTime.Now, State = Action.ACTION_ID_DESACTIVATED, PartitionName = p.Name, Detail = message
                        };
                        dal.RegiterEvent(h);
                    });
                }
                partitions = dal.GetAllPartitions();
                bool is_pactivated = partitions.Find((part) => part.Activated) != null;
                if (!is_pactivated)
                {
                    pref_model.Ready = false;
                }
                else if (!pref_model.Ready && is_pactivated)
                {
                    pref_model.Ready = true;
                }

                NotificationManager n_mngr = (NotificationManager)context.GetSystemService(Service.NotificationService);
                Notification        n      = new Notification(Resource.Drawable.Icon, "", DateTime.UtcNow.Millisecond);
                Intent notificationIntent  = new Intent(context, typeof(MainActivity));
                //PendingIntent pendingIntent = PendingIntent.GetActivity(this, 0, notificationIntent, 0);
                n.Defaults |= NotificationDefaults.All;
                n.Flags    |= NotificationFlags.OnlyAlertOnce;
                n.SetLatestEventInfo(context, "Tarea Planificada", "Nombre: " + schudle.Label, null);
                n_mngr.Notify(ALARM_NOTIFICATION_ID, n);

                DayOfWeek?      daytoSchudle = DateTime.Now.DayOfWeek;
                Schudle         nearest      = SchudlerManager.GetNearestSchudleData(out daytoSchudle);
                SchudlerManager schudler     = new SchudlerManager(context);
                schudler.Cancel();
                if (nearest != null)
                {
                    schudler.RegisterSchudle(nearest, (DayOfWeek)daytoSchudle);
                }
            }
            PowerManager pwr_mngr = (PowerManager)context.GetSystemService(Context.PowerService);

            PowerManager.WakeLock w = pwr_mngr.NewWakeLock(WakeLockFlags.Full, "Schudle");
            w.Acquire(5000);
            Intent i = new Intent(context, typeof(DetectorService));

            context.StartService(i);
            //Intent i = new Intent (context, typeof(MainActivity));
            //context.StartActivity (i);
            //context.StopService (i);
            //context.StartService(i);

            //PowerManager pwr_mngr =(PowerManager) context.GetSystemService (Context.PowerService);
            //pwr_mngr.NewWakeLock (WakeLockFlags.Full, "Schudle" );
        }
Esempio n. 2
0
        public override void OnCallStateChanged(CallState state, String incomingNumber)
        {
            //Device call state: Ringing. A new call arrived and is ringing or waiting. In the latter case, another call is already active.

            PreferencesModel prefmodel = Global.GetAppPreferences(context);
            DAL dal = new DAL();

            if (state == CallState.Ringing)
            {
                if (prefmodel.Last_Call_State == CallState.Idle &&
                    (prefmodel.numbers.Contains(incomingNumber.CleanNumber())))
                {
                    var h = new HistoryItem {
                        Time          = DateTime.Now,
                        State         = Action.ACTION_ID_INCOMING_CALL,
                        PartitionName = "",
                        Detail        = "LLAMADA ENTRANTE:" + incomingNumber
                    };
                    dal.RegiterEvent(h);
                    prefmodel.Ready = !prefmodel.Ready;
                    if (prefmodel.Ready)
                    {
                        prefmodel.Schudled_Call        = true;
                        prefmodel.Schudled_Call_Number = incomingNumber;
                        dal.ActivateAllPartitions();
                    }
                    else
                    {
                        dal.DesactivateAllPartitions();
                    }

                    SchudlerManager s_mngr = new SchudlerManager(context);
                    s_mngr.RegisterRestartServiceSchudle();

                    Intent i = new Intent(context, typeof(DetectorService));
                    if (Binder != null)
                    {
                        var service = Binder.GetService();
                        service.ForceStop();
                    }
                }
                //if (Binder != null)
                //{
                //    var service = Binder.GetService();
                //    service.Stop();
                //}
                prefmodel.Last_Call_State = state;
            }
            //Device call state: Off-hook. At least one call exists that is dialing, active, or on hold, and no calls are ringing or waiting.
            if (state == CallState.Offhook)
            {
                prefmodel.Last_Call_State = state;
                //if (Binder != null)
                //{
                //    var service = Binder.GetService();
                //    service.Stop();
                //}
            }
            //Device call state: No activity.
            if (state == CallState.Idle)
            {
                if (prefmodel.Last_Call_State == CallState.Offhook)
                {
                    //Intent i = new Intent (context, typeof(DetectorService));
                    //context.StopService (i);
                    //context.StartService(i);
                    //if(Binder!=null){
                    //	var service= Binder.GetService ();
                    //	service.Start();
                    //}
                }
                prefmodel.Last_Call_State = state;
            }
        }
Esempio n. 3
0
 void UpdateHistory(HistoryItem item)
 {
     RunOnUiThread(() => {
         history_adapter.AddHistoryData(item);
     });
 }
Esempio n. 4
0
        private void OnNewToken(object sender, DTMFTokenBuildedEventArgs edt)
        {
            lock (sync_object)
            {
                DAL dal = new DAL();
                List <Partition> particiones = dal.GetAllPartitions();
                if (edt.Token == prefs_model.Pin)
                {
                    prefs_model.Ready = !prefs_model.Ready;

                    if (prefs_model.Ready)
                    {
                        /*if(speech_engine_inited)
                         *                                              speech_synt.Speak("Alarma activada",QueueMode.Flush,null);*/
                        particiones.ForEach((p) => dal.UpdatePartitionState(p.Id, true));
                        NotifyEvent("Alarma Activada", "Todas las particiones activadas");
                        var h = new HistoryItem
                        {
                            Time          = DateTime.Now,
                            State         = Action.ACTION_ID_ACTIVATED,
                            PartitionName = "TODAS",
                            Detail        = "TODAS LAS PARTICIONES ACTIVADAS"
                        };
                        dal.RegiterEvent(h);
                        NotifyNewEvent(h);
                        //Ready=true;
                    }
                    else
                    {
                        /*if(speech_engine_inited)
                         *                                              speech_synt.Speak("Alarma desactivada",QueueMode.Flush,null);*/
                        particiones.ForEach((p) => dal.UpdatePartitionState(p.Id, false));
                        NotifyEvent("Alarma Desactivada", "Todas las particiones desactivadas");
                        var h = new HistoryItem
                        {
                            Time          = DateTime.Now,
                            State         = Action.ACTION_ID_DESACTIVATED,
                            PartitionName = "TODAS",
                            Detail        = "TODAS LAS PARTICIONES DESACTIVADAS"
                        };
                        dal.RegiterEvent(h);
                        NotifyNewEvent(h);
                    }
                }
                else
                {
                    var p = particiones.Find((part) => part.Code == edt.Token);
                    if (p != null)
                    {
                        string detail = "";
                        p.Zones = dal.GetPartitionsZones(p.Id);
                        if (p.Activated)
                        {
                            detail = "Particion Desactivada:" + "Particion " + p.Name + " Desactivada";
                            NotifyEvent("Particion Desactivada", "Particion " + p.Name + " Desactivada");
                            var h = new HistoryItem {
                                Time = DateTime.Now, State = Action.ACTION_ID_DESACTIVATED, PartitionName = p.Name, Detail = detail
                            };
                            dal.RegiterEvent(h);
                            NotifyNewEvent(h);
                            p.Activated = false;
                            dal.UpdatePartitionState(p.Id, false);
                            if (particiones.Find((part) => part.Activated) == null)
                            {
                                prefs_model.Ready = false;
                            }
                        }
                        else
                        {
                            detail = "Particion Activada:" + "Particion " + p.Name + " Activada";
                            NotifyEvent("Particion Activada", "Particion " + p.Name + " Activada");
                            p.Activated = true;
                            dal.UpdatePartitionState(p.Id, false);
                            var h = new HistoryItem {
                                Time = DateTime.Now, State = Action.ACTION_ID_ACTIVATED, PartitionName = p.Name, Detail = detail
                            };
                            dal.RegiterEvent(h);
                            NotifyNewEvent(h);
                            prefs_model.Ready = false;
                        }
                    }
                    else
                    {
                        var z = (edt.Token.All(cp => cp == edt.Token[0])) ? dal.GetZoneByCode(edt.Token[0].ToString()) : null;
                        if (z != null)
                        {
                            p = particiones.Find((part) => part.Id == z.PartitionId);
                            if (!z.Fired && p.Activated)
                            {
                                if ((DateTime.Now - p.ChangeStateTime) >= new TimeSpan(0, 0, prefs_model.Time_To_GO))
                                {
                                    var due_time = (z.Inmediate ? 0 : prefs_model.Time_To_IN * 1000);
                                    var timer    = new System.Threading.Timer((o) => {
                                        Partition particion = o as Partition;
                                        var zone            = particion.Zones[0];

                                        particion = dal.GetPartitionByName(p.Name);
                                        if (particion.Activated)
                                        {
                                            prefs_model.Fired = true;
                                            zone.Fired        = true;
                                            dal.UpdateZoneState(zone.Id, true);
                                            string message = "Sensor: " + z.Name + ".Partición: " + particion.Name + ".Hora:" + DateTime.Now.ToShortTimeString();
                                            var h          = new HistoryItem {
                                                Time = DateTime.Now, State = Action.ACTION_ID_FIRED, PartitionName = particion.Name, Detail = message
                                            };
                                            dal.RegiterEvent(h);
                                            NotifyNewEvent(h);
                                            Intent intent = new Intent("DroidVigia.DroidVigia.DroidVigia.ToneDetected");
                                            intent.PutExtra("message", message);
                                            SendBroadcast(intent);
                                            if (!Notificando)
                                            {
                                                Notificando = true;
                                            }
                                        }
                                    }, new Partition {
                                        Id = p.Id, Name = p.Name, Activated = p.Activated, ChangeStateTime = p.ChangeStateTime, Zones = new List <Zone> {
                                            z
                                        }
                                    }, due_time, -1);
                                }
                            }
                        }
                    }
                }
            }
            if (NewToken != null)
            {
                try
                {
                    NewToken.BeginInvoke(null, edt, null, null);
                }
                catch { }
            }
        }
Esempio n. 5
0
 public ActionRegisteredEventArgs(HistoryItem new_action)
 {
     NewData = new_action;
 }