package allone.verbank.apad.client.component;
import android.text.InputFilter;
import android.text.Spanned;
/**
*
* @Title: ComponentDigitCtrlFilter.java
* @Package allone.verbank.apad.client.component
* @Description: 为了限制edit根据商品输入指定的位数和小数位
* @author qiulinhe qiu.linhe@allone.cn
*/
public class ComponentDigitCtrlFilter implements InputFilter {
private boolean isJPY;
private int digit;
public ComponentDigitCtrlFilter(boolean isJPY, int digit) {
this.isJPY = isJPY;
this.digit = digit;
}
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
// 删除等特殊字符,直接返回
if ("".equals(source.toString())) {
return null;
}
String oriValue = dest.toString();
StringBuffer sb = new StringBuffer(oriValue);
sb.append(source);
String newValue = sb.toString();
String[] newValueVec = newValue.split("\\.");
if (newValueVec.length == 2) {
double number = Double.parseDouble(newValueVec[0]);
boolean numberflag = true;
if (isJPY) {
numberflag = ((number - 999 > 0.000001) ? false : true);
} else {
numberflag = ((number - 99 > 0.000001) ? false : true);
}
boolean digitflag = true;
try {
String digitNumber = newValueVec[1];
digitflag = digitNumber.toCharArray().length > digit ? false : true;
} catch (Exception ex) {
digitflag = false;
}
if (numberflag && digitflag) {
return source;
} else {
return "";
}
} else {
double value = Double.parseDouble(newValue);
if (isJPY) {
return value > 999 ? "" : source;
} else {
return value > 99 ? "" : source;
}
}
// dest.subSequence(dstart, dend)
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有