Bladeren bron

本地手动选择授权文件进行授权,授权时进行loading提示
解决登记时身份证和姓名加密上传查本地时查不到身份证信息问题

ifengouy 2 jaren geleden
bovenliggende
commit
6e6d5ff02e

+ 1 - 0
app/src/main/AndroidManifest.xml

@@ -40,6 +40,7 @@
         <activity android:name=".activity.VisitSignActivity" />
         <activity android:name=".activity.VisitInputActivity" />
         <activity android:name=".activity.VisitLogActivity" />
+        <activity android:name=".activity.AuthActivity" />
 
         <service
             android:name=".service.PullDataService"

+ 27 - 1
app/src/main/java/com/sunwin/visitorapp/BaseActivity.java

@@ -1,11 +1,13 @@
 package com.sunwin.visitorapp;
 
+import android.content.Intent;
 import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.os.Bundle;
 
 import androidx.appcompat.app.AppCompatActivity;
 
+import com.sunwin.visitorapp.activity.HomeAc;
 import com.sunwin.visitorapp.utils.AppManager;
 import com.sunwin.visitorapp.utils.Constant;
 import com.sunwin.visitorapp.utils.SharePrefenceUtils;
@@ -14,7 +16,7 @@ import com.sunwin.visitorapp.view.LoadingDialog;
 public class BaseActivity extends AppCompatActivity {
 
     protected static String TAG = "";
-    protected AppCompatActivity mContext;
+    protected BaseActivity mContext;
     protected LoadingDialog loadingDialog;
 
     protected boolean isLogin;
@@ -56,4 +58,28 @@ public class BaseActivity extends AppCompatActivity {
         res.updateConfiguration(config, res.getDisplayMetrics());
         return res;
     }
+
+    /**
+     * 进入应用程序
+     */
+    protected void openApplication() {
+        boolean isLogin = SharePrefenceUtils.getBoolean(Constant.ISharePrefence.LOGINTAG, false);
+        if (isLogin) {
+            gotoMain();
+        } else {
+            gotoLogin();
+        }
+    }
+
+    private void gotoMain() {
+        Intent intent = new Intent(this, HomeAc.class);
+        startActivity(intent);
+        finish();
+    }
+
+    private void gotoLogin() {
+        Intent intent = new Intent(this, LoginActivity.class);
+        startActivity(intent);
+        finish();
+    }
 }

+ 19 - 37
app/src/main/java/com/sunwin/visitorapp/SplashActivity.java

@@ -14,16 +14,14 @@ import android.os.Bundle;
 import android.os.Handler;
 import android.os.Message;
 import android.text.TextUtils;
-import android.util.Log;
 
 import androidx.annotation.NonNull;
-import androidx.appcompat.app.AppCompatActivity;
 import androidx.core.app.ActivityCompat;
 
 import com.srp.AuthApi.AuthApi;
 import com.srp.AuthApi.AuthApplyResponse;
 import com.srp.AuthApi.ErrorCodeConfig;
-import com.sunwin.visitorapp.activity.HomeAc;
+import com.sunwin.visitorapp.activity.AuthActivity;
 import com.sunwin.visitorapp.face.FRAbsLoopFactory;
 import com.sunwin.visitorapp.service.PullDataService;
 import com.sunwin.visitorapp.utils.AppManager;
@@ -41,7 +39,7 @@ import java.lang.ref.WeakReference;
 import java.util.ArrayList;
 import java.util.Iterator;
 
-public class SplashActivity extends AppCompatActivity {
+public class SplashActivity extends BaseActivity {
 
     private static final int REQUEST_FOR_PERMISSION = 100;
     private static final String TAG = "SplashActivity";
@@ -72,7 +70,6 @@ public class SplashActivity extends AppCompatActivity {
     }
 
     private void initData() {
-        authPermission();
         initPermission();
         requestDevicePermission();
     }
@@ -81,14 +78,11 @@ public class SplashActivity extends AppCompatActivity {
 
 //        String cert = readExternal(CERT_PATH).trim();
         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();
+            startAuthActivity();
             return;
         }
-
+        loadingDialog.showLoadingDialog("授权中,请等待...");
         authApi.authDevice(this.getApplicationContext(), cert, "", new AuthApi.AuthDeviceCallBack() {
             @Override
             public void GetAuthDeviceResult(final AuthApplyResponse result) {
@@ -100,6 +94,8 @@ public class SplashActivity extends AppCompatActivity {
                             ToastUtils.showToast("Apply update: OK");
                             SharePrefenceUtils.putBoolean(Constant.ISharePrefence.ISINIT, true);
                             new FRAbsLoopFactory().createFRAblLoop(SplashActivity.this, Constant.NumerValue.FRABS_TYPE);
+                            loadingDialog.dismissLoadingDialog();
+                            openApplication();
                         }
                     });
                 } else {
@@ -107,6 +103,8 @@ public class SplashActivity extends AppCompatActivity {
                         @Override
                         public void run() {
                             ToastUtils.showToast("Apply update: error. error code is: " + result.errorCode + " , error message: " + result.errorMessage);
+                            loadingDialog.dismissLoadingDialog();
+                            startAuthActivity();
                         }
                     });
                 }
@@ -115,6 +113,11 @@ public class SplashActivity extends AppCompatActivity {
 
     }
 
+    private void startAuthActivity() {
+        startActivity(new Intent(SplashActivity.this, AuthActivity.class));
+        finish();
+    }
+
     public String readFile(Context context) {
         String content = "";
         try {
@@ -136,7 +139,7 @@ public class SplashActivity extends AppCompatActivity {
         } catch (IOException var9) {
             LogUtil.d(TAG, var9.getMessage());
         }
-        SharePrefenceUtils.putString(Constant.ISharePrefence.CERT,content);
+        SharePrefenceUtils.putString(Constant.ISharePrefence.CERT, content);
         return content;
     }
 
@@ -170,7 +173,7 @@ public class SplashActivity extends AppCompatActivity {
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
             requestPer2();
         } else {
-            openApplication();
+            authAndOpenApplication();
         }
     }
 
@@ -185,7 +188,7 @@ public class SplashActivity extends AppCompatActivity {
             }
         }
         if (permissions.size() == 0) {
-            openApplication();
+            authAndOpenApplication();
             return;
         }
         String[] permissionStr = permissions.toArray(new String[0]);
@@ -201,7 +204,7 @@ public class SplashActivity extends AppCompatActivity {
         switch (requestCode) {
             case REQUEST_FOR_PERMISSION:
                 if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
-                    openApplication();
+                    authAndOpenApplication();
                 } else {
                     ToastUtils.showToast("请您授予应用相应权限!");
                 }
@@ -212,29 +215,8 @@ public class SplashActivity extends AppCompatActivity {
         }
     }
 
-
-    /**
-     * 进入应用程序
-     */
-    private void openApplication() {
-        boolean isLogin = SharePrefenceUtils.getBoolean(Constant.ISharePrefence.LOGINTAG, false);
-        if (isLogin) {
-            gotoMain();
-        } else {
-            gotoLogin();
-        }
-    }
-
-    private void gotoMain() {
-        Intent intent = new Intent(this, HomeAc.class);
-        startActivity(intent);
-        finish();
-    }
-
-    private void gotoLogin() {
-        Intent intent = new Intent(this, LoginActivity.class);
-        startActivity(intent);
-        finish();
+    protected void authAndOpenApplication() {
+        authPermission();
     }
 
     private final String ACTION_USB_PERMISSION = "com.sunwin.visitorapp.USB_PERMISSION";

+ 116 - 0
app/src/main/java/com/sunwin/visitorapp/activity/AuthActivity.java

@@ -0,0 +1,116 @@
+package com.sunwin.visitorapp.activity;
+
+import android.os.Bundle;
+import android.os.Environment;
+import android.text.TextUtils;
+import android.widget.Button;
+
+import androidx.annotation.NonNull;
+
+import com.github.gzuliyujiang.filepicker.ExplorerConfig;
+import com.github.gzuliyujiang.filepicker.FileExplorer;
+import com.github.gzuliyujiang.filepicker.annotation.ExplorerMode;
+import com.github.gzuliyujiang.filepicker.contract.OnFileClickedListener;
+import com.srp.AuthApi.AuthApi;
+import com.srp.AuthApi.AuthApplyResponse;
+import com.srp.AuthApi.ErrorCodeConfig;
+import com.sunwin.visitorapp.BaseActivity;
+import com.sunwin.visitorapp.R;
+import com.sunwin.visitorapp.face.FRAbsLoopFactory;
+import com.sunwin.visitorapp.utils.Constant;
+import com.sunwin.visitorapp.utils.FileUtil;
+import com.sunwin.visitorapp.utils.SharePrefenceUtils;
+import com.sunwin.visitorapp.utils.ToastUtils;
+import com.sunwin.visitorapp.view.UINav;
+
+import org.jetbrains.annotations.NotNull;
+
+import java.io.File;
+
+public class AuthActivity extends BaseActivity implements OnFileClickedListener {
+    private FileExplorer mFileExplorer;
+    private Button mBtnAuth;
+    private AuthApi authApi;
+    private UINav mUINav;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_auth);
+
+        authApi = new AuthApi();
+        initView();
+    }
+
+    private void initView() {
+        mFileExplorer = (FileExplorer) findViewById(R.id.fileExplorer);
+        initFilePicker();
+        mUINav = (UINav) findViewById(R.id.UINav);
+        mUINav.setData(this, "请点击授权文件授权");
+    }
+
+    private void initFilePicker() {
+        ExplorerConfig config = new ExplorerConfig(this);
+        config.setRootDir(Environment.getExternalStorageDirectory());
+        config.setLoadAsync(true);
+        config.setExplorerMode(ExplorerMode.FILE);
+        config.setShowHomeDir(true);
+        config.setShowUpDir(true);
+        config.setShowHideDir(true);
+        config.setOnFileClickedListener(this);
+        mFileExplorer.load(config);
+
+//        config.setOnFilePickedListener(this);
+//        FilePicker picker = new FilePicker(this);
+//        picker.setExplorerConfig(config);
+//        picker.show();
+
+    }
+
+
+    private void authPermission(File file) {
+
+        if (file == null || !file.exists()) {
+            ToastUtils.showToast("请选择文件");
+            return;
+        }
+        String cert = FileUtil.readFile(file.getPath());
+        if (TextUtils.isEmpty(cert)) {
+            ToastUtils.showToast("cert is null");
+            return;
+        }
+        loadingDialog.showLoadingDialog("授权中,请等待...");
+        authApi.authDevice(this.getApplicationContext(), cert, "", new AuthApi.AuthDeviceCallBack() {
+            @Override
+            public void GetAuthDeviceResult(final AuthApplyResponse result) {
+                if (result.errorCode == ErrorCodeConfig.AUTH_SUCCESS) {
+
+                    runOnUiThread(new Runnable() {
+                        @Override
+                        public void run() {
+                            ToastUtils.showToast("Apply update: OK");
+                            SharePrefenceUtils.putBoolean(Constant.ISharePrefence.ISINIT, true);
+                            new FRAbsLoopFactory().createFRAblLoop(mContext, Constant.NumerValue.FRABS_TYPE);
+                            loadingDialog.dismissLoadingDialog();
+                            openApplication();
+                        }
+                    });
+                } else {
+                    runOnUiThread(new Runnable() {
+                        @Override
+                        public void run() {
+                            loadingDialog.dismissLoadingDialog();
+                            ToastUtils.showToast("Apply update: error. error code is: " + result.errorCode + " , error message: " + result.errorMessage);
+                        }
+                    });
+                }
+            }
+        });
+    }
+
+
+    @Override
+    public void onFileClicked(@NonNull @NotNull File file) {
+        authPermission(file);
+    }
+}

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

@@ -226,14 +226,14 @@ public class VisitorRegisterAc extends BaseActivity implements View.OnClickListe
         infoModel.setPostDate(startTime);
         infoModel.setLostDate(endTime);
         infoModel.setCardNo(cardNum);
-        infoModel.setIdNum(idNum);
+        infoModel.setIdNum(userInfo.getIdNum());
         if (isLogin) {
             infoModel.setStatus(0);
         } else {
             infoModel.setStatus(-2);
         }
         infoModel.setType(2);
-        infoModel.setPersonName(name);
+        infoModel.setPersonName(userInfo.getPerson_name());
         infoModel.setDeptId(deptNo + "");
         infoModel.setCategoryId(categoryId);
 

+ 29 - 1
app/src/main/java/com/sunwin/visitorapp/utils/FileUtil.java

@@ -12,16 +12,44 @@ import android.text.TextUtils;
 
 import com.sunwin.visitorapp.face.CameraPreviewData;
 
+import java.io.BufferedReader;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.io.OutputStream;
 
 public class FileUtil {
     private static final String TAG = "FileUtil";
 
+    public static String readFile(String filename) {
+        String content = "";
+        try {
+
+            FileInputStream inputStream = new FileInputStream(filename);
+            if (inputStream != null) {
+                InputStreamReader inputreader = new InputStreamReader(inputStream);
+                String line;
+                for (BufferedReader buffreader = new BufferedReader(inputreader);
+                     (line = buffreader.readLine()) != null;
+                     content = line) {
+                }
+                inputStream.close();
+            } else {
+                ToastUtils.showToast("未找到文件");
+            }
+        } catch (FileNotFoundException var8) {
+            LogUtil.d(TAG, "The File doesn't not exist.");
+        } catch (IOException var9) {
+            LogUtil.d(TAG, var9.getMessage());
+        }
+        SharePrefenceUtils.putString(Constant.ISharePrefence.CERT, content);
+        return content;
+    }
 
     public static String copyToFilesDir(Context context, Uri uri) {
         try {
@@ -140,7 +168,7 @@ public class FileUtil {
     }
 
     public static boolean deleteFile(String path) {
-        if (TextUtils.isEmpty(path)){
+        if (TextUtils.isEmpty(path)) {
             return false;
         }
         File file = new File(path);

+ 32 - 0
app/src/main/res/layout/activity_auth.xml

@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical">
+
+    <com.sunwin.visitorapp.view.UINav
+        android:id="@+id/UINav"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content" />
+
+    <com.github.gzuliyujiang.filepicker.FileExplorer
+        android:id="@+id/fileExplorer"
+        android:layout_weight="1"
+        android:layout_width="match_parent"
+        android:layout_height="0dp"
+        android:layout_marginTop="10dp" />
+
+    <Button
+        android:layout_marginLeft="20dp"
+        android:layout_marginRight="20dp"
+        android:layout_marginBottom="50dp"
+        android:id="@+id/btn_auth"
+        android:textSize="@dimen/sp_20"
+        android:textColor="@color/white"
+        android:background="@drawable/shape_bg_white_yellow"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:visibility="gone"
+        android:layout_marginTop="100dp"
+        android:text="授权" />
+</LinearLayout>

BIN
app/visitor.jks