Exemplo n.º 1
0
        public bool OnMenuItemClick(IMenuItem item)
        {
            switch (item.ItemId)
            {
            case (MENU_ITEM_DELETE):
                DAL dal = new DAL();
                dal.DeleteSchudle(adapter[item_long_pressed_index].Label);

                adapter.DetachSchudle(adapter[item_long_pressed_index].Label);
                DayOfWeek?      daytoSchudle = DateTime.Now.DayOfWeek;
                Schudle         nearest      = SchudlerManager.GetNearestSchudleData(out daytoSchudle);
                SchudlerManager schudler     = new SchudlerManager(this);
                schudler.Cancel();
                if (nearest != null)
                {
                    schudler.RegisterSchudle(nearest, (DayOfWeek)daytoSchudle);
                }

                break;

            case (MENU_ITEM_CREATE):
                Intent i = new Intent(this, typeof(SchudleDataActivity));
                StartActivity(i);
                break;
            }
            return(true);
        }
Exemplo n.º 2
0
        public override View GetView(int position, View convertView, ViewGroup
                                     parent)
        {
            //Get our object for this position
            var item = this.Schudles[position];
            //Try to reuse convertView if it’s not null, otherwise inflate it from
            //our item layout
            // This gives us some performance gains by not always inflating a new
            //view
            // This will sound familiar to MonoTouch developers with
            //UITableViewCell.DequeueReusableCell()
            var view = convertView;

            if (convertView == null || !(convertView is RelativeLayout))
            {
                view = context.LayoutInflater.Inflate(Resource.Layout.PartitionItemLayout,
                                                      parent, false);
            }
            //Find references to each subview in the list item’s view

            var text1 = view.FindViewById(Resource.Id.partitionLayout_textView1) as TextView;
            var text2 = view.FindViewById(Resource.Id.partitionLayout_textView2) as TextView;

            var tbutton = view.FindViewById(Resource.Id.partitionLayout_toggleButton1) as ToggleButton;

            //Assign this item’s values to the various subviews
            text2.Text             = item.Label;
            text1.Text             = item.Hour + ":" + item.Minute;
            tbutton.Checked        = item.Enabled;
            tbutton.CheckedChange += (object sender, CompoundButton.CheckedChangeEventArgs e) => {
                DAL dal     = new DAL();
                var schudle = this.Schudles[position];
                if (e.IsChecked)
                {
                    schudle.Enabled = true;
                    dal.UpdateSchudleState(item.Label, true);
                }
                else
                {
                    schudle.Enabled = false;
                    dal.UpdateSchudleState(item.Label, false);
                }
                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);
                }
            };
            //Finally return the view
            return(view);
        }
Exemplo n.º 3
0
        public override void OnReceive(Context context, Intent intent)
        {
            var prefs_model = Global.GetAppPreferences(context);

            if (prefs_model.Last_Call_State == Android.Telephony.CallState.Idle)
            {
                Intent callIntent = new Intent(Intent.ActionCall, Android.Net.Uri.Parse("tel:" + prefs_model.Schudled_Call_Number));
                callIntent.AddFlags(ActivityFlags.NewTask);
                context.StartActivity(callIntent);
                prefs_model.Schudled_Call        = false;
                prefs_model.Schudled_Call_Number = "";
            }
            else
            {
                SchudlerManager schudler = new SchudlerManager(context);
                schudler.RegisterSchudleCall();
            }
        }
Exemplo n.º 4
0
        public static Schudle GetNearestSchudleData(out DayOfWeek?dayToSchudle)
        {
            DAL dal          = new DAL();
            var schudlesList = dal.GetAllSchudles().Where(s => s.Enabled).ToList();

            if (schudlesList.Count == 0)
            {
                dayToSchudle = DateTime.Now.DayOfWeek;
                return(null);
            }
            else
            {
                DayOfWeek day    = DateTime.Now.DayOfWeek;
                int       hour   = DateTime.Now.Hour;
                int       minute = DateTime.Now.Minute;
                //Si existe un schudle en el mismo dia con hora posterior a la actual
                var today_schudles       = schudlesList.FindAll((s) => s.Days.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries).ToArray().Any((d) => d.ToDayOfWeakEnum() == day));
                var today_closer_schudle = today_schudles.Where(s => s.Hour > hour || (s.Hour == hour && s.Minute > minute)).OrderBy((s) => s.Hour).OrderBy((s) => s.Minute).ToList();
                if (today_closer_schudle != null && today_closer_schudle.Count > 0)
                {
                    dayToSchudle = DateTime.Now.DayOfWeek;
                    return(today_closer_schudle[0]);
                }
                //si hay un solo schudle
                if (schudlesList.Count == 1)
                {
                    dayToSchudle = NextDayInString(schudlesList[0].Days, DateTime.Now.DayOfWeek);
                    return(schudlesList [0]);
                }
                //si existe un schudle un dia despues del actual antes del fin de la semana
                String  day_to_right       = "";
                Schudle more_left_to_right = SchudlerManager.MoreLeftToTheRight(out day_to_right, schudlesList, DateTime.Now.DayOfWeek);
                if (day_to_right.ToDayOfWeakEnum() != DateTime.Now.DayOfWeek && day_to_right != "")
                {
                    dayToSchudle = (DayOfWeek)day_to_right.ToDayOfWeakEnum();
                    return(more_left_to_right);
                }
                //si existe un schudle un dia anterior del actual y ya se verifico q no hay ningun schudle en dia posterior se programa  para la proxima semana.
                String  day_to_left       = "";
                Schudle more_left_to_Left = SchudlerManager.MoreLeftToTheLeft(out day_to_left, schudlesList, DateTime.Now.DayOfWeek);
                dayToSchudle = day_to_left.ToDayOfWeakEnum();
                return(more_left_to_Left);
            }
        }
Exemplo n.º 5
0
        public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
        {
            base.OnStartCommand(intent, flags, startId);

            // For each start request, send a message to start a job and deliver the
            // start ID so we know which request we're stopping when we finish the job
            // If we get killed, after returning from here, restart

            notification_mngr = (NotificationManager)GetSystemService(Context.NotificationService);
            notification      = new Notification(Resource.Drawable.vigia_icon2, "Servicio de deteccion en ejecucion.");
            Intent notificationIntent = new Intent(this, typeof(MainActivity));

            //PendingIntent pendingIntent = PendingIntent.GetActivity(this, 0, notificationIntent, 0);
            notification_pendingIntent = PendingIntent.GetActivity(this, 0, notificationIntent, PendingIntentFlags.UpdateCurrent);
            notification.SetLatestEventInfo(this, "Servicio Iniciado", "Servicio de deteccion iniciado.Hora:" + DateTime.Now.ToShortTimeString(), notification_pendingIntent);
            StartForeground(NOTIFICATION_ID, notification);
            Init();
            SchudlerManager schudler = new SchudlerManager(this);

            schudler.RegisterNextSchudle();
            //speech_synt = new TextToSpeech (this, this);
            return(StartCommandResult.Sticky);
        }
Exemplo n.º 6
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" );
        }
Exemplo n.º 7
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;
            }
        }