protected void CreateItems() { var style = new TextStyle(HOBD.theme.PhoneTextNormalStyle); if (grid != null) { this.Remove(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.Add(grid, 0, 0, LayoutX, LayoutY); }
private PanoramaSection CreateHorizontalFeaturedSection() { var img1 = ResourceManager.Instance.GetBitmapFromEmbeddedResource("thumbnail.png"); var img2 = ResourceManager.Instance.GetBitmapFromEmbeddedResource("squareimg.png"); var img3 = ResourceManager.Instance.GetBitmapFromEmbeddedResource("thumbnail2.png"); var img4 = ResourceManager.Instance.GetBitmapFromEmbeddedResource("thumbnail3.png"); var imageSize = new Size(190, 150); var grid = new Grid { Columns = new MeasureDefinition[] { 200, 200, 200, 200 }, Rows = new MeasureDefinition[] { 160, 160 } }; grid[0, 0] = new ImageElement(img1) { Size = imageSize }; grid[0, 1] = new ImageElement(img2) { Size = imageSize }; grid[0, 2] = new ImageElement(img3) { Size = imageSize }; grid[0, 3] = new ImageElement(img4) { Size = imageSize }; grid[1, 0] = new ImageElement(img3) { Size = imageSize }; grid[1, 1] = new ImageElement(img4) { Size = imageSize }; grid[1, 2] = new ImageElement(img1) { Size = imageSize }; grid[1, 3] = new ImageElement(img2) { Size = imageSize }; var section = new PanoramaSection("features"); section.AddElement(grid); //, 0, 0, 480, 320 return section; }
private PanoramaSection CreateFeaturedSection() { var img1 = ResourceManager.Instance.GetBitmapFromEmbeddedResource("thumbnail.png"); var img2 = ResourceManager.Instance.GetBitmapFromEmbeddedResource("squareimg.png"); var img3 = ResourceManager.Instance.GetBitmapFromEmbeddedResource("thumbnail2.png"); var titleStyle = new TextStyle(HOBD.theme.PhoneFontFamilySemiBold, HOBD.theme.PhoneFontSizeLarge, Color.White); var subtitleStyle = HOBD.theme.PhoneTextBlockBase; var moreStyle = new TextStyle(HOBD.theme.PhoneTextLargeStyle.FontFamily, HOBD.theme.PhoneFontSizeMediumLarge, HOBD.theme.PanoramaNormalBrush); var section = new PanoramaSection("small"); var grid = new Grid { Columns = new MeasureDefinition[] { 120, 180 }, Rows = new MeasureDefinition[] { 70, 50, 70, 50, 70, 50, 75 } }; grid[0, 0] = new ImageElement(img1) { Size = new Size(100, 100) }; grid[0, 1] = new DynamicElement("ONE") { Style = titleStyle }; grid[1, 1] = new DynamicElement("LOREM IPSUM LOREM") { Style = subtitleStyle }; grid[2, 0] = new ImageElement(img2) { Size = new Size(100, 100) }; grid[2, 1] = new DynamicElement("TWO") { Style = titleStyle }; grid[3, 1] = new DynamicElement("LOREM IPSUM LOREM") { Style = subtitleStyle }; grid[4, 0] = new ImageElement(img3) { Size = new Size(100, 100) }; grid[4, 1] = new DynamicElement("THREE") { Style = titleStyle }; grid[5, 1] = new DynamicElement("LOREM IPSUM LOREM") { Style = subtitleStyle }; grid[6, 1] = new TextElement("more") { Style = moreStyle }; section.AddElement(grid); // , 0, 0, 300, 700 return section; }
protected virtual void LoadSections() { try{ XmlReaderSettings xrs = new XmlReaderSettings(); xrs.IgnoreWhitespace = true; xrs.IgnoreComments = true; XmlReader reader = XmlReader.Create(Path.Combine(HOBD.AppPath, HOBD.config.Layout), xrs); reader.Read(); reader.ReadStartElement("ui"); while( reader.IsStartElement("section") ){ var title = t(reader.GetAttribute("name")); var section = CreateCommonSection(title); reader.ReadStartElement("section"); if (reader.IsStartElement("grid")){ var rows = reader.GetAttribute("rows"); var cols = reader.GetAttribute("cols"); var rows_a = rows.Split(seps).Select(r => r.Trim().Length == 0 ? 0 : int.Parse(r.Trim())); var cols_a = cols.Split(seps).Select(r => r.Trim().Length == 0 ? 0 : int.Parse(r.Trim())); var converted = new IEnumerable<int>[]{rows_a, cols_a}.Select( arr => { var arr_s = arr.Sum(); if (arr_s < 100){ var count = arr.Count(r => r == 0); if (count > 0){ int autosize = (100-arr_s) / count; arr = arr.Select( r => r == 0 ? autosize : r); } } return arr; }).ToList(); rows_a = converted[0].Select(r => r * this.layoutY / 100); cols_a = converted[1].Select(r => r * this.layoutX / 100); var grid = new Grid { Columns = cols_a.Select(r => (MeasureDefinition)r).ToArray(), Rows = rows_a.Select(r => (MeasureDefinition)r).ToArray(), }; int crow = 0, ccol = 0; reader.ReadStartElement("grid"); while(reader.IsStartElement("item")){ var attrs = new Dictionary<string, string>(); while (reader.MoveToNextAttribute()) { attrs.Add(reader.Name, reader.Value); } reader.MoveToElement(); reader.ReadStartElement("item"); // attrs var sensorItem = CreateItem(attrs, section); if (sensorItem != null) { grid.Add(crow, ccol, sensorItem); } // next item in grid ccol++; if (ccol == cols_a.Count()){ ccol = 0; crow++; } if (crow == rows_a.Count()){ break; } } grid.Location = new Point(10, 0); grid.Size = new Size(layoutX, layoutY-SectionContentDelta); section.AddElement(grid); reader.ReadEndElement(); } this.panorama.AddSection(section); reader.ReadEndElement(); } }catch(XmlException e){ Logger.error("HomePage", "error creating layout", e); } }
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; }
protected void CreateItems() { var style = new TextStyle(HOBD.theme.PhoneTextNormalStyle); Grid grid; int height = LayoutY/4; grid = new Grid { Columns = new MeasureDefinition[] { LayoutX/2, LayoutX/2 }, Rows = new MeasureDefinition[] { height, height, height, height } }; int idx = 0, idx2 = 0; foreach(var p in Content) { string label = UIContent(p); if (p.Equals(Selected)){ label = ">> " + label; } var e = new IconTextElement("icon.png", label){ HandleTapAction = OnChoose }; uiMapping.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 }