コード例 #1
0
        private void CenterSelectedDigit()
        {
            DigitView selected = null;

            for (int i = 0; i < DigitCount; i++)
            {
                selected = (DigitView)_mainLayout.GetChildAt(i);
                if (selected.Selected)
                {
                    break;
                }
                selected = null;
            }

            if (selected != null)
            {
                int width = Resources.DisplayMetrics.WidthPixels / 2;
                this.SmoothScrollTo((int)selected.GetX() - width, (int)selected.GetY());
            }
        }
コード例 #2
0
        private void PinChanging(object sender, TextChangedEventArgs e)
        {
            int length = string.Concat(e.Text).Length;

            for (int i = 0; i < DigitCount; i++)
            {
                DigitView digit = (DigitView)_mainLayout.GetChildAt(i);
                if (length > i)
                {
                    digit.Text = MASK;
                }
                else
                {
                    digit.Text = string.Empty;
                }

                if (_pinInputField.HasFocus || _pinInputField.HasWindowFocus)
                {
                    if (i == length)
                    {
                        digit.Selected = true;
                        CenterSelectedDigit();
                    }
                    else
                    {
                        digit.Selected = false;
                    }
                }
            }

            if (length == DigitCount)
            {
                // Finished
                var handler = PinCompleted;
                handler?.Invoke(this, new PinCompletedEventArgs(_pinInputField.Text));
                PinListener?.PinEntered(_pinInputField.Text);
                _pinInputField.ClearFocus();
                HideKeyboard();
            }
        }
コード例 #3
0
        private void LoadViews()
        {
            if (!ShouldRedraw)
            {
                return;
            }

            var pin = _pinInputField.Text;

            //LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent);
            //layoutParams.Gravity = GravityFlags.Center;

            _mainLayout.RemoveAllViews();
            //_mainLayout.LayoutParameters = layoutParams;
            _mainLayout.SetGravity(GravityFlags.Center);
            _mainLayout.Orientation = Android.Widget.Orientation.Horizontal;

            LinearLayout.LayoutParams digitParams = new LinearLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent);
            digitParams.SetMargins(DigitSpacing / 2, 0, DigitSpacing / 2, 0);
            digitParams.Gravity = GravityFlags.Center;

            // Add a digit view for each digit
            for (int i = 0; i < DigitCount; i++)
            {
                DigitView digitView = new DigitView(Context);
                digitView.LayoutParameters = digitParams;
                digitView.SetWidth(DigitWidth);
                digitView.SetHeight(DigitHeight);

                digitView.Background = SetupDrawable();

                digitView.SetTextColor(TextColor);
                digitView.TextSize = TextSize;
                digitView.Gravity  = GravityFlags.Center;

                if (pin.Length > i)
                {
                    digitView.Text = MASK;
                }
                else if (pin.Length == i)
                {
                    digitView.Selected = true;
                }

                _mainLayout.AddView(digitView);
            }

            _pinInputField.TextSize = 0;
            _pinInputField.SetBackgroundColor(Color.Transparent);
            _pinInputField.SetTextColor(Color.Transparent);
            _pinInputField.SetCursorVisible(false);
            _pinInputField.SetFilters(new IInputFilter[] { new InputFilterLengthFilter((int)DigitCount) });
            _pinInputField.InputType      = InputTypes.ClassNumber;
            _pinInputField.ImeOptions     = (ImeAction)ImeFlags.NoExtractUi;
            _pinInputField.MovementMethod = null;

            _pinInputField.FocusChange -= ViewFocused;
            _pinInputField.FocusChange += ViewFocused;

            _pinInputField.TextChanged -= PinChanging;
            _pinInputField.TextChanged += PinChanging;
        }