private void update() { score.Text = "Memory Score: " + Math.Round(grade, 2); left++; num.Text = left.ToString() + " / " + copy.getCards().Count().ToString(); correctLbl.Text = ""; card.BackgroundColor = Color.DarkTurquoise; entry.Text = ""; nextBtn.IsVisible = false; fixBtn.IsVisible = false; wrongBtn.IsVisible = false; enterBtn.IsVisible = true; if (set.getCards().Count > 0) { current = set.getCards().First(); string output = ""; foreach (String point in current.getPoints()) { output += point + "\n"; } card.Text = output; if (audioOn == true) { CrossTextToSpeech.Dispose(); var text = card.Text; CrossTextToSpeech.Current.Speak(text); } } }
private void clickLogic(Button sender) { CrossTextToSpeech.Dispose(); if (next.IsVisible == false) { if ((audioOn == true) && (sender.BackgroundColor != Color.Yellow)) { var text = sender.Text; CrossTextToSpeech.Current.Speak(text); buttonA.BackgroundColor = Color.LightGray; buttonB.BackgroundColor = Color.LightGray; buttonC.BackgroundColor = Color.LightGray; buttonD.BackgroundColor = Color.LightGray; sender.BackgroundColor = Color.Yellow; } else { check(sender); } } else if (sender.BackgroundColor == Color.Green) { if (audioOn == true) { var text = sender.Text; CrossTextToSpeech.Current.Speak(text); } } }
private void next_Click(Button sender, EventArgs e) {//Text = "Choose" var text = sender.Text; if (cardList.Count > 0) { if (audioOn == true) { text = sender.Text; CrossTextToSpeech.Dispose(); CrossTextToSpeech.Current.Speak(text); } set = new CardSet("Deck", cardList); Navigation.PushAsync(new Games(studentList, set, audioOn)); } else { errorLabel.IsVisible = true; if (audioOn == true) { text = errorLabel.Text; CrossTextToSpeech.Dispose(); CrossTextToSpeech.Current.Speak(text); } } }
public override void OnBackPressed() { //base.OnStop(); base.OnDestroy(); CrossTextToSpeech.Dispose(); base.OnBackPressed(); }
private void init() { decks = new List <CardSet>(); decks.Add(new CardSet()); CardSet set2 = createSet2(); decks.Add(set2); cardList = new List <FlashCard>(); buttonList = new List <Button>(); errorLabel = this.FindByName <Label>("error"); errorLabel.IsVisible = false; //dynamically create buttons depending on number of study sets StackLayout entireLayout = this.FindByName <StackLayout>("entire"); //put scroll view around entireLayout StackLayout copyLayout = this.FindByName <StackLayout>("select"); Label copyLabel = this.FindByName <Label>("selectText"); foreach (CardSet cardSet in decks) {//create buttons dynamically StackLayout layout = new StackLayout(); layout.Orientation = copyLayout.Orientation; Button button = new Button(); button.WidthRequest = 40; button.HeightRequest = 40; Label label = new Label(); label.Text = cardSet.getSet(); button.Clicked += delegate(object sender, EventArgs e) { add_Click(sender, e); if (audioOn == true) { var text = label.Text; if (button.Text == ".") { text = text + " select"; } else { text = text + " deselect"; } CrossTextToSpeech.Dispose(); CrossTextToSpeech.Current.Speak(text); } }; label.FontSize = copyLabel.FontSize; label.FontAttributes = copyLabel.FontAttributes; label.VerticalOptions = copyLabel.VerticalOptions; layout.Children.Add(button); layout.Children.Add(label); entireLayout.Children.Add(layout); buttonList.Add(button); } }
private void try_Click(object sender, EventArgs e) { CrossTextToSpeech.Dispose(); //print answer correctLbl.Text = current.getTopic(); bool pass = false; if ((entry.Text == null) || (entry.Text == "")) { //visibly check card.BackgroundColor = Color.Yellow; wrongBtn.IsVisible = true; fixBtn.IsVisible = true; var text = correctLbl.Text; CrossTextToSpeech.Current.Speak(text); } else { //check answer if (current.getTopic().ToUpper() == entry.Text.ToUpper()) { //correct card.BackgroundColor = Color.Green; grade += UP; score.Text = "Memory Score: " + Math.Round(grade, 2) + " CORRECT!"; if (audioOn == true) { CrossTextToSpeech.Current.Speak("correct"); } nextBtn.IsVisible = true; } else { //incorrect card.BackgroundColor = Color.Red; grade -= DOWN; score.Text = "Memory Score: " + Math.Round(grade, 2) + " INCORRECT!"; if (audioOn == true) { CrossTextToSpeech.Current.Speak("incorrect"); } nextBtn.IsVisible = true; fixBtn.IsVisible = true; var text = correctLbl.Text; CrossTextToSpeech.Current.Speak(text); } } enterBtn.IsVisible = false; }
private void check(Button sender) { CrossTextToSpeech.Dispose(); buttonA.BackgroundColor = Color.LightGray; buttonB.BackgroundColor = Color.LightGray; buttonC.BackgroundColor = Color.LightGray; buttonD.BackgroundColor = Color.LightGray; if (sender.Text == questions.First().getCorrect()) { sender.BackgroundColor = Color.Green; grade += UP; scoreLbl.Text = "Test Score: " + Math.Round(grade, 2) + " CORRECT!"; if (audioOn == true) { CrossTextToSpeech.Current.Speak("correct"); } } else { sender.BackgroundColor = Color.Red; grade -= DOWN; scoreLbl.Text = "Test Score: " + Math.Round(grade, 2) + " INCORRECT!"; if (audioOn == true) { CrossTextToSpeech.Current.Speak("incorrect"); } //error catch if (questions.Count == 0) { return; } //find correct answer if (buttonA.Text == questions.First().getCorrect()) { buttonA.BackgroundColor = Color.Green; } else if (buttonB.Text == questions.First().getCorrect()) { buttonB.BackgroundColor = Color.Green; } else if (buttonC.Text == questions.First().getCorrect()) { buttonC.BackgroundColor = Color.Green; } else if (buttonD.Text == questions.First().getCorrect()) { buttonD.BackgroundColor = Color.Green; } } questions.Remove(questions.First()); buttonNext.IsVisible = true; }
public MainPage(List <Student> users, bool audio) { InitializeComponent(); CrossTextToSpeech.Dispose(); studentList = users; audioOn = audio; ImageButton buttonAudio = this.FindByName <ImageButton>("sound"); if (audioOn == true) { buttonAudio.Source = "audioIsOn.png"; } }
private void all_Click(Button sender, EventArgs e) { errorLabel.IsVisible = false; if (sender.Text == ".") { if (audioOn == true) { var text = "Select None"; CrossTextToSpeech.Dispose(); CrossTextToSpeech.Current.Speak(text); } int i = 0; sender.Text = ""; foreach (Button button in buttonList) { //add_Click(button, e); button.Text = ""; foreach (FlashCard card in decks[i].getCards()) { if (cardList.Contains(card)) { cardList.Remove(card); } } i++; } } else { if (audioOn == true) { var text = "Select All"; CrossTextToSpeech.Dispose(); CrossTextToSpeech.Current.Speak(text); } sender.Text = "."; int i = 0; foreach (Button button in buttonList) { button.Text = "."; foreach (FlashCard card in decks[i].getCards()) { if (!cardList.Contains(card)) { cardList.Add(card); } } i++; } } }
private void audio_Click(ImageButton sender, EventArgs e) { CrossTextToSpeech.Dispose(); if (audioOn == false) { CrossTextToSpeech.Current.Speak("Audio On"); sender.Source = "audioIsOn.png"; audioOn = true; } else { CrossTextToSpeech.Current.Speak("Audio Off"); sender.Source = "audio.png"; audioOn = false; } }
//objects private void cardFace_Click(Button sender, EventArgs e) { CrossTextToSpeech.Dispose(); //take text and present audio if (audioOn == true) { if (card.BackgroundColor != Color.DarkTurquoise) { var text = correctLbl.Text; CrossTextToSpeech.Current.Speak(text); } else { var text = sender.Text; CrossTextToSpeech.Current.Speak(text); } } }
private void click(Button sender) { CrossTextToSpeech.Dispose(); currentBtn = sender; bool view = false; foreach (Button btn in buttonList) //reset red buttons { if (btn.BackgroundColor == Color.Red) { btn.BackgroundColor = Color.LightGray; } else if (btn.BackgroundColor == Color.Green) { //hide green buttons btn.IsVisible = false; } if (btn.IsVisible == true) { view = true; } } //check for visibility if (view == false) { //check if final score is ready final score reload(); //exit if invisible button is clicked return; } else if (sender.IsVisible == false) { return; } //change button color if (sender.BackgroundColor == Color.Yellow) { sender.BackgroundColor = Color.LightGray; } else { sender.BackgroundColor = Color.Yellow; compare(); } }
private void start() { copy.setSet("Memory"); UP = MAX / set.getCards().Count(); DOWN = UP / 5; grade = 0; score = this.FindByName <Label>("title"); num = this.FindByName <Label>("page"); card = this.FindByName <Button>("cardFace"); entry = this.FindByName <Entry>("answer"); enterBtn = this.FindByName <Button>("try"); nextBtn = this.FindByName <Button>("next"); fixBtn = this.FindByName <Button>("fix"); wrongBtn = this.FindByName <Button>("wrong"); correctLbl = this.FindByName <Label>("correct"); recordBtn = this.FindByName <Button>("record"); card.BackgroundColor = Color.DarkTurquoise; //entry.BackgroundColor = Color.White; fixBtn.IsVisible = false; //hide wrongBtn.IsVisible = false; //hide nextBtn.IsVisible = false; //hide left = 1; num.Text = left.ToString() + " / " + copy.getCards().Count().ToString(); current = set.getCards().First(); string output = ""; int i = 0; foreach (String point in current.getPoints()) { i++; output += i.ToString() + ") " + point + "\n"; } card.Text = output; if (audioOn == true) { CrossTextToSpeech.Dispose(); var text = card.Text; CrossTextToSpeech.Current.Speak(text); } }
private void fix_Click(object sender, EventArgs e) { CrossTextToSpeech.Dispose(); if (wrongBtn.IsVisible == true) { if (audioOn == true) { CrossTextToSpeech.Current.Speak("correct"); } if (set.getCards().Count > 0) { set.getCards().Remove(set.getCards().First()); } grade += UP; } else { if (audioOn == true) { CrossTextToSpeech.Current.Speak("fixed"); } if (set.getCards().Count > 0) { set.getCards().Remove(set.getCards().First()); } grade += UP + DOWN; } if (set.getCards().Count == 0) { grade = Math.Round(grade, 2); Navigation.PushAsync(new FinalScore(studentList, grade, copy, audioOn)); } else { update(); } }
private void init() { CrossTextToSpeech.Dispose(); //iterate question count count++; //set colors buttonNext.IsVisible = false; scoreLbl.Text = "Test Score: " + Math.Round(grade, 2); buttonA.BackgroundColor = Color.Orange; buttonB.BackgroundColor = Color.CornflowerBlue; buttonC.BackgroundColor = Color.Salmon; buttonD.BackgroundColor = Color.MediumPurple; MultipleChoice current = questions.First(); List <String> options = new List <String>(); options.Add(current.getA()); options.Add(current.getB()); options.Add(current.getC()); options.Add(current.getCorrect()); Shuffle <String> opt = new Shuffle <String>(options); questionLbl.Text = count + ") " + current.getQuestion(); if (audioOn == true) { var text = questionLbl.Text; CrossTextToSpeech.Current.Speak(text); } buttonA.Text = opt.getList()[0]; buttonB.Text = opt.getList()[1]; buttonC.Text = opt.getList()[2]; buttonD.Text = opt.getList()[3]; while (options.Count > 0) { options.Remove(options.First()); } }
private void wrong_Click(object sender, EventArgs e) { CrossTextToSpeech.Dispose(); if (audioOn == true) { CrossTextToSpeech.Current.Speak("Incorrect"); } //remove card if (set.getCards().Count > 0) { set.getCards().Remove(set.getCards().First()); } grade -= DOWN; //if set is done if (set.getCards().Count == 0) { grade = Math.Round(grade, 2); Navigation.PushAsync(new FinalScore(studentList, grade, copy, audioOn)); } else { update(); } }
private void start() { CrossTextToSpeech.Dispose(); int num = 20; //number of questions if (set.getCards().Count < num) { num = set.getCards().Count; } UP = MAX / num; DOWN = UP / 5; set.setSet("Test"); questionLbl = this.FindByName <Label>("question"); scoreLbl = this.FindByName <Label>("title"); buttonA = this.FindByName <Button>("a"); buttonB = this.FindByName <Button>("b"); buttonC = this.FindByName <Button>("c"); buttonD = this.FindByName <Button>("d"); buttonNext = this.FindByName <Button>("next"); grade = 0; count = 0; questions = new List <MultipleChoice>(); Random random = new Random(); int rnd; List <String> options = new List <String>(); foreach (FlashCard card in set.getCards()) { String ques = card.getTopic(); String point1, point2, point3, correct; rnd = random.Next(0, 4); //probability if ((card.getPoints().Count >= 3) && (rnd == 1)) //at least 3 points { Shuffle <String> allTrue = new Shuffle <String>(card.getPoints()); point1 = allTrue.getList()[0]; point2 = allTrue.getList()[1]; point3 = allTrue.getList()[2]; correct = "All are true"; questions.Add(new MultipleChoice(ques, point1, point2, point3, correct, card)); } else { correct = card.getPoints().First(); int rnd1 = random.Next(0, 10); if (rnd1 == 1)//chance for 'all are true' incorrect option { options.Add("All are true"); } while (options.Count < 3) { rnd = random.Next(set.getCards().Count - 1); if (set.getCards()[rnd] != card) { //if not looking at same card, choose one point as wrong answer if (!options.Contains(set.getCards()[rnd].getPoints().First())) { options.Add(set.getCards()[rnd].getPoints().First()); } } } //incorrect options questions.Add(new MultipleChoice(ques, options[0], options[1], options[2], correct, card)); while (options.Count > 0) { options.Remove(options.First()); } } } if (questions.Count > num) { Shuffle <MultipleChoice> ques = new Shuffle <MultipleChoice>(questions); questions = ques.getList(); while (questions.Count > num) { //only num number of questions questions.Remove(questions.First()); } } }
public static Page GetMainPage() { var speakButton = new Button { Text = "Speak" }; var languageButton = new Button { Text = "Default Language" }; var sliderPitch = new Slider(0, 2.0, 1.0); var sliderRate = new Slider(0, 2.0, Device.OnPlatform(.25, 1.0, 1.0)); var sliderVolume = new Slider(0, 1.0, 1.0); var useDefaults = new Switch { IsToggled = false }; speakButton.Clicked += (sender, args) => { CrossSms.Current.SendSms("Hello there!", "+16024926689"); var text = "The quick brown fox jumped over the lazy dog."; if (useDefaults.IsToggled) { CrossTextToSpeech.Current.Speak(text); return; } CrossTextToSpeech.Current.Speak(text, pitch: (float)sliderPitch.Value, speakRate: (float)sliderRate.Value, volume: (float)sliderVolume.Value, crossLocale: locale); }; var vibrateButton = new Button { Text = "Vibrate" }; var sliderVibrate = new Slider(0, 10000.0, 500.0); vibrateButton.Clicked += (sender, args) => { //var v = DependencyService.Get<IVibrate>(); //v.Vibration((int)sliderVibrate.Value); Refractored.Xam.Vibrate.CrossVibrate.Current.Vibration((int)sliderVibrate.Value); }; var connectivityButton = new Button { Text = "Connectivity Test" }; var connected = new Label { Text = "Is Connected: " }; var connectionTypes = new Label { Text = "Connection Types: " }; var bandwidths = new Label { Text = "Bandwidths" }; var host = new Entry { Text = "127.0.0.1" }; var host2 = new Entry { Text = "montemagno.com" }; var port = new Entry { Text = "80", Keyboard = Keyboard.Numeric }; var canReach1 = new Label { Text = "Can reach1: " }; var canReach2 = new Label { Text = "Can reach2: " }; connectivityButton.Clicked += async(sender, args) => { connected.Text = CrossConnectivity.Current.IsConnected ? "Connected" : "No Connection"; bandwidths.Text = "Bandwidths: "; foreach (var band in CrossConnectivity.Current.Bandwidths) { bandwidths.Text += band.ToString() + ", "; } connectionTypes.Text = "ConnectionTypes: "; foreach (var band in CrossConnectivity.Current.ConnectionTypes) { connectionTypes.Text += band.ToString() + ", "; } try { canReach1.Text = await CrossConnectivity.Current.IsReachable(host.Text) ? "Reachable" : "Not reachable"; } catch (Exception ex) { } try { canReach2.Text = await CrossConnectivity.Current.IsRemoteReachable(host2.Text, int.Parse(port.Text)) ? "Reachable" : "Not reachable"; } catch (Exception ex) { } }; languageButton.Clicked += async(sender, args) => { var locales = CrossTextToSpeech.Current.GetInstalledLanguages(); var items = locales.Select(a => a.ToString()).ToArray(); if (Device.OS == TargetPlatform.Android) { DependencyService.Get <IDialogs>().DisplayActionSheet("Language", "OK", items, which => { languageButton.Text = items[which]; locale = locales.ElementAt(which); }); } else { var selected = await page.DisplayActionSheet("Language", "OK", null, items); if (string.IsNullOrWhiteSpace(selected) || selected == "OK") { return; } languageButton.Text = selected; locale = new CrossLocale { Language = selected }; //fine for iOS/WP } }; var disposeButton = new Button { Text = "Dispose Me" }; disposeButton.Clicked += (sender, args) => { CrossConnectivity.Dispose(); CrossTextToSpeech.Dispose(); }; page = new ContentPage { Content = new ScrollView { Content = new StackLayout { Padding = 40, Spacing = 10, Children = { new Label { Text = "Hello, Forms!" }, new Label { Text = "Pitch" }, sliderPitch, new Label { Text = "Speak Rate" }, sliderRate, new Label { Text = "Volume" }, sliderVolume, new Label { Text = "Use Defaults" }, useDefaults, languageButton, speakButton, new Label { Text = "Vibrate Length" }, sliderVibrate, vibrateButton, new Label { Text = "Generated AppId: " + CrossDeviceInfo.Current.GenerateAppId() }, new Label { Text = "Generated AppId: " + CrossDeviceInfo.Current.GenerateAppId(true) }, new Label { Text = "Generated AppId: " + CrossDeviceInfo.Current.GenerateAppId(true, "hello") }, new Label { Text = "Generated AppId: " + CrossDeviceInfo.Current.GenerateAppId(true, "hello", "world") }, new Label { Text = "Id: " + CrossDeviceInfo.Current.Id }, new Label { Text = "Model: " + CrossDeviceInfo.Current.Model }, new Label { Text = "Platform: " + CrossDeviceInfo.Current.Platform }, new Label { Text = "Version: " + CrossDeviceInfo.Current.Version }, connectivityButton, connected, bandwidths, connectionTypes, host, host2, port, canReach1, canReach2, disposeButton, new StackLayout { HeightRequest = 300 }, new CircleImage { BorderColor = Color.Pink, BorderThickness = 3, HeightRequest = 150, WidthRequest = 150, Aspect = Aspect.AspectFill, HorizontalOptions = LayoutOptions.Center, Source = UriImageSource.FromUri(new Uri("http://upload.wikimedia.org/wikipedia/commons/5/55/Tamarin_portrait.JPG")) }, new CircleImage { BorderColor = Color.Purple, BorderThickness = 6, HeightRequest = 150, WidthRequest = 150, Aspect = Aspect.AspectFill, HorizontalOptions = LayoutOptions.Center, Source = UriImageSource.FromUri(new Uri("http://upload.wikimedia.org/wikipedia/commons/e/ed/Saguinus_tripartitus_-_Golden-mantled_Tamarin.jpg")) }, new CircleImage { BorderColor = Color.Yellow, BorderThickness = 9, HeightRequest = 150, WidthRequest = 150, Aspect = Aspect.AspectFill, HorizontalOptions = LayoutOptions.Center, Source = UriImageSource.FromUri(new Uri("http://upload.wikimedia.org/wikipedia/commons/5/53/Golden_Lion_Tamarin_Leontopithecus_rosalia.jpg")) } } } } }; CrossConnectivity.Current.ConnectivityChanged += (sender, args) => { page.DisplayAlert("Connectivity Changed", "IsConnected: " + args.IsConnected.ToString(), "OK"); }; return(page); }
public static Page GetMainPage() { var speakButton = new Button { Text = "Speak" }; var languageButton = new Button { Text = "Default Language" }; var sliderPitch = new Slider(0, 2.0, 1.0); var sliderRate = new Slider(0, 2.0, Device.OnPlatform(.25, 1.0, 1.0)); var sliderVolume = new Slider(0, 1.0, 1.0); var useDefaults = new Switch { IsToggled = false }; speakButton.Clicked += (sender, args) => { var text = "The quick brown fox jumped over the lazy dog."; if (useDefaults.IsToggled) { CrossTextToSpeech.Current.Speak(text); return; } CrossTextToSpeech.Current.Speak(text, pitch: (float)sliderPitch.Value, speakRate: (float)sliderRate.Value, volume: (float)sliderVolume.Value, crossLocale: locale); }; var vibrateButton = new Button { Text = "Vibrate" }; var sliderVibrate = new Slider(0, 10000.0, 500.0); vibrateButton.Clicked += (sender, args) => { //var v = DependencyService.Get<IVibrate>(); //v.Vibration((int)sliderVibrate.Value); Refractored.Xam.Vibrate.CrossVibrate.Current.Vibration((int)sliderVibrate.Value); }; var connectivityButton = new Button { Text = "Connectivity Test" }; var connected = new Label { Text = "Is Connected: " }; var connectionTypes = new Label { Text = "Connection Types: " }; var bandwidths = new Label { Text = "Bandwidths" }; var host = new Entry { Text = "127.0.0.1" }; var host2 = new Entry { Text = "montemagno.com" }; var port = new Entry { Text = "80", Keyboard = Keyboard.Numeric }; var canReach1 = new Label { Text = "Can reach1: " }; var canReach2 = new Label { Text = "Can reach2: " }; connectivityButton.Clicked += async(sender, args) => { connected.Text = CrossConnectivity.Current.IsConnected ? "Connected" : "No Connection"; bandwidths.Text = "Bandwidths: "; foreach (var band in CrossConnectivity.Current.Bandwidths) { bandwidths.Text += band.ToString() + ", "; } connectionTypes.Text = "ConnectionTypes: "; foreach (var band in CrossConnectivity.Current.ConnectionTypes) { connectionTypes.Text += band.ToString() + ", "; } try { canReach1.Text = await CrossConnectivity.Current.IsReachable(host.Text) ? "Reachable" : "Not reachable"; } catch (Exception ex) { } try { canReach2.Text = await CrossConnectivity.Current.IsRemoteReachable(host2.Text, int.Parse(port.Text)) ? "Reachable" : "Not reachable"; } catch (Exception ex) { } }; languageButton.Clicked += async(sender, args) => { var locales = CrossTextToSpeech.Current.GetInstalledLanguages(); var items = locales.Select(a => a.ToString()).ToArray(); if (Device.OS == TargetPlatform.Android) { DependencyService.Get <IDialogs>().DisplayActionSheet("Language", "OK", items, which => { languageButton.Text = items[which]; locale = locales.ElementAt(which); }); } else { var selected = await page.DisplayActionSheet("Language", "OK", null, items); if (string.IsNullOrWhiteSpace(selected) || selected == "OK") { return; } languageButton.Text = selected; locale = new CrossLocale { Language = selected }; //fine for iOS/WP } }; var disposeButton = new Button { Text = "Dispose Me" }; disposeButton.Clicked += (sender, args) => { CrossConnectivity.Dispose(); CrossTextToSpeech.Dispose(); }; page = new ContentPage { Content = new ScrollView { Content = new StackLayout { Padding = 40, Spacing = 10, Children = { new Label { Text = "Hello, Forms!" }, new Label { Text = "Pitch" }, sliderPitch, new Label { Text = "Speak Rate" }, sliderRate, new Label { Text = "Volume" }, sliderVolume, new Label { Text = "Use Defaults" }, useDefaults, languageButton, speakButton, new Label { Text = "Vibrate Length" }, sliderVibrate, vibrateButton, new Label { Text = "Generated AppId: " + CrossDeviceInfo.Current.GenerateAppId() }, new Label { Text = "Generated AppId: " + CrossDeviceInfo.Current.GenerateAppId(true) }, new Label { Text = "Generated AppId: " + CrossDeviceInfo.Current.GenerateAppId(true, "hello") }, new Label { Text = "Generated AppId: " + CrossDeviceInfo.Current.GenerateAppId(true, "hello", "world") }, new Label { Text = "Id: " + CrossDeviceInfo.Current.Id }, new Label { Text = "Model: " + CrossDeviceInfo.Current.Model }, new Label { Text = "Platform: " + CrossDeviceInfo.Current.Platform }, new Label { Text = "Version: " + CrossDeviceInfo.Current.Version }, connectivityButton, connected, bandwidths, connectionTypes, host, host2, port, canReach1, canReach2, disposeButton } } } }; CrossConnectivity.Current.ConnectivityChanged += (sender, args) => { page.DisplayAlert("Connectivity Changed", "IsConnected: " + args.IsConnected.ToString(), "OK"); }; return(page); }
public static Page GetMainPage() { return(new NavigationPage(new Home())); var speakButton = new Button { Text = "Speak" }; var languageButton = new Button { Text = "Default Language" }; var sliderPitch = new Slider(0, 2.0, 1.0); var sliderRate = new Slider(0, 2.0, Device.OnPlatform(.25, 1.0, 1.0)); var sliderVolume = new Slider(0, 1.0, 1.0); var useDefaults = new Switch { IsToggled = false }; speakButton.Clicked += (sender, args) => { //CrossSms.Current.SendSms("Hello there!", "+16024926689"); var text = "The quick brown fox jumped over the lazy dog."; if (useDefaults.IsToggled) { CrossTextToSpeech.Current.Speak(text); return; } CrossTextToSpeech.Current.Speak(text, pitch: (float)sliderPitch.Value, speakRate: (float)sliderRate.Value, volume: (float)sliderVolume.Value, crossLocale: locale); }; var vibrateButton = new Button { Text = "Vibrate" }; var sliderVibrate = new Slider(0, 10000.0, 500.0); var connectivityButton = new Button { Text = "Connectivity Test" }; var connected = new Label { Text = "Is Connected: " }; var connectionTypes = new Label { Text = "Connection Types: " }; var bandwidths = new Label { Text = "Bandwidths" }; var host = new Entry { Text = "127.0.0.1" }; var host2 = new Entry { Text = "montemagno.com" }; var port = new Entry { Text = "80", Keyboard = Keyboard.Numeric }; var canReach1 = new Label { Text = "Can reach1: " }; var canReach2 = new Label { Text = "Can reach2: " }; connectivityButton.Clicked += async(sender, args) => { connected.Text = CrossConnectivity.Current.IsConnected ? "Connected" : "No Connection"; bandwidths.Text = "Bandwidths: "; foreach (var band in CrossConnectivity.Current.Bandwidths) { bandwidths.Text += band.ToString() + ", "; } connectionTypes.Text = "ConnectionTypes: "; foreach (var band in CrossConnectivity.Current.ConnectionTypes) { connectionTypes.Text += band.ToString() + ", "; } try { canReach1.Text = await CrossConnectivity.Current.IsReachable(host.Text) ? "Reachable" : "Not reachable"; } catch (Exception ex) { } try { canReach2.Text = await CrossConnectivity.Current.IsRemoteReachable(host2.Text, int.Parse(port.Text)) ? "Reachable" : "Not reachable"; } catch (Exception ex) { } }; languageButton.Clicked += async(sender, args) => { var locales = CrossTextToSpeech.Current.GetInstalledLanguages(); var items = locales.Select(a => a.ToString()).ToArray(); if (Device.OS == TargetPlatform.Android) { DependencyService.Get <IDialogs>().DisplayActionSheet("Language", "OK", items, which => { languageButton.Text = items[which]; locale = locales.ElementAt(which); }); } else { var selected = await page.DisplayActionSheet("Language", "OK", null, items); if (string.IsNullOrWhiteSpace(selected) || selected == "OK") { return; } languageButton.Text = selected; locale = new CrossLocale { Language = selected }; //fine for iOS/WP } }; var disposeButton = new Button { Text = "Dispose Me" }; disposeButton.Clicked += (sender, args) => { CrossConnectivity.Dispose(); CrossTextToSpeech.Dispose(); CrossBattery.Dispose(); }; var getBatteryButton = new Button { Text = "Get Battery Stats" }; var batteryLevel = new Label { Text = "Level?" }; var batteryStatus = new Label { Text = "Status?" }; var batteryChargeType = new Label { Text = "ChargeType?" }; var batteryIsLow = new Label { Text = "IsLow" }; getBatteryButton.Clicked += (sender, args) => { batteryLevel.Text = "Level: " + CrossBattery.Current.RemainingChargePercent; batteryStatus.Text = "Status: " + CrossBattery.Current.Status.ToString(); batteryChargeType.Text = "ChargeType: " + CrossBattery.Current.PowerSource.ToString(); batteryIsLow.Text = "IsLow: " + ((CrossBattery.Current.RemainingChargePercent <= 15) ? "YES" : "NO"); }; CrossBattery.Current.BatteryChanged += (sender, args) => { batteryLevel.Text = "Changed EVENT! Level: " + args.RemainingChargePercent; batteryStatus.Text = "Status: " + args.Status.ToString(); batteryChargeType.Text = "ChargeType: " + args.PowerSource.ToString(); batteryIsLow.Text = "IsLow: " + ((args.IsLow) ? "YES" : "NO"); }; var navigateLatLong = new Button { Text = "Navigate Lat Long" }; navigateLatLong.Clicked += (sender, args) => { CrossExternalMaps.Current.NavigateTo("Space Needle", 47.6204, -122.3491); }; var navigateAddress = new Button { Text = "Navigate Address" }; navigateAddress.Clicked += (sender, args) => { CrossExternalMaps.Current.NavigateTo("Xamarin", "394 pacific ave.", "San Francisco", "CA", "94111", "USA", "USA"); }; var buttonContacts = new Button { Text = "Contacts" }; buttonContacts.Clicked += (sender, args) => { page.Navigation.PushAsync(new ContactsPage()); }; var buttonGetGPS = new Button { Text = "GetGPS" }; var labelGPS = new Label { Text = "GPS goes here" }; buttonGetGPS.Clicked += async(sender, args) => { var locator = CrossGeolocator.Current; locator.DesiredAccuracy = 50; labelGPS.Text = "Getting gps"; var position = await locator.GetPositionAsync(timeout : 10000); if (position == null) { labelGPS.Text = "null gps :("; return; } labelGPS.Text = string.Format("Time: {0} \nLat: {1} \nLong: {2} \n Altitude: {3} \nAltitude Accuracy: {4} \nAccuracy: {5} \n Heading: {6} \n Speed: {7}", position.Timestamp, position.Latitude, position.Longitude, position.Altitude, position.AltitudeAccuracy, position.Accuracy, position.Heading, position.Speed); }; page = new ContentPage { Content = new ScrollView { Content = new StackLayout { Padding = 40, Spacing = 10, Children = { new Label { Text = "Hello, Forms!" }, new Label { Text = "Pitch" }, sliderPitch, new Label { Text = "Speak Rate" }, sliderRate, new Label { Text = "Volume" }, sliderVolume, new Label { Text = "Use Defaults" }, useDefaults, languageButton, speakButton, new Label { Text = "Vibrate Length" }, sliderVibrate, vibrateButton, new Label { Text = "Generated AppId: " + CrossDeviceInfo.Current.GenerateAppId() }, new Label { Text = "Generated AppId: " + CrossDeviceInfo.Current.GenerateAppId(true) }, new Label { Text = "Generated AppId: " + CrossDeviceInfo.Current.GenerateAppId(true, "hello") }, new Label { Text = "Generated AppId: " + CrossDeviceInfo.Current.GenerateAppId(true, "hello", "world") }, new Label { Text = "Id: " + CrossDeviceInfo.Current.Id }, new Label { Text = "Model: " + CrossDeviceInfo.Current.Model }, new Label { Text = "Platform: " + CrossDeviceInfo.Current.Platform }, new Label { Text = "Version: " + CrossDeviceInfo.Current.Version }, connectivityButton, connected, bandwidths, connectionTypes, host, host2, port, canReach1, canReach2, disposeButton, new CircleImage { BorderColor = Color.Pink, BorderThickness = 3, HeightRequest = 150, WidthRequest = 150, Aspect = Aspect.AspectFill, HorizontalOptions = LayoutOptions.Center, Source = UriImageSource.FromUri(new Uri("http://upload.wikimedia.org/wikipedia/commons/5/55/Tamarin_portrait.JPG")) }, new CircleImage { BorderColor = Color.Purple, BorderThickness = 6, HeightRequest = 150, WidthRequest = 150, Aspect = Aspect.AspectFill, HorizontalOptions = LayoutOptions.Center, Source = UriImageSource.FromUri(new Uri("http://upload.wikimedia.org/wikipedia/commons/e/ed/Saguinus_tripartitus_-_Golden-mantled_Tamarin.jpg")) }, new CircleImage { BorderColor = Color.Yellow, BorderThickness = 9, HeightRequest = 150, WidthRequest = 150, Aspect = Aspect.AspectFill, HorizontalOptions = LayoutOptions.Center, Source = UriImageSource.FromUri(new Uri("http://upload.wikimedia.org/wikipedia/commons/5/53/Golden_Lion_Tamarin_Leontopithecus_rosalia.jpg")) }, getBatteryButton, new Label { Text = "Battery Level" }, batteryLevel, new Label { Text = "Battery Status" }, batteryStatus, new Label { Text = "Battery Charge Type" }, batteryChargeType, new Label { Text = "Battery is low" }, batteryIsLow, navigateAddress, navigateLatLong, buttonContacts, buttonGetGPS, labelGPS } } } }; CrossConnectivity.Current.ConnectivityChanged += (sender, args) => { page.DisplayAlert("Connectivity Changed", "IsConnected: " + args.IsConnected.ToString(), "OK"); }; return(new NavigationPage(page)); }