public async void OnButtonClick(object sender, EventArgs e) { string entryText = textEntry.Text; AnalyticsHelpers.TrackEvent(AnalyticsConstants.GO_BUTTON_TAPPED, new Dictionary <string, string> { { AnalyticsConstants.TEXT_ENTERED, entryText } }); Device.BeginInvokeOnMainThread(() => { //Hide the keyboard textEntry.Unfocus(); //Show the activity indicator and hide the Go Button activityIndicator.IsRunning = true; activityIndicator.IsVisible = true; goButton.IsVisible = false; goButton.IsEnabled = false; }); //Perform a task for 2000 miliseconds await Task.Delay(2000); Device.BeginInvokeOnMainThread(() => { //Hide the activity indicator now that task has completed activityIndicator.IsRunning = false; activityIndicator.IsVisible = false; goButton.IsVisible = true; goButton.IsEnabled = true; //display the textLabel.Text = entryText; }); }
public async void OnButtonClick(object sender, EventArgs e) { string entryText = textEntry.Text; Insights.Track(Insights_Constants.GO_BUTTON_TAPPED, Insights_Constants.TEXT_ENTERED, entryText); Device.BeginInvokeOnMainThread(() => { //Hide the keyboard textEntry.Unfocus(); //Show the activity indicator and hide the Go Button activityIndicator.IsRunning = true; activityIndicator.IsVisible = true; goButton.IsVisible = false; goButton.IsEnabled = false; }); //Perform a task for 2000 miliseconds var timer = Insights.TrackTime(Insights_Constants.ACTIVITY_INDICATOR_ONSCREEN); timer.Start(); await Task.Delay(2000); timer.Stop(); Device.BeginInvokeOnMainThread(() => { //Hide the activity indicator now that task has completed activityIndicator.IsRunning = false; activityIndicator.IsVisible = false; goButton.IsVisible = true; goButton.IsEnabled = true; //display the textLabel.Text = entryText; }); }
public NewUserSignUpPage() { ViewModel.SaveFailed += HandleSaveFailed; ViewModel.TakePhotoFailed += HandleTakePhotoFailed; ViewModel.SaveSuccessfullyCompleted += HandleSaveSuccessfullyCompleted; BackgroundColor = Color.FromHex("2980b9"); var passwordEntry = new StyledEntry(1) { Placeholder = "Password", IsPassword = true, HorizontalOptions = LayoutOptions.Fill, HorizontalTextAlignment = TextAlignment.End, VerticalOptions = LayoutOptions.Fill, PlaceholderColor = Color.FromHex("749FA8"), ReturnType = ReturnType.Done }; passwordEntry.ReturnCommand = new Command(() => passwordEntry.Unfocus()); passwordEntry.SetBinding(Xamarin.Forms.Entry.TextProperty, nameof(ViewModel.PasswordEntryText)); var usernameEntry = new StyledEntry(1) { Placeholder = "Username", HorizontalOptions = LayoutOptions.Fill, HorizontalTextAlignment = TextAlignment.End, PlaceholderColor = Color.FromHex("749FA8"), ReturnType = ReturnType.Next, ReturnCommand = new Command(() => passwordEntry.Focus()) }; usernameEntry.SetBinding(Xamarin.Forms.Entry.TextProperty, nameof(ViewModel.UsernameEntryText)); _saveUsernameButton = new StyledButton(Borders.Thin, 1) { Text = "Save User", HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.EndAndExpand }; _saveUsernameButton.SetBinding(IsEnabledProperty, nameof(ViewModel.IsInternetConnectionInactive)); _saveUsernameButton.SetBinding(Button.CommandProperty, nameof(ViewModel.SaveButtonCommand)); _cancelButton = new StyledButton(Borders.Thin, 1) { Text = "Cancel", HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.End }; _cancelButton.Clicked += HandleCancelButtonClicked; _cancelButton.SetBinding(IsEnabledProperty, nameof(ViewModel.IsInternetConnectionInactive)); _cancelButton.SetBinding(Button.CommandProperty, nameof(ViewModel.CancelButtonCommand)); _takePhotoButton = new StyledButton(Borders.Thin, 1) { Text = "Take Photo", HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.EndAndExpand }; _takePhotoButton.SetBinding(IsEnabledProperty, nameof(ViewModel.IsInternetConnectionInactive)); _takePhotoButton.SetBinding(Button.CommandProperty, nameof(ViewModel.TakePhotoButtonCommand)); var isFacialRecognitionCompletedDescriptionLabel = new StyledLabel { Text = "Facial Recognition Completed", VerticalTextAlignment = TextAlignment.Center }; var isFacialRecognitionCompletedLabel = new FontAwesomeIcon { TextColor = Color.White, VerticalTextAlignment = TextAlignment.Center, HorizontalTextAlignment = TextAlignment.Center }; isFacialRecognitionCompletedLabel.SetBinding(Label.TextProperty, nameof(ViewModel.FontAwesomeLabelText)); if (Device.RuntimePlatform is Device.iOS) { isFacialRecognitionCompletedLabel.SetBinding(IsVisibleProperty, nameof(ViewModel.IsInternetConnectionInactive)); } var activityIndicator = new ActivityIndicator { Color = Color.White, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.EndAndExpand, }; activityIndicator.SetBinding(IsVisibleProperty, nameof(ViewModel.IsInternetConnectionActive)); activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, nameof(ViewModel.IsInternetConnectionActive)); var facialRecognitionStackLayout = new StackLayout { Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.Center, Children = { isFacialRecognitionCompletedDescriptionLabel, isFacialRecognitionCompletedLabel } }; var stackLayout = new StackLayout { Padding = new Thickness(20, 50, 20, 20), VerticalOptions = LayoutOptions.FillAndExpand, Children = { new Label { Text = "Please enter username", TextColor = Color.White, HorizontalOptions = LayoutOptions.Start }, usernameEntry, new Label { Text = "Please enter password", TextColor = Color.White, HorizontalOptions = LayoutOptions.Start }, passwordEntry, _takePhotoButton, facialRecognitionStackLayout, } }; switch (Device.RuntimePlatform) { case Device.iOS: facialRecognitionStackLayout.Children.Add(activityIndicator); break; case Device.Android: stackLayout.Children.Add(activityIndicator); break; default: throw new NotSupportedException("Device Runtime Unsupported"); } stackLayout.Children.Add(_saveUsernameButton); stackLayout.Children.Add(_cancelButton); Content = new Xamarin.Forms.ScrollView { Content = stackLayout }; On <Xamarin.Forms.PlatformConfiguration.iOS>().SetUseSafeArea(true); }