Beispiel #1
0
        private void LvDevices_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
        {
            //Toast.MakeText(this, "Button ON: " + listDevices[e.Position].deviceId + " clicked", ToastLength.Short).Show();
            var index = lvDevices.SelectedItemId;

            index = index + 1;
            Log.Info("LIST:", "INDEX= " + index);
            HttpWebRequestHandler HWRH = new HttpWebRequestHandler(this);

            HWRH.webRestHandler(index.ToString(), "deleting", "deleting", "deleting", "delete");
        }
 public void addDevice()
 {
     try
     {
         HttpWebRequestHandler HWRH = new HttpWebRequestHandler(context);
         HWRH.webRestHandler(dId, dName, null, dTimer, "add");
     }
     catch (Exception exception)
     {
         Console.WriteLine("ERROR WHEN ADDING DEVICE: " + exception);
         Toast.MakeText(context, "Error, something went wrong. try again...", ToastLength.Short).Show();
     }
 }
        public async Task <string> GetTemp()
        {
            string temp = "";

            try
            {
                HttpWebRequestHandler HWRH = new HttpWebRequestHandler(context);
                temp = await HWRH.webRestHandler(null, null, null, null, "temp");
            }
            catch (Exception ex)
            {
                Log.Error("GetTemp", "Error when trying to get temp: " + ex);
                Toast.MakeText(context, "Error, something went wrong. try again...", ToastLength.Short).Show();
            }
            return(temp);
        }
Beispiel #4
0
        private void BtnMarvinOff_Click(object sender, EventArgs e)
        {
            AlertDialog.Builder alert = new AlertDialog.Builder(this);

            alert.SetTitle("Are you sure?");
            alert.SetMessage("You are closing pc, are you sure?");
            alert.SetPositiveButton("OK", (senderAlert, args) =>
            {
                HttpWebRequestHandler HWRH = new HttpWebRequestHandler(this);
                HWRH.webRestHandler(null, null, null, null, "shutdown");
            });
            alert.SetNegativeButton("Cancel", (senderAlert, args) =>
            {
            });
            Dialog dialog = alert.Create();

            dialog.Show();
        }
Beispiel #5
0
        private void BtnLightsOn_Click(object sender, EventArgs e)
        {
            HttpWebRequestHandler HWRH = new HttpWebRequestHandler(this);

            HWRH.webRestHandler(null, null, null, null, "caselighton");
        }
Beispiel #6
0
        private void BtnMarvinOn_Click(object sender, EventArgs e)
        {
            HttpWebRequestHandler HWRH = new HttpWebRequestHandler(this);

            HWRH.webRestHandler(null, null, null, null, "start");
        }
        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            var view = convertView ?? activity.LayoutInflater.Inflate(Resource.Layout.devicelistview, parent, false);



            var deviceName  = view.FindViewById <TextView>(Resource.Id.tvdevicename);
            var deviceOn    = view.FindViewById <Button>(Resource.Id.btndeviceon);
            var deviceOff   = view.FindViewById <Button>(Resource.Id.btndeviceoff);
            var deviceTimer = view.FindViewById <Button>(Resource.Id.btndevicetimer);


            //GetDevices GD = new GetDevices();
            //List<devicesItem> deviceslist = new List<devicesItem>();

            //deviceslist = await GD.GetDeviceList();

            //deviceName.Text = "DeviceName";
            deviceName.Text  = devicelistArrayList[position].deviceName + " " + devicelistArrayList[position].deviceId;
            deviceOn.Text    = devicelistArrayList[position].deviceOn;
            deviceOff.Text   = devicelistArrayList[position].deviceOff;
            deviceTimer.Text = devicelistArrayList[position].timer.ToString();


            var localOn    = new LocalOnclickListener();
            var localOff   = new LocalOnclickListener();
            var localTimer = new LocalOnclickListener();


            localOn.HandleOnClick = () =>
            {
                HttpWebRequestHandler HWRH = new HttpWebRequestHandler(activity);
                int id = position + 1;
                //Toast.MakeText(this.activity, devicelistArrayList[position].Name + "DEVICEON id: " + position, ToastLength.Short).Show();
                HWRH.webRestHandler(id.ToString(), null, "on", devicelistArrayList[position].timer.ToString(), "control");
                Log.Info("ButtonOn: ", "Clicked");
            };



            localOff.HandleOnClick = () =>
            {
                HttpWebRequestHandler HWRH = new HttpWebRequestHandler(activity);
                int id = position + 1;
                //Toast.MakeText(this.activity, devicelistArrayList[position].Name + "DEVICEON id: " + position, ToastLength.Short).Show();
                HWRH.webRestHandler(id.ToString(), null, "off", "0", "control");
                Log.Info("ButtonOFF: ", "Clicked");
            };

            localTimer.HandleOnClick = () =>
            {
                //Toast.MakeText(this.activity, devicelistArrayList[position].Name + "DEVICETIMER id: " + position, ToastLength.Short).Show();
            };

            deviceOn.SetOnClickListener(localOn);
            deviceOff.SetOnClickListener(localOff);
            deviceTimer.SetOnClickListener(localTimer);
            deviceName.LongClick += delegate
            {
                AlertDialog.Builder alert = new AlertDialog.Builder(activity);
                alert.SetTitle("Remove device?");
                alert.SetMessage("Press OK if you really want delete device");
                alert.SetPositiveButton("OK", (senderAlert, args) =>
                {
                    HttpWebRequestHandler HWRH = new HttpWebRequestHandler(activity);
                    int id = position + 1;
                    HWRH.webRestHandler(id.ToString(), null, null, null, "delete");
                    Toast.MakeText(activity, "DELETING DEVICE... " + id.ToString(), ToastLength.Long).Show();
                    devicelistArrayList.RemoveAt(position);
                    //Recreate activity for refreshing listview
                    activity.Recreate();
                });

                alert.SetNegativeButton("Cancel", (senderAlert, args) =>
                {
                });

                Dialog dialog = alert.Create();
                dialog.Show();
            };



            //deviceOn.Click += delegate
            //{
            //    int deviceId = devicelistArrayList[position].id;
            //    string deviceName = devicelistArrayList[position].Name;

            //    //Toast.MakeText(this.activity,"DeviceOn id: "+ deviceId, ToastLength.Short).Show();

            //    if (deviceName == "kahvinkeitin " + deviceId)
            //    {
            //        Toast.MakeText(this.activity, "IF DeviceOn id: " + deviceId, ToastLength.Short).Show();
            //    }

            //};

            return(view);
        }
Beispiel #8
0
        private async void AddDevice_Click(object sender, EventArgs e)
        {
            //Toast.MakeText(this, "Add Button clikced", ToastLength.Short).Show();

            //devicesItem items = new devicesItem();

            if (dName.Text == "" || dTimer.Text.ToString() == "")
            {
                Toast.MakeText(this, "Name or Time is empty!?", ToastLength.Short).Show();
            }
            else
            {
                List <devicesItem> devlist;
                GetDevices         GD = new GetDevices();
                devlist = await GD.GetDeviceList();

                alert    = new AlertDialog.Builder(this);
                devName  = dName.Text;
                devTimer = dTimer.Text.ToString();
                int deviceId = devlist.Count;
                deviceId = deviceId + 1;
                alert.SetTitle("Redy to add device!");
                alert.SetMessage("Press OK when your device is ready to pairing");
                alert.SetPositiveButton("OK", async(senderAlert, args) =>
                {
                    //Console.WriteLine("Devlis count: " + devlist.Count());
                    List <int> devidslist = new List <int>();
                    try
                    {
                        //foreach (devicesItem items in devlist)
                        //{
                        //    Console.WriteLine("DEVLIST VALUES: " + items.deviceId.ToString());
                        //    if (devlist.Contains(items))
                        //    {
                        //        Log.Debug("LIST","ALREADY ON LIST: " + items.deviceName);
                        //    }
                        //    devidslist.Add(items.deviceId);
                        //    Log.Debug("AddDevice", "Devlist count: " + devidslist.Count);
                        //}
                        //int deviceId = devidslist.Count;

                        try
                        {
                            HttpWebRequestHandler HWRH = new HttpWebRequestHandler(this);
                            Console.WriteLine("TEXTINPUT: " + devName + devTimer);
                            await HWRH.webRestHandler(deviceId.ToString(), devName, null, devTimer, "add");
                            await Task.Delay(1000);
                            await HWRH.webRestHandler(deviceId.ToString(), devName, "on", "0", "control");
                        }
                        catch (Exception expection)
                        {
                            Console.WriteLine("ERROR WHEN ADDING DEVICE: " + expection);
                            Toast.MakeText(this, "Error! something went wrong, try again...", ToastLength.Short).Show();
                        }

                        //var main = new Intent(this, typeof(MainActivity));
                        //StartActivity(main);
                        Toast.MakeText(this, "Device " + devName.ToString() + " added!", ToastLength.Short).Show();
                        //this.Recreate();
                    }
                    catch (Exception expection)
                    {
                        Console.WriteLine("foreach error: " + expection);
                        Toast.MakeText(this, "Error! something went wrong, try again...", ToastLength.Short).Show();
                    }
                });

                Dialog dialog = alert.Create();
                dialog.Show();
            }
        }