Exemplo n.º 1
0
        public void HandleCustomEntry()
        {
            SetContentView(Resource.Layout.Main);                                                                          // xml specifies layout view
            mKeyboard = new Android.InputMethodServices.Keyboard(this, Resource.Xml.keyboard2);                            // KB xml
            et        = (TextView)FindViewById(Resource.Id.target);                                                        // User input is text view. Text entry caused standard KB to appear
            var inputManager = (InputMethodManager)MainActivity.mainActivity.GetSystemService(Context.InputMethodService); // Not necessary now

            inputManager.HideSoftInputFromWindow(et.WindowToken, HideSoftInputFlags.None);
            inputManager.HideSoftInputFromInputMethod(et.WindowToken, HideSoftInputFlags.None);
            Window.DecorView.ClearFocus();
            et.ClearFocus();
            mKeyboardView            = (CustomKeyboardView)this.FindViewById(Resource.Id.keyboard_view);
            mKeyboardView.Keyboard   = mKeyboard;
            mKeyboardView.Visibility = ViewStates.Visible;
            // MainActivity.app.Unfocus();

            /*
             * et.Touch += (sender1, e1) => {
             *  System.Diagnostics.Debug.WriteLine("onTouch - true");
             *  // mKeyboardView.Visibility = ViewStates.Visible;
             *  // ShowKeyboard(mTargetView);
             *  // ShowKeyboardWithAnimation();
             *  // MainActivity.app.Unfocus();
             *  e1.Handled = true;
             * };
             */

            mKeyboardView.Key += (sender1, e1) =>
            {
                long eventTime = JavaSystem.CurrentTimeMillis();
                // System.Diagnostics.Debug.WriteLine("mKeyboardView.Key event, primarycode: " + e1.PrimaryCode);
                if (ProcessKeyCode(e1.PrimaryCode))
                {
                    // System.Diagnostics.Debug.WriteLine("mKeyboardView done with keyboard entry");
                    active = false;
                    Finish();
                }
            };
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState)
        {
            base.OnCreateView (inflater, container, savedInstanceState);

            var view = inflater.Inflate (Resource.Layout.LogInDialog, container, false);

            mTxtUserName = view.FindViewById<EditText> (Resource.Id.txtUserName);
            mTxtPassword = view.FindViewById<EditText> (Resource.Id.txtPassword);

            mCheckbox = view.FindViewById<CheckBox> (Resource.Id.LoginCheckBox);

            try{
                var CheckPrefs = Application.Context.GetSharedPreferences("MyCheckState", FileCreationMode.Private);
                checkState = CheckPrefs.GetString("CheckState", null);

            }catch{

            }

            switch (checkState)
            {
            case "False":
                mCheckbox.Checked = false;
                break;
            case "True":
                mCheckbox.Checked = true;
                try{
                    var UsernamePrefs = Application.Context.GetSharedPreferences("username", FileCreationMode.Private);
                    mTxtUserName.Text = UsernamePrefs.GetString("username", null);

                }catch{

                }
                try{
                    var PasswordPrefs = Application.Context.GetSharedPreferences("password", FileCreationMode.Private);
                    mTxtPassword.Text = PasswordPrefs.GetString("password", null);

                }catch{

                }
                break;
            default:
                mCheckbox.Checked = true;
                break;
            }

            mBtnSignUp = view.FindViewById<Button> (Resource.Id.btnLogInDialog);
            mErrorText = view.FindViewById<TextView> (Resource.Id.txtError);

            mProgressBar = view.FindViewById<ProgressBar> (Resource.Id.progressBar);

            mProgressBar.Visibility = ViewStates.Invisible;

            mBtnSignUp.Click +=  (object sender, EventArgs e) => {

                mProgressBar.Visibility = ViewStates.Visible;

                mTxtUserName.ClearFocus();
                mErrorText.ClearFocus();
                mBtnSignUp.RequestFocus();

                mErrorText.Text=string.Format("登录中...");

                //关键盘

                InputMethodManager inputManager = (InputMethodManager)Activity.GetSystemService(Context.InputMethodService);

                inputManager.HideSoftInputFromWindow(mTxtPassword.WindowToken, HideSoftInputFlags.None);
                inputManager.HideSoftInputFromWindow(mTxtUserName.WindowToken, HideSoftInputFlags.None);

                mWorker=new BackgroundWorker();
                mWorker.WorkerSupportsCancellation = true;

                mWorker.DoWork+= delegate(object sender1, DoWorkEventArgs e1) {

                    BackgroundWorker mworker = sender1 as BackgroundWorker;

                    if (mworker.CancellationPending == true) {
                        e1.Cancel = true;
                    } else {
                        checkPassword();
                    }

                };

                mWorker.RunWorkerCompleted+=delegate(object sender1, RunWorkerCompletedEventArgs e1) {

                    if (e1.Cancelled == true) {

                    } else if (!(e1.Error == null)) {

                    } else {
                        worker_RunWorkerCompleted();
                    }

                };

                if (mWorker.IsBusy != true) {
                    mWorker.RunWorkerAsync ();
                }

            };

            return view;
        }