Quellcode durchsuchen

二维码测试

everywindchase vor 3 Monaten
Ursprung
Commit
c56f8a6174

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

@@ -99,6 +99,13 @@
                 android:windowSoftInputMode="adjustPan|stateHidden"
         >
         </activity>
+        <activity
+                android:name=".ui.activity.QrCodeScanActivity"
+                android:configChanges="screenSize|keyboardHidden|orientation|keyboard|locale|layoutDirection"
+                android:launchMode="singleTask"
+                android:windowSoftInputMode="adjustPan|stateHidden"
+        >
+        </activity>
     </application>
 
 </manifest>

+ 50 - 0
app/src/main/java/jx/cn/escort/ui/activity/QrCodeScanActivity.kt

@@ -0,0 +1,50 @@
+package jx.cn.escort.ui.activity
+
+import android.content.Context
+import android.content.Intent
+import android.graphics.Bitmap
+import android.os.Bundle
+import androidx.appcompat.app.AppCompatActivity
+import androidx.fragment.app.FragmentTransaction
+import com.xuexiang.xqrcode.XQRCode
+import com.xuexiang.xqrcode.util.QRCodeAnalyzeUtils.AnalyzeCallback
+import com.xuexiang.xui.XUI
+import com.xuexiang.xui.widget.toast.XToast
+import jx.cn.escort.databinding.ActivityQrcodeBinding
+import jx.cn.escort.extension.ExtensionBinding.Companion.binding
+import jx.cn.escort.utils.ActivityUtils
+import org.koin.core.component.KoinComponent
+import org.koin.core.component.inject
+
+
+class QrCodeScanActivity: AppCompatActivity(), KoinComponent {
+
+    private val mBinding: ActivityQrcodeBinding by binding<ActivityQrcodeBinding>()
+
+    private val mContext: Context by  inject()
+    override fun onCreate(savedInstanceState: Bundle?) {
+        XUI.initTheme(this@QrCodeScanActivity);
+        super.onCreate(savedInstanceState)
+        setContentView(mBinding.root)
+        ActivityUtils.authCamera(this@QrCodeScanActivity){
+            var fm=supportFragmentManager
+            val captureFragment = XQRCode.getCaptureFragment(jx.cn.escort.R.layout.fragment_qrcode)
+            captureFragment.analyzeCallback=analyzeCallback
+            val  transaction: FragmentTransaction =fm.beginTransaction()
+            transaction.replace(jx.cn.escort.R.id.qr_content,captureFragment)
+            transaction.commitAllowingStateLoss()
+        }
+    }
+
+
+    val analyzeCallback: AnalyzeCallback = object : AnalyzeCallback {
+        override fun onAnalyzeSuccess(bitmap: Bitmap, result: String) {
+            XToast.info(this@QrCodeScanActivity, "扫描成功:${result}").show();
+        }
+
+        override fun onAnalyzeFailed() {
+            XToast.info(this@QrCodeScanActivity, "扫描失败").show();
+        }
+    }
+
+}

+ 25 - 3
app/src/main/java/jx/cn/escort/ui/fragment/NetConfirmFragment.kt

@@ -1,18 +1,27 @@
 package jx.cn.escort.ui.fragment
 
+import android.Manifest.permission.*
+import android.R
 import android.content.Context
+import android.content.DialogInterface
 import android.content.SharedPreferences
 import android.os.Bundle
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
+import android.widget.FrameLayout
 import androidx.fragment.app.Fragment
+import androidx.fragment.app.FragmentContainerView
+import androidx.fragment.app.FragmentTransaction
+import androidx.fragment.app.findFragment
+import com.xuexiang.xqrcode.XQRCode
 import com.xuexiang.xui.widget.actionbar.TitleBar
-import jx.cn.escort.R
+import com.xuexiang.xui.widget.button.roundbutton.RoundButton
+import com.xuexiang.xui.widget.dialog.materialdialog.MaterialDialog
 import jx.cn.escort.R.layout
-import jx.cn.escort.ui.activity.ActionTaskHandActivity
 import jx.cn.escort.ui.activity.EscortTaskHandActivity
 import jx.cn.escort.ui.activity.MainActivity
+import jx.cn.escort.ui.activity.QrCodeScanActivity
 import jx.cn.escort.utils.ActivityUtils
 import org.koin.core.component.KoinComponent
 import org.koin.core.component.inject
@@ -31,8 +40,9 @@ class NetConfirmFragment (context: Context): Fragment(), KoinComponent {
 
     override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
         val netConfirmFragment:View=inflater.inflate(layout.fragment_net_confirm,container,false)
+        val btnScan=netConfirmFragment.findViewById<RoundButton>(jx.cn.escort.R.id.btn_scan)
         val escortTaskHandActivity = context as EscortTaskHandActivity
-        var taskHandleTitle = escortTaskHandActivity.findViewById<TitleBar>(R.id.task_handle_title)
+        var taskHandleTitle = escortTaskHandActivity.findViewById<TitleBar>(jx.cn.escort.R.id.task_handle_title)
         taskHandleTitle.setTitle("网点交接")
         taskHandleTitle.setLeftClickListener(object:View.OnClickListener{
             override fun onClick(v: View?) {
@@ -40,6 +50,18 @@ class NetConfirmFragment (context: Context): Fragment(), KoinComponent {
             }
         })
 
+
+
+
+
+        btnScan.setOnClickListener(object:View.OnClickListener{
+            override fun onClick(v: View?) {
+              ActivityUtils.startActivity(context,QrCodeScanActivity::class.java)
+
+            }
+        })
+
+
         return netConfirmFragment
     }
 

+ 1 - 72
app/src/main/java/jx/cn/escort/ui/fragment/TaskFaceFragment.kt

@@ -91,80 +91,9 @@ class TaskFaceFragment (context: Context): Fragment(), KoinComponent {
                     .customView(inflate, true)
                     .title("拿起手机刷脸").showListener(object : DialogInterface.OnShowListener {
                         override fun onShow(dialog: DialogInterface?) {
-                            if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(
-                                    context,
-                                    Manifest.permission.CAMERA
-                                )
-                            ) {
-
-
-                                ActivityCompat.requestPermissions(activity, arrayOf(Manifest.permission.CAMERA), 100)
-
-                                //打开自定义授权弹窗
-                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
-                                    // Android 13及以上完整照片和视频访问权限
-                                    if (ContextCompat.checkSelfPermission(
-                                            context,
-                                            READ_MEDIA_IMAGES
-                                        ) == PERMISSION_GRANTED
-                                    ) {
-                                        ActivityCompat.requestPermissions(
-                                            activity, arrayOf(
-                                                Manifest.permission.READ_MEDIA_IMAGES
-                                            ), 101
-                                        )
-                                    }
-                                    if (ContextCompat.checkSelfPermission(
-                                            context,
-                                            READ_MEDIA_VIDEO
-                                        ) == PERMISSION_GRANTED
-                                    ) {
-                                        ActivityCompat.requestPermissions(
-                                            activity,
-                                            arrayOf(Manifest.permission.READ_MEDIA_VIDEO),
-                                            102
-                                        )
-                                    }
-                                    if (ContextCompat.checkSelfPermission(
-                                            context,
-                                            READ_MEDIA_AUDIO
-                                        ) == PERMISSION_GRANTED
-                                    ) {
-                                        ActivityCompat.requestPermissions(
-                                            activity,
-                                            arrayOf(Manifest.permission.READ_MEDIA_AUDIO),
-                                            103
-                                        )
-                                    }
-
-                                } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
-                                    // Android 12及以下完整本地读写访问权限
-                                    if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(
-                                            context,
-                                            Manifest.permission.READ_EXTERNAL_STORAGE
-                                        )
-                                    ) {
-                                        ActivityCompat.requestPermissions(
-                                            activity, arrayOf(
-                                                Manifest.permission.READ_EXTERNAL_STORAGE
-                                            ), 104
-                                        )
-                                    }
-                                    if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(
-                                            context,
-                                            Manifest.permission.WRITE_EXTERNAL_STORAGE
-                                        )
-                                    ) {
-                                        ActivityCompat.requestPermissions(
-                                            activity, arrayOf(
-                                                Manifest.permission.WRITE_EXTERNAL_STORAGE
-                                            ), 105
-                                        )
-                                    }
-                                }
 
 
-                                //弹窗回调完再打开相机
+                            ActivityUtils.authCamera(activity){
 
                             }
 

+ 91 - 1
app/src/main/java/jx/cn/escort/utils/ActivityUtils.kt

@@ -1,11 +1,20 @@
 package jx.cn.escort.utils
 
 
+import android.Manifest
+import android.Manifest.permission.*
+import android.app.Activity
 import android.app.ActivityOptions
 import android.content.Context
 import android.content.Intent
+import android.content.pm.PackageManager
+import android.content.pm.PackageManager.PERMISSION_GRANTED
+import android.os.Build
+import androidx.camera.core.ImageProxy
+import androidx.core.app.ActivityCompat
+import androidx.core.content.ContextCompat
 
- class ActivityUtils {
+class ActivityUtils {
 
 
      companion object{
@@ -33,6 +42,87 @@ import android.content.Intent
          }
 
 
+         @JvmStatic
+         inline  fun  authCamera(context: Activity, callback:()->Unit) {
+             if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(
+                     context,
+                     Manifest.permission.CAMERA
+                 )
+             ) {
+
+
+                 ActivityCompat.requestPermissions(context, arrayOf(Manifest.permission.CAMERA), 100)
+
+                 //打开自定义授权弹窗
+                 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
+                     // Android 13及以上完整照片和视频访问权限
+                     if (ContextCompat.checkSelfPermission(
+                             context,
+                             READ_MEDIA_IMAGES
+                         ) == PERMISSION_GRANTED
+                     ) {
+                         ActivityCompat.requestPermissions(
+                             context, arrayOf(
+                                 Manifest.permission.READ_MEDIA_IMAGES
+                             ), 101
+                         )
+                     }
+                     if (ContextCompat.checkSelfPermission(
+                             context,
+                             READ_MEDIA_VIDEO
+                         ) == PERMISSION_GRANTED
+                     ) {
+                         ActivityCompat.requestPermissions(
+                             context,
+                             arrayOf(Manifest.permission.READ_MEDIA_VIDEO),
+                             102
+                         )
+                     }
+                     if (ContextCompat.checkSelfPermission(
+                             context,
+                             READ_MEDIA_AUDIO
+                         ) == PERMISSION_GRANTED
+                     ) {
+                         ActivityCompat.requestPermissions(
+                             context,
+                             arrayOf(Manifest.permission.READ_MEDIA_AUDIO),
+                             103
+                         )
+                     }
+
+                 } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
+                     // Android 12及以下完整本地读写访问权限
+                     if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(
+                             context,
+                             Manifest.permission.READ_EXTERNAL_STORAGE
+                         )
+                     ) {
+                         ActivityCompat.requestPermissions(
+                             context, arrayOf(
+                                 Manifest.permission.READ_EXTERNAL_STORAGE
+                             ), 104
+                         )
+                     }
+                     if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(
+                             context,
+                             Manifest.permission.WRITE_EXTERNAL_STORAGE
+                         )
+                     ) {
+                         ActivityCompat.requestPermissions(
+                             context, arrayOf(
+                                 Manifest.permission.WRITE_EXTERNAL_STORAGE
+                             ), 105
+                         )
+                     }
+                 }
+
+
+
+             }
+             //弹窗回调完再打开相机
+             callback()
+         }
+
 
      }
 

+ 24 - 0
app/src/main/res/layout/activity_qrcode.xml

@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout
+        xmlns:android="http://schemas.android.com/apk/res/android"
+        xmlns:tools="http://schemas.android.com/tools"
+        xmlns:app="http://schemas.android.com/apk/res-auto"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        tools:context=".ui.activity.QrCodeScanActivity"
+        android:background="#f5f5f5"
+>
+
+
+
+    <androidx.fragment.app.FragmentContainerView
+            android:id="@+id/qr_content"
+            android:layout_width="match_parent" android:layout_height="match_parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintEnd_toEndOf="parent"
+            android:background="#EFE9E9"
+            app:layout_constraintHorizontal_bias="0.0"
+          />
+
+
+</androidx.constraintlayout.widget.ConstraintLayout>

+ 1 - 0
app/src/main/res/layout/fragment_net_confirm.xml

@@ -177,6 +177,7 @@
 
 
     <com.xuexiang.xui.widget.button.roundbutton.RoundButton
+            android:id="@+id/btn_scan"
             app:layout_constraintStart_toStartOf="parent"
             app:layout_constraintEnd_toEndOf="parent"
             app:rb_backgroundColor="@color/MainGreen"

+ 24 - 0
app/src/main/res/layout/fragment_qrcode.xml

@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+             xmlns:app="http://schemas.android.com/apk/res-auto"
+             android:layout_width="match_parent"
+             android:layout_height="match_parent">
+
+    <SurfaceView
+            android:id="@+id/preview_view"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content" />
+
+    <com.xuexiang.xqrcode.view.ViewfinderView
+            android:id="@+id/viewfinder_view"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            app:inner_corner_length="30dp"
+            app:inner_corner_width="5dp"
+            app:inner_marginTop="80dp"
+            app:inner_scan_isCircle="false"
+            app:inner_scan_speed="10dp"
+            app:inner_height="300dp"
+            app:inner_width="300dp" />
+
+</FrameLayout>