/// <summary> /// When the user presses Customization /// Only call from XAML /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void Customize_Button_Clicked(object sender, EventArgs e) { if (Navigation.ModalStack.Count < 1) { if (!Customization.IsLoaded()) { await Navigation.PushModalAsync(new LoadingIndicator()); await Task.Run(() => { Customization.Reload(); }); await Navigation.PopModalAsync(false); } //await Navigation.PushModalAsync(new Customization()); await Navigation.PushModalAsync(new HelpMe(false)); } }
/// <summary> /// When user presses a custom conclusion button /// Only call from XAML /// </summary> /// <param name="se"></param> /// <param name="ee"></param> void Handle_CustomConclusion(object se, EventArgs ee) { string str = (se as Button).Text; string tut = ""; customConclusionHolder = Customization.GetItem(str); string sentence = subjectHolder.GetName() + " " + emotionHolder.GetName() + " " + customConclusionHolder.GetConjunction() + " " + customConclusionHolder.GetConclusion() + (subjectHolder.GetName().ToLower().StartsWith("i") ? "." : "?"); text.FontSize = CalculateFontSize(sentence); text.Text = sentence; if (keepTut) { tut = "Your full sentence is displayed here:\r\n"; Tutorial.self.tutSetPageTwo(se, ee, tutFiveText, 0.1, 0.05); topFlex.IsEnabled = false; BackButton.IsEnabled = true; } DisplayAlert("Sentence", tut + subjectHolder.GetName() + " " + emotionHolder.GetName() + " " + customConclusionHolder.GetConjunction() + " " + customConclusionHolder.GetConclusion() + (subjectHolder.GetName().ToLower().StartsWith("i") ? "." : "?"), "OK"); canGoBack = true; }
/// <summary> /// Load the default list of Conclusions from the included Options.csv /// </summary> public static void Init() { if (File.Exists(Customization.customFilename)) { Customization.Reload(); foreach (CustomConclusion c in Customization.conclusions) { AddPhrase(Time.Preset, c.GetSubject(), c.GetEmotion()); } } else { //TODO: this needs to be changed to work with iOS string res = "Oigo.Droid.Options.csv"; Stream s = IntrospectionExtensions.GetTypeInfo(typeof(GlobalData)).Assembly.GetManifestResourceStream(res); using (StreamReader reader = new StreamReader(s)) { string line; string subject = ""; string emotion = ""; string[] connection = new string[3]; string[] conclusion = new string[3]; string[] temp; while ((line = reader.ReadLine()) != null) { if (line.StartsWith(".") || line.Replace(',', ' ').Trim().Length == 0) { continue; } temp = line.Trim().Split(','); if (temp[0].Trim().Length > 0) { subject = temp[0].Trim(); } if (temp[1].Trim().Length > 0) { emotion = temp[1].Trim(); } if (temp[2].Trim().Length > 0) { connection[0] = temp[2].Trim(); connection[1] = temp[5].Trim(); connection[2] = temp[8].Trim(); } if (temp[3].Trim().Length > 0) { conclusion[0] = temp[3].Trim(); conclusion[1] = temp[6].Trim(); conclusion[2] = temp[9].Trim(); for (int i = 0; i < 3; i++) { AddPhrase((Time)i, subject, emotion, connection[i], conclusion[i]); } } } } Customization.Save(); } if (File.Exists(HelpCustomization.customFilename)) { HelpCustomization.Reload(); } else { //TODO: this needs to be changed to work with iOS string res = "Oigo.Droid.Helpme.csv"; Stream s = IntrospectionExtensions.GetTypeInfo(typeof(GlobalData)).Assembly.GetManifestResourceStream(res); using (StreamReader reader = new StreamReader(s)) { string line; string subject = ""; string emotion = ""; string connection = ""; string solution = ""; string[] temp; while ((line = reader.ReadLine()) != null) { if (line.StartsWith(".") || line.Replace(',', ' ').Trim().Length == 0) { continue; } temp = line.Trim().Split(','); if (temp[0].Trim().Length > 0) { subject = temp[0].Trim(); } if (temp[1].Trim().Length > 0) { emotion = temp[1].Trim(); } if (temp[2].Trim().Length > 0) { connection = temp[2].Trim(); } if (temp[3].Trim().Length > 0) { solution = temp[3].Trim(); HelpCustomization.solutions.Add(new Solution(emotion, connection, solution)); } } } HelpCustomization.Save(); } if (File.Exists(Tutorial.customFilename)) { ; } else { string res = "Oigo.Droid.tutStart.txt"; Stream s = IntrospectionExtensions.GetTypeInfo(typeof(GlobalData)).Assembly.GetManifestResourceStream(res); using (StreamReader sr = new StreamReader(s)) { string line; line = sr.ReadLine(); File.WriteAllText(Tutorial.customFilename, line); } } }
/// <summary> /// When user presses button to go to conclusion list /// Only call from XAML /// </summary> /// <param name="se"></param> /// <param name="ee"></param> void Handle_Goto_Conclusion(object se, EventArgs ee) { if (emotionHolder == null) { return; } topFlex.Children.Clear(); List <CustomConclusion> custom = Customization.GetConclusion(emotionHolder.GetName(), subjectHolder.GetName()); int count = (/*emotionHolder.conclusions.Count +*/ custom.Count); if (count > 9) { int i = 0; Button[] buttons = new Button[count]; count--; counter = 0; foreach (CustomConclusion c in custom) { strsize = c.GetConclusion().Length; ff = Math.Round((proportion / strsize), 1); if (ff > 34) { ff = 34; } Button temp = new Button { Text = c.GetConclusion(), Padding = 5, FontSize = ff }; AbsoluteLayout.SetLayoutBounds(temp, new Rectangle(0.5 * (counter % 3), 0.5 * (counter / 3), 0.33, 0.33)); AbsoluteLayout.SetLayoutFlags(temp, AbsoluteLayoutFlags.All); temp.Clicked += (s, e) => Handle_CustomConclusion(s, e); buttons[i++] = temp; counter++; if (counter >= 7) { counter = 0; } } i = 0; if (page > 0) { Button temp = new Button { Text = "<-", Padding = 10, FontSize = 26 }; AbsoluteLayout.SetLayoutBounds(temp, new Rectangle(0.5, 1, 0.33, 0.33)); AbsoluteLayout.SetLayoutFlags(temp, AbsoluteLayoutFlags.All); temp.Clicked += (s, e) => Handle_Page_Decrease(s, e); topFlex.Children.Add(temp); } else { topFlex.Children.Add(buttons[i++ + (page * 7)]); } topFlex.Children.Add(buttons[i++ + (page * 7)]); if (page < (count / 7)) { Button temp = new Button { Text = "->", Padding = 10, FontSize = 26 }; AbsoluteLayout.SetLayoutBounds(temp, new Rectangle(1, 1, 0.33, 0.33)); AbsoluteLayout.SetLayoutFlags(temp, AbsoluteLayoutFlags.All); temp.Clicked += (s, e) => Handle_Page_Increase(s, e); topFlex.Children.Add(temp); } for (; i < 7; i++) { if (i + (page * 7) >= buttons.Length) { break; } topFlex.Children.Add(buttons[i + (page * 7)]); } } else { counter = 0; foreach (CustomConclusion c in custom) { strsize = c.GetConclusion().Length; ff = Math.Round((proportion / strsize), 1); if (ff > 34) { ff = 34; } Button temp = new Button { Text = c.GetConclusion(), Padding = 5, FontSize = ff }; AbsoluteLayout.SetLayoutBounds(temp, new Rectangle(0.5 * (counter % 3), 0.5 * (counter / 3), 0.33, 0.33)); AbsoluteLayout.SetLayoutFlags(temp, AbsoluteLayoutFlags.All); temp.Clicked += (s, e) => Handle_CustomConclusion(s, e); topFlex.Children.Add(temp); counter++; } } text.FontSize = 28; text.Text = subjectHolder.GetName() + " " + emotionHolder.GetName(); customConclusionHolder = null; canGoBack = true; }
/// <summary> /// When user presses an emotion button /// Only call from XAML /// </summary> /// <param name="se"></param> /// <param name="ee"></param> void Handle_Emotion(object se, EventArgs ee) { topFlex.Children.Clear(); Color col = ((se as Button).Parent as StackLayout).BackgroundColor; //gets color of emotion button border.BackgroundColor = col; //sets border of top frame to 'col' string str = (se as Button).Text; emotionHolder = subjectHolder.GetEmotion(str); if (keepTut) { Tutorial.self.tutSetPageTwo(se, ee, tutFourText, 0.6, 0.05); } List <CustomConclusion> custom = Customization.GetConclusion(emotionHolder.GetName(), subjectHolder.GetName()); int count = (/*emotionHolder.conclusions.Count +*/ custom.Count); if (count > 9) { int i = 0; Button[] buttons = new Button[count]; count--; counter = 0; foreach (CustomConclusion c in custom) { strsize = c.GetConclusion().Length; ff = Math.Round((proportion / strsize), 1); if (ff > 34) { ff = 34; } Button temp = new Button { Text = c.GetConclusion(), Padding = 5, FontSize = ff }; AbsoluteLayout.SetLayoutBounds(temp, new Rectangle(0.5 * (counter % 3), 0.5 * (counter / 3), 0.33, 0.33)); AbsoluteLayout.SetLayoutFlags(temp, AbsoluteLayoutFlags.All); temp.Clicked += (s, e) => Handle_CustomConclusion(s, e); buttons[i++] = temp; counter++; if (counter >= 7) { counter = 0; } } i = 0; if (page > 0) { Button temp = new Button { Text = "<-", Padding = 10, FontSize = 26 }; AbsoluteLayout.SetLayoutBounds(temp, new Rectangle(0.5, 1, 0.33, 0.33)); AbsoluteLayout.SetLayoutFlags(temp, AbsoluteLayoutFlags.All); temp.Clicked += (s, e) => Handle_Page_Decrease(s, e); topFlex.Children.Add(temp); } else { topFlex.Children.Add(buttons[i++ + (page * 7)]); } topFlex.Children.Add(buttons[i++ + (page * 7)]); if (page < (count / 7)) { Button temp = new Button { Text = "->", Padding = 10, FontSize = 26 }; AbsoluteLayout.SetLayoutBounds(temp, new Rectangle(1, 1, 0.33, 0.33)); AbsoluteLayout.SetLayoutFlags(temp, AbsoluteLayoutFlags.All); temp.Clicked += (s, e) => Handle_Page_Increase(s, e); topFlex.Children.Add(temp); } for (; i < 7; i++) { if (i + (page * 7) >= buttons.Length) { break; } topFlex.Children.Add(buttons[i + (page * 7)]); } } else { counter = 0; foreach (CustomConclusion c in custom) { strsize = c.GetConclusion().Length; ff = Math.Round((proportion / strsize), 1); if (ff > 34) { ff = 34; } Button temp = new Button { Text = c.GetConclusion(), Padding = 5, FontSize = ff }; AbsoluteLayout.SetLayoutBounds(temp, new Rectangle(0.5 * (counter % 3), 0.5 * (counter / 3), 0.33, 0.33)); AbsoluteLayout.SetLayoutFlags(temp, AbsoluteLayoutFlags.All); temp.Clicked += (s, e) => Handle_CustomConclusion(s, e); topFlex.Children.Add(temp); counter++; } } text.Text = subjectHolder.GetName() + " " + emotionHolder.GetName(); canGoBack = true; }