コード例 #1
0
        private void SwapFromTo()
        {
            //Swap Text in boxes.
            string TmpText = FromSearchText.Text;

            FromSearchText.Text = ToSearchText.Text;
            ToSearchText.Text   = TmpText;

            //Swap visibility states of hints.
            ViewStates TmpViewState = FromSearchHint.Visibility;

            FromSearchHint.Visibility = ToSearchHint.Visibility;
            ToSearchHint.Visibility   = TmpViewState;

            //Swap Data stored in variables
            RtStationData TmpStation = FromStation;

            FromStation = ToStation;
            ToStation   = TmpStation;

            //If both data not null, start a departure search.
            if (FromStation != null && ToStation != null)
            {
                RtTrainDeparturesView.ShowDepartures(FromStation.Code, ToStation.Code);
            }
        }
コード例 #2
0
        //Main thing
        public RtStationData[] SearchStations(string SearchQuery, int MaxResults, RtGPS SortDistance, bool NavigableOnly)
        {
            //Create empty return variable
            List <RtStationData> StationResults = new List <RtStationData>();

            //Check input parameter is valid
            if (SearchQuery.Length != ZEROLENGTH)
            {
                //Check if input is three capital letters
                if (SearchQuery.Length == THREELENGTH && SearchQuery.ToUpper() == SearchQuery)
                {
                    //Search by CRS Code
                    StationResults = RtStations.SearchByCRS(SearchQuery).ToList();
                }
                else
                {
                    //Search by Name
                    StationResults = RtStations.SearchByName(SearchQuery, MaxResults).ToList();
                }
            }

            //If Navigable Only, filter
            if (NavigableOnly)
            {
                //Loop through results, if not navigable, remove and minus iterator
                for (int i = 0; i < StationResults.Count; i++)
                {
                    if (!NAVIGABLESTATIONS.Contains(StationResults[i].Code))
                    {
                        StationResults.Remove(StationResults[i]);
                        i--;
                    }
                }
            }

            if (SortDistance != null)
            {
                //Create GPS Instance in another thread.
                for (int z = 0; z < StationResults.Count - 1; z++)
                {
                    for (int i = 0; i < StationResults.Count - 1; i++)
                    {
                        if (SortDistance.DistanceFromLatLonInKm(StationResults[i + 1].Latitude, StationResults[i + 1].Longitude, SortDistance.Latitude, SortDistance.Longitude) <
                            SortDistance.DistanceFromLatLonInKm(StationResults[i].Latitude, StationResults[i].Longitude, SortDistance.Latitude, SortDistance.Longitude))
                        {
                            RtStationData tmp = StationResults[i];
                            StationResults[i]     = StationResults[i + 1];
                            StationResults[i + 1] = tmp;
                        }
                    }
                }
            }

            //SearchQuery Invalid
            return(StationResults.ToArray());
        }
コード例 #3
0
        private void StationSearchDialog_StationSelected(int DialogID, RtStationData RtStationData)
        {
            if (DialogID == 0)
            {
                FromSearchText.Text = RtStationData.StationName;
                FromSearchHint.Visibility = ViewStates.Gone;
                FromStation = RtStationData;
            }
            else
            {
                ToSearchText.Text = RtStationData.StationName;
                ToSearchHint.Visibility = ViewStates.Gone;
                ToStation = RtStationData;
            }

            if (FromStation != null && ToStation != null)
                RtTrainDeparturesView.ShowDepartures(FromStation.Code, ToStation.Code);
        }
コード例 #4
0
        //Draw results
        private void DrawResults(LinearLayout ResultsRoot, RtGPS GPS)
        {
            //If GPS sending position
            if ((GPS.Ready && Option_SearchLocation) || !Option_SearchLocation)
            {
                //Search stations
                RtStationData[] data = new RtStations().SearchStations(SearchInput.Text, MAXSEARCHRESULTS, (Option_SearchLocation) ? GPS : null, Option_SearchNavigable);

                //Clear Results View
                ResultsRoot.RemoveAllViews();

                //Loop through stations data
                for (int i = 0; i < data.Length; i++)
                {
                    //Create a local copy of variable for click event
                    RtStationData localdat = data[i];

                    //Result Back
                    LinearLayout ResultBack = new LinearLayout(this.Context);
                    ResultBack.LayoutParameters = RtGraphicsLayouts.LayoutParameters(RtGraphicsLayouts.EXPAND, DIALOGRESULTHEIGHT);
                    ResultBack.SetDpPadding(RtGraphicsLayouts, SMALLPADDING, SMALLPADDING, SMALLPADDING, SMALLPADDING);
                    ResultBack.SetGravity(GravityFlags.CenterVertical);
                    ResultsRoot.AddView(ResultBack);

                    //Result Station Name
                    TextView ResultStationName = new TextView(this.Context);
                    ResultStationName.Format(RtGraphicsExt.TextFormats.Paragraph);
                    ResultStationName.Text = data[i].StationName;
                    ResultBack.AddView(ResultStationName);

                    //Result Station CRS
                    TextView ResultCRS = new TextView(this.Context);
                    ResultCRS.LayoutParameters = RtGraphicsLayouts.LayoutParameters(RtGraphicsLayouts.EXPAND, RtGraphicsLayouts.CONTAIN);
                    ResultCRS.SetDpPadding(RtGraphicsLayouts, ZERO, ZERO, SMALLPADDING, ZERO);
                    ResultCRS.Format(RtGraphicsExt.TextFormats.Paragraph1);
                    ResultCRS.Text    = data[i].Code;
                    ResultCRS.Gravity = GravityFlags.Right;
                    ResultBack.AddView(ResultCRS);

                    //Result Back Event
                    ResultBack.Click += delegate
                    {
                        //If callback isn't null, invoke it, causing sleection to be returned and dialog hidden.
                        StationSelected?.Invoke(DialogID, localdat);
                        CloseDialog();
                    };
                }

                //If theres no stations
                if (data.Length == ZERO)
                {
                    ResultsRoot.RemoveAllViews();
                    ResultsRoot.AddView(DrawErrorMessage(ERROR_NOSTATIONSFOUND));
                    GPS = new RtGPS((LocationManager)ContextWrapper.GetSystemService(ContextWrapper.LocationService));
                }
            }
            else if (GPS.NoGPS)
            {
                //If no GPS
                ResultsRoot.RemoveAllViews();
                ResultsRoot.AddView(DrawErrorMessage(ERROR_GPSTURNEDOFF));
                GPS = new RtGPS((LocationManager)ContextWrapper.GetSystemService(ContextWrapper.LocationService));
            }
            else
            {
                //If GPS not ready
                ResultsRoot.RemoveAllViews();
                ResultsRoot.AddView(DrawErrorMessage(ERROR_GPSLOADING));
            }
        }