コード例 #1
0
        /// <summary>
        /// Defines the action when tapped on a cell. It displays activators in a pop up
        /// or goes to the edit device screen when in editing mode.
        /// </summary>
        public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
        {
            if (!tableView.Editing)
            {
                var device = GetSectionRow(indexPath);
                if (device.Activators.Count != 0)
                {
                    // Create the contents of the pop up window, which is a list of activators.
                    var popupNavVC = new UITableViewActivators();
                    popupNavVC.Title  = device.Name;
                    popupNavVC.device = device;

                    var navigationController = new UINavigationController(popupNavVC);
                    navigationController.ModalPresentationStyle = UIModalPresentationStyle.Popover;
                    navigationController.PreferredContentSize   = new CoreGraphics.CGSize(tableView.Window.Screen.Bounds.Width, tableView.RowHeight * device.Activators.Count);

                    // Define the layout of the pop up
                    nfloat heightPop    = 20 + navigationController.NavigationBar.Frame.Size.Height;
                    var    popPresenter = navigationController.PopoverPresentationController;
                    popPresenter.SourceView = owner.View;
                    popPresenter.SourceRect = new CoreGraphics.CGRect(0, tableView.Window.Screen.Bounds.Height / 2 - heightPop, 0, 0);
                    popPresenter.Delegate   = new PopoverDelegate();
                    popPresenter.PermittedArrowDirections = 0;
                    popPresenter.BackgroundColor          = UIColor.White;
                    // Show the pop up
                    owner.PresentViewController(navigationController, true, null);
                }
            }
            // Go to edit name window for non-insert cells
            else
            {
                UIViewControllerEditDeviceName editViewController = new UIViewControllerEditDeviceName(this.owner);
                editViewController.device = GetSectionRow(indexPath);
                owner.NavigationController.PushViewController(editViewController, true);
            }
            tableView.DeselectRow(indexPath, true);
        }
コード例 #2
0
        /// <summary>
        /// This method processes the speech recognition result.
        /// It can perform five actions: turning on a device, turning off a device, adding a new device, editing a device and removing a device.
        /// </summary>
        /// <param name="result"></param>
        public void ProcessSpeech(string result)
        {
            Device device;

            if (result == null)
            {   // Something went wrong with recognizing speech
                WarningMessage.Display(strings.speechError, strings.tryAgain, this);
            }
            else
            {
                result = result.ToLower();
                if (result.Contains("activate") || (result.Contains("turn") && result.Contains("on")))
                {   // Turning on a device
                    device = GetDevice(result);
                    if (device != null)
                    {
                        SetDevice(device, true);
                    }
                }
                else if (result.Contains("deactivate") || (result.Contains("turn") && result.Contains("off")))
                {   // Turning off a device
                    device = GetDevice(result);
                    if (device != null)
                    {
                        SetDevice(device, false);
                    }
                    else
                    {
                        WarningMessage.Display(strings.noDeviceFound, strings.pronounceDeviceNameCorrectly, this);
                    }
                }
                else if (result.Contains("add device") || (result.Contains("new device")))
                {   // Adding a new device
                    ((TableSourceDevicesMain)DevicesTable.Source).InsertAction();
                }
                else if (result.Contains("edit"))
                {   // Editing a device
                    device = GetDevice(result);
                    if (device != null)
                    {
                        UIViewControllerEditDeviceName editViewController = new UIViewControllerEditDeviceName(this);
                        editViewController.device = device;
                        NavigationController.PushViewController(editViewController, true);
                    }
                    else
                    {
                        WarningMessage.Display(strings.noDeviceFound, strings.pronounceDeviceNameCorrectly, this);
                    }
                }
                else if (result.Contains("remove") || result.Contains("delete"))
                {   // Removing a device
                    device = GetDevice(result);
                    if (device != null)
                    {
                        // Loop over devices until device is found
                        for (int section = 0; section < ((TableSourceDevicesMain)DevicesTable.Source).serverDevices.Count; section++)
                        {
                            var devices = ((TableSourceDevicesMain)DevicesTable.Source).serverDevices[section];
                            for (int row = 0; row < devices.Count; row++)
                            {
                                if (device.DeviceId.Equals(devices[row].DeviceId))
                                {
                                    if (Globals.LocalLogin)
                                    {
                                        try
                                        {   // Remove device from server
                                            Globals.LocalServerinteractor.RemoveDevice(devices[row]);
                                        }
                                        catch (ServerInteractionException ex)
                                        {
                                            Console.WriteLine("Exception while removing device. (Bug in server: exception is always thrown)");
                                            Console.Out.WriteLine(ex);
                                        }
                                    }
                                    else // Global login
                                    {
                                        var deviceServerInteractor = devices[row].ServerInteractor;
                                        try
                                        {
                                            deviceServerInteractor.RemoveDevice(devices[row]);
                                        }
                                        catch (ServerInteractionException ex)
                                        {
                                            Console.WriteLine("Exception while removing device. (Bug in server: exception is always thrown)");
                                            Console.Out.WriteLine(ex);
                                        }
                                    }

                                    // Remove device from list with devices and refresh device list
                                    ((TableSourceDevicesMain)DevicesTable.Source).serverDevices[section].RemoveAt(row);
                                    RefreshDeviceList();
                                    TableView.ReloadData();
                                }
                            }
                        }
                    }
                    else
                    {
                        WarningMessage.Display(strings.noDeviceFound, strings.pronounceDeviceNameCorrectly, this);
                    }
                }
                else
                {   // Result did not contain any of the above keywords
                    WarningMessage.Display(result + " " + strings.speechNotACommand, strings.tryAgain, this);
                }
            }
        }