예제 #1
0
        void PlayClickSound()
        {
            if (_clickSound == null)
            {
                _clickSound = new SystemSound(PlaySoundNo);
            }

            _clickSound.PlaySystemSoundAsync();
        }
예제 #2
0
        /// <summary>
        /// Feedback the specified effect and mode.
        /// </summary>
        /// <param name="effect">Effect.</param>
        /// <param name="mode">Mode.</param>
        public void Feedback(HapticEffect effect, KeyClicks mode = KeyClicks.Default)
        {
            var soundEnabled = (mode & KeyClicks.On) > 0;

            if (mode == KeyClicks.Default)
            {
                soundEnabled = (Forms9Patch.Settings.KeyClicks & KeyClicks.On) > 0;
                if (Forms9Patch.Settings.KeyClicks == KeyClicks.Default)
                {
                    // this no longer works and there doesn't appear to be a way to detect if keyclicks is on
                    //var type = CFPreferences.CurrentApplication;
                    CFPreferences.AppSynchronize("/var/mobile/Library/Preferences/com.apple.preferences.sounds");
                    soundEnabled = CFPreferences.GetAppBooleanValue("keyboard", "/var/mobile/Library/Preferences/com.apple.preferences.sounds");
                }
            }

            if (soundEnabled)
            {
                switch (effect)
                {
                case HapticEffect.None:
                    break;

                case HapticEffect.KeyClick:
                    click.PlaySystemSoundAsync();
                    break;

                case HapticEffect.Return:
                    modifier.PlaySystemSoundAsync();
                    break;

                case HapticEffect.Delete:
                    delete.PlaySystemSoundAsync();
                    break;
                }
            }
        }
예제 #3
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);
        }