private async void SaveMeme(object sender, EventArgs e) { ShowActivityIndicator(); if (IsAdd) { MemeCaptions newMeme = new MemeCaptions(); newMeme.UpperCaption = upperCaptionEditor.Text; newMeme.LowerCaption = lowerCaptionEditor.Text; newMeme.computeFullCaption(); newMeme.NeutralVal = neutralSlider.Value; newMeme.SadnessVal = sadnessSlider.Value; newMeme.HappinessVal = happinessSlider.Value; newMeme.DisgustVal = disgustSlider.Value; newMeme.ContemptVal = contemptSlider.Value; newMeme.AngerVal = angerSlider.Value; newMeme.FearVal = fearSlider.Value; newMeme.SurpriseVal = surpriseSlider.Value; MemeList.Items.Add(newMeme); await AzureManager.AzureManagerInstance.CreateNewMeme(newMeme); } else { CurrentlyEditingMeme.UpperCaption = upperCaptionEditor.Text; CurrentlyEditingMeme.LowerCaption = lowerCaptionEditor.Text; CurrentlyEditingMeme.computeFullCaption(); CurrentlyEditingMeme.NeutralVal = neutralSlider.Value; CurrentlyEditingMeme.SadnessVal = sadnessSlider.Value; CurrentlyEditingMeme.HappinessVal = happinessSlider.Value; CurrentlyEditingMeme.DisgustVal = disgustSlider.Value; CurrentlyEditingMeme.ContemptVal = contemptSlider.Value; CurrentlyEditingMeme.AngerVal = angerSlider.Value; CurrentlyEditingMeme.FearVal = fearSlider.Value; CurrentlyEditingMeme.SurpriseVal = surpriseSlider.Value; await AzureManager.AzureManagerInstance.UpdateMeme(CurrentlyEditingMeme); } await Navigation.PopAsync(); }
public MemeEdit(MemeCaptions meme, bool isAdd, MemeListViewModel memeList) { InitializeComponent(); NavigationPage.SetHasNavigationBar(this, false); IsAdd = isAdd; MemeList = memeList; if (isAdd) { // this is work around for slider bug in Xamarin, valueChanged not firing on first time tap neutralSlider.Value = 0.01; happinessSlider.Value = 0.01; sadnessSlider.Value = 0.01; angerSlider.Value = 0.01; fearSlider.Value = 0.01; contemptSlider.Value = 0.01; disgustSlider.Value = 0.01; surpriseSlider.Value = 0.01; } else { CurrentlyEditingMeme = meme; lowerCaptionEditor.Text = meme.LowerCaption; upperCaptionEditor.Text = meme.UpperCaption; neutralSlider.Value = meme.NeutralVal; happinessSlider.Value = meme.HappinessVal; sadnessSlider.Value = meme.SadnessVal; angerSlider.Value = meme.AngerVal; fearSlider.Value = meme.FearVal; contemptSlider.Value = meme.ContemptVal; disgustSlider.Value = meme.DisgustVal; surpriseSlider.Value = meme.SurpriseVal; // this is work around for slider bug in Xamarin, valueChanged not firing on first time tap if (neutralSlider.Value == 0) { neutralSlider.Value = 0.01; } if (happinessSlider.Value == 0) { happinessSlider.Value = 0.01; } if (sadnessSlider.Value == 0) { sadnessSlider.Value = 0.01; } if (angerSlider.Value == 0) { angerSlider.Value = 0.01; } if (fearSlider.Value == 0) { fearSlider.Value = 0.01; } if (contemptSlider.Value == 0) { contemptSlider.Value = 0.01; } if (disgustSlider.Value == 0) { disgustSlider.Value = 0.01; } if (surpriseSlider.Value == 0) { surpriseSlider.Value = 0.01; } deleteButton.IsEnabled = true; } }
public async Task DeleteMeme(MemeCaptions meme) { await this.CaptionTable.DeleteAsync(meme); }
public async Task UpdateMeme(MemeCaptions meme) { await this.CaptionTable.UpdateAsync(meme); }
public async Task CreateNewMeme(MemeCaptions meme) { await this.CaptionTable.InsertAsync(meme); }
async Task MatchPhotoToMeme(MediaFile file) { var client = new HttpClient(); client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "215a704d96294185a8392d0928df1f67"); string uri = "https://westus.api.cognitive.microsoft.com/emotion/v1.0/recognize?"; HttpResponseMessage response; byte[] byteData = GetImageAsByteArray(file); List <EmotionModel> emotionModels = null; using (var content = new ByteArrayContent(byteData)) { content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); response = await client.PostAsync(uri, content); if (response.IsSuccessStatusCode) { var responseString = await response.Content.ReadAsStringAsync(); emotionModels = JsonConvert.DeserializeObject <List <EmotionModel> >(responseString); } } if (emotionModels == null) { await DisplayAlert("Connection Error", "Unable to analyse photo", "OK"); return; } else if (emotionModels.Count < 1) { AttachMeme("THIS IMAGE", "IS NOT EVEN WORTH MEMEFYING"); } else { if (emotionModels.Count > 1) { await DisplayAlert("Hey", "Memefy currently works best with only one face in the photo :)", "OK"); } List <MemeCaptions> memeList = await AzureManager.AzureManagerInstance.GetCaptionList(); double minEmotionDifference = Double.MaxValue; double emotionDifference; MemeCaptions bestMeme = null; foreach (MemeCaptions meme in memeList) { emotionDifference = 0; emotionDifference += Math.Abs(meme.AngerVal - emotionModels[0].Scores.Anger); emotionDifference += Math.Abs(meme.NeutralVal - emotionModels[0].Scores.Neutral); emotionDifference += Math.Abs(meme.HappinessVal - emotionModels[0].Scores.Happiness); emotionDifference += Math.Abs(meme.SadnessVal - emotionModels[0].Scores.Sadness); emotionDifference += Math.Abs(meme.ContemptVal - emotionModels[0].Scores.Contempt); emotionDifference += Math.Abs(meme.FearVal - emotionModels[0].Scores.Fear); emotionDifference += Math.Abs(meme.DisgustVal - emotionModels[0].Scores.Disgust); emotionDifference += Math.Abs(meme.SurpriseVal - emotionModels[0].Scores.Surprise); if (emotionDifference < minEmotionDifference) { minEmotionDifference = emotionDifference; bestMeme = meme; } } if (bestMeme == null) { await DisplayAlert("No memes found", "No memes found", "OK"); return; } else { AttachMeme(bestMeme.UpperCaption, bestMeme.LowerCaption); } } }