|
|
|
@ -1,6 +1,7 @@
|
|
|
|
package com.example.tyre;
|
|
|
|
package com.example.tyre;
|
|
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
|
|
|
|
|
|
|
|
import android.app.ProgressDialog;
|
|
|
|
import android.app.ProgressDialog;
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Context;
|
|
|
|
@ -19,22 +20,18 @@ import android.widget.Button;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.android.hdhe.uhf.reader.UhfReader;
|
|
|
|
import com.android.hdhe.uhf.reader.UhfReader;
|
|
|
|
import com.android.hdhe.uhf.readerInterface.TagModel;
|
|
|
|
import com.android.hdhe.uhf.readerInterface.TagModel;
|
|
|
|
import com.example.tyre.adapter.CarRecordAdapter;
|
|
|
|
import com.example.tyre.entity.AjaxResult;
|
|
|
|
import com.example.tyre.databinding.ActivityTyreLayoutBinding;
|
|
|
|
|
|
|
|
import com.example.tyre.entity.BaseCar;
|
|
|
|
import com.example.tyre.entity.BaseCar;
|
|
|
|
import com.example.tyre.entity.CarLifecycleDTO;
|
|
|
|
import com.example.tyre.entity.BaseTyre;
|
|
|
|
import com.example.tyre.entity.CarMaintenanceLifecycleDTO;
|
|
|
|
|
|
|
|
import com.example.tyre.entity.EPC;
|
|
|
|
import com.example.tyre.entity.EPC;
|
|
|
|
import com.example.tyre.maintenance.base.MyRecultCall;
|
|
|
|
import com.example.tyre.maintenance.base.MyRecultCall;
|
|
|
|
import com.example.tyre.maintenance.base.MyResult;
|
|
|
|
import com.example.tyre.maintenance.base.MyResult;
|
|
|
|
import com.example.tyre.maintenance.been.BaseTyre;
|
|
|
|
|
|
|
|
import com.example.tyre.util.CarSelectionDialog;
|
|
|
|
import com.example.tyre.util.CarSelectionDialog;
|
|
|
|
import com.example.tyre.util.CommonDialog;
|
|
|
|
import com.example.tyre.util.CommonDialog;
|
|
|
|
import com.example.tyre.util.MyUrl;
|
|
|
|
import com.example.tyre.util.MyUrl;
|
|
|
|
|
|
|
|
import com.example.tyre.util.SharedPreferencesUtils;
|
|
|
|
import com.example.tyre.util.Util;
|
|
|
|
import com.example.tyre.util.Util;
|
|
|
|
import com.google.android.material.textfield.TextInputEditText;
|
|
|
|
import com.google.android.material.textfield.TextInputEditText;
|
|
|
|
import com.google.android.material.textfield.TextInputLayout;
|
|
|
|
import com.google.android.material.textfield.TextInputLayout;
|
|
|
|
@ -54,74 +51,44 @@ import cn.pda.serialport.Tools;
|
|
|
|
import okhttp3.MediaType;
|
|
|
|
import okhttp3.MediaType;
|
|
|
|
import okhttp3.RequestBody;
|
|
|
|
import okhttp3.RequestBody;
|
|
|
|
|
|
|
|
|
|
|
|
public class TyreLayoutActivity extends AppCompatActivity implements CarRecordAdapter.ItemClickCall {
|
|
|
|
import com.example.tyre.databinding.ActivityTyreLayoutBinding;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class TyreLayoutActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ActivityTyreLayoutBinding binding;
|
|
|
|
|
|
|
|
|
|
|
|
// 防抖延迟时间 (毫秒)
|
|
|
|
|
|
|
|
private static final long DEBOUNCE_DELAY = 500;
|
|
|
|
|
|
|
|
public MediaType JSON = MediaType.parse("application/json; charset=utf-8");
|
|
|
|
|
|
|
|
TextInputEditText etPlateNumber;
|
|
|
|
TextInputEditText etPlateNumber;
|
|
|
|
Button btnRetrieve;
|
|
|
|
Button btnRetrieve;
|
|
|
|
TextInputLayout tilPlateNumber;
|
|
|
|
TextInputLayout tilPlateNumber;
|
|
|
|
long lastTime;
|
|
|
|
|
|
|
|
long nextTime;
|
|
|
|
|
|
|
|
String min = "EC0001012026010100000001"; // 左边界(包含)
|
|
|
|
|
|
|
|
String max = "EC0001012026010100100000"; // 右边界(包含)
|
|
|
|
|
|
|
|
private ActivityTyreLayoutBinding binding;
|
|
|
|
|
|
|
|
private ProgressDialog progressDialog;
|
|
|
|
private ProgressDialog progressDialog;
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isStart = true;
|
|
|
|
private boolean isStart = true;
|
|
|
|
private boolean runFlag = true;
|
|
|
|
private boolean runFlag = true;
|
|
|
|
private boolean startFlag = false;
|
|
|
|
private boolean startFlag = false;
|
|
|
|
private UhfReader manager; // UHF manager,UHF Operating handle
|
|
|
|
private UhfReader manager; // UHF manager,UHF Operating handle
|
|
|
|
private ArrayList<EPC> listEPC;
|
|
|
|
private ArrayList<EPC> listEPC;
|
|
|
|
private ArrayList<String> listepc = new ArrayList<String>();
|
|
|
|
private ArrayList<String> listepc = new ArrayList<String>();
|
|
|
|
|
|
|
|
long lastTime;
|
|
|
|
|
|
|
|
long nextTime;
|
|
|
|
private Toast mToast;
|
|
|
|
private Toast mToast;
|
|
|
|
private Toast toast;
|
|
|
|
private Toast toast;
|
|
|
|
private KeyReceiver keyReceiver;
|
|
|
|
private KeyReceiver keyReceiver;
|
|
|
|
private CarRecordAdapter adapter;
|
|
|
|
String min = "EC0001012026010100000001"; // 左边界(包含)
|
|
|
|
// 用于存储最后一次扫描到的 EPC
|
|
|
|
String max = "EC0001012026010100100000"; // 右边界(包含)
|
|
|
|
private String lastScannedEpc;
|
|
|
|
// 1. 定义数据模型类 (对应后台返回的字段)
|
|
|
|
// 用于处理防抖逻辑的 Handler
|
|
|
|
public static class TireData {
|
|
|
|
private Handler debounceHandler = new Handler(new Handler.Callback() {
|
|
|
|
public String position; // 轮位名称
|
|
|
|
@Override
|
|
|
|
public String brand; // 品牌
|
|
|
|
public boolean handleMessage(Message msg) {
|
|
|
|
public String spec; // 规格
|
|
|
|
if (msg.what == 1 && lastScannedEpc != null) {
|
|
|
|
public String installDate; // 安装日期
|
|
|
|
// 延迟时间到,执行查询
|
|
|
|
|
|
|
|
showLoadingDialog();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 查询车辆数据方法
|
|
|
|
public TireData(String position, String brand, String spec, String installDate) {
|
|
|
|
findCar(lastScannedEpc);
|
|
|
|
this.position = position;
|
|
|
|
lastScannedEpc = null; // 清空,等待下一次扫描
|
|
|
|
this.brand = brand;
|
|
|
|
|
|
|
|
this.spec = spec;
|
|
|
|
|
|
|
|
this.installDate = installDate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 判断字符串是否在指定的区间内(包含边界)
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param target 要判断的目标字符串
|
|
|
|
|
|
|
|
* @param min 区间左边界
|
|
|
|
|
|
|
|
* @param max 区间右边界
|
|
|
|
|
|
|
|
* @return true=在区间内,false=不在
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static boolean isInRange(String target, String min, String max) {
|
|
|
|
|
|
|
|
// 空值校验,避免空指针异常
|
|
|
|
|
|
|
|
if (target == null || min == null || max == null) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// compareTo规则:
|
|
|
|
|
|
|
|
// 1. 字符串相等返回0;
|
|
|
|
|
|
|
|
// 2. 目标字符串 > 对比字符串 返回正数;
|
|
|
|
|
|
|
|
// 3. 目标字符串 < 对比字符串 返回负数。
|
|
|
|
|
|
|
|
// 因此:target >= min 等价于 target.compareTo(min) >= 0;
|
|
|
|
|
|
|
|
// target <= max 等价于 target.compareTo(max) <= 0。
|
|
|
|
|
|
|
|
return target.compareTo(min) >= 0 && target.compareTo(max) <= 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 点击item
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(int position) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@ -139,12 +106,10 @@ public class TyreLayoutActivity extends AppCompatActivity implements CarRecordAd
|
|
|
|
tilPlateNumber = binding.tilPlateNumber;
|
|
|
|
tilPlateNumber = binding.tilPlateNumber;
|
|
|
|
etPlateNumber.addTextChangedListener(new TextWatcher() {
|
|
|
|
etPlateNumber.addTextChangedListener(new TextWatcher() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void afterTextChanged(Editable s) {
|
|
|
|
public void afterTextChanged(Editable s) {
|
|
|
|
@ -155,13 +120,11 @@ public class TyreLayoutActivity extends AppCompatActivity implements CarRecordAd
|
|
|
|
String plateNumber = etPlateNumber.getText().toString().trim();
|
|
|
|
String plateNumber = etPlateNumber.getText().toString().trim();
|
|
|
|
if (!plateNumber.isEmpty()) {
|
|
|
|
if (!plateNumber.isEmpty()) {
|
|
|
|
showLoadingDialog();
|
|
|
|
showLoadingDialog();
|
|
|
|
performSearchOld(plateNumber);
|
|
|
|
performSearch(plateNumber);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
tilPlateNumber.setError("车牌号不能为空");
|
|
|
|
tilPlateNumber.setError("车牌号不能为空");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
adapter = new CarRecordAdapter(this, this);
|
|
|
|
|
|
|
|
binding.setAdapter(adapter);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void bindViews() {
|
|
|
|
private void bindViews() {
|
|
|
|
@ -173,14 +136,14 @@ public class TyreLayoutActivity extends AppCompatActivity implements CarRecordAd
|
|
|
|
private void setupClickListeners() {
|
|
|
|
private void setupClickListeners() {
|
|
|
|
binding.btnRetrieve.setOnClickListener(v -> {
|
|
|
|
binding.btnRetrieve.setOnClickListener(v -> {
|
|
|
|
String PlateNumber = etPlateNumber.getText().toString();
|
|
|
|
String PlateNumber = etPlateNumber.getText().toString();
|
|
|
|
if (PlateNumber == null || PlateNumber.isEmpty()) {
|
|
|
|
if (PlateNumber == null || PlateNumber.isEmpty())
|
|
|
|
|
|
|
|
{
|
|
|
|
new CommonDialog(TyreLayoutActivity.this).setMessage("请输入车牌号!").show();
|
|
|
|
new CommonDialog(TyreLayoutActivity.this).setMessage("请输入车牌号!").show();
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
carBangding(PlateNumber);
|
|
|
|
carBangding(PlateNumber);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
super.onResume();
|
|
|
|
@ -192,99 +155,34 @@ public class TyreLayoutActivity extends AppCompatActivity implements CarRecordAd
|
|
|
|
registerReceiver();
|
|
|
|
registerReceiver();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onPause() {
|
|
|
|
public void onPause() {
|
|
|
|
startFlag = false;
|
|
|
|
startFlag = false;
|
|
|
|
super.onPause();
|
|
|
|
super.onPause();
|
|
|
|
unregisterReceiver();
|
|
|
|
unregisterReceiver();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
|
|
|
protected void onDestroy() {
|
|
|
|
startFlag = false;
|
|
|
|
startFlag = false;
|
|
|
|
runFlag = false;
|
|
|
|
runFlag = false;
|
|
|
|
super.onDestroy();
|
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public MediaType JSON = MediaType.parse("application/json; charset=utf-8");
|
|
|
|
private void selectInfo(String carNo) {
|
|
|
|
private void performSearch(String carNo) {
|
|
|
|
OkGo.<MyResult>get(MyUrl.url + "/tyre/car/lifecycle/" + carNo)
|
|
|
|
Map<String ,String> map=new HashMap<>();
|
|
|
|
.execute(new MyRecultCall(progressDialog, this) {
|
|
|
|
|
|
|
|
@SuppressLint("NotifyDataSetChanged")
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onSuccess(Response<MyResult> response) {
|
|
|
|
|
|
|
|
super.onSuccess(response);
|
|
|
|
|
|
|
|
MyResult body = response.body();
|
|
|
|
|
|
|
|
if (body.getCode() == 0) {
|
|
|
|
|
|
|
|
CarLifecycleDTO carLifecycleDTO =
|
|
|
|
|
|
|
|
new Gson().fromJson(body.getJson(), CarLifecycleDTO.class);
|
|
|
|
|
|
|
|
List<CarMaintenanceLifecycleDTO> maintenanceList =
|
|
|
|
|
|
|
|
carLifecycleDTO.getMaintenanceList();
|
|
|
|
|
|
|
|
if (maintenanceList != null && !maintenanceList.isEmpty()) {
|
|
|
|
|
|
|
|
adapter.setList(maintenanceList);
|
|
|
|
|
|
|
|
adapter.notifyDataSetChanged();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 轮位显示
|
|
|
|
|
|
|
|
List<BaseTyre> mountedTyres = carLifecycleDTO.getMountedTyres();
|
|
|
|
|
|
|
|
mountedTyres.forEach(tire -> {
|
|
|
|
|
|
|
|
String wheelPostion = tire.getWheelPostion();
|
|
|
|
|
|
|
|
initTire(wheelPostion, tire);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
// 显示里程
|
|
|
|
|
|
|
|
binding.selectInfoMileage.setText(carLifecycleDTO.getCar().getInputMileage());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化轮胎信息
|
|
|
|
|
|
|
|
private void initTire(String wheelPostion, com.example.tyre.maintenance.been.BaseTyre baseTyre) {
|
|
|
|
|
|
|
|
binding.setTire1(new com.example.tyre.maintenance.been.BaseTyre());
|
|
|
|
|
|
|
|
binding.setTire2(new com.example.tyre.maintenance.been.BaseTyre());
|
|
|
|
|
|
|
|
binding.setTire3(new com.example.tyre.maintenance.been.BaseTyre());
|
|
|
|
|
|
|
|
binding.setTire4(new com.example.tyre.maintenance.been.BaseTyre());
|
|
|
|
|
|
|
|
binding.setTire5(new com.example.tyre.maintenance.been.BaseTyre());
|
|
|
|
|
|
|
|
binding.setTire6(new com.example.tyre.maintenance.been.BaseTyre());
|
|
|
|
|
|
|
|
switch (wheelPostion) {
|
|
|
|
|
|
|
|
case "左前轮":
|
|
|
|
|
|
|
|
binding.setTire1(baseTyre);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "右前轮":
|
|
|
|
|
|
|
|
binding.setTire2(baseTyre);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "左外轮":
|
|
|
|
|
|
|
|
binding.setTire3(baseTyre);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "左内轮":
|
|
|
|
|
|
|
|
binding.setTire4(baseTyre);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case "右内轮":
|
|
|
|
|
|
|
|
binding.setTire5(baseTyre);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "右外轮":
|
|
|
|
|
|
|
|
binding.setTire6(baseTyre);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 检索车牌号
|
|
|
|
|
|
|
|
private void performSearchOld(String carNo) {
|
|
|
|
|
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
|
|
|
|
|
map.put("carNo", carNo);
|
|
|
|
map.put("carNo", carNo);
|
|
|
|
OkGo.<MyResult>post(MyUrl.url + "/tyre/car/PdaQueryCarList")
|
|
|
|
OkGo.<MyResult>post(MyUrl.url + "/tyre/car/PdaQueryCarList")
|
|
|
|
.tag(this)
|
|
|
|
.tag(this)
|
|
|
|
.upRequestBody(RequestBody.create(JSON, new Gson().toJson(map)))
|
|
|
|
.upRequestBody(RequestBody.create(JSON, new Gson().toJson(map)))
|
|
|
|
.params("carNo", carNo)
|
|
|
|
.params("carNo", carNo)
|
|
|
|
.execute(
|
|
|
|
.execute(
|
|
|
|
new MyRecultCall(progressDialog, this) {
|
|
|
|
new MyRecultCall(progressDialog,this){
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onSuccess(Response<MyResult> response) {
|
|
|
|
public void onSuccess(Response<MyResult> response) {
|
|
|
|
super.onSuccess(response);
|
|
|
|
super.onSuccess(response);
|
|
|
|
var body = response.body();
|
|
|
|
var body = response.body();
|
|
|
|
if (body.getCode() == 0) {
|
|
|
|
if (body.getCode()==0) {
|
|
|
|
Gson gson = new Gson();
|
|
|
|
Gson gson = new Gson();
|
|
|
|
|
|
|
|
|
|
|
|
List<BaseCar> baseCarList =
|
|
|
|
List<BaseCar> baseCarList =
|
|
|
|
@ -317,7 +215,6 @@ public class TyreLayoutActivity extends AppCompatActivity implements CarRecordAd
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}*/);
|
|
|
|
}*/);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void showCarSelectionDialog(List<String> carNoList) {
|
|
|
|
private void showCarSelectionDialog(List<String> carNoList) {
|
|
|
|
CarSelectionDialog dialog = new CarSelectionDialog(this, carNoList);
|
|
|
|
CarSelectionDialog dialog = new CarSelectionDialog(this, carNoList);
|
|
|
|
dialog.setOnCarSelectedListener(new CarSelectionDialog.OnCarSelectedListener() {
|
|
|
|
dialog.setOnCarSelectedListener(new CarSelectionDialog.OnCarSelectedListener() {
|
|
|
|
@ -325,45 +222,25 @@ public class TyreLayoutActivity extends AppCompatActivity implements CarRecordAd
|
|
|
|
public void onCarSelected(String carNo) {
|
|
|
|
public void onCarSelected(String carNo) {
|
|
|
|
// 处理选中的车辆
|
|
|
|
// 处理选中的车辆
|
|
|
|
etPlateNumber.setText(carNo);
|
|
|
|
etPlateNumber.setText(carNo);
|
|
|
|
selectInfo(carNo);// 检索车辆信息
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
dialog.show();
|
|
|
|
dialog.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void carBangding(String PlateNumber) {
|
|
|
|
private void carBangding(String PlateNumber) {
|
|
|
|
OkGo.<String>post(MyUrl.url + "/tyre/tyre/getCarBingTire")
|
|
|
|
OkGo.<String>post(MyUrl.url + "/tyre/tyre/getCarBingTire")
|
|
|
|
.tag(this).params("carNo", PlateNumber)
|
|
|
|
.tag(this).params("carNo", PlateNumber)
|
|
|
|
.execute(new StringCallback() {
|
|
|
|
.execute(new StringCallback() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onSuccess(Response<String> response) {
|
|
|
|
public void onSuccess(Response<String> response) {
|
|
|
|
// hideLoadingDialog();
|
|
|
|
//hideLoadingDialog();
|
|
|
|
String body = response.body();
|
|
|
|
String body = response.body();
|
|
|
|
Gson gson = new Gson();
|
|
|
|
Gson gson=new Gson();
|
|
|
|
// List<BaseTyre> baseTyreList = gson.fromJson(body, BaseTyre.class);
|
|
|
|
// List<BaseTyre> baseTyreList = gson.fromJson(body, BaseTyre.class);
|
|
|
|
List<BaseTyre> baseTyreList =
|
|
|
|
List<BaseTyre> baseTyreList = gson.fromJson(body, new com.google.gson.reflect.TypeToken<List<BaseTyre>>(){}.getType());
|
|
|
|
gson.fromJson(body, new com.google.gson.reflect.TypeToken<List<BaseTyre>>() {
|
|
|
|
|
|
|
|
}.getType());
|
|
|
|
|
|
|
|
bindDataToViews(baseTyreList);
|
|
|
|
bindDataToViews(baseTyreList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// private void bindDataToViews(List<BaseTyre> dataList) {
|
|
|
|
|
|
|
|
// // 假设 dataList.get(0) 是左前轮,dataList.get(1) 是右前轮...
|
|
|
|
|
|
|
|
// // 请根据你实际的列表顺序调整索引
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if (dataList.size() >= 2) {
|
|
|
|
|
|
|
|
// // 绑定左前轮
|
|
|
|
|
|
|
|
// updateTireView(findViewById(R.id.tire_left_front), dataList.get(0));
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // 绑定右前轮
|
|
|
|
|
|
|
|
// updateTireView(findViewById(R.id.tire_right_front), dataList.get(1));
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // 绑定其他轮胎...
|
|
|
|
|
|
|
|
// // updateTireView(findViewById(R.id.tire_left_mid), dataList.get(2));
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void findCar(String carNumber) {
|
|
|
|
private void findCar(String carNumber) {
|
|
|
|
OkGo.<String>post(MyUrl.url + "/tyre/car/queryCarByRfid").tag(this).params("rfid", carNumber).execute(new StringCallback() {
|
|
|
|
OkGo.<String>post(MyUrl.url + "/tyre/car/queryCarByRfid").tag(this).params("rfid", carNumber).execute(new StringCallback() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@ -377,7 +254,7 @@ public class TyreLayoutActivity extends AppCompatActivity implements CarRecordAd
|
|
|
|
// 空值处理:若字段为 null 则显示空字符串
|
|
|
|
// 空值处理:若字段为 null 则显示空字符串
|
|
|
|
String carNo = safeGetString(baseCar.getCarNo());
|
|
|
|
String carNo = safeGetString(baseCar.getCarNo());
|
|
|
|
etPlateNumber.setText(carNo);
|
|
|
|
etPlateNumber.setText(carNo);
|
|
|
|
} else {
|
|
|
|
}else {
|
|
|
|
new CommonDialog(TyreLayoutActivity.this).setMessage("请检查车辆芯片绑定数据!").show();
|
|
|
|
new CommonDialog(TyreLayoutActivity.this).setMessage("请检查车辆芯片绑定数据!").show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (JsonSyntaxException e) {
|
|
|
|
} catch (JsonSyntaxException e) {
|
|
|
|
@ -386,11 +263,9 @@ public class TyreLayoutActivity extends AppCompatActivity implements CarRecordAd
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String safeGetString(String value) {
|
|
|
|
private String safeGetString(String value) {
|
|
|
|
return value == null || "null".equals(value) ? "" : value;
|
|
|
|
return value == null || "null".equals(value) ? "" : value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 核心方法:将数据绑定到具体的 Include 视图上
|
|
|
|
* 核心方法:将数据绑定到具体的 Include 视图上
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ -417,15 +292,15 @@ public class TyreLayoutActivity extends AppCompatActivity implements CarRecordAd
|
|
|
|
targetView = findViewById(R.id.tire_middle_left);
|
|
|
|
targetView = findViewById(R.id.tire_middle_left);
|
|
|
|
TextView viewById = targetView.findViewById(R.id.iv_tire_icon);
|
|
|
|
TextView viewById = targetView.findViewById(R.id.iv_tire_icon);
|
|
|
|
viewById.setText("左内轮");
|
|
|
|
viewById.setText("左内轮");
|
|
|
|
} else if ("右内轮".equals(pos)) {
|
|
|
|
}else if ("右内轮".equals(pos)) {
|
|
|
|
targetView = findViewById(R.id.tire_middle_right);
|
|
|
|
targetView = findViewById(R.id.tire_middle_right);
|
|
|
|
TextView viewById = targetView.findViewById(R.id.iv_tire_icon);
|
|
|
|
TextView viewById = targetView.findViewById(R.id.iv_tire_icon);
|
|
|
|
viewById.setText("右内轮");
|
|
|
|
viewById.setText("右内轮");
|
|
|
|
} else if ("左外轮".equals(pos)) {
|
|
|
|
}else if ("左外轮".equals(pos)) {
|
|
|
|
targetView = findViewById(R.id.tire_bottom_left);
|
|
|
|
targetView = findViewById(R.id.tire_bottom_left);
|
|
|
|
TextView viewById = targetView.findViewById(R.id.iv_tire_icon);
|
|
|
|
TextView viewById = targetView.findViewById(R.id.iv_tire_icon);
|
|
|
|
viewById.setText("左外轮");
|
|
|
|
viewById.setText("左外轮");
|
|
|
|
} else if ("右外轮".equals(pos)) {
|
|
|
|
}else if ("右外轮".equals(pos)) {
|
|
|
|
targetView = findViewById(R.id.tire_bottom_right);
|
|
|
|
targetView = findViewById(R.id.tire_bottom_right);
|
|
|
|
TextView viewById = targetView.findViewById(R.id.iv_tire_icon);
|
|
|
|
TextView viewById = targetView.findViewById(R.id.iv_tire_icon);
|
|
|
|
viewById.setText("右外轮");
|
|
|
|
viewById.setText("右外轮");
|
|
|
|
@ -437,10 +312,24 @@ public class TyreLayoutActivity extends AppCompatActivity implements CarRecordAd
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// private void bindDataToViews(List<BaseTyre> dataList) {
|
|
|
|
|
|
|
|
// // 假设 dataList.get(0) 是左前轮,dataList.get(1) 是右前轮...
|
|
|
|
|
|
|
|
// // 请根据你实际的列表顺序调整索引
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if (dataList.size() >= 2) {
|
|
|
|
|
|
|
|
// // 绑定左前轮
|
|
|
|
|
|
|
|
// updateTireView(findViewById(R.id.tire_left_front), dataList.get(0));
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // 绑定右前轮
|
|
|
|
|
|
|
|
// updateTireView(findViewById(R.id.tire_right_front), dataList.get(1));
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // 绑定其他轮胎...
|
|
|
|
|
|
|
|
// // updateTireView(findViewById(R.id.tire_left_mid), dataList.get(2));
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 通用方法:更新单个轮胎卡片的 UI
|
|
|
|
* 通用方法:更新单个轮胎卡片的 UI
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param container include 标签对应的根布局 View
|
|
|
|
* @param container include 标签对应的根布局 View
|
|
|
|
* @param data 该轮胎的数据对象
|
|
|
|
* @param data 该轮胎的数据对象
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ -456,7 +345,7 @@ public class TyreLayoutActivity extends AppCompatActivity implements CarRecordAd
|
|
|
|
if (tvBrand != null) tvBrand.setText("品牌: " + data.getTyreBrand());
|
|
|
|
if (tvBrand != null) tvBrand.setText("品牌: " + data.getTyreBrand());
|
|
|
|
if (tvSpec != null) tvSpec.setText("规格: " + data.getTyreModel());
|
|
|
|
if (tvSpec != null) tvSpec.setText("规格: " + data.getTyreModel());
|
|
|
|
if (tvSelfNo != null) tvSelfNo.setText("自编号: " + data.getSelfNo());
|
|
|
|
if (tvSelfNo != null) tvSelfNo.setText("自编号: " + data.getSelfNo());
|
|
|
|
// if (tvDate != null) tvDate.setText("日期: " + data.getCreateTime());
|
|
|
|
if (tvDate != null) tvDate.setText("日期: " + data.getCreateTime());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void addToList(final List<EPC> list, final String epc, final byte rssi) {
|
|
|
|
private void addToList(final List<EPC> list, final String epc, final byte rssi) {
|
|
|
|
@ -472,7 +361,7 @@ public class TyreLayoutActivity extends AppCompatActivity implements CarRecordAd
|
|
|
|
list.add(epcTag);
|
|
|
|
list.add(epcTag);
|
|
|
|
listepc.add(epc);
|
|
|
|
listepc.add(epc);
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
}else {
|
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
|
EPC mEPC = list.get(i);
|
|
|
|
EPC mEPC = list.get(i);
|
|
|
|
// list contain this epc
|
|
|
|
// list contain this epc
|
|
|
|
@ -501,13 +390,13 @@ public class TyreLayoutActivity extends AppCompatActivity implements CarRecordAd
|
|
|
|
nextTime = lastTime;
|
|
|
|
nextTime = lastTime;
|
|
|
|
Log.e("TAG", "run: " + time);
|
|
|
|
Log.e("TAG", "run: " + time);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (listepc != null && !listepc.isEmpty()) {
|
|
|
|
if (listepc != null && !listepc.isEmpty()){
|
|
|
|
startFlag = false;
|
|
|
|
startFlag = false;
|
|
|
|
String currentEpc = listepc.get(0);
|
|
|
|
String currentEpc = listepc.get(0);
|
|
|
|
if (isInRange(currentEpc, min, max)) {
|
|
|
|
if (isInRange(currentEpc, min, max)) {
|
|
|
|
// 请求后台 查询车辆信息
|
|
|
|
//请求后台 查询车辆信息
|
|
|
|
// car.setText(currentEpc);
|
|
|
|
// car.setText(currentEpc);
|
|
|
|
// 请求后台
|
|
|
|
//请求后台
|
|
|
|
debounceHandler.removeMessages(1);
|
|
|
|
debounceHandler.removeMessages(1);
|
|
|
|
lastScannedEpc = currentEpc;
|
|
|
|
lastScannedEpc = currentEpc;
|
|
|
|
debounceHandler.sendEmptyMessageDelayed(1, DEBOUNCE_DELAY);
|
|
|
|
debounceHandler.sendEmptyMessageDelayed(1, DEBOUNCE_DELAY);
|
|
|
|
@ -519,52 +408,50 @@ public class TyreLayoutActivity extends AppCompatActivity implements CarRecordAd
|
|
|
|
});
|
|
|
|
});
|
|
|
|
Log.e("EPC", "listepc:+ " + listepc);
|
|
|
|
Log.e("EPC", "listepc:+ " + listepc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 判断字符串是否在指定的区间内(包含边界)
|
|
|
|
|
|
|
|
* @param target 要判断的目标字符串
|
|
|
|
|
|
|
|
* @param min 区间左边界
|
|
|
|
|
|
|
|
* @param max 区间右边界
|
|
|
|
|
|
|
|
* @return true=在区间内,false=不在
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static boolean isInRange(String target, String min, String max) {
|
|
|
|
|
|
|
|
// 空值校验,避免空指针异常
|
|
|
|
|
|
|
|
if (target == null || min == null || max == null) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// compareTo规则:
|
|
|
|
|
|
|
|
// 1. 字符串相等返回0;
|
|
|
|
|
|
|
|
// 2. 目标字符串 > 对比字符串 返回正数;
|
|
|
|
|
|
|
|
// 3. 目标字符串 < 对比字符串 返回负数。
|
|
|
|
|
|
|
|
// 因此:target >= min 等价于 target.compareTo(min) >= 0;
|
|
|
|
|
|
|
|
// target <= max 等价于 target.compareTo(max) <= 0。
|
|
|
|
|
|
|
|
return target.compareTo(min) >= 0 && target.compareTo(max) <= 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 防抖延迟时间 (毫秒)
|
|
|
|
|
|
|
|
private static final long DEBOUNCE_DELAY = 500;
|
|
|
|
|
|
|
|
// 用于存储最后一次扫描到的 EPC
|
|
|
|
|
|
|
|
private String lastScannedEpc;
|
|
|
|
|
|
|
|
// 用于处理防抖逻辑的 Handler
|
|
|
|
|
|
|
|
private Handler debounceHandler = new Handler(new Handler.Callback() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public boolean handleMessage(Message msg) {
|
|
|
|
|
|
|
|
if (msg.what == 1 && lastScannedEpc != null) {
|
|
|
|
|
|
|
|
// 延迟时间到,执行查询
|
|
|
|
|
|
|
|
showLoadingDialog();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//查询车辆数据方法
|
|
|
|
|
|
|
|
findCar(lastScannedEpc);
|
|
|
|
|
|
|
|
lastScannedEpc = null; // 清空,等待下一次扫描
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
private void clearData() {
|
|
|
|
private void clearData() {
|
|
|
|
listEPC.removeAll(listEPC);
|
|
|
|
listEPC.removeAll(listEPC);
|
|
|
|
listepc.removeAll(listepc);
|
|
|
|
listepc.removeAll(listepc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void registerReceiver() {
|
|
|
|
|
|
|
|
keyReceiver = new KeyReceiver();
|
|
|
|
|
|
|
|
IntentFilter filter = new IntentFilter();
|
|
|
|
|
|
|
|
filter.addAction("android.rfid.FUN_KEY");
|
|
|
|
|
|
|
|
filter.addAction("android.intent.action.FUN_KEY");
|
|
|
|
|
|
|
|
registerReceiver(keyReceiver, filter);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void unregisterReceiver() {
|
|
|
|
|
|
|
|
unregisterReceiver(keyReceiver);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void showLoadingDialog() {
|
|
|
|
|
|
|
|
progressDialog = new ProgressDialog(this);
|
|
|
|
|
|
|
|
progressDialog.setMessage("数据加载中...");
|
|
|
|
|
|
|
|
progressDialog.setCancelable(false);
|
|
|
|
|
|
|
|
progressDialog.show();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void hideLoadingDialog() {
|
|
|
|
|
|
|
|
if (progressDialog != null && progressDialog.isShowing()) {
|
|
|
|
|
|
|
|
progressDialog.dismiss();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 1. 定义数据模型类 (对应后台返回的字段)
|
|
|
|
|
|
|
|
public static class TireData {
|
|
|
|
|
|
|
|
public String position; // 轮位名称
|
|
|
|
|
|
|
|
public String brand; // 品牌
|
|
|
|
|
|
|
|
public String spec; // 规格
|
|
|
|
|
|
|
|
public String installDate; // 安装日期
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public TireData(String position, String brand, String spec, String installDate) {
|
|
|
|
|
|
|
|
this.position = position;
|
|
|
|
|
|
|
|
this.brand = brand;
|
|
|
|
|
|
|
|
this.spec = spec;
|
|
|
|
|
|
|
|
this.installDate = installDate;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private class KeyReceiver extends BroadcastReceiver {
|
|
|
|
private class KeyReceiver extends BroadcastReceiver {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
@ -587,26 +474,35 @@ public class TyreLayoutActivity extends AppCompatActivity implements CarRecordAd
|
|
|
|
case KeyEvent.KEYCODE_F4:
|
|
|
|
case KeyEvent.KEYCODE_F4:
|
|
|
|
case KeyEvent.KEYCODE_F5:
|
|
|
|
case KeyEvent.KEYCODE_F5:
|
|
|
|
case 136:
|
|
|
|
case 136:
|
|
|
|
// 扫描
|
|
|
|
//扫描
|
|
|
|
startFlag = true;
|
|
|
|
startFlag = true;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void registerReceiver() {
|
|
|
|
|
|
|
|
keyReceiver = new KeyReceiver();
|
|
|
|
|
|
|
|
IntentFilter filter = new IntentFilter();
|
|
|
|
|
|
|
|
filter.addAction("android.rfid.FUN_KEY");
|
|
|
|
|
|
|
|
filter.addAction("android.intent.action.FUN_KEY");
|
|
|
|
|
|
|
|
registerReceiver(keyReceiver, filter);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void unregisterReceiver() {
|
|
|
|
|
|
|
|
unregisterReceiver(keyReceiver);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class InventoryThread extends Thread {
|
|
|
|
class InventoryThread extends Thread {
|
|
|
|
byte[] accessPassword = Tools.HexString2Bytes("00000000");
|
|
|
|
|
|
|
|
private List<TagModel> tagList;
|
|
|
|
private List<TagModel> tagList;
|
|
|
|
|
|
|
|
byte[] accessPassword = Tools.HexString2Bytes("00000000");
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
public void run() {
|
|
|
|
super.run();
|
|
|
|
super.run();
|
|
|
|
while (runFlag) {
|
|
|
|
while (runFlag) {
|
|
|
|
if (startFlag) {
|
|
|
|
if (startFlag) {
|
|
|
|
tagList = manager.inventoryRealTime(); // 实时盘存
|
|
|
|
tagList = manager.inventoryRealTime(); //实时盘存
|
|
|
|
if (tagList != null && !tagList.isEmpty()) {
|
|
|
|
if (tagList != null && !tagList.isEmpty()) {
|
|
|
|
// 播放提示音
|
|
|
|
//播放提示音
|
|
|
|
Util.play(1, 0);
|
|
|
|
Util.play(1, 0);
|
|
|
|
for (TagModel tag : tagList) {
|
|
|
|
for (TagModel tag : tagList) {
|
|
|
|
if (tag == null) {
|
|
|
|
if (tag == null) {
|
|
|
|
@ -614,8 +510,7 @@ public class TyreLayoutActivity extends AppCompatActivity implements CarRecordAd
|
|
|
|
// String epcStr = new String(epc);
|
|
|
|
// String epcStr = new String(epc);
|
|
|
|
addToList(listEPC, epcStr, (byte) -1);
|
|
|
|
addToList(listEPC, epcStr, (byte) -1);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
String epcStr =
|
|
|
|
String epcStr = Tools.Bytes2HexString(tag.getmEpcBytes(), tag.getmEpcBytes().length);
|
|
|
|
Tools.Bytes2HexString(tag.getmEpcBytes(), tag.getmEpcBytes().length);
|
|
|
|
|
|
|
|
// String epcStr = new String(epc);
|
|
|
|
// String epcStr = new String(epc);
|
|
|
|
byte rssi = tag.getmRssi();
|
|
|
|
byte rssi = tag.getmRssi();
|
|
|
|
addToList(listEPC, epcStr, rssi);
|
|
|
|
addToList(listEPC, epcStr, rssi);
|
|
|
|
@ -634,4 +529,16 @@ public class TyreLayoutActivity extends AppCompatActivity implements CarRecordAd
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void showLoadingDialog() {
|
|
|
|
|
|
|
|
progressDialog = new ProgressDialog(this);
|
|
|
|
|
|
|
|
progressDialog.setMessage("数据加载中...");
|
|
|
|
|
|
|
|
progressDialog.setCancelable(false);
|
|
|
|
|
|
|
|
progressDialog.show();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void hideLoadingDialog() {
|
|
|
|
|
|
|
|
if (progressDialog != null && progressDialog.isShowing()) {
|
|
|
|
|
|
|
|
progressDialog.dismiss();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|