Selaa lähdekoodia

修改人脸识别次数
启动页启动数据获取
增加人脸采集信息提示框
其他修改

ifengouy 2 vuotta sitten
vanhempi
commit
f51b953a20

+ 8 - 1
app/src/main/java/com/sunwin/visitorapp/SplashActivity.java

@@ -25,6 +25,7 @@ import com.srp.AuthApi.AuthApplyResponse;
 import com.srp.AuthApi.ErrorCodeConfig;
 import com.sunwin.visitorapp.activity.HomeAc;
 import com.sunwin.visitorapp.face.FRAbsLoopFactory;
+import com.sunwin.visitorapp.service.PullDataService;
 import com.sunwin.visitorapp.utils.AppManager;
 import com.sunwin.visitorapp.utils.Constant;
 import com.sunwin.visitorapp.utils.LogUtil;
@@ -57,6 +58,8 @@ public class SplashActivity extends AppCompatActivity {
         authApi = new AuthApi();
         initData();
         myHandler.sendEmptyMessageDelayed(0, 500);
+
+        PullDataService.enqueueWork(this, new Intent());
     }
 
     @Override
@@ -78,7 +81,10 @@ public class SplashActivity extends AppCompatActivity {
     private void authPermission() {
 
 //        String cert = readExternal(CERT_PATH).trim();
-        String cert = readFile(this);
+        String cert = SharePrefenceUtils.getString(Constant.ISharePrefence.CERT, "");
+        if (TextUtils.isEmpty(cert)){
+            cert = readFile(this);
+        }
         if (TextUtils.isEmpty(cert)) {
 //            Toast.makeText(this, "cert is null", Toast.LENGTH_SHORT).show();
             return;
@@ -130,6 +136,7 @@ public class SplashActivity extends AppCompatActivity {
         } catch (IOException var9) {
             LogUtil.d(TAG, var9.getMessage());
         }
+        SharePrefenceUtils.putString(Constant.ISharePrefence.CERT,content);
         return content;
     }
 

+ 9 - 0
app/src/main/java/com/sunwin/visitorapp/activity/HomeAc.java

@@ -13,6 +13,7 @@ import androidx.fragment.app.FragmentManager;
 import androidx.fragment.app.FragmentTransaction;
 
 import com.sunwin.visitorapp.BaseActivity;
+import com.sunwin.visitorapp.LoginActivity;
 import com.sunwin.visitorapp.R;
 import com.sunwin.visitorapp.fragment.HomeFr;
 import com.sunwin.visitorapp.fragment.RegTypeFragment;
@@ -27,6 +28,7 @@ public class HomeAc extends BaseActivity implements View.OnClickListener, RegTyp
     private UINav mUINav;
     private RelativeLayout mLlHomeTitle;
     private TextView mTextTitle;
+    private TextView tv_loginOut;
     private LinearLayout mViewMenu;
     private ImageView mImageSetting;
 
@@ -94,6 +96,11 @@ public class HomeAc extends BaseActivity implements View.OnClickListener, RegTyp
             case R.id.ImageSetting:
                 startActivity(new Intent(mContext, SettingAc.class));
                 break;
+            case R.id.tv_loginOut:
+                SharePrefenceUtils.putBoolean(Constant.ISharePrefence.LOGINTAG, false);
+                startActivity(new Intent(mContext, LoginActivity.class));
+                finish();
+                break;
         }
     }
 
@@ -101,6 +108,7 @@ public class HomeAc extends BaseActivity implements View.OnClickListener, RegTyp
         mUINav = (UINav) findViewById(R.id.UINav);
         mLlHomeTitle = (RelativeLayout) findViewById(R.id.ll_home_title);
         mLlHomeTitle = (RelativeLayout) findViewById(R.id.ll_home_title);
+        tv_loginOut = findViewById(R.id.tv_loginOut);
         mTextTitle = findViewById(R.id.TextTitle);
         mViewMenu = findViewById(R.id.ViewMenu);
         mImageSetting = findViewById(R.id.ImageSetting);
@@ -111,6 +119,7 @@ public class HomeAc extends BaseActivity implements View.OnClickListener, RegTyp
         findViewById(R.id.MenuItemLeave).setOnClickListener(this);
         findViewById(R.id.MenuItemCheck).setOnClickListener(this);
         findViewById(R.id.ImageSetting).setOnClickListener(this);
+        tv_loginOut.setOnClickListener(this);
         showHome(true);
 
         mViewMenu.setVisibility(isLogin ? View.VISIBLE : View.INVISIBLE);

+ 2 - 0
app/src/main/java/com/sunwin/visitorapp/activity/VisitInputActivity.java

@@ -56,6 +56,8 @@ public class VisitInputActivity extends BaseActivity implements View.OnClickList
             return;
         }
         OpenDoorByFaceNetResultInfo info = new OpenDoorByFaceNetResultInfo();
+        info.setIdNum(idNum);
+        info.setPerson_name(name);
         Intent intent = new Intent(mContext, NoCardRegActivity.class);
         intent.putExtra(Constant.IIntentValue.CURRENTFACEPATH,currentFacePath);
         intent.putExtra(Constant.IIntentValue.RECOGNIZE_INFO,info);

+ 9 - 0
app/src/main/java/com/sunwin/visitorapp/activity/VisitSignActivity.java

@@ -1,5 +1,6 @@
 package com.sunwin.visitorapp.activity;
 
+import android.content.DialogInterface;
 import android.content.Intent;
 import android.os.Bundle;
 import android.text.TextUtils;
@@ -7,8 +8,11 @@ import android.view.View;
 import android.widget.LinearLayout;
 import android.widget.TextView;
 
+import androidx.appcompat.app.AlertDialog;
+
 import com.sunwin.visitorapp.BaseActivity;
 import com.sunwin.visitorapp.BaseApplication;
+import com.sunwin.visitorapp.LoginActivity;
 import com.sunwin.visitorapp.R;
 import com.sunwin.visitorapp.db.DatabaseManager;
 import com.sunwin.visitorapp.db.UserInfoModel;
@@ -21,10 +25,12 @@ import com.sunwin.visitorapp.net.ApiService;
 import com.sunwin.visitorapp.net.BaseRsult;
 import com.sunwin.visitorapp.net.RetrofitUtil;
 import com.sunwin.visitorapp.service.PullDataService;
+import com.sunwin.visitorapp.utils.AppUtil;
 import com.sunwin.visitorapp.utils.BitmapUtils;
 import com.sunwin.visitorapp.utils.Constant;
 import com.sunwin.visitorapp.utils.FileUtil;
 import com.sunwin.visitorapp.utils.LogUtil;
+import com.sunwin.visitorapp.utils.SharePrefenceUtils;
 import com.sunwin.visitorapp.utils.TimeUtils;
 import com.sunwin.visitorapp.utils.ToastUtils;
 import com.sunwin.visitorapp.view.FaceDetecterView;
@@ -146,6 +152,7 @@ public class VisitSignActivity extends BaseActivity implements IdCardReadCallbac
                             boolean b = FileUtil.deleteFile(currentFace);
                             LogUtil.e(TAG, "delete File=" + b);
                         }
+                        ToastUtils.showToast("保存成功");
                     } else {
                         requsetModel.setNeedUpdate(true);
                         ToastUtils.showToast("保存失败");
@@ -190,6 +197,7 @@ public class VisitSignActivity extends BaseActivity implements IdCardReadCallbac
         String idNum = openDoorByFaceNetResultInfo.getIdNum();
         currentFace = openDoorByFaceNetResultInfo.getCurrentFace();
         similarity = openDoorByFaceNetResultInfo.getSimilarity();
+        similarity =  AppUtil.retains3decimal(similarity);
         updataUserInfoByIdNum(idNum, 1);
     }
 
@@ -228,4 +236,5 @@ public class VisitSignActivity extends BaseActivity implements IdCardReadCallbac
             });
         }
     }
+
 }

+ 0 - 1
app/src/main/java/com/sunwin/visitorapp/activity/VisitorRegActivity.java

@@ -50,7 +50,6 @@ public class VisitorRegActivity extends BaseActivity implements View.OnClickList
         visitRegType = getIntent().getIntExtra(Constant.IIntentValue.VISIT_REG_TYPE, 1);
         initialData();
         initView();
-        PullDataService.enqueueWork(this, new Intent());
     }
 
     private void initialData() {

+ 15 - 3
app/src/main/java/com/sunwin/visitorapp/activity/VisitorRegisterAc.java

@@ -1,6 +1,7 @@
 package com.sunwin.visitorapp.activity;
 
 import android.os.Bundle;
+import android.text.TextUtils;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.AdapterView;
@@ -161,6 +162,9 @@ public class VisitorRegisterAc extends BaseActivity implements View.OnClickListe
         showHead(currentFacePath, mImageVisitorPhoto);
         mTextVisitorIdCode.setText(userInfo.getIdNum());
         mTextVisitorName.setText(userInfo.getPerson_name());
+
+        mEditVisitTimeBegin.setText(TimeUtils.stampToDate(System.currentTimeMillis()));
+        mEditVisitTimeEnd.setText(TimeUtils.stampToDate(System.currentTimeMillis()));
     }
 
     private void showHead(String path, ImageView iv_head) {
@@ -188,7 +192,6 @@ public class VisitorRegisterAc extends BaseActivity implements View.OnClickListe
 
     private void submit() {
         UserInfoModel oldUserinfo = null;
-        loadingDialog.showLoadingDialog("");
 
         String phone = mEditPhone.getText().toString().trim();
         String idNum = mTextVisitorIdCode.getText().toString().trim();
@@ -205,6 +208,13 @@ public class VisitorRegisterAc extends BaseActivity implements View.OnClickListe
         String comeReason = mComeReason.getText().toString().trim();
         String company = mEditCompany.getText().toString().trim();
 
+        if (TextUtils.isEmpty(phone)) {
+            ToastUtils.showToast("请输入手机号码");
+            return;
+        }
+
+
+        loadingDialog.showLoadingDialog("");
         UserInfoModel infoModel = new UserInfoModel();
         infoModel.setPhone(phone);
         infoModel.setVisitorLpCode(carPlate);
@@ -222,7 +232,7 @@ public class VisitorRegisterAc extends BaseActivity implements View.OnClickListe
         infoModel.setDeptId(deptNo + "");
         infoModel.setCategoryId(categoryId);
 
-        LogUtil.e(TAG,"categoryName ="+categoryName);
+        LogUtil.e(TAG, "categoryName =" + categoryName);
         List<UserInfoModel> userInfoModels = DatabaseManager.getInstance().query(UserInfoModel.class, "idNum", idNum);
         if (userInfoModels.size() != 0) {
             oldUserinfo = userInfoModels.get(0);
@@ -264,6 +274,8 @@ public class VisitorRegisterAc extends BaseActivity implements View.OnClickListe
                         ToastUtils.showToast("保存成功");
                         finish();
                         AppManager.getAppManager().finishActivity(VisitorRegActivity.class);
+                        AppManager.getAppManager().finishActivity(NoCardRegActivity.class);
+                        AppManager.getAppManager().finishActivity(VisitInputActivity.class);
                     } else {
                         loadingDialog.dismissLoadingDialog();
                         ToastUtils.showToast("保存失败");
@@ -338,7 +350,7 @@ public class VisitorRegisterAc extends BaseActivity implements View.OnClickListe
                     .setDayText("日")
                     .setCyclic(false)
                     .setMinMillseconds(System.currentTimeMillis() - tenYears)
-                    .setMaxMillseconds(System.currentTimeMillis()+tenYears)
+                    .setMaxMillseconds(System.currentTimeMillis() + tenYears)
                     .setCurrentMillseconds(System.currentTimeMillis())
                     .setThemeColor(getResources().getColor(R.color.timepicker_dialog_bg))
                     .setType(Type.YEAR_MONTH_DAY)

+ 2 - 0
app/src/main/java/com/sunwin/visitorapp/camera/CameraSurfaceView.java

@@ -15,6 +15,7 @@ import android.view.SurfaceHolder;
 import android.view.SurfaceView;
 
 import com.guo.android_extend.tools.FrameHelper;
+import com.sunwin.visitorapp.face.SwFaceLoop;
 import com.sunwin.visitorapp.utils.Constant;
 import com.sunwin.visitorapp.utils.LogUtil;
 
@@ -211,6 +212,7 @@ public class CameraSurfaceView extends SurfaceView implements SurfaceHolder.Call
     }
 
     public void reStartCamera() {
+        SwFaceLoop.getInstance().recognizeTime =0;
         openCamera();
         mCamera.setDisplayOrientation(Constant.rotate);
         mCamera.startPreview();

+ 24 - 5
app/src/main/java/com/sunwin/visitorapp/face/SwFaceLoop.java

@@ -59,7 +59,7 @@ public class SwFaceLoop extends FRAbsLoop {
     private boolean isRecognized;
     private ArrayBlockingQueue<CameraPreviewData> mFeedFrameQueue;
     private ArrayBlockingQueue<DetectResult> mDetectResultQueue;
-    private int recognizeTime;
+    public int recognizeTime;
     private RecognizeThread mRecognizeThread;
 
     private String group_name = "facepass";
@@ -406,10 +406,10 @@ public class SwFaceLoop extends FRAbsLoop {
                                 openDoorByFaceNetResultInfo.setIdNum(infoModel.getIdNum());
                                 openDoorByFaceNetResultInfo.setPerson_name(infoModel.getPersonName());
                                 EventBus.getDefault().post(new DescEvent().setDesc(DescEvent.DESC_FR_SUCC).setOpenDoorByFaceNetResultInfo(openDoorByFaceNetResultInfo));
-
+                                recognizeTime = 0;
                             } else {
                                 //未匹配到用户
-                                recognizeNoUser();
+                                recognizeNoUser(result.faceToken);
                             }
 
                         } else {
@@ -428,12 +428,30 @@ public class SwFaceLoop extends FRAbsLoop {
 
     }
 
-    private void recognizeNoUser() {
+    public void resetTraceId() {
+        if (mFacePassHandler != null) {
+            mFacePassHandler.reset();
+        }
+    }
+
+    private void recognizeNoUser(byte[] faceToken) {
         LogUtil.e(TAG, "---------recognizeNoUser---------");
+        try {
+            resetTraceId();
+            mFacePassHandler.deleteFace(faceToken);
+        } catch (FacePassException e) {
+            e.printStackTrace();
+        }
     }
 
     private void recognizeFail() {
-        LogUtil.e(TAG, "---------recognizeFail---------");
+        ++recognizeTime;
+        LogUtil.e(TAG, "recognizeFail==========================recognizeTime = " + recognizeTime);
+        if (recognizeTime == Constant.COMPARSION_FREQUENCY) {
+            EventBus.getDefault().post(new DescEvent().setDesc(DescEvent.DESC_FR_NO_BODY));
+            recognizeTime = 0;
+        }
+        resetTraceId();
     }
 
     private void idCardRecognite(DetectResult detectResult) {
@@ -492,6 +510,7 @@ public class SwFaceLoop extends FRAbsLoop {
                     if (recognizeTime == Constant.COMPARSION_FREQUENCY) {
                         EventBus.getDefault().post(new DescEvent().setDesc(DescEvent.DESC_FR_NO_BODY));
                         idCardInfo = null;
+                        recognizeTime = 0;
                     }
                 }
             } catch (Exception e) {

+ 26 - 4
app/src/main/java/com/sunwin/visitorapp/fragment/NoCardRegFragment.java

@@ -1,5 +1,6 @@
 package com.sunwin.visitorapp.fragment;
 
+import android.content.DialogInterface;
 import android.content.Intent;
 import android.os.Bundle;
 import android.os.Handler;
@@ -9,11 +10,11 @@ import android.view.ViewGroup;
 
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
+import androidx.appcompat.app.AlertDialog;
 
 import com.sunwin.visitorapp.BaseApplication;
 import com.sunwin.visitorapp.BaseFragment;
 import com.sunwin.visitorapp.R;
-import com.sunwin.visitorapp.activity.NoCardRegActivity;
 import com.sunwin.visitorapp.activity.VisitorRegisterAc;
 import com.sunwin.visitorapp.face.CameraPreviewData;
 import com.sunwin.visitorapp.model.OpenDoorByFaceNetResultInfo;
@@ -27,7 +28,6 @@ import org.jetbrains.annotations.NotNull;
 
 import java.io.File;
 import java.io.IOException;
-import java.io.Serializable;
 
 public class NoCardRegFragment extends BaseFragment implements FaceDetecterView.Listener {
     private FaceDetecterView mFaceDetecterView;
@@ -76,12 +76,34 @@ public class NoCardRegFragment extends BaseFragment implements FaceDetecterView.
     private void initView(View view) {
         mFaceDetecterView = view.findViewById(R.id.faceDetecterView);
         mFaceDetecterView.config(mContext, this);
-        mFaceDetecterView.needTakePic = true;
-        BaseApplication.getSystemTTS().playText("请看摄像头");
+        showTipDialog();
+
 
     }
 
 
+    private void showTipDialog() {        // 创建退出对话框
+        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
+        builder.setTitle("温馨提示");
+        builder.setCancelable(false);
+        builder.setMessage("将对您的面部拍摄一张照片,用于人员信息录入,如同意请点击确定");
+        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
+            @Override
+            public void onClick(DialogInterface dialog, int which) {
+                mFaceDetecterView.needTakePic = true;
+                BaseApplication.getSystemTTS().playText("请看摄像头");
+            }
+        });
+        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
+            @Override
+            public void onClick(DialogInterface dialog, int which) {
+                mContext.finish();
+            }
+        });
+        builder.show();
+
+    }
+
     /**
      * ------------------FaceDetecterView.Listener 开始------------------------------
      */

+ 14 - 0
app/src/main/java/com/sunwin/visitorapp/utils/AppUtil.java

@@ -4,6 +4,8 @@ import android.os.Build;
 
 import com.sunwin.visitorapp.BaseApplication;
 
+import java.math.BigDecimal;
+
 public class AppUtil {
     public static String getPackageName(){
         return BaseApplication.getInstance().getPackageName();
@@ -12,4 +14,16 @@ public class AppUtil {
     public  static String getDeviceId(){
         return Build.SERIAL;
     }
+
+    public static double retains3decimal(double num) {
+        String s = num + "";
+        int position = s.length() - s.indexOf(".") - 1;
+        if (position <= 3) {
+            return num;
+        }
+        BigDecimal decimal = new BigDecimal(s);
+        BigDecimal bigDecimal = decimal.setScale(3, BigDecimal.ROUND_DOWN);
+        double v = bigDecimal.doubleValue();
+        return v;
+    }
 }

+ 3 - 2
app/src/main/java/com/sunwin/visitorapp/utils/Constant.java

@@ -1,7 +1,6 @@
 package com.sunwin.visitorapp.utils;
 
 
-import android.app.usage.ExternalStorageStats;
 import android.os.Environment;
 
 public class Constant {
@@ -9,6 +8,7 @@ public class Constant {
     final public static int rotate = SharePrefenceUtils.getInt("cameraRotate", 0);
     final public static boolean isFrontCamera = SharePrefenceUtils.getBoolean("isFrontCamera", false);
     final public static boolean isSufaRotate = SharePrefenceUtils.getBoolean("sufaRotate", false);
+
     public static int COMPARSION_VALUE = SharePrefenceUtils.getInt("comparsion_value", Constant.NumerValue.defaultComparsionValue);
     public static int COMPARSION_FREQUENCY = SharePrefenceUtils.getInt("comparsion_frequency_value", Constant.NumerValue.defaultComparsionFrequency);
     public int AVOID_SAME_PEOPLE_VALUE = SharePrefenceUtils.getInt("avoid_same_people_value", Constant.NumerValue.defaultAvoidSamePeopleValue);
@@ -24,7 +24,7 @@ public class Constant {
     public static final String SWBINDIR = "/sdcard/models";
     public static final String SWRECODE = "/sdcard/swRecode";
 
-    public static final String RecognitionDir = Environment.getExternalStorageDirectory()+"/faceRecognition/"; //记录图片存储位置
+    public static final String RecognitionDir = Environment.getExternalStorageDirectory() + "/faceRecognition/"; //记录图片存储位置
 
     public static volatile boolean isReConnectUsb = false;//是否重新连接
 
@@ -39,6 +39,7 @@ public class Constant {
         String BASEURL = "baseurl";
         String LOGINTAG = "loginTag";
         String ISINIT = "isInit";
+        String CERT = "cert";
     }
 
     public interface ITable {//数据库表相关字段

+ 12 - 1
app/src/main/res/layout/activity_home.xml

@@ -25,7 +25,18 @@
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:orientation="horizontal">
-
+            <TextView
+                android:id="@+id/tv_loginOut"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="退出登录"
+                android:textSize="@dimen/sp_20"
+                android:layout_alignParentLeft="true"
+                android:layout_marginLeft="20dp"
+                android:textColor="@color/black"
+                android:padding="10dp"
+                android:scaleType="fitCenter"
+                android:src="@drawable/ui_vector_setting" />
             <TextView
                 android:id="@+id/TextTitle"
                 android:layout_width="wrap_content"

+ 5 - 1
app/src/main/res/layout/activity_login.xml

@@ -45,7 +45,9 @@
             android:layout_height="wrap_content"
             android:background="@drawable/shape_bg_white_rectangle"
             android:drawablePadding="5dp"
+            android:padding="5dp"
             android:hint="请输入用户名"
+            android:text="admin"
             android:imeOptions="actionNext"
             android:inputType="text"
             android:singleLine="true"
@@ -74,8 +76,10 @@
             android:background="@drawable/shape_bg_white_rectangle"
             android:drawablePadding="5dp"
             android:hint="请输入密码"
+            android:text="123456"
+            android:padding="5dp"
             android:imeOptions="actionNext"
-            android:inputType="text"
+            android:inputType="textPassword"
             android:singleLine="true"
             android:textColor="@color/color_333333"
             android:textSize="@dimen/sp_20" />