private async Task TakePhotoClick() { if (!this.captureInProgress) { this.captureInProgress = true; var photoBytes = await this.cameraView.TakePicture(); this.infoTitleText.Text = RatingMsgHelper.GetRecognizingRatingTitle(); this.infoDescriptionText.Text = RatingMsgHelper.GetRecognizingRatingDescription(); this.stars.Visibility = ViewStates.Visible; this.overlay.Visibility = ViewStates.Visible; this.takePhotoImage.Visibility = ViewStates.Invisible; this.smilePattern.Visibility = ViewStates.Invisible; this.infoDescriptionText.Visibility = ViewStates.Visible; using (var memoryStream = new MemoryStream(photoBytes)) { var emotionService = new EmotionService(); var firstFaceEmotion = default(Emotion); try { var emotionList = await emotionService.RecognizeAsync(memoryStream); firstFaceEmotion = emotionList.FirstOrDefault(); } catch { await UserDialogs.Instance.AlertAsync("There was an error analyzing your photo. Please, try again."); } if (firstFaceEmotion != null) { var happiness = firstFaceEmotion.Scores.Happiness; var textDescriptions = emotionService.GetTextsFor(happiness); this.infoTitleText.Text = textDescriptions.Top; this.infoDescriptionText.Text = textDescriptions.Message; RunStarAnimation(happiness); } else { this.infoTitleText.Text = RatingMsgHelper.GetNoFaceDetectedTitle(); this.infoDescriptionText.Text = RatingMsgHelper.GetNoFaceDetectedMsg(); } this.postButtons.Visibility = ViewStates.Visible; this.overlay.Visibility = ViewStates.Invisible; } this.captureInProgress = false; } }
private void SetInitialState() { this.infoTitleText.Text = RatingMsgHelper.GetInitialRatingTitle(); this.starsView.Percentage = 0.0f; this.stars.Visibility = ViewStates.Invisible; this.takePhotoImage.Visibility = ViewStates.Visible; this.postButtons.Visibility = ViewStates.Invisible; this.smilePattern.Visibility = ViewStates.Visible; this.infoDescriptionText.Visibility = ViewStates.Invisible; this.overlay.Visibility = ViewStates.Invisible; }