public void Validate() { var errorMsg = ""; if (user.Text.Length == 0 && pass.Text.Length == 0) { if (user.Text.Length == 0 || pass.Text.Length == 0) { errorMsg = "Please Enter User Name "; } if (pass.Text.Length == 0 || pass.Text.Length == 0) { errorMsg = errorMsg + "Please Enter Password"; } Toast.MakeText(this, errorMsg, ToastLength.Long).Show(); return; } else { cpd = new CustomProgressDialog(this); cpd.SetCancelable(false); cpd.Show(); DoLogin(user.Text, pass.Text); } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); //create a new dialog dialog = CustomProgressDialog.CreateDialog(this); dialog.OnWindowFocusChanged(true); Button btnGO = FindViewById <Button>(Resource.Id.go); btnGO.Click += (s, e) => { int result = 0; //show the dialog dialog.Show(); //do some things Task task = new Task(() => { for (int i = 0; i < 100; i++) { result += i; } }); task.ContinueWith(t => { Intent intent = new Intent(this, typeof(LastActivity)); intent.PutExtra("name", result.ToString()); StartActivity(intent); }); task.Start(); }; }
public MyWebViewClientrail(Android.App.Activity ac) { this.ac = ac; cpd = new CustomProgressDialog(ac); cpd.Show(); }
async void DoLogin(string username, string pasword) { cpd.Show(); LoginModel model = new LoginModel(); model.Username = username; model.Password = pasword; string ret = ""; try { var thread = new System.Threading.Thread(new ThreadStart(async delegate { cpd.Show(); })); thread.Start(); while (thread.ThreadState == ThreadState.Running) { await Task.Delay(100); } ret = await restService.PostServiceMethod(model).ConfigureAwait(false); if (ret.StartsWith("Error")) { cpd.DismissDialog(); if (ret.Contains("403")) { Toast.MakeText(this, "Invalis Username/Password", ToastLength.Long).Show(); } else { Toast.MakeText(this, ret, ToastLength.Long).Show(); } // login failed } else { try { STPUserInfo userinfo = new STPUserInfo(); userinfo = JsonConvert.DeserializeObject <STPUserInfo>(ret); edit.Clear(); // login suceeded, parse json edit.PutString("username", userinfo.DisplayName); edit.PutInt("userid", userinfo.UserID); edit.PutString("profilePath", userinfo.ImageURL); edit.PutBoolean("pluscard", userinfo.PlusCard); edit.PutBoolean("banned", userinfo.Banned); edit.Apply(); cpd.DismissDialog(); Finish(); Toast.MakeText(this, "Welcome " + userinfo.DisplayName, ToastLength.Long).Show(); } catch (Exception e) { cpd.DismissDialog(); Toast.MakeText(this, e.Message, ToastLength.Long).Show(); } } } catch (Exception e) { cpd.DismissDialog(); if (e.Message.Contains("403")) { Toast.MakeText(this, "Invalis Username/Password", ToastLength.Long).Show(); } else { Toast.MakeText(this, ret, ToastLength.Long).Show(); } } }
protected override void OnCreate(Bundle savedInstanceState) { StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder(); StrictMode.SetVmPolicy(builder.Build()); StrictMode.ThreadPolicy.Builder builder1 = new StrictMode.ThreadPolicy.Builder().PermitAll(); StrictMode.SetThreadPolicy(builder1.Build()); base.OnCreate(savedInstanceState); progress = new ProgressDialog(this); progress.Indeterminate = true; progress.SetProgressStyle(ProgressDialogStyle.Spinner); progress.SetCancelable(false); progress.SetMessage("Please wait..."); con = new InternetConnection(); dba = new DBHelper(); restService = new ServiceHelper(); SetContentView(Resource.Layout.Registration_Layout); other_email = Intent.GetStringExtra("email"); other_user = Intent.GetStringExtra("username"); pref = GetSharedPreferences("login", FileCreationMode.Private); edit = pref.Edit(); U_Name = FindViewById <TextView>(Resource.Id.user); M_obile = FindViewById <TextInputEditText>(Resource.Id.mobile); email_add = FindViewById <TextView>(Resource.Id.email); pass_word = FindViewById <TextInputEditText>(Resource.Id.pass); confrirm_password = FindViewById <TextInputEditText>(Resource.Id.confirmpassword); Registration = FindViewById <Button>(Resource.Id.submit); U_Name.Text = other_user; email_add.Text = other_email; Dateofbirth = FindViewById <TextInputEditText>(Resource.Id.birth); Gender = FindViewById <TextInputEditText>(Resource.Id.gender); //U_Name.Text = GoogleAuth_Activity.user_Name; //U_Name.SetCursorVisible(false); //U_Name.SetFadingEdgeLength(10); //U_Name.Enabled = false; //email_add.Text = GoogleAuth_Activity.alreadyregistered; //email_add.SetCursorVisible(false); //email_add.SetFadingEdgeLength(10); //email_add.Enabled = false; Dateofbirth.Click += DateSelect_OnClick;; Registration.Click += async delegate { other_user = U_Name.Text.ToString(); other_mobile = M_obile.Text.ToString(); other_email = email_add.Text.ToString(); other_pass = pass_word.Text.ToString(); otherconfirm_pass = confrirm_password.Text.ToString(); var hasNumber = new Regex(@"[0-9]+"); var hasUpperChar = new Regex(@"[A-Z]+"); var hasMiniMaxChars = new Regex(@".{6,25}"); var hasLowerChar = new Regex(@"[a-z]+"); var hasSymbols = new Regex(@"[!@#$%^&*()_+=\[{\]};:<>|./?,-]"); if (other_user.Equals("")) { Toast.MakeText(this, "Please Enter UserName", ToastLength.Short).Show(); return; } if (other_mobile.Equals("") || other_mobile.Length < 10) { Toast.MakeText(this, "Please Enter 10 digit Mobile Number", ToastLength.Short).Show(); return; } if (other_email.Equals("") || !other_email.Contains("@")) { Toast.MakeText(this, "Please Enter valid email address", ToastLength.Short).Show(); return; } if (other_pass.Equals("") || !hasNumber.IsMatch(other_pass) || !hasUpperChar.IsMatch(other_pass) || !hasMiniMaxChars.IsMatch(other_pass) || !hasLowerChar.IsMatch(other_pass) || !hasSymbols.IsMatch(other_pass)) { Toast.MakeText(this, "Password Should have minimum 6 character, minumum one special char, one uppercase letter,one lowercase letter", ToastLength.Short).Show(); return; } if (other_mobile.Length < 6) { Toast.MakeText(this, "Please Enter minimum 6 digit password", ToastLength.Short).Show(); return; } if (!other_pass.Equals(otherconfirm_pass)) { Toast.MakeText(this, "Password and confirm password should be same", ToastLength.Short).Show(); return; } //if (con.connectivity()) //{ // RegistrationData(); //} else { cpd = new CustomProgressDialog(this); cpd.SetCancelable(false); cpd.Show(); DoRegistration(other_user, other_pass, other_mobile, other_email); } }; }
async void DoRegistration(string username, string pasword, string mobilenumber, string emailadress) { //string hash = new LoginModel().GetHash(pasword, username); string timestamp = DateTime.Now.ToString("yyyyMMddHHmmss"); LoginModel objmodel = new LoginModel { Username = emailadress, Password = pasword, Mobile = mobilenumber, Email = emailadress, DisplayName = username, LoginType = "stportal", ts = timestamp }; objmodel.hash = objmodel.GetHash(); string test = JsonConvert.SerializeObject(objmodel); string response = ""; try { var thread = new System.Threading.Thread(new ThreadStart(async delegate { cpd.Show(); })); thread.Start(); while (thread.ThreadState == ThreadState.Running) { await Task.Delay(100); } response = await restService.PostServiceMethodRegistration(objmodel).ConfigureAwait(false); } catch (Exception we) { cpd.DismissDialog(); //var errresponse = (HttpWebResponse)we.Response; //using (StreamReader errreader = new StreamReader(errresponse.GetResponseStream())) //{ // responseString = errreader.ReadToEnd(); //} ////Toast.MakeText(this, e.Message, ToastLength.Long).Show(); } if (response.StartsWith("Error")) { cpd.DismissDialog(); Toast.MakeText(this, response, ToastLength.Long).Show(); // login failed } else { try { cpd.DismissDialog(); STPUserInfo userinfo = new STPUserInfo(); userinfo = JsonConvert.DeserializeObject <STPUserInfo>(response); if (response.Contains("UserAlreadyRegistered")) { //var registerintent = new Intent(this, typeof(MainActivity)); //StartActivityForResult(registerintent, 123); //Toast.MakeText(this, "Welcome " + userinfo.DisplayName, ToastLength.Long).Show(); } else { STPUserInfo userinfo2 = new STPUserInfo(); userinfo = JsonConvert.DeserializeObject <STPUserInfo>(response); edit.Clear(); // login suceeded, parse json edit.PutString("username", userinfo.DisplayName); edit.PutString("profilePath", userinfo.ImageURL); edit.PutInt("userid", userinfo.UserID); edit.PutBoolean("pluscard", userinfo.PlusCard); edit.PutBoolean("banned", userinfo.Banned); edit.Apply(); Finish(); Toast.MakeText(this, "Welcome " + userinfo.DisplayName, ToastLength.Long).Show(); // var registerintent = new Intent(this, typeof(MainActivity)); // StartActivityForResult(registerintent, 123); } } catch (Exception e) { cpd.DismissDialog(); Toast.MakeText(this, e.Message, ToastLength.Long).Show(); } } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Create your application here //使用加载等待页面 dialog = CustomProgressDialog.CreateDialog(this); dialog.OnWindowFocusChanged(true); LoginSystemType = Intent.GetStringExtra("LoginSystemType"); username = Intent.GetStringExtra("username"); EditText sampCount = FindViewById <EditText>(Resource.Id.sampCount); readIc = FindViewById <ToggleButton>(Resource.Id.btReadic); readIc.Click += icRead; dialog.Show(); //地点下拉菜单 sampAdressName = bsinf.selectAdress(); sp_adresssname = FindViewById <Spinner>(Resource.Id.sampAdress); //填充数据库数据 ArrayAdapter <string> adapter_adressName = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem, sampAdressName); adapter_adressName.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem); sp_adresssname.Adapter = adapter_adressName; sp_adresssname.ItemSelected += adress_ItemSelected; //业务类型 samp_mode = FindViewById <Spinner>(Resource.Id.sampMode); //填充xml文件数据 ArrayAdapter adapter_mode = ArrayAdapter.CreateFromResource(this, Resource.Array.SampMode, Android.Resource.Layout.SimpleSpinnerItem); adapter_mode.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem); samp_mode.Adapter = adapter_mode; samp_mode.Prompt = "请选择"; samp_mode.ItemSelected += selectMode_ItemSelected; //数量 samp_weight = FindViewById <EditText>(Resource.Id.sampCount); if (samp_weight.Text == "") { samp_weight.Text = "0.00"; } else { sampWeight = Convert.ToDouble(samp_weight.Text); } //单位 samp_util = FindViewById <Spinner>(Resource.Id.sampunilt); sampUtile = bsinf.selectUtil(); //填充数据 ArrayAdapter adapter_utile = ArrayAdapter.CreateFromResource(this, Resource.Array.SampUtile, Android.Resource.Layout.SimpleSpinnerItem); adapter_utile.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem); samp_util.Adapter = adapter_utile; //sp_goodsname.ItemSelected += TargetSpinner_ItemSelected; //萤石取样位置 samp_yshi = FindViewById <Spinner>(Resource.Id.sampYshi); ArrayAdapter adpter_yshi = ArrayAdapter.CreateFromResource(this, Resource.Array.SampYshi, Android.Resource.Layout.SimpleSpinnerItem); adpter_yshi.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem); samp_yshi.Adapter = adpter_yshi; }