Esempio n. 1
0
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            closeButton.Frame = closeFrame;
            //SessionPresetsButton.Frame = sessionPresetsFrame;

            //this.View.BringSubviewToFront(closeButton);
            //this.View.BringSubviewToFront(flashButton);

            //if (flashFrame.Width == 0)
            //{
            //    flashButton.Frame = new CGRect(this.View.Frame.Size.Width - 64, 0, 64, 64);
            //}
            //else
            //{
            //    flashButton.Frame = flashFrame;
            //}

            //flashButton = new UIButton(new CGRect(UIScreen.MainScreen.Bounds.Size.Width - 10 - 60, 10, 60, 60));
            //flashButton.Frame = new CGRect(this.View.Frame.Size.Width - 64, 0, 64, 64);
            //flashButton.SetImage(UIImage.FromBundle("flashbuttonoff.png"), UIControlState.Normal);
            //flashButton.SetImage(UIImage.FromBundle("flashbuttonon.png"), UIControlState.Selected);
            //flashButton.Selected = false;
            //flashButton.Hidden = false;
            //flashButton.SetBackgroundImage(null, UIControlState.Normal);
            //flashButton.SetBackgroundImage(null, UIControlState.Selected);

            flashButton.TouchUpInside += delegate
            {
                this.toggleTorch();
            };


            closeButton.TouchUpInside += delegate {
                //if (successCallback != null)
                //{
                //    successCallback.barcodeDetected(null);

                //}
                //else
                //{
                //    handleResult(null);
                //}

                OnScanCompleted?.Invoke(string.Empty, "EXIT");
                DismissViewController(true, null); //화면 종료
            };

            //if (flashFrame.Width == 0)
            //{
            //    flashButton.Frame = new CGRect(this.View.Frame.Size.Width - 64, 0, 64, 64);
            //}
            //else
            //{
            //    flashButton.Frame = flashFrame;
            //}
        }
Esempio n. 2
0
        public void ClientRead(ServerNetObject type, IReadMessage msg, float sendingTime)
        {
            bool wasScanCompletedPreviously = IsScanCompleted;

            scanTimer = msg.ReadSingle();
            if (!wasScanCompletedPreviously && IsScanCompleted)
            {
                OnScanCompleted?.Invoke(this);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 스캔화면 자동 종료
        /// Finsh() 호출하지 않아도 됨.
        /// </summary>
        public override void OnBackPressed()
        {
            base.OnBackPressed();
            Barcode barcode = new Barcode
            {
                DisplayValue = "EXIT"
            };

            OnScanCompleted?.Invoke(barcode);
            OnScanCompleted = null;
        }
        /// <summary>
        /// For each assembly specified, detect the .net runtime the dll is targeting
        /// </summary>
        /// <param name="runnerAssemblies"></param>
        /// <returns></returns>
        private Dictionary <string, FrameworkType> DetectRunnersFromAssemblies(string runnerAssemblies)
        {
            OnScanStarted?.Invoke();
            var assemblyMetadata = new Dictionary <string, FrameworkType>();

            // load all of the assemblies and inspect them
            foreach (var assemblyPath in runnerAssemblies.Split(" ", StringSplitOptions.RemoveEmptyEntries))
            {
                var fullpath = assemblyPath;
                assemblyMetadata.Add(fullpath, PortableExecutableHelper.GetAssemblyFrameworkType(fullpath));
            }
            OnScanCompleted?.Invoke();
            return(assemblyMetadata);
        }
Esempio n. 5
0
        //partial void SelectMetadataObjectTypes(UIButton sender)
        //{
        //    var controller = new ItemSelectionViewController<AVMetadataObjectType>(this,
        //                                                                           MetadataObjectTypeItemSelectionIdentifier,
        //                                                                           this.metadataOutput.AvailableMetadataObjectTypes.GetFlags().ToList(),
        //                                                                           this.metadataOutput.MetadataObjectTypes.GetFlags().ToList(),
        //                                                                           true);

        //    this.PresentItemSelectionViewController(controller);
        //}

        /// <summary>
        /// 2.스캔결과값
        /// </summary>
        /// <param name="metadataObject"></param>
        /// <returns></returns>
        private MetadataObjectLayer CreateMetadataOverlay(AVMetadataObject metadataObject)
        {
            // Transform the metadata object so the bounds are updated to reflect those of the video preview layer.
            var transformedMetadataObject = this.PreviewView.VideoPreviewLayer.GetTransformedMetadataObject(metadataObject);

            // Create the initial metadata object overlay layer that can be used for either machine readable codes or faces.
            //빔 컬러
            var metadataObjectOverlayLayer = new MetadataObjectLayer
            {
                LineWidth      = 3,
                LineJoin       = CAShapeLayer.JoinRound,
                MetadataObject = transformedMetadataObject,
                FillColor      = UIColor.Red.CGColor,
                StrokeColor    = UIColor.Red.CGColor
                                 //FillColor = this.View.TintColor.ColorWithAlpha(0.3f).CGColor,
                                 //StrokeColor = this.View.TintColor.ColorWithAlpha(0.7f).CGColor
            };

            var barcodeMetadataObject = transformedMetadataObject as AVMetadataMachineReadableCodeObject;

            if (barcodeMetadataObject != null)
            {
                var barcodeOverlayPath = this.BarcodeOverlayPathWithCorners(barcodeMetadataObject.Corners);
                metadataObjectOverlayLayer.Path = barcodeOverlayPath;

                // If the metadata object has a string value, display it.
                string textLayerString = null;

                //스캔된 바코드 값
                //바코드 타입 : barcodeMetadataObject.Type
                if (!string.IsNullOrEmpty(barcodeMetadataObject.StringValue))
                {
                    textLayerString = barcodeMetadataObject.StringValue;
                }
                else
                {
                    // TODO: add Descriptor (line 618 in original iOS sample)
                }

                //스캔된 바코드 값
                if (!string.IsNullOrEmpty(textLayerString))
                {
                    Console.WriteLine("========Result========");
                    Console.WriteLine(barcodeMetadataObject.Type + ", " + barcodeMetadataObject.StringValue);

                    //this.PreviewView.customOverlay.tableSource.tableItems.Add(new TableItem { Heading = "heading", SubHeading = "subheading", ImageName = "barcode36x36.png" });

                    //this.InvokeOnMainThread(() => { this.PreviewView.customOverlay.RowAdd("aa", "bb"); });

                    var barcodeOverlayBoundingBox = barcodeOverlayPath.BoundingBox;

                    var font = UIFont.BoldSystemFontOfSize(16).ToCTFont();

                    var textLayer = new CATextLayer();
                    textLayer.TextAlignmentMode = CATextLayerAlignmentMode.Center;
                    //글자표시 박스, 높이가 작아서 글자 안보임 +50추가
                    textLayer.Bounds = new CGRect(0, 0, barcodeOverlayBoundingBox.Size.Width + 20, barcodeOverlayBoundingBox.Size.Height + 50);
                    //textLayer.Bounds = new CGRect(0, 0, 300, 100);
                    textLayer.ContentsScale = UIScreen.MainScreen.Scale;
                    textLayer.Position      = new CGPoint(barcodeOverlayBoundingBox.GetMidX(), barcodeOverlayBoundingBox.GetMidY());
                    textLayer.Wrapped       = true;
                    textLayer.Transform     = CATransform3D.MakeFromAffine(this.PreviewView.Transform).Invert();

                    //-------------------------------------
                    //스캔된 바코드 biz logic
                    //-------------------------------------

                    //연속 스캔
                    if (this.IsContinue)
                    {
                        if (this.IsFixed)
                        {
                            if (this.AllScanBarcode.Contains(textLayerString))
                            {
                                //1. 저장 했는지?
                                if (this.SaveCompletedBarcode.Contains(textLayerString))
                                {
                                    //저장 완료
                                    //Color.Green
                                    textLayer.String           = "저장 완료\n" + textLayerString;
                                    textLayer.AttributedString = new NSAttributedString(textLayer.String, new CTStringAttributes
                                    {
                                        Font            = font,
                                        StrokeWidth     = 0,
                                        StrokeColor     = UIColor.Black.CGColor,
                                        ForegroundColor = UIColor.Green.CGColor
                                    });

                                    //경고
                                    audioCautionPlayer.Play();
                                    doubleVibrator.PlaySystemSoundAsync();
                                }
                                //2. Scan 완료 했는지?
                                else if (this.ScanCompletedBarcode.Contains(textLayerString))
                                {
                                    //스캔 완료
                                    //Color.Yellow
                                    textLayer.String           = "스캔 완료\n" + textLayerString;
                                    textLayer.AttributedString = new NSAttributedString(textLayer.String, new CTStringAttributes
                                    {
                                        Font            = font,
                                        StrokeWidth     = 0,
                                        StrokeColor     = UIColor.Black.CGColor,
                                        ForegroundColor = UIColor.Yellow.CGColor
                                    });

                                    //경고
                                    audioCautionPlayer.Play();
                                    doubleVibrator.PlaySystemSoundAsync();
                                }
                                else
                                {
                                    //------------
                                    //정상처리 작업
                                    //------------
                                    OnScanCompleted?.Invoke(barcodeMetadataObject.Type.ToString(), textLayerString);

                                    textLayer.String           = textLayerString;
                                    textLayer.AttributedString = new NSAttributedString(textLayer.String, new CTStringAttributes
                                    {
                                        Font            = font,
                                        StrokeWidth     = 0,
                                        StrokeColor     = UIColor.Black.CGColor,
                                        ForegroundColor = UIColor.White.CGColor
                                    });

                                    //정상
                                    audioPlayer.Play();
                                    SystemSound.Vibrate.PlaySystemSoundAsync();

                                    if (!this.ScanCompletedBarcode.Contains(textLayerString))
                                    {
                                        this.ScanCompletedBarcode.Add(textLayerString);
                                    }

                                    if (this.AllScanBarcode.Count == this.SaveCompletedBarcode.Count + this.ScanCompletedBarcode.Count)
                                    {
                                        this.session.StopRunning();

                                        OnScanCompleted?.Invoke(string.Empty, "EXIT");
                                        DismissViewController(true, null); //화면 종료
                                    }
                                    else
                                    {
                                        //연속스캔 사이의 간격 지정
                                        //이 함수 호출하는 부분에서 처리
                                    }
                                }
                            }
                            else
                            {
                                //스캔 대상X
                                //Color.Red
                                textLayer.String           = "스캔 대상X\n" + textLayerString;
                                textLayer.AttributedString = new NSAttributedString(textLayer.String, new CTStringAttributes
                                {
                                    Font            = font,
                                    StrokeWidth     = 0,
                                    StrokeColor     = UIColor.Black.CGColor,
                                    ForegroundColor = UIColor.Red.CGColor
                                });

                                //경고
                                audioCautionPlayer.Play();
                                doubleVibrator.PlaySystemSoundAsync();
                            }
                        }
                        //비고정(스캔 대상 없음)
                        else
                        {
                            //현재로서는 biz로직 없음
                        }
                    }
                    //단일 스캔
                    else
                    {
                        this.session.StopRunning();

                        textLayer.String           = textLayerString;
                        textLayer.AttributedString = new NSAttributedString(textLayer.String, new CTStringAttributes
                        {
                            Font            = font,
                            StrokeWidth     = 0,
                            StrokeColor     = UIColor.Black.CGColor,
                            ForegroundColor = UIColor.White.CGColor
                        });

                        //정상
                        audioPlayer.Play();
                        SystemSound.Vibrate.PlaySystemSoundAsync();

                        OnScanCompleted?.Invoke(barcodeMetadataObject.Type.ToString(), textLayerString);
                        DismissViewController(true, null); //화면 종료
                    }

                    //화면에 표시
                    textLayer.SetFont(font);
                    metadataObjectOverlayLayer.AddSublayer(textLayer);
                }
            }
            else if (transformedMetadataObject is AVMetadataFaceObject)
            {
                metadataObjectOverlayLayer.Path = CGPath.FromRect(transformedMetadataObject.Bounds);
            }

            return(metadataObjectOverlayLayer);
        }
Esempio n. 6
0
            /**
             * Update the position/characteristics of the face within the overlay.
             * 바코드 Result부분
             */
            public override void OnUpdate(Detector.Detections detections, Java.Lang.Object item)
            {
                //2개이상 바코드를 스캔해서 경고창이 발생할 경우 화면이 Freeze된다.
                //if (detections.DetectedItems.Size() != 1)
                //{
                //    return;
                //}

                Rect  rect = ((BarcodeScannerActivity)_activity).mPreview.mSurfaceView._clipBounds;
                float left;
                float right;
                float top;
                float bottom;

                //IList<Point> point = (item as Barcode).CornerPoints;
                if (!Settings.ScanMode.Equals("FULL"))
                {
                    left  = (rect.Left * (float)((BarcodeScannerActivity)_activity).mCameraSource.PreviewSize.Height) / (float)((BarcodeScannerActivity)_activity).mPreview.mSurfaceView.scaleNominatorX;
                    right = (rect.Right * (float)((BarcodeScannerActivity)_activity).mCameraSource.PreviewSize.Height) / (float)((BarcodeScannerActivity)_activity).mPreview.mSurfaceView.scaleNominatorX;

                    top    = (rect.Top * (float)((BarcodeScannerActivity)_activity).mCameraSource.PreviewSize.Width) / (float)((BarcodeScannerActivity)_activity).mPreview.mSurfaceView.scaleNominatorY;
                    bottom = (rect.Bottom * (float)((BarcodeScannerActivity)_activity).mCameraSource.PreviewSize.Width) / (float)((BarcodeScannerActivity)_activity).mPreview.mSurfaceView.scaleNominatorY;

                    //관심영여과 스캔한 바코드가 교차영역이 없으면 skip한다.
                    //카메라와 PreView 좌표가 넘어온다. Layout 크기와 Preview 카메라 크기가 다르면 아래 코드는 작동하지 않는다.
                    //if (!(item as Barcode).BoundingBox.Intersect(((BarcodeScannerActivity)_activity).mPreview.mSurfaceView.GetAreaOfInterestCamera()))

                    if (!(item as Barcode).BoundingBox.Intersect(new Rect((int)left, (int)top, (int)right, (int)bottom)))
                    {
                        return;
                    }
                }

                //화면 표시
                mOverlay.Add(mBarcodeGraphic);

                //1. 단일/연속 구분
                //연속 스캔
                if (((BarcodeScannerActivity)_activity).IsContinue)
                {
                    //고정(스캔 해야할 대상이 정해져 있음)
                    if (((BarcodeScannerActivity)_activity).IsFixed)
                    {
                        if (((BarcodeScannerActivity)_activity).AllScanBarcode.Contains(item.JavaCast <Barcode>().DisplayValue))
                        {
                            //1. 저장 했는지?
                            if (((BarcodeScannerActivity)_activity).SaveCompletedBarcode.Contains(item.JavaCast <Barcode>().DisplayValue))
                            {
                                //CameraStop();
                                mBarcodeGraphic.UpdateBarcode(item.JavaCast <Barcode>(), "저장 완료", 3);
                                //long[] pattern = { 0, 100, 1000 };
                                Warning();

                                //Task.Run(() =>
                                //{
                                //    ((BarcodeScannerActivity)_activity).StartCameraSource();
                                //});
                            }
                            //2. Scan완료 했는지?
                            else if (((BarcodeScannerActivity)_activity).ScanCompletedBarcode.Contains(item.JavaCast <Barcode>().DisplayValue))
                            {
                                //CameraStop();
                                mBarcodeGraphic.UpdateBarcode(item.JavaCast <Barcode>(), "스캔 완료", 1);
                                //long[] pattern = { 0, 100, 1000 };
                                Warning();

                                //Task.Run(() =>
                                //{
                                //    ((BarcodeScannerActivity)_activity).StartCameraSource();
                                //});
                            }
                            else
                            {
                                //------------
                                //정상처리 작업
                                //------------
                                mBarcodeGraphic.UpdateBarcode(item.JavaCast <Barcode>(), string.Empty, 0);
                                OnScanCompleted?.Invoke(item.JavaCast <Barcode>());

                                ((BarcodeScannerActivity)_activity)._playerBeep.Start();

                                if (((BarcodeScannerActivity)_activity).vibrator != null)
                                {
                                    try
                                    {
                                        ((BarcodeScannerActivity)_activity).vibrator.Vibrate(300);
                                    }
                                    catch (Exception e)
                                    {
                                        Console.WriteLine(e.Message);
                                    }
                                }

                                if (!((BarcodeScannerActivity)_activity).ScanCompletedBarcode.Contains(item.JavaCast <Barcode>().DisplayValue))
                                {
                                    ((BarcodeScannerActivity)_activity).ScanCompletedBarcode.Add(item.JavaCast <Barcode>().DisplayValue);
                                }

                                if
                                (
                                    ((BarcodeScannerActivity)_activity).AllScanBarcode.Count ==
                                    ((BarcodeScannerActivity)_activity).SaveCompletedBarcode.Count +
                                    ((BarcodeScannerActivity)_activity).ScanCompletedBarcode.Count
                                )
                                {
                                    CameraStop();
                                    Barcode barcode = new Barcode
                                    {
                                        DisplayValue = "EXIT"
                                    };
                                    OnScanCompleted?.Invoke(barcode);

                                    //Task.Delay(200).Wait();
                                    Thread.Sleep(300);
                                    ((BarcodeScannerActivity)_activity).Finish(); //Finsh해야 스캔 화면 종료됨.
                                }
                                else
                                {
                                    //연속스캔 사이의 간격 지정
                                    //Task.Delay(1000).Wait();
                                    Thread.Sleep(1000);
                                }
                            }
                        }
                        else
                        {
                            mBarcodeGraphic.UpdateBarcode(item.JavaCast <Barcode>(), "스캔 대상X", 2);
                            Warning();
                        }
                    }
                    //비고정(스캔 대상이 없음)
                    else
                    {
                        //현재로서는 biz로직이 없음
                        //mBarcodeGraphic.UpdateBarcode(item.JavaCast<Barcode>(), 0, ((BarcodeScannerActivity)_activity).rowPosition++);
                        //OnScanCompleted(item.JavaCast<Barcode>());
                        //if (!((BarcodeScannerActivity)_activity).ScanCompletedBarcode.Contains(item.JavaCast<Barcode>().DisplayValue))
                        //{
                        //    ((BarcodeScannerActivity)_activity).ScanCompletedBarcode.Add(item.JavaCast<Barcode>().DisplayValue);
                        //}

                        //Task.Delay(700).Wait();
                    }
                }
                //단일 스캔
                else
                {
                    CameraStop();
                    mBarcodeGraphic.UpdateBarcode(item.JavaCast <Barcode>(), string.Empty, 1);
                    OnScanCompleted?.Invoke(item.JavaCast <Barcode>());

                    ((BarcodeScannerActivity)_activity)._playerBeep.Start();

                    if (((BarcodeScannerActivity)_activity).vibrator != null)
                    {
                        try
                        {
#pragma warning disable CS0618 // Type or member is obsolete
                            ((BarcodeScannerActivity)_activity).vibrator.Vibrate(300);
#pragma warning restore CS0618 // Type or member is obsolete
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    }

                    //Task.Delay(200).Wait();
                    Thread.Sleep(300);
                    ((BarcodeScannerActivity)_activity).Finish(); //Finsh해야 스캔 화면 종료됨.
                }

                if (mBarcodeGraphic != null)
                {
                    mOverlay.Remove(mBarcodeGraphic);
                }
            }
 public void ScanCompleted()
 {
     OnScanCompleted?.Invoke(ScandedBarcode);
 }
Esempio n. 8
0
 private IEnumerable <ScanCompletedEventHandler> ScanCompletedEventHandlers()
 {
     return(from d in OnScanCompleted.GetInvocationList() select(ScanCompletedEventHandler) d);
 }