|
|
@@ -0,0 +1,386 @@ |
|
|
|
package com.huntersun.vkyes.etcopencard.project.ui.activity.after; |
|
|
|
|
|
|
|
import android.annotation.SuppressLint; |
|
|
|
import android.app.Activity; |
|
|
|
import android.bluetooth.BluetoothAdapter; |
|
|
|
import android.content.Intent; |
|
|
|
import android.text.TextUtils; |
|
|
|
|
|
|
|
import androidx.annotation.NonNull; |
|
|
|
|
|
|
|
import com.blankj.utilcode.util.LogUtils; |
|
|
|
import com.hjq.base.BaseDialog; |
|
|
|
import com.huntersun.vky.obublelib.box.BoxManagers; |
|
|
|
import com.huntersun.vkyes.etcopencard.project.api.MyRetrofit; |
|
|
|
import com.huntersun.vkyes.etcopencard.project.api.Result; |
|
|
|
import com.huntersun.vkyes.etcopencard.project.api.bean.IFCode; |
|
|
|
import com.huntersun.vkyes.etcopencard.project.api.bean.ResultBean; |
|
|
|
import com.huntersun.vkyes.etcopencard.project.bluetooth.BluetoothDialog; |
|
|
|
import com.huntersun.vkyes.etcopencard.project.bluetooth.BluetoothWriteCardWriteTab; |
|
|
|
import com.huntersun.vkyes.etcopencard.project.bluetooth.MethodManager; |
|
|
|
import com.huntersun.vkyes.etcopencard.project.bluetooth.ServiceStatus; |
|
|
|
import com.huntersun.vkyes.etcopencard.project.bluetooth.bean.CardReadInfoBean; |
|
|
|
import com.huntersun.vkyes.etcopencard.project.bluetooth.bean.ObuReadInfoBean; |
|
|
|
import com.huntersun.vkyes.etcopencard.project.dialog.PercentageProgressDialog; |
|
|
|
import com.huntersun.vkyes.etcopencard.project.tool.DateUtils; |
|
|
|
import com.huntersun.vkyes.etcopencard.src.app.AppActivity; |
|
|
|
import com.huntersun.vkyes.etcopencard.src.ui.dialog.MessageDialog; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
public class RenewUtils { |
|
|
|
|
|
|
|
private AppActivity context; |
|
|
|
|
|
|
|
private String renewalType; |
|
|
|
private String cardId; |
|
|
|
private String obuId; |
|
|
|
private String oldObuExpireTime; |
|
|
|
private String oldCardExpireTime; |
|
|
|
|
|
|
|
private PercentageProgressDialog progressDialog; |
|
|
|
RenewlCallback callback; |
|
|
|
|
|
|
|
public RenewUtils(AppActivity context,String renewalType,String oldCardExpireTime,String oldObuExpireTime,RenewlCallback callback){ |
|
|
|
this.oldCardExpireTime = oldCardExpireTime; |
|
|
|
this.oldObuExpireTime = oldObuExpireTime; |
|
|
|
this.renewalType = renewalType; |
|
|
|
this.context = context; |
|
|
|
this.callback = callback; |
|
|
|
initProgress(); |
|
|
|
} |
|
|
|
|
|
|
|
interface RenewlCallback{ |
|
|
|
void success(); |
|
|
|
void fail(); |
|
|
|
} |
|
|
|
|
|
|
|
private void initProgress() { |
|
|
|
progressDialog = new PercentageProgressDialog(context); |
|
|
|
progressDialog.setMessage("正在续期中..."); |
|
|
|
} |
|
|
|
|
|
|
|
private void callback(boolean success){ |
|
|
|
if (callback!=null){ |
|
|
|
if (success) { |
|
|
|
callback.success(); |
|
|
|
}else{ |
|
|
|
callback.fail(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//续期 |
|
|
|
public void renewl() { |
|
|
|
new BluetoothDialog.Builder(context).setResult(new BluetoothDialog.Builder.OnResult() { |
|
|
|
/** |
|
|
|
* 未打开的蓝牙 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public void unopenedBluetooth() { |
|
|
|
Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); |
|
|
|
context.startActivityForResult(intent, 1); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 蓝牙连接成功 |
|
|
|
* @param boxManagers 盒子对象 |
|
|
|
*/ |
|
|
|
@SuppressLint("LogNotTimber") |
|
|
|
@Override |
|
|
|
public void BluetoothLinkIsSuccessful(BoxManagers boxManagers) { |
|
|
|
context.showDialog("读取卡签信息"); |
|
|
|
versionCheck(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void BluetoothLinkIsSuccessful9901(int code, int isPlk) { |
|
|
|
context.showDialog("读取卡签信息"); |
|
|
|
BluetoothDialog.Builder.readObu(new BluetoothDialog.ReadObuCallBack() { |
|
|
|
@Override |
|
|
|
public void onSuccess(String s) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onSuccessObuBean(ObuReadInfoBean obuInfoBean) { |
|
|
|
BluetoothDialog.Builder.readCard(new BluetoothDialog.ReadCardCallBack() { |
|
|
|
@Override |
|
|
|
public void onSuccess(String s) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onSuccessCardBean(CardReadInfoBean cardInfoBean) { |
|
|
|
context.hideDialog(); |
|
|
|
renewlCardAndObuApply(cardInfoBean.cardNo,obuInfoBean.num,isPlk); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFail(String s) { |
|
|
|
LogUtils.e(s); |
|
|
|
context.hideDialog(); |
|
|
|
callback(false); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFail(String s) { |
|
|
|
LogUtils.e(s); |
|
|
|
context.hideDialog(); |
|
|
|
callback(false); |
|
|
|
|
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
}) |
|
|
|
.show(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 卡签版本校验 |
|
|
|
*/ |
|
|
|
private void versionCheck() { |
|
|
|
// HashMap<String, String> params = new HashMap<>(); |
|
|
|
// params.put("transOrderId", transOrderId); |
|
|
|
// params.put("cmd", cmd); |
|
|
|
// params.put("cmdResult", cmdResult); |
|
|
|
// params.put("stepNo", stepNo); |
|
|
|
// MyRetrofit.newInstance(IFCode.IFCODE_VERSION_CHECK, params, new MyRetrofit.ReturnResult() { |
|
|
|
// @Override |
|
|
|
// public void onSuccess(ResultBean resultBean, ResultBean.BizContent bizContent) { |
|
|
|
// if ("100".equals(bizContent.stepNo)) { |
|
|
|
String enableTime = DateUtils.date2Str(DateUtils.yyyyMMdd); |
|
|
|
String expireTime = DateUtils.getYearsAdd(10, DateUtils.yyyyMMdd); |
|
|
|
BoxManagers.gerBoxManager().writeSystem(enableTime+expireTime); |
|
|
|
BoxManagers.gerBoxManager().ReadCard(); |
|
|
|
context.hideDialog(); |
|
|
|
renewlCardAndObuApply(BoxManagers.mCardInfoBean.getCard_No(),BoxManagers.mWriteVehicleInfoBean.getContractNo(),-1); |
|
|
|
// } else { |
|
|
|
// if ("CARD".equals(bizContent.cmdType)) { |
|
|
|
// String cmdResult = BluetoothWriteCardWriteTab.writeCard(bizContent.getCommand()); |
|
|
|
// versionCheck(bizContent.transOrderId, bizContent.cmd, cmdResult, bizContent.stepNo, bizContent1); |
|
|
|
// } else { |
|
|
|
// ServiceStatus ss = MethodManager.sendApduEsam(bizContent.getCommand()); |
|
|
|
// versionCheck(bizContent.transOrderId, bizContent.cmd, ss.getServiceInfo(), bizContent.stepNo, bizContent1); |
|
|
|
// } |
|
|
|
// } |
|
|
|
// } |
|
|
|
// }); |
|
|
|
LogUtils.e("非国密续期====================="); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 续期申请 |
|
|
|
* |
|
|
|
* @param |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public void renewlCardAndObuApply(String cardId,String obuId,int isPlk) { |
|
|
|
this.cardId = cardId; |
|
|
|
this.obuId = obuId; |
|
|
|
context.runOnUiThread(new Runnable() { |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
progressDialog.setProgress(5); |
|
|
|
progressDialog.show(); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
HashMap<String, String> parmas = new HashMap<>(); |
|
|
|
parmas.put("renewalType", renewalType); |
|
|
|
parmas.put("cardId", cardId); |
|
|
|
parmas.put("obuId", obuId); |
|
|
|
MyRetrofit.newInstanceGZ(IFCode.IFCODE_RENEWL, parmas, new MyRetrofit.ReturnResult() { |
|
|
|
@Override |
|
|
|
public void onSuccess(ResultBean resultBean, ResultBean.BizContent bizContent) { |
|
|
|
if (null != bizContent.cmd) { |
|
|
|
context.runOnUiThread(new Runnable() { |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
progressDialog.setProgress((Integer.parseInt(bizContent.stepNo) + 1) * 5); |
|
|
|
}}); |
|
|
|
if ("CARD".equals(bizContent.cmdType)) { |
|
|
|
if (isPlk!=-1){ |
|
|
|
BluetoothDialog.Builder.transCmd(bizContent.cmd.split(","), "10", new BluetoothDialog.PerformCmdCallBack() { |
|
|
|
@Override |
|
|
|
public void performOnSuccess(String[] strings) { |
|
|
|
activationReCallBack(bizContent.cmd, TextUtils.join(",",strings), bizContent.stepNo, bizContent.transOrderId,isPlk); |
|
|
|
} |
|
|
|
}); |
|
|
|
}else { |
|
|
|
String cmdResult = BluetoothWriteCardWriteTab.writeCard(bizContent.cmd); |
|
|
|
activationReCallBack(bizContent.cmd, cmdResult, bizContent.stepNo, bizContent.transOrderId,isPlk); |
|
|
|
} |
|
|
|
} else { |
|
|
|
if (isPlk != -1){ |
|
|
|
BluetoothDialog.Builder.transCmd(bizContent.cmd.split(","), "20", new BluetoothDialog.PerformCmdCallBack() { |
|
|
|
@Override |
|
|
|
public void performOnSuccess(String[] strings) { |
|
|
|
activationReCallBack(bizContent.cmd, TextUtils.join(",",strings), bizContent.stepNo, bizContent.transOrderId,isPlk); |
|
|
|
} |
|
|
|
}); |
|
|
|
}else { |
|
|
|
StringBuilder buffer = writeObu(bizContent.cmd); |
|
|
|
activationReCallBack(bizContent.cmd, buffer.toString(), bizContent.stepNo, bizContent.transOrderId,isPlk); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
context.runOnUiThread(new Runnable() { |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
progressDialog.dismiss(); |
|
|
|
|
|
|
|
new MessageDialog.Builder(context) |
|
|
|
.setCancel(null) |
|
|
|
.setTitle("提示") |
|
|
|
.setConfirm("确认") |
|
|
|
.setMessage("指令为空") |
|
|
|
.show(); |
|
|
|
}}); |
|
|
|
callback(false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onError(Result resp) { |
|
|
|
progressDialog.dismiss(); |
|
|
|
new MessageDialog.Builder(context) |
|
|
|
.setCancel(null) |
|
|
|
.setTitle("提示") |
|
|
|
.setConfirm("确认") |
|
|
|
.setMessage(resp.message) |
|
|
|
.show(); |
|
|
|
callback(false); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
@NonNull |
|
|
|
private StringBuilder writeObu(String cmd) { |
|
|
|
String[] commands_arry = cmd.split(","); //命令排列 |
|
|
|
String[] results = new String[commands_arry.length]; //结果 |
|
|
|
int len = results.length; |
|
|
|
int split = 0; |
|
|
|
for (int i = 0; i < len; i++) { |
|
|
|
//透传写卡指令 |
|
|
|
ServiceStatus resp_string = MethodManager.sendApduEsam(commands_arry[i]); |
|
|
|
results[i] = resp_string.getServiceInfo(); |
|
|
|
} |
|
|
|
//分隔字符流文件 |
|
|
|
StringBuilder buffer = new StringBuilder(); |
|
|
|
for (int i = 0; i < len; i++) { |
|
|
|
buffer.append(results[i]); |
|
|
|
if (i != len - 1) { |
|
|
|
buffer.append(","); |
|
|
|
} |
|
|
|
} |
|
|
|
return buffer; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* @param cmd 指令 |
|
|
|
* @param cmdResult 结果 |
|
|
|
* @param stepNo 步骤号 |
|
|
|
* @param transOrderId 二发订单号 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
public void activationReCallBack(String cmd, String cmdResult, String stepNo, String transOrderId,int isPlk) { |
|
|
|
HashMap<String, String> params = new HashMap<>(); |
|
|
|
params.put("transOrderId", transOrderId); |
|
|
|
params.put("cmd", cmd); |
|
|
|
params.put("cmdResult", cmdResult); |
|
|
|
params.put("stepNo", stepNo); |
|
|
|
MyRetrofit.newInstanceGZ(IFCode.IFCODE_RW_RENEWL, params, new MyRetrofit.ReturnResult() { |
|
|
|
@Override |
|
|
|
public void onSuccess(ResultBean resultBean, ResultBean.BizContent bizContent) { |
|
|
|
progressDialog.setProgress((Integer.parseInt(bizContent.stepNo)+1)*5); |
|
|
|
if ("100".equals(bizContent.stepNo)) { |
|
|
|
// LiveEventBus.get("homeOneUpdateData").post(""); |
|
|
|
progressDialog.dismiss(); |
|
|
|
confirm(); |
|
|
|
} else { |
|
|
|
if (null != bizContent.cmd) { |
|
|
|
if ("CARD".equals(bizContent.cmdType)) { |
|
|
|
if (isPlk!=-1){ |
|
|
|
BluetoothDialog.Builder.transCmd(bizContent.cmd.split(","), "10", new BluetoothDialog.PerformCmdCallBack() { |
|
|
|
@Override |
|
|
|
public void performOnSuccess(String[] strings) { |
|
|
|
activationReCallBack(bizContent.cmd,TextUtils.join(",",strings), bizContent.stepNo, bizContent.transOrderId,isPlk); |
|
|
|
} |
|
|
|
}); |
|
|
|
}else { |
|
|
|
String cmdResult = BluetoothWriteCardWriteTab.writeCard(bizContent.cmd); |
|
|
|
activationReCallBack(bizContent.cmd, cmdResult, bizContent.stepNo, bizContent.transOrderId,isPlk); |
|
|
|
} |
|
|
|
} else { |
|
|
|
if (isPlk != -1){ |
|
|
|
BluetoothDialog.Builder.transCmd(bizContent.cmd.split(","), "20", new BluetoothDialog.PerformCmdCallBack() { |
|
|
|
@Override |
|
|
|
public void performOnSuccess(String[] strings) { |
|
|
|
activationReCallBack(bizContent.cmd, TextUtils.join(",",strings), bizContent.stepNo, bizContent.transOrderId,isPlk); |
|
|
|
} |
|
|
|
}); |
|
|
|
}else { |
|
|
|
StringBuilder buffer = writeObu(bizContent.cmd); |
|
|
|
activationReCallBack(bizContent.cmd, buffer.toString(), bizContent.stepNo, bizContent.transOrderId,isPlk); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onError(Result resp) { |
|
|
|
progressDialog.dismiss(); |
|
|
|
new MessageDialog.Builder(context) |
|
|
|
.setCancel(null) |
|
|
|
.setConfirm("确认") |
|
|
|
.setMessage(resp.message) |
|
|
|
.show(); |
|
|
|
callback(false); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
void confirm(){ |
|
|
|
HashMap<String, String> params = new HashMap<>(); |
|
|
|
params.put("renewalType", renewalType); |
|
|
|
params.put("cardId", cardId); |
|
|
|
params.put("obuId", obuId); |
|
|
|
params.put("stepNo", "100"); |
|
|
|
params.put("oldCardExpireTime",oldCardExpireTime); |
|
|
|
params.put("oldObuExpireTime",oldObuExpireTime); |
|
|
|
MyRetrofit.newInstanceGZ(IFCode.IFCODE_RENEWL_CONFIRM, params, new MyRetrofit.ReturnResult() { |
|
|
|
@Override |
|
|
|
public void onSuccess(ResultBean resultBean, ResultBean.BizContent bizContent) { |
|
|
|
new MessageDialog.Builder(context) |
|
|
|
.setCancel(null) |
|
|
|
.setConfirm("确认") |
|
|
|
.setMessage("续期成功") |
|
|
|
.setListener(new MessageDialog.OnListener() { |
|
|
|
@Override |
|
|
|
public void onConfirm(BaseDialog dialog) { |
|
|
|
callback(true); |
|
|
|
} |
|
|
|
}) |
|
|
|
.show(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onError(Result resp) { |
|
|
|
new MessageDialog.Builder(context) |
|
|
|
.setCancel(null) |
|
|
|
.setConfirm("确认") |
|
|
|
.setMessage(resp.message) |
|
|
|
.show(); |
|
|
|
callback(false); |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
} |