Explorar o código

1.重写登录页面

JaycePC hai 6 meses
pai
achega
97521b6ae4

+ 10 - 34
HttpCoreLibrary/src/main/java/com/rc/httpcore/HttpClient.kt

@@ -28,7 +28,6 @@ object HttpClient {
     private val LOGGER: Logger = Logger.getLogger(HttpClient::class.java.name)
     var token: String? = null
     var vName: String = "1.0.0"
-    var httpClient: OkHttpClient? = null
 
 
     fun init(appContext: Context) {
@@ -53,7 +52,7 @@ object HttpClient {
 
     private fun buildRetrofit(
         baseUrl: String = HttpConfig.API_BASE_URL,
-        okHttpClient: OkHttpClient? = buildHttpClient()
+        okHttpClient: OkHttpClient = buildHttpClient()
     ): Retrofit {
         return Retrofit.Builder()
             .client(okHttpClient)
@@ -64,44 +63,21 @@ object HttpClient {
             .build()
     }
 
-    private fun buildHttpClient(): OkHttpClient? {
+    private fun buildHttpClient(): OkHttpClient {
 //        //设置日志打印级别
 //        val interceptor = HttpLoggingInterceptor(HttpLoggingInterceptor.Logger { message ->
 //            LOGGER.log(Level.INFO, message)
 //        })
 //        interceptor.level = HttpLoggingInterceptor.Level.BODY
-
-        val logPath = "/sdcard/logs/"
-        val config = LogUtils.getConfig()
-        // log开关控制
-        config.setLogSwitch(true)
-        // log控制台开关
-        config.setConsoleSwitch(true)
-        // logTag
-        config.setGlobalTag("Jayce")
-        // log头部信息开关
-        config.setLogHeadSwitch(true)
-        // log文件开关
-        config.setLog2FileSwitch(true)
-        config.setDir(logPath)
-        // log文件前缀
-        config.setFilePrefix(AppUtils.getAppName())
-        // log边框开关
-        config.setBorderSwitch(true)
-        // log文件保存天数
-        config.setSaveDays(7)
-        if (null == httpClient) {
-            return OkHttpClient.Builder()
-                .readTimeout(TIMEOUT_DEFAULT, TimeUnit.SECONDS) // 设置读取超时时间
-                .connectTimeout(TIMEOUT_DEFAULT, TimeUnit.SECONDS) // 设置请求超时时间
-                .writeTimeout(TIMEOUT_DEFAULT, TimeUnit.SECONDS) // 设置写入超时时间
-                .addNetworkInterceptor(TokenHeaderInterceptor())
-                .addInterceptor(LogInterceptor())//添加请求日志
-                .retryOnConnectionFailure(true) // 设置出现错误进行重新连接
+        return return OkHttpClient.Builder()
+            .readTimeout(TIMEOUT_DEFAULT, TimeUnit.SECONDS) // 设置读取超时时间
+            .connectTimeout(TIMEOUT_DEFAULT, TimeUnit.SECONDS) // 设置请求超时时间
+            .writeTimeout(TIMEOUT_DEFAULT, TimeUnit.SECONDS) // 设置写入超时时间
+            .addNetworkInterceptor(TokenHeaderInterceptor())
+            .addInterceptor(LogInterceptor())//添加请求日志
+//            .retryOnConnectionFailure(true) // 设置出现错误进行重新连接
 //            .dns(OkHttpDNS())
-                .build()
-        }
-        return httpClient;
+            .build()
     }
 
 }

+ 1 - 1
app/build.gradle

@@ -12,7 +12,7 @@ android {
         minSdkVersion 24
         targetSdkVersion 34
         versionCode 3
-        versionName "1.06"
+        versionName "1.08"
 
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
 

+ 5 - 4
app/src/main/AndroidManifest.xml

@@ -51,7 +51,8 @@
             android:name=".ui.learn.LearnDetailWebActivity"
             android:exported="false" />
 
-        <receiver android:name=".broadcast.BootBroadcastReceiver"
+        <receiver
+            android:name=".broadcast.BootBroadcastReceiver"
             android:exported="true">
             <intent-filter>
                 <action android:name="android.intent.action.BOOT_COMPLETED" />
@@ -61,7 +62,7 @@
         </receiver>
 
         <activity
-            android:name=".ui.SplashActivity"
+            android:name=".ui.StartActivity"
             android:exported="true"
             android:launchMode="singleTop"
             android:screenOrientation="landscape">
@@ -139,7 +140,6 @@
             android:name=".ui.learn.LearnDetailActivity"
             android:configChanges="orientation|screenSize|keyboardHidden"
             android:hardwareAccelerated="true"
-
             android:screenOrientation="landscape"
             android:windowSoftInputMode="adjustPan" />
         <activity
@@ -186,7 +186,8 @@
                 android:resource="@xml/file_paths_public" />
         </provider>
 
-        <receiver android:name=".receiver.OpenApkReceiver"
+        <receiver
+            android:name=".receiver.OpenApkReceiver"
             android:exported="true">
             <intent-filter>
                 <action android:name="android.intent.action.PACKAGE_REPLACED" />

+ 26 - 3
app/src/main/java/com/dlc/exam/ExamApp.kt

@@ -13,9 +13,11 @@ import android.util.Log
 import android.widget.Toast
 import androidx.localbroadcastmanager.content.LocalBroadcastManager
 import androidx.multidex.MultiDex
+import com.blankj.utilcode.util.AppUtils
+import com.blankj.utilcode.util.LogUtils
 import com.dlc.exam.common.Constants
 import com.dlc.exam.sp.EnvSp
-import com.dlc.exam.ui.SplashActivity
+import com.dlc.exam.ui.StartActivity
 import com.iflytek.cloud.SpeechConstant
 import com.iflytek.cloud.SpeechUtility
 import com.rc.core.log.RcLog
@@ -43,6 +45,27 @@ class ExamApp : Application() {
     override fun onCreate() {
         super.onCreate()
 
+        val logPath = "/sdcard/logs/"
+        val config = LogUtils.getConfig()
+        // log开关控制
+        config.setLogSwitch(true)
+        // log控制台开关
+        config.setConsoleSwitch(true)
+        // logTag
+        config.setGlobalTag("Jayce")
+        // log头部信息开关
+        config.setLogHeadSwitch(true)
+        // log文件开关
+        config.setLog2FileSwitch(true)
+        config.setDir(logPath)
+        // log文件前缀
+        config.setFilePrefix(AppUtils.getAppName())
+        // log边框开关
+        config.setBorderSwitch(true)
+        // log文件保存天数
+        config.setSaveDays(7)
+
+
         ScreenAdapter.initAppDensity(this)
 
         CrashHandler.initCrash(this)
@@ -84,7 +107,7 @@ class ExamApp : Application() {
                 // Token过期,进入登录页
                 val intent = Intent().apply {
                     flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
-                    setClass(this@ExamApp, SplashActivity::class.java)
+                    setClass(this@ExamApp, StartActivity::class.java)
                 }
                 removeCallbacksAndMessages(null)
                 startActivity(intent)
@@ -96,7 +119,7 @@ class ExamApp : Application() {
         return try {
             val activityManager = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
             val componentName = activityManager.getRunningTasks(1)[0].topActivity
-            SplashActivity::class.java.name == componentName?.className
+            StartActivity::class.java.name == componentName?.className
         } catch (e: Exception) {
             false
         }

+ 2 - 2
app/src/main/java/com/dlc/exam/broadcast/BootBroadcastReceiver.kt

@@ -3,7 +3,7 @@ package com.dlc.exam.broadcast
 import android.content.BroadcastReceiver
 import android.content.Context
 import android.content.Intent
-import com.dlc.exam.ui.SplashActivity
+import com.dlc.exam.ui.StartActivity
 
 /**
  * info
@@ -17,7 +17,7 @@ class BootBroadcastReceiver : BroadcastReceiver() {
             context?.let {
                 val splashIntent = Intent(
                     it,
-                    SplashActivity::class.java
+                    StartActivity::class.java
                 ).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) }
                 it.startActivity(splashIntent)
             }

+ 9 - 4
app/src/main/java/com/dlc/exam/common/CommonUtils.kt

@@ -4,7 +4,7 @@ import android.content.Context
 import android.content.Intent
 import android.graphics.Bitmap
 import android.provider.Settings
-import com.dlc.exam.ui.SplashActivity
+import com.dlc.exam.ui.StartActivity
 import java.io.BufferedOutputStream
 import java.io.File
 import java.io.FileOutputStream
@@ -28,7 +28,12 @@ object CommonUtils {
 //            return "55e2dffeeca9660e"
         } else {
             try {
-                "EXAM_${Settings.Secure.getString(context.contentResolver, Settings.Secure.ANDROID_ID)}"
+                "EXAM_${
+                    Settings.Secure.getString(
+                        context.contentResolver,
+                        Settings.Secure.ANDROID_ID
+                    )
+                }"
             } catch (e: Exception) {
                 defId
             }
@@ -36,7 +41,7 @@ object CommonUtils {
     }
 
     fun restartApp(appContext: Context) {
-        val intent = Intent(appContext, SplashActivity::class.java)
+        val intent = Intent(appContext, StartActivity::class.java)
         val restartIntent = Intent.makeRestartActivityTask(intent.component)
         appContext.startActivity(restartIntent)
         exitProcess(0)
@@ -79,7 +84,7 @@ object CommonUtils {
     fun stringToMD5(value: String?): String? {
         if (value.isNullOrEmpty()) return null
 
-        val secretBytes  = MessageDigest.getInstance("MD5").digest(value.toByteArray())
+        val secretBytes = MessageDigest.getInstance("MD5").digest(value.toByteArray())
         var md5code: String = BigInteger(1, secretBytes).toString(16)
         for (i in 0 until 32 - md5code.length) {
             md5code = "0$md5code"

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 661 - 661
app/src/main/java/com/dlc/exam/ui/SplashActivity.kt


+ 123 - 0
app/src/main/java/com/dlc/exam/ui/StartActivity.java

@@ -0,0 +1,123 @@
+package com.dlc.exam.ui;
+
+import android.Manifest;
+import android.os.Bundle;
+import android.os.CountDownTimer;
+import android.view.View;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.appcompat.app.AlertDialog;
+
+import com.arcsoft.face.ActiveFileInfo;
+import com.arcsoft.face.ErrorInfo;
+import com.arcsoft.face.FaceEngine;
+import com.arcsoft.face.enums.RuntimeABI;
+import com.blankj.utilcode.util.ActivityUtils;
+import com.blankj.utilcode.util.AppUtils;
+import com.blankj.utilcode.util.LogUtils;
+import com.dlc.exam.common.Constants;
+import com.dlc.exam.databinding.ActivityStartBinding;
+import com.dlc.exam.ui.settings.PasswordDialog;
+import com.dlc.exam.ui.settings.SettingsActivity;
+import com.rc.core.ui.activity.RcBaseActivity;
+import com.tbruyelle.rxpermissions2.RxPermissions;
+
+import io.reactivex.disposables.Disposable;
+import kotlin.Unit;
+import kotlin.jvm.functions.Function0;
+
+public class StartActivity extends RcBaseActivity<ActivityStartBinding> {
+
+    private ActivityStartBinding binding;
+
+    @NonNull
+    @Override
+    protected ActivityStartBinding createViewBinding() {
+        return binding = ActivityStartBinding.inflate(getLayoutInflater());
+    }
+
+    @Override
+    protected void initViews(@Nullable Bundle savedInstanceState) {
+        super.initViews(savedInstanceState);
+        binding.versionName.setText(AppUtils.getAppVersionName());
+
+        binding.firm.setOnLongClickListener(new View.OnLongClickListener() {
+            @Override
+            public boolean onLongClick(View v) {
+                new PasswordDialog(StartActivity.this, new Function0<Unit>() {
+                    @Override
+                    public Unit invoke() {
+                        ActivityUtils.startActivity(SettingsActivity.class);
+                        finish();
+                        return null;
+                    }
+                }).show();
+                return true;
+            }
+        });
+
+        requestPermission();
+    }
+
+    private CountDownTimer activeTimer;
+
+    private void requestPermission() {
+        Disposable disposable = new RxPermissions(this).request(Manifest.permission.WRITE_EXTERNAL_STORAGE,
+                Manifest.permission.READ_EXTERNAL_STORAGE,
+                Manifest.permission.CAMERA,
+                Manifest.permission.READ_PHONE_STATE,
+                Manifest.permission.RECORD_AUDIO).subscribe(aBoolean -> {
+            if (aBoolean) {
+                activeTimer = new CountDownTimer(1000, 1000) {
+                    @Override
+                    public void onTick(long millisUntilFinished) {
+
+                    }
+
+                    @Override
+                    public void onFinish() {
+                        if (activeOnlineFaceEngine()) {
+                            activeTimer.cancel();
+                            activeTimer = null;
+                            finish();
+                            ActivityUtils.startActivity(MainActivity.class);
+                        } else {
+                            activeTimer.start();
+                        }
+                    }
+                };
+                activeTimer.start();
+            } else {
+                new AlertDialog.Builder(StartActivity.this)
+                        .setTitle("提示")
+                        .setMessage("您必须同意所有权限才可以继续使用")
+                        .setNegativeButton("确定", (dialog, which)
+                                -> requestPermission())
+                        .show();
+            }
+        });
+        addDisposable(disposable);
+    }
+
+    private boolean activeOnlineFaceEngine() {
+        RuntimeABI runtimeABI = FaceEngine.getRuntimeABI();
+        LogUtils.d("虹软", runtimeABI);
+        ActiveFileInfo activeFileInfo = new ActiveFileInfo();
+        int res = FaceEngine.getActiveFileInfo(this, activeFileInfo);
+        if (res == ErrorInfo.MOK) {
+            LogUtils.d(activeFileInfo.toString());
+            return true;
+        } else {
+            int code = FaceEngine.activeOnline(this, Constants.ArcFace.APP_ID, Constants.ArcFace.SDK_KEY);
+            LogUtils.d("虹软激活", code);
+            if (ErrorInfo.MOK == code || code == ErrorInfo.MERR_ASF_ALREADY_ACTIVATED) {
+                showToast("人脸引擎已激活");
+                return true;
+            } else {
+                showToast("人脸引擎激活失败!" + code);
+            }
+        }
+        return false;
+    }
+}

+ 3 - 7
app/src/main/java/com/dlc/exam/ui/settings/SettingsActivity.kt

@@ -6,21 +6,17 @@ import android.os.Looper
 import android.os.Message
 import android.provider.Settings
 import android.view.LayoutInflater
-import com.bumptech.glide.Glide
 import com.dlc.exam.common.CommonUtils
 import com.dlc.exam.common.Constants
 import com.dlc.exam.databinding.ActivitySettingsBinding
 import com.dlc.exam.sp.EnvConfig
 import com.dlc.exam.sp.EnvSp
-import com.dlc.exam.ui.SplashActivity
+import com.dlc.exam.ui.StartActivity
 import com.rc.core.ui.ActivityCollector
 import com.rc.core.ui.activity.RcBaseActivity
 import com.rc.core.util.DeviceUtils
 import com.rc.httpcore.HttpConfig
 import java.lang.ref.WeakReference
-import java.text.SimpleDateFormat
-import java.util.Calendar
-import java.util.Locale
 
 /**
  * info
@@ -34,7 +30,7 @@ class SettingsActivity : RcBaseActivity<ActivitySettingsBinding>() {
     override fun initListener() {
         viewBinding.back.setOnClickListener {
             ActivityCollector.finishAll()
-            val intent = Intent(this, SplashActivity::class.java)
+            val intent = Intent(this, StartActivity::class.java)
             startActivity(intent)
         }
 
@@ -97,7 +93,7 @@ class SettingsActivity : RcBaseActivity<ActivitySettingsBinding>() {
             settingPwd
         )
         EnvSp.saveEnv(this, envConfig)
-       weakHandler.sendEmptyMessageDelayed(1, 1000)
+        weakHandler.sendEmptyMessageDelayed(1, 1000)
 //        object : Handler(Looper.getMainLooper()) {
 //            override fun handleMessage(msg: Message) {
 //                showToast("设置成功")

+ 0 - 6
app/src/main/res/layout/activity_splash.xml

@@ -67,12 +67,6 @@
 
     </LinearLayout>
 
-    <ImageView
-        android:id="@+id/banner"
-        android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:contentDescription="@null"
-        android:scaleType="fitXY" />
 
     <View
         android:id="@+id/settings"

+ 38 - 0
app/src/main/res/layout/activity_start.xml

@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:id="@+id/main"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:background="@mipmap/img_bg"
+    tools:context=".ui.StartActivity">
+
+    <TextView
+        android:id="@+id/logo"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_centerInParent="true"
+        android:drawableTop="@mipmap/icon_log_wto"
+        android:drawablePadding="50dp"
+        android:text="欢迎使用实验室安全学习与考试系统"
+        android:textColor="@color/white"
+        android:textSize="28sp" />
+
+    <TextView
+        android:id="@+id/versionName"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentBottom="true" />
+
+    <TextView
+        android:id="@+id/firm"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentBottom="true"
+        android:layout_centerHorizontal="true"
+        android:layout_marginBottom="12dp"
+        android:text="@string/copy_right"
+        android:textColor="#666666"
+        android:textSize="12sp" />
+</RelativeLayout>