| | |
| | | import android.os.Bundle; |
| | | import android.os.Handler; |
| | | import android.os.Message; |
| | | import android.os.SystemClock; |
| | | import android.text.Editable; |
| | | import android.text.SpannableString; |
| | | import android.text.Spanned; |
| | |
| | | import com.doumee.keyCabinet.MApplication; |
| | | import com.doumee.keyCabinet.R; |
| | | import com.doumee.keyCabinet.base.MyBaseActivity; |
| | | import com.doumee.keyCabinet.dao.DaoManager; |
| | | import com.doumee.keyCabinet.dao.FingerPrintDo; |
| | | import com.doumee.keyCabinet.databinding.FaceActivityBinding; |
| | | import com.doumee.keyCabinet.event.FaceStatusChangeEvent; |
| | | import com.doumee.keyCabinet.event.HttpEvent; |
| | | import com.doumee.keyCabinet.event.JiujinBeginEvent; |
| | | import com.doumee.keyCabinet.event.JiujinResultEvent; |
| | | import com.doumee.keyCabinet.event.RefreshFingerEvent; |
| | | import com.doumee.keyCabinet.event.TimeClockEvent; |
| | | import com.doumee.keyCabinet.ui.keyCabinet.KeyCabinetActivity; |
| | | import com.doumee.keyCabinet.utils.BraceletLogUtils; |
| | | import com.doumee.keyCabinet.utils.face.FaceUtils; |
| | | import com.doumee.keyCabinet.utils.face.model.SingleBaseConfig; |
| | | import com.doumee.keyCabinet.utils.usb.DevComm; |
| | | import com.doumee.keyCabinet.utils.usb.IUsbConnState; |
| | | import com.doumee.lib_coremodel.bean.event.ActionEventData; |
| | | import com.doumee.lib_coremodel.util.SpUtil; |
| | | import com.doumee.lib_coremodel.util.StringUtil; |
| | | import com.doumee.lib_coremodel.view.ToastView; |
| | | import com.example.datalibrary.callback.CameraDataCallback; |
| | | import com.example.datalibrary.callback.FaceDetectCallBack; |
| | | import com.example.datalibrary.db.DBManager; |
| | | import com.example.datalibrary.gatecamera.CameraPreviewManager; |
| | | import com.example.datalibrary.gl.view.GlMantleSurfacView; |
| | | import com.example.datalibrary.manager.FaceSDKManager; |
| | |
| | | @Override |
| | | public void initData(@Nullable Bundle savedInstanceState) { |
| | | //getPermission(); |
| | | initDev(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | getDB().clZw.setVisibility(View.GONE); |
| | | getDB().clFace.setVisibility(View.VISIBLE); |
| | | setFaceModel(0); |
| | | setFingerStatus(1); |
| | | break; |
| | | case 10: |
| | | //取-管理员指纹验证 |
| | |
| | | getDB().clFace.setVisibility(View.GONE); |
| | | getDB().clZw.setVisibility(View.VISIBLE); |
| | | setFaceModel(2); |
| | | setFingerStatus(0); |
| | | break; |
| | | case 1: |
| | | //取-管理员刷卡验证 |
| | |
| | | getDB().clZw.setVisibility(View.GONE); |
| | | getDB().clCard.setVisibility(View.VISIBLE); |
| | | setFaceModel(2); |
| | | setFingerStatus(1); |
| | | break; |
| | | case 5: |
| | | //取-司机验证方式选择页 |
| | |
| | | getDB().clSjXuan.setVisibility(View.GONE); |
| | | getDB().clFace.setVisibility(View.VISIBLE); |
| | | setFaceModel(1); |
| | | setFingerStatus(1); |
| | | break; |
| | | case 11: |
| | | //取-司机指纹验证 |
| | |
| | | getDB().clSjXuan.setVisibility(View.GONE); |
| | | getDB().clZw.setVisibility(View.VISIBLE); |
| | | setFaceModel(2); |
| | | setFingerStatus(0); |
| | | break; |
| | | case 3: |
| | | //取-司机刷卡验证 |
| | |
| | | getDB().clSjXuan.setVisibility(View.GONE); |
| | | getDB().clCard.setVisibility(View.VISIBLE); |
| | | setFaceModel(2); |
| | | setFingerStatus(1); |
| | | break; |
| | | case 4: |
| | | //取-司机酒精检测 |
| | |
| | | getDB().clZw.setVisibility(View.GONE); |
| | | getDB().clFace.setVisibility(View.VISIBLE); |
| | | setFaceModel(1); |
| | | setFingerStatus(1); |
| | | break; |
| | | case 12: |
| | | //还-司机人脸验证 |
| | | //还-司机指纹验证 |
| | | getDB().tvTitle.setText("司机身份验证"); |
| | | getDB().clCard.setVisibility(View.GONE); |
| | | getDB().clFace.setVisibility(View.GONE); |
| | | getDB().clZw.setVisibility(View.VISIBLE); |
| | | setFaceModel(2); |
| | | setFingerStatus(0); |
| | | break; |
| | | case 8: |
| | | //还-司机刷卡验证 |
| | |
| | | getDB().clFace.setVisibility(View.GONE); |
| | | getDB().clCard.setVisibility(View.VISIBLE); |
| | | setFaceModel(2); |
| | | setFingerStatus(1); |
| | | break; |
| | | case 9: |
| | | //取-司机酒精检测失败 |
| | |
| | | } |
| | | } |
| | | |
| | | private void setFingerStatus(int fs){ |
| | | if(fs==0){ |
| | | //开始检测 |
| | | identify(); |
| | | }else { |
| | | //关闭检测 |
| | | mBCancel = true; |
| | | } |
| | | } |
| | | |
| | | private Bitmap bitmap; |
| | | private byte[] secondFeature = new byte[512]; |
| | | @Override |
| | |
| | | } |
| | | break; |
| | | case 9: |
| | | //管理员指纹验证 |
| | | statusFsm(10); |
| | | //指纹验证 |
| | | if(status==0) { |
| | | statusFsm(10); |
| | | }else { |
| | | statusFsm(12); |
| | | } |
| | | break; |
| | | case 10: |
| | | //司机指纹验证 |
| | |
| | | faceDetectCallBack = null; |
| | | glMantleSurfacView = null; |
| | | FaceSDKManager.getInstance().destroy(); |
| | | mBCancel = true; |
| | | if(mDevComm!=null){ |
| | | mDevComm.CloseComm(); |
| | | } |
| | | } |
| | | |
| | | private int resultCount = 0; |
| | |
| | | } |
| | | } |
| | | |
| | | /**------------------------指纹模块--------------------------*/ |
| | | |
| | | private void getUserIdByFingerId(int fingerId){ |
| | | runOnUiThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | FingerPrintDo printDo = DaoManager.getFingerPrintDao().getByFingerId(fingerId); |
| | | if(printDo!=null){ |
| | | if(status==10){ |
| | | //取-管理员指纹验证 |
| | | MApplication.getLoginBean().setAutoMemberId(printDo.getMemberId()); |
| | | EventBus.getDefault().post(new FaceStatusChangeEvent(5)); |
| | | }else if(status==11){ |
| | | //取-司机指纹验证 |
| | | MApplication.getLoginBean().setMemberId(printDo.getMemberId()); |
| | | MApplication.getLoginBean().setAuthType(2); |
| | | if(MApplication.getConfigBean()!=null&&MApplication.getConfigBean().getAlcoholStatus()==1) { |
| | | //非酒精检测 |
| | | startActivity(KeyCabinetActivity.class); |
| | | finish(); |
| | | }else { |
| | | //酒精检测 |
| | | EventBus.getDefault().post(new FaceStatusChangeEvent(4)); |
| | | } |
| | | }else if(status==12){ |
| | | //还-司机 |
| | | MApplication.getLoginBean().setMemberId(printDo.getMemberId()); |
| | | MApplication.getLoginBean().setAuthType(2); |
| | | startActivity(KeyCabinetActivity.class); |
| | | finish(); |
| | | } |
| | | }else { |
| | | //找不到,删除指纹 |
| | | if(deleteID(fingerId)) { |
| | | //继续查指纹 |
| | | identify(); |
| | | }else { |
| | | showToast("未查询到用户"); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | private static DevComm mDevComm; |
| | | //是否结束录入 |
| | | private boolean mBCancel = true; |
| | | private byte[] m_binImage = new byte[1024 * 100]; |
| | | private final IUsbConnState m_IConnectionHandler = new IUsbConnState() { |
| | | @Override |
| | | public void onUsbConnected() { |
| | | //String[] w_strInfo = new String[1]; |
| | | /*if (mDevComm.Run_TestConnection() == DevComm.ERR_SUCCESS) { |
| | | if (mDevComm.Run_GetDeviceInfo(w_strInfo) == DevComm.ERR_SUCCESS) { |
| | | |
| | | getVM().addInfo("连接usb成功"); |
| | | }else { |
| | | getVM().addInfo("连接设备失败1," + mDevComm.Run_GetDeviceInfo(w_strInfo)); |
| | | } |
| | | } else { |
| | | getVM().addInfo("连接设备失败2," + mDevComm.Run_TestConnection()); |
| | | }*/ |
| | | } |
| | | |
| | | @Override |
| | | public void onUsbPermissionDenied() { |
| | | Toast.makeText(mContext, "无设备权限", Toast.LENGTH_SHORT).show(); |
| | | } |
| | | |
| | | @Override |
| | | public void onDeviceNotFound() { |
| | | Toast.makeText(mContext, "未发现指纹设备", Toast.LENGTH_SHORT).show(); |
| | | } |
| | | }; |
| | | |
| | | private void initDev(){ |
| | | mDevComm = new DevComm(this, m_IConnectionHandler); |
| | | openDevice(); |
| | | } |
| | | /** |
| | | * 开启设备 |
| | | */ |
| | | private void openDevice() { |
| | | String[] w_strInfo = new String[1]; |
| | | |
| | | if (mDevComm != null) { |
| | | if (!mDevComm.IsInit()) { |
| | | if (mDevComm.OpenComm("USB", 19200) == false) { |
| | | EventBus.getDefault().post(new HttpEvent("初始化设备失败")); |
| | | return; |
| | | } |
| | | } |
| | | if (mDevComm.Run_TestConnection() == DevComm.ERR_SUCCESS) { |
| | | if (mDevComm.Run_GetDeviceInfo(w_strInfo) == DevComm.ERR_SUCCESS) { |
| | | EventBus.getDefault().post(new HttpEvent("开启设备成功")); |
| | | } else { |
| | | EventBus.getDefault().post(new HttpEvent("连接设备失败3," + mDevComm.Run_GetDeviceInfo(w_strInfo))); |
| | | } |
| | | } else { |
| | | runOnUiThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | EventBus.getDefault().post(new HttpEvent("连接设备失败4,"+mDevComm.Run_TestConnection())); |
| | | } |
| | | }); |
| | | mDevComm.CloseComm(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void identify() { |
| | | if (!mDevComm.IsInit()) |
| | | return; |
| | | |
| | | mBCancel = false; |
| | | new Thread(new Runnable() { |
| | | int w_nRet; |
| | | int[] w_nID = new int[1]; |
| | | int[] w_nLearned = new int[1]; |
| | | int[] w_nWidth = new int[1]; |
| | | int[] w_nHeight = new int[1]; |
| | | |
| | | @Override |
| | | public void run() { |
| | | |
| | | while (true) { |
| | | if(mBCancel){ |
| | | //停止 |
| | | return; |
| | | } |
| | | if (capturing() < 0) |
| | | return; |
| | | //松开手指 |
| | | |
| | | // Up Cpatured Image |
| | | if (mDevComm.m_nConnected == 2) { |
| | | w_nRet = mDevComm.Run_UpImage(0, m_binImage, w_nWidth, w_nHeight); |
| | | |
| | | if (w_nRet != DevComm.ERR_SUCCESS) { |
| | | showToast(DevComm.GetErrorMsg(w_nRet)); |
| | | return; |
| | | } |
| | | } |
| | | |
| | | // Create template |
| | | w_nRet = mDevComm.Run_Generate(0); |
| | | |
| | | if (w_nRet != DevComm.ERR_SUCCESS) { |
| | | if (w_nRet == DevComm.ERR_CONNECTION) { |
| | | showToast(DevComm.GetErrorMsg(w_nRet)); |
| | | return; |
| | | } else { |
| | | SystemClock.sleep(1000); |
| | | continue; |
| | | } |
| | | } |
| | | |
| | | // Identify |
| | | w_nRet = mDevComm.Run_Search(0, 1, 500, w_nID, w_nLearned); |
| | | if(mBCancel){ |
| | | //停止 |
| | | return; |
| | | } |
| | | if (w_nRet == DevComm.ERR_SUCCESS) { |
| | | //找到了 |
| | | //showToast("找到了,"+w_nID[0]); |
| | | getUserIdByFingerId(w_nID[0]); |
| | | break; |
| | | //m_strPost = String.format("Result : Success\r\nTemplate No : %d, Learn Result : %d\r\nMatch Time : %dms", w_nID[0], w_nLearned[0], m_nPassedTime); |
| | | } else { |
| | | //没找到 |
| | | //showToast("没找到"); |
| | | /*m_strPost = String.format("\r\nMatch Time : %dms", m_nPassedTime); |
| | | m_strPost = GetErrorMsg(w_nRet) + m_strPost;*/ |
| | | } |
| | | } |
| | | } |
| | | }).start(); |
| | | } |
| | | |
| | | /** |
| | | * 获取指纹 |
| | | * @return |
| | | */ |
| | | private int capturing() { |
| | | int w_nRet; |
| | | while (true) { |
| | | if(isFinishing()){ |
| | | break; |
| | | } |
| | | w_nRet = mDevComm.Run_GetImage(); |
| | | |
| | | if (w_nRet == DevComm.ERR_CONNECTION) { |
| | | showToast("通信错误!"); |
| | | return -1; |
| | | } else if (w_nRet == DevComm.ERR_SUCCESS) { |
| | | break; |
| | | } |
| | | if (mBCancel) { |
| | | return -1; |
| | | } |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | private boolean deleteID(int fingerId) { |
| | | int m_nUserID = fingerId; |
| | | int w_nRet; |
| | | |
| | | if (!mDevComm.IsInit()) |
| | | return false; |
| | | |
| | | w_nRet = mDevComm.Run_DelChar(m_nUserID, m_nUserID); |
| | | if (w_nRet != DevComm.ERR_SUCCESS&&w_nRet!=DevComm.ERR_TMPL_EMPTY) { |
| | | //删除失败 |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | private void showToast(String msg){ |
| | | if(!isFinishing()){ |
| | | runOnUiThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | Toast.makeText(mContext, msg, Toast.LENGTH_SHORT).show(); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | } |