Preyea Regmi
4 years ago
15 changed files with 544 additions and 494 deletions
-
BIN.idea/caches/build_file_checksums.ser
-
1SpinnerDatePickerLib-release/build/.transforms/4647f6ab949e605a829eced215dd9825.bin
-
BINSpinnerDatePickerLib-release/build/.transforms/4647f6ab949e605a829eced215dd9825/SpinnerDatePickerLib-release-runtime/classes.dex
-
136app/src/main/java/com/gmeremit/online/gmeremittance_native/common/view/MTextInputMaskedEditText.java
-
185app/src/main/java/com/gmeremit/online/gmeremittance_native/common/view/MaskedTextWatcher.java
-
5app/src/main/java/com/gmeremit/online/gmeremittance_native/common/view/ValueListener.java
-
4app/src/main/java/com/gmeremit/online/gmeremittance_native/customwidgets/maskedittext/MaskedTextWatcher.java
-
57app/src/main/java/com/gmeremit/online/gmeremittance_native/kycV3/view/personal/CustomerDetailFragment.java
-
2app/src/main/java/com/gmeremit/online/gmeremittance_native/loginV2/presenter/LoginV2Presenter.java
-
5app/src/main/res/color/textinput_hint_color.xml
-
600app/src/main/res/layout/fragment_kyc_customer_detail.xml
-
9app/src/main/res/layout/fragment_kyc_document.xml
-
11app/src/main/res/values/attrs.xml
-
4app/src/main/res/values/colors.xml
-
19app/src/main/res/values/styles.xml
@ -0,0 +1 @@ |
|||
o/SpinnerDatePickerLib-release-runtime |
@ -0,0 +1,136 @@ |
|||
package com.gmeremit.online.gmeremittance_native.common.view; |
|||
|
|||
import android.content.Context; |
|||
import android.content.res.TypedArray; |
|||
import android.text.InputFilter; |
|||
import android.text.InputType; |
|||
import android.util.AttributeSet; |
|||
import android.util.TypedValue; |
|||
|
|||
import com.gmeremit.online.gmeremittance_native.R; |
|||
import com.gmeremit.online.gmeremittance_native.customwidgets.FontCache; |
|||
import com.gmeremit.online.gmeremittance_native.customwidgets.GmeEditText; |
|||
import com.gmeremit.online.gmeremittance_native.customwidgets.maskedittext.GmeMaskedEditText; |
|||
import com.google.android.material.textfield.TextInputEditText; |
|||
|
|||
public class MTextInputMaskedEditText extends TextInputEditText { |
|||
|
|||
|
|||
private MaskedTextWatcher maskedTextWatcher; |
|||
private int maskingType = 0; |
|||
private String prefixText = ""; |
|||
private boolean isAlphaNumeric = true; |
|||
private GmeMaskedEditText.ValueListener valueListener; |
|||
|
|||
public MTextInputMaskedEditText(Context context) { |
|||
super(context); |
|||
init(context, null); |
|||
} |
|||
|
|||
public MTextInputMaskedEditText(Context context, AttributeSet attrs) { |
|||
super(context, attrs); |
|||
init(context, attrs); |
|||
} |
|||
|
|||
public MTextInputMaskedEditText(Context context, AttributeSet attrs, int defStyleAttr) { |
|||
super(context, attrs, defStyleAttr); |
|||
init(context, attrs); |
|||
} |
|||
|
|||
private void init(Context context, AttributeSet attrs) { |
|||
if (attrs != null) { |
|||
|
|||
TypedArray a = null; |
|||
|
|||
try { |
|||
a = getContext().obtainStyledAttributes(attrs, R.styleable.MTextInputMaskedEditText); |
|||
String fontName = a.getString(R.styleable.MTextInputMaskedEditText_maskedEdTxtFontName); |
|||
setTypeface(FontCache.getTypeface(fontName, context)); |
|||
|
|||
TypedValue outValue = new TypedValue(); |
|||
boolean result = a.getValue(R.styleable.GMEMaskedEditText_textType, outValue); |
|||
if (result) { |
|||
maskingType = outValue.data; |
|||
prefixText = a.getString(R.styleable.GMEMaskedEditText_prefixText); |
|||
if (prefixText == null) |
|||
prefixText = ""; |
|||
setupMasking(); |
|||
|
|||
} |
|||
|
|||
} catch (Exception e) { |
|||
|
|||
} finally { |
|||
if (a != null) |
|||
a.recycle(); |
|||
|
|||
} |
|||
} |
|||
} |
|||
|
|||
public void setMaskingType(int value) { |
|||
maskingType = value; |
|||
setupMasking(); |
|||
} |
|||
|
|||
private void setupMasking() { |
|||
String phoneMask = ""; |
|||
switch (maskingType) { |
|||
|
|||
|
|||
case 0: |
|||
isAlphaNumeric = true; |
|||
setInputType(InputType.TYPE_CLASS_TEXT); |
|||
setFilters(new InputFilter[]{new GmeEditText.RegExInputFilter("^[a-zA-Z0-9]+$"), new InputFilter.LengthFilter(50)}); |
|||
if (maskedTextWatcher != null) |
|||
removeTextChangedListener(maskedTextWatcher); |
|||
maskedTextWatcher=null; |
|||
break; |
|||
|
|||
case 1: |
|||
if (prefixText.length() > 0) |
|||
phoneMask = "-######-#######"; |
|||
else |
|||
phoneMask = "######-#######"; |
|||
isAlphaNumeric = false; |
|||
setInputType(InputType.TYPE_CLASS_PHONE); |
|||
if (maskedTextWatcher != null) |
|||
removeTextChangedListener(maskedTextWatcher); |
|||
maskedTextWatcher = new MaskedTextWatcher(phoneMask, prefixText, "#", this, isAlphaNumeric); |
|||
addTextChangedListener(maskedTextWatcher); |
|||
setFilters(new InputFilter[]{ new InputFilter.LengthFilter(14)}); |
|||
// maskedTextWatcher.setValueListener(valueListener); |
|||
break; |
|||
|
|||
case 2: |
|||
if (prefixText.length() > 0) |
|||
phoneMask = "-####-#####"; |
|||
else |
|||
phoneMask = "###-####-#####"; |
|||
isAlphaNumeric = false; |
|||
setInputType(InputType.TYPE_CLASS_PHONE); |
|||
if (maskedTextWatcher != null) |
|||
removeTextChangedListener(maskedTextWatcher); |
|||
maskedTextWatcher = new MaskedTextWatcher(phoneMask, prefixText, "#", this, isAlphaNumeric); |
|||
addTextChangedListener(maskedTextWatcher); |
|||
setFilters(new InputFilter[]{ new InputFilter.LengthFilter(13)}); |
|||
break; |
|||
|
|||
default: |
|||
isAlphaNumeric = true; |
|||
setInputType(InputType.TYPE_CLASS_TEXT); |
|||
if (maskedTextWatcher != null) |
|||
removeTextChangedListener(maskedTextWatcher); |
|||
maskedTextWatcher=null; |
|||
break; |
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
|
|||
public void setValueListener(ValueListener listener, boolean truncatePrefix) { |
|||
maskedTextWatcher.setValueListener(listener,truncatePrefix); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,185 @@ |
|||
package com.gmeremit.online.gmeremittance_native.common.view; |
|||
|
|||
import android.text.Editable; |
|||
import android.text.TextWatcher; |
|||
import android.widget.EditText; |
|||
import android.widget.TextView; |
|||
|
|||
import com.gmeremit.online.gmeremittance_native.customwidgets.maskedittext.GmeMaskedEditText; |
|||
|
|||
import java.util.LinkedList; |
|||
import java.util.Queue; |
|||
import java.util.regex.Matcher; |
|||
import java.util.regex.Pattern; |
|||
|
|||
class MaskedTextWatcher implements TextWatcher { |
|||
|
|||
private final String maskString; |
|||
private final String prefixText; |
|||
private static boolean isAlphaNumeric; |
|||
private ValueListener valueListener; |
|||
private final Pattern maskPattern; |
|||
private final EditText editText; |
|||
private boolean shouldTruncatePrefix; |
|||
|
|||
MaskedTextWatcher(String maskString, String prefixText, String maskSymbol, EditText editText, boolean isAlphaNumeric) { |
|||
this.maskString = maskString; |
|||
this.prefixText = prefixText; |
|||
this.maskPattern = Pattern.compile(maskSymbol); |
|||
this.editText = editText; |
|||
this.valueListener = null; |
|||
this.isAlphaNumeric = isAlphaNumeric; |
|||
} |
|||
|
|||
public void setValueListener(ValueListener listener,boolean shouldTruncatePrefix) { |
|||
this.valueListener = listener; |
|||
this.shouldTruncatePrefix=shouldTruncatePrefix; |
|||
} |
|||
|
|||
private String result = ""; |
|||
private EditState state = EditState.IDLE; |
|||
private Integer cursorPosition; |
|||
private Integer cursorShifting; |
|||
|
|||
private String phoneString = ""; |
|||
|
|||
@Override |
|||
public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
|||
if (state == EditState.IDLE) { |
|||
cursorShifting = s.length(); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void onTextChanged(CharSequence s, int start, int before, int count) { |
|||
|
|||
} |
|||
|
|||
|
|||
@Override |
|||
public void afterTextChanged(Editable s) { |
|||
final String value = s.toString(); |
|||
if (state == EditState.RELEASE) { |
|||
cursorShifting = s.length() - cursorShifting; |
|||
cursorPosition = cursorPosition + cursorShifting; |
|||
if (cursorShifting > 0) { |
|||
if (cursorPosition < value.length()) { |
|||
cursorPosition--; |
|||
if (isAlphaNumeric && !Character.isLetterOrDigit(value.charAt(cursorPosition))) { |
|||
cursorPosition++; |
|||
} |
|||
if (!isAlphaNumeric && !Character.isDigit(value.charAt(cursorPosition))) { |
|||
cursorPosition++; |
|||
} |
|||
} |
|||
|
|||
} else { |
|||
cursorPosition++; |
|||
} |
|||
|
|||
editText.setSelection(Math.max(0, Math.min(cursorPosition, value.length()))); |
|||
|
|||
state = EditState.IDLE; |
|||
return; |
|||
} |
|||
|
|||
if (state == EditState.IDLE) { |
|||
if (s.toString().isEmpty()) { |
|||
phoneString = ""; |
|||
cursorPosition = 0; |
|||
return; |
|||
} |
|||
|
|||
cursorPosition = editText.getSelectionStart(); |
|||
|
|||
String rawString = value.replace(prefixText, ""); |
|||
//Raw string contains the character input from user. |
|||
rawString = getRegExPattern().matcher(rawString).replaceAll(""); |
|||
Queue<Character> charsQueue = new LinkedList<>(); |
|||
for (char c : rawString.toCharArray()) { |
|||
charsQueue.add(c); |
|||
} |
|||
|
|||
//Build masked text for display. |
|||
StringBuilder rawMaskBuilder = new StringBuilder(prefixText + maskString); |
|||
Matcher matcher = maskPattern.matcher(prefixText + maskString); |
|||
while (matcher.find()) { |
|||
int start = matcher.start(); |
|||
if (!charsQueue.isEmpty()) { |
|||
rawMaskBuilder.replace(start, start + 1, charsQueue.poll().toString()); |
|||
if (charsQueue.isEmpty()) { |
|||
result = rawMaskBuilder.substring(0, start + 1); |
|||
break; |
|||
} |
|||
} else { |
|||
result = rawMaskBuilder.substring(0, start); |
|||
break; |
|||
} |
|||
} |
|||
|
|||
//Prepare to send to the listener the raw data that user has entered. |
|||
String data = getRegExPattern().matcher(rawMaskBuilder.toString()).replaceAll(""); |
|||
|
|||
if (valueListener != null) { |
|||
if (prefixText.length() > 0) { |
|||
if(shouldTruncatePrefix) |
|||
valueListener.onValueChanged(data.substring(prefixText.length() - 1)); |
|||
else |
|||
valueListener.onValueChanged(data); |
|||
} |
|||
else |
|||
valueListener.onValueChanged(data); |
|||
} |
|||
state = EditState.EDIT; |
|||
} |
|||
|
|||
switch (state) { |
|||
case EDIT: |
|||
state = EditState.CLEAR; |
|||
s.clear(); |
|||
break; |
|||
case CLEAR: |
|||
state = EditState.RELEASE; |
|||
s.append(result, 0, result.length()); |
|||
break; |
|||
default: |
|||
break; |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Experimental. |
|||
* |
|||
* @param editText |
|||
* @param mask |
|||
*/ |
|||
@Deprecated |
|||
public static void validatePresetup(TextView editText, String mask) { |
|||
//Check setOnFocusChangeListener |
|||
if (editText.getOnFocusChangeListener() != null) { |
|||
throw new RuntimeException("If you wanna to use OnFocusChangeListener add it through withOnFocusChangeListener() method"); |
|||
} |
|||
//Check maskString |
|||
if (mask == null) { |
|||
throw new RuntimeException("Mask can't be null"); |
|||
} |
|||
|
|||
} |
|||
|
|||
private static Pattern getRegExPattern() { |
|||
if (MaskedTextWatcher.isAlphaNumeric) |
|||
return Pattern.compile("[^[a-zA-Z0-9]*$]"); |
|||
else |
|||
return Pattern.compile("[^\\d]+"); |
|||
|
|||
} |
|||
|
|||
public String getPhone() { |
|||
return phoneString; |
|||
} |
|||
|
|||
enum EditState { |
|||
IDLE, EDIT, CLEAR, RELEASE |
|||
} |
|||
} |
@ -0,0 +1,5 @@ |
|||
package com.gmeremit.online.gmeremittance_native.common.view; |
|||
|
|||
public interface ValueListener { |
|||
void onValueChanged(String value); |
|||
} |
@ -0,0 +1,5 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> |
|||
<item android:state_focused="true" android:color="@color/hint_color_active"/> |
|||
<item android:color="@color/hint_color_inactive"/> |
|||
</selector> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue