示例#1
0
        private static Schudle MoreLeftToTheRight(out String dayToSchudle, List <Schudle> schudlesList, DayOfWeek pivot)
        {
            Schudle nearest = null;

            dayToSchudle = "";
            if (schudlesList.Count > 1)
            {
                nearest = schudlesList [0];
                DayOfWeek dayToSchudleE = NextDayInString(nearest.Days, pivot);
                dayToSchudle = StringExtensions.ToDayOfWeakStringFromEnum(dayToSchudleE);
                for (int i = 1; i < schudlesList.Count; i++)
                {
                    string[]  days         = schudlesList [i].Days.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries).ToArray();
                    DayOfWeek?temp_nearest = NextDayInString(schudlesList[i].Days, pivot);
                    if ((temp_nearest < dayToSchudleE && temp_nearest > pivot) ||
                        (temp_nearest == dayToSchudleE && schudlesList [i].Hour <nearest.Hour && temp_nearest> pivot) ||
                        (temp_nearest == dayToSchudleE && schudlesList [i].Hour == nearest.Hour && schudlesList [i].Minute <nearest.Minute && temp_nearest> pivot))
                    {
                        dayToSchudleE = (DayOfWeek)temp_nearest;
                        dayToSchudle  = StringExtensions.ToDayOfWeakStringFromEnum(dayToSchudleE);
                        nearest       = schudlesList [i];
                    }
                }
            }

            return(nearest);
        }
示例#2
0
        public void RegisterSchudle(Schudle s, DayOfWeek dayofwaek)
        {
            AlarmManager  alarm_mngr = (AlarmManager)context.GetSystemService(Context.AlarmService);
            Intent        intent     = new Intent("DroidVigia.DroidVigia.DroidVigia.SchudledAlarm");
            PendingIntent pintent    = PendingIntent.GetBroadcast(context, 0, intent, PendingIntentFlags.OneShot);
            var           pref_model = Global.GetAppPreferences(context);

            pref_model.Next_Schudle_Name = s.Label;
            var schudled_time = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, s.Hour, s.Minute, 0);
            int diff_days     = 0;

            if (dayofwaek > DateTime.Now.DayOfWeek)
            {
                diff_days = dayofwaek - DateTime.Now.DayOfWeek;
            }
            if (dayofwaek < DateTime.Now.DayOfWeek)
            {
                diff_days = (DayOfWeek.Saturday - DateTime.Now.DayOfWeek) + ((int)dayofwaek + 1);
            }
            schudled_time = schudled_time.AddDays(diff_days);
            long millis = (long)(schudled_time - DateTime.Now).TotalMilliseconds;

            //Calendar future= Calendar.GetInstance(Java.Util.TimeZone.Default);
            //future.Add(Java.Util.CalendarField.Millisecond, (int)millis);
            alarm_mngr.Set(AlarmType.ElapsedRealtimeWakeup, SystemClock.ElapsedRealtime() + millis, pintent);
        }
示例#3
0
        public Schudle GetSchudleByName(string name)
        {
            Schudle s = null;

            try{
                connection.Open();
                using (var c = connection.CreateCommand()) {
                    c.CommandText = "Select * from Schudle where Label=@Label";
                    c.Parameters.AddWithValue("@Label", name);
                    c.CommandType = CommandType.Text;
                    SqliteDataReader reader = c.ExecuteReader();
                    while (reader.Read())
                    {
                        s = MapSchudleFromReader(reader);
                    }
                }
            }
            catch (Exception e) {
                ;
            }
            finally{
                connection.Close();
            }
            return(s);
        }
示例#4
0
        public List <Schudle> GetAllSchudles()
        {
            List <Schudle> result = new List <Schudle>();

            try{
                connection.Open();
                using (var c = connection.CreateCommand()) {
                    c.CommandText = "Select * from Schudle";
                    c.CommandType = CommandType.Text;
                    SqliteDataReader reader = c.ExecuteReader();

                    while (reader.Read())
                    {
                        Schudle s = MapSchudleFromReader(reader);
                        result.Add(s);
                    }
                }
            }
            catch (Exception e) {
                ;
            }
            finally{
                connection.Close();
            }
            return(result);
        }
示例#5
0
        public int NewSchudle(Schudle s)
        {
            int res = -1;

            try{
                connection.Open();
                using (var c = connection.CreateCommand()) {
                    c.CommandText = "Insert into Schudle(Label,Hour,Minute,Days,PartitionNames,ActionId,Enabled) values(@Label,@Hour,@Minute,@Days,@PartitionNames,@ActionId,@Enabled)";
                    c.CommandType = CommandType.Text;
                    c.Parameters.AddWithValue("@Label", s.Label);
                    c.Parameters.AddWithValue("@PartitionNames", s.PartitionNames);
                    c.Parameters.AddWithValue("@Hour", s.Hour);
                    //c.Parameters.AddWithValue("@Minute",s.Minute);
                    var param = new SqliteParameter();
                    param.DbType        = DbType.Int16;
                    param.ParameterName = "@Minute";
                    param.Value         = s.Minute;
                    c.Parameters.Add(param);
                    c.Parameters.AddWithValue("@Days", s.Days);
                    c.Parameters.AddWithValue("@Enabled", s.Enabled);
                    c.Parameters.AddWithValue("@ActionId", s.ActionId);
                    res = c.ExecuteNonQuery();
                }
            }
            catch (Exception) {}
            finally{
                connection.Close();
            }
            return(res);
        }
示例#6
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);
        }
示例#7
0
        public void RegisterNextSchudle()
        {
            DayOfWeek?daytoSchudle = DateTime.Now.DayOfWeek;
            Schudle   nearest      = GetNearestSchudleData(out daytoSchudle);

            if (nearest != null)
            {
                Cancel();
                RegisterSchudle(nearest, (DayOfWeek)daytoSchudle);
            }
        }
示例#8
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);
            }
        }
示例#9
0
        Schudle MapSchudleFromReader(IDataReader reader, bool use_Subfix = false)
        {
            string s_Label          = (use_Subfix?"s_Label":"Label");
            string s_Hour           = (use_Subfix?"s_Hour":"Hour");
            string s_Minute         = (use_Subfix?"s_Minute":"Minute");
            string s_Days           = (use_Subfix?"s_Days":"Days");
            string s_PartitionNames = (use_Subfix?"s_PartitionNames":"PartitionNames");
            string s_Enabled        = (use_Subfix?"p_Enabled":"Enabled");
            string s_ActionId       = (use_Subfix?"p_ActionId":"ActionId");


            Schudle s = new Schudle();

            s.Label          = reader [s_Label].ToString();
            s.PartitionNames = Convert.ToString(reader [s_PartitionNames]);
            s.Days           = Convert.ToString(reader [s_Days]);
            s.Enabled        = Convert.ToBoolean(reader [s_Enabled]);
            s.Hour           = Convert.ToInt32(reader [s_Hour]);
            s.Minute         = Convert.ToInt32(reader [s_Minute]);
            s.ActionId       = Convert.ToInt32(reader [s_ActionId]);
            return(s);
        }
示例#10
0
        private void OnAceptar(object sender, EventArgs e)
        {
            s = new Schudle();
            var tb_Etiqueta     = FindViewById <EditText> (Resource.Id.tb_Schudle_Label);
            var tp_time         = FindViewById <TimePicker> (Resource.Id.tp_shudle_time);
            var rb_armar_alarma = FindViewById <RadioButton> (Resource.Id.rb_AlarmReady);

            s.Label          = tb_Etiqueta.Text;
            s.PartitionNames = PartitionsStringFromList();
            s.Days           = DaysStringFromList();
            s.Hour           = (int)tp_time.CurrentHour;
            s.Minute         = (int)tp_time.CurrentMinute;
            s.ActionId       = rb_armar_alarma.Checked ? Action.ACTION_ID_ACTIVATED : Action.ACTION_ID_DESACTIVATED;
            if (s.Label != "" && s.Days != "" && s.PartitionNames != "")
            {
                DAL dal = new DAL();
                dal.NewSchudle(s);
                Toast.MakeText(this, "Tarea Creada", ToastLength.Short);
                //this.MoveTaskToBack (true);
                this.OnBackPressed();
            }
        }
示例#11
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" );
        }
示例#12
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.NewSchudleLayout);
            schudle_label = this.Intent.GetStringExtra(SCHUDLE_ID_EXTRA);

            var tp_time = FindViewById <TimePicker> (Resource.Id.tp_shudle_time);

            tp_time.SetIs24HourView(Java.Lang.Boolean.True);

            DAL dal = new DAL();

            if (schudle_label != "" && schudle_label != null)
            {
                var bt_aceptar = FindViewById <Button> (Resource.Id.bt_NewSchudle);
                bt_aceptar.Enabled = false;
                s                   = dal.GetSchudleByName(schudle_label);
                Partitions          = s.PartitionNames.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries).ToList();
                selected_partitions = new bool[Partitions.Count()];
                var list_particiones = dal.GetAllPartitions();
                list_particiones.ForEach(p => {
                    if (s.PartitionNames.Contains(p.Name))
                    {
                        selected_partitions[Partitions.IndexOf(p.Name)] = true;
                    }
                });
                selected_days = new bool[days.Count()];
                days.ToList().ForEach(d => {
                    if (s.Days.Contains(d))
                    {
                        selected_days[days.ToList().IndexOf(d)] = true;
                    }
                });
                var rb_armar_alarma    = FindViewById <RadioButton> (Resource.Id.rb_AlarmReady);
                var rb_desarmar_alarma = FindViewById <RadioButton> (Resource.Id.rb_AlarmNotReady);

                if (s.ActionId == Action.ACTION_ID_ACTIVATED)
                {
                    rb_armar_alarma.Checked = true;
                }
                else
                {
                    rb_desarmar_alarma.Checked = true;
                }

                tp_time.CurrentHour   = new Java.Lang.Integer(s.Hour);
                tp_time.CurrentMinute = new Java.Lang.Integer(s.Minute);

                var tb_Etiqueta = FindViewById <EditText> (Resource.Id.tb_Schudle_Label);
                tb_Etiqueta.Text = s.Label;
            }
            else
            {
                Partitions            = dal.GetAllPartitions().Select(p => p.Name).ToList();
                selected_partitions   = Partitions.Select(p => false).ToArray();
                selected_days         = days.Select(p => false).ToArray();
                tp_time.CurrentHour   = new Java.Lang.Integer(0);
                tp_time.CurrentMinute = new Java.Lang.Integer(0);
            }

            // Create your application here
        }