From 07b0239f824ddb5a0cadf93f20ff6247f72baca2 Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期三, 19 一月 2022 11:32:03 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/wxr0114' into wjc

---
 HDL-ON_Android/Scan.cs |  144 +++++++++++++++++++++++++++++++++++------------
 1 files changed, 106 insertions(+), 38 deletions(-)

diff --git a/HDL-ON_Android/Scan.cs b/HDL-ON_Android/Scan.cs
index 01cbcb3..f4f5de5 100644
--- a/HDL-ON_Android/Scan.cs
+++ b/HDL-ON_Android/Scan.cs
@@ -1,70 +1,121 @@
 锘縰sing System;
 using System.IO;
+using Android.Content;
 using Shared;
 using ZXing.Mobile;
 
 namespace HDL_ON
 {
-    public class Scan
+    public class Scan: Java.Lang.Object,HDL_ON_Android.ScanActivity.ScanResult
     {
         public Scan()
         {
         }
-        static MobileBarcodeScanner scanner;
-        public static void OpenScan(Action<string> action)
+
+        private static Scan ins;
+
+        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;
+            //string cancel = "鍙栨秷";
+            //string flashText = "";
+            //string titleText = "浜岀淮鐮佹壂鎻�";
+            //if (Language.CurrentLanguage != "Chinese")
+            //{
+            //    cancel = "Cancel";
+            //    flashText = "";
+            //    titleText = "Scan";
+            //}
 
             ((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
                 {
                     action?.Invoke(null);
+                    Action action1 = () => {
+                        Intent intent = new Intent(Android.Provider.Settings.ActionApplicationDetailsSettings);
+                        intent.AddFlags(ActivityFlags.NewTask);
+                        Android.Net.Uri uri = Android.Net.Uri.FromParts("package", Application.Activity.PackageName, null);
+                        intent.SetData(uri);
+                        Application.Activity.StartActivity(intent);
+                    };
+                    if (string.IsNullOrEmpty(TipMsg))
+                    {
+                        if (Language.CurrentLanguage == "Chinese")
+                        {
+                            new HDL_ON.UI.PublicAssmebly().TipOptionMsg(StringId.Tip, "鐩告満璁块棶鏉冮檺宸茶鎷掔粷锛岃鍓嶅線绯荤粺璁剧疆鎵撳紑鐩稿叧鏉冮檺銆�", action1);
+                        }
+                        else
+                        {
+                            new HDL_ON.UI.PublicAssmebly().TipOptionMsg(StringId.Tip, "Camera access has been denied. Please go to system settings to open relevant permissions.", action1);
+                        }
+                    }
+                    else
+                    {
+                        new HDL_ON.UI.PublicAssmebly().TipOptionMsg(StringId.Tip, TipMsg,action1,45);
+                        TipMsg = string.Empty;
+                    }
                 }
             });
         }
@@ -122,5 +173,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