public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            if (savedInstanceState?.ContainsKey("Line") == true)
            {
                int lineId = savedInstanceState.GetInt("Line");
                line = TramUrWayApplication.GetLine(lineId);
            }
            if (savedInstanceState?.ContainsKey("Color") == true)
            {
                int argb = savedInstanceState.GetInt("Color");
                color = new Color(argb);
            }

            return(inflater.Inflate(Resource.Layout.LineMapFragment, container, false));
        }
Exemple #2
0
        private void FromButton_Click(object sender, EventArgs e)
        {
            PopupMenu menu = new PopupMenu(this, sender as View);

            menu.MenuItemClick += (s, a) =>
            {
                if (a.Item.ItemId == 0)
                {
                    UpdateAutoFrom();
                }
                else if (a.Item.ItemId == 1)
                {
                    fromTextView.RequestFocus();
                    fromTextView.ShowDropDown();
                    fromTextView.SelectAll();

                    fromTextView.PostDelayed(() =>
                    {
                        InputMethodManager inputMethodManager = GetSystemService(Context.InputMethodService) as InputMethodManager;
                        inputMethodManager.ShowSoftInput(fromTextView, ShowFlags.Forced);
                    }, 250);
                }
                else
                {
                    Stop stop = TramUrWayApplication.GetStop(a.Item.ItemId);
                    fromTextView.Text = stop.Name;
                }
            };

            // Auto: based on current location and favorites
            if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.AccessFineLocation) == Permission.Granted)
            {
                menu.Menu.Add(1, 0, 1, "Automatique").SetIcon(Resource.Drawable.ic_place);
            }

            // Favorite stops
            foreach (Stop stop in TramUrWayApplication.Config.FavoriteStops.GroupBy(s => s.Name).Select(g => g.First()))
            {
                menu.Menu.Add(1, stop.Id, 2, stop.Name);
            }

            // Other: focus the search box and trigger autocomplete
            menu.Menu.Add(1, 1, 3, "Autre ...");

            menu.Show();
        }
Exemple #3
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            if (savedInstanceState?.ContainsKey("Line") == true && savedInstanceState?.ContainsKey("Route") == true)
            {
                int  lineId = savedInstanceState.GetInt("Line");
                Line line   = TramUrWayApplication.GetLine(lineId);

                int routeId = savedInstanceState.GetInt("Route");
                route = line.Routes.FirstOrDefault(r => r.Id == routeId);
            }
            if (savedInstanceState?.ContainsKey("Color") == true)
            {
                int argb = savedInstanceState.GetInt("Color");
                color = new Color(argb);
            }

            View view = inflater.Inflate(Resource.Layout.RouteFragment, container, false);

            // Refresh widget
            swipeRefresh          = view.FindViewById <SwipeRefreshLayout>(Resource.Id.RouteFragment_SwipeRefresh);
            swipeRefresh.Refresh += (s, e) => QueryRefresh?.Invoke(s, e);
            swipeRefresh.SetColorSchemeColors(color.ToArgb());

            // Steps list
            recyclerView              = view.FindViewById <RecyclerView>(Resource.Id.RouteFragment_StopList);
            recyclerView.Focusable    = false;
            recyclerView.HasFixedSize = true;
            recyclerView.SetLayoutManager(new LinearLayoutManager(recyclerView.Context));
            recyclerView.AddItemDecoration(new DividerItemDecoration(recyclerView.Context, LinearLayoutManager.Vertical));
            recyclerView.SetAdapter(routeAdapter = new RouteAdapter(route));

            if (lastTimeSteps != null)
            {
                routeAdapter.Update(lastTimeSteps, lastTransports);
            }

            return(view);
        }
Exemple #4
0
        private void ToButton_Click(object sender, EventArgs e)
        {
            PopupMenu menu = new PopupMenu(this, sender as View);

            menu.MenuItemClick += (s, a) =>
            {
                if (a.Item.ItemId == 1)
                {
                    toTextView.RequestFocus();
                    toTextView.ShowDropDown();
                    toTextView.SelectAll();

                    toTextView.PostDelayed(() =>
                    {
                        InputMethodManager inputMethodManager = GetSystemService(Context.InputMethodService) as InputMethodManager;
                        inputMethodManager.ShowSoftInput(toTextView, ShowFlags.Forced);
                    }, 250);
                }
                else
                {
                    Stop stop = TramUrWayApplication.GetStop(a.Item.ItemId);
                    toTextView.Text = stop.Name;
                }
            };

            // Favorite stops
            foreach (Stop stop in TramUrWayApplication.Config.FavoriteStops.GroupBy(s => s.Name).Select(g => g.First()))
            {
                menu.Menu.Add(1, stop.Id, 2, stop.Name);
            }

            // Other: focus the search box and trigger autocomplete
            menu.Menu.Add(1, 1, 3, "Autre ...");

            menu.Show();
        }
Exemple #5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            OnCreate(savedInstanceState, Resource.Layout.RouteActivity);
            Title = "Itinéraire";

            SupportActionBar.SetDisplayHomeAsUpEnabled(true);

            // Handle bundle parameter
            Bundle extras = Intent.Extras;

            if (extras != null && extras.ContainsKey("RouteSegments"))
            {
                string[] routeSegmentsData = extras.GetStringArray("RouteSegments");

                routeSegments = new List <RouteSegment>();
                foreach (string routeSegmentData in routeSegmentsData)
                {
                    JObject routeSegmentObject = JsonConvert.DeserializeObject(routeSegmentData) as JObject;
                    if (routeSegmentObject == null)
                    {
                        throw new Exception("Unable to decode specified route information");
                    }

                    Line line = TramUrWayApplication.GetLine(routeSegmentObject["Line"].Value <int>());

                    int      fromRouteId = routeSegmentObject["From.Route"].Value <int>();
                    int      fromStopId  = routeSegmentObject["From.Stop"].Value <int>();
                    DateTime fromDate    = routeSegmentObject["From.Date"].Value <DateTime>();

                    int      toRouteId = routeSegmentObject["To.Route"].Value <int>();
                    int      toStopId  = routeSegmentObject["To.Stop"].Value <int>();
                    DateTime toDate    = routeSegmentObject["To.Date"].Value <DateTime>();

                    Route fromRoute = line.Routes.First(r => r.Id == fromRouteId);
                    Step  from      = fromRoute.Steps.First(s => s.Stop.Id == fromStopId);

                    Route toRoute = line.Routes.First(r => r.Id == toRouteId);
                    Step  to      = toRoute.Steps.First(s => s.Stop.Id == toStopId);

                    List <TimeStep> timeSteps = new List <TimeStep>();

                    foreach (JObject timeStepObject in routeSegmentObject["TimeSteps"] as JArray)
                    {
                        int      routeId = timeStepObject["Route"].Value <int>();
                        int      stopId  = timeStepObject["Stop"].Value <int>();
                        DateTime date    = timeStepObject["Date"].Value <DateTime>();

                        Route route = line.Routes.First(r => r.Id == routeId);
                        Step  step  = fromRoute.Steps.First(s => s.Stop.Id == stopId);

                        timeSteps.Add(new TimeStep()
                        {
                            Step = step, Date = date
                        });
                    }

                    routeSegments.Add(new RouteSegment()
                    {
                        Line = line, From = from, DateFrom = fromDate, To = to, DateTo = toDate, TimeSteps = timeSteps.ToArray()
                    });
                }

                from = routeSegments.First().From.Stop;
                to   = routeSegments.Last().To.Stop;
            }

            if (from == null || to == null)
            {
                throw new Exception("Could not find specified route information");
            }

            // Initialize UI
            ImageView fromIconView = FindViewById <ImageView>(Resource.Id.RouteActivity_FromIcon);

            fromIconView.SetImageDrawable(from.Line.GetIconDrawable(this));

            TextView fromNameView = FindViewById <TextView>(Resource.Id.RouteActivity_FromName);

            fromNameView.Text = from.Name;

            TextView fromDateView = FindViewById <TextView>(Resource.Id.RouteActivity_FromDate);

            fromDateView.Text = routeSegments.First().DateFrom.ToString("HH:mm");

            ImageView toIconView = FindViewById <ImageView>(Resource.Id.RouteActivity_ToIcon);

            toIconView.SetImageDrawable(to.Line.GetIconDrawable(this));

            TextView toNameView = FindViewById <TextView>(Resource.Id.RouteActivity_ToName);

            toNameView.Text = to.Name;

            TextView toDateView = FindViewById <TextView>(Resource.Id.RouteActivity_ToDate);

            toDateView.Text = routeSegments.Last().DateTo.ToString("HH:mm");

            // Details view
            RecyclerView recyclerView = FindViewById <RecyclerView>(Resource.Id.RouteActivity_SegmentsList);

            recyclerView.SetLayoutManager(new WrapLayoutManager(recyclerView.Context));
            recyclerView.AddItemDecoration(new DividerItemDecoration(recyclerView.Context, LinearLayoutManager.Vertical, true));
            recyclerView.SetAdapter(new RouteSegmentAdapter(routeSegments.ToArray()));
            recyclerView.NestedScrollingEnabled = false;

            // Setup maps fragment
            mapFragment = SupportFragmentManager.FindFragmentById(Resource.Id.RouteActivity_Map) as SupportMapFragment;
            mapFragment.GetMapAsync(this);
        }
Exemple #6
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            OnCreate(savedInstanceState, Resource.Layout.LineActivity);

            SupportActionBar.SetDisplayHomeAsUpEnabled(true);

            // Handle bundle parameter
            Bundle extras = Intent.Extras;

            if (extras != null && extras.ContainsKey("Line"))
            {
                int lineId = -1;

                // Parse device path
                try
                {
                    lineId = extras.GetInt("Line");
                }
                catch (Exception e)
                {
                    Toast.MakeText(Parent, "Wrong line id", ToastLength.Short).Show();
                    Finish();
                }

                // Try to find device
                line = TramUrWayApplication.GetLine(lineId);
            }
#if DEBUG
            else
            {
                line = TramUrWayApplication.GetLine(2);
            }
#endif
            if (line == null)
            {
                throw new Exception("Could not find any line matching the specified id");
            }

            Title = line.Name;

            // Change toolbar color
            Color color     = Utils.GetColorForLine(this, line);
            Color darkColor = new Color(color.R * 2 / 3, color.G * 2 / 3, color.B * 2 / 3);

            SupportActionBar.SetBackgroundDrawable(new ColorDrawable(color));

            if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
            {
                Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
                Window.ClearFlags(WindowManagerFlags.TranslucentStatus);
                Window.SetStatusBarColor(darkColor);
            }

            // Tabs
            fragments = new List <TabFragment>()
            {
                new LineMapFragment(line, color)
            };
            foreach (Route route in line.Routes)
            {
                LineRouteFragment routeFragment = new LineRouteFragment(route, color);
                routeFragment.QueryRefresh += SwipeRefresh_Refresh;

                fragments.Add(routeFragment);
            }

            viewPager = FindViewById <ViewPager>(Resource.Id.LineActivity_ViewPager);
            viewPager.OffscreenPageLimit = fragments.Count;
            viewPager.Adapter            = new TabFragmentsAdapter(SupportFragmentManager, fragments.ToArray());

            if (extras != null && extras.ContainsKey("Route"))
            {
                int routeId = extras.GetInt("Route");
                viewPager.SetCurrentItem(1 + routeId, false);
            }
            else
            {
                viewPager.SetCurrentItem(1, false);
            }

            TabLayout tabLayout = FindViewById <TabLayout>(Resource.Id.LineActivity_Tabs);
            tabLayout.SetBackgroundColor(color);
            tabLayout.SetSelectedTabIndicatorColor(unchecked ((int)0xFFFFFFFF));
            tabLayout.SetupWithViewPager(viewPager);
            tabLayout.GetTabAt(0).SetIcon(Resource.Drawable.ic_map).SetText("");
        }
Exemple #7
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            OnCreate(savedInstanceState, Resource.Layout.StopActivity);

            SupportActionBar.SetDisplayHomeAsUpEnabled(true);

            // Handle bundle parameter
            Bundle extras = Intent.Extras;

            if (extras != null && extras.ContainsKey("Stop"))
            {
                int stopId = extras.GetInt("Stop");
                stop = TramUrWayApplication.GetStop(stopId);
            }
#if DEBUG
            else
            {
                stop = TramUrWayApplication.Lines.SelectMany(l => l.Stops).FirstOrDefault(s => s.Name == "Saint-Lazare");
            }
#endif
            if (stop == null)
            {
                throw new Exception("Could not find any stop matching the specified id");
            }

            if (extras != null && extras.ContainsKey("Line"))
            {
                int lineId = extras.GetInt("Line");
                line = TramUrWayApplication.GetLine(lineId);
            }
            else
            {
                line = stop.Line;
            }

            Title = stop.Name;

            // Change toolbar color
            Color color     = Utils.GetColorForLine(this, line);
            Color darkColor = new Color(color.R * 2 / 3, color.G * 2 / 3, color.B * 2 / 3);

            SupportActionBar.SetBackgroundDrawable(new ColorDrawable(color));

            if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
            {
                Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
                Window.ClearFlags(WindowManagerFlags.TranslucentStatus);
                Window.SetStatusBarColor(darkColor);
            }

            // Refresh widget
            swipeRefresh          = FindViewById <SwipeRefreshLayout>(Resource.Id.StopActivity_SwipeRefresh);
            swipeRefresh.Refresh += SwipeRefresh_Refresh;
            swipeRefresh.SetColorSchemeColors(color.ToArgb());

            // Initialize UI
            lineLabel      = FindViewById <TextView>(Resource.Id.StopActivity_LineLabel);
            lineLabel.Text = line.Name;
            lineLabel.SetTextColor(darkColor);

            listStopList = FindViewById <RecyclerView>(Resource.Id.StopActivity_LineStopList);
            listStopList.HasFixedSize           = true;
            listStopList.NestedScrollingEnabled = false;
            listStopList.SetLayoutManager(new WrapLayoutManager(this));
            listStopList.AddItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.Vertical));

            otherLabel = FindViewById <TextView>(Resource.Id.StopActivity_OtherLabel);
            otherLabel.SetTextColor(darkColor);

            otherStopList = FindViewById <RecyclerView>(Resource.Id.StopActivity_OtherStopList);
            otherStopList.HasFixedSize           = true;
            otherStopList.NestedScrollingEnabled = false;
            otherStopList.SetLayoutManager(new WrapLayoutManager(this));
            otherStopList.AddItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.Vertical));
        }
Exemple #8
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.RoutesActivity);
            NavigationItemId = Resource.Id.SideMenu_Routes;

            OnPostCreate();

            Stop[]   stops     = TramUrWayApplication.Lines.SelectMany(l => l.Stops).ToArray();
            string[] stopNames = stops.Select(s => s.Name).Distinct().ToArray();

            // Initialize UI
            fromLayout   = FindViewById <TextInputLayout>(Resource.Id.RoutesActivity_FromLayout);
            fromTextView = FindViewById <AutoCompleteTextView>(Resource.Id.RoutesActivity_From);
            //fromTextView.Adapter = new ArrayAdapter<string>(this, Resource.Layout.RouteAutocompleteItem, stopNames);
            fromTextView.Adapter      = new StopNameAdapter(this);
            fromTextView.TextChanged += TextView_TextChanged;

            View fromButton = FindViewById(Resource.Id.RoutesActivity_FromButton);

            fromButton.Click += FromButton_Click;

            toLayout   = FindViewById <TextInputLayout>(Resource.Id.RoutesActivity_ToLayout);
            toTextView = FindViewById <AutoCompleteTextView>(Resource.Id.RoutesActivity_To);
            //toTextView.Adapter = new ArrayAdapter<string>(this, Resource.Layout.RouteAutocompleteItem, stopNames);
            toTextView.Adapter      = new StopNameAdapter(this);
            toTextView.TextChanged += TextView_TextChanged;

            View toButton = FindViewById(Resource.Id.RoutesActivity_ToButton);

            toButton.Click += ToButton_Click;

            View dateLayout = FindViewById(Resource.Id.RoutesActivity_DateLayout);

            dateLayout.Click += DateLayout_Click;

            // Handle bundle parameter
            Bundle extras = Intent.Extras;

            if (extras != null && extras.ContainsKey("From"))
            {
                int  stopId = extras.GetInt("From");
                Stop stop   = TramUrWayApplication.GetStop(stopId);
                if (stop != null)
                {
                    fromTextView.Text = stop.Name;
                }
            }

            if (extras != null && extras.ContainsKey("To"))
            {
                int  stopId = extras.GetInt("To");
                Stop stop   = TramUrWayApplication.GetStop(stopId);
                if (stop != null)
                {
                    toTextView.Text = stop.Name;
                }
            }
#if DEBUG
            //else
            //    toTextView.Text = "Odysseum";
#endif

            recyclerView = FindViewById <RecyclerView>(Resource.Id.RoutesActivity_RoutesList);
            recyclerView.SetLayoutManager(new LinearLayoutManager(recyclerView.Context));
            recyclerView.AddItemDecoration(new DividerItemDecoration(recyclerView.Context, LinearLayoutManager.Vertical));
            recyclerView.SetAdapter(routeSegmentAdapter = new RouteSegmentsAdapter());

            // Refresh widget
            swipeRefresh          = FindViewById <SwipeRefreshLayout>(Resource.Id.RoutesActivity_SwipeRefresh);
            swipeRefresh.Refresh += SwipeRefresh_Refresh;
            swipeRefresh.SetColorSchemeColors(Resources.GetColor(Resource.Color.colorAccent).ToArgb());

            noResultsView            = FindViewById(Resource.Id.RoutesActivity_NoResults);
            noResultsView.Visibility = ViewStates.Gone;
        }