Package com.google.i18n.phonenumbers
Class AsYouTypeFormatter
java.lang.Object
com.google.i18n.phonenumbers.AsYouTypeFormatter
A formatter which formats phone numbers as they are entered.
An AsYouTypeFormatter can be created by invoking
PhoneNumberUtil.getAsYouTypeFormatter(java.lang.String)
. After that, digits can be added by invoking
inputDigit(char)
on the formatter instance, and the partially formatted phone number will be
returned each time a digit is added. clear()
can be invoked before formatting a new
number.
See the unittests for more details on how the formatter is to be used.
- Author:
- Shaopeng Jia
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears the internal state of the formatter, so it can be reused.int
Returns the current position in the partially formatted phone number of the character which was previously passed in as the parameter ofinputDigitAndRememberPosition(char)
.inputDigit
(char nextChar) Formats a phone number on-the-fly as each digit is entered.inputDigitAndRememberPosition
(char nextChar) Same asinputDigit(char)
, but remembers the position wherenextChar
is inserted, so that it can be retrieved later by usinggetRememberedPosition()
.
-
Method Details
-
clear
public void clear()Clears the internal state of the formatter, so it can be reused. -
inputDigit
Formats a phone number on-the-fly as each digit is entered.- Parameters:
nextChar
- the most recently entered digit of a phone number. Formatting characters are allowed, but as soon as they are encountered this method formats the number as entered and not "as you type" anymore. Full width digits and Arabic-indic digits are allowed, and will be shown as they are.- Returns:
- the partially formatted phone number.
-
inputDigitAndRememberPosition
Same asinputDigit(char)
, but remembers the position wherenextChar
is inserted, so that it can be retrieved later by usinggetRememberedPosition()
. The remembered position will be automatically adjusted if additional formatting characters are later inserted/removed in front ofnextChar
. -
getRememberedPosition
public int getRememberedPosition()Returns the current position in the partially formatted phone number of the character which was previously passed in as the parameter ofinputDigitAndRememberPosition(char)
.
-