android.telephony.PhoneNumberFormattingTextWatcher Java Examples

The following examples show how to use android.telephony.PhoneNumberFormattingTextWatcher. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DialerFragment.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mDualPane = getResources().getBoolean(R.bool.use_dual_panes);
    digitFormater = new PhoneNumberFormattingTextWatcher();
    // Auto complete list in case of text
    autoCompleteAdapter = new ContactsSearchAdapter(getActivity());
    autoCompleteListItemListener = new OnAutoCompleteListItemClicked(autoCompleteAdapter);

    if(isDigit == null) {
        isDigit = !prefsWrapper.getPreferenceBooleanValue(SipConfigManager.START_WITH_TEXT_DIALER);
    }
    
    setHasOptionsMenu(true);
}
 
Example #2
Source File: EditorView.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Builds the editor view.
 *
 * @param activity        The activity on top of which the UI should be displayed.
 * @param observerForTest Optional event observer for testing.
 */
public EditorView(Activity activity, PaymentRequestObserverForTest observerForTest) {
    super(activity, R.style.FullscreenWhiteDialog);
    mContext = activity;
    mObserverForTest = observerForTest;
    mHandler = new Handler();
    mPhoneFormatterTask = new AsyncTask<Void, Void, PhoneNumberFormattingTextWatcher>() {
        @Override
        protected PhoneNumberFormattingTextWatcher doInBackground(Void... unused) {
            return new PhoneNumberFormattingTextWatcher();
        }
    }.execute();

    mEditorActionListener = new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                mDoneButton.performClick();
                return true;
            } else if (actionId == EditorInfo.IME_ACTION_NEXT) {
                View next = v.focusSearch(View.FOCUS_FORWARD);
                if (next != null && next instanceof AutoCompleteTextView) {
                    focusInputField(next);
                    return true;
                }
            }
            return false;
        }
    };
}
 
Example #3
Source File: EditorView.java    From delion with Apache License 2.0 5 votes vote down vote up
/** Immediately returns the phone formatter or null if it has not initialized yet. */
private PhoneNumberFormattingTextWatcher getPhoneFormatter() {
    try {
        return mPhoneFormatterTask.get(0, TimeUnit.MILLISECONDS);
    } catch (CancellationException | ExecutionException | InterruptedException
            | TimeoutException e) {
        return null;
    }
}
 
Example #4
Source File: MobileNumberEditText.java    From android-card-form with MIT License 5 votes vote down vote up
private void init() {
    if (isInEditMode()) {
        return;
    }

    setInputType(InputType.TYPE_CLASS_PHONE);
    InputFilter[] filters = { new LengthFilter(14) };
    setFilters(filters);
    addTextChangedListener(new PhoneNumberFormattingTextWatcher());
}
 
Example #5
Source File: AccountAboutYouFragment.java    From arcusandroid with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view =  super.onCreateView(inflater, container, savedInstanceState);

    firstNameField = (Version1EditText) view.findViewById(R.id.fragment_account_name_firstName);
    lastNameField = (Version1EditText) view.findViewById(R.id.fragment_account_name_lastName);
    mobileNumberField = (Version1EditText) view.findViewById(R.id.fragment_account_phone_number);

    // including the "1 " and "-" marks that get added by the PhoneNumberFormattingTextWatcher
    mobileNumberField.setFilters(new InputFilter[]{new InputFilter.LengthFilter(14)});
    mobileNumberField.addTextChangedListener(new PhoneNumberFormattingTextWatcher());

    cameraBtn = (ImageView) view.findViewById(R.id.fragment_account_camera);
    FrameLayout photoLayout = (FrameLayout) view.findViewById(R.id.photo_layout);

    // Initialize the circular image with a person avatar illustration
    ImageManager.with(getActivity())
            .putDrawableResource(R.drawable.image_user)
            .fit()
            .into(cameraBtn)
            .execute();

    photoLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            PersonModel personModel = SessionController.instance().getPerson();
            if (personModel == null) {
                return;
            }

            ImageManager.with(getActivity())
                    .putUserGeneratedPersonImage(personModel.getId())
                    .fromCameraOrGallery()
                    .withTransform(new CropCircleTransformation())
                    .useAsWallpaper(AlphaPreset.LIGHTEN)
                    .into(cameraBtn)
                    .execute();
        }
    });

    DeviceContact contact = getController().getDeviceContact();
    if(contact != null) {
        firstNameField.setText(contact.getFirstName());
        lastNameField.setText(contact.getLastName());
    }

    return view;
}
 
Example #6
Source File: EditorTextField.java    From delion with Apache License 2.0 4 votes vote down vote up
public EditorTextField(Context context, final EditorFieldModel fieldModel,
        OnEditorActionListener actionlistener, PhoneNumberFormattingTextWatcher formatter,
        PaymentRequestObserverForTest observer) {
    super(context);
    assert fieldModel.getInputTypeHint() != EditorFieldModel.INPUT_TYPE_HINT_DROPDOWN;
    mEditorFieldModel = fieldModel;
    mObserverForTest = observer;

    // Build up the label.  Required fields are indicated by appending a '*'.
    CharSequence label = fieldModel.getLabel();
    if (fieldModel.isRequired()) label = label + REQUIRED_FIELD_INDICATOR;
    setHint(label);

    // The EditText becomes a child of this class.  The TextInputLayout manages how it looks.
    LayoutInflater.from(context).inflate(R.layout.payments_request_editor_textview, this, true);
    mInput = (AutoCompleteTextView) findViewById(R.id.text_view);
    mInput.setText(fieldModel.getValue());
    mInput.setOnEditorActionListener(actionlistener);

    // Validate the field when the user de-focuses it.
    mInput.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                mHasFocusedAtLeastOnce = true;
            } else if (mHasFocusedAtLeastOnce) {
                // Show no errors until the user has already tried to edit the field once.
                updateDisplayedError(!mEditorFieldModel.isValid());
            }
        }
    });

    // Update the model as the user edits the field.
    mInput.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            fieldModel.setValue(s.toString());
            updateDisplayedError(false);
            if (mObserverForTest != null) {
                mObserverForTest.onPaymentRequestEditorTextUpdate();
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {}
    });

    // Display any autofill suggestions.
    if (fieldModel.getSuggestions() != null && !fieldModel.getSuggestions().isEmpty()) {
        mInput.setAdapter(new ArrayAdapter<CharSequence>(getContext(),
                android.R.layout.simple_spinner_dropdown_item,
                fieldModel.getSuggestions()));
        mInput.setThreshold(0);
    }

    switch (fieldModel.getInputTypeHint()) {
        case EditorFieldModel.INPUT_TYPE_HINT_PHONE:
            mInput.setInputType(InputType.TYPE_CLASS_PHONE);
            break;
        case EditorFieldModel.INPUT_TYPE_HINT_EMAIL:
            mInput.setInputType(InputType.TYPE_CLASS_TEXT
                    | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
            break;
        case EditorFieldModel.INPUT_TYPE_HINT_STREET_LINES:
            // TODO(rouslan): Provide a hint to the keyboard that the street lines are
            // likely to have numbers.
            mInput.setInputType(InputType.TYPE_CLASS_TEXT
                    | InputType.TYPE_TEXT_FLAG_CAP_WORDS
                    | InputType.TYPE_TEXT_FLAG_MULTI_LINE
                    | InputType.TYPE_TEXT_VARIATION_POSTAL_ADDRESS);
            break;
        case EditorFieldModel.INPUT_TYPE_HINT_PERSON_NAME:
            mInput.setInputType(InputType.TYPE_CLASS_TEXT
                    | InputType.TYPE_TEXT_FLAG_CAP_WORDS
                    | InputType.TYPE_TEXT_VARIATION_PERSON_NAME);
            break;
        case EditorFieldModel.INPUT_TYPE_HINT_REGION:
            mInput.setInputType(InputType.TYPE_CLASS_TEXT
                    | InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS
                    | InputType.TYPE_TEXT_VARIATION_POSTAL_ADDRESS);
            break;
        case EditorFieldModel.INPUT_TYPE_HINT_ALPHA_NUMERIC:
            // Intentionally fall through.
            // TODO(rouslan): Provide a hint to the keyboard that postal code and sorting
            // code are likely to have numbers.
        default:
            mInput.setInputType(InputType.TYPE_CLASS_TEXT
                    | InputType.TYPE_TEXT_FLAG_CAP_WORDS
                    | InputType.TYPE_TEXT_VARIATION_POSTAL_ADDRESS);
            break;
    }
}
 
Example #7
Source File: EditorView.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Builds the editor view.
 *
 * @param activity        The activity on top of which the UI should be displayed.
 * @param observerForTest Optional event observer for testing.
 */
public EditorView(Activity activity, PaymentRequestObserverForTest observerForTest) {
    super(activity, R.style.FullscreenWhite);
    mContext = activity;
    mObserverForTest = observerForTest;
    mHandler = new Handler();
    mEditorActionListener = new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                mDoneButton.performClick();
                return true;
            } else if (actionId == EditorInfo.IME_ACTION_NEXT) {
                View next = v.focusSearch(View.FOCUS_FORWARD);
                if (next != null) {
                    next.requestFocus();
                    return true;
                }
            }
            return false;
        }
    };

    mHalfRowMargin = activity.getResources().getDimensionPixelSize(
            R.dimen.payments_section_large_spacing);
    mFieldViews = new ArrayList<>();
    mEditableTextFields = new ArrayList<>();
    mDropdownFields = new ArrayList<>();

    final Pattern cardNumberPattern = Pattern.compile("^[\\d- ]*$");
    mCardNumberInputFilter = new InputFilter() {
        @Override
        public CharSequence filter(
                CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
            // Accept deletions.
            if (start == end) return null;

            // Accept digits, "-", and spaces.
            if (cardNumberPattern.matcher(source.subSequence(start, end)).matches()) {
                return null;
            }

            // Reject everything else.
            return "";
        }
    };

    mCardNumberFormatter = new CreditCardNumberFormattingTextWatcher();
    new AsyncTask<Void, Void, PhoneNumberFormattingTextWatcher>() {
        @Override
        protected PhoneNumberFormattingTextWatcher doInBackground(Void... unused) {
            return new PhoneNumberFormattingTextWatcher();
        }

        @Override
        protected void onPostExecute(PhoneNumberFormattingTextWatcher result) {
            mPhoneFormatter = result;
            if (mPhoneInput != null) {
                mPhoneInput.addTextChangedListener(mPhoneFormatter);
            }
        }
    }.execute();
}