Beispiel #1
0
        protected override void OnDoubleClick(EventArgs e)
        {
            base.OnDoubleClick(e);
            if (e is MouseEventArgs e2)
            {
                if (Program.mode == 1)
                {
                    if (NameLabelRectangle.Contains(e2.Location))
                    {
                        if (DeckUsb != null)
                        {
                            TextBox txtBox = new TextBox()
                            {
                                Bounds      = NameLabelRectangleWithoutPrefix,
                                Width       = Width - Padding.Right * 2,
                                Text        = DeckUsb.Model,
                                BorderStyle = BorderStyle.None,
                                BackColor   = BackColor,
                                ForeColor   = ForeColor,
                            };
                            txtBox.LostFocus += (s, ee) =>
                            {
                                if (txtBox.Text.Trim() != string.Empty)
                                {
                                    DeckUsb.Model = txtBox.Text.Trim();
                                    Refresh();
                                }
                                Controls.Remove(txtBox);
                            };
                            txtBox.KeyUp += (s, ee) =>
                            {
                                if (ee.KeyCode != Keys.Enter)
                                {
                                    return;
                                }
                                if (txtBox.Text.Trim() != string.Empty)
                                {
                                    DeckUsb.Model = txtBox.Text.Trim();
                                    Refresh();
                                }
                                Controls.Remove(txtBox);
                            };
                            Controls.Add(txtBox);
                            txtBox.Focus();
                        }
                    }
                    else
                    {
                        if (Tag is MainForm frm)
                        {
                            if (DevicePersistManager.IsDeviceTest)
                            {
                                Program.client.RemoveAllForwards(DeckUsb);
                                Program.client.CreateForward(DevicePersistManager.DeviceUsb, $"tcp:{ApplicationSettingsManager.Settings.PORT}", $"tcp:{ApplicationSettingsManager.Settings.PORT}", true);

                                Program.client.ExecuteRemoteCommand("am force-stop net.nickac.DisplayButtons", DeckUsb, null);
                                Thread.Sleep(1400);
                                Program.client.ExecuteRemoteCommand("am start -a android.intent.action.VIEW -e mode 1 net.nickac.DisplayButtons/.MainActivity", DeckUsb, null);
                                Thread.Sleep(1200);
                                Initilizator.ClientThread.Stop();
                                Initilizator.ClientThread = new Misc.ClientThread();
                                Initilizator.ClientThread.Start();
                                //   DevicePersistManager.PersistUsbMode(DeckUsb);
                                //       MainForm.Instance.StartLoad(true);
                                //   MainForm.Instance.Start_configs();
                            }
                            else
                            {
                                //  PersistUsbMode(DeckUsb);
                                Program.client.RemoveAllForwards(DeckUsb);
                                Program.client.CreateForward(DevicePersistManager.DeviceUsb, $"tcp:{ApplicationSettingsManager.Settings.PORT}", $"tcp:{ApplicationSettingsManager.Settings.PORT}", true);

                                Initilizator.ClientThread.Stop();
                                Initilizator.ClientThread = new Misc.ClientThread();
                                Initilizator.ClientThread.Start();
                            }
                        }
                    }
                }
                else
                {
                    if (DeckDevice != null)
                    {
                        if (NameLabelRectangle.Contains(e2.Location))
                        {
                            TextBox txtBox = new TextBox()
                            {
                                Bounds      = NameLabelRectangleWithoutPrefix,
                                Width       = Width - Padding.Right * 2,
                                Text        = DeckDevice.DeviceName,
                                BorderStyle = BorderStyle.None,
                                BackColor   = BackColor,
                                ForeColor   = ForeColor,
                            };
                            txtBox.LostFocus += (s, ee) =>
                            {
                                if (txtBox.Text.Trim() != string.Empty)
                                {
                                    DeckDevice.DeviceName = txtBox.Text.Trim();
                                    Refresh();
                                }
                                Controls.Remove(txtBox);
                            };
                            txtBox.KeyUp += (s, ee) =>
                            {
                                if (ee.KeyCode != Keys.Enter)
                                {
                                    return;
                                }
                                if (txtBox.Text.Trim() != string.Empty)
                                {
                                    DeckDevice.DeviceName = txtBox.Text.Trim();
                                    Refresh();
                                }
                                Controls.Remove(txtBox);
                            };
                            Controls.Add(txtBox);
                            txtBox.Focus();
                        }
                        else
                        {
                            if (Tag is MainForm frm)
                            {
                                if (DevicePersistManager.IsVirtualDeviceConnected)
                                {
                                    Debug.WriteLine("DEVICE MNANAWE 2");
                                    if (frm.CurrentDevice.DeviceGuid == DeckDevice.DeviceGuid)
                                    {
                                        //Someone clicked on the same device. Unload this one.
                                        DevicePersistManager.OnDeviceDisconnected(this, DeckDevice);
                                        DevicePersistManager.IsVirtualDeviceConnected = false;


                                        frm.ChangeButtonsVisibility(false);
                                        frm.CurrentDevice = null;
                                        frm.RefreshAllButtons(false);
                                        frm.Activate();
                                    }
                                    else
                                    {
                                        Debug.WriteLine("DEVICE MNANAWE 2");
                                        //Someone requested another device. Unload current virtual device..
                                        DevicePersistManager.OnDeviceDisconnected(this, frm.CurrentDevice);
                                        DevicePersistManager.IsVirtualDeviceConnected = false;
                                        frm.ChangeButtonsVisibility(false);
                                        frm.CurrentDevice = null;
                                        frm.RefreshAllButtons(false);
                                    }
                                }
                                else
                                {
                                    Debug.WriteLine("DEVICE MNANAWE 3");
                                    frm.CurrentDevice = DeckDevice;
                                    DevicePersistManager.IsVirtualDeviceConnected = true;
                                    DevicePersistManager.OnDeviceConnected(this, DeckDevice);
                                    frm.ChangeButtonsVisibility(true);
                                    frm.RefreshAllButtons(false);
                                    void tempConnected(object s, DevicePersistManager.DeviceEventArgs ee)
                                    {
                                        if (ee.Device.DeviceGuid == DeckDevice.DeviceGuid)
                                        {
                                            return;
                                        }
                                        DevicePersistManager.DeviceConnected -= tempConnected;
                                        if (DevicePersistManager.IsVirtualDeviceConnected)
                                        {
                                            //We had a virtual device.
                                            DevicePersistManager.OnDeviceDisconnected(this, DeckDevice);
                                            DevicePersistManager.IsVirtualDeviceConnected = false;
                                            frm.ChangeButtonsVisibility(false);
                                        }
                                    }

                                    DevicePersistManager.DeviceConnected += tempConnected;
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #2
0
        protected override void OnDoubleClick(EventArgs e)
        {
            base.OnDoubleClick(e);
            if (e is MouseEventArgs e2)
            {
                if (DeckDevice != null)
                {
                    if (NameLabelRectangle.Contains(e2.Location))
                    {
                        TextBox txtBox = new TextBox()
                        {
                            Bounds      = NameLabelRectangleWithoutPrefix,
                            Width       = Width - Padding.Right * 2,
                            Text        = DeckDevice.DeviceName,
                            BorderStyle = BorderStyle.None,
                            BackColor   = BackColor,
                            ForeColor   = ForeColor,
                        };
                        txtBox.LostFocus += (s, ee) => {
                            if (txtBox.Text.Trim() != string.Empty)
                            {
                                DeckDevice.DeviceName = txtBox.Text.Trim();
                                Refresh();
                            }
                            Controls.Remove(txtBox);
                        };
                        txtBox.KeyUp += (s, ee) => {
                            if (ee.KeyCode != Keys.Enter)
                            {
                                return;
                            }
                            if (txtBox.Text.Trim() != string.Empty)
                            {
                                DeckDevice.DeviceName = txtBox.Text.Trim();
                                Refresh();
                            }
                            Controls.Remove(txtBox);
                        };
                        Controls.Add(txtBox);
                        txtBox.Focus();
                    }
                    else
                    {
                        if (Tag is MainForm frm)
                        {
                            if (IsVirtualDeviceConnected)
                            {
                                if (frm.CurrentDevice.DeviceGuid == DeckDevice.DeviceGuid)
                                {
                                    //Someone clicked on the same device. Unload this one.
                                    OnDeviceDisconnected(this, DeckDevice);
                                    IsVirtualDeviceConnected = false;


                                    frm.ChangeButtonsVisibility(false);
                                    frm.CurrentDevice = null;
                                    frm.RefreshAllButtons(false);
                                    frm.Activate();
                                }
                                else
                                {
                                    //Someone requested another device. Unload current virtual device..
                                    OnDeviceDisconnected(this, frm.CurrentDevice);
                                    IsVirtualDeviceConnected = false;
                                    frm.ChangeButtonsVisibility(false);
                                    frm.CurrentDevice = null;
                                    frm.RefreshAllButtons(false);
                                }
                            }
                            else
                            {
                                frm.CurrentDevice        = DeckDevice;
                                IsVirtualDeviceConnected = true;
                                OnDeviceConnected(this, DeckDevice);
                                frm.ChangeButtonsVisibility(true);
                                frm.RefreshAllButtons(false);
                                void tempConnected(object s, DeviceEventArgs ee)
                                {
                                    if (ee.Device.DeviceGuid == DeckDevice.DeviceGuid)
                                    {
                                        return;
                                    }
                                    DeviceConnected -= tempConnected;
                                    if (IsVirtualDeviceConnected)
                                    {
                                        //We had a virtual device.
                                        OnDeviceDisconnected(this, DeckDevice);
                                        IsVirtualDeviceConnected = false;
                                        frm.ChangeButtonsVisibility(false);
                                    }
                                }

                                DeviceConnected += tempConnected;
                            }
                        }
                    }
                }
            }
        }