Exemple #1
0
        protected override void OnLocationReceived(Context context, Android.Locations.Location loc)
        {
            //base.OnLocationReceived(context, loc);
            RunManager rm        = RunManager.Get(mRunLocationListFragment.Activity);
            Run        activeRun = rm.GetActiveRun();

            if (activeRun != null && activeRun.Id == mRunLocationListFragment.mRunId)
            {
                RunLocationListAdapter adapter      = ((RunLocationListAdapter)mRunLocationListFragment.ListAdapter);
                List <RunLocation>     runLocations = rm.GetLocationsForRun(activeRun.Id);
                RunLocation            runLocation  = runLocations[runLocations.Count - 1];
                adapter.Add(runLocation);
                adapter.NotifyDataSetChanged();
                mRunLocationListFragment.ListView.SmoothScrollToPosition(runLocations.Count);
            }
        }
Exemple #2
0
        public override void OnCreate(Android.OS.Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            mRunId = Activity.Intent.Extras.GetInt(RunListFragment.RUN_ID, -1);

            mRunManager = RunManager.Get(Activity);

            if (mRunId != -1)
            {
                RunLocationListAdapter adapter = new RunLocationListAdapter(Activity, mRunManager.GetLocationsForRun(mRunId));
                ListAdapter = adapter;
            }

            CurrentLocationReceiver = new RunLocationListReceiver(this);
            Activity.RegisterReceiver(CurrentLocationReceiver, new IntentFilter(RunManager.ACTION_LOCATION));
        }
Exemple #3
0
        public void UpdateUI()
        {
            if (CurrentRun != null && !CurrentRun.Active)
            {
                mRunLocations = mRunManager.GetLocationsForRun(CurrentRun.Id);

                if (mRunLocations.Count > 0)
                {
                    mStartedTextView.Text = CurrentRun.StartDate.ToLocalTime().ToString();

                    mLatitudeTextView.Text  = mRunLocations[0].Latitude.ToString();
                    mLongitudeTextView.Text = mRunLocations[0].Longitude.ToString();
                    mAltitudeTextView.Text  = mRunLocations[0].Altitude.ToString();

                    int durationSeconds = (int)Math.Ceiling((mRunLocations[mRunLocations.Count - 1].Time - CurrentRun.StartDate).TotalSeconds);
                    mDurationTextView.Text = Run.FormatDuration(durationSeconds);

//					var location = new LatLng(mRunLocations[mRunLocations.Count -1].Latitude, mRunLocations[mRunLocations.Count -1].Longitude);
//					var cu = CameraUpdateFactory.NewLatLngZoom (location, 20);
//					mGoogleMap.MoveCamera (cu);
                    DrawRunTrack(false);
                }
                else
                {
                    var     toast   = Toast.MakeText(Activity, Resource.String.empty_run_message, ToastLength.Long);
                    Display display = Activity.WindowManager.DefaultDisplay;
                    var     size    = new Android.Graphics.Point();
                    display.GetSize(size);
                    toast.SetGravity(GravityFlags.Top, 0, size.Y / 6);
                    toast.Show();
                }

                if (mRunManager.IsTrackingRun())
                {
                    mStartButton.Enabled    = false;
                    mStartButton.Visibility = ViewStates.Invisible;
                    mStopButton.Enabled     = false;
                    mStopButton.Visibility  = ViewStates.Invisible;
                }
                else
                {
                    mStartButton.Enabled = true;
                    mStopButton.Enabled  = false;
                }
            }
            else
            {
                bool started = mRunManager.IsTrackingRun();

                if (CurrentRun != null)
                {
                    mRunLocations         = mRunManager.GetLocationsForRun(CurrentRun.Id);
                    mStartedTextView.Text = CurrentRun.StartDate.ToLocalTime().ToString();
                }

                int durationSeconds = 0;
                if (CurrentRun != null && LastLocation != null)
                {
                    DateTime lastLocTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(LastLocation.Time);
                    durationSeconds         = CurrentRun.GetDurationSeconds(lastLocTime);
                    mLatitudeTextView.Text  = LastLocation.Latitude.ToString();
                    mLongitudeTextView.Text = LastLocation.Longitude.ToString();
                    mAltitudeTextView.Text  = LastLocation.Altitude.ToString();
                    mDurationTextView.Text  = Run.FormatDuration(durationSeconds);
                    CurrentRun.Duration     = durationSeconds;
                    mRunManager.UpdateItem <Run>(CurrentRun);

//					var location = new LatLng(LastLocation.Latitude, LastLocation.Longitude);
//					var cu = CameraUpdateFactory.NewLatLngZoom (location, 20);
//					mGoogleMap.MoveCamera (cu);
                    DrawRunTrack(true);
                }

                mStartButton.Enabled = !started;
                mStopButton.Enabled  = started;
            }
        }