示例#1
0
文件: HomePage.cs 项目: leewoody/hobd
        protected virtual void CreateThemeSection()
        {
            IEnumerable <object> fileList = null;

            try{
                fileList = Directory.GetFiles(Path.Combine(HOBD.AppPath, "themes"), "*.theme")
                           .OrderBy(s => s)
                           .Select(s => (object)Path.GetFileName(s));
            }catch (Exception e) {
                Logger.error("HomePage", "No themes found", e);
            }
            var section = new ListSection(t("Choose Theme"), null, layoutX, layoutY - SectionContentDelta)
            {
                Selected     = HOBD.config.Theme,
                Content      = fileList,
                UIContent    = (f) => Path.GetFileNameWithoutExtension((string)f),
                ChooseAction = (path) => {
                    panorama.CurrentSectionIndex -= 1;
                    HOBD.config.Theme             = "themes/" + path;
                    HOBD.config.Save();
                    HOBD.ReloadTheme();
                    ReloadUI();
                }
            };

            this.PushVolatileSection(section);
        }
示例#2
0
 private static void Main(string[] args)
 {
     if (!HOBD.Init())
     {
         return;
     }
     HOBD.Run("hobd.HomePage");
 }
示例#3
0
 public static void ReloadLang()
 {
     i18n.Clear();
     HOBD.LoadLang("en");
     if (config.Language != "en")
     {
         HOBD.LoadLang(config.Language);
     }
 }
示例#4
0
        public ConfigurationSection(int layoutX, int layoutY) :
            base(HOBD.t("Connection port settings"))
        {
            LayoutX = layoutX;
            LayoutY = layoutY;

            CreateItems();

            OnBluetoothScan(null);
        }
示例#5
0
文件: HomePage.cs 项目: leewoody/hobd
        protected virtual UIElement CreateItem(Dictionary <string, string> attrs, PanoramaSection section)
        {
            string id = "";

            try{
                if (!attrs.TryGetValue("id", out id))
                {
                    return(null);
                }

                var sensor = HOBD.Registry.Sensor(id);
                if (sensor != null)
                {
                    var sensorItem = new SensorTextElement(sensor, attrs);
                    sensorItem.HandleTapAction = () => { sensorItem.Text = HOBD.t("sdesc." + sensor.Name); Redraw(); };

                    List <SensorTextElement> ui_list = null;
                    sensorUIMap.TryGetValue(sensor, out ui_list);
                    if (ui_list == null)
                    {
                        ui_list = new List <SensorTextElement>();
                        sensorUIMap.Add(sensor, ui_list);
                    }
                    ui_list.Add(sensorItem);

                    List <SensorListener> sensor_list = null;
                    sectionSensorMap.TryGetValue(section, out sensor_list);
                    if (sensor_list == null)
                    {
                        sensor_list = new List <SensorListener>();
                        sectionSensorMap.Add(section, sensor_list);
                    }

                    SensorListener sl = new SensorListener();
                    sl.sensor = sensor;
                    sl.period = 0;
                    string period = null;
                    if (attrs.TryGetValue("period", out period))
                    {
                        sl.period = int.Parse(period);
                    }

                    sensor_list.Add(sl);

                    return(sensorItem);
                }
            }catch (Exception e)
            {
                Logger.error("CreateItem", "Failed creating Sensor Element: " + id, e);
            }
            return(new DynamicElement("n/a: " + id)
            {
                Style = HOBD.theme.PhoneTextSmallStyle
            });
        }
示例#6
0
文件: HomePage.cs 项目: leewoody/hobd
        protected virtual void CreatePortSection()
        {
            var section = new ConfigurationSection(layoutX, layoutY - SectionContentDelta)
            {
                ChoosePortAction = () => {
                    panorama.CurrentSectionIndex -= 1;
                    HOBD.config.Save();
                    HOBD.EngineConnect();
                    HOBD.engine.Activate();
                }
            };

            panorama.AddSection(section);
            this.volatileSection          = section;
            panorama.CurrentSectionIndex += 1;
        }
示例#7
0
文件: HomePage.cs 项目: leewoody/hobd
 protected virtual void CreateVehicleSection()
 {
     this.PushVolatileSection(
         new ListSection(t("Vehicle Type"), null, layoutX, layoutY - SectionContentDelta)
     {
         Selected     = HOBD.config.Vehicle,
         Content      = HOBD.config.Vehicles.Select((s) => (object)s.Name),
         UIContent    = s => (string)s,
         ChooseAction = (v) => {
             panorama.CurrentSectionIndex -= 1;
             HOBD.config.Vehicle           = (string)v;
             HOBD.config.Save();
             HOBD.ReloadVehicle();
             ReloadUI();
         }
     }
         );
 }
示例#8
0
        void DiscoverBT()
        {
            try{
                BluetoothRadio.PrimaryRadio.Mode = RadioMode.Discoverable;
                BluetoothClient bluetoothClient = new BluetoothClient();
                UpdateBTStatus(HOBD.t("Scanning Bluetooth.."));

                bluetoothDeviceInfo = bluetoothClient.DiscoverDevices(10, true, false, true);
                foreach (var di in bluetoothDeviceInfo)
                {
                    Logger.info("ConfigurationPage", "BT name=" + di.DeviceName + ", addr=" + di.DeviceAddress.ToString());
                }
            }catch (Exception e) {
                UpdateBTStatus(HOBD.t("Bluetooth scan failed"));
                Logger.error("ConfigurationPage", "", e);
            }
            UpdateBTStatus(HOBD.t("Scan Again"));
            CreateItems();
            discoverBThread = null;
        }
示例#9
0
文件: HomePage.cs 项目: leewoody/hobd
        protected virtual void CreateLanguageSection()
        {
            IEnumerable <object> codesList = Directory.GetFiles(Path.Combine(HOBD.AppPath, "lang"), "??.lang")
                                             .Select((f) => (object)Path.GetFileNameWithoutExtension(f))
                                             .OrderBy(s => s);

            var section = new ListSection(t("Language"), null, layoutX, layoutY - SectionContentDelta)
            {
                Selected     = HOBD.config.Language,
                Content      = codesList,
                UIContent    = (l) => t((string)l),
                ChooseAction = (l) => {
                    panorama.CurrentSectionIndex -= 1;
                    HOBD.config.Language          = (string)l;
                    HOBD.config.Save();
                    HOBD.ReloadLang();
                    ReloadUI();
                }
            };

            this.PushVolatileSection(section);
        }
示例#10
0
        protected void CreateItems()
        {
            var style = new TextStyle(HOBD.theme.PhoneTextNormalStyle);

            if (grid != null)
            {
                this.RemoveElement(grid);
            }

            int height = LayoutY / 6;

            grid = new Grid
            {
                Columns = new MeasureDefinition[] { LayoutX / 3, LayoutX / 3, LayoutX / 3 },
                Rows    = new MeasureDefinition[] { height, height, height, height, height, height }
            };

            int idx = 0, idx2 = 0;

            foreach (var p in SerialPort.GetPortNames().OrderBy(s => s))
            {
                var label = p;

                if (string.Compare(HOBD.config.Port, p, true) == 0)
                {
                    label = ">> " + label;
                }

                var e = new IconTextElement("icon_com.png", label)
                {
                    HandleTapAction = OnChoosePort
                };

                portMapping.Add(e, p);

                grid[idx++, idx2] = e;
                if (idx >= grid.Rows.Length)
                {
                    idx = 0;
                    idx2++;
                }
                if (idx2 >= grid.Columns.Length)
                {
                    return;
                }
            }

            uiBTScan = new IconTextElement("icon_bt.png", HOBD.t("Scan Again"))
            {
                HandleTapAction = OnBluetoothScan
            };
            grid[idx++, idx2] = uiBTScan;
            if (idx >= grid.Rows.Length)
            {
                idx = 0;
                idx2++;
            }

            foreach (var di in bluetoothDeviceInfo)
            {
                var label = di.DeviceName;

                var p = "btspp://" + di.DeviceAddress.ToString();
                if (HOBD.config.Port.StartsWith(p))
                {
                    label = ">> " + label;
                }

                var e = new IconTextElement("icon_bt.png", label)
                {
                    HandleTapAction = OnChoosePort
                };

                portMapping.Add(e, p);

                grid[idx++, idx2] = e;
                if (idx >= grid.Rows.Length)
                {
                    idx = 0;
                    idx2++;
                }
                if (idx2 >= grid.Columns.Length)
                {
                    return;
                }
            }
            this.AddElement(grid);
            // , 0, 0, LayoutX, LayoutY
        }
示例#11
0
        public SensorTextElement(Sensor sensor, Dictionary <string, string> attrs)
        {
            this.Text = "-";

            this.Name = HOBD.t("sname." + sensor.Name);

            this.Units          = sensor.Units;
            this.needConversion = HOBD.uConverter.NeedConversion(this.Units);
            if (this.needConversion)
            {
                this.TUnits = HOBD.uConverter.ConvertUnits(this.Units);
            }
            else
            {
                this.TUnits = this.Units;
            }
            this.TUnits = HOBD.t(this.TUnits);
            if (this.Units == "seconds")
            {
                customFormat = true;
            }

            this.Style = new TextStyle(HOBD.theme.PhoneTextNormalStyle);

            string textSize = null;

            attrs.TryGetValue("size", out textSize);

            if (textSize == "small")
            {
                this.Style.FontSize = HOBD.theme.PhoneFontSizeNormal;
            }
            else if (textSize == "large")
            {
                this.Style.FontSize = HOBD.theme.PhoneFontSizeLarge;
            }
            else if (textSize == "huge")
            {
                this.Style.FontSize = HOBD.theme.PhoneFontSizeExtraExtraLarge;
            }
            else if (textSize == "giant")
            {
                this.Style.FontSize = HOBD.theme.PhoneFontSizeHuge;
            }
            else
            {
                this.Style.FontSize = HOBD.theme.PhoneFontSizeMediumLarge;
            }

            string precision = null;

            attrs.TryGetValue("precision", out precision);
            if (precision != null)
            {
                try {
                    this.Precision = int.Parse(precision);
                }catch (Exception e) {
                    Logger.error("SensorTextElement", "init", e);
                }
            }

            //var style = new TextStyle(HOBD.theme.PhoneTextLargeStyle.FontFamily, HOBD.theme.PhoneFontSizeMediumLarge, HOBD.theme.PanoramaNormalBrush);
        }
示例#12
0
文件: HomePage.cs 项目: leewoody/hobd
 protected static string t(string val)
 {
     return(HOBD.t(val));
 }
示例#13
0
文件: HomePage.cs 项目: leewoody/hobd
        protected virtual PanoramaSection CreateMenuSection()
        {
            var section = CreateCommonSection(t("Settings"));

            var style = new TextStyle(HOBD.theme.PhoneTextNormalStyle);
            //style.FontSize = HOBD.theme.PhoneFontSizeLarge;

            var height0 = (layoutY - SectionContentDelta);
            var height  = height0 / 6;

            menuGrid = new Grid
            {
                Columns = new MeasureDefinition[] { layoutX / 3 - 20, layoutX / 3 - 20, layoutX / 3 - 20 },
                Rows    = new MeasureDefinition[] { height, height, height, height, height }
            };

            menuGrid[0, 0] = new DynamicElement(t("Reset trips"))
            {
                Style = style, HandleTapAction = (e) => { HOBD.Registry.TriggerReset(); }
            };
            menuGrid[1, 0] = new DynamicElement(t("Minimize"))
            {
                Style = style, HandleTapAction = (e) => { /* TODO */ }
            };
            menuGrid[2, 0] = new DynamicElement(t("Exit"))
            {
                Style           = style,
                HandleTapAction = (e) => Application.Exit()
            };

            menuGrid[0, 1] = new DynamicElement(t("Port settings"))
            {
                Style           = style,
                HandleTapAction = (e) => CreatePortSection()
            };
            menuGrid[1, 1] = new DynamicElement(t("Vehicle"))
            {
                Style           = style,
                HandleTapAction = (e) => CreateVehicleSection()
            };
            menuGrid[2, 1] = new DynamicElement(t("Theme"))
            {
                Style           = style,
                HandleTapAction = (e) => CreateThemeSection()
            };
            menuGrid[3, 1] = new DynamicElement(t("Language"))
            {
                Style           = style,
                HandleTapAction = (e) => CreateLanguageSection()
            };
            menuGrid[4, 1] = new DynamicElement(t("Display Units"))
            {
                Style           = style,
                HandleTapAction = (e) => this.PushVolatileSection(
                    new ListSection(t("Display Units"), null, layoutX, layoutY - SectionContentDelta)
                {
                    Selected     = HOBD.config.Units,
                    Content      = new string[] { "metric", "imperial" }.Select((s) => (object)s),
                    UIContent    = (l) => t((string)l),
                    ChooseAction = (l) => {
                        panorama.CurrentSectionIndex -= 1;
                        HOBD.config.Units             = (string)l;
                        HOBD.config.Save();
                        HOBD.ReloadUnits();
                        ReloadUI();
                    }
                })
            };


            menuGrid[0, 2] = new DynamicElement(t("Sensor push"))
            {
                Style           = style,
                HandleTapAction = (e) => CreateSensorPushSection()
            };

            section.AddElement(menuGrid);
            //, 10, 0, layoutX, height0

            var link = t("hobdrive.com");
            var info = new DynamicElement(link)
            {
                Style = new TextStyle(style)
                {
                    FontSize = HOBD.theme.PhoneFontSizeNormal
                },
                HandleTapAction = (e) => {
                    try{
                        System.Diagnostics.Process.Start(link, "");
                    }catch (Exception) {}
                }
            };

            section.AddElement(info);
            //, 10, height0 - 40, layoutX, 20

            return(section);
        }