From 48ba446936b51fffafa7c3600c0dadc6ac0e8c20 Mon Sep 17 00:00:00 2001 From: 陈嘉乐 <cjl@hdlchina.com.cn> Date: 星期五, 10 七月 2020 10:52:13 +0800 Subject: [PATCH] 2020-07-10-01 --- ZigbeeApp/GateWay.Droid/Application.cs | 86 ++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 84 insertions(+), 2 deletions(-) diff --git a/ZigbeeApp/GateWay.Droid/Application.cs b/ZigbeeApp/GateWay.Droid/Application.cs old mode 100644 new mode 100755 index b200e36..32c6c9d --- a/ZigbeeApp/GateWay.Droid/Application.cs +++ b/ZigbeeApp/GateWay.Droid/Application.cs @@ -15,7 +15,9 @@ using Microsoft.AppCenter.Analytics; using Microsoft.AppCenter.Crashes; using Com.Tencent.MM.Sdk.Openapi; - +using ZXing.Mobile; +using System.IO; + namespace com.hdl.home { @@ -95,7 +97,10 @@ var req = new SendAuth.Req { Scope = "snsapi_userinfo", State = "ZigbeeApp" }; api.SendReq(req); } - /// <summary>鈥� /// 鎵�鏈夊垵濮嬪寲鍏ㄩ儴鍦ㄨ繖涓柟娉曞疄鐜扳�� /// </summary>鈥� void initAll()鈥� {鈥� BaseActivity.IsEnnableGPS = false; + /// <summary>鈥� /// 鎵�鏈夊垵濮嬪寲鍏ㄩ儴鍦ㄨ繖涓柟娉曞疄鐜扳�� /// </summary>鈥� void initAll()鈥� { + string checkFile = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Shared.Phone.UserCenter.DirNameResourse.OpenGbsFile); + Shared.Application.IsGpsEnable = System.IO.File.Exists(checkFile); + //璁剧疆鏋佸厜璋冭瘯妯″紡锛屼负false鏃跺彧鎵撳嵃璀﹀憡淇℃伅 // System.Console.WriteLine($"AAA : {System.DateTime.Now.ToString()}"); #if Release鈥� JPushInterface.SetDebugMode(false); @@ -273,3 +278,80 @@ } } } + +namespace Shared +{ + public static class QRCode + { + static ZXing.Mobile.MobileBarcodeScanner scanner; + public static void ScanQRcode(Action<string> action, string cancel = "鍙栨秷", string flashText = "闂厜鐏�", string titleText = "浜岀淮鐮佹壂鎻�") + { + ((BaseActivity)Shared.Application.Activity).SetCamera(async (obj) => + { + if (obj) + { + if (scanner == null) + { + MobileBarcodeScanner.Initialize(Shared.Application.Activity.Application); + var mZXingCustomScanView = new GateWay.Droid.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 += () => { + + 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); + + } + else + { + action?.Invoke(null); + } + }); + } + + public static byte[] BytesFromText(string text, int width = 300, int height = 300) + { + var barcodeWriter = new ZXing.Mobile.BarcodeWriter + { + Format = ZXing.BarcodeFormat.QR_CODE, + Options = new ZXing.Common.EncodingOptions + { + Width = width, + Height = height, + Margin = 0 + } + }; + + barcodeWriter.Renderer = new ZXing.Mobile.BitmapRenderer(); + var bitmap = barcodeWriter.Write(text); + using (var stream = new MemoryStream()) + { + bitmap.Compress(Android.Graphics.Bitmap.CompressFormat.Png, 100, stream); // this is the diff between iOS and Android + stream.Position = 0; + return stream.ToArray(); + } + } + } +} -- Gitblit v1.8.0