public CalibrationDesktop(TouchCalibrationPoints calPoints)
        {
            DrawBackground += CalibrationDesktop_DrawBackground;
            _calibrationPoints = calPoints;
            _currentCalibrationPoint = 0;
            _isCalibrating = false;

            _doneButton = new TextButton("Done", _width / 2 - 50, _height - 40, 100, 35);
            _doneButton.Visible = false;
            _doneButton.ButtonPressed += (s) =>
            {
                _calDoneTimer.Dispose();
                if (CalibrationComplete != null) CalibrationComplete(this);
            };
            base.AddChild(_doneButton);

            _timerLabel = new Label(string.Empty, 10, 10, _width - 20, 0);
            _timerLabel.CenterText = true;
            _timerLabel.AutoHeight = true;
            _timerLabel.Visible = false;
            base.AddChild(_timerLabel);
        }
        private void CreateCommonLayout()
        {
            string keyLine = Keys[0][_charSetUsed];
            int keyWidth = (_width - (keyLine.Length + 1) * _uiMargin) / keyLine.Length;
            int keyHeight = (_height / 2 - 5 * _uiMargin) / 4;

            int widthRemaining = _width - ((keyLine.Length + 1) * _uiMargin + keyLine.Length * keyWidth);

            int x = _uiMargin + widthRemaining / 2,
                y = _uiMargin;

            _editLabel = new Label(string.Empty, x, y, _width - 2 * _uiMargin - widthRemaining, StyleManager.CurrentStyle.LabelFont.Height);
            base.AddChild(_editLabel);

            _editTextbox = new EditableTextBox(string.Empty, x, y, _editLabel._width, _height / 4 - 2 * _uiMargin);
            base.AddChild(_editTextbox);

            #region done/cancel buttons
            x = _editTextbox.ScreenRight - 2 * keyWidth - _uiMargin;
            y = _editTextbox.ScreenBottom + _uiMargin;

            _doneButton = new TextButton("Done", x, y, 2 * keyWidth + _uiMargin, keyHeight);
            _doneButton.ButtonPressed += (sender) => { Close(); };
            base.AddChild(_doneButton);

            x -= keyWidth * 2 + _uiMargin * 2;
            TextButton _cancelButton = new TextButton("Cancel", x, y, keyWidth * 2 + _uiMargin, keyHeight);
            _cancelButton.ButtonPressed += (sender) =>
            {
                _editTextbox.Text = _initialText;
                if (_allowCloseOnlyWhenValid)
                {
                    if (_editTextbox.Valid)
                        Close();
                }
                else Close();
            };
            base.AddChild(_cancelButton);
            #endregion

            #region left/right/clear buttons
            Color transparentColor = ColorUtility.ColorFromRGB(255, 0, 255);
            Bitmap leftImg = Resources.Images.GetBitmap(Resources.Images.BitmapResources.arrowLeft);

            x = _uiMargin + widthRemaining / 2;
            y = _editTextbox.Height + 2 * _uiMargin;

            leftImg.MakeTransparent(transparentColor);
            _leftBut = new ImageButton(leftImg, x, y, keyHeight, keyHeight);
            _leftBut.RepeatKeyPress = true;
            _leftBut.ButtonPressed += (sender) =>
            {
                if (_editTextbox.CarretPosition != 0)
                {
                    _editTextbox.CarretPosition--;
                    RemakeButtonsEnabled();
                }
            };
            _leftBut.Enabled = false;
            x += _leftBut.Width + _uiMargin;
            base.AddChild(_leftBut);

            Bitmap rightImg = Resources.Images.GetBitmap(Resources.Images.BitmapResources.arrowRight);
            rightImg.MakeTransparent(transparentColor);
            _rightBut = new ImageButton(rightImg, x, y, keyHeight, keyHeight);
            _rightBut.RepeatKeyPress = true;
            _rightBut.ButtonPressed += (sender) =>
            {
                if (_editTextbox.CarretPosition != _editTextbox.Text.Length)
                {
                    _editTextbox.CarretPosition++;
                    RemakeButtonsEnabled();
                }
            };
            _rightBut.Enabled = false;
            x += _rightBut.Width + _uiMargin;
            base.AddChild(_rightBut);

            Bitmap clearImg = Resources.Images.GetBitmap(Resources.Images.BitmapResources.clear);
            clearImg.MakeTransparent(transparentColor);
            _clearBut = new ImageButton(clearImg, x, y, keyHeight, keyHeight);
            _clearBut.ButtonPressed += (sender) =>
            {
                if (_editTextbox.Text.Length != 0)
                {
                    _editTextbox.Text = string.Empty;
                    RemakeButtonsEnabled();
                }
            };
            _clearBut.Enabled = false;
            base.AddChild(_clearBut);
            #endregion
        }
        private static void CreateSettingsPanel(Panel panel)
        {
            Label title = new Label("Settings", 5, 5, 200, Fonts.ArialMediumBold.Height) { Font = Fonts.ArialMediumBold };
            panel.AddChild(title);

            const int btMargin = 10, btHeight = 50;
            int btWidth = (panel.Width - btMargin) / 4;

            int x = 5;
            ToggleButton stNetwork, stAudio, stDisplay, stOther;
            panel.AddChild(stNetwork = new ToggleTextButton("Network", x, title.ScreenBottom + 15, btWidth, btHeight) { IsChecked = true, Tag = 0 }); x += btWidth;
            panel.AddChild(stAudio = new ToggleTextButton("Audio", x, title.ScreenBottom + 15, btWidth, btHeight) { Tag = 1 }); x += btWidth;
            panel.AddChild(stDisplay = new ToggleTextButton("Display", x, title.ScreenBottom + 15, btWidth, btHeight) { Tag = 2 }); x += btWidth;
            panel.AddChild(stOther = new ToggleTextButton("Other", x, title.ScreenBottom + 15, btWidth, btHeight) { Tag = 3 }); x += btWidth;

            Panel[] settingsPanels = new Panel[4];
            int visiblePanel = 0;

            UiEventHandler btCheckChanged = (s) =>
            {
                if (!((ToggleButton)s).IsChecked) return;
                settingsPanels[visiblePanel].Suspended = true;
                visiblePanel = (int)s.Tag;
                settingsPanels[visiblePanel].Suspended = false;
            };

            stNetwork.IsCheckedChanged += btCheckChanged;
            stAudio.IsCheckedChanged += btCheckChanged;
            stDisplay.IsCheckedChanged += btCheckChanged;
            stOther.IsCheckedChanged += btCheckChanged;

            int panelWidth = panel.Width - btMargin;
            int panelHeight = panel.Height - stNetwork.ScreenBottom - btMargin / 2;
            for (int i = 0; i < 4; i++)
                panel.AddChild(settingsPanels[i] = new Panel(btMargin / 2, stNetwork.ScreenBottom, panelWidth, panelHeight) { Suspended = visiblePanel != i });

            CreateNetworkSettingsPanel(settingsPanels[0]);
            CreateAudioSettingsPanel(settingsPanels[1]);
            CreateDisplaySettingsPanel(settingsPanels[2]);
            CreateOtherSettingsPanel(settingsPanels[3]);
        }
        private static void CreateWeatherPanel(Panel panel)
        {
            //initial weather place
            const string initialPlace = "Timisoara";

            proxyForWeather = AppSettings.Instance.Network.UseProxy && !AppSettings.Instance.Network.Proxy.UseForRadio ? new WebProxy(AppSettings.Instance.Network.Proxy.Address) : null;

            //create a new Yahoo! Weather Provider
            YahooWeatherProvider yProvider = new YahooWeatherProvider();
            GoogleWeatherProvider gProvider = new GoogleWeatherProvider();

            RadioButton rdYahoo = null, rdGoogle = null;
            Ui.Controls.TouchControls.Button refreshButton = null;

            Label title = new Label("Weather", 5, 5, 200, Fonts.ArialMediumBold.Height) { Font = Fonts.ArialMediumBold };
            panel.AddChild(title);

            //create text box for weather place
            TextBox txtWeatherPlace = new TextBox(string.Empty, 5, title.ScreenBottom + 15, 170, 30) { Validator = (s) => s.Trim().Length != 0, EditTextLabel = "Place:" };
            panel.AddChild(txtWeatherPlace);

            //create a weather control and add it on the desktop (centered)
            GoogleWeatherControl gControl = new GoogleWeatherControl(gProvider.LastWeatherCondition, 0, 80) { Visible = false };
            YahooWeatherControl yControl = new YahooWeatherControl(yProvider.LastWeatherCondition, 0, 0);
            gControl.X = (panel.Width - gControl.Width) / 2;
            gControl.Y = txtWeatherPlace.ScreenBottom + (panel.Height - txtWeatherPlace.ScreenBottom - gControl.Height) / 2;
            yControl.X = (panel.Width - yControl.Width) / 2;
            yControl.Y = gControl.Y;
            panel.AddChild(gControl);
            panel.AddChild(yControl);

            //watch for text changed
            string oldPlace = string.Empty;
            const string noWeatherInfo = "No weather info";
            string basicWeatherInfo = null;
            GetWeatherInfo = () =>
            {
                if (basicWeatherInfo == null)
                {
                    basicWeatherInfo = null;
                    if (rdGoogle.IsChecked)
                    {
                        if (gProvider.LastWeatherCondition != null)
                            basicWeatherInfo = gProvider.LastWeatherCondition.City + " " + gProvider.LastWeatherCondition.CurrentCondition.Temp;
                    }
                    else if (rdYahoo.IsChecked)
                    {
                        if (yProvider.LastWeatherCondition != null)
                            basicWeatherInfo = yProvider.LastWeatherCondition.Location + " " + yProvider.LastWeatherCondition.Temperature;
                    }
                    if (basicWeatherInfo == null)
                        basicWeatherInfo = noWeatherInfo;
                }
                return basicWeatherInfo;
            };

            SimpleAction refreshWeather = () =>
            {
                try
                {
                    if (!Ethernet.IsCableConnected) return;
                }
                catch (Exception)
                {
                    //TODO: emulator throws exception
                }

                //disable the textbox
                txtWeatherPlace.Enabled = yControl.Enabled = gControl.Enabled = refreshButton.Enabled = false;
                //get the weather in a new Thread
                new Thread(() =>
                {
                    if (yProvider.SetWeatherPlace(oldPlace, proxyForWeather)) yProvider.GetWeather(proxyForWeather);
                    yControl.WeatherCondition = yProvider.LastWeatherCondition;

                    gProvider.GetWeather(oldPlace, proxyForWeather);
                    gControl.WeatherCondition = gProvider.LastWeatherCondition;

                    basicWeatherInfo = null;

                    txtWeatherPlace.Enabled = yControl.Enabled = gControl.Enabled = refreshButton.Enabled = true;
                }).Start();
            };

            AppConfig.OnNetworkConnected += () => refreshWeather();

            txtWeatherPlace.TextChanged += (newPlace, valid) =>
            {
                string nPlace = newPlace.Trim().ToLower();
                //if the new place is different
                if (nPlace != oldPlace)
                {
                    oldPlace = nPlace;
                    refreshWeather();
                }
            };

            //refresh the text colors according to the current style
            StyleManager.StyleChanged += (oldStyle, newStyle) =>
            {
                yControl.WeatherCondition = yProvider.LastWeatherCondition;
                gControl.WeatherCondition = gProvider.LastWeatherCondition;
            };


            panel.AddChild(refreshButton = new ImageButton(Images.GetBitmap(Images.BitmapResources.imgRefresh),
                txtWeatherPlace.X + txtWeatherPlace.Width + 5, txtWeatherPlace.Y, txtWeatherPlace.Height, txtWeatherPlace.Height));
            refreshButton.ButtonPressed += (s) => refreshWeather();

            panel.AddChild(rdYahoo = new RadioButton("Yahoo", refreshButton.X + refreshButton.Width + 15, refreshButton.ScreenTop + refreshButton.Height / 2 - 13, 80, 26) { IsChecked = true });
            panel.AddChild(rdGoogle = new RadioButton("Google", rdYahoo.X + rdYahoo.Width + 15, txtWeatherPlace.ScreenTop + txtWeatherPlace.Height / 2 - 13, rdYahoo.Width, 26));
            UiEventHandler checkChanged = (s) =>
            {
                //this will trigger once for each radio button
                if (!((RadioButton)s).IsChecked) return;

                bool oldValue = panel.Suspended;
                panel.Suspended = true;
                if (rdYahoo.IsChecked)
                {
                    yControl.Visible = true;
                    gControl.Visible = false;
                }
                else
                {
                    yControl.Visible = false;
                    gControl.Visible = true;
                }
                basicWeatherInfo = null;
                panel.Suspended = oldValue;
            };
            rdGoogle.IsCheckedChanged += checkChanged;
            rdYahoo.IsCheckedChanged += checkChanged;

            //set the text to trigger a get on the weather
            txtWeatherPlace.Text = initialPlace;
        }
        private static void CreatePlayerPanel(Panel panel)
        {
            const int btSize = 50;
            const int margin = 5;

            Label title = new Label("Player", 5, 5, 200, Fonts.ArialMediumBold.Height) { Font = Fonts.ArialMediumBold };
            panel.AddChild(title);

            FsList fsList = new FsList(5, title.Y + title.Height + 5, panel.Width - margin * 3 - btSize, panel.Height - (title.Y + title.Height + margin * 3 + btSize));
            panel.AddChild(fsList);

            ArrayList rootItems = new ArrayList();

            FsItem currentPlaying = null;

            SimpleActionParamString playFile = (filePath) =>
            {
                switch (VsDriver.Status)
                {
                    case VsStatus.Connecting: return false;
                    case VsStatus.PlayingRadio: return false;
                    case VsStatus.Playing: VsDriver.StopFile(); break;
                    case VsStatus.Paused: VsDriver.ResumeFile(); VsDriver.StopFile(); break;
                }
                int tries = 5;
                Exception lastEx = null;
                while (tries-- != 0)
                {
                    try
                    {
                        FileStream file = File.Open(filePath, FileMode.Open);
                        VsDriver.PlayFile(file);
                        lastEx = null;
                        break;
                    }
                    catch (Exception ex) { lastEx = ex; }
                }

                if (lastEx != null)
                {
                    new Thread(() =>
                    {
                        using (MessageBox mb = new MessageBox(lastEx.Message, "Error", MessageBoxButtons.Ok, MessageBoxIcons.Error)) mb.Show();
                    }).Start();
                    return false;
                }
                return true;
            };

            #region list double click
            fsList.OnDoubleClick += (s) =>
            {
                FsItem selectedItem = fsList.SelectedItem;
                if (selectedItem == null) return;

                if (selectedItem.IsBack)
                {
                    fsList.ClearItems();
                    fsList.Folder = selectedItem.Parent;

                    if (fsList.Folder.Parent != null)
                        fsList.AddItems(fsList.Folder.Parent.Childs);
                    else
                        fsList.AddItems(rootItems);
                }
                else if (selectedItem.IsDirectory)
                {
                    if (selectedItem.Childs == null)
                    {
                        selectedItem.Childs = new ArrayList();
                        string[] dirs = Directory.GetDirectories(selectedItem.Path);
                        selectedItem.Childs.Add(new FsItem(selectedItem) { IsBack = true, Name = "Back" });
                        foreach (string dir in dirs)
                            selectedItem.Childs.Add(new FsItem(selectedItem) { IsBack = false, IsDirectory = true, IsMusicFile = false, Name = Path.GetFileName(dir), Path = dir });

                        string[] files = Directory.GetFiles(selectedItem.Path);
                        foreach (string file in files)
                        {
                            string extension = Path.GetExtension(file).ToLower();
                            bool isMusicFile = extension.Equals(".mp3");
                            selectedItem.Childs.Add(new FsItem(selectedItem) { IsBack = false, IsDirectory = false, IsMusicFile = isMusicFile, Name = Path.GetFileName(file), Path = file });
                        }
                    }

                    fsList.Folder = selectedItem;
                    fsList.ClearItems();
                    fsList.AddItems(selectedItem.Childs);
                }
                else if (selectedItem.IsMusicFile)
                {
                    if (playFile(selectedItem.Path))
                    {
                        currentPlaying = selectedItem;
                        fsList.CurrentPlaying = currentPlaying;
                    }
                }
            };
            #endregion

            #region removable media events
            RemovableMedia.Insert += (s, e) =>
            {
                FsItem newItem = new FsItem(null) { IsBack = false, IsDirectory = true, IsMusicFile = false, Name = e.Volume.Name, Path = e.Volume.RootDirectory };
                rootItems.Add(newItem);

                if (fsList.Folder == null)
                    fsList.AddItem(newItem);
            };

            RemovableMedia.Eject += (s, e) =>
            {
                FsItem toRemove = null;
                foreach (FsItem fsItem in rootItems) if (fsItem.Path == e.Volume.RootDirectory) { toRemove = fsItem; break; }
                if (toRemove != null)
                {
                    rootItems.Remove(toRemove);
                    if (fsList.Folder == null)
                        fsList.RemoveItem(toRemove);

                    else if (fsList.Folder.GetRootNode().Path == e.Volume.RootDirectory)
                    {
                        fsList.Folder = null;
                        fsList.ClearItems();
                        fsList.AddItems(rootItems);
                    }
                }
            };
            #endregion

            ImageButton btDelete;
            panel.AddChild(btDelete = new ImageButton(Images.GetBitmap(Images.BitmapResources.imgDelete), fsList.X + fsList.Width + margin, fsList.Y, btSize, btSize));
            btDelete.ButtonPressed += (s) =>
            {
                FsItem selectedItem = fsList.SelectedItem;
                if (selectedItem == null || selectedItem.IsBack || selectedItem.Parent == null) return;
                if (selectedItem == currentPlaying) VsDriver.StopFile();

                new Thread(new ThreadStart(() =>
                {
                    using (MessageBox mb = new MessageBox("Are you sure you want to delete\n" + selectedItem.Name + "?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcons.Delete))
                    {
                        if (mb.Show() == MessageBoxResult.Yes)
                        {
                            try
                            {
                                if (selectedItem.IsDirectory) Directory.Delete(selectedItem.Path);
                                else File.Delete(selectedItem.Path);

                                selectedItem.Parent.Childs.Remove(selectedItem);
                                fsList.RemoveItem(selectedItem);
                            }
                            catch (Exception)
                            {
                                using (MessageBox err = new MessageBox("Error deleting item", "Error", MessageBoxButtons.Ok, MessageBoxIcons.Error))
                                    err.Show();
                            }
                        }
                    }
                })).Start();
            };

            ImageButton btPlay, btStop, btNext, btPrev;
            int x = fsList.X, y = fsList.Y + fsList.Height + margin;

            Bitmap imgPlay = Images.GetBitmap(Images.BitmapResources.btPlay), imgPause = Images.GetBitmap(Images.BitmapResources.btPause);

            panel.AddChild(btPrev = new ImageButton(Images.GetBitmap(Images.BitmapResources.btBack), x, y, btSize, btSize)); x += margin + btSize;
            panel.AddChild(btPlay = new ImageButton(Images.GetBitmap(Images.BitmapResources.btPlay), x, y, btSize, btSize)); x += margin + btSize;
            panel.AddChild(btNext = new ImageButton(Images.GetBitmap(Images.BitmapResources.btForward), x, y, btSize, btSize)); x += margin + btSize;
            panel.AddChild(btStop = new ImageButton(Images.GetBitmap(Images.BitmapResources.btStop), x, y, btSize, btSize));

            #region prev/play/next/stop events
            bool ignore = false;
            UiEventHandler actionPrev = (s) =>
            {
                if (ignore) return;
                try
                {
                    ignore = true;

                    if (currentPlaying == null) return;
                    FsItem aux = currentPlaying;

                    int stIndex = aux.Parent.Childs.IndexOf(aux);
                    if (stIndex == -1) return;

                    FsItem nextToPlay;
                    do
                    {
                        stIndex--;
                        if (stIndex < 0) stIndex = aux.Parent.Childs.Count - 1;
                        nextToPlay = (FsItem)aux.Parent.Childs[stIndex];
                        if (nextToPlay.IsMusicFile) break;
                    } while (true);

                    if (playFile(nextToPlay.Path))
                    {
                        currentPlaying = nextToPlay;
                        fsList.CurrentPlaying = currentPlaying;
                    }
                }
                finally
                {
                    ignore = false;
                }
            };

            UiEventHandler actionNext = (s) =>
            {
                if (ignore) return;
                try
                {
                    ignore = true;

                    if (currentPlaying == null) return;
                    FsItem aux = currentPlaying;

                    int stIndex = aux.Parent.Childs.IndexOf(aux);
                    if (stIndex == -1) return;

                    FsItem nextToPlay;
                    do
                    {
                        stIndex++;
                        if (stIndex == aux.Parent.Childs.Count) stIndex = 0;
                        nextToPlay = (FsItem)aux.Parent.Childs[stIndex];
                        if (nextToPlay.IsMusicFile) break;
                    } while (true);

                    if (playFile(nextToPlay.Path))
                    {
                        currentPlaying = nextToPlay;
                        fsList.CurrentPlaying = currentPlaying;
                    }
                }
                finally
                {
                    ignore = false;
                }
            };

            btPrev.ButtonPressed += actionPrev;
            btNext.ButtonPressed += actionNext;

            btPlay.ButtonPressed += (s) =>
            {
                switch (VsDriver.Status)
                {
                    case VsStatus.Playing: VsDriver.PauseFile(); break;
                    case VsStatus.Paused: VsDriver.ResumeFile(); break;
                    case VsStatus.Stopped:
                        FsItem selectedItem = fsList.SelectedItem;
                        if (selectedItem != null && selectedItem.IsMusicFile)
                        {
                            if (playFile(selectedItem.Path))
                            {
                                currentPlaying = selectedItem;
                                fsList.CurrentPlaying = currentPlaying;
                            }
                        }
                        break;
                }
            };

            bool stopPressed = false;
            btStop.ButtonPressed += (s) =>
            {
                switch (VsDriver.Status)
                {
                    case VsStatus.Playing: stopPressed = true; VsDriver.StopFile(); break;
                    case VsStatus.Paused: stopPressed = true; VsDriver.ResumeFile(); VsDriver.StopFile(); break;
                }
            };
            #endregion

            VsDriver.VsStatusChanged += (status) =>
            {
                if (status == VsStatus.Playing)
                    btPlay.Image = imgPause;
                else
                {
                    if (status == VsStatus.Stopped)
                    {
                        if (!stopPressed)
                        {
                            if (currentPlaying != null)
                                actionNext(btNext);
                        }
                        else
                        {
                            currentPlaying = null;
                            fsList.CurrentPlaying = currentPlaying;
                            stopPressed = false;
                        }
                    }
                    btPlay.Image = imgPlay;
                }
            };
        }
        private static void CreateRadioPanel(Panel panel)
        {
            Label title = new Label("Radio", 5, 5, 200, Fonts.ArialMediumBold.Height) { Font = Fonts.ArialMediumBold };
            panel.AddChild(title);

            const int btSize = 50;
            const int margin = 5;

            int y = title.X + title.Height + margin;
            RadioStationsList radioList = new RadioStationsList(margin, y, panel.Width - margin * 3 - btSize, panel.Height - y - margin * 2 - btSize);

            foreach (RadioStationItem item in AppSettings.Instance.RadioStations)
                radioList.AddItem(item);

            Mp.Ui.Controls.TouchControls.Button btAdd, btRemove, btEdit;
            panel.AddChild(btAdd = new ImageButton(Images.GetBitmap(Images.BitmapResources.imgAdd), radioList.X + radioList.Width + margin, radioList.Y, btSize, btSize));
            panel.AddChild(btRemove = new ImageButton(Images.GetBitmap(Images.BitmapResources.imgDelete), btAdd.X, btAdd.Y + btSize + margin, btSize, btSize));
            panel.AddChild(btEdit = new ImageButton(Images.GetBitmap(Images.BitmapResources.imgEdit), btAdd.X, btRemove.Y + btSize + margin, btSize, btSize));

            EditStationDialog esd = new EditStationDialog();

            #region add/remove/edit events
            btAdd.ButtonPressed += (s) =>
            {
                new Thread(() =>
                {
                    RadioStationItem item = new RadioStationItem("http://", string.Empty);
                    if (esd.Show("New Radio Station", item))
                    {
                        radioList.AddItem(item);
                        AppSettings.Instance.RadioStations.Add(item);
                        AppSettings.Instance.Save();
                    }
                }).Start();
            };

            btRemove.ButtonPressed += (s) =>
            {
                if (radioList.SelectedIndex != -1)
                {
                    RadioStationItem selItem = radioList.SelectedItem;
                    new Thread(() =>
                    {
                        using (MessageBox mb = new MessageBox("Are you sure you want to delete\n" + selItem.Name + "?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcons.Delete))
                            if (mb.Show() == MessageBoxResult.Yes)
                            {
                                radioList.RemoveItem(selItem);
                                AppSettings.Instance.RadioStations.Remove(selItem);
                                AppSettings.Instance.Save();
                            }
                    }).Start();
                }
            };

            btEdit.ButtonPressed += (s) =>
            {
                if (radioList.SelectedIndex != -1)
                {
                    RadioStationItem selItem = radioList.SelectedItem;
                    new Thread(() =>
                    {
                        if (esd.Show("Edit Radio Station", selItem))
                        {
                            radioList.Refresh();
                            AppSettings.Instance.Save();
                        }
                    }).Start();
                }
            };
            #endregion

            ImageButton btPlay, btStop;
            panel.AddChild(btPlay = new ImageButton(Images.GetBitmap(Images.BitmapResources.btPlay), radioList.X, radioList.Y + radioList.Height + margin, btSize, btSize));
            panel.AddChild(btStop = new ImageButton(Images.GetBitmap(Images.BitmapResources.btStop), btPlay.X + btPlay.Width + margin, radioList.Y + radioList.Height + margin, btSize, btSize));

            RadioStationItem playingItem = null;
            int playingIndex = 0;

            VsDriver.VsStatusChanged += (status) =>
            {
                if (playingItem == null) return;
                switch (status)
                {
                    case VsStatus.Connecting:
                        playingItem.IsConnecting = true;
                        radioList.RefreshItem(playingIndex);
                        break;

                    case VsStatus.PlayingRadio:
                        playingItem.IsConnecting = false;
                        playingItem.IsPlaying = true;
                        radioList.RefreshItem(playingIndex);
                        break;

                    case VsStatus.Stopped:
                        playingItem.IsPlaying = false;
                        playingItem.IsConnecting = false;
                        radioList.RefreshItem(playingIndex);
                        break;
                }
            };

            string metaData = null;

            GetRadioInfo += () =>
            {
                return VsDriver.Status == VsStatus.PlayingRadio ? metaData : null;
            };

            char[] metadataSeparators = new char[] { ';' };
            VsDriver.VsRadioMetaDataReceived += (newMetaData) =>
            {
                string[] metaDataParams = newMetaData.Split(metadataSeparators);
                metaData = newMetaData;
            };

            btPlay.ButtonPressed += (s) =>
            {
                if (radioList.SelectedIndex == -1) return;
                if (playingItem == null)
                {
                    playingItem = radioList.SelectedItem;
                    playingIndex = radioList.SelectedIndex;
                }
                else
                {
                    VsDriver.StopRadio();
                    playingItem = radioList.SelectedItem;
                    playingIndex = radioList.SelectedIndex;
                }
                VsDriver.ConnectToStation(playingItem.Address);
            };

            btStop.ButtonPressed += (s) =>
            {
                VsDriver.StopRadio();
                playingItem = null;
            };

            panel.AddChild(radioList);
        }