示例#1
0
        private static void CreateNetworkSettingsPanel(Panel panel)
        {
            const int leftMargin = 10;
            const int topMargin = 10;

            NetworkInterface net = NetworkInterface.GetAllNetworkInterfaces()[0];

            bool isDhcp = net.IsDhcpEnabled;
            int labelFontHeightDiv2 = StyleManager.CurrentStyle.LabelFont.Height / 2;

            RadioButton rdStatic, rdDynamic;
            panel.AddChild(new Label("Configuration", leftMargin, topMargin + 13 - labelFontHeightDiv2, 80, 25));
            panel.AddChild(rdStatic = new RadioButton("Static", 100, topMargin, 80, 26) { IsChecked = !isDhcp });
            panel.AddChild(rdDynamic = new RadioButton("Dynamic", rdStatic.X + rdStatic.Width + 10, topMargin, 80, 26) { IsChecked = isDhcp });

            TextBox txtIp, txtNetMask, txtGateway, txtDns;

            int y = rdStatic.Y + rdStatic.Height + 5;

            panel.AddChild(new Label("Address", leftMargin, y + 15 - labelFontHeightDiv2, 80, 25));
            panel.AddChild(txtIp = new TextBox(net.IPAddress.ToString(), 100, y, 175, 30)
            {
                EditTextLabel = "IP Address",
                Validator = NetValidators.IpValidator,
                AllowedChars = AllowedCharTypesEnum.Ip,
                Enabled = !isDhcp
            });
            y += 35;

            panel.AddChild(new Label("Netmask", leftMargin, y + 15 - labelFontHeightDiv2, 80, 25));
            panel.AddChild(txtNetMask = new TextBox(net.SubnetMask.ToString(), 100, y, 175, 30)
            {
                EditTextLabel = "Subnet Mask",
                Validator = NetValidators.NetMaskValidator,
                AllowedChars = AllowedCharTypesEnum.Ip,
                Enabled = !isDhcp
            });
            y += 35;

            panel.AddChild(new Label("Gateway", leftMargin, y + 15 - labelFontHeightDiv2, 80, 25));
            panel.AddChild(txtGateway = new TextBox(net.GatewayAddress.ToString(), 100, y, 175, 30)
            {
                EditTextLabel = "Gateway IP Address",
                Validator = NetValidators.IpValidator,
                AllowedChars = AllowedCharTypesEnum.Ip,
                Enabled = !isDhcp
            });
            y += 35;

            panel.AddChild(new Label("Dns", leftMargin, y + 15 - labelFontHeightDiv2, 80, 25));
            panel.AddChild(txtDns = new TextBox(net.DnsAddresses.Length >= 1 ? net.DnsAddresses[0] : string.Empty, 100, y, 175, 30)
            {
                EditTextLabel = "DNS Address",
                Validator = NetValidators.IpAllowEmptyValidator,
                AllowedChars = AllowedCharTypesEnum.Ip,
                Enabled = !isDhcp
            });
            y += 35;

            TextButton applyButton = null, proxyButton;

            UiEventHandler modeChangedHandler = (s) =>
            {
                bool dynamicSelected = rdDynamic.IsChecked;

                panel.Suspended = true;

                txtIp.Enabled = !dynamicSelected;
                txtNetMask.Enabled = !dynamicSelected;
                txtGateway.Enabled = !dynamicSelected;
                txtDns.Enabled = !dynamicSelected;

                if (!dynamicSelected)
                {
                    txtIp.Text = net.IPAddress.ToString();
                    txtNetMask.Text = net.SubnetMask.ToString();
                    txtGateway.Text = net.GatewayAddress.ToString();
                    txtDns.Text = net.DnsAddresses.Length >= 1 ? net.DnsAddresses[0].ToString() : string.Empty;
                }
                else applyButton.Enabled = true;

                panel.Suspended = false;
            };
            rdStatic.IsCheckedChanged += modeChangedHandler;

            int x = txtIp.X + txtIp.Width + 10;
            panel.AddChild(applyButton = new TextButton("Apply", x, txtIp.Y, panel.Width - x - 10, txtIp.Height * 2 + 5) { Enabled = false });
            panel.AddChild(proxyButton = new TextButton("Proxy", x, txtGateway.Y, panel.Width - x - 10, txtGateway.Height * 2 + 5));

            applyButton.ButtonPressed += (s) =>
            {
                applyButton.Enabled = false;

                AppSettings.Instance.Network.DhcpEnabled = rdDynamic.IsChecked;

                if (rdDynamic.IsChecked)
                {
                    net.EnableDhcp();
                }
                else
                {
                    net.EnableStaticIP(txtIp.Text, txtNetMask.Text, txtGateway.Text);

                    if (txtDns.Text.Length != 0)
                    {
                        AppSettings.Instance.Network.DnsAddresses = new string[] { txtDns.Text };
                        net.EnableStaticDns(AppSettings.Instance.Network.DnsAddresses);
                    }
                    AppSettings.Instance.Network.IpAddress = IPAddress.Parse(txtIp.Text).GetAddressBytes();
                    AppSettings.Instance.Network.NetMask = IPAddress.Parse(txtNetMask.Text).GetAddressBytes();
                    AppSettings.Instance.Network.Gateway = IPAddress.Parse(txtGateway.Text).GetAddressBytes();
                }

                AppSettings.Instance.Save();
            };

            ProxyDialog proxyDiag = new ProxyDialog();
            proxyButton.ButtonPressed += (s) =>
            {
                new Thread(new ThreadStart(() =>
                    {
                        if (proxyDiag.Show(AppSettings.Instance.Network.UseProxy, AppSettings.Instance.Network.Proxy.UseForRadio, AppSettings.Instance.Network.Proxy.Address))
                        {
                            AppSettings.Instance.Network.UseProxy = proxyDiag.UseProxy;
                            AppSettings.Instance.Network.Proxy.UseForRadio = proxyDiag.UseForRadio;
                            AppSettings.Instance.Network.Proxy.Address = proxyDiag.ProxyAddress;

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

                            AppSettings.Instance.Save();
                        }
                    })).Start();
            };

            txtDns.TextChanged += (nt, valid) => applyButton.Enabled = valid;
            txtIp.TextChanged += (nt, valid) => applyButton.Enabled = valid;
            txtGateway.TextChanged += (nt, valid) => applyButton.Enabled = valid;
            txtNetMask.TextChanged += (nt, valid) => applyButton.Enabled = valid;
        }
示例#2
0
        private static void CreateDisplaySettingsPanel(Panel panel)
        {
            const int leftMargin = 5, topMargin = 8;
            int labelFontHeightDiv2 = StyleManager.CurrentStyle.LabelFont.Height / 2;

            int y = topMargin;

            Slider brightnessSlider, timeoutSlider;

            panel.AddChild(brightnessSlider = new Slider(leftMargin + 70, y, panel.Width - leftMargin * 2 - 70, 35));
            brightnessSlider.Maximum = 31;
            brightnessSlider.Minimum = 0;
            brightnessSlider.Position = 31 - AppConfig.LcdBacklightLevel;
            brightnessSlider.PositionChanged += (s) =>
            {
                AppSettings.Instance.LcdBacklightLevel = (byte)(31 - brightnessSlider.Position);
                AppSettings.Instance.Save();
                AppConfig.LcdBacklightLevel = AppSettings.Instance.LcdBacklightLevel;
            };
            panel.AddChild(new Label("Brightness", leftMargin, y + brightnessSlider.Height / 2 - labelFontHeightDiv2, 70, 35));
            y += 45;

            panel.AddChild(timeoutSlider = new Slider(leftMargin + 70, y, panel.Width - leftMargin * 2 - 70, 35));
            timeoutSlider.Maximum = 180;
            timeoutSlider.Minimum = 20;
            timeoutSlider.Position = AppSettings.Instance.ShowScreenSaverAfterSec;
            timeoutSlider.PositionChanged += (s) =>
            {
                AppSettings.Instance.ShowScreenSaverAfterSec = timeoutSlider.Position;
                AppSettings.Instance.Save();
                DesktopManager.Instance.SetInputTimeout(AppSettings.Instance.ShowScreenSaverAfterSec * 1000);
            };
            panel.AddChild(new Label("Timeout", leftMargin, y + brightnessSlider.Height / 2 - labelFontHeightDiv2, 70, 35));
            y += 50;

            panel.AddChild(new Label("Style", leftMargin, y, 70, 30));
            y += 30;
            RadioButton rdLight, rdDark, rdMetroDark, rdMetroLight;

            panel.AddChild(rdMetroLight = new RadioButton("Metro Light", leftMargin, y, (panel.Width - leftMargin * 2) / 4, 26) { IsChecked = true, Tag = new StyleMetroLight() });
            panel.AddChild(rdLight = new RadioButton("Light", leftMargin + rdMetroLight.Width, rdMetroLight.Y, rdMetroLight.Width, 26) { Tag = new StyleLight() });
            panel.AddChild(rdMetroDark = new RadioButton("Metro Dark", leftMargin + rdMetroLight.Width * 2, rdMetroLight.Y, rdMetroLight.Width, 26) { Tag = new StyleMetroDark() });
            panel.AddChild(rdDark = new RadioButton("Dark", leftMargin + rdMetroLight.Width * 3, rdMetroLight.Y, rdMetroLight.Width, 26) { Tag = new StyleDark() });

            UiEventHandler radioCheckedChanged = (s) =>
            {
                RadioButton sender = (RadioButton)s;
                if (sender.IsChecked) StyleManager.CurrentStyle = (Style)sender.Tag;
            };

            rdLight.IsCheckedChanged += radioCheckedChanged;
            rdMetroDark.IsCheckedChanged += radioCheckedChanged;
            rdMetroLight.IsCheckedChanged += radioCheckedChanged;
            rdDark.IsCheckedChanged += radioCheckedChanged;
        }
示例#3
0
        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;
        }