Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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("");
        }
Exemplo n.º 5
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));
        }