Esempio n. 1
0
        public Home()
        {
            var label = new Label
            {
                
 Text = "Location App", 
 TextColor = Color.White, 
 HorizontalOptions = LayoutOptions.Center, 
 VerticalOptions = LayoutOptions.Center, 
 FontAttributes = FontAttributes.Bold, 
 FontSize = 20


                                                                                                                                                                                                               



            };
            



            Label jokeText = new Label {
                Text              = "",
                TextColor         = Color.White,
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.StartAndExpand,
                FontSize          = 18,
                FontAttributes    = FontAttributes.Bold
            };

            var button = new Button
            {
                
 Text = "Find my location", 
 HorizontalOptions = LayoutOptions.Center, 
 WidthRequest = 180, 
 BackgroundColor = Color.Purple, 
 HeightRequest = 50, 
 FontSize = 15, 
 BorderRadius = 13,
                

 TextColor = Color.White

            }; 


            button.Clicked += async(sender, e) => {
                HttpClient client   = new HttpClient();
                Uri        uri      = new Uri("https://ipinfo.io/json");
                string     obstring = await client.GetStringAsync(uri);

                Joke joke = JsonConvert.DeserializeObject <Joke> (obstring);

                jokeText.Text = "You are located in " + " " + joke.city + " " + joke.region + " " + joke.country;
            };



            var stackLayout = new StackLayout
            {
                
 BackgroundColor = Color.FromRgb(255, 179, 179), 
 VerticalOptions = LayoutOptions.CenterAndExpand, 

 Children = { 
 label, button, jokeText
 } 


            }; 

 Content = new ScrollView
            {
                
 Content = stackLayout, 
 BackgroundColor = Color.FromRgb(255, 179, 179), 
 Padding = new Thickness(10, 60) 
 
 


            }; 

        }
Esempio n. 2
0
        public Home()
        {
            Label title = new Label {
                Text = "Part 2",
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.StartAndExpand,
                FontSize          = Device.GetNamedSize(NamedSize.Large, typeof(Label))
            };

            Label subtitle = new Label {
                Text = "Click below to get a hilarious joke",
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.StartAndExpand,
                FontSize          = Device.GetNamedSize(NamedSize.Medium, typeof(Label))
            };
            //Label entryText = new Label {
            //	Text = "Enter your name to get a custom Joke",
            //	HorizontalOptions = LayoutOptions.Center,
            //	VerticalOptions = LayoutOptions.StartAndExpand,
            //	FontSize = Device.GetNamedSize (NamedSize.Medium, typeof (Label))
            //};

            //Entry firstNameEntry = new Entry {
            //	Text = "First Name",
            //	HorizontalOptions = LayoutOptions.CenterAndExpand,
            //	VerticalOptions = LayoutOptions.StartAndExpand,

            //};

            //Entry lastNameEntry = new Entry {
            //	Text = "Last Name",
            //	HorizontalOptions = LayoutOptions.CenterAndExpand,
            //	VerticalOptions = LayoutOptions.StartAndExpand,
            //};
            Label jokeText = new Label {
                Text = "",
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.StartAndExpand,
                FontSize          = Device.GetNamedSize(NamedSize.Medium, typeof(Label))
            };

            Button jokeButton = new Button {
                Text = "Get Joke",
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.StartAndExpand,
                FontSize          = Device.GetNamedSize(NamedSize.Medium, typeof(Button))
            };

            jokeButton.Clicked += async(sender, e) => {
                HttpClient client   = new HttpClient();
                Uri        uri      = new Uri("http://api.icndb.com/jokes/random?limitTo=[nerdy]");
                string     obstring = await client.GetStringAsync(uri);

                Joke joke = JsonConvert.DeserializeObject <Joke> (obstring);
                jokeText.Text = joke.value.joke;
                DependencyService.Get <ITextToSpeech> ().Speak(joke.value.joke);
            };

            //Button customJokeButton = new Button {
            //	Text = "Get Custom Joke",
            //	HorizontalOptions = LayoutOptions.Center,
            //	VerticalOptions = LayoutOptions.StartAndExpand,
            //	FontSize = Device.GetNamedSize (NamedSize.Medium, typeof (Button))
            //};
            //customJokeButton.Clicked+= async (sender, e) => {
            //	HttpClient client = new HttpClient();
            //	Uri uri = new Uri("http://api.icndb.com/jokes/random?limitTo=[nerdy]&firstName="
            //		+ firstNameEntry.Text+"&lastName="+ lastNameEntry.Text);
            //	string obstring = await client.GetStringAsync (uri);
            //	Joke joke = JsonConvert.DeserializeObject<Joke> (obstring);
            //	jokeText.Text = joke.value.joke;
            //	DependencyService.Get<ITextToSpeech> ().Speak (joke.value.joke);
            //};



            StackLayout stack = new StackLayout {
                //Children = {title, subtitle, entryText, firstNameEntry,
                //    lastNameEntry, jokeButton, customJokeButton, jokeText},
                Children = { title, subtitle, jokeButton, jokeText },
                Padding  = 20
            };

            this.Padding = new Thickness(0, Device.OnPlatform(20, 0, 0), 0, 0);
            this.Content = stack;
        }