예제 #1
0
        protected async override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Display);

            MojioClient client = Globals.client;

            client.PageSize = 15; //Gets 15 results
            MojioResponse <Results <Trip> > response = await client.GetAsync <Trip> ();

            Results <Trip> result = response.Data;

            var    results      = FindViewById <TextView> (Resource.Id.tripResults);
            int    tripIndex    = 1;
            String outputString = "";

            // Iterate over each trip
            foreach (Trip trip in result.Data)
            {
                outputString += string.Format("Trip {0}:", tripIndex) + System.Environment.NewLine + "Start time: " + trip.StartTime.ToString()
                                + System.Environment.NewLine + "End time: " + trip.EndTime.ToString() + System.Environment.NewLine + "Longitude: "
                                + trip.EndLocation.Lng.ToString() + System.Environment.NewLine + "Latitude: " + trip.EndLocation.Lat.ToString()
                                + System.Environment.NewLine + "Max Speed: " + trip.MaxSpeed.Value.ToString() + " km/h"
                                + System.Environment.NewLine + System.Environment.NewLine;
                tripIndex++;
            }
            results.Text = outputString;
        }
예제 #2
0
            public async void getTripData(View view)
            {
                //TODO use global preference instead
                var numTripsToDisplay = 20;

                var prefs      = Application.Context.GetSharedPreferences("settings", FileCreationMode.Private);
                var prefEditor = prefs.Edit();

                if (!MojioConnectionHelper.isClientLoggedIn())
                {
                    await MojioConnectionHelper.setupMojioConnection(prefs);
                }


                if (firstStart)
                {
                    firstStart = false;
                    Globals.client.PageSize = 500; //Gets 15 results
                    MojioResponse <Results <Trip> > response = await Globals.client.GetAsync <Trip> ();

                    Results <Trip> result = response.Data;

                    //var results = view.FindViewById<TextView> (Resource.Id.tripResults);

                    tripIndex = 0;
                    fuelEcon  = 0.0;


                    tripIndex--;

                    list = new List <TripData> ();
                    //iterate over each trip to create TripData for each existing trip.

                    foreach (Trip trip in result.Data)
                    {
                        try {
                            fuelEcon += (double)trip.FuelEfficiency;
                            tripIndex++;
                            TripData td = new TripData(trip.StartTime, trip.EndTime, trip.MaxSpeed.Value.ToString(), trip.EndLocation.Lat.ToString(), trip.EndLocation.Lng.ToString(),
                                                       trip.FuelEfficiency.ToString(), trip.FuelLevel.ToString(), trip.StartLocation.Lat.ToString(), trip.StartLocation.Lng.ToString());
                            //add new trip to beginning of list, so they are in most recent first order
                            list.Insert(0, td);
                        } catch (Exception e) {
                            Console.WriteLine("Exception:" + e);
                        }
                    }
                }
                prefEditor.PutString("speed", "disabled");

                int i              = 1;
                var firstTrip      = true;
                var tripsDisplayed = 0;
                // programmatically create a view widget for each trip
                LinearLayout linlay = view.FindViewById <LinearLayout> (Resource.Id.linearLayout28);

                // remove all old children
                Console.Write("NUMCHILDREN: " + linlay.ChildCount);

                for (int j = linlay.ChildCount - 1; j >= 0; j--)
                {
                    linlay.RemoveViewAt(j);
                }

                //places all the UI elements
                foreach (TripData td in list)
                {
                    if (tripsDisplayed > numTripsToDisplay)
                    {
                        break;
                    }
                    else
                    {
                        tripsDisplayed++;
                    }

                    // get most recent time
                    if (firstTrip)
                    {
                        lastTime  = td.startDate + " @ " + td.startTime;
                        firstTrip = false;
                    }
                    else
                    {
                        // drive divider first for every one except for first card
                        var space = new Space(Application.Context)
                        {
                            LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, 10)
                        };
                        var divider = new LinearLayout(Application.Context)
                        {
                            LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, 1)
                        };

                        divider.SetBackgroundColor(Resources.GetColor(17170432));  //darker grey

                        //add divider then space for padding
                        linlay.AddView(divider);
                        linlay.AddView(space);
                    }


                    ImageView mapButton = new ImageView(Application.Context);
                    mapButton.SetImageResource(Resource.Drawable.mapButton);
                    mapButton.SetAdjustViewBounds(true);
                    mapButton.Click += delegate {
                        var tripviewActivity = new Intent(Activity, typeof(tripviewActivity));
                        // Create bundle to send to tripViewActivity
                        Bundle extras = new Bundle();
                        extras.PutString("endlat", (td.endlocationlat));
                        extras.PutString("endlng", (td.endlocationlng));
                        extras.PutString("startlat", (td.startlocationlat));
                        extras.PutString("startlng", (td.startlocationlng));
                        extras.PutString("fuelEfficiency", (td.fuelEfficiency));
                        extras.PutString("fuelLevel", (td.fuelLevel));
                        extras.PutString("startTime", (td.startTime));
                        extras.PutString("startDate", (td.startDate));
                        extras.PutString("maxSpeed", (td.maxSpeed));
                        extras.PutString("endTime", (td.endDateTime));
                        tripviewActivity.PutExtra("extras", extras);
                        StartActivity(tripviewActivity);
                    };
                    linlay.AddView(mapButton);

                    TextView tv = new TextView(Application.Context);
                    tv.Text     = td.startDate + " @ " + td.startTime;
                    tv.TextSize = 30;
                    //tv.Elevation = 4;
                    tv.SetPadding(5, 5, 5, 5);
                    //tv.SetBackgroundColor (Android.Graphics.Color.ParseColor("#BBDEFB"));
                    tv.SetTextColor(Resources.GetColor(Resource.Color.black_text));
                    linlay.AddView(tv);
                    i++;

                    LinearLayout innerll1 = new LinearLayout(Application.Context);
                    innerll1.Orientation = Android.Widget.Orientation.Horizontal;
                    innerll1.Id          = i + 5000;
                    //innerll1.Elevation = 4;
                    innerll1.SetPadding(5, 5, 5, 5);
                    //innerll1.SetBackgroundColor (Android.Graphics.Color.ParseColor("#BBDEFB"));

                    ImageView iv1 = new ImageView(Application.Context);
                    iv1.SetImageResource(Resource.Drawable.stopwatch);
                    iv1.SetMaxHeight(50);
                    iv1.SetColorFilter(Resources.GetColor(Resource.Color.accent));
                    iv1.SetAdjustViewBounds(true);
                    innerll1.AddView(iv1);

                    TextView tv1 = new TextView(Application.Context);
                    tv1.Text     = "   " + td.tripLength;
                    tv1.TextSize = 20;
                    tv1.SetTextColor(Resources.GetColor(Resource.Color.secondary_text));
                    innerll1.AddView(tv1);
                    linlay.AddView(innerll1);

                    LinearLayout innerll2 = new LinearLayout(Application.Context);
                    innerll2.Orientation = Android.Widget.Orientation.Horizontal;
                    //innerll2.Elevation = 4;
                    innerll2.SetPadding(5, 5, 5, 5);
                    //innerll2.SetBackgroundColor (Android.Graphics.Color.ParseColor("#BBDEFB"));

                    ImageView iv2 = new ImageView(Application.Context);
                    iv2.SetImageResource(Resource.Drawable.speedometer);
                    iv2.SetMaxHeight(50);
                    iv2.SetColorFilter(Resources.GetColor(Resource.Color.accent));
                    iv2.SetAdjustViewBounds(true);
                    innerll2.AddView(iv2);

                    TextView tv2 = new TextView(Application.Context);
                    tv2.Text     = "   " + td.maxSpeed;
                    tv2.TextSize = 20;
                    //tv2.Elevation = 4;
                    tv2.SetTextColor(Resources.GetColor(Resource.Color.secondary_text));
                    innerll2.AddView(tv2);
                    linlay.AddView(innerll2);

                    Space spc = new Space(Application.Context);
                    spc.SetMinimumHeight(14);
                    linlay.AddView(spc);
                }

                var fuelEfficiecny = view.FindViewById <TextView> (Resource.Id.fuelUsage);
                var lastTripTime   = view.FindViewById <TextView> (Resource.Id.lastTripTime);
                var fe             = Math.Round((fuelEcon / tripIndex), 1);

                fuelEfficiecny.Text = "   " + fe + " L/100km";
                lastTripTime.Text   = "   " + lastTime;
            }