private void AnchorSaveFailed(string message)
        {
            this.RunOnUiThread(() => this.statusText.Text = message);
            AnchorVisual visual = this.anchorVisuals[string.Empty];

            visual.SetColor(this, Color.Red);
        }
예제 #2
0
        async void IOnClickListener.OnClick(View view)
        {
            if (!CanCreateAnchor())
            {
                return;
            }

            createAnchorButton.Enabled = false;
            CloudSpatialAnchor cloudAnchor = new CloudSpatialAnchor();

            cloudAnchor.LocalAnchor = PlacedVisual.LocalAnchor;
            cloudAnchor.AppProperties.Add("Shape", PlacedVisual.Shape.ToString());

            isCreatingAnchor = true;

            await CloudAnchorManager.CreateAnchorAsync(cloudAnchor);

            if ((cloudAnchor.Identifier?.Length ?? 0) == 0)
            {
                OnAnchorCreationFailed?.Invoke(PlacedVisual, "Failed to create anchor");
                return;
            }

            AnchorVisual createdAnchor = PlacedVisual;

            PlacedVisual = null;
            OnAnchorCreated?.Invoke(createdAnchor);
        }
        private Anchor CreateAnchor(HitResult hitResult)
        {
            AnchorVisual visual = new AnchorVisual(arFragment, hitResult.CreateAnchor());

            visual.SetColor(this, Color.Yellow);
            visual.AddToScene(this.arFragment);
            this.anchorVisuals[string.Empty] = visual;

            this.RunOnUiThread(() =>
            {
                this.scanProgressText.Visibility = ViewStates.Visible;
                if (this.enoughDataForSaving)
                {
                    this.statusText.Text         = "Ready to save";
                    this.actionButton.Text       = "Save cloud anchor";
                    this.actionButton.Visibility = ViewStates.Visible;
                }
                else
                {
                    this.statusText.Text = "Move around the anchor";
                }
            });

            this.currentDemoStep = DemoStep.SaveAnchor;

            return(visual.LocalAnchor);
        }
예제 #4
0
        private Anchor CreateAnchor(HitResult hitResult)
        {
            AnchorVisual visual = new AnchorVisual(hitResult.CreateAnchor());

            visual.SetColor(readyColor);
            visual.AddToScene(this.arFragment);
            this.anchorVisuals[string.Empty] = visual;

            return(visual.LocalAnchor);
        }
 public void OnClick(View view)
 {
     if (visual != null)
     {
         AnchorVisual placedAnchor = visual;
         visual = null;
         placedAnchor.IsMovable = false;
         OnAnchorPlaced?.Invoke(placedAnchor);
     }
 }
예제 #6
0
 public void OnAnchorCreationFailed(AnchorVisual placedAnchor, string errorMessage)
 {
     placedAnchor.Destroy();
     FragmentHelper.BackToPreviousFragment(this);
     RunOnUiThread(() =>
     {
         string toastMessage = "Failed to save anchor: " + errorMessage;
         Toast.MakeText(this, toastMessage, ToastLength.Long).Show();
     });
 }
예제 #7
0
        private void AnchorLookedUp(string anchorId)
        {
            Log.Debug("ASADemo", "anchor " + anchorId);
            this.anchorId = anchorId;
            this.DestroySession();

            bool anchorLocated = false;

            this.cloudAnchorManager = new AzureSpatialAnchorsManager(this.sceneView.Session);
            this.cloudAnchorManager.OnAnchorLocated += (sender, args) =>
                                                       this.RunOnUiThread(() =>
            {
                CloudSpatialAnchor anchor = args.Anchor;
                LocateAnchorStatus status = args.Status;

                if (status == LocateAnchorStatus.AlreadyTracked || status == LocateAnchorStatus.Located)
                {
                    anchorLocated = true;

                    AnchorVisual foundVisual = new AnchorVisual(anchor.LocalAnchor)
                    {
                        CloudAnchor = anchor
                    };
                    foundVisual.AnchorNode.SetParent(this.arFragment.ArSceneView.Scene);
                    string cloudAnchorIdentifier = foundVisual.CloudAnchor.Identifier;
                    foundVisual.SetColor(foundColor);
                    foundVisual.AddToScene(this.arFragment);
                    this.anchorVisuals[cloudAnchorIdentifier] = foundVisual;
                }
            });

            this.cloudAnchorManager.OnLocateAnchorsCompleted += (sender, args) =>
            {
                this.currentStep = DemoStep.Start;

                this.RunOnUiThread(() =>
                {
                    if (anchorLocated)
                    {
                        this.textView.Text = "Anchor located!";
                    }
                    else
                    {
                        this.textView.Text = "Anchor was not located. Check the logs for errors and\\or create a new anchor and try again.";
                    }

                    this.EnableCorrectUIControls();
                });
            };
            this.cloudAnchorManager.StartSession();
            AnchorLocateCriteria criteria = new AnchorLocateCriteria();

            criteria.SetIdentifiers(new string[] { anchorId });
            this.cloudAnchorManager.StartLocating(criteria);
        }
예제 #8
0
        public void OnAnchorPlaced(AnchorVisual placedAnchor)
        {
            var creationFragment = new AnchorCreationFragment();

            creationFragment.OnAnchorCreated        = OnAnchorCreated;
            creationFragment.OnAnchorCreationFailed = OnAnchorCreationFailed;
            creationFragment.CloudAnchorManager     = cloudAnchorManager;
            creationFragment.PlacedVisual           = placedAnchor;
            FragmentHelper.BackToPreviousFragment(this);
            FragmentHelper.PushFragment(this, creationFragment);
        }
        public override void OnStop()
        {
            arFragment.SetOnTapArPlaneListener(null);

            if (visual != null)
            {
                visual.Destroy();
                visual = null;
            }

            base.OnStop();
        }
        private void RenderLocatedAnchor(CloudSpatialAnchor anchor)
        {
            AnchorVisual foundVisual = new AnchorVisual(arFragment, anchor.LocalAnchor)
            {
                CloudAnchor = anchor
            };

            foundVisual.AnchorNode.SetParent(this.arFragment.ArSceneView.Scene);
            string cloudAnchorIdentifier = foundVisual.CloudAnchor.Identifier;

            foundVisual.SetColor(this, Color.Red);
            foundVisual.AddToScene(this.arFragment);
            this.anchorVisuals[cloudAnchorIdentifier] = foundVisual;
        }
예제 #11
0
        public void OnAnchorDiscovered(CloudSpatialAnchor cloudAnchor)
        {
            AnchorVisual visual = new AnchorVisual(arFragment, cloudAnchor);

            visual.SetColor(this, Android.Graphics.Color.Green);
            IDictionary <string, string> properties = cloudAnchor.AppProperties;

            if (properties.ContainsKey("Shape"))
            {
                if (Enum.TryParse(properties["Shape"], out AnchorVisual.NamedShape savedShape))
                {
                    visual.Shape = savedShape;
                }
            }
            visual.AddToScene(arFragment);
        }
예제 #12
0
        async void IOnClickListener.OnClick(View view)
        {
            if (!CanCreateAnchor())
            {
                return;
            }

            createAnchorButton.Enabled = false;
            CloudSpatialAnchor cloudAnchor = new CloudSpatialAnchor();

            cloudAnchor.LocalAnchor = PlacedVisual.LocalAnchor;
            cloudAnchor.AppProperties.Add("Shape", PlacedVisual.Shape.ToString());

            isCreatingAnchor = true;
            await CloudAnchorManager.CreateAnchorAsync(cloudAnchor)
            .ContinueWith(async cloudAnchorTask =>
            {
                try
                {
                    CloudSpatialAnchor anchor = await cloudAnchorTask;

                    string anchorId = anchor.Identifier;
                    Log.Debug("ASADemo", "anchorId: " + anchorId);
                    var anchorSharingServiceClient = new AnchorSharingServiceClient(AccountDetails.AnchorSharingServiceUrl);
                    SendAnchorResponse response    = await anchorSharingServiceClient.SendAnchorIdAsync(anchorId);
                }
                catch (CloudSpatialException)
                {
                    // to do
                    //this.CreateAnchorExceptionCompletion($"{ex.Message}, {ex.ErrorCode}");
                }
                catch (Exception)
                {
                    // to do
                    //this.CreateAnchorExceptionCompletion(ex.Message);
                    //visual.SetColor(this, Color.Red);
                }
            });

            AnchorVisual createdAnchor = PlacedVisual;

            PlacedVisual = null;
            OnAnchorCreated?.Invoke(createdAnchor);
        }
        private void TransitionToSaving(AnchorVisual visual)
        {
            Log.Debug("ASADemo:", "transition to saving");
            this.currentStep = DemoStep.SavingAnchor;
            this.EnableCorrectUIControls();
            Log.Debug("ASADemo", "creating anchor");
            CloudSpatialAnchor cloudAnchor = new CloudSpatialAnchor();

            //Date d1 = new Date(2030, 11, 21);
            //cloudAnchor.Expiration = d1;

            visual.CloudAnchor      = cloudAnchor;
            cloudAnchor.LocalAnchor = visual.LocalAnchor;

            this.cloudAnchorManager.CreateAnchorAsync(cloudAnchor)
            .ContinueWith(async cloudAnchorTask =>
            {
                try
                {
                    CloudSpatialAnchor anchor = await cloudAnchorTask;

                    string anchorId = anchor.Identifier;
                    Log.Debug("ASADemo:", "created anchor: " + anchorId);
                    visual.SetColor(this, Color.Green);
                    this.anchorVisuals[anchorId] = visual;
                    this.anchorVisuals.TryRemove(string.Empty, out _);

                    Log.Debug("ASADemo", "recording anchor with web service");
                    Log.Debug("ASADemo", "anchorId: " + anchorId);
                    SendAnchorResponse response = await this.anchorSharingServiceClient.SendAnchorIdAsync(anchorId);
                    this.AnchorPosted(response.AnchorNumber);
                }
                catch (CloudSpatialException ex)
                {
                    this.CreateAnchorExceptionCompletion($"{ex.Message}, {ex.ErrorCode}");
                }
                catch (Exception ex)
                {
                    this.CreateAnchorExceptionCompletion(ex.Message);
                    visual.SetColor(this, Color.Red);
                }
            });
        }
        private void SetupLocalCloudAnchor(AnchorVisual visual)
        {
            CloudSpatialAnchor cloudAnchor = new CloudSpatialAnchor
            {
                LocalAnchor = visual.LocalAnchor
            };

            visual.CloudAnchor = cloudAnchor;

            // In this sample app we delete the cloud anchor explicitly, but you can also set it to expire automatically
            Date     now = new Date();
            Calendar cal = Calendar.Instance;

            cal.Time = now;
            cal.Add(CalendarField.Date, 7);
            Date oneWeekFromNow = cal.Time;

            cloudAnchor.Expiration = oneWeekFromNow;
        }
        public void OnTapPlane(HitResult hitResult, Plane plane, MotionEvent motionEvent)
        {
            if (visual != null)
            {
                visual.Destroy();
                visual = null;
            }

            Anchor localAnchor = hitResult.CreateAnchor();

            visual           = new AnchorVisual(arFragment, localAnchor);
            visual.IsMovable = true;
            visual.Shape     = SelectedShape;
            visual.SetColor(arFragment.Context, Color.Yellow);
            visual.AddToScene(arFragment);

            hintText.SetText(Resource.String.hint_adjust_anchor);

            confirmPlacementButton.Enabled = true;
        }
        private void AnchorSaveSuccess(CloudSpatialAnchor result)
        {
            this.saveCount++;

            this.anchorID = result.Identifier;
            Log.Debug("ASADemo:", "created anchor: " + this.anchorID);

            AnchorVisual visual = this.anchorVisuals[string.Empty];

            visual.SetColor(this, Color.Green);
            this.anchorVisuals[this.anchorID] = visual;
            this.anchorVisuals.TryRemove(string.Empty, out _);

            if (this.basicDemo || this.saveCount == numberOfNearbyAnchors)
            {
                this.RunOnUiThread(() =>
                {
                    this.statusText.Text         = string.Empty;
                    this.actionButton.Visibility = ViewStates.Visible;
                });

                this.currentDemoStep = DemoStep.StopSession;
                this.AdvanceDemo();
            }
            else
            {
                // Need to create more anchors for nearby demo
                this.RunOnUiThread(() =>
                {
                    this.statusText.Text         = "Tap a surface to create next anchor";
                    this.actionButton.Visibility = ViewStates.Invisible;
                });

                this.currentDemoStep = DemoStep.CreateAnchor;
            }
        }
        private void TransitionToSaving(AnchorVisual visual)
        {
            Log.Debug("ASADemo:", "transition to saving");
            currentStep = DemoStep.MindrSaving;
            EnableCorrectUIControls();
            Log.Debug("ASADemo", "creating anchor");
            CloudSpatialAnchor cloudAnchor = new CloudSpatialAnchor();

            visual.CloudAnchor      = cloudAnchor;
            cloudAnchor.LocalAnchor = visual.LocalAnchor;

            cloudAnchorManager.CreateAnchorAsync(cloudAnchor)
            .ContinueWith(async cloudAnchorTask =>
            {
                try
                {
                    CloudSpatialAnchor anchor = await cloudAnchorTask;

                    string anchorId = anchor.Identifier;

                    Log.Debug("ASADemo:", "created anchor: " + anchorId);

                    Log.Debug("ASADemo", "recording anchor with web service");
                    Log.Debug("ASADemo", "anchorId: " + anchorId);

                    //SendAnchorResponse response = await this.anchorSharingServiceClient.SendAnchorIdAsync(anchorId);

                    var saveAnchorResult = await _mindrService.CreateAnchorAsync(anchorNumInput.Text, anchor.Identifier);
                    if (saveAnchorResult != null)
                    {
                        CrossClipboard.Current.SetText($"{MindrService.MindrService.BaseUrl}{saveAnchorResult.uri}");
                        visual.SetColor(savedColor);
                        AnchorPosted("");

                        await Task.Delay(1000);
                        RunOnUiThread(() =>
                        {
                            var shareIntent = new Intent(Android.Content.Intent.ActionSend);
                            shareIntent.SetType("text/plain");
                            shareIntent.PutExtra(Intent.ExtraText, $"{MindrService.MindrService.BaseUrl}{saveAnchorResult.uri}");
                            StartActivity(shareIntent);
                        });
                        await Task.Delay(1000);

                        RunOnUiThread(LocateAllAnchors);
                    }
                    else
                    {
                        visual.SetColor(failedColor);
                        await cloudAnchorManager.DeleteAnchorAsync(anchor);
                    }

                    anchorVisuals[anchorId] = visual;
                    anchorVisuals.TryRemove(string.Empty, out _);
                }
                catch (CloudSpatialException ex)
                {
                    CreateAnchorExceptionCompletion($"{ex.Message}, {ex.ErrorCode}");
                }
                catch (Exception ex)
                {
                    CreateAnchorExceptionCompletion(ex.Message);
                    visual.SetColor(failedColor);
                }
            });
        }
        public async void LocateAllAnchors()
        {
            await Task.Delay(2000);

            textView.Text = "Searching for MindRs...";

            // clean up prev session just in case
            DestroySession();

            // start locating
            cloudAnchorManager = new AzureSpatialAnchorsManager(sceneView.Session);

            var anchorLocated = false;

            cloudAnchorManager.OnAnchorLocated += (sender, args) =>
                                                  RunOnUiThread(async() =>
            {
                CloudSpatialAnchor anchor = args.Anchor;
                LocateAnchorStatus status = args.Status;

                if (status == LocateAnchorStatus.AlreadyTracked || status == LocateAnchorStatus.Located)
                {
                    AnchorVisual foundVisual = new AnchorVisual(anchor.LocalAnchor)
                    {
                        CloudAnchor = anchor
                    };

                    var mr = await _mindrService.TryGetContentsForAnchor(anchor.Identifier);
                    textView.Visibility = ViewStates.Visible;
                    textView.Text       = mr != null ? mr.actualDesc : "No data found for MindR.";

                    foundVisual.AnchorNode.SetParent(arFragment.ArSceneView.Scene);
                    string cloudAnchorIdentifier = foundVisual.CloudAnchor.Identifier;
                    foundVisual.SetColor(foundColor);
                    foundVisual.AddToScene(arFragment, textView.Text);
                    anchorVisuals[cloudAnchorIdentifier] = foundVisual;


                    foundVisual.AnchorNode.SetOnTouchListener(this);
                    anchorLocated = true;
                }
            });

            cloudAnchorManager.OnLocateAnchorsCompleted += (sender, args) =>
            {
                currentStep = DemoStep.MindrStart;

                RunOnUiThread(() =>
                {
                    textView.Text = anchorLocated ? "MindR(s) located!" : "Failed to find any MindRs.";

                    EnableCorrectUIControls();
                });
            };

            cloudAnchorManager.StartSession();

            await Task.Delay(2000);

            var ac  = new AnchorLocateCriteria();
            var ids = await _mindrService.GetAllAnchorIds();

            ac.SetIdentifiers(ids.ToArray());
            cloudAnchorManager.StartLocating(ac);
        }
예제 #19
0
 public void OnAnchorCreated(AnchorVisual createdAnchor)
 {
     createdAnchor.SetColor(this, Android.Graphics.Color.Green);
     FragmentHelper.BackToPreviousFragment(this);
 }