Example #1
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());
        }
        private void NavBarTitle_AfterTextChanged(object sender, Android.Text.AfterTextChangedEventArgs e)
        {
            string InputText = (sender as EditText).Text;

            if (InputText.Length > 0)
            {
                RtStationData[] SearchData = (InputText.Length == 3 && InputText.ToUpper() == InputText) ? RtStations.SearchByCRS(InputText) : RtStations.SearchByName(InputText);

                ContentRoot.RemoveAllViews();
                for (int i = 0; i < SearchData.Length; i++)
                {
                    LinearLayout ResultBack = new LinearLayout(this);
                    ResultBack.LayoutParameters = RtGraphicsLayouts.LayoutParameters(RtGraphicsLayouts.EXPAND, NAVBARHEIGHT);
                    ResultBack.SetDpPadding(RtGraphicsLayouts, SMALLPADDING, SMALLPADDING, SMALLPADDING, SMALLPADDING);
                    ContentRoot.AddView(ResultBack);

                    TextView tResult = new TextView(this);
                    tResult.Format(RtGraphicsExt.TextFormats.Paragraph);
                    tResult.Text = SearchData[i].Code + " - " + SearchData[i].StationName;
                    ResultBack.AddView(tResult);
                }
            }
        }
Example #3
0
        private void DrawSearchResults(LinearLayout Parent, EditText FromSearchInput, LinearLayout FromSearchBack, LinearLayout FromStationBack, TextView FromStationText, TextView FromStationNoNav, string Search, StationSelectionBoxType StationSelectionBoxType, StationFacilitiesView StationFacilitiesView)
        {
            RtStationData[] StationResults = (Search.Length == 3 && Search.ToUpper() == Search) ? RtStations.SearchByCRS(Search) : RtStations.SearchByName(Search);

            Parent.RemoveAllViews();
            for (int i = 0; i < StationResults.Length; i++)
            {
                int          ilocal     = i;
                LinearLayout ResultBack = new LinearLayout(this);
                ResultBack.LayoutParameters = RtGraphicsLayouts.LayoutParameters(RtGraphicsLayouts.EXPAND, 100);
                ResultBack.SetDpPadding(RtGraphicsLayouts, SMALLPADDING, SMALLPADDING, SMALLPADDING, SMALLPADDING);
                ResultBack.SetGravity(GravityFlags.CenterVertical);
                Parent.AddView(ResultBack);

                TextView tResult = new TextView(this);
                tResult.Format(RtGraphicsExt.TextFormats.Paragraph);
                tResult.Text = StationResults[i].Code + " - " + StationResults[i].StationName;
                ResultBack.AddView(tResult);

                ResultBack.Click += delegate
                {
                    FromStationBack.Visibility = ViewStates.Visible;
                    FromStationText.Text       = tResult.Text;
                    FromSearchBack.Visibility  = ViewStates.Gone;
                    HideKeyboard(FromSearchInput);

                    if (StationResults[ilocal].Code == "LAN" || StationResults[ilocal].Code == "PRE")
                    {
                        FromStationNoNav.Visibility = ViewStates.Gone;
                        StationFacilitiesView.Redraw(StationResults[ilocal].Code, ContentScrollerRoot);
                    }
                    else
                    {
                        FromStationNoNav.Visibility = ViewStates.Visible;
                    }

                    if (StationSelectionBoxType == StationSelectionBoxType.From)
                    {
                        FromStationCode = StationResults[ilocal].Code;
                        FromStationname = StationResults[ilocal].StationName;
                    }
                    else
                    {
                        ToStationCode = StationResults[ilocal].Code;
                        ToStationname = StationResults[ilocal].StationName;
                    }

                    StationSelectionChanged();
                };
            }
        }
        //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));
            }
        }