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

Commit

Permalink
now when nothing is inside a edittext, hint should be there the inste…
Browse files Browse the repository at this point in the history
…ad a text, when users delete all the phone number, international code text should be replaced with a international code hint
  • Loading branch information
Leonardo Javier Esparis Meza committed Mar 25, 2017
1 parent 1dd8d82 commit f7953b5
Showing 1 changed file with 21 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,64 +96,45 @@ public void beforeTextChanged(CharSequence s, int start, int count, int after) {

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// if user intent to write a number
// at international code space,
// that number shall be added next
// to the international code
// of the string, automatically
//
// Example:
//
// user intents to write this
//
// ---------------
// | +518 |
// --------------
//
// and the result shall be this
//
// ---------------
// | +581 |
// --------------
//
String currentText = s.toString();
int currentLength = currentText.length();

String code = PLUS + p_mCodeStr;
int codeLength = code.length();

if(currentLength < codeLength)
return;

for(int i = 0; i < codeLength; i++) {
if(currentText.charAt(i) != code.charAt(i)) {
String nCode = code;

for(int j = codeLength + 1; j < currentLength; j++) {
nCode += Character.toString(currentText.charAt(j));
if(currentLength < codeLength && p_mLastLenght == 0) {
setText((code + s));
} else {
try {
for(int i = 0; i < codeLength; i++) {
if(currentText.charAt(i) != code.charAt(i)) {
String nCode = code;

for(int j = codeLength + 1; j < currentLength; j++) {
nCode += Character.toString(currentText.charAt(j));
}

setText(nCode);
Selection.setSelection(getText(), i);
break;
}
}
} catch (StringIndexOutOfBoundsException ignored) {

nCode += Character.toString(currentText.charAt(i));
setText(nCode);
break;
}
}
}

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

} else {
p_mLastLenght = s.length();
if(p_mLastLenght <= (PLUS + p_mCodeStr).length())
Selection.setSelection(getText(), getText().length());

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

Expand Down

0 comments on commit f7953b5

Please sign in to comment.