1.1.5
This commit is contained in:
parent
f63c1f931e
commit
cb179b6b4b
@ -10,9 +10,9 @@
|
||||
{
|
||||
"type": "SINGLE",
|
||||
"filters": [],
|
||||
"versionCode": 5,
|
||||
"versionName": "1.0.5",
|
||||
"outputFile": "企业端正式_release_1.0.5_202204041318.apk"
|
||||
"versionCode": 8,
|
||||
"versionName": "1.0.8",
|
||||
"outputFile": "企业端正式_release_1.0.8_202204061736.apk"
|
||||
}
|
||||
]
|
||||
}
|
@ -27,6 +27,7 @@ public class PassBean implements Serializable {
|
||||
private String startTime;
|
||||
private String endTime;
|
||||
private String remarks;
|
||||
private String useDate;
|
||||
private int passNoNumber;
|
||||
private int numberOfPasses;
|
||||
private int numberOfPassesRequired;
|
||||
@ -46,6 +47,14 @@ public class PassBean implements Serializable {
|
||||
private String notUsedNumMF;
|
||||
private String notUsedNumSF;
|
||||
|
||||
public String getUseDate() {
|
||||
return useDate;
|
||||
}
|
||||
|
||||
public void setUseDate(String useDate) {
|
||||
this.useDate = useDate;
|
||||
}
|
||||
|
||||
public String getDriverIdcard() {
|
||||
return driverIdcard;
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Message
|
||||
import android.text.InputFilter
|
||||
import android.text.TextUtils
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
@ -15,6 +16,7 @@ import com.bigkoo.pickerview.view.OptionsPickerView
|
||||
import com.dahe.mylibrary.base.BaseActivity
|
||||
import com.dahe.mylibrary.net.CommonResponseBean
|
||||
import com.dahe.mylibrary.utils.TimeUtil
|
||||
import com.dahe.mylibrary.weight.NumRangeInputFilter
|
||||
import com.dahe.pass.R
|
||||
import com.dahe.pass.base.AppConfig
|
||||
import com.dahe.pass.bean.CompanyBean
|
||||
@ -33,6 +35,7 @@ import org.json.JSONArray
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
|
||||
/**
|
||||
* @ClassName ApplyActivity
|
||||
* @Author 用户
|
||||
@ -40,6 +43,8 @@ import java.util.*
|
||||
* @Description TODO
|
||||
*/
|
||||
class AddGoActivity : BaseActivity(), View.OnClickListener {
|
||||
|
||||
private var pointType : Int = 0
|
||||
private lateinit var kingKeyboard : KingKeyboard
|
||||
|
||||
override fun getLayout() = R.layout.activity_add_go
|
||||
@ -53,6 +58,11 @@ class AddGoActivity : BaseActivity(), View.OnClickListener {
|
||||
tvStartTime.setOnClickListener(this)
|
||||
tvEndTime.setOnClickListener(this)
|
||||
tvSflx.setOnClickListener(this)
|
||||
etQd.setOnClickListener(this)
|
||||
etZd.setOnClickListener(this)
|
||||
tvUpTime.setOnClickListener(this)
|
||||
// tvTxbh.filters = arrayOf<InputFilter>(InputFilterMinMax(0,2455))
|
||||
etDs.filters = arrayOf<InputFilter>(NumRangeInputFilter())
|
||||
// tvSTime.text = SPUtils.get(mContext,AppConfig.START_TIME, "").toString()
|
||||
// tvETime.text = SPUtils.get(mContext,AppConfig.END_TIME, "").toString()
|
||||
|
||||
@ -61,6 +71,7 @@ class AddGoActivity : BaseActivity(), View.OnClickListener {
|
||||
}
|
||||
|
||||
override fun initDate() {
|
||||
tvUpTime.text = TimeUtil.getNowString(SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()))
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,15 +94,54 @@ class AddGoActivity : BaseActivity(), View.OnClickListener {
|
||||
R.id.tvSub -> sub()
|
||||
R.id.tvSTime -> setBir(0, tvSTime)
|
||||
R.id.tvETime -> setBir(1, tvETime)
|
||||
R.id.tvUpTime -> setBir(2, tvUpTime)
|
||||
R.id.tvStartTime -> setBir(2, tvStartTime)
|
||||
R.id.tvEndTime -> setBir(3, tvEndTime)
|
||||
R.id.tvSflx -> freeOrBuy()
|
||||
R.id.etQd -> {
|
||||
KeyboardUtils.hideSoftInput(tvTxbh)
|
||||
if (isLoaded) {
|
||||
pointType = 0
|
||||
setProText()
|
||||
} else {
|
||||
mHandler.sendEmptyMessage(MSG_LOAD_DATA)
|
||||
}
|
||||
}
|
||||
R.id.etZd -> {
|
||||
KeyboardUtils.hideSoftInput(tvTxbh)
|
||||
if (isLoaded) {
|
||||
pointType = 1
|
||||
setProText()
|
||||
} else {
|
||||
mHandler.sendEmptyMessage(MSG_LOAD_DATA)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun sub() {
|
||||
KeyboardUtils.hideSoftInput(tvTxbh)
|
||||
|
||||
val toString = tvTxbh.text.toString()
|
||||
val substring = toString.substring(0, 1)
|
||||
if ("0"!=substring){
|
||||
showToast("通行证编号需 0 开头")
|
||||
return
|
||||
}
|
||||
val toDouble = tvTxbh.text.toString().toDouble()
|
||||
if (toDouble<1101){
|
||||
showToast("通行证编号不能小于1101")
|
||||
return
|
||||
}
|
||||
|
||||
if (toDouble>2455){
|
||||
showToast("通行证编号不能大于2455")
|
||||
return
|
||||
}
|
||||
|
||||
if (tvTxbh.text.toString().isNullOrEmpty() ||
|
||||
etCarNum.text.toString().isNullOrEmpty() || etName.text.toString().isNullOrEmpty() ||
|
||||
etPhone.text.toString().isNullOrEmpty() || etWpzl.text.toString().isNullOrEmpty() ||
|
||||
@ -102,6 +152,8 @@ class AddGoActivity : BaseActivity(), View.OnClickListener {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
val passBean = PassBean()
|
||||
passBean.passNo = """FG-${tvTxbh.text.toString()}"""
|
||||
passBean.vehicle = etCarNum.text.toString()
|
||||
@ -116,6 +168,7 @@ class AddGoActivity : BaseActivity(), View.OnClickListener {
|
||||
// passBean.useEndTime = tvETime.text.toString()
|
||||
passBean.startTime = tvStartTime.text.toString()
|
||||
passBean.endTime = tvEndTime.text.toString()
|
||||
passBean.useDate = tvUpTime.text.toString()
|
||||
passBean.remarks = tvBz.text.toString()
|
||||
// passBean.chargeType = tvSflx.text.toString()
|
||||
DataManager.getInstance().addPass(passBean)
|
||||
@ -192,12 +245,12 @@ class AddGoActivity : BaseActivity(), View.OnClickListener {
|
||||
// TimeUtil.date2String(date,SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()))
|
||||
val data =
|
||||
TimeUtil.date2String(date,
|
||||
SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault()))
|
||||
SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()))
|
||||
view.text = data
|
||||
}.setSubmitColor(Color.parseColor("#F1474B")) //确定按钮文字颜色
|
||||
.setCancelColor(Color.parseColor("#F1474B")) //取消按钮文字颜色
|
||||
.setTitleBgColor(Color.parseColor("#FFFFFF"))
|
||||
.setType(booleanArrayOf(true, true, true, true, true, false))
|
||||
.setType(booleanArrayOf(true, true, true, false, false, false))
|
||||
.setTitleText("选择时间")
|
||||
.setDate(currDate)
|
||||
.setRangDate(startDate, endtDate)
|
||||
@ -233,12 +286,18 @@ class AddGoActivity : BaseActivity(), View.OnClickListener {
|
||||
) options3Items.get(options1).get(options2).get(options3) else ""
|
||||
val tx = "$opt1tx-$opt2tx-$opt3tx"
|
||||
// tvDz.text = tx
|
||||
if (0== pointType){
|
||||
etQd.text = tx
|
||||
}else{
|
||||
etZd.text = tx
|
||||
}
|
||||
}
|
||||
.setSubmitColor(Color.parseColor("#F1474B")) //确定按钮文字颜色
|
||||
.setCancelColor(Color.parseColor("#F1474B")) //取消按钮文字颜色
|
||||
.setTitleBgColor(Color.parseColor("#FFFFFF"))
|
||||
.setBgColor(Color.parseColor("#F5F5F5"))
|
||||
.setContentTextSize(20)
|
||||
.setSelectOptions(15, 0, 0)
|
||||
.build<Any>()
|
||||
pvOptions.setPicker(options1Items as List<Nothing>?,
|
||||
options2Items as List<Nothing>?, options3Items as List<Nothing>?) //三级选择器
|
||||
|
@ -5,6 +5,7 @@ import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Message
|
||||
import android.text.InputFilter
|
||||
import android.text.TextUtils
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
@ -15,6 +16,7 @@ import com.bigkoo.pickerview.view.OptionsPickerView
|
||||
import com.dahe.mylibrary.base.BaseActivity
|
||||
import com.dahe.mylibrary.net.CommonResponseBean
|
||||
import com.dahe.mylibrary.utils.TimeUtil
|
||||
import com.dahe.mylibrary.weight.NumRangeInputFilter
|
||||
import com.dahe.pass.R
|
||||
import com.dahe.pass.base.AppConfig
|
||||
import com.dahe.pass.bean.JsonBean
|
||||
@ -26,7 +28,25 @@ import com.dahe.pass.utils.GetJsonDataUtil
|
||||
import com.dahe.pass.utils.SPUtils
|
||||
import com.google.gson.Gson
|
||||
import com.lxj.xpopup.util.KeyboardUtils
|
||||
import kotlinx.android.synthetic.main.activity_add_go.*
|
||||
import kotlinx.android.synthetic.main.activity_edit_go.*
|
||||
import kotlinx.android.synthetic.main.activity_edit_go.etCarNum
|
||||
import kotlinx.android.synthetic.main.activity_edit_go.etCardId
|
||||
import kotlinx.android.synthetic.main.activity_edit_go.etDs
|
||||
import kotlinx.android.synthetic.main.activity_edit_go.etName
|
||||
import kotlinx.android.synthetic.main.activity_edit_go.etPhone
|
||||
import kotlinx.android.synthetic.main.activity_edit_go.etQd
|
||||
import kotlinx.android.synthetic.main.activity_edit_go.etWpzl
|
||||
import kotlinx.android.synthetic.main.activity_edit_go.etZd
|
||||
import kotlinx.android.synthetic.main.activity_edit_go.tvBz
|
||||
import kotlinx.android.synthetic.main.activity_edit_go.tvETime
|
||||
import kotlinx.android.synthetic.main.activity_edit_go.tvEndTime
|
||||
import kotlinx.android.synthetic.main.activity_edit_go.tvSTime
|
||||
import kotlinx.android.synthetic.main.activity_edit_go.tvSflx
|
||||
import kotlinx.android.synthetic.main.activity_edit_go.tvStartTime
|
||||
import kotlinx.android.synthetic.main.activity_edit_go.tvSub
|
||||
import kotlinx.android.synthetic.main.activity_edit_go.tvTxbh
|
||||
import kotlinx.android.synthetic.main.activity_edit_go.tvUpTime
|
||||
import org.json.JSONArray
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
@ -46,6 +66,9 @@ class EditGoActivity : BaseActivity(), View.OnClickListener {
|
||||
setStatusBarCancelLightColor()
|
||||
setTitleBar("编辑车辆") { finish() }
|
||||
tvSub.setOnClickListener(this)
|
||||
tvUpTime.setOnClickListener(this)
|
||||
|
||||
etDs.filters = arrayOf<InputFilter>(NumRangeInputFilter())
|
||||
}
|
||||
|
||||
override fun initDate() {
|
||||
@ -76,6 +99,7 @@ class EditGoActivity : BaseActivity(), View.OnClickListener {
|
||||
when (view.id) {
|
||||
// R.id.tvSpdw -> spdw()
|
||||
R.id.tvSub -> sub()
|
||||
R.id.tvUpTime -> setBir(2, tvUpTime)
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,6 +122,7 @@ class EditGoActivity : BaseActivity(), View.OnClickListener {
|
||||
passBean.transportTonnage = etDs.text.toString()
|
||||
passBean.startPoint = etQd.text.toString()
|
||||
passBean.endPoint = etZd.text.toString()
|
||||
passBean.useDate = tvUpTime.text.toString()
|
||||
|
||||
DataManager.getInstance().detailEdit(passBean)
|
||||
.compose(DataManager.setThread())
|
||||
@ -133,12 +158,12 @@ class EditGoActivity : BaseActivity(), View.OnClickListener {
|
||||
// TimeUtil.date2String(date,SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()))
|
||||
val data =
|
||||
TimeUtil.date2String(date,
|
||||
SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault()))
|
||||
SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()))
|
||||
view.text = data
|
||||
}.setSubmitColor(Color.parseColor("#F1474B")) //确定按钮文字颜色
|
||||
.setCancelColor(Color.parseColor("#F1474B")) //取消按钮文字颜色
|
||||
.setTitleBgColor(Color.parseColor("#FFFFFF"))
|
||||
.setType(booleanArrayOf(true, true, true, true, true, false))
|
||||
.setType(booleanArrayOf(true, true, true, false, false, false))
|
||||
.setTitleText("选择时间")
|
||||
.setDate(currDate)
|
||||
.setRangDate(startDate, endtDate)
|
||||
@ -180,6 +205,7 @@ class EditGoActivity : BaseActivity(), View.OnClickListener {
|
||||
.setTitleBgColor(Color.parseColor("#FFFFFF"))
|
||||
.setBgColor(Color.parseColor("#F5F5F5"))
|
||||
.setContentTextSize(20)
|
||||
.setSelectOptions(15, 0, 0)
|
||||
.build<Any>()
|
||||
pvOptions.setPicker(options1Items as List<Nothing>?,
|
||||
options2Items as List<Nothing>?, options3Items as List<Nothing>?) //三级选择器
|
||||
|
@ -30,7 +30,7 @@ class MineFragment : BaseFragment(), View.OnClickListener {
|
||||
rlYhys.setOnClickListener(this)
|
||||
|
||||
val userInfo = SPUtils.getUserInfo(mContext).userInfo
|
||||
tvName.text = userInfo.name
|
||||
tvName.text = userInfo.enterpriseName
|
||||
tvPhone.text = userInfo.phone
|
||||
}
|
||||
|
||||
|
11
app/src/main/res/drawable/shape_gray_bg6.xml
Normal file
11
app/src/main/res/drawable/shape_gray_bg6.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="@color/color_F5" />
|
||||
<corners
|
||||
android:bottomLeftRadius="6dp"
|
||||
android:bottomRightRadius="6dp"
|
||||
android:topLeftRadius="6dp"
|
||||
android:topRightRadius="6dp" />
|
||||
|
||||
</shape>
|
@ -36,20 +36,27 @@
|
||||
android:textColor="@color/black"></TextView>
|
||||
|
||||
<TextView
|
||||
android:background="@drawable/shape_gray_bg6"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="FG-"
|
||||
android:paddingRight="10dp"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingBottom="5dp"
|
||||
android:paddingTop="5dp"
|
||||
android:textColor="@color/black"></TextView>
|
||||
|
||||
<EditText
|
||||
android:layout_marginLeft="8dp"
|
||||
android:id="@+id/tvTxbh"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:gravity="right"
|
||||
android:hint="请输入通行证编号"
|
||||
android:hint="01101-02455"
|
||||
android:inputType="number"
|
||||
android:maxLines="1"
|
||||
android:maxLength="5"
|
||||
android:singleLine="true"
|
||||
android:textSize="14dp"></EditText>
|
||||
|
||||
@ -271,6 +278,40 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginRight="8dp"
|
||||
android:background="@color/color_line"></View>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:padding="6dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="上报时间"
|
||||
android:textColor="@color/black"></TextView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvUpTime"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:gravity="right"
|
||||
android:hint="请选择上报时间"
|
||||
android:paddingRight="6dp"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="14dp"></TextView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
@ -397,17 +438,17 @@
|
||||
android:text="起点"
|
||||
android:textColor="@color/black"></TextView>
|
||||
|
||||
<EditText
|
||||
<TextView
|
||||
android:id="@+id/etQd"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:gravity="right"
|
||||
android:hint="请输入起点"
|
||||
android:hint="请选择起点"
|
||||
android:maxLines="1"
|
||||
android:paddingRight="6dp"
|
||||
android:singleLine="true"
|
||||
android:textSize="14dp"></EditText>
|
||||
android:textSize="14dp"></TextView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@ -432,17 +473,17 @@
|
||||
android:text="终点"
|
||||
android:textColor="@color/black"></TextView>
|
||||
|
||||
<EditText
|
||||
<TextView
|
||||
android:id="@+id/etZd"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:gravity="right"
|
||||
android:hint="请输入运终点"
|
||||
android:hint="请选择终点"
|
||||
android:maxLines="1"
|
||||
android:paddingRight="6dp"
|
||||
android:singleLine="true"
|
||||
android:textSize="14dp"></EditText>
|
||||
android:textSize="14dp"></TextView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -235,6 +235,7 @@
|
||||
android:textColor="@color/black"></TextView>
|
||||
|
||||
<TextView
|
||||
android:textColor="@color/black"
|
||||
android:id="@+id/etCardId"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
@ -250,6 +251,40 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginRight="8dp"
|
||||
android:background="@color/color_line"></View>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:padding="6dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="上报时间"
|
||||
android:textColor="@color/black"></TextView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvUpTime"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@null"
|
||||
android:gravity="right"
|
||||
android:hint="请选择上报时间"
|
||||
android:paddingRight="6dp"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="14dp"></TextView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
@ -285,6 +320,8 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
@ -373,7 +410,8 @@
|
||||
android:text="起点"
|
||||
android:textColor="@color/black"></TextView>
|
||||
|
||||
<EditText
|
||||
<TextView
|
||||
android:textColor="@color/black"
|
||||
android:id="@+id/etQd"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
@ -383,7 +421,7 @@
|
||||
android:maxLines="1"
|
||||
android:singleLine="true"
|
||||
android:paddingRight="6dp"
|
||||
android:textSize="14dp"></EditText>
|
||||
android:textSize="14dp"></TextView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@ -408,7 +446,8 @@
|
||||
android:text="终点"
|
||||
android:textColor="@color/black"></TextView>
|
||||
|
||||
<EditText
|
||||
<TextView
|
||||
android:textColor="@color/black"
|
||||
android:id="@+id/etZd"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
@ -418,7 +457,7 @@
|
||||
android:maxLines="1"
|
||||
android:singleLine="true"
|
||||
android:paddingRight="6dp"
|
||||
android:textSize="14dp"></EditText>
|
||||
android:textSize="14dp"></TextView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -40,8 +40,8 @@ project.ext {
|
||||
applicationId : "com.dahe.pass",
|
||||
minSdkVersion : 21,
|
||||
targetSdkVersion : 30,
|
||||
versionCode : 5,
|
||||
versionName : "1.0.5",
|
||||
versionCode : 8,
|
||||
versionName : "1.0.8",
|
||||
]
|
||||
dependencies = [
|
||||
"appcompat-v7" : "com.android.support:appcompat-v7:${SupportVersion}",
|
||||
|
@ -0,0 +1,39 @@
|
||||
package com.dahe.mylibrary.weight;
|
||||
|
||||
import android.text.InputFilter;
|
||||
import android.text.Spanned;
|
||||
|
||||
/**
|
||||
* @ClassName InputFilterMinMax
|
||||
* @Author 用户
|
||||
* @Date 2022/4/6 11:35
|
||||
* @Description TODO
|
||||
*/
|
||||
public class InputFilterMinMax implements InputFilter {
|
||||
|
||||
private int min, max;
|
||||
|
||||
public InputFilterMinMax(int min, int max) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
public InputFilterMinMax(String min, String max) {
|
||||
this.min = Integer.parseInt(min);
|
||||
this.max = Integer.parseInt(max);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
|
||||
try {
|
||||
int input = Integer.parseInt(dest.toString() + source.toString());
|
||||
if (isInRange(min, max, input))
|
||||
return null;
|
||||
} catch (NumberFormatException nfe) { }
|
||||
return "";
|
||||
}
|
||||
|
||||
private boolean isInRange(int a, int b, int c) {
|
||||
return b > a ? c >= a && c <= b : c >= b && c <= a;
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
package com.dahe.mylibrary.weight;
|
||||
|
||||
import android.text.InputFilter;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* @ClassName NumRangeInputFilter
|
||||
* @Author 用户
|
||||
* @Date 2022/4/6 11:38
|
||||
* @Description TODO
|
||||
*/
|
||||
public class NumRangeInputFilter implements InputFilter {
|
||||
|
||||
// 只允许输入数字和小数点
|
||||
private static final String REGEX = "([0-9]|\\.)*";
|
||||
// 输入的最大金额
|
||||
private static final double MAX_VALUE = 99.999;
|
||||
// 小数点后的位数
|
||||
private static final int POINTER_LENGTH = 3;
|
||||
|
||||
private static final String POINTER = ".";
|
||||
|
||||
private static final String ZERO_ZERO = "00";
|
||||
|
||||
/**
|
||||
* @param source 新输入的字符串
|
||||
* @param start 新输入的字符串起始下标,一般为0
|
||||
* @param end 新输入的字符串终点下标,一般为source长度-1
|
||||
* @param dest 输入之前文本框内容
|
||||
* @param dstart 原内容起始坐标,一般为0
|
||||
* @param dend 原内容终点坐标,一般为dest长度-1
|
||||
* @return 输入内容
|
||||
*/
|
||||
@Override
|
||||
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
|
||||
String sourceText = source.toString();
|
||||
String destText = dest.toString();
|
||||
|
||||
// 新输入的字符串为空(删除剪切等)
|
||||
if (TextUtils.isEmpty(sourceText)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// 拼成字符串
|
||||
String temp = destText.substring(0, dstart)
|
||||
+ sourceText.substring(start, end)
|
||||
+ destText.substring(dend, dest.length());
|
||||
Log.v("temp", "-" + temp);
|
||||
|
||||
// 纯数字加小数点
|
||||
if (!temp.matches(REGEX)) {
|
||||
Log.d("TAG", "!纯数字加小数点");
|
||||
return dest.subSequence(dstart, dend);
|
||||
}
|
||||
|
||||
// 小数点的情况
|
||||
if (temp.contains(POINTER)) {
|
||||
// 第一位就是小数点
|
||||
if (temp.startsWith(POINTER)) {
|
||||
Log.d("TAG", "第一位就是小数点");
|
||||
return dest.subSequence(dstart, dend);
|
||||
}
|
||||
// 不止一个小数点
|
||||
if(temp.indexOf(POINTER) != temp.lastIndexOf(POINTER)) {
|
||||
Log.d("TAG", "不止一个小数点");
|
||||
return dest.subSequence(dstart, dend);
|
||||
}
|
||||
}
|
||||
|
||||
double sumText = Double.parseDouble(temp);
|
||||
if (sumText > MAX_VALUE) {
|
||||
// 超出最大值
|
||||
Log.d("TAG", "超出最大值");
|
||||
return dest.subSequence(dstart, dend);
|
||||
}
|
||||
// 有小数点的情况下
|
||||
if (temp.contains(POINTER)) {
|
||||
//验证小数点精度,保证小数点后只能输入两位
|
||||
if (!temp.endsWith(POINTER) && temp.split("\\.")[1].length() > POINTER_LENGTH) {
|
||||
Log.d("TAG", "保证小数点后只能输入两位");
|
||||
return dest.subSequence(dstart, dend);
|
||||
}
|
||||
} else if (temp.startsWith(POINTER) || temp.startsWith(ZERO_ZERO)) {
|
||||
// 首位只能有一个0
|
||||
Log.d("TAG", "首位只能有一个0");
|
||||
return dest.subSequence(dstart, dend);
|
||||
}
|
||||
|
||||
Log.d("TAG", "正常情况");
|
||||
return source;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user