Ejemplo n.º 1
0
        protected virtual async void RangingBeaconsInRegion(object sender, ICollection <AltBeaconOrg.BoundBeacon.Beacon> beacons)
        {
            MvxTrace.TaggedTrace(TAG, "RangingBeaconsInRegion");

            if (beacons != null && beacons.Count > 0)
            {
                var foundBeacons = beacons.ToList();
                foreach (var beacon in foundBeacons)
                {
                    if (beacon.BeaconTypeCode == 0x10) //Eddystone URL
                    {
                        var url = UrlBeaconUrlCompressor.Uncompress(beacon.Id1.ToByteArray());
                        await BeaconsService.Instance.ActivateEddystoneUrl(url);
                    }
                    else if (beacon.BeaconTypeCode == 0x00) //Eddystone UID
                    {
                        var uid = beacon.Id1.ToString().Replace("0x", "") + beacon.Id2.ToString().Replace("0x", "");
                        await BeaconsService.Instance.ActivateEddystoneUrl(uid);
                    }
                    else if (beacon.BeaconTypeCode == 533) //iBeacon
                    {
                        await BeaconsService.Instance.ActivateiBeacon(
                            beacon.Id1.ToString().Replace("-", ""),
                            Int32.Parse(beacon.Id2.ToString()),
                            Int32.Parse(beacon.Id3.ToString())
                            );
                    }
                }
            }
        }
        protected override void OnHandleIntent(Intent intent)
        {
            if (intent == null)
            {
                return;
            }

            MvxTrace.TaggedTrace(TAG, "GeofenceTransitionsIntentService handle intent");

            var geofencingEvent = GeofencingEvent.FromIntent(intent);

            if (geofencingEvent.HasError)
            {
                var errorMessage = GeofenceErrorMessages.GetErrorString(this, geofencingEvent.ErrorCode);
                MvxTrace.TaggedError(TAG, errorMessage);
                return;
            }

            int geofenceTransition = geofencingEvent.GeofenceTransition;

            if (geofenceTransition != Geofence.NeverExpire)
            {
                IList <IGeofence> triggeringGeofences = geofencingEvent.TriggeringGeofences;

                var geofencesIds = GetGeofenceTransitionDetails(this, geofenceTransition, triggeringGeofences);
                LoadOffersInGeofences(geofencesIds);
            }
            else
            {
                // Log the error.
                MvxTrace.TaggedError(TAG, GetString(Resource.String.geofence_transition_invalid_type, new[] { new Java.Lang.Integer(geofenceTransition) }));
            }
        }
        public Task <bool> Start()
        {
            MvxTrace.TaggedTrace(MvxTraceLevel.Diagnostic, "Geofencing", "Start");

            var  tcs    = new TaskCompletionSource <bool>();
            bool result = false;

            UIKit.UIApplication.SharedApplication.InvokeOnMainThread(async() =>
            {
                result = await GeofencingUtil.RequestPermissionAsync();

                if (result)
                {
                    GeofencingProvider.UpdateRegionLeft += OnUpdateRegionLeft;
                    GeofencingProvider.RegionEntered    += OnRegionEntered;
                    GeofencingProvider.InitGeoFencing();

                    await SetupRegions();
                }

                tcs.TrySetResult(result);
            });

            return(tcs.Task);
        }
        protected virtual void StartMvvmCross(MvxIosViewPresenter presenter, MvxAsyncIosSetup setup)
        {
            Task.Run(async() =>
            {
                try
                {
                    await setup.InitializeAsync();

                    var startup = Mvx.Resolve <IMvxAppStart>();

                    InvokeOnMainThread(() =>
                    {
                        startup.Start();

                        RequestNotificationAuthorization();

                        Initialized = true;

                        OnInitialized?.Invoke();
                    });
#if DEBUG
                    MvxTrace.TaggedTrace(MvxTraceLevel.Diagnostic, this.GetType().FullName, $"Ellapsed milliseconds after MvvmCross setup {Base.Core.ServicesDebug.StartupTimerService.Instance.EllapsedMilliseconds()}");
                    Base.Core.ServicesDebug.StartupTimerService.Instance.StopTimer();
#endif
                }
                catch (Exception ex)
                {
                    MvxTrace.TaggedTrace(MvxTraceLevel.Error, this.GetType().FullName, ex.BuildAllMessagesAndStackTrace());
                }
            });
        }
        public override void OnCreate()
        {
            base.OnCreate();

            BuildGoogleApiClient();
            MvxTrace.TaggedTrace(TAG, "Created");
        }
Ejemplo n.º 6
0
        public void StartRagingBeacons()
        {
            MvxTrace.TaggedTrace(TAG, "StartRagingBeacons");

            if (_rangeNotifier != null)
            {
                return;
            }

            BEACONS_REGION_HEADER = $"beacons_{Context.PackageName}";

            _beaconManager = BeaconManager.GetInstanceForApplication(this);

            _regionBootstrap = new RegionBootstrap(this, new AltBeaconOrg.BoundBeacon.Region(BEACONS_REGION_HEADER, null, null, null));
            _powerSaver      = new BackgroundPowerSaver(this);

            RegisterActivityLifecycleCallbacks(this);

            _rangeNotifier = new RangeNotifier();

            //iBeacon
            _beaconManager.BeaconParsers.Add(new BeaconParser().SetBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));

            //Estimote
            _beaconManager.BeaconParsers.Add(new BeaconParser().SetBeaconLayout(BeaconParser.EddystoneUidLayout));
            _beaconManager.BeaconParsers.Add(new BeaconParser().SetBeaconLayout(BeaconParser.EddystoneTlmLayout));

            _beaconManager.BeaconParsers.Add(new BeaconParser().SetBeaconLayout(BeaconParser.EddystoneUrlLayout));

            _beaconManager.Bind(this);
        }
Ejemplo n.º 7
0
        private void PurgeMessagesOfType(Type type)
        {
            lock (this)
            {
                Dictionary <Guid, BaseSubscription> messageSubscriptions;
                if (!_subscriptions.TryGetValue(type, out messageSubscriptions))
                {
                    return;
                }

                var deadSubscriptionIds = new List <Guid>();
                foreach (var subscription in messageSubscriptions)
                {
                    if (!subscription.Value.IsAlive)
                    {
                        deadSubscriptionIds.Add(subscription.Key);
                    }
                }

                MvxTrace.TaggedTrace(GetType().Name, "Purging {0} subscriptions", deadSubscriptionIds.Count);
                foreach (var id in deadSubscriptionIds)
                {
                    messageSubscriptions.Remove(id);
                }

                PublishSubscriberChangeMessage(type, messageSubscriptions);
            }
        }
        protected override void TriggerFirstNavigate()
        {
#if DEBUG
            MvxTrace.TaggedTrace(MvxTraceLevel.Diagnostic, this.GetType().FullName, $"Ellapsed milliseconds after MvvmCross started {Base.Core.ServicesDebug.StartupTimerService.Instance.EllapsedMilliseconds()}");
            Core.ServicesDebug.StartupTimerService.Instance.StopTimer();
#endif
            base.TriggerFirstNavigate();
        }
Ejemplo n.º 9
0
        public virtual void DidEnterRegion(AltBeaconOrg.BoundBeacon.Region region)
        {
            MvxTrace.TaggedTrace(TAG, "DidEnterRegion {1}. SinceBoot: {0}", _haveDetectedBeaconsSinceBoot, region.UniqueId);

            if (!_haveDetectedBeaconsSinceBoot)
            {
                _haveDetectedBeaconsSinceBoot = true;
            }
        }
Ejemplo n.º 10
0
        // thats an OVERLOAD!, just in case somebody reads way to fast ;)
        public bool ShowViewModel(MvxViewModelRequest request, bool viewModelShouldHandleError = true)
        {
            Action action = () => {
                MvxTrace.TaggedTrace("DroidNavigation", "Navigate requested");
                _presenter.Show(request);
            };

            return(RequestMainThreadAction(action));
        }
Ejemplo n.º 11
0
        public static void Trace(MvxTraceLevel level, string message, params object[] args)
        {
            if (level < TraceBindingLevel)
            {
                return;
            }

            MvxTrace.TaggedTrace(level, Tag, message, args);
        }
Ejemplo n.º 12
0
 public bool RequestNavigate(MvxShowViewModelRequest request)
 {
     Action action = () =>
                         {
                             MvxTrace.TaggedTrace("MacNavigation", "Navigate requested");
                             _presenter.Show(request);
                         };
     return RequestMainThreadAction(action);
 }
Ejemplo n.º 13
0
 public bool RequestClose(IMvxViewModel toClose)
 {
     Action action = () =>
                         {
                             MvxTrace.TaggedTrace("MacNavigation", "Navigate back requested");
                             _presenter.Close(toClose);
                         };
     return RequestMainThreadAction(action);
 }
Ejemplo n.º 14
0
        public bool ShowViewModel(MvxViewModelRequest request)
        {
            Action action = () =>
            {
                MvxTrace.TaggedTrace("UnityNavigation", "Navigate requested");
                _presenter.Show(request);
            };

            return(RequestMainThreadAction(action));
        }
Ejemplo n.º 15
0
        protected bool RequestClose(IMvxViewModel toClose)
        {
            MvxTrace.TaggedTrace("Navigation", "Close requested");
            if (ViewDispatcher != null)
            {
                return(ViewDispatcher.RequestClose(toClose));
            }

            return(false);
        }
Ejemplo n.º 16
0
        public bool ChangePresentation(MvxPresentationHint hint)
        {
            Action action = () =>
            {
                MvxTrace.TaggedTrace("MacNavigation", "Change presentation requested");
                this._presenter.ChangePresentation(hint);
            };

            return(this.RequestMainThreadAction(action));
        }
        private string[] GetGeofenceTransitionDetails(Context context, int geofenceTransition, IList <IGeofence> triggeringGeofences)
        {
            string geofenceTransitionString = GetTransitionString(geofenceTransition);

            var triggeringGeofencesIdsList = triggeringGeofences.Select(x => x.RequestId).ToArray();

            MvxTrace.TaggedTrace(TAG, geofenceTransitionString + ": " + string.Join(", ", triggeringGeofencesIdsList));

            return(triggeringGeofencesIdsList);
        }
        public void OnLocationChanged(global::Android.Locations.Location location)
        {
            if (_googleApiClient == null || !_googleApiClient.IsConnected)
            {
                return;
            }

            UpdateRegions(location);

            MvxTrace.TaggedTrace(TAG, string.Format("OnLocationChanged Lat {0} : Long {1} – Accuracy {2} : Speed {3}", location.Latitude, location.Longitude, location.Accuracy, location.Speed));
        }
Ejemplo n.º 19
0
        public bool ShowViewModel(MvxViewModelRequest request)
        {
            Action action = () =>
            {
                MvxTrace.TaggedTrace("iOSNavigation", "Navigate requested");
                //IT seems that here is a problem in the stack.
                this._presenter.Show(request);
            };

            return(this.RequestMainThreadAction(action));
        }
 protected virtual async void OnRegionEntered(object sender, string id)
 {
     try
     {
         await AreaService.Instance.ActivateRegionBy(id);
     }
     catch (Exception ex)
     {
         MvxTrace.TaggedTrace(MvxTraceLevel.Error, "Geofencing", ex.BuildAllMessagesAndStackTrace());
     }
 }
 private void HandleResult(Statuses status, string message)
 {
     if (status.IsSuccess)
     {
         MvxTrace.TaggedTrace(TAG, message);
     }
     else
     {
         var errorMessage = GeofenceErrorMessages.GetErrorString(Application.Context, status.StatusCode);
         MvxTrace.TaggedError(TAG, errorMessage);
     }
 }
        private void DestroyService()
        {
            if (_googleApiClient != null && _googleApiClient.IsConnected)
            {
                LocationServices.FusedLocationApi.RemoveLocationUpdates(_googleApiClient, this);
                _googleApiClient?.Disconnect();
            }

            _geofenceList = new List <IGeofence>();

            MvxTrace.TaggedTrace(TAG, "Service been destroyed");
        }
Ejemplo n.º 23
0
        public void Load()
        {
            Mvx.RegisterSingleton <IGeofencingService>(() => new GeofencingService());

            try
            {
                Mvx.Resolve <IGeofencingService>().Start();
            }
            catch (Exception ex)
            {
                MvxTrace.TaggedTrace("Geofencing", ex.BuildAllMessagesAndStackTrace());
            }
        }
Ejemplo n.º 24
0
        public void Load()
        {
            Mvx.RegisterSingleton <IBeaconsScanService>(() => new BeaconsScanService());

            try
            {
                Mvx.Resolve <IBeaconsScanService>().Start();
            }
            catch (Exception ex)
            {
                MvxTrace.TaggedTrace("Beacons", ex.BuildAllMessagesAndStackTrace());
            }
        }
Ejemplo n.º 25
0
        protected bool RequestNavigate(Type viewModelType, IDictionary <string, string> parameterValues, bool clearTop, MvxRequestedBy requestedBy)
        {
            MvxTrace.TaggedTrace("Navigation", "Navigate to " + viewModelType.Name + " with args");
            if (ViewDispatcher != null)
            {
                return(ViewDispatcher.RequestNavigate(new MvxShowViewModelRequest(
                                                          viewModelType,
                                                          parameterValues,
                                                          clearTop,
                                                          requestedBy)));
            }

            return(false);
        }
        public async Task Stop()
        {
            MvxTrace.TaggedTrace(MvxTraceLevel.Error, "Geofencing", "Stop");

            var result = await GeofencingUtil.RequestPermissionAsync();

            if (result)
            {
                GeofencingProvider.UpdateRegionLeft -= OnUpdateRegionLeft;
                GeofencingProvider.RegionEntered    -= OnRegionEntered;

                GeofencingProvider.SetRegions(new System.Collections.Generic.List <CoreLocation.CLCircularRegion>());
            }
        }
Ejemplo n.º 27
0
        public Task <Coordinates> GetCurrentLocation()
        {
            var tcs = new TaskCompletionSource <Coordinates>();

            //плагин геолокации работает только в главном потоке
            Mvx.Resolve <IMvxMainThreadDispatcher>().RequestMainThreadAction(async() =>
            {
                Coordinates location = default(Coordinates);

                var hasPermission = await Mvx.Resolve <IPermissionsService>().CheckPermission(Permission.LocationWhenInUse);
                if (hasPermission)
                {
                    Position position = null;
                    try
                    {
                        var locator             = CrossGeolocator.Current;
                        locator.DesiredAccuracy = 100;

                        position = await locator.GetLastKnownLocationAsync();

                        if (position == null && locator.IsGeolocationAvailable && locator.IsGeolocationEnabled)
                        {
                            position = await locator.GetPositionAsync(TimeSpan.FromSeconds(20), null, true);
                        }
                    }
                    catch (Exception ex)
                    {
                        MvxTrace.TaggedTrace(MvxTraceLevel.Error, nameof(LocationService), () => ex.BuildAllMessagesAndStackTrace());
                    }

                    if (position != null)
                    {
                        var output = string.Format("Time: {0} \nLat: {1} \nLong: {2} \nAltitude: {3} \nAltitude Accuracy: {4} \nAccuracy: {5} \nHeading: {6} \nSpeed: {7}",
                                                   position.Timestamp, position.Latitude, position.Longitude,
                                                   position.Altitude, position.AltitudeAccuracy, position.Accuracy, position.Heading, position.Speed);

                        MvxTrace.TaggedTrace(MvxTraceLevel.Diagnostic, nameof(LocationService), () => output);

                        location = (CurrentOrLastLocation = new Coordinates {
                            Latitude = position.Latitude, Longitude = position.Longitude
                        });
                    }
                }

                tcs.TrySetResult(location);
            });

            return(tcs.Task);
        }
        private static void LocationManager_RegionLeft(object sender, CLRegionEventArgs e)
        {
            MvxTrace.TaggedTrace("Geofencing", "Left region " + e.Region.Identifier);

            if (e.Region.Identifier == USER_REGION_HEADER)
            {
                UpdateRegionLeft?.Invoke(null, EventArgs.Empty);
                return;
            }

            if (!e.Region.Identifier.StartsWith(GEO_REGION_HEADER))
            {
                return;                 //TODO On Region Lefted
            }
        }
        public override void OnTaskRemoved(Intent rootIntent)
        {
            var restartServiceIntent = new Intent(Application.Context, this.Class);

            restartServiceIntent.SetPackage(Application.Context.PackageName);

            var restartServicePendingIntent = PendingIntent.GetService(Application.Context, 3, restartServiceIntent, PendingIntentFlags.OneShot);
            var alarmService = (AlarmManager)Application.Context.GetSystemService(Context.AlarmService);

            alarmService.Set(
                AlarmType.RtcWakeup,
                SystemClock.CurrentThreadTimeMillis() + 1000,
                restartServicePendingIntent);

            MvxTrace.TaggedTrace(TAG, "Start after removed");
        }
            public override void OnReceive(Context context, Intent intent)
            {
                var restartServiceIntent = new Intent(Application.Context, typeof(GeofencingIntentService));

                restartServiceIntent.SetPackage(Application.Context.PackageName);

                PendingIntent restartServicePendingIntent = PendingIntent.GetService(Application.Context, 3, restartServiceIntent, PendingIntentFlags.OneShot);
                AlarmManager  alarmService = (AlarmManager)Application.Context.GetSystemService(Context.AlarmService);

                alarmService.Set(
                    AlarmType.RtcWakeup,
                    SystemClock.CurrentThreadTimeMillis() + 1000,
                    restartServicePendingIntent);

                MvxTrace.TaggedTrace(TAG, "Start after boot completed");
            }