Class PhoneNumberFormattingTextWatcher

  • All Implemented Interfaces:
    android.text.NoCopySpan, android.text.TextWatcher

    public class PhoneNumberFormattingTextWatcher
    extends java.lang.Object
    implements android.text.TextWatcher
    A TextWatcher used for formatting the phone number.
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface android.text.NoCopySpan

        android.text.NoCopySpan.Concrete
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void afterTextChanged​(android.text.Editable s)
      Called whenever a phone numbe has been changed somewhere in the EditText.
      void beforeTextChanged​(java.lang.CharSequence s, int start, int count, int after)
      Called when the phone number is about to be changed with a new number.
      void onTextChanged​(java.lang.CharSequence s, int cursorPosition, int before, int count)
      Called whenever a phone number is changed in the EditText.
      static java.lang.String removeCharAt​(java.lang.String s, int pos, int length)
      Removes the character at the specified position.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PhoneNumberFormattingTextWatcher

        public PhoneNumberFormattingTextWatcher​(android.widget.EditText edTxtPhone)
        Parameters:
        edTxtPhone - the EditText being observed.
    • Method Detail

      • onTextChanged

        public void onTextChanged​(java.lang.CharSequence s,
                                  int cursorPosition,
                                  int before,
                                  int count)
        Called whenever a phone number is changed in the EditText.
        Specified by:
        onTextChanged in interface android.text.TextWatcher
        Parameters:
        s - character sequence
        cursorPosition - current position
        before - length of old text
        count - number of characters
      • beforeTextChanged

        public void beforeTextChanged​(java.lang.CharSequence s,
                                      int start,
                                      int count,
                                      int after)
        Called when the phone number is about to be changed with a new number.
        Specified by:
        beforeTextChanged in interface android.text.TextWatcher
        Parameters:
        s - character sequence
        start - starting position
        count - number of characters
        after - new text length
      • afterTextChanged

        public void afterTextChanged​(android.text.Editable s)
        Called whenever a phone numbe has been changed somewhere in the EditText.
        Specified by:
        afterTextChanged in interface android.text.TextWatcher
        Parameters:
        s - character sequence
      • removeCharAt

        public static java.lang.String removeCharAt​(java.lang.String s,
                                                    int pos,
                                                    int length)
        Removes the character at the specified position.
        Parameters:
        s - character sequence
        pos - position
        length - length of string
        Returns:
        modified string with removed character