| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.doumee.keyCabinet.ui.face; |
| | | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.annotation.Nullable; |
| | | |
| | | import android.content.Context; |
| | | import android.graphics.Bitmap; |
| | | import android.hardware.Camera; |
| | | import android.os.Bundle; |
| | | import android.os.Handler; |
| | | import android.os.Message; |
| | | import android.text.TextUtils; |
| | | import android.view.View; |
| | | |
| | | import com.baidu.idl.main.facesdk.model.BDFaceSDKCommon; |
| | | import com.doumee.keyCabinet.MApplication; |
| | | import com.doumee.keyCabinet.R; |
| | | import com.doumee.keyCabinet.base.MyBaseActivity; |
| | | import com.doumee.keyCabinet.databinding.FaceActivityBinding; |
| | | 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.lib_coremodel.bean.event.ActionEventData; |
| | | import com.doumee.lib_coremodel.util.SpUtil; |
| | | import com.example.datalibrary.callback.CameraDataCallback; |
| | | import com.example.datalibrary.callback.FaceDetectCallBack; |
| | | import com.example.datalibrary.gatecamera.CameraPreviewManager; |
| | | import com.example.datalibrary.gl.view.GlMantleSurfacView; |
| | | import com.example.datalibrary.manager.FaceSDKManager; |
| | | import com.example.datalibrary.model.BDFaceCheckConfig; |
| | | import com.example.datalibrary.model.BDFaceImageConfig; |
| | | import com.example.datalibrary.model.LivenessModel; |
| | | import com.example.datalibrary.model.User; |
| | | import com.example.datalibrary.utils.FaceOnDrawTexturViewUtil; |
| | | |
| | | import org.greenrobot.eventbus.Subscribe; |
| | | |
| | | import dagger.hilt.android.AndroidEntryPoint; |
| | | |
| | | @AndroidEntryPoint |
| | | public class FaceActivity extends MyBaseActivity<FaceVM, FaceActivityBinding> implements View.OnClickListener{ |
| | | |
| | | /*å¾çè¶å¤§ï¼æ§è½æ¶èè¶å¤§ï¼ä¹å¯ä»¥éæ©640*480ï¼ 1280*720*/ |
| | | private static final int PREFER_WIDTH = SingleBaseConfig.getBaseConfig().getRgbAndNirWidth(); |
| | | private static final int PERFER_HEIGH = SingleBaseConfig.getBaseConfig().getRgbAndNirHeight(); |
| | | private Context mContext; |
| | | private boolean isCompareCheck = true; |
| | | |
| | | private User mUser; |
| | | |
| | | private GlMantleSurfacView glMantleSurfacView; |
| | | private BDFaceImageConfig bdFaceImageConfig; |
| | | private BDFaceCheckConfig bdFaceCheckConfig; |
| | | //0ï¼åï¼1ï¼è¿ |
| | | private int flag ; |
| | | private int status; |
| | | |
| | | @Override |
| | | public int getLayoutId() { |
| | | return R.layout.face_activity; |
| | | } |
| | | |
| | | @Override |
| | | public void initView(@Nullable Bundle savedInstanceState) { |
| | | isToGuild = false; |
| | | normalConfig(); |
| | | getDB().setModel(getVM()); |
| | | mContext = this; |
| | | flag = MApplication.getLoginBean().getFlag(); |
| | | statusFsm(flag==0?0:2); |
| | | //todo wmf è§£å¼ |
| | | /*FaceSDKManager.getInstance().initDataBases(this); |
| | | initFaceCheck();*/ |
| | | initView(); |
| | | } |
| | | |
| | | @Override |
| | | public void initData(@Nullable Bundle savedInstanceState) { |
| | | //getPermission(); |
| | | } |
| | | |
| | | @Override |
| | | protected void timeChange(String djs) { |
| | | getDB().tvDjs.setText(djs); |
| | | } |
| | | |
| | | private void statusFsm(int toStatus){ |
| | | status = toStatus; |
| | | switch (status){ |
| | | case 0: |
| | | //å-管çå人è¸éªè¯ |
| | | getDB().clLogin.setVisibility(View.VISIBLE); |
| | | getDB().tvTitle.setText("管çå身份éªè¯"); |
| | | getDB().vSl.setBackgroundResource(R.mipmap.ic_viewfinder); |
| | | getDB().tvTip.setText("è¯·ä¿ææ£è¸å¨åæ¯æ¡ä¸ï¼å¹¶æ ¹æ®æç¤ºå®æè¯å«"); |
| | | getDB().clRemind.setVisibility(View.VISIBLE); |
| | | getDB().btSk.setVisibility(View.VISIBLE); |
| | | |
| | | getDB().clSjRl.setVisibility(View.GONE); |
| | | getDB().clSjSk.setVisibility(View.GONE); |
| | | getDB().clTip1.setVisibility(View.GONE); |
| | | break; |
| | | case 1: |
| | | //å-管çåå·å¡éªè¯ |
| | | getDB().clLogin.setVisibility(View.VISIBLE); |
| | | getDB().tvTitle.setText("管çå身份éªè¯"); |
| | | getDB().vSl.setBackgroundResource(R.mipmap.ic_shuaka2); |
| | | getDB().tvTip.setText("请å°ICå¡è´´è¿å·å¡åºï¼åç1-2ç§"); |
| | | getDB().clRemind.setVisibility(View.GONE); |
| | | getDB().btSk.setVisibility(View.GONE); |
| | | |
| | | getDB().clSjRl.setVisibility(View.GONE); |
| | | getDB().clSjSk.setVisibility(View.VISIBLE); |
| | | getDB().clTip1.setVisibility(View.GONE); |
| | | break; |
| | | case 5: |
| | | //å-叿ºéªè¯æ¹å¼éæ©é¡µ |
| | | getDB().clLogin.setVisibility(View.VISIBLE); |
| | | getDB().tvTitle.setText("叿ºèº«ä»½éªè¯"); |
| | | getDB().vSl.setBackgroundResource(R.mipmap.ic_face); |
| | | getDB().tvTip.setText("è¯·ä¿ææ£è¸å¨åæ¯æ¡ä¸ï¼å¹¶æ ¹æ®æç¤ºå®æè¯å«"); |
| | | getDB().clRemind.setVisibility(View.VISIBLE); |
| | | getDB().btSk.setVisibility(View.GONE); |
| | | |
| | | getDB().clSjRl.setVisibility(View.VISIBLE); |
| | | getDB().clSjSk.setVisibility(View.GONE); |
| | | getDB().clTip1.setVisibility(View.GONE); |
| | | break; |
| | | case 2: |
| | | //å-叿ºäººè¸éªè¯ |
| | | getDB().clLogin.setVisibility(View.VISIBLE); |
| | | getDB().tvTitle.setText("叿ºèº«ä»½éªè¯"); |
| | | getDB().vSl.setBackgroundResource(R.mipmap.ic_viewfinder); |
| | | getDB().tvTip.setText("è¯·ä¿ææ£è¸å¨åæ¯æ¡ä¸ï¼å¹¶æ ¹æ®æç¤ºå®æè¯å«"); |
| | | getDB().clRemind.setVisibility(View.VISIBLE); |
| | | getDB().btSk.setVisibility(View.VISIBLE); |
| | | |
| | | getDB().clSjRl.setVisibility(View.GONE); |
| | | getDB().clSjSk.setVisibility(View.GONE); |
| | | getDB().clTip1.setVisibility(View.GONE); |
| | | break; |
| | | case 3: |
| | | //å-叿ºå·å¡éªè¯ |
| | | getDB().clLogin.setVisibility(View.VISIBLE); |
| | | getDB().tvTitle.setText("叿ºèº«ä»½éªè¯"); |
| | | getDB().vSl.setBackgroundResource(R.mipmap.ic_shuaka2); |
| | | getDB().tvTip.setText("请å°ICå¡è´´è¿å·å¡åºï¼åç1-2ç§"); |
| | | getDB().clRemind.setVisibility(View.GONE); |
| | | getDB().btSk.setVisibility(View.GONE); |
| | | |
| | | getDB().clSjRl.setVisibility(View.GONE); |
| | | getDB().clSjSk.setVisibility(View.VISIBLE); |
| | | getDB().clTip1.setVisibility(View.GONE); |
| | | break; |
| | | case 4: |
| | | //å-叿ºé
ç²¾æ£æµ |
| | | getDB().clLogin.setVisibility(View.VISIBLE); |
| | | getDB().tvTitle.setText("é
ç²¾æ£æµ"); |
| | | getDB().vSl.setBackgroundResource(R.mipmap.ic_jiujingjiance); |
| | | getDB().tvTip.setText("请æ¿èµ·é
ç²¾æ£æµä»ªå¹æ°"); |
| | | getDB().clRemind.setVisibility(View.GONE); |
| | | getDB().btSk.setVisibility(View.GONE); |
| | | |
| | | getDB().clSjRl.setVisibility(View.GONE); |
| | | getDB().clSjSk.setVisibility(View.GONE); |
| | | getDB().clTip1.setVisibility(View.GONE); |
| | | break; |
| | | case 6: |
| | | //å-叿ºé
ç²¾æ£æµå¤±è´¥ |
| | | getDB().clTip1.setVisibility(View.VISIBLE); |
| | | break; |
| | | case 7: |
| | | //è¿-叿ºäººè¸éªè¯ |
| | | getDB().clLogin.setVisibility(View.VISIBLE); |
| | | getDB().tvTitle.setText("叿ºèº«ä»½éªè¯"); |
| | | getDB().vSl.setBackgroundResource(R.mipmap.ic_viewfinder); |
| | | getDB().tvTip.setText("è¯·ä¿ææ£è¸å¨åæ¯æ¡ä¸ï¼å¹¶æ ¹æ®æç¤ºå®æè¯å«"); |
| | | getDB().clRemind.setVisibility(View.VISIBLE); |
| | | getDB().btSk.setVisibility(View.VISIBLE); |
| | | |
| | | getDB().clSjSk.setVisibility(View.GONE); |
| | | getDB().clSjRl.setVisibility(View.GONE); |
| | | getDB().clTip1.setVisibility(View.GONE); |
| | | break; |
| | | case 8: |
| | | //è¿-叿ºå·å¡éªè¯ |
| | | getDB().clLogin.setVisibility(View.VISIBLE); |
| | | getDB().tvTitle.setText("叿ºèº«ä»½éªè¯"); |
| | | getDB().vSl.setBackgroundResource(R.mipmap.ic_shuaka2); |
| | | getDB().tvTip.setText("请å°ICå¡è´´è¿å·å¡åºï¼åç1-2ç§"); |
| | | getDB().clRemind.setVisibility(View.GONE); |
| | | getDB().btSk.setVisibility(View.GONE); |
| | | |
| | | getDB().clSjSk.setVisibility(View.VISIBLE); |
| | | getDB().clSjRl.setVisibility(View.GONE); |
| | | getDB().clTip1.setVisibility(View.GONE); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | |
| | | private Bitmap bitmap; |
| | | private byte[] secondFeature = new byte[512]; |
| | | @Override |
| | | protected void doRegister(int type, ActionEventData data) { |
| | | switch (type){ |
| | | case 1: |
| | | //忢å°å·å¡ |
| | | if("0".equals(flag)){ |
| | | if(status==0){ |
| | | statusFsm(1); |
| | | }else if(status==2){ |
| | | statusFsm(3); |
| | | } |
| | | }else { |
| | | statusFsm(8); |
| | | } |
| | | break; |
| | | case 2: |
| | | //忢叿ºå·å¡ |
| | | statusFsm(3); |
| | | break; |
| | | case 3: |
| | | //忢叿ºäººè¸ |
| | | statusFsm(2); |
| | | break; |
| | | case 4: |
| | | //忢å°äººè¸ |
| | | if("0".equals(flag)){ |
| | | if(status==1){ |
| | | statusFsm(5); |
| | | }else if(status==3){ |
| | | statusFsm(6); |
| | | } |
| | | }else { |
| | | startActivity(KeyCabinetActivity.class); |
| | | finish(); |
| | | } |
| | | |
| | | //todo wmf |
| | | //statusFsm("0".equals(flag)?); |
| | | break; |
| | | case 5: |
| | | startActivity(KeyCabinetActivity.class); |
| | | finish(); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | |
| | | private void initFaceConfig(int height , int width){ |
| | | bdFaceImageConfig = new BDFaceImageConfig(height , width , |
| | | SingleBaseConfig.getBaseConfig().getRgbDetectDirection(), |
| | | SingleBaseConfig.getBaseConfig().getMirrorDetectRGB() , |
| | | BDFaceSDKCommon.BDFaceImageType.BDFACE_IMAGE_TYPE_YUV_NV21); |
| | | } |
| | | private void initFaceCheck(){ |
| | | bdFaceCheckConfig = FaceUtils.getInstance().getBDFaceCheckConfig(); |
| | | } |
| | | |
| | | /** |
| | | * View |
| | | */ |
| | | private void initView() { |
| | | getDB().faceDetectImageView.setVisibility(View.GONE); |
| | | |
| | | glMantleSurfacView = findViewById(R.id.camera_textureview); |
| | | glMantleSurfacView.initSurface(SingleBaseConfig.getBaseConfig().getRgbRevert(), |
| | | SingleBaseConfig.getBaseConfig().getMirrorVideoRGB() , SingleBaseConfig.getBaseConfig().isOpenGl()); |
| | | CameraPreviewManager.getInstance().startPreview(glMantleSurfacView, |
| | | SingleBaseConfig.getBaseConfig().getRgbVideoDirection() , PREFER_WIDTH, PERFER_HEIGH); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | protected void onResume() { |
| | | super.onResume(); |
| | | //todo wmf è§£å¼ |
| | | //startTestOpenDebugRegisterFunction(); |
| | | } |
| | | |
| | | private void startTestOpenDebugRegisterFunction() { |
| | | if(SingleBaseConfig.getBaseConfig().getRBGCameraId()==-1){ |
| | | if(!TextUtils.isEmpty(SpUtil.getString("rbgCameraId"))) { |
| | | SingleBaseConfig.getBaseConfig().setRBGCameraId(Integer.parseInt(SpUtil.getString("rbgCameraId"))); |
| | | } |
| | | } |
| | | if (SingleBaseConfig.getBaseConfig().getRBGCameraId() != -1) { |
| | | BraceletLogUtils.saveLog("使ç¨ç¸æº("+SingleBaseConfig.getBaseConfig().getRBGCameraId()+")"); |
| | | CameraPreviewManager.getInstance().setCameraFacing(SingleBaseConfig.getBaseConfig().getRBGCameraId()); |
| | | } else { |
| | | BraceletLogUtils.saveLog("使ç¨ç¸æº("+CameraPreviewManager.CAMERA_USB+")"); |
| | | CameraPreviewManager.getInstance().setCameraFacing(CameraPreviewManager.CAMERA_USB); |
| | | } |
| | | int[] cameraSize = CameraPreviewManager.getInstance().initCamera(new CameraPreviewManager.ErrInfoCallBack() { |
| | | @Override |
| | | public void err(String errInfo) { |
| | | BraceletLogUtils.saveLog(errInfo); |
| | | } |
| | | }); |
| | | initFaceConfig(cameraSize[1] , cameraSize[0]); |
| | | isPause = true; |
| | | count = 60; |
| | | CameraPreviewManager.getInstance().setmCameraDataCallback(dataCallback); |
| | | } |
| | | |
| | | private CameraDataCallback dataCallback = new CameraDataCallback() { |
| | | @Override |
| | | public void onGetCameraData(byte[] data, Camera camera, int width, int height) { |
| | | if(!isFinishing()){ |
| | | //isCheckFace = true; |
| | | handler.sendEmptyMessageDelayed(1,4000); |
| | | glMantleSurfacView.setFrame(); |
| | | bdFaceImageConfig.setData(data); |
| | | //å¿
é¡»ä¼å |
| | | String groupId = "0"; |
| | | FaceSDKManager.getInstance().onDetectCheck(groupId,bdFaceImageConfig, null, null, |
| | | bdFaceCheckConfig, faceDetectCallBack); |
| | | } |
| | | } |
| | | }; |
| | | //private boolean isCheckFace; |
| | | private FaceDetectCallBack faceDetectCallBack = new FaceDetectCallBack() { |
| | | @Override |
| | | public void onFaceDetectCallback(LivenessModel livenessModel) { |
| | | //System.out.println("==isOk==>onFaceDetectCallback"); |
| | | //System.out.println("==rgbInstance==>onFaceDetectCallback "+livenessModel); |
| | | // å¼åæ¨¡å¼ |
| | | //isCheckFace = false; |
| | | if(handler.hasMessages(1)){ |
| | | handler.removeMessages(1); |
| | | } |
| | | checkOpenDebugResult(livenessModel); |
| | | } |
| | | |
| | | @Override |
| | | public void onTip(int code, String msg) { |
| | | getDB().clFail.setVisibility(View.VISIBLE); |
| | | getDB().tv4.setText(msg); |
| | | handler.sendEmptyMessageDelayed(0,1000); |
| | | System.out.println("==isOk==>onTip:"+msg); |
| | | } |
| | | |
| | | @Override |
| | | public void onFaceDetectDarwCallback(LivenessModel livenessModel) { |
| | | //System.out.println("==rgbInstance==>onFaceDetectDarwCallback"); |
| | | if (isCompareCheck) { |
| | | getDB().clFail.setVisibility(View.VISIBLE); |
| | | getDB().tv4.setText(getString(R.string.face_tip2)); |
| | | handler.sendEmptyMessageDelayed(0,1000); |
| | | } |
| | | // ç»å¶äººè¸æ¡ |
| | | showFrame(livenessModel); |
| | | |
| | | } |
| | | }; |
| | | |
| | | private boolean isPause = false; |
| | | public void showFrame(LivenessModel livenessModel){ |
| | | if(isFinishing()){ |
| | | return; |
| | | } |
| | | if (livenessModel == null){ |
| | | return; |
| | | } |
| | | |
| | | if (isPause){ |
| | | glMantleSurfacView.onGlDraw(livenessModel.getTrackFaceInfo() , |
| | | livenessModel.getBdFaceImageInstance() , |
| | | FaceOnDrawTexturViewUtil.drawFaceColor(mUser , livenessModel)); |
| | | } |
| | | } |
| | | |
| | | private Handler handler = new Handler(){ |
| | | @Override |
| | | public void handleMessage(@NonNull Message msg) { |
| | | switch (msg.what){ |
| | | case 0: |
| | | getDB().clFail.setVisibility(View.GONE); |
| | | break; |
| | | case 1: |
| | | //isCheckFace = false; |
| | | break; |
| | | } |
| | | } |
| | | }; |
| | | |
| | | @Override |
| | | protected void onRestart() { |
| | | super.onRestart(); |
| | | isTimePause = false; |
| | | isToChose = false; |
| | | count = 120; |
| | | } |
| | | |
| | | private int count = 120; |
| | | private boolean isTimePause = false; |
| | | @Subscribe |
| | | public void TimeClockEvent(TimeClockEvent event) { |
| | | if (!isFinishing()&&!isTimePause) { |
| | | if (count > 0) { |
| | | count--; |
| | | if (count == 0) { |
| | | finish(); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | protected void onDestroy() { |
| | | super.onDestroy(); |
| | | handler.removeCallbacksAndMessages(null); |
| | | handler = null; |
| | | dataCallback = null; |
| | | //CameraPreviewManager.getInstance().destroy(); |
| | | faceDetectCallBack = null; |
| | | glMantleSurfacView = null; |
| | | //todo wmf è§£å¼ |
| | | //FaceSDKManager.getInstance().destroy(); |
| | | } |
| | | |
| | | private int resultCount = 0; |
| | | // ***************å¼å模å¼ç»æè¾åº************* |
| | | private void checkOpenDebugResult(final LivenessModel livenessModel) { |
| | | if(isFinishing()){ |
| | | return; |
| | | } |
| | | if(handler==null){ |
| | | return; |
| | | } |
| | | // 彿ªæ£æµå°äººè¸UIæ¾ç¤º |
| | | runOnUiThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | if (livenessModel == null) { |
| | | if (isCompareCheck) { |
| | | getDB().clFail.setVisibility(View.VISIBLE); |
| | | getDB().tv4.setText(getString(R.string.face_tip2)); |
| | | handler.sendEmptyMessageDelayed(0,1000); |
| | | } |
| | | System.out.println("======>人è¸è¯å«å¤±è´¥"); |
| | | return; |
| | | } |
| | | if (livenessModel.isQualityCheck()){ |
| | | //æ¯å¦éè¿è´¨éæ£æµ |
| | | if (isCompareCheck) { |
| | | getDB().clFail.setVisibility(View.VISIBLE); |
| | | getDB().tv4.setText(getString(R.string.face_tip2)); |
| | | handler.sendEmptyMessageDelayed(0,1000); |
| | | } |
| | | } else { |
| | | User user = livenessModel.getUser(); |
| | | if (user == null) { |
| | | mUser = null; |
| | | if (isCompareCheck) { |
| | | getDB().clFail.setVisibility(View.VISIBLE); |
| | | getDB().tv4.setText(getString(R.string.face_tip2)); |
| | | handler.sendEmptyMessageDelayed(0,1000); |
| | | } |
| | | |
| | | } else { |
| | | //ä¼å
ä¼å |
| | | if("0".equals(user.getGroupId())){ |
| | | 11 |
| | | }else { |
| | | if (isCompareCheck) { |
| | | getDB().clFail.setVisibility(View.VISIBLE); |
| | | getDB().tv4.setText(getString(R.string.face_tip2)); |
| | | handler.sendEmptyMessageDelayed(0,1000); |
| | | } |
| | | resultCount++; |
| | | if (resultCount >= 3) { |
| | | resultCount = 0; |
| | | }else { |
| | | return; |
| | | } |
| | | } |
| | | mUser = user; |
| | | if (isCompareCheck) { |
| | | getDB().clFail.setVisibility(View.GONE); |
| | | if(handler.hasMessages(0)) { |
| | | handler.removeMessages(0); |
| | | } |
| | | /*textHuanying.setVisibility(View.GONE); |
| | | userNameLayout.setVisibility(View.VISIBLE); |
| | | nameImage.setImageResource(R.mipmap.ic_tips_gate_success); |
| | | nameText.setTextColor(Color.parseColor("#0dc6ff")); |
| | | nameText.setText(FileUtils.spotString(user.getUserName()) + " æ¬¢è¿æ¨");*/ |
| | | } |
| | | if(!isToChose) { |
| | | isToChose = true; |
| | | //è¯å«æåï¼è·³è½¬ |
| | | Bundle bundle = new Bundle(); |
| | | bundle.putString("busId", user.getUserId()); |
| | | bundle.putString("type", "0"); |
| | | //Toast.makeText(mContext, user.getUserName(), Toast.LENGTH_SHORT).show(); |
| | | //startActivity(ChoseTicketActivity.class, bundle); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | boolean isToChose = false; |
| | | |
| | | @Override |
| | | public void onClick(View v) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | protected void onPause() { |
| | | super.onPause(); |
| | | isPause = false; |
| | | isTimePause = true; |
| | | //todo wmf è§£å¼ |
| | | //CameraPreviewManager.getInstance().stopPreview(); |
| | | } |
| | | } |