예제 #1
0
        public void SetFence(Location location, double minRange, double maxRange, Action onInRange = null, Action onOutOfRange = null)
        {
            if (m_fence != null)
            {
                ForegroundPositionService.Instance.DiscardFence(m_fence);
            }

            m_fence = ForegroundPositionService.Instance.CreateFence(
                location,
                minRange, maxRange, (locations) =>
            {
                SetInRange(true);

                if (onInRange != null)
                {
                    onInRange();
                }
            },
                () =>
            {
                SetInRange(false);

                if (onOutOfRange != null)
                {
                    onOutOfRange();
                }
            }
                );
        }
예제 #2
0
 static AwarenessFence CreateLocationFence()
 {
     return(AwarenessFence.Or(
                LocationFence.Entering(0, 0, 1000),
                LocationFence.Exiting(0, 0, 1000),
                LocationFence.In(0, 0, 1000, 100)
                ));
 }
예제 #3
0
        internal void DiscardFence(LocationFence fence)
        {
            fence.StopWatching();

            lock (m_fences)
            {
                m_fences.Remove(fence);
            }
        }
예제 #4
0
        public override void Start()
        {
            if (!ActivationContext.IsOpen)
            {
                return;
            }

            ShowTask();

            // Store these - the task can be updated
            m_taskLocations = Task.Locations;

            if (Task.Locations != null &&
                Task.Locations.Length > 0)
            {
                if (ShouldHoldLocations)
                {
                    foreach (var l in Task.Locations)
                    {
                        RecentlyUsedLocationService.Instance.HoldLocation(l);
                    }
                }

                if (Task.ActionRange != null)
                {
                    m_fence = LocationFence.Watch(
                        Task.Locations,
                        Task.ActionRange.Min.GetValueOrDefault(),
                        Task.ActionRange.Max.GetValueOrDefault(double.MaxValue),
                        (inRangeLocations) =>
                    {
                        // In range
                        ActivationContext.FireEvent(TaskAction.InRange);
                        ActivationContext.SetState("in_range");

                        if (Task.Action == TaskAction.InRange)
                        {
                            // That's it! Task is comlete.
                            Complete(inRangeLocations.FirstOrDefault());
                        }
                    },
                        () =>
                    {
                        // Out of range
                        ActivationContext.ClearState("in_range");
                    });
                }
            }

            base.Start();
        }
예제 #5
0
        private async Task RequestLocationSnapshotAsync()
        {
            if (await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location) == PermissionStatus.Granted)
            {
                // store current location
                ILocationResult locationResult = await Awareness.SnapshotApi.GetLocationAsync(AwarenessApiClient);

                global::Android.Locations.Location location = locationResult.Location;
                DateTimeOffset timestamp = new DateTimeOffset(1970, 1, 1, 0, 0, 0, new TimeSpan()).AddMilliseconds(location.Time);
                await StoreDatumAsync(new LocationDatum(timestamp, location.HasAccuracy ? location.Accuracy : -1, location.Latitude, location.Longitude));

                // replace the previous location fence with one around the current location. additions and removals are handled
                // in the order specified below.
                FenceUpdateRequestBuilder locationFenceRequestBuilder = new FenceUpdateRequestBuilder();
                UpdateRequestBuilder(null, AWARENESS_EXITING_LOCATION_FENCE_KEY, FenceUpdateAction.Remove, ref locationFenceRequestBuilder);
                AwarenessFence locationFence = LocationFence.Exiting(location.Latitude, location.Longitude, _locationChangeRadiusMeters);
                UpdateRequestBuilder(locationFence, AWARENESS_EXITING_LOCATION_FENCE_KEY, FenceUpdateAction.Add, ref locationFenceRequestBuilder);
                await UpdateFencesAsync(locationFenceRequestBuilder.Build());
            }
        }
예제 #6
0
        public override void Stop()
        {
            HideTask();

            if (ShouldHoldLocations && Task.Locations != null)
            {
                foreach (var l in Task.Locations)
                {
                    RecentlyUsedLocationService.Instance.ReleaseLocation(l);
                }
            }

            if (m_fence != null)
            {
                m_fence.StopWatching();
                m_fence = null;
            }

            base.Stop();
        }
예제 #7
0
        public LocationFence CreateFence(
            Location location,
            double minRange,
            double maxRange,
            Action <IEnumerable <Location> > inRange,
            Action outOfRange)
        {
            var fence = LocationFence.Watch(
                location,
                minRange,
                maxRange,
                inRange,
                outOfRange);

            lock (m_fences)
            {
                m_fences.Add(fence);
            }

            return(fence);
        }
예제 #8
0
 private async Task <Statuses> RegisterLocationFence() => await Awareness.FenceApi.UpdateFencesAsync(_googleApiClient, new FenceUpdateRequestBuilder()
                                                                                                     .AddFence(LocationFenceKey, LocationFence.Entering(Latitude, Longitude, Radius)
                                                                                                               , PendingIntent.GetBroadcast(this, 10001, new Intent(FenceReceiverAction), PendingIntentFlags.UpdateCurrent))
                                                                                                     .Build());