示例#1
0
        private async void LoginButton_Click(object sender, EventArgs e)
        {
            loginButton.Enabled = false;
            try
            {
                await GlobalServices.XjtuSite.Account.LoginAsync(userNameView.Text, passwordView.Text);

                // ±£´æÉèÖá£
                using (var pref = GetPreferences(FileCreationMode.Private))
                {
                    var edit         = pref.Edit();
                    var savePassword = savePasswordCheckBox.Checked;
                    edit.PutString("userName", userNameView.Text);
                    edit.PutString("password", savePassword ? passwordView.Text : "");
                    edit.PutBoolean("savePassword", savePassword);
                    edit.Commit();
                }
                GlobalServices.SaveState();
                DroidUtility.ShowToast(this, "µÇ¼³É¹¦¡£");
            }
            catch (Exception ex)
            {
                DroidUtility.ReportException(this, ex);
            }
            finally
            {
                loginButton.Enabled = true;
            }
        }
示例#2
0
 public async Task <bool> UpdateAccountStatus()
 {
     if (GlobalServices.XjtuSite.Account.IsInvalidated)
     {
         DroidUtility.ShowToast(this, "ÕýÔÚ²éѯµÇ¼״̬¡­¡­");
         await GlobalServices.XjtuSite.Account.UpdateAsync();
     }
     if (GlobalServices.XjtuSite.Account.IsLoggedIn)
     {
         var intent = new Intent(this, typeof(MainActivity));
         StartActivity(intent);
         this.Finish();
         return(true);
     }
     return(false);
 }
示例#3
0
        private async Task Redirect()
        {
            offlineNotice.Visibility = ViewStates.Gone;
            if (GlobalServices.XjtuSite.Account.IsInvalidated)
            {
                try
                {
                    await GlobalServices.XjtuSite.Account.UpdateAsync();
                }
                catch (Exception ex) when(ex is WebException || ex is TaskCanceledException)
                {
                    offlineNotice.Visibility = ViewStates.Visible;
                    DroidUtility.ReportException(this, ex);
                    return;
                }
            }
            var intent = new Intent(this, GlobalServices.XjtuSite.Account.IsLoggedIn
                ? typeof(MainActivity)
                : typeof(LoginActivity));

            StartActivity(intent);
            this.Finish();
        }
        public Task <string> GetPasswordAsync(Stream keypadImageStream, IList <MapAreaInfo> mapAreas, SiteManager site)
        {
            var tcs = new TaskCompletionSource <string>();
            var adb = new AlertDialog.Builder(Context);

            using (var inflater = LayoutInflater.From(adb.Context))
            {
                var    view                  = inflater.Inflate(Resource.Layout.XjtuCardPassword, null);
                var    passwordView          = view.FindViewById <TextView>(Resource.Id.passwordTextView);
                var    padTable              = view.FindViewById <TableLayout>(Resource.Id.passwordPadTable);
                var    currentPassword       = "";
                Action updatePasswordDisplay = () =>
                {
                    passwordView.Text = new string('#', currentPassword.Length);
                };
                //生成按键。
                var keypadBitmap = BitmapFactory.DecodeStream(keypadImageStream);
                for (var row = 0; row < 4; row++)
                {
                    var tr = new TableRow(adb.Context)
                    {
                        LayoutParameters = new ViewGroup.LayoutParams(
                            ViewGroup.LayoutParams.WrapContent,
                            ViewGroup.LayoutParams.WrapContent)
                    };
                    padTable.AddView(tr);
                    for (var col = 0; col < 3; col++)
                    {
                        var  index      = row * 3 + col;
                        var  indexExpr  = Convert.ToString(index);
                        View buttonView = null;
                        if (index <= 9)
                        {
                            var area   = mapAreas.First(a => a.Value == indexExpr);
                            var button = new ImageButton(adb.Context)
                            {
                                LayoutParameters = new TableRow.LayoutParams(
                                    ViewGroup.LayoutParams.WrapContent,
                                    ViewGroup.LayoutParams.WrapContent),
                            };
                            button.SetMinimumWidth(DroidUtility.DipToPixelsX(64));
                            button.SetMinimumHeight(DroidUtility.DipToPixelsY(64));
                            button.SetImageBitmap(Bitmap.CreateBitmap(keypadBitmap, area.X1, area.Y1, area.Width, area.Height));
                            button.SetScaleType(ImageView.ScaleType.FitCenter);
                            button.Click += (_, e) =>
                            {
                                currentPassword += indexExpr;
                                updatePasswordDisplay();
                            };
                            buttonView = button;
                        }
                        else if (index == 10)
                        {
                            var button = new Button(adb.Context)
                            {
                                Text             = "更正",
                                LayoutParameters = new TableRow.LayoutParams(
                                    ViewGroup.LayoutParams.MatchParent,
                                    ViewGroup.LayoutParams.WrapContent)
                                {
                                    Span    = 2,
                                    Gravity = GravityFlags.CenterVertical
                                }
                            };
                            button.Click += (_, e) =>
                            {
                                currentPassword = "";
                                updatePasswordDisplay();
                            };
                            buttonView = button;
                        }
                        if (buttonView != null)
                        {
                            tr.AddView(buttonView);
                        }
                    }
                }
                //初始化界面。
                updatePasswordDisplay();
                adb.SetView(view)
                .SetPositiveButton("确定", (_, e) =>
                {
                    tcs.SetResult(currentPassword);
                })
                .SetNegativeButton("取消", (_, e) =>
                {
                    tcs.SetResult(null);
                })
                .Show();
            }
            return(tcs.Task);
        }