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)
        {
            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" );
        }