Ejemplo n.º 1
0
        public override void OnCreate(Android.OS.Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            mRunManager             = RunManager.Get(Activity);
            CurrentLocationReceiver = new RunLocationReceiver(this);
            Activity.RegisterReceiver(CurrentLocationReceiver, new IntentFilter(RunManager.ACTION_LOCATION));
        }
Ejemplo n.º 2
0
 public static RunManager Get(Context c)
 {
     if (sRunManager == null)
     {
         // Use the application context to avoid leaking activities
         sRunManager = new RunManager(c.ApplicationContext);
     }
     return(sRunManager);
 }
Ejemplo n.º 3
0
        public override void OnCreate(Android.OS.Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetHasOptionsMenu(true);
            RetainInstance = true;
            mRunManager    = RunManager.Get(Activity);
            mRunManager.CreateDatabase();

            RunListAdapter adapter = new RunListAdapter(Activity, mRunManager.GetRuns());

            ListAdapter = adapter;
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
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));
        }
Ejemplo n.º 6
0
        protected override void OnLocationReceived(Context context, Android.Locations.Location loc)
        {
            //base.OnLocationReceived(context, loc);
            RunManager rm = RunManager.Get(mRunFragment.Activity);

            // trying to ignore old locations, but this call always seems to pass a location with the current time
            // so leaving out for now
            //			var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            //			var now = DateTime.UtcNow;
            //			var seconds = (now - epoch).TotalSeconds;
            //
            //			var locTimeSeconds = loc.Time /1000;
            //
            //			if (locTimeSeconds < seconds - 60)
            //				return;

            var now         = DateTime.UtcNow;
            var lastLocTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(loc.Time);

            if ((now - lastLocTime).TotalSeconds < 10.0)
            {
                if (rm.IsTrackingRun())
                {
                    mRunFragment.LastLocation = loc;
                    // Moved to LocationReceiver
//					RunLocation rl = new RunLocation();
//					rl.RunId = mRunFragment.CurrentRun.Id;
//					rl.Latitude = loc.Latitude;
//					rl.Longitude = loc.Longitude;
//					rl.Altitude = loc.Altitude;
//					rl.Time = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(loc.Time);
//					rl.Provider = loc.Provider;
//					rm.InsertItem<RunLocation>(rl);
                }

                if (mRunFragment.IsVisible)
                {
                    mRunFragment.UpdateUI();
                }
            }
        }
Ejemplo n.º 7
0
        protected virtual void OnLocationReceived(Context context, Location loc)
        {
            //			Console.WriteLine("[{0}] {1} Got location from {2}: {3}, {4}", TAG, this, loc.Provider, loc.Latitude, loc.Longitude);
            RunManager rm  = RunManager.Get(context);
            Run        run = rm.GetActiveRun();

            if (rm.IsTrackingRun() && run != null)
            {
                RunLocation rl = new RunLocation();
                rl.RunId     = run.Id;
                rl.Latitude  = loc.Latitude;
                rl.Longitude = loc.Longitude;
                rl.Altitude  = loc.Altitude;
                rl.Time      = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(loc.Time);
                rl.Provider  = loc.Provider;
                rm.InsertItem <RunLocation>(rl);

                if ((DateTime.UtcNow - run.StartDate).Minutes % 5 == 0 && (DateTime.UtcNow - run.StartDate).Seconds % 60 == 0)
                {
                    // Open activity on click notification. (Need to handle properly so off for now)
                    Intent intent = new Intent(context, typeof(RunActivity));
                    intent.AddFlags(ActivityFlags.SingleTop);
                    const int     pendingIntentId = 0;
                    PendingIntent pendingIntent   = PendingIntent.GetActivity(context, pendingIntentId, intent, PendingIntentFlags.OneShot);

                    Notification notification = new Notification.Builder(context)
                                                .SetTicker(context.Resources.GetString(Resource.String.tracking_run_notification_title))
                                                .SetSmallIcon(Android.Resource.Drawable.IcMenuView)
                                                .SetContentTitle(context.Resources.GetString(Resource.String.tracking_run_notification_title))
                                                .SetContentText(context.Resources.GetString(Resource.String.tracking_run_notification_text))
                                                .SetContentIntent(pendingIntent)
                                                .SetAutoCancel(true)
                                                .Build();

                    NotificationManager notificationManager = context.GetSystemService(Context.NotificationService) as NotificationManager;

                    const int notificationId = 0;
                    notificationManager.Notify(notificationId, notification);
                }
            }
        }