From 592974441a4df95fffd9167c90192da1a390b1c2 Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期二, 06 六月 2023 11:51:12 +0800
Subject: [PATCH] Merge branch 'Dev-Branch'

---
 HDL-ON_Android/Scan.cs |  112 ++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 73 insertions(+), 39 deletions(-)

diff --git a/HDL-ON_Android/Scan.cs b/HDL-ON_Android/Scan.cs
index 0a5f4dc..ea1bf16 100644
--- a/HDL-ON_Android/Scan.cs
+++ b/HDL-ON_Android/Scan.cs
@@ -6,65 +6,80 @@
 
 namespace HDL_ON
 {
-    public class Scan
+    public class Scan: Java.Lang.Object,HDL_ON_Android.ScanActivity.ScanResult
     {
         public Scan()
         {
         }
 
-        public static string TipMsg = string.Empty;
+        private static Scan ins;
 
-        static MobileBarcodeScanner scanner;
-        public static void OpenScan(Action<string> action)
+        public static Scan Ins
         {
-            string cancel = "鍙栨秷";
-            string flashText = "";
-            string titleText = "浜岀淮鐮佹壂鎻�";
-            if (Language.CurrentLanguage != "Chinese")
+            get
             {
-                cancel = "Cancel";
-                flashText = "";
-                titleText = "Scan";
+                if (ins == null)
+                {
+                    ins = new Scan();
+                }
+                return ins;
             }
+
+        }
+
+        public string TipMsg = string.Empty;
+
+        Action<string> resultAction;
+        static MobileBarcodeScanner scanner;
+
+
+        public void OpenScan(Action<string> action)
+        {
+            resultAction = action;
 
             ((BaseActivity)Shared.Application.Activity).SetCamera(async (obj) =>
             {
-                if (obj)
+                if (obj)//鏉冮檺鏄惁鎵撳紑
                 {
                     if (scanner == null)
                     {
-                        MobileBarcodeScanner.Initialize(Shared.Application.Activity.Application);
-                        var mZXingCustomScanView = new ZXingCustomScanView(Shared.Application.Activity.Application);
-                        mZXingCustomScanView.cancelTextView.Text = cancel;
-                        mZXingCustomScanView.flashTextView.Text = flashText;
-                        mZXingCustomScanView.titleTextView.Text = titleText;
-                        var bOn = false;
-                        scanner = new ZXing.Mobile.MobileBarcodeScanner()
-                        {
-                            UseCustomOverlay = true,
-                            CustomOverlay = mZXingCustomScanView
-                        };
 
-                        mZXingCustomScanView.OnCancel += () =>
-                        {
+                        var intent = new Intent(Shared.Application.Activity, typeof(HDL_ON_Android.ScanActivity));
+                        Shared.Application.Activity.StartActivity(intent);
 
-                            scanner?.Cancel();
-                        };
+                        HDL_ON_Android.ScanActivity.InitDdd(this);
 
-                        mZXingCustomScanView.OnTorch += () =>
-                        {
-                            bOn = !bOn;
-                            scanner?.Torch(bOn);
-                        };
+                        //MobileBarcodeScanner.Initialize(Shared.Application.Activity.Application);
+                        //var mZXingCustomScanView = new ZXingCustomScanView(Shared.Application.Activity.Application);
+                        //mZXingCustomScanView.cancelTextView.Text = cancel;
+                        //mZXingCustomScanView.flashTextView.Text = flashText;
+                        //mZXingCustomScanView.titleTextView.Text = titleText;
+                        //mZXingCustomScanView.SetMinimumWidth( 1800);
+                        //var bOn = false;
+                        //scanner = new ZXing.Mobile.MobileBarcodeScanner()
+                        //{
+                        //    UseCustomOverlay = true,
+                        //    CustomOverlay = mZXingCustomScanView
+                        //};
+                        ////scanner.CustomOverlay.width
+                        //mZXingCustomScanView.OnCancel += () =>
+                        //{
+
+                        //    scanner?.Cancel();
+                        //};
+
+                        //mZXingCustomScanView.OnTorch += () =>
+                        //{
+                        //    bOn = !bOn;
+                        //    scanner?.Torch(bOn);
+                        //};
                     }
 
-                    var result = await scanner.Scan();
-
-                    if (result != null)
-                        action?.Invoke(result.Text);
-                    else
-                        action?.Invoke(null);
-
+                    //var result = await scanner.Scan();
+                    //if (result != null)
+                    //    action?.Invoke(result.Text);
+                    //else
+                    //    action?.Invoke(null);
                 }
                 else
                 {
@@ -98,6 +113,8 @@
 
         public static byte[] BytesFromText(string text, int width = 300, int height = 300)
         {
+            if (text == "") return null;
+
             var barcodeWriter = new ZXing.Mobile.BarcodeWriter
             {
                 Format = ZXing.BarcodeFormat.QR_CODE,
@@ -149,5 +166,22 @@
         //        }
         //    });
         //}
+
+
+        //static void initFromCameraParameters(Android.Graphics.Camera camera)
+        //{
+        //    //camera.SetLocation
+        //}
+
+        public void onResult(string result)
+        {
+            if (!string.IsNullOrEmpty( result))
+                resultAction?.Invoke(result);
+            else
+                resultAction?.Invoke(null);
+        }
     }
+
+
+
 }

--
Gitblit v1.8.0