コード例 #1
0
        public void RegisterGeofences(PlaceGeofence[] fenceData)
        {
            if(pendingIntent != null)
            {
                Toast.MakeText(context, "Removing old fences", ToastLength.Short).Show();
                currentStage = FencingStage.Removing;
            }

            if (fencesToAdd == null)
            {
                fencesToAdd = new List<IGeofence>();
            }

            ISharedPreferences prefs = context.GetSharedPreferences("FENCES", FileCreationMode.MultiProcess);
            ISharedPreferencesEditor editor = prefs.Edit();

            editor.Clear();
            editor.Apply();

            foreach (PlaceGeofence fence in fenceData)
            {
                fencesToAdd.Add(new GeofenceBuilder()
                    .SetCircularRegion(fence.lat, fence.lng, fence.radius)
                    .SetExpirationDuration(Geofence.NeverExpire)
                    .SetRequestId(fence.placeId)
                    .SetLoiteringDelay(0)
                    .SetTransitionTypes(Geofence.GeofenceTransitionEnter | Geofence.GeofenceTransitionDwell | Geofence.GeofenceTransitionExit)
                    .Build());

                editor.PutString(fence.placeId, JsonConvert.SerializeObject(fence));
            }

            editor.Apply();

            if(googleApiClient == null)
            {
                intent = new Intent(context, typeof(GeofencingReceiver));
                googleApiClient = new GoogleApiClientBuilder(context)
                    .AddApi(LocationServices.Api)
                    .AddConnectionCallbacks(this)
                    .AddOnConnectionFailedListener(this)
                    .Build();
            }
            
            googleApiClient.Connect();
        }
コード例 #2
0
 private async void OnExitedGeofences(PlaceGeofence fence)
 {
     Intent intent = await PrepareIntent(fence);
     AndroidUtils.SendNotification(
         "Record about " + fence.name + "!", "It looks like you're leaving " + fence.name + "! Why not practice your speech by making a voice diary about your visit?",
         typeof(RecordPlaceEntryActivity), 
         intent,
         this
     );
     RemoveFence(fence);
 }
コード例 #3
0
        private async Task<Intent> PrepareIntent(PlaceGeofence fence)
        {
            Intent intent = new Intent(this, typeof(RecordPlaceEntryActivity));

            string imgRef = (fence.imageRef != null) ? fence.imageRef : null;

            if (imgRef != null)
            {
                imgRef = await ServerData.FetchPlacePhoto(fence, 800, 600);
            }

            intent.PutExtra("PlaceImage", imgRef);
            intent.PutExtra("PlaceName", fence.name);
            intent.PutExtra("PlaceID", fence.placeId);
            intent.PutExtra("PlaceLat", fence.lat);
            intent.PutExtra("PlaceLng", fence.lng);

            return intent;
        }
コード例 #4
0
        /// <summary>
        /// Stop watching this fence to save battery/ prevent being annoying
        /// </summary>
        /// <param name="fence"></param>
        private void RemoveFence(PlaceGeofence fence)
        {
            if(client == null)
            {
                client = new GoogleApiClientBuilder(this)
                    .AddApi(LocationServices.Api)
                    .AddConnectionCallbacks(this)
                    .Build();
            }

            client.Connect();

            toRemove = new List<string>();
            toRemove.Add(fence.placeId);
        }