From f71e74b5f0d2716fbf05da016cdaa18d64e09f80 Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期四, 31 十二月 2020 17:01:18 +0800
Subject: [PATCH] 又换完成最新门锁。空气质量传感器完成数据和基本配置功能。开发图表和自动化的同事可下载此代码

---
 ZigbeeApp/Home.Ios/ZXingOverlayView.cs |  168 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 168 insertions(+), 0 deletions(-)

diff --git a/ZigbeeApp/Home.Ios/ZXingOverlayView.cs b/ZigbeeApp/Home.Ios/ZXingOverlayView.cs
new file mode 100755
index 0000000..e7bc553
--- /dev/null
+++ b/ZigbeeApp/Home.Ios/ZXingOverlayView.cs
@@ -0,0 +1,168 @@
+锘縰sing System;
+using System.Collections.Generic;
+using AVFoundation;
+using CoreGraphics;
+using UIKit;
+
+namespace Home.IOS
+{
+    public class ZXingOverlayView : UIView
+    {
+        public UILabel textBottom;
+        UIView redLine;
+        public Action OnCancel;
+        public Action OnTorch;
+        public UIBarButtonItem cancelButton;
+        public UIBarButtonItem torchButton;
+        public string cancelText = "鍙栨秷";
+        public string flashText = "闂厜鐏�";
+        public string bottomText = "鎵竴鎵�";
+
+        CGSize screenSize = UIScreen.MainScreen.Bounds.Size;
+
+        public ZXingOverlayView(string cancelText = "鍙栨秷", string flashText = "闂厜鐏�", string titleText = "鎵竴鎵�") : base()
+        {
+            this.cancelText = cancelText;
+            this.flashText = flashText;
+            this.bottomText = titleText;
+
+            Opaque = false;
+            BackgroundColor = UIColor.Clear;
+
+            textBottom = new UILabel()
+            {
+                Frame = new CGRect(0, (screenSize.Height - 44 + screenSize.Width * 0.75f) / 2, screenSize.Width, 40f),
+                Text = bottomText,
+                Font = UIFont.SystemFontOfSize(13),
+                TextAlignment = UITextAlignment.Center,
+                TextColor = UIColor.White,
+                Lines = 0,
+                BackgroundColor = UIColor.Clear
+            };
+            this.AddSubview(textBottom);
+
+            var captureDevice = AVCaptureDevice.GetDefaultDevice(AVMediaType.Video);
+
+            bool hasTorch = false;
+
+            if (captureDevice != null)
+                hasTorch = captureDevice.TorchAvailable;
+
+            InvokeOnMainThread(delegate {
+                // Setting tool bar
+                var toolBar = new UIToolbar(new CGRect(0, Frame.Height - 44, Frame.Width, 44));
+
+                var buttons = new List<UIBarButtonItem>();
+                cancelButton = new UIBarButtonItem(cancelText, UIBarButtonItemStyle.Done, delegate { OnCancel?.Invoke(); });
+                cancelButton.SetTitleTextAttributes(new UITextAttributes { TextColor = UIColor.White }, UIControlState.Normal);
+                buttons.Add(cancelButton);
+                if (hasTorch)
+                {
+                    buttons.Add(new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace));
+
+                    torchButton = new UIBarButtonItem(flashText, UIBarButtonItemStyle.Done, delegate { OnTorch?.Invoke(); });
+                    torchButton.SetTitleTextAttributes(new UITextAttributes { TextColor = UIColor.White }, UIControlState.Normal);
+                    buttons.Add(torchButton);
+                }
+
+                toolBar.Items = buttons.ToArray();
+                toolBar.BarTintColor = UIColor.Clear;
+                toolBar.Translucent = true;
+                toolBar.TintColor = UIColor.Black;
+                toolBar.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleTopMargin;
+                Add(toolBar);
+            });
+
+        }
+
+        public override void Draw(CGRect rect)
+        {
+            CGRect screenDrawRect = new CGRect(0, 0, screenSize.Width, screenSize.Height - 44);
+
+            //涓棿娓呯┖鐨勭煩褰㈡
+            CGRect clearDrawRect = new CGRect(screenDrawRect.Size.Width * 0.125f, (screenDrawRect.Size.Height - screenDrawRect.Size.Width * 0.75f) / 2,
+                                              screenDrawRect.Size.Width * 0.75f, screenDrawRect.Size.Width * 0.75f);
+
+            CGContext ctx = UIGraphics.GetCurrentContext();
+            AddScreenFillRect(ctx, screenDrawRect);
+            AddCenterClearRect(ctx, clearDrawRect);
+            AddWhiteRect(ctx, clearDrawRect);
+            AddCornerLineWithContext(ctx, clearDrawRect);
+        }
+        //娣诲姞灞忓箷鍗婇�忔槑濉厖鑹�
+        private void AddScreenFillRect(CGContext ctx, CGRect rect)
+        {
+            ctx.SetFillColor(new CGColor(0, 0, 0, 0.5f));
+            ctx.FillRect(rect);
+        }
+        //娣诲姞涓績鍏ㄩ�忔槑濉厖鑹�
+        private void AddCenterClearRect(CGContext ctx, CGRect rect)
+        {
+            ctx.ClearRect(rect);
+        }
+        //鏍规嵁鐐圭敾绾�
+        private void AddLine(CGPoint[] pointA, CGPoint[] pointB, CGContext ctx)
+        {
+            ctx.SetLineWidth(2f);
+            ctx.AddLines(pointA);
+            ctx.AddLines(pointB);
+        }
+        //娣诲姞鐧借壊鏂规
+        private void AddWhiteRect(CGContext ctx, CGRect rect)
+        {
+            ctx.StrokeRect(rect);
+            ctx.SetStrokeColor(new CGColor(1, 1, 1, 1));
+            ctx.SetLineWidth(0.8f);
+            ctx.AddRect(rect);
+            ctx.StrokePath();
+        }
+        //娣诲姞鍥涗釜瑙掔殑钃濊壊
+        private void AddCornerLineWithContext(CGContext ctx, CGRect rect)
+        {
+            //鐢诲洓涓竟瑙�
+            ctx.SetLineWidth(2f);
+            ctx.SetStrokeColor(UIColor.FromRGB(22, 118, 188).CGColor);
+
+            //宸︿笂瑙�
+            CGPoint[] poinsTopLeftA = new CGPoint[] { new CGPoint(rect.Location.X + 0.7f, rect.Location.Y), new CGPoint(rect.Location.X + 0.7f, rect.Location.Y + 15f) };
+
+            CGPoint[] poinsTopLeftB = new CGPoint[] { new CGPoint(rect.Location.X, rect.Location.Y + 0.7f), new CGPoint(rect.Location.X + 15f, rect.Location.Y + 0.7f) };
+
+            AddLine(poinsTopLeftA, poinsTopLeftB, ctx);
+
+            //宸︿笅瑙�
+            CGPoint[] poinsBottomLeftA = new CGPoint[] { new CGPoint(rect.Location.X + 0.7f, rect.Location.Y + rect.Size.Height - 15f), new CGPoint(rect.Location.X + 0.7f, rect.Location.Y + rect.Size.Height) };
+
+            CGPoint[] poinsBottomLeftB = new CGPoint[] { new CGPoint(rect.Location.X, rect.Location.Y + rect.Size.Height - 0.7f), new CGPoint(rect.Location.X + 0.7f + 15f, rect.Location.Y + rect.Size.Height - 0.7f) };
+
+            AddLine(poinsBottomLeftA, poinsBottomLeftB, ctx);
+
+            //鍙充笂瑙�
+            CGPoint[] poinsTopRightA = new CGPoint[] { new CGPoint(rect.Location.X + rect.Size.Width - 15f, rect.Location.Y + 0.7f), new CGPoint(rect.Location.X + rect.Size.Width, rect.Location.Y + 0.7) };
+
+            CGPoint[] poinsTopRightB = new CGPoint[] { new CGPoint(rect.Location.X + rect.Size.Width - 0.7f, rect.Location.Y), new CGPoint(rect.Location.X + rect.Size.Width - 0.7f, rect.Location.Y + 15 + 0.7) };
+
+            AddLine(poinsTopRightA, poinsTopRightB, ctx);
+
+            CGPoint[] poinsBottomRightA = new CGPoint[] { new CGPoint(rect.Location.X + rect.Size.Width - 0.7f, rect.Location.Y + rect.Size.Height - 15f), new CGPoint(rect.Location.X - 0.7f + rect.Size.Width, rect.Location.Y + rect.Size.Height) };
+
+            CGPoint[] poinsBottomRightB = new CGPoint[] { new CGPoint(rect.Location.X + rect.Size.Width - 15f, rect.Location.Y + rect.Size.Height - 0.7f), new CGPoint(rect.Location.X + rect.Size.Width, rect.Location.Y + rect.Size.Height - 0.7f) };
+
+            AddLine(poinsBottomRightA, poinsBottomRightB, ctx);
+
+            ctx.StrokePath();
+        }
+
+        public void Destroy()
+        {
+            InvokeOnMainThread(() => {
+                textBottom.RemoveFromSuperview();
+                redLine.RemoveFromSuperview();
+
+                textBottom = null;
+                redLine = null;
+            });
+        }
+
+    }
+}

--
Gitblit v1.8.0