private async void bntRecoverClick(object sender, EventArgs e) { try { if (string.IsNullOrWhiteSpace(email.Text) || string.IsNullOrEmpty(email.Text)) { Snackbar bar = Snackbar.Make(parentForgot, Html.FromHtml("<font color=\"#000000\">Fill email</font>"), Snackbar.LengthLong); Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout)bar.View; layout.SetMinimumHeight(100); layout.SetBackgroundColor(Android.Graphics.Color.White); layout.TextAlignment = TextAlignment.Center; layout.ScrollBarSize = 16; bar.SetActionTextColor(Android.Content.Res.ColorStateList.ValueOf(Android.Graphics.Color.Red)); bar.SetDuration(Snackbar.LengthLong); bar.SetAction("Ok", (v) => { }); bar.Show(); } else { string txtEmailForgot = email.Text; var httpClient = new HttpClient(); var content = new StringContent(JsonConvert.SerializeObject(new { Email = txtEmailForgot }), Encoding.UTF8, "application/json"); var result = await httpClient.PostAsync("UrlApi" + "api/account/forgotpassword", content); var response = await result.Content.ReadAsStringAsync(); Toast.MakeText(this, "Check your email please.", ToastLength.Long).Show(); StartActivity(typeof(LogIn)); } } catch (HttpRequestException httpEx) { Snackbar bar = Snackbar.Make(parentForgot, Html.FromHtml("<font color=\"#000000\">Check your internet connection</font>"), Snackbar.LengthLong); Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout)bar.View; layout.SetMinimumHeight(100); layout.SetBackgroundColor(Android.Graphics.Color.White); layout.TextAlignment = TextAlignment.Center; layout.ScrollBarSize = 16; bar.SetActionTextColor(Android.Content.Res.ColorStateList.ValueOf(Android.Graphics.Color.Red)); bar.SetDuration(Snackbar.LengthIndefinite); bar.SetAction("Ok", (v) => { }); bar.Show(); } catch (Exception ex) { Snackbar bar = Snackbar.Make(parentForgot, Html.FromHtml("<font color=\"#000000\">Error: " + ex + "</font>"), Snackbar.LengthLong); Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout)bar.View; layout.SetMinimumHeight(100); layout.SetBackgroundColor(Android.Graphics.Color.White); layout.TextAlignment = TextAlignment.Center; layout.ScrollBarSize = 16; bar.SetActionTextColor(Android.Content.Res.ColorStateList.ValueOf(Android.Graphics.Color.Red)); bar.SetDuration(Snackbar.LengthIndefinite); bar.SetAction("Ok", (v) => { }); bar.Show(); } }
private void displaySnackBar(string text) { Snackbar bar = Snackbar.Make(view, Html.FromHtml("<font color=\"#000000\">" + text + "</font>"), Snackbar.LengthLong); Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout)bar.View; layout.SetMinimumHeight(100); layout.SetBackgroundColor(Android.Graphics.Color.White); layout.TextAlignment = TextAlignment.Center; layout.ScrollBarSize = 20; bar.SetActionTextColor(Android.Content.Res.ColorStateList.ValueOf(Android.Graphics.Color.Red)); bar.SetDuration(Snackbar.LengthIndefinite); bar.SetAction("Ok", (v) => { }); bar.Show(); }
/** * Update Snackbar bottom margin */ public void updateSnackbar(View child, View dependency) { if (dependency != null && dependency is Snackbar.SnackbarLayout) { snackbarLayout = (Snackbar.SnackbarLayout)dependency; if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat) { snackbarLayout.AddOnLayoutChangeListener( new CustomIOnLayoutChangeListener( (View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) => { if (floatingActionButton != null && floatingActionButton.LayoutParameters is ViewGroup.MarginLayoutParams) { ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams)floatingActionButton.LayoutParameters; snackBarY = bottom - v.GetY(); fabTargetOffset = fabDefaultBottomMargin - child.TranslationY + snackBarY; p.SetMargins(p.LeftMargin, p.TopMargin, p.RightMargin, (int)fabTargetOffset); floatingActionButton.RequestLayout(); } // Pass navigation height to listener if (navigationPositionListener != null) { navigationPositionListener.onPositionChange((int)(child.MeasuredHeight - child.TranslationY + snackBarY)); } } ) ); } if (mSnackbarHeight == -1) { mSnackbarHeight = dependency.Height; } int targetMargin = (int)(child.MeasuredHeight - child.TranslationY); if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop) { child.BringToFront(); } if (dependency.LayoutParameters is ViewGroup.MarginLayoutParams) { ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams)dependency.LayoutParameters; p.SetMargins(p.LeftMargin, p.TopMargin, p.RightMargin, targetMargin); dependency.RequestLayout(); } } }
//Snackbar preventing accidental exit public override void OnBackPressed() { if (drawerLayout.IsDrawerOpen(GravityCompat.Start)) { drawerLayout.CloseDrawers(); } else { Snackbar snackbar = Snackbar.Make((View)cameraSurfaceView, "Use the home button to exit", Snackbar.LengthShort); Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout)snackbar.View; //get the snackbar layout layout.SetMinimumHeight(110); layout.SetBackgroundColor(Android.Graphics.Color.DarkOrange); TextView snackbarTextView = snackbar.View.FindViewById <TextView>(Resource.Id.snackbar_text); //change text size snackbarTextView.SetTextSize(Android.Util.ComplexUnitType.Dip, 29); // snackbar.Show(); } }
private async void clickBtnLogIn(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(username.Text) || string.IsNullOrEmpty(username.Text)) { Snackbar bar = Snackbar.Make(parentLayout, "Fill username", Snackbar.LengthLong); bar.SetText(Html.FromHtml("<font color=\"#000000\">Fill username</font>")); Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout)bar.View; layout.SetMinimumHeight(100); layout.SetBackgroundColor(Android.Graphics.Color.White); layout.TextAlignment = TextAlignment.Center; layout.ScrollBarSize = 16; bar.SetActionTextColor(Android.Content.Res.ColorStateList.ValueOf(Android.Graphics.Color.Red)); bar.SetDuration(Snackbar.LengthLong); bar.SetAction("Ok", (v) => { }); bar.Show(); } else if (string.IsNullOrWhiteSpace(password.Text) || string.IsNullOrEmpty(password.Text)) { Snackbar bar = Snackbar.Make(parentLayout, Html.FromHtml("<font color=\"#000000\">Fill password</font>"), Snackbar.LengthLong); Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout)bar.View; layout.SetMinimumHeight(100); layout.SetBackgroundColor(Android.Graphics.Color.White); layout.TextAlignment = TextAlignment.Center; layout.ScrollBarSize = 16; bar.SetActionTextColor(Android.Content.Res.ColorStateList.ValueOf(Android.Graphics.Color.Red)); bar.SetDuration(Snackbar.LengthLong); bar.SetAction("Ok", (v) => { }); bar.Show(); } else { var progressDialog = new ProgressDialog(this); try { progressDialog.SetIcon(2130968582); progressDialog.SetCancelable(true); progressDialog.SetMessage("Please wait!"); progressDialog.SetProgressStyle(ProgressDialogStyle.Spinner); progressDialog.Show(); var client = new HttpClient(); var keyValueLogIn = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("username", username.Text), new KeyValuePair <string, string>("password", password.Text), new KeyValuePair <string, string>("grant_type", "password") }; var request = new HttpRequestMessage(HttpMethod.Post, "UrlApiToken"); request.Content = new FormUrlEncodedContent(keyValueLogIn); var response = await client.SendAsync(request); var content = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode) { TokenModel tokenFromServer = JsonConvert.DeserializeObject <TokenModel>(content); var jsonContent = JsonConvert.SerializeObject(username.Text); var LogIncontent = new StringContent(jsonContent, Encoding.ASCII, "application/json"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenFromServer.access_token); response = await client.PostAsync("UrlApi" + "api/Account/userdata", LogIncontent); var userData = await response.Content.ReadAsStringAsync(); User user = JsonConvert.DeserializeObject <User>(userData); var userSession = new UserSession { FirstName = user.FirstName, LastName = user.LastName, userId = user.userId, Token = tokenFromServer.access_token, user_image = user.user_image }; con.Insert(userSession); progressDialog.Cancel(); StartActivity(typeof(MainActivity)); } else { LogInError logInError = JsonConvert.DeserializeObject <LogInError>(content); var alertLogInError = new Android.App.AlertDialog.Builder(this); alertLogInError.SetTitle(logInError.error); alertLogInError.SetMessage(logInError.error_description); username.Text = ""; password.Text = ""; Snackbar bar = Snackbar.Make(parentLayout, Html.FromHtml("<font color=\"#000000\">" + logInError.error + " - " + logInError.error_description + "</font>"), Snackbar.LengthLong); Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout)bar.View; layout.SetMinimumHeight(100); layout.SetBackgroundColor(Android.Graphics.Color.White); layout.TextAlignment = TextAlignment.Center; layout.ScrollBarSize = 16; bar.SetActionTextColor(Android.Content.Res.ColorStateList.ValueOf(Android.Graphics.Color.Red)); bar.SetDuration(Snackbar.LengthLong); bar.SetAction("Ok", (v) => { }); bar.Show(); progressDialog.Cancel(); } } catch (HttpRequestException httpEx) { Snackbar bar = Snackbar.Make(parentLayout, Html.FromHtml("<font color=\"#000000\">Please check your internet connection!</font>"), Snackbar.LengthLong); Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout)bar.View; layout.SetMinimumHeight(100); layout.SetBackgroundColor(Android.Graphics.Color.White); layout.TextAlignment = TextAlignment.Center; layout.ScrollBarSize = 16; bar.SetActionTextColor(Android.Content.Res.ColorStateList.ValueOf(Android.Graphics.Color.Red)); bar.SetDuration(Snackbar.LengthIndefinite); bar.SetAction("Ok", (v) => { }); bar.Show(); progressDialog.Cancel(); } catch (Exception ex) { Snackbar bar = Snackbar.Make(parentLayout, Html.FromHtml("<font color=\"#000000\">Error: " + ex + "</font>"), Snackbar.LengthLong); Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout)bar.View; layout.SetMinimumHeight(100); layout.SetBackgroundColor(Android.Graphics.Color.White); layout.TextAlignment = TextAlignment.Center; layout.ScrollBarSize = 16; bar.SetActionTextColor(Android.Content.Res.ColorStateList.ValueOf(Android.Graphics.Color.Red)); bar.SetDuration(Snackbar.LengthIndefinite); bar.SetAction("Ok", (v) => { }); bar.Show(); progressDialog.Cancel(); } } }
private async void clickBtnRegister(object sender, EventArgs e) { if (string.IsNullOrEmpty(Email.Text) || string.IsNullOrWhiteSpace(Email.Text)) { displaySnackBar("Fill Email!"); } else if (string.IsNullOrEmpty(Username.Text) || string.IsNullOrWhiteSpace(Username.Text)) { displaySnackBar("Fill username!"); } else if (string.IsNullOrEmpty(Password.Text) || string.IsNullOrWhiteSpace(Password.Text)) { displaySnackBar("Fill password!"); } else if (string.IsNullOrEmpty(ConfirmPassword.Text) || string.IsNullOrWhiteSpace(ConfirmPassword.Text)) { displaySnackBar("Fill column confirm password!"); } else if (string.IsNullOrEmpty(FirstName.Text) || string.IsNullOrWhiteSpace(FirstName.Text)) { displaySnackBar("Fill First name!"); } else if (string.IsNullOrEmpty(LastName.Text) || string.IsNullOrWhiteSpace(LastName.Text)) { displaySnackBar("Fill Last name!"); } else if (Password.Text != ConfirmPassword.Text) { displaySnackBar("Confirm password do not match with password. Please check them."); } else { var progressDialog = new ProgressDialog(this); progressDialog.SetCancelable(true); progressDialog.SetMessage("Please wait!"); progressDialog.SetProgressStyle(ProgressDialogStyle.Spinner); progressDialog.Show(); string email = Email.Text; string username = Username.Text; string password = Password.Text; string confirmPassword = ConfirmPassword.Text; string fistName = FirstName.Text; string lastName = LastName.Text; string phoneNumber = PhoneNumber.Text; httpClient = new HttpClient(); var resultForUsername = await httpClient.PostAsync("UrlApiapi/account/checkUsername", new StringContent(JsonConvert.SerializeObject(username), Encoding.UTF8, "application/json")); var responseForUsername = await resultForUsername.Content.ReadAsStringAsync(); var resultForEmail = await httpClient.PostAsync("UrlApiapi/account/checkEmail", new StringContent(JsonConvert.SerializeObject(email), Encoding.UTF8, "application/json")); var responseForEmail = await resultForEmail.Content.ReadAsStringAsync(); if (responseForUsername == "true") { displaySnackBar("There exist user with this username."); progressDialog.Hide(); } else if (responseForEmail == "true") { displaySnackBar("There exisit new user with this mail."); progressDialog.Hide(); } else { string base64Image = ""; try { UserImage.BuildDrawingCache(true); BitmapDrawable bd = (BitmapDrawable)UserImage.Drawable; Bitmap bitmap = bd.Bitmap; byte[] imageData; using (MemoryStream stream = new MemoryStream()) { bitmap.Compress(Bitmap.CompressFormat.Png, 0, stream); imageData = stream.ToArray(); } base64Image = Convert.ToBase64String(imageData); } catch (Exception ex) { } try { var signUp = new SignUp { Email = email, UserName = username, FirstName = fistName, LastName = lastName, BirthDate = DateTime.Now.ToString(), Password = password, PhoneNumber = phoneNumber, user_image = base64Image, ConfirmPassword = confirmPassword, Gender = "M" }; var httpClient = new HttpClient(); var jsonContent = JsonConvert.SerializeObject(signUp); var content = new StringContent(jsonContent, Encoding.UTF8, "application/json"); var response = await httpClient.PostAsync("UrlApiapi/account/Register", content); var responseString = await response.Content.ReadAsStringAsync(); Toast.MakeText(this, "Check your email for further details.", ToastLength.Long).Show(); progressDialog.Cancel(); StartActivity(typeof(LogIn)); } catch (HttpRequestException httpEx) { Snackbar bar = Snackbar.Make(linearLayout2, "Please check your internet connection!", Snackbar.LengthLong); Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout)bar.View; layout.SetMinimumHeight(100); layout.SetBackgroundColor(Android.Graphics.Color.White); layout.TextAlignment = TextAlignment.Center; layout.ScrollBarSize = 16; bar.SetActionTextColor(Android.Content.Res.ColorStateList.ValueOf(Android.Graphics.Color.Red)); bar.SetDuration(Snackbar.LengthIndefinite); bar.SetAction("Ok", (v) => { }); bar.Show(); progressDialog.Cancel(); } catch (Exception ex) { progressDialog.Cancel(); Toast.MakeText(this, "Error: " + ex, ToastLength.Long).Show(); } } } }