158 lines
4.7 KiB
Java
158 lines
4.7 KiB
Java
|
package com.scb.phone.view.custom.common;
|
||
|
|
||
|
import android.content.Context;
|
||
|
import android.graphics.Rect;
|
||
|
import android.text.InputFilter;
|
||
|
import android.text.TextUtils;
|
||
|
import android.util.AttributeSet;
|
||
|
import android.view.KeyEvent;
|
||
|
import android.widget.TextView;
|
||
|
import com.google.android.material.textfield.TextInputEditText;
|
||
|
import com.google.android.material.textfield.TextInputLayout;
|
||
|
import com.scb.phone.R;
|
||
|
import com.scb.phone.view.custom.common.UnitsEditText;
|
||
|
import java.math.BigDecimal;
|
||
|
import o.C10398eCy;
|
||
|
import o.C6583cXR;
|
||
|
import o.fLX;
|
||
|
import o.fLY;
|
||
|
|
||
|
/* loaded from: classes5.dex */
|
||
|
public class UnitsEditText extends TextInputEditText {
|
||
|
private RVV a;
|
||
|
private fLX c;
|
||
|
private InputFilter[] d;
|
||
|
private BigDecimal e;
|
||
|
|
||
|
/* loaded from: classes5.dex */
|
||
|
public interface RVV {
|
||
|
void b(BigDecimal bigDecimal);
|
||
|
|
||
|
void d();
|
||
|
}
|
||
|
|
||
|
public UnitsEditText(Context context) {
|
||
|
this(context, null);
|
||
|
}
|
||
|
|
||
|
public UnitsEditText(Context context, AttributeSet attributeSet) {
|
||
|
this(context, attributeSet, R.attr.editTextStyle);
|
||
|
}
|
||
|
|
||
|
public UnitsEditText(Context context, AttributeSet attributeSet, int i) {
|
||
|
super(context, attributeSet, i);
|
||
|
this.c = new fLX(this, new C10398eCy(this));
|
||
|
InputFilter[] inputFilterArr = {new fLY(false)};
|
||
|
this.d = inputFilterArr;
|
||
|
setFilters(inputFilterArr);
|
||
|
addTextChangedListener(this.c);
|
||
|
setOnEditorActionListener(new TextView.OnEditorActionListener(this) { // from class: o.eCB
|
||
|
private UnitsEditText a;
|
||
|
|
||
|
@Override // android.widget.TextView.OnEditorActionListener
|
||
|
public final boolean onEditorAction(TextView textView, int i2, KeyEvent keyEvent) {
|
||
|
return UnitsEditText.c(this.a, i2);
|
||
|
}
|
||
|
|
||
|
{
|
||
|
this.a = this;
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
public void setSpecificFilter(boolean z) {
|
||
|
InputFilter[] inputFilterArr = {new fLY(z)};
|
||
|
this.d = inputFilterArr;
|
||
|
setFilters(inputFilterArr);
|
||
|
}
|
||
|
|
||
|
public void setUnitFormattingTextWatcher(fLX flx) {
|
||
|
removeTextChangedListener(this.c);
|
||
|
flx.a(new C10398eCy(this));
|
||
|
this.c = flx;
|
||
|
addTextChangedListener(flx);
|
||
|
}
|
||
|
|
||
|
@Override // android.widget.TextView, android.view.View
|
||
|
protected void onFocusChanged(boolean z, int i, Rect rect) {
|
||
|
super.onFocusChanged(z, i, rect);
|
||
|
if (z) {
|
||
|
setHint("");
|
||
|
} else if (TextUtils.isEmpty(getText())) {
|
||
|
setHint(R.string.unit_limit);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override // android.widget.TextView, android.view.View
|
||
|
public boolean onKeyPreIme(int i, KeyEvent keyEvent) {
|
||
|
if (i == 4 && keyEvent.getAction() == 1) {
|
||
|
if (TextUtils.isEmpty(getText())) {
|
||
|
this.e = new BigDecimal(0);
|
||
|
} else {
|
||
|
setFormattedUnit(C6583cXR.c(this.e));
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
return super.onKeyPreIme(i, keyEvent);
|
||
|
}
|
||
|
|
||
|
@Override // android.view.View
|
||
|
public boolean dispatchKeyEvent(KeyEvent keyEvent) {
|
||
|
if (keyEvent.getKeyCode() == 67 && keyEvent.getAction() == 1) {
|
||
|
if (TextUtils.isEmpty(getText())) {
|
||
|
BigDecimal bigDecimal = new BigDecimal(0);
|
||
|
this.e = bigDecimal;
|
||
|
RVV rvv = this.a;
|
||
|
if (rvv != null) {
|
||
|
rvv.b(bigDecimal);
|
||
|
}
|
||
|
setFormattedUnit(C6583cXR.c(this.e));
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
return super.dispatchKeyEvent(keyEvent);
|
||
|
}
|
||
|
|
||
|
public void setFormattedUnit(String str) {
|
||
|
if (getParent() instanceof TextInputLayout) {
|
||
|
((TextInputLayout) getParent()).setError(null);
|
||
|
}
|
||
|
if (C6583cXR.q(str)) {
|
||
|
setText("");
|
||
|
return;
|
||
|
}
|
||
|
setFilters(new InputFilter[0]);
|
||
|
setText(str);
|
||
|
setUnitFormattingTextWatcher(this.c);
|
||
|
setFilters(this.d);
|
||
|
}
|
||
|
|
||
|
public static /* synthetic */ void b(UnitsEditText unitsEditText, BigDecimal bigDecimal) {
|
||
|
unitsEditText.e = bigDecimal;
|
||
|
RVV rvv = unitsEditText.a;
|
||
|
if (rvv != null) {
|
||
|
rvv.b(bigDecimal);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static /* synthetic */ boolean c(UnitsEditText unitsEditText, int i) {
|
||
|
if (i != 6) {
|
||
|
return false;
|
||
|
}
|
||
|
RVV rvv = unitsEditText.a;
|
||
|
if (rvv != null) {
|
||
|
rvv.d();
|
||
|
}
|
||
|
unitsEditText.clearFocus();
|
||
|
if (TextUtils.isEmpty(unitsEditText.getText())) {
|
||
|
return true;
|
||
|
}
|
||
|
unitsEditText.setFormattedUnit(C6583cXR.c(unitsEditText.e));
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
public void setOnUnitChangeListener(RVV rvv) {
|
||
|
this.a = rvv;
|
||
|
}
|
||
|
}
|