Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
adding new project description
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonardo Javier Esparis Meza committed Mar 25, 2017
1 parent 99d6188 commit 1dd8d82
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PhoneEditText [![](https://jitpack.io/v/leoxnidas/PhoneEditText.svg)](https://jitpack.io/#leoxnidas/PhoneEditText) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-PhoneEditText-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/5310) [![API](https://img.shields.io/badge/API-15%2B-blue.svg?style=flat)](https://android-arsenal.com/api?level=15)
-------------
special phoneedittext library that allows you to have internationals phone codes in a simple edittext, all international phone codes came from [https://countrycode.org/](https://countrycode.org/)
simple android library that allows you to have internationals phone codes in a simple edittext, all international phone codes came from [https://countrycode.org/](https://countrycode.org/)


Usage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ public void setCode(int code) {
if(Codes.isCodeValid(code)) {
p_mCode = code;
p_mCodeStr = Codes.asString(code);
setText((PLUS + p_mCodeStr));

if(getText().toString().length() > p_mCodeStr.length())
setText((PLUS + p_mCodeStr));
else
setHint((PLUS + p_mCodeStr));

Selection.setSelection(getText(), getText().toString().length());
} else {
throw new RuntimeException("International code does not exists.");
Expand All @@ -84,6 +89,8 @@ public void addTextChangedListener(TextWatcher watcher) {

private class PhoneEditTextWatcher implements TextWatcher {

private int p_mLastLenght = 0;

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

Expand Down Expand Up @@ -135,13 +142,18 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {

@Override
public void afterTextChanged(Editable s) {
if(s.length() < (1 + p_mCodeStr.length())) {
setText((PLUS + p_mCodeStr));
Selection.setSelection(getText(), (PLUS + p_mCodeStr).length());
}
if(s.length() == (PLUS + p_mCodeStr).length() - 1
&& p_mLastLenght > (PLUS + p_mCodeStr).length() - 1) {
setText("");

} else {
p_mLastLenght = s.length();

if(getSelectionStart() <= p_mCodeStr.length() - 1)
Selection.setSelection(s, s.length());
if(p_mLastLenght == 1) {
setText((PLUS + p_mCodeStr + s.toString()));
Selection.setSelection(getText(), getText().length());
}
}
}
}

Expand Down

0 comments on commit 1dd8d82

Please sign in to comment.