예제 #1
0
        private void Init()
        {
            base.RemoveAllViews();

            Orientation = Orientation.Vertical;

            View view = Inflate(Context, Resource.Layout.avs, null);

            AddView(view);

            //get the arrays of values from Strings
            postcodeText = Resources.GetStringArray(Resource.Array.avs_countries_postcode_label_text);

            countrySpinner    = view.FindViewById <Spinner> (Resource.Id.countrySpinner);
            postCodeContainer = view.FindViewById(Resource.Id.postCodeContainer);
            postCodeEditText  = view.FindViewById <EditText> (Resource.Id.postCodeEditText);
            postCodeTitleText = view.FindViewById <TextView> (Resource.Id.postCodeTitleText);
            avsMsgText        = view.FindViewById <TextView> (Resource.Id.avsMsgText);

            Typeface type = Typefaces.LoadTypefaceFromRaw(Context, Resource.Raw.courier);

            postCodeEditText.Typeface = type;

            List <string> countries = new List <string> ();

            foreach (BillingCountryOptions option in Enum.GetValues(typeof(BillingCountryOptions)))
            {
                countries.Add(option.ToDescriptionString());
            }

            // Populate country spinner
            ArrayAdapter <string> dataAdapter = new CountryArrayAdapter(Context,
                                                                        Android.Resource.Layout.SimpleSpinnerItem, countries.ToArray(), type);

            dataAdapter.SetDropDownViewResource(Resource.Layout.country_spinner_dropdown_item);
            countrySpinner.Adapter = dataAdapter;

            countrySpinner.ItemSelected += (sender, args) => {
                postCodeTitleText.Text = postcodeText [args.Position];
                postCodeEditText.Hint  = postcodeText [args.Position];
                if (args.Position == 3)
                {
                    postCodeContainer.Visibility = ViewStates.Invisible;
                    avsMsgText.Visibility        = ViewStates.Visible;
                    avsMsgText.BringToFront();
                }
                else
                {
                    postCodeContainer.Visibility = ViewStates.Visible;
                    postCodeContainer.BringToFront();
                    avsMsgText.Visibility = ViewStates.Invisible;
                    if (!Volatile.Read(ref ignoreFocus))
                    {
                        postCodeEditText.RequestFocus();
                    }
                }
            };
        }
예제 #2
0
        public void AddFixedText(string text)
        {
            EditText fixedText = new EditText(Context);

            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent);
            layoutParams.Gravity = GravityFlags.CenterVertical;
            fixedText.SetTextAppearance(Context, Resource.Style.judo_payments_CardText);
            fixedText.LayoutParameters = layoutParams;
            fixedText.Enabled          = false;
            fixedText.Focusable        = false;
            fixedText.Text             = text;
            fixedText.SetBackgroundColor(Resources.GetColor(Android.Resource.Color.Transparent));
            fixedText.SetPadding(0, 0, 0, 0);
            Typeface type = Typefaces.LoadTypefaceFromRaw(Context, Resource.Raw.courier);

            fixedText.Typeface = type;

            if (linearLayout.ChildCount > 1)
            {
                linearLayout.RemoveViewAt(0);
            }
            linearLayout.AddView(fixedText, 0);
        }
예제 #3
0
        private void Init()
        {
            base.RemoveAllViews();

            hintTextView = new EditText(Context);
            textTextView = new NoCursorMovingEditText(Context, BackKeyPressed);

            linearLayout = new LinearLayout(Context);
            linearLayout.LayoutParameters = new ViewGroup.LayoutParams(LinearLayout.LayoutParams.MatchParent, (int)GetContainerHeight());

            textLayout = new RelativeLayout(Context);
            textLayout.LayoutParameters = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MatchParent, 1);
            textLayout.SetGravity(GravityFlags.Center);

            linearLayout.AddView(textLayout);

            textTextView.SetTextAppearance(Context, Resource.Style.judo_payments_CardText);
            hintTextView.SetTextAppearance(Context, Resource.Style.judo_payments_HintText);

            LayoutParams lp = new LayoutParams(LinearLayout.LayoutParams.MatchParent,
                                               LinearLayout.LayoutParams.WrapContent);

            lp.AddRule(LayoutRules.CenterVertical);

            hintTextView.LayoutParameters = lp;
            textTextView.LayoutParameters = lp;
            hintTextView.Enabled          = false;
            hintTextView.Focusable        = false;

            textTextView.InputType = InputTypes.ClassNumber | InputTypes.TextFlagNoSuggestions;
            hintTextView.InputType = InputTypes.ClassNumber | InputTypes.TextFlagNoSuggestions;

            hintTextView.SetBackgroundColor(Resources.GetColor(Android.Resource.Color.Transparent));
            textTextView.SetBackgroundColor(Resources.GetColor(Android.Resource.Color.Transparent));
            int horizontalPadding =
                Resources.GetDimensionPixelOffset(Resource.Dimension.backgroundhinttextview_horizontal_padding);

            hintTextView.SetPadding(horizontalPadding, 0, horizontalPadding, 0);
            textTextView.SetPadding(horizontalPadding, 0, horizontalPadding, 0);

            textErrorView = new EditText(Context);
            RelativeLayout.LayoutParams errorLP = new RelativeLayout.LayoutParams(LayoutParams.MatchParent,
                                                                                  LayoutParams.WrapContent);
            errorLP.AddRule(LayoutRules.CenterVertical);

            int margin = UiUtils.ToPixels(Context, 2);

            errorLP.SetMargins(margin, 0, margin, 0);

            textErrorView.LayoutParameters = errorLP;
            textErrorView.Enabled          = false;
            textErrorView.Focusable        = false;
            textErrorView.Visibility       = ViewStates.Gone;
            textErrorView.SetBackgroundColor(Color.Red);
            int errorVerticalPadding =
                Context.Resources.GetDimensionPixelOffset(
                    Resource.Dimension.backgroundhinttextview_error_vertical_padding);

            textErrorView.SetPadding(horizontalPadding, errorVerticalPadding, horizontalPadding, errorVerticalPadding);
            textErrorView.Text = errorText;
            textErrorView.SetSingleLine(true);
            textErrorView.Gravity = GravityFlags.Center;
            textErrorView.SetTextAppearance(Context, Resource.Style.judo_payments_ErrorText);

            //set courier font
            Typeface type = Typefaces.LoadTypefaceFromRaw(Context, Resource.Raw.courier);

            hintTextView.SetTypeface(Typeface.Monospace, TypefaceStyle.Normal);
            textTextView.SetTypeface(Typeface.Monospace, TypefaceStyle.Normal);
            textErrorView.Typeface = type;


            textLayout.AddView(hintTextView);
            textLayout.AddView(textTextView);

            AddView(linearLayout);

            IEnumerable <char> previousCharSequence;
            EventHandler <TextChangedEventArgs> beforeTextChanged = (sender, args) => {
                previousCharSequence = args.Text;
            };

            EventHandler <TextChangedEventArgs> textChanged = (sender, args) => {
                beforeTextSize = args.BeforeCount;
            };

            EventHandler <AfterTextChangedEventArgs> afterTextChanged = null;


            Action <string> updateTextView = newText => {
                textTextView.TextChanged       -= textChanged;
                textTextView.BeforeTextChanged -= beforeTextChanged;
                textTextView.AfterTextChanged  -= afterTextChanged;

                textTextView.Text = newText;

                textTextView.TextChanged       += textChanged;
                textTextView.BeforeTextChanged += beforeTextChanged;
                textTextView.AfterTextChanged  += afterTextChanged;
            };

            afterTextChanged = (sender, args) => {
                var length   = args.Editable.ToString().Length;
                var deleting = beforeTextSize == 1;

                if (deleting)
                {
                    nextMustBeDeleted = false;
                }
                else
                {
                    if (nextMustBeDeleted && length > 0)
                    {
                        updateTextView(args.Editable.SubSequence(0, length - 1));
                        UpdateHintTextForCurrentTextEntry();
                        return;
                    }
                }

                // If we are deleting (we've just removed a space char, so delete another char please:
                // Or if we've pressed space don't allow it!
                if ((deleting && skipCharsAtPositions.Contains(length)) ||
                    (length > 0 && IsCharInFilter(args.Editable.CharAt(length - 1)) &&
                     !skipCharsAtPositions.Contains(length - 1)))
                {
                    updateTextView(length == 0 ? "" : args.Editable.SubSequence(0, length - 1));
                    textTextView.SetSelection(length == 0 ? 0 : length - 1);
                    UpdateHintTextForCurrentTextEntry();
                    return;
                }

                // Adds a non numeric char at positions needed
                for (int i = 0; i < skipCharsAtPositions.Count; ++i)
                {
                    // We rescan all letters recursively to catch when a users pastes into the edittext
                    int charPosition = skipCharsAtPositions [i];
                    if (length > charPosition)
                    {
                        if (hintText [charPosition] != args.Editable.ToString() [charPosition])
                        {
                            updateTextView(args.Editable.SubSequence(0, charPosition) + "" + hintText [charPosition] +
                                           args.Editable.SubSequence(charPosition, args.Editable.Length()));
                            UpdateHintTextForCurrentTextEntry();
                            return;
                        }
                    }
                    else
                    {
                        if (length == charPosition)
                        {
                            updateTextView(textTextView.Text + "" + hintText [charPosition]);
                        }
                    }
                }

                UpdateHintTextForCurrentTextEntry();

                // We've got all the chars we need, fire off our listener
                if (length >= LengthToStartValidation())
                {
                    try {
                        ValidateInput(args.Editable.ToString());
                        if (OnEntryComplete != null)
                        {
                            OnEntryComplete(args.Editable.ToString());
                        }
                        return;
                    } catch (Exception exception) {
                        Log.Error(JudoSDKManager.DEBUG_TAG, exception.Message, exception);
                    }

                    ShowInvalid();
                }
                else
                {
                    if (OnProgress != null)
                    {
                        OnProgress(length);
                    }
                }
            };

            textTextView.BeforeTextChanged += beforeTextChanged;

            textTextView.TextChanged += textChanged;

            textTextView.AfterTextChanged += afterTextChanged;
        }