Ejemplo n.º 1
0
        void SetupCamera()
        {
            adapter.ItemClick += async(sender, args) =>
            {
                var image = viewModel.Images[args.Position].ThumbnailLink;
                //var percentage = await viewModel.AnalyzeImageAsync(image);
                await viewModel.ShowImageMessage(ImageType, Percentage);
            };

            var fab = FindViewById <FloatingActionButton>(Resource.Id.fab_photo);

            fab.Visibility = ViewStates.Visible;

            fab.Click += async(sender, args) =>
            {
                //Get references to elements
                var progress           = FindViewById <ProgressBar>(Resource.Id.my_progress);
                var happinessLevelText = FindViewById <TextView>(Resource.Id.happiness_level_text);
                var helpCardText       = FindViewById <TextView>(Resource.Id.help_card_text);
                var helpCard           = FindViewById <CardView>(Resource.Id.help_card);

                //Hide startup and results elements
                fab.Enabled                   = false;
                fab.Visibility                = ViewStates.Gone;
                recyclerView.Visibility       = ViewStates.Gone;
                happinessLevelText.Visibility = ViewStates.Gone;

                //Show progress elements
                progress.Visibility     = ViewStates.Visible;
                helpCardText.Text       = "Analysing your happiness...";
                helpCardText.Visibility = ViewStates.Visible;
                helpCard.Visibility     = ViewStates.Visible;

                //Go to photo app then analyse over emotion api
                Percentage = await viewModel.TakePhotoAndAnalyzeAsync();

                //Change analysing text to results text
                var text = string.Format("You are {0}% happy! \nCute coming right up...", Percentage);
                helpCardText.Text = text;

                //Set the images to get
                SetImageType();

                //Search for the images
                await viewModel.SearchForImagesAsync(string.Format("cute {0}", ImageType.Trim()));

                //Set happiness level text
                happinessLevelText.Text = string.Format("You are {0}% happy as {1}", Percentage, ImageType);

                //Hide progress elements
                progress.Visibility     = ViewStates.Gone;
                helpCardText.Visibility = ViewStates.Gone;
                helpCard.Visibility     = ViewStates.Gone;

                //Show results and restart elements
                fab.Visibility = ViewStates.Visible;
                happinessLevelText.Visibility = ViewStates.Visible;
                recyclerView.Visibility       = ViewStates.Visible;
                fab.Enabled = true;
            };
        }