async void takePhoto(object sender, EventArgs e) { Stack.IsVisible = true; var photo = await PhotoClient.TakePhotoAsync(); List <ClassData> classDatas = new List <ClassData>(); string[] vs = {}; if (photo == null) { Stack.IsVisible = false; return; } try { var ps = await CognitiveAPIClient.AnalizeAsync(photo.Path); foreach (var v in ps.Images[0].Classifiers[0].Classes) { var transData = App.client.GetAsync("https://script.google.com/macros/s/AKfycbwIMB_gK-VENxT4-BqKAtgOI779dL1TnOyR-qR1wAzjWmXta0W5/exec?text=" + v.Class + "&source=en&target=ja").Result; v.Class = await transData.Content.ReadAsStringAsync(); Console.WriteLine("{0}:{1}:{2}", v.ID, v.Class, v.Score); float num = float.Parse(v.Score) * 100; v.Score = num.ToString() + "%"; var limit = v.Date - DateTime.Now; v.Limit = String.Format("残り : {0}日", limit.Days.ToString()); v.image = photo.AlbumPath; v.Quantity = "1個"; classDatas.Add(v); } foreach (var i in classDatas) { vs.CopyTo(vs = new string[vs.Length + 1], 0); vs[vs.Length - 1] = i.Class; } var res = await DisplayActionSheet("あなたの食品はもしかして...", "閉じる", "破棄する", vs); foreach (var i in classDatas) { if (res == i.Class) { Console.WriteLine("photoUrl : " + i.image); await App.FoodDatabase.SaveItemAsync(i); break; } } listView.ItemsSource = await App.FoodDatabase.GetItemsAsync(); Stack.IsVisible = false; } catch (Exception ex) { await DisplayAlert("通信失敗", "", "閉じる"); Console.WriteLine(ex.Message); return; } }
async void OnSendClicked(object sender, EventArgs e) { if (App.Authenticator.user == null) { await DisplayAlert("ログインしてください", "", "戻る"); await Navigation.PopAsync(); return; } if (Info.Text == null) { await DisplayAlert("情報を入れてください", "", "閉じる"); return; } await DisplayAlert("食材撮影", "今の状態を撮影してください", "OK"); var photoUrl = await PhotoClient.TakePhotoAsync(); if (photoUrl == null) { return; } var num = await postImage(photoUrl.Path); await FoodPost(num); return; }
async void OnSendClicked(object sender, EventArgs e) { if (App.Authenticator.user == null) { await DisplayAlert("ログインしてください", "", "戻る"); await Navigation.PopAsync(); return; } if (Info.Text == null) { await DisplayAlert("情報を入れてください", "", "閉じる"); return; } try { await DisplayAlert("食材撮影", "今の状態を撮影してください", "OK"); var photoUrl = await PhotoClient.TakePhotoAsync(); if (photoUrl == null) { return; } var num = await postImage(photoUrl.Path); await FoodPost(num); } catch (Exception ex) { Console.WriteLine(ex.Message); await DisplayAlert("失敗", "通信に失敗しました", "閉じる"); return; } return; }