protected void Page_Load(object sender, EventArgs e) { ArrayList nodeList = new ArrayList(); Node a = new Node("A"); nodeList.Add(a); a = new Node("A"); nodeList.Add(a); a.EdgeList.Add(new Edge("A", "B", 1)); a = new Node("B"); nodeList.Add(a); a.EdgeList.Add(new Edge("B", "C", 1)); a = new Node("A"); nodeList.Add(a); a.EdgeList.Add(new Edge("A", "B", 1)); a = new Node("C"); nodeList.Add(a); RoutePlanner planner = new RoutePlanner(); RoutePlanResult result = null; //Paln 函数是核心函数,首先将所有节点喂给模型,然后输入起点和终点,返回最优路径 result = planner.Paln(nodeList, "A", "C"); Response.Write("距离为" + result.getWeight()); printRouteResult(result); Response.Write("C"); //Response.Write("上海"); //Response.Write("<br>"); planner = null; //***************** A Node 北京 ******************* //Node aNode = new Node("北京"); //nodeList.Add(aNode); //aNode.EdgeList.Add(new Edge("北京", "上海", 20)); //aNode.EdgeList.Add(new Edge("北京", "武汉", 40)); }
private void GivenARoutePlanner() { var townPlanner = TownPlanner.Create(_streetSpecificationReader); townPlanner.LoadStreetSpecification(); _routeplanner = RoutePlanner.Create(townPlanner); }
public void MultiplyTreeCountsTest() { // Arrange var screenBuffer = new ScreenBuffer(_input); var routePlanner = new RoutePlanner(screenBuffer); var slopes = new[] { new SlopeModel { Right = 1, Down = 1 }, new SlopeModel { Right = 3, Down = 1 }, new SlopeModel { Right = 5, Down = 1 }, new SlopeModel { Right = 7, Down = 1 }, new SlopeModel { Right = 1, Down = 2 }, }; // Act var treeCount = routePlanner.MultiplyTreeCounts(slopes); // Assert Assert.That(treeCount, Is.EqualTo(336)); }
protected void Page_Load(object sender, EventArgs e) { string pointA = "北京"; string pointB = "上海"; ArrayList nodeList = new ArrayList(); Node aNode = new Node("北京"); nodeList.Add(aNode); aNode.EdgeList.Add(new Edge("北京", "上海", 20)); aNode.EdgeList.Add(new Edge("北京", "武汉", 60)); Node dNode = new Node("武汉"); nodeList.Add(dNode); dNode.EdgeList.Add(new Edge("武汉", "北京", 40)); //string output = JsonConvert.SerializeObject(nodeList); //File.WriteAllText(@Server.MapPath("~/data/ExampleSQL.json"), output); RoutePlanner planner = new RoutePlanner(); RoutePlanResult result = null; result = planner.Paln(nodeList, pointA, pointB); Response.Write("距离为" + result.getWeight()); printRouteResult(result); Response.Write(pointB); Response.Write("</br>"); planner = null; }
public void Start(Point src, string name, Orientation orientation) { route = new RoutePlanner(robot, map); StartRoutingTo(src, name); this.orientations.Add(orientation); this.names.Add(name); }
static void Main(string[] args) { DisplayTitle(); if (args.Length != 1) { DisplayUsage(); WaitForKeyPress(); return; } IStreetSpecificationReader fileReader = new StreetSpecificationFileReader(args[0]); ITownPlanner townplanner = TownPlanner.Create(fileReader); townplanner.LoadStreetSpecification(); var routeplanner = RoutePlanner.Create(townplanner); DisplayTownPlanningReport(townplanner); DisplayApproachOneReport(routeplanner); DisplayApproachTwoReport(routeplanner); WaitForKeyPress(); }
protected void BtnDijkstra_Click(object sender, EventArgs e) { string strPointAID, strPointBID; strPointAID = DdlPointA.SelectedValue; strPointBID = DdlPointB.SelectedValue; if (strPointAID.Equals(strPointBID)) { Response.Write("距离为: 0<br />路径: " + strPointAID); return; } try { // 调包, 运行Dijkstra算法 RoutePlanner planner = new RoutePlanner(); RoutePlanResult planResult = planner.Paln(arrayNodes, strPointAID, strPointBID); if (planResult.getWeight() < 100000) { Response.Write("距离为: " + planResult.getWeight().ToString()); PrintRouteResult(planResult); Response.Write(strPointBID + "<br />"); } else { Response.Write("无路径<br />"); } planner = null; } catch (Exception Ex) { Response.Write(Ex.Message); } }
protected void Page_Load(object sender, EventArgs e) { ArrayList nodeList = new ArrayList(); //Node aNode = new Node("北京"); //nodeList.Add(aNode); //aNode.EdgeList.Add(new Edge("北京", "上海", 20)); //aNode.EdgeList.Add(new Edge("北京", "武汉", 40)); Node bNode = new Node("上海"); nodeList.Add(bNode); bNode.EdgeList.Add(new Edge("上海", "北京", 20)); bNode.EdgeList.Add(new Edge("上海", "武汉", 70)); Node cNode = new Node("武汉"); nodeList.Add(cNode); cNode.EdgeList.Add(new Edge("武汉", "北京", 40)); cNode.EdgeList.Add(new Edge("武汉", "上海", 70)); RoutePlanner planner = new RoutePlanner(); RoutePlanResult result = null; result = planner.Paln(nodeList, "武汉", "上海"); Response.Write("距离为" + result.getWeight()); printRouteResult(result); Response.Write("上海"); Response.Write("<br />"); planner = null; }
private void GivenADefaultTownPlanner() { var townPlanner = TownPlanner.Create(new StreetSpecificationFileReader("street1.txt")); townPlanner.LoadStreetSpecification(); _routePlanner = RoutePlanner.Create(townPlanner); }
protected void Page_Load(object sender, EventArgs e) { ArrayList nodeList = new ArrayList();//结点的序列 //***************** A Node 北京 ******************* Node aNode = new Node("北京"); nodeList.Add(aNode); aNode.EdgeList.Add(new Edge("北京", "上海", 20)); aNode.EdgeList.Add(new Edge("北京", "武汉", 40)); //***************** B Node 上海******************* Node bNode = new Node("上海"); nodeList.Add(bNode); bNode.EdgeList.Add(new Edge("上海", "武汉", 70)); bNode.EdgeList.Add(new Edge("上海", "北京", 20)); //***************** D Node ******************* Node dNode = new Node("武汉"); nodeList.Add(dNode); dNode.EdgeList.Add(new Edge("武汉", "上海", 70)); dNode.EdgeList.Add(new Edge("武汉", "北京", 40)); RoutePlanner planner = new RoutePlanner(); RoutePlanResult result = null; //Paln函数是核心函数,首先将所有节点喂给模型,然后输入起点和终点,返回最优路径 result = planner.Paln(nodeList, "武汉", "上海"); Response.Write("距离为" + result.getWeight()); printRouteResult(result); Response.Write("上海"); Response.Write("<br>"); planner = null; }
public Vehicle(Warehouse homeLocation, Warehouse currentLocation, RoutePlanner routePlanner) { HomeLocation = homeLocation; CurrentLocation = currentLocation; this.routePlanner = routePlanner; CurrentOrder = null; SetRoute(null); }
protected void btnStart_Click(object sender, EventArgs e) { if (ddlStart.SelectedValue == "0" || ddlEnd.SelectedValue == "0") { Response.Write("<script>alert('Didn't Choose!');</script>"); return; } if (ddlStart.SelectedValue == ddlEnd.SelectedValue) { lblResult.Text = "There is no need to walk!"; return; } SQLHelper sh = new SQLHelper(); DataSet dsNodeList = new DataSet(); string sqlNodeList = ("SELECT [Location1] AS [Location] FROM [dbo].[TblLocation] UNION SELECT [Location2] FROM [dbo].[TblLocation]"); sh.RunSQL(sqlNodeList, ref dsNodeList); int nodeNumber = dsNodeList.Tables[0].Rows.Count; Node[] node = new Node[nodeNumber]; ArrayList nodeList = new ArrayList(); for (int i = 0; i < nodeNumber; i++) { node[i] = new Node(dsNodeList.Tables[0].Rows[i][0].ToString()); nodeList.Add(node[i]); } DataSet dsPath = new DataSet(); for (int i = 0; i < nodeNumber; i++) { string sqlNodePath = string.Format("SELECT [Location2] AS Location,[distance] FROM [dbo].[TblLocation] WHERE [Location1] = '{0}' UNION SELECT [Location1] AS Location,[distance] FROM [dbo].[TblLocation] WHERE [Location2] = '{0}' ", node[i].ID.ToString()); sh.RunSQL(sqlNodePath, ref dsPath); for (int j = 0; j < dsPath.Tables[0].Rows.Count; j++) { node[i].EdgeList.Add(new Edge(node[i].ID.ToString(), dsPath.Tables[0].Rows[j][0].ToString(), double.Parse(dsPath.Tables[0].Rows[j][1].ToString()))); } dsPath = null; } sh.Close(); sh = null; RoutePlanner planner = new RoutePlanner(); RoutePlanResult result = planner.Paln(nodeList, ddlStart.SelectedValue, ddlEnd.SelectedValue); lblResult.Text = "Distance:" + result.getWeight().ToString() + " Route:" + DetailedRoute(result); planner = null; }
private static void DisplayApproachOneReport(RoutePlanner routeplanner) { System.Console.WriteLine(); System.Console.WriteLine("Newspaper delivery report (Story 2)"); System.Console.WriteLine("-----------------------------------"); System.Console.WriteLine(); System.Console.WriteLine("Appraoch one delivery order: {0}", string.Join(", ", routeplanner.GetDeliveryByNorthSideThenSouthSide())); System.Console.WriteLine("Appraoch one total road crossings: {0}", routeplanner.TotalRoadCrossing()); }
/// <summary> /// Service constructor /// </summary> public TrackroamerLocationAndMappingService(DsspServiceCreationPort creationPort) : base(creationPort) { _routePlanner = new RoutePlanner(_mapperVicinity); _mapperVicinity.robotDirection = new Direction() { heading = 45.0d, bearing = 110.0d }; }
public WaypointController(int unitId, LoggingManager log, INetworkDatabase network) { _network = network; _routePlanner = new RoutePlanner(network); _log = log; var eh = _log.GetEntityHandle(this.GetType(), unitId); _infoPin = _log.GetSignalPin(eh, "info"); _statePin = _log.GetSignalPin(eh, "state"); }
public void setMapper(MapperVicinity mapper, RoutePlanner routePlanner) { if (mapWindow != null) { _mapperVicinity = mapper; _routePlanner = routePlanner; mapWindow.mapperViewControl1.CurrentMapper = mapper; mapWindow.mapperViewControl1.CurrentRoutePlanner = routePlanner; } }
public Simulation() { var routeValidator = new RouteValidator(); var routeFactory = Route.Factory(routeValidator); var routePlanner = new RoutePlanner(routeFactory); var transportManager = new TransportManager(); _deliveryManager = new DeliveryManager(routePlanner, transportManager); }
public void Start(Point src, List <String> names, List <Orientation> orientations) { route = new RoutePlanner(robot, map); StartRoutingTo(src, names[0]); this.orientations.AddRange(orientations); this.names.AddRange(names); // var rec = FindStageRegion(name); // Point p = FindDestinationPoint(Rectangle.Round(rec)); // route.Start(src, p); // this.orientation = orientation; }
private void ComputeRoute(object sender, EventArgs args) { int jumpsPerLeg = 4; int maxJumps = 6; var jumpDistance = FloatHelper.AsFloat(MaxJumpDistance.Text); if (Math.Abs(jumpDistance) < 0.0000001f) { MessageBox.Show("Please enter a valid floating point jump distance.", "F**k!", MessageBoxButtons.OK); return; } var idealSellDistance = FloatHelper.AsFloat(IdealSellDistance.Text); if (Math.Abs(idealSellDistance) < 0.0000001f) { MessageBox.Show("Please enter a valid floating point jump distance.", "F**k!", MessageBoxButtons.OK); return; } try { jumpsPerLeg = Convert.ToInt32(JumpsPerLeg.Text); } catch { MessageBox.Show("Please enter a valid number of legs per jump.", "F**k!", MessageBoxButtons.OK); return; } try { maxJumps = Convert.ToInt32(MaxJumps.Text); } catch { MessageBox.Show("Please enter a valid number of max jumps.", "F**k!", MessageBoxButtons.OK); return; } if (!ValidateComboBox(CurrentSystem)) { return; } RoutePlanner planner = new RoutePlanner(availableRares.Values.ToList(), jumpDistance); StarSystem start = galaxy.Systems[CurrentSystem.Text]; currentRoute = planner.FindRoute(start, idealSellDistance, jumpsPerLeg, maxJumps); OnRouteUpdated(); }
public void CountTreesTest(int right, int down, int expectedTreeCount) { // Arrange var screenBuffer = new ScreenBuffer(_input); var routePlanner = new RoutePlanner(screenBuffer); // Act var treeCount = routePlanner.CountTrees(new SlopeModel { Right = right, Down = down }); // Assert Assert.That(treeCount, Is.EqualTo(expectedTreeCount)); }
public void planRoute() { MapperVicinity mv = mapperViewControl1.CurrentMapper; RoutePlanner routePlanner = mapperViewControl1.CurrentRoutePlanner; RoutePlan plan = routePlanner.planRoute(); bestHeadingLabel.Content = "Best Heading abs=" + (plan.bestHeading.HasValue ? Math.Round((double)plan.bestHeading).ToString() : "N/A") + " rel (turn)=" + (plan.bestHeading.HasValue ? Math.Round((double)plan.bestHeading).ToString() : "N/A"); closestObstacleLabel.Content = "ClosestObstacle at " + (plan.closestObstacleMeters.HasValue ? (Math.Round((double)plan.closestObstacleMeters, 2).ToString() + " m") : "N/A"); legLengthLabel.Content = "Leg Length = " + (plan.legMeters.HasValue ? (Math.Round((double)plan.legMeters, 2).ToString() + " m") : "N/A (turn only)"); timeSpentLabel.Content = plan.timeSpentPlanning.ToString(); mapperViewControl1.RedrawMap(); }
private void navigateBtn_Click(object sender, EventArgs e) { CreatePathForm createPathForm = new CreatePathForm(); createPathForm.map = map; createPathForm.FormClosing += (o, form) => { route = new RoutePlanner(robot, map); var src = new Point(Int32.Parse(createPathForm.srcXTextBox.Text), Int32.Parse(createPathForm.srcYTextBox.Text)); var dest = new Point(Int32.Parse(createPathForm.dstXtextBox.Text), Int32.Parse(createPathForm.dstYTextBox.Text)); route.Start(src, dest); Timer1.Enabled = true; }; createPathForm.Show(); }
static void Main(string[] args) { // 构造一个 图. Graph graph = new Graph(); graph.Init(); // 最短路径计算. RoutePlanner planner = new RoutePlanner(); RoutePlanResult result = planner.Paln(graph.NodeList, "A", "D"); // 输出结果. Console.WriteLine(result.ToString()); Console.ReadLine(); }
/// <summary> /// 从源星球到目标星球的最短路径(待优化:保存源星球的最短路径表,下次寻找不必再次运算算法) /// </summary> /// <param name="StartStar">源星球</param> /// <param name="EndStar">目标星球</param> /// <returns>所有经过的星球(包括目标星球)</returns> public static RoutePlanResult Plan(UnitStar StartStar, UnitStar EndStar) { RoutePlanResult result = new RoutePlanResult(); //在调用最短路径算法前, Node.CheckNodeCanReach先判断目标节点是否在源节点移动半径内,是的话直接返回源节点(两点之间,直线最短) if (StartStar.CheckStarReachByDistance(EndStar) == true) { result.PassedStars.Add(StartStar); result.PassedStars.Add(EndStar); result.Weight = StartStar.GetTargetStarDistance(EndStar); } else { RoutePlanner planner = new RoutePlanner(); result = planner.Paln(MogoWorld.m_dataMapManager.GetStarList(), StartStar.UnitId, EndStar.UnitId); result.PassedStars.Add(EndStar); planner = null; } return(result); }
protected void Button1_Click(object sender, EventArgs e) { RoutePlanner planner = new RoutePlanner(); RoutePlanResult result = null; result = planner.Paln(nodeList, ddlStart.SelectedValue, ddlEnd.SelectedValue); //当路径的权值返回是double的最大值,就认为,两点间的距离是正无穷,也就是不通的 double aim = Math.Abs(result.getWeight() - double.MaxValue); string finalpath = string.Format("{0}到{1}的路径是:", ddlStart.SelectedValue, ddlEnd.SelectedValue); Response.Write(finalpath); if (aim <= 0) { Response.Write("距离为正无穷"); } else { Response.Write("距离为" + result.getWeight()); //输出路径 printRouteResult(result); } planner = null; }
protected void Button1_Click(object sender, EventArgs e) { string pointA = ddlPointA.SelectedItem.Text; string pointB = ddlPointB.SelectedItem.Text; if (pointA == pointB) { Response.Write("不能起始地为同一处!"); } else { //生成图 ArrayList nodeList = new ArrayList(); string sql = "select PointA from tblDistance2020 group by PointA"; SQLHelper sh1 = new SQLHelper(); DataTable dt = new DataTable(); DataSet ds = new DataSet(); try { sh1.RunSQL(sql, ref ds); if (ds.Tables[0] != null) { dt = ds.Tables[0]; if (dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { Node node = new Node(dr[0].ToString()); nodeList.Add(node); string sql2 = string.Format("select * from tblDistance2020 where PointA='{0}'", dr[0].ToString()); SQLHelper sh2 = new SQLHelper(); DataTable dt2 = new DataTable(); DataSet ds2 = new DataSet(); sh2.RunSQL(sql2, ref ds2); if (ds2.Tables[0] != null) { dt2 = ds2.Tables[0]; if (dt2.Rows.Count > 0) { foreach (DataRow dr2 in dt2.Rows) { node.EdgeList.Add(new Edge(dr2[1].ToString(), dr2[2].ToString(), double.Parse(dr2[3].ToString()))); } } } sh2.Close(); } } } } catch (Exception ex) { Response.Write(ex.Message); } finally { sh1.Close(); } RoutePlanner planner = new RoutePlanner(); RoutePlanResult result = null; try { result = planner.Paln(nodeList, pointA, pointB); Response.Write("距离为" + result.getWeight()); printRouteResult(result); Response.Write(pointB); Response.Write("</br>"); planner = null; } catch { Response.Write("两地不能到达!"); } } }
protected void Button1_Click(object sender, EventArgs e) { //需要四个sql,sh,ds,dt,row string sqla1, sqla2, sqlb1, sqlb2; string ca = ""; string cb = ""; string start = ddl1.SelectedValue; string end = ddl2.SelectedValue; SQLHelper sha1 = new SQLHelper(); SQLHelper sha2 = new SQLHelper(); SQLHelper shb1 = new SQLHelper(); SQLHelper shb2 = new SQLHelper(); DataSet dsa1 = new DataSet(); DataSet dsb1 = new DataSet(); DataTable dta1, dta2, dtb1, dtb2; DataRow[] ra1, ra2, rb1, rb2; ArrayList nodeList = new ArrayList(); //思路:遍历A,对A的每一个城市,遍历所有路径;然后遍历B中不在A中的城市,同样遍历路径 //介于debug次数过多,把快捷的debug方法写在这里提醒自己:通过response.write监视nodelist的录入 sqla1 = "select PointA from students.dbo.tblDistance group by PointA"; sha1.RunSQL(sqla1, ref dsa1); dta1 = dsa1.Tables[0]; ra1 = dta1.Select("PointA is not null"); sha1.Close(); for (int i = 0; i <= dta1.Rows.Count - 1; i++) { ca = ra1[i]["PointA"].ToString(); Node a = new Node(ca); nodeList.Add(a); DataSet dsa2 = new DataSet(); //dsa2、dsb2一定要在for循环内反复声明,以清空set内存;否则,新ref到的数据会加入到Tables[0]中而非替换之 sqla2 = string.Format("select PointA,PointB,Distance from students.dbo.tblDistance where PointA='{0}' group by PointA,PointB,Distance", ca); sha2.RunSQL(sqla2, ref dsa2); dta2 = dsa2.Tables[0]; ra2 = dta2.Select("PointA is not null"); sha2.Close(); for (int j = 0; j <= dta2.Rows.Count - 1; j++) { cb = ra2[j]["PointB"].ToString(); a.EdgeList.Add(new Edge(ca, cb, double.Parse(ra2[j]["Distance"].ToString()))); } } sqlb1 = "select PointB from (select PointB from students.dbo.tblDistance group by PointB)B left join (select PointA from students.dbo.tblDistance group by PointA)A on A.PointA=B.PointB where PointA is null"; shb1.RunSQL(sqlb1, ref dsb1); dtb1 = dsb1.Tables[0]; rb1 = dtb1.Select("PointB is not null"); shb1.Close(); for (int i = 0; i <= dtb1.Rows.Count - 1; i++) { cb = rb1[i]["PointB"].ToString(); DataSet dsb2 = new DataSet(); sqlb2 = string.Format("select PointA,PointB,Distance from students.dbo.tblDistance where PointB='{0}' group by PointA,PointB,Distance", cb); shb2.RunSQL(sqlb2, ref dsb2); dtb2 = dsb2.Tables[0]; rb2 = dtb2.Select("PointB is not null"); shb2.Close(); Node b = new Node(cb); nodeList.Add(b); for (int j = 0; j <= dtb2.Rows.Count - 1; j++) { ca = rb2[j]["PointA"].ToString(); b.EdgeList.Add(new Edge(cb, ca, double.Parse(rb2[j]["Distance"].ToString()))); } } RoutePlanner planner = new RoutePlanner(); RoutePlanResult result = null; if (start == end) { Response.Write("距离为0"); } else { result = planner.Paln(nodeList, start, end); if (result.getWeight() > 100000000) { Response.Write("两地无通路!"); } else { Response.Write("距离为" + result.getWeight()); printRouteResult(result); Response.Write(end + "</br>"); planner = null; } } }
public Route Action(RoutePlanner rp) { return(null); //rp.PlanRoute(); }
protected double robotCornerDistanceMeters = 0.0d; // to account for robot dimensions when adding measurements from corner-located proximity sensors. public MainWindow() { InitializeComponent(); routePlanner = new RoutePlanner(mapperVicinity); this.Closing += new System.ComponentModel.CancelEventHandler(MainWindow_Closing); //create picpxmod device. _picpxmod = new ProximityModule(0x0925, 0x7001); // see PIC Firmware - usb_descriptors.c lines 178,179 _picpxmod.HasReadFrameEvent += pmFrameCompleteHandler; _picpxmod.DeviceAttachedEvent += new EventHandler <ProximityModuleEventArgs>(_picpxmod_DeviceAttachedEvent); _picpxmod.DeviceDetachedEvent += new EventHandler <ProximityModuleEventArgs>(_picpxmod_DeviceDetachedEvent); bool deviceAttached = _picpxmod.FindTheHid(); pmValuesLabel.Content = deviceAttached ? "Proximity Board Found" : string.Format("Proximity Board NOT Found\r\nYour USB Device\r\nmust have:\r\n vendorId=0x{0:X}\r\nproductId=0x{1:X}", _picpxmod.vendorId, _picpxmod.productId); mapperVicinity.robotPosition = (GeoPosition)robotPositionDefault.Clone(); mapperVicinity.robotDirection = (Direction)robotDirectionDefault.Clone(); // we will need this later: robotCornerDistanceMeters = Math.Sqrt(mapperVicinity.robotState.robotLengthMeters * mapperVicinity.robotState.robotLengthMeters + mapperVicinity.robotState.robotWidthMeters * mapperVicinity.robotState.robotWidthMeters) / 2.0d; // --------- debug ------------ GeoPosition pos1 = (GeoPosition)mapperVicinity.robotPosition.Clone(); //pos1.translate(new Distance(1.0d), new Distance(1.0d)); // geo coordinates - East North pos1.translate(new Direction() { heading = mapperVicinity.robotDirection.heading, bearingRelative = 45.0d }, new Distance(1.0d)); // robot coordinates - forward right DetectedObstacle dobst1 = new DetectedObstacle(pos1) { color = Colors.Red }; mapperVicinity.Add(dobst1); GeoPosition pos2 = (GeoPosition)mapperVicinity.robotPosition.Clone(); //pos2.translate(new Distance(-1.0d), new Distance(1.0d)); // geo coordinates - West North pos2.translate(new Direction() { heading = mapperVicinity.robotDirection.heading, bearingRelative = -45.0d }, new Distance(1.0d)); // robot coordinates - forward left DetectedObstacle dobst2 = new DetectedObstacle(pos2) { color = Colors.Yellow }; //mapperVicinity.Add(dobst2); mapperVicinity.computeMapPositions(); // --------- end debug ------------ }
//Show Departures Method public void ShowDepartures(string FromCRS, string ToCRS) { //Show this view and hide the empty departures list. _TrainDeparturesLayout.Visibility = ViewStates.Gone; _TrainDeparturesLoading.Visibility = ViewStates.Visible; _RootLayout.Visibility = ViewStates.Visible; //Download departures data new Thread(() => { RoutePlanner.RequestStatus RequestStatus; RouteSummary[] DeparturesData = new RoutePlanner().GetRouteInfo(FromCRS, ToCRS, out RequestStatus); //On the UI thread, create result views. if (RequestStatus == RoutePlanner.RequestStatus.OK) { Activity.RunOnUiThread(() => { _TrainDeparturesLayout.RemoveAllViews(); //Draw departures list for (int i = 0; i < DeparturesData.Length; i++) { int LocalIndex = i; LinearLayout lTrainTimeBack = new LinearLayout(this.Context); lTrainTimeBack.LayoutParameters = RtGraphicsLayouts.LayoutParameters(RtGraphicsLayouts.EXPAND, 150); lTrainTimeBack.Orientation = Orientation.Vertical; lTrainTimeBack.SetDpPadding(RtGraphicsLayouts, 2, 2, 2, 2); lTrainTimeBack.SetBackgroundResource(Resource.Drawable.StyleCornerBox); _TrainDeparturesLayout.AddView(lTrainTimeBack); LinearLayout lTrainTimeContent = new LinearLayout(this.Context); lTrainTimeContent.LayoutParameters = RtGraphicsLayouts.LayoutParameters(RtGraphicsLayouts.EXPAND, 100); lTrainTimeBack.AddView(lTrainTimeContent); LinearLayout lTrainTimeContentTOCBar = new LinearLayout(this.Context); lTrainTimeContentTOCBar.LayoutParameters = RtGraphicsLayouts.LayoutParameters(RtGraphicsLayouts.EXPAND, 44); lTrainTimeBack.AddView(lTrainTimeContentTOCBar); LinearLayout lTrainTimeArrival = new LinearLayout(this.Context); lTrainTimeArrival.LayoutParameters = RtGraphicsLayouts.LayoutParameters(-550, RtGraphicsLayouts.EXPAND); lTrainTimeArrival.Orientation = Orientation.Vertical; lTrainTimeArrival.SetDpPadding(RtGraphicsLayouts, 0, 50, 0, 0); lTrainTimeContent.AddView(lTrainTimeArrival); LinearLayout lTrainTimeDuration = new LinearLayout(this.Context); lTrainTimeDuration.LayoutParameters = RtGraphicsLayouts.LayoutParameters(-400, RtGraphicsLayouts.EXPAND); lTrainTimeContent.AddView(lTrainTimeDuration); LinearLayout lTrainTimeDeparture = new LinearLayout(this.Context); lTrainTimeDeparture.LayoutParameters = RtGraphicsLayouts.LayoutParameters(-550, RtGraphicsLayouts.EXPAND); lTrainTimeDeparture.Orientation = Orientation.Vertical; lTrainTimeDeparture.SetDpPadding(RtGraphicsLayouts, 0, 50, 0, 0); lTrainTimeContent.AddView(lTrainTimeDeparture); TextView DepartureTime = new TextView(this.Context); DepartureTime.LayoutParameters = RtGraphicsLayouts.LayoutParameters(RtGraphicsLayouts.EXPAND, RtGraphicsLayouts.EXPAND); DepartureTime.TextSize = 16; DepartureTime.Text = DeparturesData[i].DepartureTime; DepartureTime.Gravity = GravityFlags.Center; lTrainTimeDeparture.AddView(DepartureTime); TextView ArrivalTime = new TextView(this.Context); ArrivalTime.LayoutParameters = RtGraphicsLayouts.LayoutParameters(RtGraphicsLayouts.EXPAND, RtGraphicsLayouts.EXPAND); ArrivalTime.TextSize = 16; ArrivalTime.Text = DeparturesData[i].ArrivalTime; ArrivalTime.Gravity = GravityFlags.Center; lTrainTimeArrival.AddView(ArrivalTime); ////////////////////////////////////////////////// // // // // // // // // // // // // ////////////////////////////////////////////////// // Textview Stuff textview // Departure Time Arrival Time LinearLayout lVert = new LinearLayout(this.Context); lVert.LayoutParameters = RtGraphicsLayouts.LayoutParameters(RtGraphicsLayouts.EXPAND, RtGraphicsLayouts.EXPAND); lVert.SetDpPadding(RtGraphicsLayouts, 25, 0, 0, 0); lVert.Orientation = Orientation.Vertical; lTrainTimeContent.AddView(lVert); LinearLayout lHori1 = new LinearLayout(this.Context); lVert.AddView(lHori1); ImageView DepartureIcon = new ImageView(this.Context); DepartureIcon.LayoutParameters = RtGraphicsLayouts.LayoutParameters(50, 50); DepartureIcon.SetImageResource(Resource.Drawable.Icon_DeparturesFrom); lHori1.AddView(DepartureIcon); TextView JourneyTime = new TextView(this.Context); JourneyTime.TextSize = 16; //JourneyTime.Text = DeparturesData[i].durationHours + "h " + ((DeparturesData[i].durationMinutes.Length == 1) ? "0" + DeparturesData[i].durationMinutes : DeparturesData[i].durationMinutes) + "m"; JourneyTime.SetTextColor(RtGraphicsColours.GreyLightest); lHori1.AddView(JourneyTime); ImageView ArrivalIcon = new ImageView(this.Context); ArrivalIcon.LayoutParameters = RtGraphicsLayouts.LayoutParameters(50, 50); ArrivalIcon.SetImageResource(Resource.Drawable.Icon_DeparturesTo); lHori1.AddView(ArrivalIcon); LinearLayout lHori = new LinearLayout(this.Context); lVert.AddView(lHori); TextView tPlannedArrival = new TextView(this.Context); tPlannedArrival.SetTextColor(Android.Graphics.Color.Gray); //tPlannedArrival.Text = DeparturesData[i].changes + " Changes"; lHori.AddView(tPlannedArrival); TextView tActualArrival = new TextView(this.Context); tActualArrival.SetTextColor(Android.Graphics.Color.LightGray); tActualArrival.SetDpPadding(RtGraphicsLayouts, 25, 0, 0, 0); //tActualArrival.Text = DeparturesData[i].statusMessage; lHori.AddView(tActualArrival); if (tActualArrival.Text == "on time") { tActualArrival.Text = "On Time"; tActualArrival.SetTextColor(Android.Graphics.Color.DarkGreen); } else if (tActualArrival.Text == "Ca:nc") { tActualArrival.SetTextColor(Android.Graphics.Color.DarkRed); } else if (tActualArrival.Text == "null") { tActualArrival.Visibility = ViewStates.Gone; } LinearLayout lSpacer = new LinearLayout(this.Context); lSpacer.LayoutParameters = RtGraphicsLayouts.LayoutParameters(RtGraphicsLayouts.EXPAND, 20); _TrainDeparturesLayout.AddView(lSpacer); } //lTrainTimeBack.Click += delegate { Callback?.Invoke(DeparturesData[LocalIndex]); }; //Once all drawn, show departures list _TrainDeparturesLayout.Visibility = ViewStates.Visible; _TrainDeparturesLoading.Visibility = ViewStates.Gone; }); } else if (RequestStatus == RoutePlanner.RequestStatus.ERROR) { Activity.RunOnUiThread(() => { _TrainDeparturesLayout.RemoveAllViews(); TextView FromSearchEmpty = new TextView(this.Context); FromSearchEmpty.LayoutParameters = RtGraphicsLayouts.LayoutParameters(RtGraphicsLayouts.EXPAND, 400); FromSearchEmpty.Gravity = GravityFlags.Center; FromSearchEmpty.Format(RtGraphicsExt.TextFormats.Paragraph1); FromSearchEmpty.Text = "No Connection."; _TrainDeparturesLayout.AddView(FromSearchEmpty); _TrainDeparturesLayout.Visibility = ViewStates.Visible; _TrainDeparturesLoading.Visibility = ViewStates.Gone; }); } else if (RequestStatus == RoutePlanner.RequestStatus.EMPTY) { Activity.RunOnUiThread(() => { _TrainDeparturesLayout.RemoveAllViews(); TextView FromSearchEmpty = new TextView(this.Context); FromSearchEmpty.LayoutParameters = RtGraphicsLayouts.LayoutParameters(RtGraphicsLayouts.EXPAND, 400); FromSearchEmpty.Gravity = GravityFlags.Center; FromSearchEmpty.Format(RtGraphicsExt.TextFormats.Paragraph1); FromSearchEmpty.Text = "No Departures."; _TrainDeparturesLayout.AddView(FromSearchEmpty); _TrainDeparturesLayout.Visibility = ViewStates.Visible; _TrainDeparturesLoading.Visibility = ViewStates.Gone; }); } }).Start(); }