Browse Source

fix 4 rebuild code

dev
赵明涛 12 hours ago
parent
commit
e0136b3ddf
  1. 71
      app/src/main/java/com/ouxuan/oxface/OXFaceOnlineActivity.java
  2. 124
      app/src/main/java/com/ouxuan/oxface/device/GateABController.java

71
app/src/main/java/com/ouxuan/oxface/OXFaceOnlineActivity.java

@ -53,8 +53,6 @@ import com.ouxuan.oxface.network.OrderVerificationResultHandler;
import com.ouxuan.oxface.network.LeaveVerificationManager; import com.ouxuan.oxface.network.LeaveVerificationManager;
import com.ouxuan.oxface.utils.VenueSceneUtils; import com.ouxuan.oxface.utils.VenueSceneUtils;
import com.ouxuan.oxface.network.NetworkStatusIndicator; import com.ouxuan.oxface.network.NetworkStatusIndicator;
import com.ouxuan.oxface.device.OxUDP;
import com.ouxuan.oxface.device.OxUDPUsageExample;
import com.ouxuan.oxface.abgate.GateUnavailableDialog; import com.ouxuan.oxface.abgate.GateUnavailableDialog;
import com.ouxuan.oxface.abgate.ABGateManager; import com.ouxuan.oxface.abgate.ABGateManager;
import com.ouxuan.oxface.device.GateABController; import com.ouxuan.oxface.device.GateABController;
@ -196,10 +194,6 @@ public class OXFaceOnlineActivity extends BaseActivity implements View.OnClickLi
// 网络状态指示器 // 网络状态指示器
private NetworkStatusIndicator networkStatusIndicator; private NetworkStatusIndicator networkStatusIndicator;
// UDP门禁控制
private OxUDPUsageExample udpExample;
private boolean isUDPInitialized = false;
// AB门禁不可用弹窗 // AB门禁不可用弹窗
private GateUnavailableDialog gateUnavailableDialog; private GateUnavailableDialog gateUnavailableDialog;
private GateABController gateABController; private GateABController gateABController;
@ -226,9 +220,6 @@ public class OXFaceOnlineActivity extends BaseActivity implements View.OnClickLi
initView(); initView();
// 初始化UDP门禁控制
initializeUDPGateControl();
// 初始化网络状态指示器 // 初始化网络状态指示器
initNetworkStatusIndicator(); initNetworkStatusIndicator();
@ -296,9 +287,9 @@ public class OXFaceOnlineActivity extends BaseActivity implements View.OnClickLi
} }
// 离场校验成功后开启B门 // 离场校验成功后开启B门
if (isUDPInitialized && udpExample != null) {
if (gateABController != null) {
LogManager.logInfo(TAG, "离场校验成功,开启B门"); LogManager.logInfo(TAG, "离场校验成功,开启B门");
udpExample.handleFaceRecognitionSuccess(false); // 参数保留兼容性实际都开B门
gateABController.handleFaceRecognitionSuccess(false); // 参数保留兼容性实际都开B门
} }
} }
}); });
@ -367,9 +358,9 @@ public class OXFaceOnlineActivity extends BaseActivity implements View.OnClickLi
@Override @Override
public void onVerificationSuccess(com.ouxuan.oxface.network.api.PadApiService.CheckOrderResult data, int verificationType) { public void onVerificationSuccess(com.ouxuan.oxface.network.api.PadApiService.CheckOrderResult data, int verificationType) {
// 订单核销成功后开启B门 // 订单核销成功后开启B门
if (isUDPInitialized && udpExample != null) {
if (gateABController != null) {
LogManager.logInfo(TAG, "订单核销成功,开启B门"); LogManager.logInfo(TAG, "订单核销成功,开启B门");
udpExample.handleFaceRecognitionSuccess(true); // 参数保留兼容性实际都开B门
gateABController.handleFaceRecognitionSuccess(true); // 参数保留兼容性实际都开B门
} }
// 然后处理原有的页面跳转逻辑 // 然后处理原有的页面跳转逻辑
@ -623,28 +614,6 @@ public class OXFaceOnlineActivity extends BaseActivity implements View.OnClickLi
} }
/** /**
* 初始化UDP门禁控制
*/
private void initializeUDPGateControl() {
try {
LogManager.logInfo(TAG, "开始初始化UDP门禁控制");
// 初始化UDP使用示例类
udpExample = new OxUDPUsageExample(this);
// 初始化UDP门禁功能
udpExample.initializeInFaceActivity();
isUDPInitialized = true;
LogManager.logInfo(TAG, "UDP门禁控制初始化成功");
} catch (Exception e) {
LogManager.logError(TAG, "UDP门禁控制初始化失败", e);
isUDPInitialized = false;
}
}
/**
* 初始化网络状态指示器 * 初始化网络状态指示器
*/ */
private void initNetworkStatusIndicator() { private void initNetworkStatusIndicator() {
@ -779,13 +748,13 @@ public class OXFaceOnlineActivity extends BaseActivity implements View.OnClickLi
// 人数异常弹窗关闭后恢复正常的门禁监控状态 // 人数异常弹窗关闭后恢复正常的门禁监控状态
try { try {
// 检查UDP是否正常初始化如果没有则重新初始化 // 检查UDP是否正常初始化如果没有则重新初始化
if (udpExample != null && !udpExample.isUDPInitialized()) {
if (gateABController != null && !gateABController.isUDPInitialized()) {
LogManager.logInfo(TAG, "UDP未初始化,重新初始化UDP门禁控制"); LogManager.logInfo(TAG, "UDP未初始化,重新初始化UDP门禁控制");
udpExample.initializeInFaceActivity();
gateABController.reinitializeUDP();
// 稍等片刻后启动轮询确保初始化完成 // 稍等片刻后启动轮询确保初始化完成
new Handler(Looper.getMainLooper()).postDelayed(() -> { new Handler(Looper.getMainLooper()).postDelayed(() -> {
if (udpExample != null) {
udpExample.startGatePolling();
if (gateABController != null) {
gateABController.startUDPPolling();
LogManager.logInfo(TAG, "UDP门禁状态轮询已重新启动"); LogManager.logInfo(TAG, "UDP门禁状态轮询已重新启动");
} }
}, 500); }, 500);
@ -893,8 +862,8 @@ public class OXFaceOnlineActivity extends BaseActivity implements View.OnClickLi
} }
// 启动UDP门禁状态轮询 // 启动UDP门禁状态轮询
if (isUDPInitialized && udpExample != null) {
udpExample.startGatePolling();
if (gateABController != null && gateABController.isUDPInitialized()) {
gateABController.startUDPPolling();
LogManager.logInfo(TAG, "UDP门禁状态轮询已启动"); LogManager.logInfo(TAG, "UDP门禁状态轮询已启动");
} }
@ -1416,14 +1385,6 @@ public class OXFaceOnlineActivity extends BaseActivity implements View.OnClickLi
networkStatusIndicator = null; networkStatusIndicator = null;
} }
// 清理UDP门禁控制资源
if (udpExample != null) {
udpExample.cleanup();
udpExample = null;
LogManager.logInfo(TAG, "UDP门禁控制资源已清理");
}
isUDPInitialized = false;
// 释放AB门禁管理和不可用弹窗资源 // 释放AB门禁管理和不可用弹窗资源
if (gateUnavailableDialog != null) { if (gateUnavailableDialog != null) {
gateUnavailableDialog.release(); gateUnavailableDialog.release();
@ -1491,8 +1452,8 @@ public class OXFaceOnlineActivity extends BaseActivity implements View.OnClickLi
} }
// 停止UDP门禁状态轮询 // 停止UDP门禁状态轮询
if (isUDPInitialized && udpExample != null) {
udpExample.stopGatePolling();
if (gateABController != null) {
gateABController.stopUDPPolling();
LogManager.logInfo(TAG, "UDP门禁状态轮询已停止"); LogManager.logInfo(TAG, "UDP门禁状态轮询已停止");
} }
@ -1717,9 +1678,9 @@ public class OXFaceOnlineActivity extends BaseActivity implements View.OnClickLi
hideLoadingStatus(); hideLoadingStatus();
// 直接开启B门 // 直接开启B门
if (isUDPInitialized && udpExample != null) {
if (gateABController != null) {
LogManager.logInfo(TAG, "gate_enter_open_enable为true,直接开启B门"); LogManager.logInfo(TAG, "gate_enter_open_enable为true,直接开启B门");
udpExample.handleFaceRecognitionSuccess(false); // 参数保留兼容性实际都开B门
gateABController.handleFaceRecognitionSuccess(false); // 参数保留兼容性实际都开B门
} }
} }
}, 2000); }, 2000);
@ -1733,9 +1694,9 @@ public class OXFaceOnlineActivity extends BaseActivity implements View.OnClickLi
showLoadingStatus("网络不可用,直接开门"); showLoadingStatus("网络不可用,直接开门");
// 直接开启B门防止用户卡在场内 // 直接开启B门防止用户卡在场内
if (isUDPInitialized && udpExample != null) {
if (gateABController != null) {
LogManager.logInfo(TAG, "离场场景网络不可用,直接开启B门"); LogManager.logInfo(TAG, "离场场景网络不可用,直接开启B门");
udpExample.handleFaceRecognitionSuccess(false); // 开启B门
gateABController.handleFaceRecognitionSuccess(false); // 开启B门
} }
// 3秒后隐藏提示 // 3秒后隐藏提示

124
app/src/main/java/com/ouxuan/oxface/device/GateABController.java

@ -225,6 +225,8 @@ public class GateABController {
// 初始化UDP控制器 // 初始化UDP控制器
if (udpController != null) { if (udpController != null) {
udpController.initUDP(context); udpController.initUDP(context);
// 设置UDP状态监听器
setupUDPStateListener();
LogManager.logInfo(TAG, "UDP控制器初始化完成"); LogManager.logInfo(TAG, "UDP控制器初始化完成");
} }
@ -1069,6 +1071,128 @@ public class GateABController {
}); });
} }
// ========== UDP状态监听相关方法 ==========
/**
* 设置UDP状态监听器
*/
private void setupUDPStateListener() {
if (udpController == null) {
LogManager.logWarning(TAG, "UDP控制器为空,无法设置状态监听器");
return;
}
// 设置状态监听器
udpController.setStateListener(new OxUDP.UDPStateListener() {
@Override
public void onGateStateUpdate(boolean gateAState, boolean gateBState, String rawData) {
LogManager.logInfo(TAG, "门禁状态更新 - A门: " + (gateAState ? "开启" : "关闭") +
", B门: " + (gateBState ? "开启" : "关闭"));
// 更新门状态到GateABControllerUDP连接状态为true能收到状态说明连接正常
updateGateState(gateAState, gateBState, true, "");
}
@Override
public void onGateOpenResult(String gateType, boolean success) {
LogManager.logInfo(TAG, gateType + "门开启结果: " + (success ? "成功" : "失败"));
}
@Override
public void onUDPError(String error) {
LogManager.logError(TAG, "UDP通信错误: " + error);
// UDP通信错误时设置连接状态为false门状态为false默认关闭
updateGateState(false, false, false, error);
}
});
// 设置设备监听器
udpController.setDeviceListener(new OxUDP.UDPDeviceListener() {
@Override
public void onDeviceInfoUpdate(String deviceInfo) {
LogManager.logInfo(TAG, "设备信息更新: " + deviceInfo);
}
@Override
public void onDeviceConnectionChange(boolean connected) {
LogManager.logInfo(TAG, "设备连接状态: " + (connected ? "已连接" : "已断开"));
if (connected) {
// 设备连接成功开始轮询
startUDPPolling();
} else {
// 设备连接失败设置UDP连接状态为false
updateGateState(false, false, false, "设备连接断开");
}
}
});
LogManager.logInfo(TAG, "UDP状态监听器设置完成");
}
/**
* 开始UDP门禁状态轮询
*/
public void startUDPPolling() {
if (udpController != null) {
LogManager.logInfo(TAG, "开始UDP门禁状态轮询");
udpController.startPolling();
} else {
LogManager.logWarning(TAG, "UDP控制器为空,无法开始轮询");
}
}
/**
* 停止UDP门禁状态轮询
*/
public void stopUDPPolling() {
if (udpController != null) {
LogManager.logInfo(TAG, "停止UDP门禁状态轮询");
udpController.stopPolling();
} else {
LogManager.logWarning(TAG, "UDP控制器为空,无法停止轮询");
}
}
/**
* 重新初始化UDP控制器用于恢复监听器链条
*/
public void reinitializeUDP() {
if (context != null && udpController != null) {
LogManager.logInfo(TAG, "重新初始化UDP控制器");
udpController.initUDP(context);
setupUDPStateListener();
} else {
LogManager.logWarning(TAG, "无法重新初始化UDP,context或udpController为空");
}
}
/**
* 检查UDP是否已初始化
* @return true表示UDP已初始化false表示未初始化
*/
public boolean isUDPInitialized() {
return udpController != null && udpController.isInitialized();
}
/**
* 人脸识别成功后开门处理
* 无论进场还是离场都开启B门
* @param isEntry true: 进门, false: 出门参数保留为兼容性但不影响实际操作
*/
public void handleFaceRecognitionSuccess(boolean isEntry) {
LogManager.logInfo(TAG, "人脸识别成功,准备开B门: " + (isEntry ? "进门场景" : "离场场景"));
// 无论是进场还是离场都开启B门
if (udpController != null && udpController.isInitialized()) {
udpController.openGateB();
LogManager.logInfo(TAG, "人脸识别成功,已发送B门开启命令");
} else {
LogManager.logWarning(TAG, "UDP控制器未初始化,无法开启B门");
}
}
/** /**
* 门禁不可用监听器接口 * 门禁不可用监听器接口
* 扩展GateABStateListener增加弹窗触发功能 * 扩展GateABStateListener增加弹窗触发功能

Loading…
Cancel
Save