コード例 #1
0
        private void rect_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            System.Windows.Shapes.Shape button = (System.Windows.Shapes.Shape)sender;
            DeviceButton DB = (DeviceButton)button.Tag;

            OnButtonClick(DB);
        }
コード例 #2
0
        public static void RunCommand()
        {
            IElectronicDevice newDevice = TVRemote.getDevice();

            TurnTVOn onCommand = new TurnTVOn(newDevice);

            DeviceButton onPressed = new DeviceButton(onCommand);

            onPressed.Press();

            // -------

            TurnTVOff offCommand = new TurnTVOff(newDevice);

            onPressed = new DeviceButton(offCommand);

            onPressed.Press();

            // -------

            TurnTVUp upCommand = new TurnTVUp(newDevice);

            onPressed = new DeviceButton(upCommand);

            onPressed.Press();
        }
コード例 #3
0
    // Update is called once per frame
    public void addButton(string name, string address)
    {
        GameObject   btn       = Instantiate(buttonPrefabs) as GameObject;
        DeviceButton handleBtn = btn.GetComponent <DeviceButton> ();

        handleBtn.name       = name;
        handleBtn.address    = address;
        btn.transform.parent = transform;
    }
コード例 #4
0
        public void TestTVOn()
        {
            Device       device  = new Television();
            Command      command = new On(device);
            DeviceButton button  = new DeviceButton(command);

            button.press();
            Assert.AreEqual(device.status, Status.on);
        }
コード例 #5
0
        public void OnButtonClick(DeviceButton DB)
        {
            ButtonEventHandler handler = ButtonClick;

            if (handler != null)
            {
                handler(this, new ButtonEventArgs(DB));
            }
        }
コード例 #6
0
ファイル: WdaDriver.cs プロジェクト: quamotion/malaga
 /// <summary>
 /// Presses a hardware (device) button.
 /// </summary>
 /// <param name="button">
 /// The button to press.
 /// </param>
 /// <param name="cancellationToken">
 /// A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation.
 /// </param>
 /// <returns>
 /// A <see cref="Task"/> which represents the asynchronous operation.
 /// </returns>
 public virtual void PressDeviceButton(DeviceButton button)
 {
     this.Execute(
         WdaDriverCommand.PressDeviceButton,
         new Dictionary <string, object>()
     {
         { "button", (int)button }
     });
 }
コード例 #7
0
        public void TestRadioOff()
        {
            Device       device  = new Radio();
            Command      command = new Off(device);
            DeviceButton button  = new DeviceButton(command);

            button.press();
            button.press();
            Assert.AreEqual(device.status, Status.off);
        }
コード例 #8
0
        public void TestVolumeDownRadio()
        {
            int expected = 4;

            Device       device  = new Radio();
            Command      command = new VolumeDown(device);
            DeviceButton button  = new DeviceButton(command);

            for (int i = 0; i < 6; i++)
            {
                button.press();
            }

            Assert.AreEqual(expected, device.volume);
        }
コード例 #9
0
            /// <summary>
            /// Gets the direction that belongs to one of the Sticks
            /// </summary>
            /// <returns>The Direction corresponding with the X and Y value</returns>
            public Direction GetDirection(DeviceButton stick)
            {
                DeviceState state = GetState();

                if (stick == DeviceButton.LeftStick)
                {
                    return(GetDirection(state.LeftThumbStick.X, state.LeftThumbStick.Y, X_CENTER_L, Y_CENTER_L));
                }
                else if (stick == DeviceButton.RightStick)
                {
                    return(GetDirection(state.RightThumbStick.X, state.RightThumbStick.Y, X_CENTER_R, Y_CENTER_R));
                }

                return(Direction.None);
            }
コード例 #10
0
        public void TestVolumeDownTV()
        {
            int expected = 5;

            Device       device  = new Television();
            Command      command = new VolumeDown(device);
            DeviceButton button  = new DeviceButton(command);

            for (int i = 0; i < 5; i++)
            {
                button.press();
            }

            Assert.AreEqual(expected, device.volume);
        }
コード例 #11
0
        public static void Main()
        {
            ICommand          command;
            IElectronicDevice device;
            DeviceButton      button;

            device = new Television();

            command = new TurnOn(device);
            button  = new DeviceButton(command);
            button.Press();

            command = new TurnOff(device);
            button  = new DeviceButton(command);
            button.Press();

            command = new TurnUp(device);
            button  = new DeviceButton(command);
            button.Press();
            button.Press();
            button.Press();

            command = new TurnDown(device);
            button  = new DeviceButton(command);
            button.Press();

            // -----------------------------------

            device = new Radio();

            command = new TurnOn(device);
            button  = new DeviceButton(command);
            button.Press();

            command = new TurnOff(device);
            button  = new DeviceButton(command);
            button.Press();

            command = new TurnUp(device);
            button  = new DeviceButton(command);
            button.Press();
            button.Press();
            button.Press();

            command = new TurnDown(device);
            button  = new DeviceButton(command);
            button.Press();
        }
コード例 #12
0
        //
        // Device tab page
        //
        public TabPage DevicesTab()
        {
            TabPage page = new TabPage("Device");

            page.AutoScroll = true;

            for (int DeviceID = 0; DeviceID < Bass.BASS_GetDeviceCount(); DeviceID++)
            {
                DeviceButton button = new DeviceButton(DeviceID);
                button.Parent = page;

                button.Dock = DockStyle.Top;
            }

            return(page);
        }
コード例 #13
0
    void Start()
    {
        Debug.Log("------------------Command Pattern--------------");
        IElectronicDevice device = TVRemove.GetDevice();

        TurnTVOn     onCommand = new TurnTVOn(device);
        DeviceButton onPressed = new DeviceButton(onCommand);

        onPressed.Press();

        // -----------------------

        TurnTVOff offCommand = new TurnTVOff(device);

        onPressed = new DeviceButton(offCommand);
        onPressed.Press();

        TurnVolumeUp volUpCommand = new TurnVolumeUp(device);

        onPressed = new DeviceButton(volUpCommand);
        onPressed.Press();
        onPressed.Press();
        onPressed.Press();

        TurnVolumeDown volDownCommand = new TurnVolumeDown(device);

        onPressed = new DeviceButton(volDownCommand);
        onPressed.Press();

        // -----------------------
        Television tv    = new Television();
        Radio      radio = new Radio();

        List <IElectronicDevice> allDevices = new List <IElectronicDevice>();

        allDevices.Add(tv);
        allDevices.Add(radio);

        TurnItAllOff turnOffDevices = new TurnItAllOff(allDevices);
        DeviceButton turnThemOff    = new DeviceButton(turnOffDevices);

        turnThemOff.Press();

        // -----------------------
        turnThemOff.PressUndo();
    }
コード例 #14
0
ファイル: Program.cs プロジェクト: vijiram29/command-pattern
        static void Main(string[] args)
        {
            // Instantiate a new television.
            Device television = new Television();

            // Create a new command to turn on the television.
            Command turnTelevisionOn = new TurnOn(television);

            // Create a new device button and set the command to
            // turn the television on.
            DeviceButton deviceButton = new DeviceButton(turnTelevisionOn);

            // Press the device button (in turn, executing the command).
            deviceButton.Press();

            // Make a new command to turn off the television, set
            // the command for the device button, and "press" it.
            Command turnTelevisionOff = new TurnOff(television);

            deviceButton.SetCommand(turnTelevisionOff);
            deviceButton.Press();

            Command turnTelevisionVolumeUp = new TurnVolumeUp(television);

            deviceButton.SetCommand(turnTelevisionVolumeUp);

            // Press the button multiple times, then "press" undo.
            deviceButton.Press();
            deviceButton.Press();
            deviceButton.Press();
            deviceButton.PressUndo();
            deviceButton.PressUndo();

            // Instantiate a radio!
            Device radio = new Radio();

            // Make a command to turn the radio off, since we can
            // just use Spotify.
            Command turnRadioOff = new TurnOff(radio);

            deviceButton.SetCommand(turnRadioOff);
            deviceButton.Press();

            Console.ReadKey();
        }
コード例 #15
0
        internal async Task AddDeviceContainer()
        {
            if (DeviceScroller != null)
            {
                return;
            }

            if (TreeScroller != null && PropertiesScroller != null)
            {
                await TreeScroller.parent.Remove(TreeScroller);

                await PropertiesScroller.parent.Remove(PropertiesScroller);

                TreeScroller       = null;
                PropertiesScroller = null;
            }

            DeviceScroller = await Row.Add(new ScrollView()
            {
                ShowVerticalScrollBars   = false,
                ShowHorizontalScrollBars = true
            }.Id("DeviceScroller").Background(color : "#111").Padding(10).Height(100.Percent()));

            await LoadDevice();

            if (PageTabs.Count > 0)
            {
                PageTabs[1]?.Margin(left: 0);
            }

            CloseButton?.X(570);
            DeviceTabs.ForEach(view => view.Visible = true);
            PageTabs.ForEach(view => view.Visible   = false);

            DevicePanel.HeaderButtons
            .AddRange(new List <View> {
                DeviceTabs[DeviceTabs.Count - 1], DeviceTabs[DeviceTabs.Count - 2], DeviceTabs[DeviceTabs.Count - 3]
            });

            await DevicePanel.Activate();

            PageButton?.Background(color: DeviceScroller == null ? SELECTED : "#444");
            DeviceButton?.Background(color: DeviceScroller != null ? SELECTED : "#444");
        }
コード例 #16
0
        private void ResizeDeviceButtons()
        {
            if (DeviceScreenShotImageBK.ActualWidth == 0)
            {
                return;
            }
            foreach (Shape s in mButtons)
            {
                DeviceButton DB = (DeviceButton)s.Tag;

                s.Width  = DB.Width / scaleFactor;
                s.Height = DB.Height / scaleFactor;

                double left = (DeviceScreenShotGrid.ActualWidth - DeviceScreenShotImageBK.ActualWidth) / 2 + DB.Left / scaleFactor;
                double top  = (DeviceScreenShotGrid.ActualHeight - DeviceScreenShotImageBK.ActualHeight) / 2 + DB.Top / scaleFactor;

                s.Margin = new Thickness(left, top, 0, 0);
            }
        }
コード例 #17
0
        public void TestUndo()
        {
            Device       device  = new Radio();
            Command      command = new On(device);
            DeviceButton button  = new DeviceButton(command);

            button.press();
            Assert.AreEqual(device.status, Status.on);
            button.pressUndo();
            Assert.AreEqual(device.status, Status.off);

            Command      c = new VolumeUp(device);
            DeviceButton b = new DeviceButton(c);

            b.press();
            Assert.AreEqual(11, device.volume);
            b.pressUndo();
            Assert.AreEqual(10, device.volume);
        }
        public static void FirstDemo()
        {
            IElectronicDevice newDevice = TvRemote.getDevice();
            TurnTvOn          onCommand = new TurnTvOn(newDevice);
            DeviceButton      onPressed = new DeviceButton(onCommand);

            onPressed.Press();
            TurnTvOff offcommand = new TurnTvOff(newDevice);

            onPressed = new DeviceButton(offcommand);
            onPressed.Press();


            TurnTvUp upcommand = new TurnTvUp(newDevice);

            onPressed = new DeviceButton(upcommand);
            onPressed.Press();
            onPressed.Press();
            onPressed.Press();
        }
コード例 #19
0
        internal async Task AddPageContainer()
        {
            if (TreeScroller != null)
            {
                return;
            }

            if (DeviceScroller != null)
            {
                await DeviceScroller.parent.Remove(DeviceScroller);

                DeviceScroller = null;
            }

            TreeScroller = await Row.Add(new ScrollView().Id("TreeScroller").Width(50.Percent())
                                         .Background(color: "#333"));

            new[] { TreeScroller, PropertiesScroller }
            .Do(x =>
            {
                x.ShowHorizontalScrollBars = x.ShowVerticalScrollBars = true;
                x.Padding(10).Height(100.Percent());
                x.ShowVerticalScrollBars = false;
            });

            await Row.WhenShown(() => Row.Add(PropertiesScroller));

            await CreateTreeView();

            if (PageTabs.Count > 0)
            {
                PageTabs[1]?.Margin(left: 320);
            }

            CloseButton?.X(570);
            PageTabs.ForEach(view => view.Visible   = true);
            DeviceTabs.ForEach(view => view.Visible = false);

            PageButton?.Background(color: DeviceScroller == null ? SELECTED : "#444");
            DeviceButton?.Background(color: DeviceScroller != null ? SELECTED : "#444");
        }
コード例 #20
0
ファイル: Program.cs プロジェクト: rgonzalezv/Design-Patterns
        static void Main(string[] args)
        {
            IElectronicDevice newDevice = TVRemote.GetDevice();

            ICommand     onCommand = new TurnTVOn(newDevice);
            DeviceButton onPressed = new DeviceButton(onCommand);

            onPressed.press();

            ICommand offCommand = new TurnTVOff(newDevice);

            onPressed = new DeviceButton(offCommand);
            onPressed.press();

            ICommand volUpCommand = new TurnTVUp(newDevice);

            onPressed = new DeviceButton(volUpCommand);
            onPressed.press();
            onPressed.press();
            onPressed.press();

            ICommand volDownCommand = new TurnTVDown(newDevice);

            onPressed = new DeviceButton(volDownCommand);
            onPressed.press();

            // ---------------------------------- //

            Television theTV    = new Television();
            Radio      theRadio = new Radio();

            List <IElectronicDevice> allDevices = new List <IElectronicDevice>();

            allDevices.Add(theTV);
            allDevices.Add(theRadio);

            TurnItAllOff turnOffDevices = new TurnItAllOff(allDevices);
            DeviceButton turnThemOff    = new DeviceButton(turnOffDevices);

            turnThemOff.press();
        }
コード例 #21
0
        private void DeviceViewPage_OnButtonClick(object sender, DeviceViewPage.ButtonEventArgs e)
        {
            Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;

            DeviceButton DB = e.DeviceButton;

            if (IsRecording)
            {
                ActDeviceButton act = new ActDeviceButton();
                act.Description = DB.SendCommand;
                act.Value       = DB.SendCommand;
                mAndroidADBDriver.BusinessFlow.AddAct(act);
            }


            if (DB.SendCommand.StartsWith("Press "))
            {
                string key = DB.SendCommand.Replace("Press ", "");
                mAndroidADBDriver.Press(key);
            }
            // Change to PressKeyCode
            else if (DB.SendCommand.StartsWith("PressKey "))
            {
                string key     = DB.SendCommand.Replace("PressKey ", "");
                int    KeyCode = int.Parse(key);
                mAndroidADBDriver.PressKeyCode(KeyCode);
            }
            else
            {
                //Remove from here and create special action
                // we assume it is shell command
                string result = mAndroidADBDriver.ExecuteShellCommand(DB.SendCommand);
            }

            Mouse.OverrideCursor = null;
        }
コード例 #22
0
        /// <summary>
        /// Helper method to configure a single DeviceButton and add it the configuration
        /// </summary>
        /// <param name="btn">The target DeviceButton</param>
        /// <param name="data">The ScriptSettings object which it needs to be saved too</param>
        /// <param name="input">InputManager object to handle input</param>
        /// <param name="guid">The GUID of the controller</param>
        private bool ConfigureDigitalDpadButton(DeviceButton btn, ScriptSettings data, DirectInputManager input, string guid)
        {
            while (input.GetDpadValue() == -1)
            {
                if (Game.IsKeyPressed(System.Windows.Forms.Keys.Escape))
                {
                    return(false);
                }
                UI.ShowSubtitle("Press and hold the " + GetBtnText(btn) + " button on the controller for 1 second. Press the Esc key to cancel.", 120);
                Script.Wait(100);
            }

            int dpadValue = input.GetDpadValue();

            UI.ShowSubtitle("Please hold the " + GetBtnText(btn) + " button to confirm it.");
            Script.Wait(1000);

            if (dpadValue == -1)
            {
                UI.ShowSubtitle("Now hold the " + GetBtnText(btn) + " button to confirm.");
                Script.Wait(1000);
                ConfigureDigitalDpadButton(btn, data, input, guid);
            }
            else
            {
                data.SetValue(guid, btn.ToString(), dpadValue);
                while (input.GetDpadValue() != -1)
                {
                    UI.ShowSubtitle("Now let go the button to configure the next one.");
                    Script.Wait(100);
                }
                Script.Wait(1000);
            }

            return(true);
        }
コード例 #23
0
 /// <summary>
 /// Checks if a single of the given DeviceButtons is pressed
 /// </summary>
 /// <param name="btn">The DeviceButton to check</param>
 /// <returns></returns>
 public bool isPressed(DeviceButton btn)
 {
     return(GetState().Buttons.Contains(btn));
 }
コード例 #24
0
 public ButtonEventArgs(DeviceButton db)
 {
     mDB = db;
 }
コード例 #25
0
 private void ControllerActionsGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
 {
     DeviceButton CA = (DeviceButton)ControllerActionsGrid.SelectedItem;
 }
コード例 #26
0
 /// <summary>
 /// Helper method which shows the DeviceButon in green text
 /// </summary>
 /// <param name="btn">The specific DeviceButton</param>
 /// <returns>"~g~'Start'~w~" for example</returns>
 private string GetBtnText(DeviceButton btn)
 {
     return("~g~'" + btn + "'~w~");
 }
コード例 #27
0
 public void ButtonIdSetting()
 {
     TriggerButton  = new DeviceButton(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger);
     GripButton     = new DeviceButton(Valve.VR.EVRButtonId.k_EButton_Grip);
     TouchpadButton = new TouchPadButton(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad);
 }
コード例 #28
0
ファイル: PlayWithRemote.cs プロジェクト: Kalle-kula/Patterns
        static void Main(string[] args)
        {
            // Gets the ElectronicDevice to use:
            IElectronicDevice newDevice = TvRemote.getDevice();

            // TurnTVOn contains the command to turn on the tv
            // When execute() is called on this command object
            // it will execute the method on() in Television:
            TurnTvOn onCommand = new TurnTvOn(newDevice);

            // Calling the execute() causes on() to execute in Television
            DeviceButton onPressed = new DeviceButton(onCommand);

            // When press() is called theCommand.execute(); executes
            onPressed.press();
            //----------------------------------------------------------

            // Now when execute() is called off() of Television executes
            TurnTvOff offCommand = new TurnTvOff(newDevice);

            // Calling the execute() causes off() to execute in Television
            onPressed = new DeviceButton(offCommand);

            // When press() is called theCommand.execute(); executes
            onPressed.press();
            //----------------------------------------------------------

            // Now when execute() is called volumeUp() of Television executes
            TvTurnUpp volUppCommand = new TvTurnUpp(newDevice);

            // Calling the execute() causes volumeUp() to execute in Television
            onPressed = new DeviceButton(volUppCommand);

            // When press() is called theCommand.execute(); executes
            onPressed.press();
            onPressed.press();
            onPressed.press();
            //----------------------------------------------------------

            // Creating a TV and Radio to turn off with 1 press
            Television theTv = new Television();
            Radio theRadio = new Radio();

            // Add the Electronic Devices to a List
            List<IElectronicDevice> allDevices = new List<IElectronicDevice>();

            allDevices.Add(theTv);
            allDevices.Add(theRadio);

            // Send the List of Electronic Devices to TurnItAllOff
            // where a call to run execute() on this function will
            // call off() for each device in the list
            TurnItAllOff turnOffDevices = new TurnItAllOff(allDevices);

            // This calls for execute() to run which calls for off() to
            // run for every ElectronicDevice
            DeviceButton turnThemOff = new DeviceButton(turnOffDevices);
            turnThemOff.press();
            //----------------------------------------------------------

            /*
             * It is common to be able to undo a command in a command pattern
             * To do so, DeviceButton will have a method called undo
             * Undo() will perform the opposite action that the normal
             * Command performs. undo() needs to be added to every class
             * with an execute()
             */
            turnThemOff.pressUndo();
            onPressed.pressUndo();
            // To undo more than one command add them to a LinkedList
            // using addFirst(). Then execute undo on each item until
            // there are none left. (This is your Homework)
            Console.ReadLine();
        }