public void OnTextChanged(ICharSequence s, int start, int before, int count)
            {
                string value = mEditText.Text.Replace(",", "").Replace("\u20b1", "").Replace(".", "").TrimStart('0');

                if (mIsForPrice & value == "")
                {
                    //disable ok
                    int   colorInt = mContext.GetColor(Resource.Color.jepoyGray);
                    Color color    = new Color(colorInt);
                    mNumpadOk.SetTextColor(color);
                    mNumpadOk.Enabled = false;
                }
                else
                {
                    //enable ok
                    int   colorInt = mContext.GetColor(Resource.Color.colorAccent);
                    Color color    = new Color(colorInt);
                    mNumpadOk.SetTextColor(color);
                    mNumpadOk.Enabled = true;
                }

                decimal ul;

                if (decimal.TryParse(value, out ul))
                {
                    ul /= 100;
                    mEditText.RemoveTextChangedListener(this);
                    mEditText.Text = "\u20b1" + string.Format("{0:n}", ul);
                    mEditText.AddTextChangedListener(this);
                }
            }
        public void OnTextChanged(ICharSequence s, int start, int before, int count)
        {
            if (!s.ToString().Equals(lastAmount))
            {
                string cleanString = clearCurrencyToNumber(s.ToString());
                try
                {
                    string formattedAmount = transformtocurrency(cleanString);
                    editText.RemoveTextChangedListener(this);
                    editText.Text = formattedAmount;
                    editText.SetSelection(formattedAmount.Length);
                    editText.AddTextChangedListener(this);

                    if (lastCursorPosition != lastAmount.Length && lastCursorPosition != -1)
                    {
                        int lengthDelta     = formattedAmount.Length - lastAmount.Length;
                        int newCursorOffset = Java.Lang.Math.Max(0, Java.Lang.Math.Min(formattedAmount.Length, lastCursorPosition + lengthDelta));
                        editText.SetSelection(newCursorOffset);
                    }
                }
                catch (System.Exception e)
                {
                }
            }
            else if (s.ToString() == "")
            {
                return;
            }
        }
Exemplo n.º 3
0
        public override View GetView(Context context, View convertView, ViewGroup parent)
        {
            TextView label;
            var      view = DroidResources.LoadStringEntryLayout(context, convertView, parent, LayoutId, out label, out _entry);

            if (view != null)
            {
                // Warning! Crazy ass hack ahead!
                // since we can't know when out convertedView was was swapped from inside us, we store the
                // old textwatcher in the tag element so it can be removed!!!! (barf, rech, yucky!)
                if (_entry.Tag != null)
                {
                    _entry.RemoveTextChangedListener((ITextWatcher)_entry.Tag);
                }

                _entry.Text = this.Value;
                _entry.Hint = this.Hint;
                //_entry.EditorAction += new EventHandler<TextView.EditorActionEventArgs>(_entry_EditorAction);
                _entry.ImeOptions = ImeAction.Unspecified;

                if (this.Password)
                {
                    _entry.InputType = InputTypes.ClassText | InputTypes.TextVariationPassword;
                }
                else if (this.Numeric)
                {
                    _entry.InputType = InputTypes.ClassNumber | InputTypes.NumberFlagDecimal | InputTypes.NumberFlagSigned;
                }
                else
                {
                    _entry.InputType = InputTypes.ClassText;
                }

                if (Lines > 1)
                {
                    _entry.InputType |= InputTypes.TextFlagMultiLine;
                    _entry.SetLines(Lines);
                }
                else if (Send != null)
                {
                    _entry.ImeOptions = ImeAction.Go;
                    _entry.SetImeActionLabel("Go", ImeAction.Go);
                    _entry.EditorAction += new EventHandler <TextView.EditorActionEventArgs>(_entry_EditorAction);
                }

                // continuation of crazy ass hack, stash away the listener value so we can look it up later
                _entry.Tag = this;
                _entry.AddTextChangedListener(this);
                if (label == null)
                {
                    _entry.Hint = Caption;
                }
                else
                {
                    label.Text = Caption;
                }
            }

            return(view);
        }
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         EditText?.RemoveTextChangedListener(this);
     }
     base.Dispose(disposing);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Ons the text changed.
 /// </summary>
 /// <param name="s">S.</param>
 /// <param name="start">Start.</param>
 /// <param name="before">Before.</param>
 /// <param name="count">Count.</param>
 public void OnTextChanged(ICharSequence s, int start, int before, int count)
 {
     if (tipoFormateador == TIPO_PESO_KG)
     {
         textoFormateado = MascarasEditText.formatearMonto(editText.Text);
         editText.RemoveTextChangedListener(this);
         editText.Text = textoFormateado;
         editText.AddTextChangedListener(this);
         editText.SetSelection(editText.Text.Length);
         editText.SetCursorVisible(true);
     }
 }
            public void OnTextChanged(ICharSequence s, int start, int before, int count)
            {
                mIsCashDiscountSelected = GlobalVariables.mIsCashDiscountSelected;

                string value = mIsCashDiscountSelected ? mEditText.Text.Replace(",", "").Replace("\u20b1", "").Replace(".", "").TrimStart('0') :
                               mEditText.Text.Replace(",", "").Replace("%", "").Replace(".", "").TrimStart('0');

                decimal ul;

                if (decimal.TryParse(value, out ul))
                {
                    ul /= 100;
                    mEditText.RemoveTextChangedListener(this);
                    if (mIsCashDiscountSelected)
                    {
                        if (ul >= currentOriginalSubtotal)
                        {
                            ul = currentOriginalSubtotal;
                        }
                        mEditText.Text = "\u20b1" + string.Format("{0:n}", ul);
                    }
                    else
                    {
                        if (ul >= 100)
                        {
                            ul = 100;
                        }
                        mEditText.Text = string.Format("{0:n}", ul) + "%";
                    }

                    mEditText.AddTextChangedListener(this);
                }
                if (ul == 0)
                {
                    mTxtOrigPrice.Visibility = ViewStates.Invisible;
                }
                else
                {
                    mTxtOrigPrice.Visibility = ViewStates.Visible;
                }
                if (mIsCashDiscountSelected)
                {
                    mEtPercentageDiscount.Text = string.Format("{0:n}", GetPercentageDiscount(ul, currentOriginalSubtotal)) + "%";
                    mTxtDiscountedPrice.Text   = "\u20b1" + string.Format("{0:n}", (currentOriginalSubtotal - ul));
                }
                else
                {
                    mEtCashDiscount.Text = "\u20b1" + string.Format("{0:n}", GetCashDiscount(ul, currentOriginalSubtotal));
                    decimal cashDiscountAmtmEtCashDiscount = Convert.ToDecimal(mEtCashDiscount.Text.Replace("\u20b1", ""));
                    mTxtDiscountedPrice.Text = "\u20b1" + string.Format("{0:n}", (currentOriginalSubtotal - cashDiscountAmtmEtCashDiscount));
                }
            }
Exemplo n.º 7
0
        public void OnTextChanged(ICharSequence s, int start, int before, int count)
        {
            string rawString;
            string firstString = "";

            try
            {
                firstString = s.ToString().Substring(0, 1);
            }
            catch (System.Exception)
            {
                firstString = "";
            }

            if (firstString != mCurrencySign)
            {
                try
                {
                    rawString = s.ToString().Substring(1, s.ToString().Length - 1);
                }
                catch (System.Exception)
                {
                    rawString = s.ToString();
                }
            }
            else
            {
                rawString = s.ToString();
            }
            if (s.ToString() == mCurrencySign + " 0.0")
            {
                mEditText.Text = mCurrencySign + " 0.00";
                mEditText.SetSelection(mEditText.Text.Length);
            }
            string  value  = rawString.Replace(" ", "").Replace(",", "").Replace(mCurrencySign, "").Replace(".", "").TrimStart('0');
            string  value2 = value == "" ? "0" : value;
            decimal ul;

            if (decimal.TryParse(value2, out ul))
            {
                ul /= 100;
                mEditText.RemoveTextChangedListener(this);
                string formatted = mCurrencySign + " " + string.Format("{0:n}", ul);
                mEditText.Text = formatted;
                mEditText.SetSelection(formatted.Length);
                mEditText.AddTextChangedListener(this);
            }
        }
Exemplo n.º 8
0
        public override View GetView(Context context, View convertView, ViewGroup parent)
        {
            Log.Debug("MDD", "EntryElement: GetView: ConvertView: " + ((convertView == null) ? "false" : "true") +
                      " Value: " + Value + " Hint: " + Hint + " Password: "******"true" : "false"));


            TextView label;
            var      view = DroidResources.LoadStringEntryLayout(context, convertView, parent, LayoutId, out label, out _entry);

            if (view != null)
            {
                // Warning! Crazy ass hack ahead!
                // since we can't know when out convertedView was was swapped from inside us, we store the
                // old textwatcher in the tag element so it can be removed!!!! (barf, rech, yucky!)
                if (_entry.Tag != null)
                {
                    _entry.RemoveTextChangedListener((ITextWatcher)_entry.Tag);
                }

                _entry.Text = this.Value;
                _entry.Hint = this.Hint;
                _entry.LayoutParameters.Width = this.Width;

                if (this.Password)
                {
                    _entry.InputType = (InputTypes.ClassText | InputTypes.TextVariationPassword);
                }
                else if (this.Numeric)
                {
                    _entry.InputType = (InputTypes.ClassNumber | InputTypes.NumberFlagDecimal | InputTypes.NumberFlagSigned);
                }
                else
                {
                    _entry.InputType = InputTypes.ClassText;
                }

                _entry.Enabled = this.Enabled;

                // continuation of crazy ass hack, stash away the listener value so we can look it up later
                _entry.Tag = this;
                _entry.AddTextChangedListener(this);

                label.Text = (label != null) ? Caption: string.Empty;
            }
            return(view);
        }
Exemplo n.º 9
0
        public override View GetView(Context context, View convertView, ViewGroup parent)
        {
            TextView label;
            var      view = DroidResources.LoadStringEntryLayout(context, convertView, parent, LayoutId, out label, out _entry);

            if (view != null)
            {
                view.FocusableInTouchMode = false;
                view.Focusable            = false;
                view.Clickable            = false;

                _entry.FocusableInTouchMode = true;
                _entry.Focusable            = true;
                _entry.Clickable            = true;

                _entry.Text = Value;
                _entry.Hint = Hint;

                _entry.InputType = KeyboardType.InputTypesFromUIKeyboardType();

                if (Password)
                {
                    _entry.InputType |= InputTypes.TextVariationPassword;
                }

                if (Lines > 1)
                {
                    _entry.InputType |= InputTypes.TextFlagMultiLine;
                    _entry.SetLines(Lines);
                }
                else if (Send != null)
                {
                    _entry.ImeOptions = ImeAction.Go;
                    _entry.SetImeActionLabel("Go", ImeAction.Go);
                }
                else
                {
                    _entry.ImeOptions = ReturnKeyType.ImeActionFromUIReturnKeyType();
                }

                if (_entry.Tag == null)
                {
                    _entry.Tag = this;
                    _entry.AddTextChangedListener(this);
                }
                else if (_entry.Tag != this)
                {
                    _entry.RemoveTextChangedListener((ITextWatcher)_entry.Tag);
                    _entry.AddTextChangedListener(this);
                    if (Send != null)
                    {
                        _entry.EditorAction += _entry_EditorAction;
                    }
                }

                _entry.OnFocusChangeListener = this;

                if (label == null)
                {
                    _entry.Hint = Caption;
                }
                else
                {
                    label.Text = Caption;
                }
            }

            return(view);
        }
Exemplo n.º 10
0
        public void OnTextChanged(ICharSequence s, int start, int before, int count)
        {
            if (tipoFormateador == TIPO_RUT)
            {
                textoFormateado = MascarasEditText.formatearRut(editText.Text);
                editText.RemoveTextChangedListener(this); // removemos el lister para no caer en loop infinito.
                editText.Text = textoFormateado;
                editText.AddTextChangedListener(this);
                editText.SetSelection(editText.Text.Length);
                // editText.SetRawInputType(InputTypes.NumberVariationNormal);
                //editText.InputType = Android.Text.InputTypes.TextVariationPassword; //| Android.Text.InputTypes.ClassNumber;
                editText.SetCursorVisible(true);
            }
            else if (tipoFormateador == TIPO_MONTO_PESOS)
            {
                textoFormateado = MascarasEditText.formatearMonto(editText.Text);
                editText.RemoveTextChangedListener(this); // removemos el lister para no caer en loop infinito.
                editText.Text = textoFormateado;
                editText.AddTextChangedListener(this);
                editText.SetSelection(editText.Text.Length);
                // editText.SetRawInputType(InputTypes.NumberVariationNormal);
                //editText.InputType = Android.Text.InputTypes.TextVariationPassword; //| Android.Text.InputTypes.ClassNumber;
                editText.SetCursorVisible(true);
            }
            else if (tipoFormateador == TIPO_MONTO_USD)
            {
                string dolar = editText.Text;
                if (dolar.Equals("0.0"))
                {
                    dolar = "0,00";
                }
                dolar = dolar.Replace(",", "");
                if (dolar.Trim().Length >= 3)
                {
                    dolar = dolar.Replace(".0", "");
                    int    tam_var      = dolar.Length;
                    string decimalDolar = dolar.Substring((tam_var - 2), 2);
                    dolar             = dolar.Replace(dolar.Substring((tam_var - 2), 2), "");
                    dolar             = dolar + "," + decimalDolar;
                    montoDolar        = dolar.Split(',');
                    montoDolarEntero  = montoDolar[0];
                    montoDolarDecimal = montoDolar[1];
                    if (!dolar.Contains(","))
                    {
                        montoDolarEntero = dolar;
                    }
                }
                else if (dolar.Trim().Length == 2)
                {
                    dolar = dolar.Replace(".0", "");
                    dolar = dolar.Replace(",", "");
                    int    tam_var      = dolar.Length;
                    string decimalDolar = dolar.Substring((tam_var - 1), 1);
                    dolar             = dolar.Replace(dolar.Substring((tam_var - 1), 1), "");
                    dolar             = dolar + "," + decimalDolar;
                    montoDolar        = dolar.Split(',');
                    montoDolarEntero  = montoDolar[0];
                    montoDolarDecimal = montoDolar[1];
                    if (!dolar.Contains(","))
                    {
                        montoDolarEntero = dolar;
                    }
                }
                else if (dolar.Trim().Length == 1)
                {
                    montoDolarDecimal = string.Empty;
                    dolar             = dolar.Replace(",", "");
                    dolar             = dolar + string.Empty;
                    if (!dolar.Contains(","))
                    {
                        montoDolarEntero = dolar;
                    }
                }
                else if (dolar.Trim().Length == 0)
                {
                    montoDolarEntero = string.Empty;
                    dolar            = dolar + string.Empty;
                    if (!dolar.Contains(","))
                    {
                        montoDolarEntero = dolar;
                    }
                }
                textoFormateado = MascarasEditText.formatearMontoDolar(montoDolarEntero, montoDolarDecimal);
                editText.RemoveTextChangedListener(this); // removemos el lister para no caer en loop infinito.
                editText.Text = textoFormateado;

                string   editTextFormateado = editText.Text;
                string[] div;
                string   montoDolarEnt = string.Empty;
                string   montoDolarDec = string.Empty;
                editText.AddTextChangedListener(this);
                div           = editTextFormateado.Split(',');
                montoDolarEnt = div[0];
                montoDolarDec = div[1];
                editText.SetSelection(editText.Text.Length);
                if (montoDolarDec.Trim().Length >= 3)
                {
                    editText.SetSelection(editText.Text.Length - 3);
                }
                // editText.SetRawInputType(InputTypes.NumberVariationNormal);
                //editText.InputType = Android.Text.InputTypes.TextVariationPassword; //| Android.Text.InputTypes.ClassNumber;
                editText.SetCursorVisible(true);
            }
        }