private async Task ExecuteLoadItemsCommand() { if (IsBusy) return; IsBusy = true; try{ var httpClient = new HttpClient(); var feed = "http://api.espn.com/v1/sports/soccer/fifa.world/teams?apikey=trs58u4j7gw4aat7ck8dsmgc"; var responseString = await httpClient.GetStringAsync(feed); Teams.Clear(); var items = await ParseFeed(responseString); foreach (var item in items.OrderBy(t => t.Name)) { Teams.Add(item); } keepTeams = Teams.ToList(); } catch (Exception) { var page = new ContentPage(); page.DisplayAlert ("Error", "Unable to load teams.", "OK", null); } IsBusy = false; }
public async Task ExecuteLoadStatsCommand() { if (IsBusy) return; IsBusy = true; try { var adminManager = new AdminManager(Settings.AccessToken); Names.Clear(); foreach(var name in await adminManager.PopularNames()) { Names.Add(name); } } catch (Exception ex) { var page = new ContentPage(); page.DisplayAlert("Error", "Unable to load.", "OK"); ; } finally { IsBusy = false; } }
private void ExecuteLoadItemsCommand() { if (IsBusy) return; IsBusy = true; try { KnockoutMatches.Clear(); var result = MatchService.GetKnockoutMatches(); foreach (var item in result) { KnockoutMatches.Add(item); } } catch (Exception) { var page = new ContentPage(); page.DisplayAlert("Error", "Unable to load matches.", "OK", null); } IsBusy = false; }
public async Task ExecuteLoadFlagsCommand() { if (IsBusy) return; IsBusy = true; try { var userManager = new UserManager(Settings.AccessToken); var flags = await userManager.GetFlags(); //Use linq to sorty our monkeys by name and then group them by the new name sort property var sorted = from flag in flags orderby flag.AlertLevel group flag by flag.AlertLevel.ToString() into flagGroup select new Grouping<string, Flag>(flagGroup.Key, flagGroup); //create a new collection of groups FlagsGrouped = new ObservableCollection<Grouping<string, Flag>>(sorted); OnPropertyChanged("FlagsGrouped"); } catch (Exception ex) { var page = new ContentPage(); page.DisplayAlert("Error", "Unable to load flags.", "OK"); ; } finally { IsBusy = false; } }
public async Task ExecuteLoadStatsCommand() { if (IsBusy) return; IsBusy = true; try { var adminManager = new AdminManager(Settings.AccessToken); RegDates.Clear(); foreach(var reg in await adminManager.TotalRegistrations()) { RegDates.Add(new MyRegDate { Title = new DateTime(reg.Year, reg.Month, reg.Day).ToString("D"), Detail = reg.Total.ToString() }); } } catch (Exception ex) { var page = new ContentPage(); page.DisplayAlert("Error", "Unable to load.", "OK"); ; } finally { IsBusy = false; } }
public async Task ExecuteArticleCommand() { if (IsBusy) return; IsBusy = true; LoadArticleCommand.ChangeCanExecute(); try { GetArticleHtmlandUpdate(); Expand = " CLOSE ▲"; OnPropertyChanged("Expand"); } catch (Exception ex) { var page = new ContentPage(); page.DisplayAlert("Error", "Unable to load Article Content.", "OK"); } IsBusy = false; LoadArticleCommand.ChangeCanExecute(); }
private async Task ExecuteLoadItemsCommand() { if (IsBusy) return; IsBusy = true; try{ var responseString = string.Empty; using(var httpClient = new HttpClient()) { var feed = "http://feeds.hanselman.com/ScottHanselman"; responseString = await httpClient.GetStringAsync(feed); } FeedItems.Clear(); var items = await ParseFeed(responseString); foreach (var item in items) { FeedItems.Add(item); } } catch (Exception ex) { var page = new ContentPage(); var result = page.DisplayAlert ("Error", "Unable to load blog.", "OK"); } IsBusy = false; }
public MainPage() { button = new Button { Text = "Click me", }; label = new Label { XAlign = TextAlignment.Center, Text = "Welcome to Xamarin Forms!" }; button.Clicked += async (sender, e) => { var data = "Cryptographic example"; var pass = "******"; var contentPage = new ContentPage(); var salt = Crypto.CreateSalt(16); await contentPage.DisplayAlert("Alert", "Encrypting String " + data + ", with salt " + BitConverter.ToString(salt), "OK"); var bytes = Crypto.EncryptAes(data, pass, salt); await contentPage.DisplayAlert("Alert", "Encrypted, Now Decrypting", "OK"); var str = Crypto.DecryptAes(bytes, pass, salt); await contentPage.DisplayAlert("Alert", "Decryted " + str, "OK"); }; this.Title = "Crypto Forms"; // The root page of your application this.Content = new StackLayout { VerticalOptions = LayoutOptions.Center, Children = { label, button } }; }
public App() { var editField = new Entry { Placeholder = "Enter text for setting", Text = SettingsSample.Helpers.Settings.GeneralSettings }; var buttonSave = new Button { Text = "Save Setting" }; var buttonGet = new Button { Text = "Get Setting" }; // The root page of your application MainPage = new ContentPage { Content = new StackLayout { VerticalOptions = LayoutOptions.Center, Children = { new Label { XAlign = TextAlignment.Center, Text = "Enter value to save to settings:" }, editField, buttonSave, buttonGet } } }; buttonSave.Clicked += (sender, args) => { SettingsSample.Helpers.Settings.GeneralSettings = editField.Text; }; buttonGet.Clicked += (sender, args) => { MainPage.DisplayAlert("Current Value:", SettingsSample.Helpers.Settings.GeneralSettings, "OK"); }; }
public async Task ExecuteLoadStatsCommand() { if (IsBusy) return; IsBusy = true; try { var adminManager = new AdminManager(Settings.AccessToken); var avatarManager = new AvatarManager(Settings.AccessToken); Count = await adminManager.TotalAvatarCount(); var avas = await avatarManager.GetStaticAvatars(); Avatars.Clear(); var items = await adminManager.PopularAvatars(); foreach(var avatar in items.OrderByDescending(a => a.Count)) { var myava = avas.FirstOrDefault(a => a.Id == avatar.AvatarId); if (myava == null) continue; Avatars.Add(new MyAvatar { Count = avatar.Count.ToString(), Location = myava.Location, Url = EndPoints.BaseUrl + myava.Location }); } } catch (Exception ex) { var page = new ContentPage(); page.DisplayAlert("Error", "Unable to load.", "OK"); ; } finally { IsBusy = false; } }
private async Task ExecuteLoadItemsCommand() { if (IsBusy) return; IsBusy = true; try{ /* var items = App.WorkManager.GetWorkItems(); foreach(var item in items) { workItems.Add(item); } */ } catch (Exception ex) { var page = new ContentPage(); var result = page.DisplayAlert ("Error", "Unable to load work items.", "OK"); } IsBusy = false; }
public App() { var loginButton = new Button { Text = "Login", StyleId = "loginButton" }; var mainPage = new ContentPage { Content = new StackLayout { VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center, Children = { new Entry { Placeholder = "Username", StyleId = "username" }, new Entry { Placeholder = "Password", StyleId = "password" }, loginButton } } }; loginButton.Clicked += async (object sender, EventArgs e) => { await mainPage.DisplayAlert ("Login", "Logged In", "OK"); }; // The root page of your application MainPage = mainPage; }
// -------------------------------------------------------------------------- // // CONSTRUCTORS // // -------------------------------------------------------------------------- public App () { // Create the orange image that goes on the main screen of the app var orangeImage = new CustomImage { Aspect = Aspect.Fill }; orangeImage.Source = "orange_square.png"; // Create a ContentPage to use as the view of the app. var page = new ContentPage { Content = new StackLayout { VerticalOptions = LayoutOptions.Center, Children = { orangeImage } } }; // When the image dispatches a tap event (custom event, see CustomImage.cs), // then display an alert. orangeImage.TapEvent += (object sender, PointEventArgs e) => { page.DisplayAlert("Tap!", String.Format("({0}, {1})", e.X, e.Y), "Cancel"); }; // Set the main page of the app. MainPage = page; }
private async Task ExecuteLoadItemsCommand() { if (IsBusy) return; IsBusy = true; try { Result.Clear(); using(var httpClient = new HttpClient()) { for (int i = 1; i <= 15; i++) { var feed = string.Format("http://footballdb.herokuapp.com/api/v1/event/world.2014/round/{0}",i); var responseString = await httpClient.GetStringAsync(feed); Result.AddRange(MatchService.GetMatchDay(responseString)); } foreach(var item in Result) { item.HomeScore = (item.HomeScore == "" || item.HomeScore == null) ? "0" : item.HomeScore; item.AwayScore = (item.AwayScore == "" || item.AwayScore == null) ? "0" : item.AwayScore; } } this.ItemsLoaded(this, new EventArgs()); } catch (Exception) { var page = new ContentPage(); page.DisplayAlert ("Error", "Unable to load matches.", "OK", null); } IsBusy = false; }
private async Task ExecuteLoadItemsCommand() { if (IsBusy) return; IsBusy = true; var error = false; try { var httpClient = new HttpClient(); var feed = "http://blog.appointy.com/feed/"; var responseString = await httpClient.GetStringAsync(feed); FeedItems.Clear(); var items = await ParseFeed(responseString); foreach (var feedItem in items) { FeedItems.Add(feedItem); } } catch { error = true; } if (error) { var page = new ContentPage(); var result = page.DisplayAlert("Oops!", "Unable to load .", "OK"); } IsBusy = false; }
public static Page GetMainPage() { var page = new ContentPage() { BackgroundColor = Color.Gray }; var header = new BoxView { BackgroundColor = Color.Blue, Color = Color.Blue }; var wrapper = new CardsView(); for (int i = 0; i < 1; i++) { var panel = new StackLayout(); panel.Children.Add(new Label { Text = "I am a card: " + i + "!!!", Font = Font.SystemFontOfSize(NamedSize.Large), VerticalOptions = LayoutOptions.Center, TextColor = Color.Black }); panel.Children.Add(new Label { Text = "Row 2", Font = Font.SystemFontOfSize(NamedSize.Large), VerticalOptions = LayoutOptions.Center, TextColor = Color.Black }); panel.Children.Add(new Button {Text = "Click Me", Command = new Command(() => { page.DisplayAlert("Click", "You clicked me!", "Ok"); }) }); var card = new CardContentView { Padding = 15, CornderRadius = 5, Content = panel, BackgroundColor = Color.White, Command = new Command(() => { page.DisplayAlert("Alert", "I am a card: " + i + "!!!", "Ok"); }) }; wrapper.AddCard(card); } // wrapper.Content = stack; var content = new AbsoluteLayout(); content.Children.Add(header, new Rectangle(0, 0, 1, 0.25), AbsoluteLayoutFlags.SizeProportional); content.Children.Add(wrapper, new Rectangle(1, 0.25, 1, 1), AbsoluteLayoutFlags.All); page.Content = content; return new NavigationPage(page); }
private async Task ExecuteLoadItemsCommand() { if (IsBusy) { return; } IsBusy = true; var error = false; try { //var responseString = string.Empty; //using (var httpClient = new HttpClient()) //{ // responseString = await httpClient.GetStringAsync(ServiceUrls.GetShops); //} //var items = JsonConvert.DeserializeObject<IList<Shop>>(responseString); var items = DummyService.GetOrders(); Orders.Clear(); foreach (var item in items) { Orders.Add(item); } } catch { error = true; } if (error) { var page = new ContentPage(); await page.DisplayAlert("Error", "Unable to load orders.", "OK"); } IsBusy = false; }
public async Task ExecuteHideArticleInfoCommand() { if (IsBusy) return; IsBusy = true; HideArticleInfoCommand.ChangeCanExecute(); try { if (App.ArticleInfoVisible == null) return; if(App.ArticleInfoVisible) {Expand = " CLOSE ▲"; ArticleInfoVisible = true; } else { Expand = " EXPAND ▼"; ArticleInfoVisible = false; } OnPropertyChanged("Expand"); OnPropertyChanged("ArticleInfoVisible"); } catch { var page = new ContentPage(); page.DisplayAlert("Error", "Unable to load Article Content.", "OK"); } IsBusy = false; LoadArticleCommand.ChangeCanExecute(); }
public App() { var layout = new RelativeLayout(); var label = new Label { XAlign = TextAlignment.Center, YAlign = TextAlignment.Center, Text = "Hello Floating Action Button!" }; layout.Children.Add( label, xConstraint: Constraint.Constant(0), yConstraint: Constraint.Constant(0), widthConstraint: Constraint.RelativeToParent(parent => parent.Width), heightConstraint: Constraint.RelativeToParent(parent => parent.Height) ); var normalFab = new FAB.Forms.FloatingActionButton(); normalFab.Source = "plus.png"; normalFab.Size = FabSize.Normal; layout.Children.Add( normalFab, xConstraint: Constraint.RelativeToParent((parent) => { return (parent.Width - normalFab.Width) - 16; }), yConstraint: Constraint.RelativeToParent((parent) => { return (parent.Height - normalFab.Height) - 16; }) ); normalFab.SizeChanged += (sender, args) => { layout.ForceLayout(); }; var miniFab = new FAB.Forms.FloatingActionButton(); miniFab.Source = "plus.png"; miniFab.Size = FabSize.Mini; layout.Children.Add( miniFab, xConstraint: Constraint.RelativeToParent((parent) => { return (parent.Width - miniFab.Width) - 16; }), yConstraint: Constraint.RelativeToView(normalFab, (parent, view) => { return (view.Y - miniFab.Height) - 16; }) ); miniFab.SizeChanged += (sender, args) => { layout.ForceLayout(); }; // The root page of your application MainPage = new ContentPage { BackgroundColor = Color.White, Content = layout }; normalFab.Clicked += (sender, e) => { MainPage.DisplayAlert("Floating Action Button", "You clicked the normal FAB!", "Awesome!"); }; miniFab.Clicked += (sender, e) => { MainPage.DisplayAlert("Floating Action Button", "You clicked the mini FAB!", "Awesome!"); }; }
private async Task ExecuteLoadItemsCommand() { if (IsBusy) return; IsBusy = true; var error = false; try { var httpClient = new HttpClient(); var feed = string.Empty; switch (item) { case MenuType.Hanselminutes: feed = "http://feeds.podtrac.com/9dPm65vdpLL1"; break; case MenuType.Ratchet: feed = "http://feeds.feedburner.com/RatchetAndTheGeek?format=xml"; break; case MenuType.DeveloperLife: feed = "http://feeds.feedburner.com/ThisDevelopersLife?format=xml"; break; } var responseString = await httpClient.GetStringAsync(feed); FeedItems.Clear(); var items = await ParseFeed(responseString); foreach (var feedItem in items) { FeedItems.Add(feedItem); } } catch { error = true; } if (error) { var page = new ContentPage(); var result = page.DisplayAlert("Error", "Unable to load podcast feed.", "OK"); } IsBusy = false; }
private async void ExecuteLoadTweetsCommand () { if (IsBusy) return; IsBusy = true; try { Tweets.Clear (); var auth = new ApplicationOnlyAuthorizer () { CredentialStore = new InMemoryCredentialStore { ConsumerKey = "ZTmEODUCChOhLXO4lnUCEbH2I", ConsumerSecret = "Y8z2Wouc5ckFb1a0wjUDT9KAI6DUat5tFNdmIkPLl8T4Nyaa2J", }, }; await auth.AuthorizeAsync (); var twitterContext = new TwitterContext (auth); #if !WINDOWS_PHONE IQueryable<LinqToTwitter.Status> queryResponse = (from tweet in twitterContext.Status where tweet.Type == StatusType.User && tweet.ScreenName == "shanselman" && tweet.Count == 100 && tweet.IncludeRetweets == true && tweet.ExcludeReplies == true select tweet); var queryTweets = queryResponse.ToList (); var tweets = (from tweet in queryTweets select new Tweet { StatusID = tweet.StatusID, ScreenName = tweet.User.ScreenNameResponse, Text = tweet.Text, CurrentUserRetweet = tweet.CurrentUserRetweet, CreatedAt = tweet.CreatedAt }).ToList (); #else var tweets = await (from tweet in twitterContext.Status where tweet.Type == StatusType.User && tweet.ScreenName == "shanselman" && tweet.Count == 100 && tweet.IncludeRetweets == true && tweet.ExcludeReplies == true select new Tweet { StatusID = tweet.StatusID, ScreenName = tweet.User.ScreenNameResponse, Text = tweet.Text, CurrentUserRetweet = tweet.CurrentUserRetweet, CreatedAt = tweet.CreatedAt }).ToListAsync(); #endif foreach (var tweet in tweets) { Tweets.Add (tweet); } } catch (Exception ex) { var page = new ContentPage(); page.DisplayAlert ("Error", "Unable to load twitter.", "OK", null); } IsBusy = false; }
async void doPhotoLibrary(PhotoListData pld) { #if __ANDROID__ MediaPicker picker = new MediaPicker(Forms.Context); #else MediaPicker picker = new MediaPicker(); #endif if (picker.IsPhotoGalleryAvailable == false) { var page = new ContentPage(); var result = page.DisplayAlert("Warning", "Photo is not available", "OK"); return; } else { try { var resultfile = await picker.PickPhoto(); #if __ANDROID__ //showDrawingView(pld); #else //showDrawingView(pld); #endif } catch (Exception e) { } } }
async void doCameraPhoto(PhotoListData pld) { #if __ANDROID__ MediaPicker picker = new MediaPicker(Forms.Context); #else MediaPicker picker = new MediaPicker(); #endif if (picker.IsCameraAvailable == false) { var page = new ContentPage(); var result = page.DisplayAlert("Warning", "Camera is not available", "OK"); return; } else { try { var resultfile = await picker.TakePhoto(null); #if __ANDROID__ showDrawingView(pld); #else showDrawingView(pld); #endif } catch (Exception ex) { } } }
public async Task ExecuteLoadUsersCommand() { if (IsBusy) return; IsBusy = true; try { var adminManager = new AdminManager(Settings.AccessToken); var users = await adminManager.FlagUserList(Flag.Id); //Use linq to users by name and then group them by the new name sort property var sorted = from user in users orderby user.NickName group user by (user.NickName.Length == 0 ? "?" : user.NickName[0].ToString()) into userGroup select new Grouping<string, User>(userGroup.Key, userGroup); //create a new collection of groups UsersGrouped = new ObservableCollection<Grouping<string, User>>(sorted); OnPropertyChanged("UsersGroupeds"); } catch (Exception ex) { var page = new ContentPage(); page.DisplayAlert("Error", "Unable to load users.", "OK"); ; } finally { IsBusy = false; } }
public App() { // The root page of your application var indicator = new ActivityIndicator() { HorizontalOptions = LayoutOptions.CenterAndExpand }; indicator.IsVisible = false; var numeroDePersonasEntry = new Entry { Text = "5" }; Stepper numeroDePersonasStepper = new Stepper { Minimum = 0, Maximum = 30, Increment = 1, Value = 5, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.CenterAndExpand }; var set3Button = new Button{ Text = "3" }; set3Button.Clicked += delegate(object sender, EventArgs e) { numeroDePersonasEntry.Text = "3"; numeroDePersonasStepper.Value = 3; }; var set4Button = new Button{ Text = "4" }; set4Button.Clicked += delegate(object sender, EventArgs e) { numeroDePersonasEntry.Text = "4"; numeroDePersonasStepper.Value = 4; }; var set5Button = new Button{ Text = "5" }; set5Button.Clicked += delegate(object sender, EventArgs e) { numeroDePersonasEntry.Text = "5"; numeroDePersonasStepper.Value = 5; }; var set6Button = new Button{ Text = "6" }; set6Button.Clicked += delegate(object sender, EventArgs e) { numeroDePersonasEntry.Text = "6"; numeroDePersonasStepper.Value = 6; }; var set7Button = new Button{ Text = "7" }; set7Button.Clicked += delegate(object sender, EventArgs e) { numeroDePersonasEntry.Text = "7"; numeroDePersonasStepper.Value = 7; }; var set8Button = new Button{ Text = "8" }; set8Button.Clicked += delegate(object sender, EventArgs e){ numeroDePersonasEntry.Text = "8"; numeroDePersonasStepper.Value = 8; }; numeroDePersonasStepper.ValueChanged += delegate(object sender, ValueChangedEventArgs e) { try { int numeroDePersonas = Int32.Parse( numeroDePersonasEntry.Text ) ; numeroDePersonasEntry.Text = "" + e.NewValue ; } catch(Exception exception) { } }; var totalDeLaComidaEntry = new Entry { Text = "500", HorizontalOptions = LayoutOptions.FillAndExpand }; var plus500Button = new Button{ Text = "+500" }; plus500Button.Clicked += delegate(object sender, EventArgs e){ try { float totalDeLaComida = float.Parse( totalDeLaComidaEntry.Text ) ; totalDeLaComidaEntry.Text = "" + ( totalDeLaComida + 500f); } catch( Exception exception ) { } }; var plus300Button = new Button{ Text = "+300" }; plus300Button.Clicked += delegate(object sender, EventArgs e){ try { float totalDeLaComida = float.Parse( totalDeLaComidaEntry.Text ) ; totalDeLaComidaEntry.Text = "" + ( totalDeLaComida + 300f); } catch( Exception exception ) { } }; var plus100Button = new Button{ Text = "+100" }; plus100Button.Clicked += delegate(object sender, EventArgs e){ try { float totalDeLaComida = float.Parse( totalDeLaComidaEntry.Text ) ; totalDeLaComidaEntry.Text = "" + ( totalDeLaComida + 100f ); } catch( Exception exception ) { } }; var plus50Button = new Button{ Text = "+50" }; plus50Button.Clicked += delegate(object sender, EventArgs e){ try { float totalDeLaComida = float.Parse( totalDeLaComidaEntry.Text ) ; totalDeLaComidaEntry.Text = "" + ( totalDeLaComida + 50f); } catch( Exception exception ) { } }; var plus30Button = new Button{ Text = "+30" }; plus30Button.Clicked += delegate(object sender, EventArgs e){ try { float totalDeLaComida = float.Parse( totalDeLaComidaEntry.Text ) ; totalDeLaComidaEntry.Text = "" + ( totalDeLaComida + 30f); } catch( Exception exception ) { } }; var plus10Button = new Button{ Text = "+10" }; plus10Button.Clicked += delegate(object sender, EventArgs e){ try { float totalDeLaComida = float.Parse( totalDeLaComidaEntry.Text ) ; totalDeLaComidaEntry.Text = "" + ( totalDeLaComida + 10f); } catch( Exception exception ) { } }; var plus5Button = new Button{ Text = "+5" }; plus5Button.Clicked += delegate(object sender, EventArgs e){ try { float totalDeLaComida = float.Parse( totalDeLaComidaEntry.Text ) ; totalDeLaComidaEntry.Text = "" + ( totalDeLaComida + 5f); } catch( Exception exception ) { } }; var plus3Button = new Button{ Text = "+3" }; plus3Button.Clicked += delegate(object sender, EventArgs e){ try { float totalDeLaComida = float.Parse( totalDeLaComidaEntry.Text ) ; totalDeLaComidaEntry.Text = "" + ( totalDeLaComida + 3f); } catch( Exception exception ) { } }; var plus1Button = new Button{ Text = "+1" }; plus1Button.Clicked += delegate(object sender, EventArgs e){ try { float totalDeLaComida = float.Parse( totalDeLaComidaEntry.Text ) ; totalDeLaComidaEntry.Text = "" + ( totalDeLaComida + 1f); } catch( Exception exception ) { } }; var cambiarMonedaButton = new Button{ Text = "MXN" }; cambiarMonedaButton.Clicked += async delegate(object sender, EventArgs e){ try { float totalDeLaComida = float.Parse( totalDeLaComidaEntry.Text ) ; indicator.IsVisible = true; indicator.IsRunning = true; var from = "USD"; var to = "MXN"; if( cambiarMonedaButton.Text.Equals("MXN")) { from = "USD"; to = "MXN"; } else { from = "MXN"; to = "USD"; } HttpResponse<string> response = await Unirest.get("https://currency-exchange.p.mashape.com/exchange?from="+from+"&q="+totalDeLaComida+"&"+to+"=MXN") .header("X-Mashape-Key", "xUnaD3PLmhmshJQmfF35NhFUZUOSp1vJXQtjsnrTrGSsoxOBad") .header("Accept", "text/plain") .asStringAsync(); indicator.IsRunning = false; indicator.IsVisible = false; totalDeLaComidaEntry.Text = response.Body; if( cambiarMonedaButton.Text.Equals("MXN")) { cambiarMonedaButton.Text = "USD"; } else { cambiarMonedaButton.Text = "MXN"; } //MainPage.DisplayAlert ("Calculado", "Cambio:" +response.Body , "OK"); } catch( Exception exception ) { } }; var porcentajeDePropinaEntry = new Entry { Text = "10" }; var porcentajeDePropinaSlider = new Slider(0,100,10) ; porcentajeDePropinaSlider.ValueChanged += delegate(object sender, ValueChangedEventArgs e) { porcentajeDePropinaEntry.Text = "" + e.NewValue; }; var CalcularPropinaButton = new Button { Text = "Calcular propina", FontSize = Device.GetNamedSize (NamedSize.Large, typeof(Label)), FontAttributes = FontAttributes.Bold }; MainPage = new ContentPage { Content = new ContentView{ Padding = 40, Content = new StackLayout { VerticalOptions = LayoutOptions.Center, Children = { new Label { XAlign = TextAlignment.Center, Text = "Numero de personas", FontSize = Device.GetNamedSize (NamedSize.Large, typeof(Label)), FontAttributes = FontAttributes.Bold }, new StackLayout { Orientation = StackOrientation.Horizontal, Padding = 20, Children ={ set3Button, set4Button, set5Button, set6Button, set7Button, set8Button } }, new StackLayout { Orientation = StackOrientation.Horizontal, Padding = 20, Children ={ numeroDePersonasStepper, } }, numeroDePersonasEntry, new Label { XAlign = TextAlignment.Center, Text = "Total de la comida ( $ )", FontSize = Device.GetNamedSize (NamedSize.Large, typeof(Label)), FontAttributes = FontAttributes.Bold }, new StackLayout { Orientation = StackOrientation.Horizontal, Padding = 20, Children ={ new StackLayout { Orientation = StackOrientation.Vertical, Padding = 20, Children ={ plus500Button, plus300Button, plus100Button, } }, new StackLayout { Orientation = StackOrientation.Vertical, Padding = 20, Children ={ plus50Button, plus30Button, plus10Button, } }, new StackLayout { Orientation = StackOrientation.Vertical, Padding = 20, Children ={ plus5Button, plus3Button, plus1Button, } }, } }, new StackLayout { Orientation = StackOrientation.Horizontal, Padding = 20, Children ={ totalDeLaComidaEntry, indicator, cambiarMonedaButton} }, new Label { XAlign = TextAlignment.Center, Text = "Porcentaje de propina ( % )", FontSize = Device.GetNamedSize (NamedSize.Large, typeof(Label)), FontAttributes = FontAttributes.Bold }, porcentajeDePropinaSlider, porcentajeDePropinaEntry, CalcularPropinaButton } } } }; CalcularPropinaButton.Clicked += delegate(object sender, EventArgs e) { try { int numeroDePersonas = Int32.Parse( numeroDePersonasEntry.Text ) ; float totalDeLaComida = float.Parse( totalDeLaComidaEntry.Text ); float porcentajeDePropina = float.Parse( porcentajeDePropinaEntry.Text ); float propinaPorPersona = ( totalDeLaComida / (float)numeroDePersonas ) * (porcentajeDePropina / 100f); MainPage.DisplayAlert ("Calculado", "Propina por persona:" + propinaPorPersona , "OK"); } catch(Exception exception) { MainPage.DisplayAlert ("Erro", "Favor de revisar los campos" , "OK"); } }; }
public async Task ExecuteLoadTweetsCommand() { if (IsBusy) return; IsBusy = true; LoadTweetsCommand.ChangeCanExecute(); var error = false; try { Tweets.Clear(); var auth = new ApplicationOnlyAuthorizer() { CredentialStore = new InMemoryCredentialStore { ConsumerKey = "ZTmEODUCChOhLXO4lnUCEbH2I", ConsumerSecret = "Y8z2Wouc5ckFb1a0wjUDT9KAI6DUat5tFNdmIkPLl8T4Nyaa2J", }, }; await auth.AuthorizeAsync(); var twitterContext = new TwitterContext(auth); var queryResponse = await (from tweet in twitterContext.Status where tweet.Type == StatusType.User && tweet.ScreenName == "shanselman" && tweet.Count == 100 && tweet.IncludeRetweets == true && tweet.ExcludeReplies == true select tweet).ToListAsync(); var tweets = (from tweet in queryResponse select new Tweet { StatusID = tweet.StatusID, ScreenName = tweet.User.ScreenNameResponse, Text = tweet.Text, CurrentUserRetweet = tweet.CurrentUserRetweet, CreatedAt = tweet.CreatedAt, Image = tweet.RetweetedStatus != null && tweet.RetweetedStatus.User != null ? tweet.RetweetedStatus.User.ProfileImageUrl.Replace("http://", "https://") : (tweet.User.ScreenNameResponse == "shanselman" ? "scott159.png" : tweet.User.ProfileImageUrl.Replace("http://", "https://")) }).ToList(); foreach (var tweet in tweets) { Tweets.Add(tweet); } if (Device.OS == TargetPlatform.iOS) { // only does anything on iOS, for the Watch DependencyService.Get<ITweetStore>().Save(tweets); } } catch { error = true; } if (error) { var page = new ContentPage(); await page.DisplayAlert("Error", "Unable to load tweets.", "OK"); } IsBusy = false; LoadTweetsCommand.ChangeCanExecute(); }