private void DefaultsFab_Click(object sender, EventArgs e)
        {
            //StartActivityForResult(typeof(ScanTemplateActivity), AndroidHelper.RESULT_PRODUCT_DEFAULTS);
            ViewModel.ViewProductDefaults();
            scanner.Cancel();

            adjustingDefaults = true;
        }
Example #2
0
        async void BtnCustomView_TouchUpInsideAsync(object sender, EventArgs e)
        {
            try
            {
                //Create an instance of our custom overlay
                customOverlay = new CustomOverlayView();
                //Wireup the buttons from our custom overlay
                customOverlay.ButtonTorch.TouchUpInside += delegate {
                    scanner.ToggleTorch();
                };
                customOverlay.ButtonCancel.TouchUpInside += delegate {
                    scanner.Cancel();
                };

                //Tell our scanner to use our custom overlay
                scanner.UseCustomOverlay = true;
                scanner.CustomOverlay    = customOverlay;

                var result = await scanner.Scan(new MobileBarcodeScanningOptions { AutoRotate = true });

                HandleScanResult(result);
            }
            catch (Exception ex)
            {
                npcc_services.inf_mobile_exception_managerAsync(ex.Message);
            }
        }
Example #3
0
        void buttonSample3_Click(object sender, EventArgs e)
        {
            var scanner = new MobileBarcodeScanner(this);

            var overlay = (LinearLayout)this.LayoutInflater.Inflate(Resource.Layout.ScanOverlayLayout, null, false);

            var buttonCancel = overlay.FindViewById <Button>(Resource.Id.buttonCancelScan);
            var buttonFlash  = overlay.FindViewById <Button>(Resource.Id.buttonToggleFlash);

            buttonCancel.Click += (object sender2, EventArgs e2) =>
            {
                scanner.Cancel();
            };

            buttonFlash.Click += (object sender2, EventArgs e2) =>
            {
                scanner.ToggleTorch();
            };

            scanner.UseCustomOverlay = true;
            scanner.CustomOverlay    = overlay;

            scanner.Scan().ContinueWith((t) => {
                ShowMessage(t.Result != null ? "Scanned: " + t.Result.Text : "No Barcode Scanned");
            });
        }
Example #4
0
        public override void ViewDidLoad()
        {
            //Create a new instance of our scanner
            scanner = new MobileBarcodeScanner();

            //Setup our button
            buttonDefaultScan       = new UIButton(UIButtonType.RoundedRect);
            buttonDefaultScan.Frame = new RectangleF(20, 80, 280, 40);
            buttonDefaultScan.SetTitle("Scan with Default View", UIControlState.Normal);
            buttonDefaultScan.TouchUpInside += (sender, e) =>
            {
                //Tell our scanner to use the default overlay
                scanner.UseCustomOverlay = false;
                //We can customize the top and bottom text of the default overlay
                scanner.TopText    = "Hold camera up to barcode to scan";
                scanner.BottomText = "Barcode will automatically scan";

                //Start scanning
                scanner.Scan().ContinueWith((t) =>
                {
                    //Our scanning finished callback
                    if (t.Status == System.Threading.Tasks.TaskStatus.RanToCompletion)
                    {
                        HandleScanResult(t.Result);
                    }
                });
            };

            buttonCustomScan       = new UIButton(UIButtonType.RoundedRect);
            buttonCustomScan.Frame = new RectangleF(20, 20, 280, 40);
            buttonCustomScan.SetTitle("Scan with Custom View", UIControlState.Normal);
            buttonCustomScan.TouchUpInside += (sender, e) =>
            {
                //Create an instance of our custom overlay
                customOverlay = new CustomOverlayView();
                //Wireup the buttons from our custom overlay
                customOverlay.ButtonTorch.TouchUpInside += delegate {
                    scanner.ToggleTorch();
                };
                customOverlay.ButtonCancel.TouchUpInside += delegate {
                    scanner.Cancel();
                };

                //Tell our scanner to use our custom overlay
                scanner.UseCustomOverlay = true;
                scanner.CustomOverlay    = customOverlay;

                scanner.Scan().ContinueWith((t) =>
                {
                    //Our scanning finished callback
                    if (t.Status == System.Threading.Tasks.TaskStatus.RanToCompletion)
                    {
                        HandleScanResult(t.Result);
                    }
                });
            };

            this.View.AddSubview(buttonDefaultScan);
            this.View.AddSubview(buttonCustomScan);
        }
Example #5
0
        void _qrFoundEventVoid(string stringData)
        {
            _scanner.Cancel();

            string activationCode = "null";

            if (stringData.Contains("itsbeta.com/activate?activation_code="))
            {
                activationCode = stringData.Split('=')[1];
                qrValid        = true;
            }
            else
            {
                string qrtoastStr = "QR Code несоответствует формату";
                if (!AppInfo.IsLocaleRu)
                {
                    qrtoastStr = "Wrong QR-Code format mismatch";
                }
                RunOnUiThread(() => Toast.MakeText(this, qrtoastStr, ToastLength.Short).Show());
                qrValid = false;
            }

            if (qrValid)
            {
                RunOnUiThread(() => ShowQRDialog());
                ThreadStart threadStart = new ThreadStart(() => AsyncActivizationViaQR(activationCode));
                Thread      loadThread  = new Thread(threadStart);
                loadThread.Start();
                qrValid = false;
            }
        }
Example #6
0
        private void buttonScanCustom_Click(object sender, RoutedEventArgs e)
        {
            //Get our UIElement from the MainPage.xaml (this) file
            // to use as our custom overlay
            if (customOverlayElement == null)
            {
                customOverlayElement = this.customOverlay.Children[0];
                this.customOverlay.Children.RemoveAt(0);
            }

            //Wireup our buttons from the custom overlay
            this.buttonCancel.Click += (s, e2) =>
            {
                scanner.Cancel();
            };
            this.buttonFlash.Click += (s, e2) =>
            {
                scanner.ToggleTorch();
            };

            //Set our custom overlay and enable it
            scanner.CustomOverlay    = customOverlayElement;
            scanner.UseCustomOverlay = true;

            //Start scanning
            scanner.Scan().ContinueWith(t =>
            {
                if (t.Result != null)
                {
                    HandleScanResult(t.Result);
                }
            });
        }
Example #7
0
        protected async void StartScanning()
        {
            scanner = new MobileBarcodeScanner()
            {
                UseCustomOverlay = true
            };

            var customOverlay = LayoutInflater.FromContext(this).Inflate(Resource.Layout.QRoverlay, null);

            customOverlay.FindViewById <ImageButton>(Resource.Id.qr_flashlight_button).Click += (ob, ev) =>
            {
                scanner.ToggleTorch();
            };
            customOverlay.FindViewById <ImageButton>(Resource.Id.qr_cancel_button).Click += (ob, ev) =>
            {
                scanner.Cancel();
            };

            scanner.CustomOverlay = customOverlay;

            var opts = new MobileBarcodeScanningOptions()
            {
                AutoRotate = true, PossibleFormats = new List <BarcodeFormat> {
                    BarcodeFormat.QR_CODE
                }
            };

            var result = await scanner.Scan(opts);

            HandleScanResult(result);
        }
Example #8
0
        async void AutoScan()
        {
            scanner.UseCustomOverlay = true;
            zxingOverlay             = LayoutInflater.FromContext(this).Inflate(Resource.Layout.ZxingOverlay, null);

            ImageView ivScanning    = zxingOverlay.FindViewById <ImageView>(Resource.Id.ivScanning);
            Button    btnCancelScan = zxingOverlay.FindViewById <Button>(Resource.Id.btnCancelScan);

            btnCancelScan.Click += (s, e) =>
            {
                if (scanner != null)
                {
                    scanner.Cancel();
                }
            };

            zxingOverlay.Measure(MeasureSpecMode.Unspecified.GetHashCode(), MeasureSpecMode.Unspecified.GetHashCode());
            int width  = zxingOverlay.MeasuredWidth;
            int height = zxingOverlay.MeasuredHeight;

            // 从上到下的平移动画
            Animation verticalAnimation = new TranslateAnimation(0, 0, 0, height);

            verticalAnimation.Duration    = 3000;               // 动画持续时间
            verticalAnimation.RepeatCount = Animation.Infinite; // 无限循环

            // 播放动画
            ivScanning.Animation = verticalAnimation;
            verticalAnimation.StartNow();

            scanner.CustomOverlay = zxingOverlay;
            var mbs = MobileBarcodeScanningOptions.Default;

            mbs.AssumeGS1                 = true;
            mbs.AutoRotate                = true;
            mbs.DisableAutofocus          = false;
            mbs.PureBarcode               = false;
            mbs.TryInverted               = true;
            mbs.TryHarder                 = true;
            mbs.UseCode39ExtendedMode     = true;
            mbs.UseFrontCameraIfAvailable = false;
            mbs.UseNativeScanning         = true;

            var result = await scanner.Scan(this, mbs);

            HandleScanResult(result);
        }
Example #9
0
 protected override bool OnBackButtonPressed()
 {
     if (isScanning)
     {
         scanner.Cancel();
         return(true);
     }
     return(base.OnBackButtonPressed());
 }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.LinkSticker);

            clientName = Android.OS.Build.Manufacturer + " " + Android.OS.Build.Model;

            InitElements();

            FindViewById <RelativeLayout>(Resource.Id.backRL).Click += (s, e) => OnBackPressed();

            _linkStickerBn.Click += async(s, e) =>
            {
                if (Build.VERSION.SdkInt >= Build.VERSION_CODES.M)
                {
                    RequestCameraPermissions();
                }

                MobileBarcodeScanner.Initialize(Application);
                _optionsCustom = new MobileBarcodeScanningOptions();
                _scanner       = new MobileBarcodeScanner();

                _scanner = new MobileBarcodeScanner();
                _scanner.UseCustomOverlay = true;

                //Inflate our custom overlay from a resource layout
                _zxingOverlay = LayoutInflater.FromContext(this).Inflate(Resource.Layout.ZxingOverlay, null);

                //Find the button from our resource layout and wire up the click event
                _flashButton       = _zxingOverlay.FindViewById <Button>(Resource.Id.buttonZxingFlash);
                _cancelButton      = _zxingOverlay.FindViewById <Button>(Resource.Id.buttonZxingCancel);
                _flashButton.Text  = TranslationHelper.GetString("flash", GetCurrentCulture.GetCurrentCultureInfo());
                _cancelButton.Text = TranslationHelper.GetString("cancel", GetCurrentCulture.GetCurrentCultureInfo());
                _flashButton.SetTypeface(_tf, TypefaceStyle.Normal);
                _cancelButton.SetTypeface(_tf, TypefaceStyle.Normal);
                _flashButton.Click  += (sender, e1) => _scanner.ToggleTorch();
                _cancelButton.Click += (sender, e1) => _scanner.Cancel();

                //Set our custom overlay
                _scanner.CustomOverlay = _zxingOverlay;
                try
                {
                    _optionsCustom.CameraResolutionSelector = new CameraResolutionSelectorDelegate(SelectLowestResolutionMatchingDisplayAspectRatio);//new CameraResolution { Height = 1920, Width = 1080 };
                }
                catch (Exception ex)
                {
                }
                _optionsCustom.AutoRotate = false;
                if (Build.VERSION.SdkInt < Build.VERSION_CODES.M)
                {
                    await LaunchScanner();
                }
            };

            _orderBn.Click += OpenOrderLink;
        }
Example #11
0
 private void HandleScanResult(Result result)
 {
     if (result != null && !string.IsNullOrEmpty(result.Text))
     {
         var scannerViewModel = ViewModel as ScannerViewModel;
         scannerViewModel?.SaveToDatabase(result.Text);
         _scanner.Cancel();
     }
     else
     {
         StartScan();
     }
 }
Example #12
0
        private async System.Threading.Tasks.Task ScanFunction()
        {
            //Tell our scanner we want to use a custom overlay instead of the default
            scanner.UseCustomOverlay = true;

            //Inflate our custom overlay from a resource layout
            scanOverlay = LayoutInflater.FromContext(this).Inflate(Resource.Layout.ScanLayout, null);

            //Find the button from our resource layout and wire up the click event
            buttonFlash        = scanOverlay.FindViewById <Button>(Resource.Id.buttonFlash);
            buttonFlash.Click += (sender, e) =>
            {
                scanner.ToggleTorch();
            };

            buttonCancelScan        = scanOverlay.FindViewById <Button>(Resource.Id.buttonCancel);
            buttonCancelScan.Click += (sender, e) => scanner.Cancel();

            //Set our custom overlay
            scanner.CustomOverlay = scanOverlay;

            //Set scanner possible modes
            var options = new MobileBarcodeScanningOptions();

            options.PossibleFormats = new List <BarcodeFormat>()
            {
                BarcodeFormat.QR_CODE,
                BarcodeFormat.PDF_417,
                BarcodeFormat.CODE_39
            };

            //Start scanning!
            var result = await scanner.Scan(options);


            string msg = "";

            if (result != null && !string.IsNullOrEmpty(result.Text))
            {
                msg = result.Text;
                if (result.BarcodeFormat == BarcodeFormat.QR_CODE)
                {
                    RecipientBurstAddress.Text = msg;
                }
            }
            else
            {
                msg = "Scanning Cancelled!";
                this.RunOnUiThread(() => Toast.MakeText(this, msg, ToastLength.Long).Show());
            }
        }
        public async Task <string> RetrieveFromQRAsync()
        {
            var   scanTask = _qrScanner.Scan(_qrScannerOptions);
            await scanTask;

            _qrScanner.Cancel();

            if (scanTask.Result == null)
            {
                return(string.Empty);
            }

            return(scanTask.Result.Text);
        }
Example #14
0
        public override void OnBackPressed()
        {
            _barcodeScanner.Cancel();

            if (_searchView.Iconified)
            {
                base.OnBackPressed();
            }
            else
            {
                _searchView.OnActionViewCollapsed();
                _searchView.Iconified = true;
            }
        }
Example #15
0
        public override void ViewDidLoad()
        {
            //Create a new instance of our scanner
            scanner = new MobileBarcodeScanner(this.NavigationController);

            //Setup our button
            buttonDefaultScan       = new UIButton(UIButtonType.RoundedRect);
            buttonDefaultScan.Frame = new RectangleF(20, 80, 280, 40);
            buttonDefaultScan.SetTitle("Scan with Default View", UIControlState.Normal);
            buttonDefaultScan.TouchUpInside += async(sender, e) =>
            {
                //Tell our scanner to use the default overlay
                scanner.UseCustomOverlay = false;
                //We can customize the top and bottom text of the default overlay
                scanner.TopText    = "Hold camera up to barcode to scan";
                scanner.BottomText = "Barcode will automatically scan";

                //Start scanning
                var result = await scanner.Scan();

                HandleScanResult(result);
            };

            buttonCustomScan       = new UIButton(UIButtonType.RoundedRect);
            buttonCustomScan.Frame = new RectangleF(20, 20, 280, 40);
            buttonCustomScan.SetTitle("Scan with Custom View", UIControlState.Normal);
            buttonCustomScan.TouchUpInside += async(sender, e) =>
            {
                //Create an instance of our custom overlay
                customOverlay = new CustomOverlayView();
                //Wireup the buttons from our custom overlay
                customOverlay.ButtonTorch.TouchUpInside += delegate {
                    scanner.ToggleTorch();
                };
                customOverlay.ButtonCancel.TouchUpInside += delegate {
                    scanner.Cancel();
                };

                //Tell our scanner to use our custom overlay
                scanner.UseCustomOverlay = true;
                scanner.CustomOverlay    = customOverlay;

                var result = await scanner.Scan();

                HandleScanResult(result);
            };

            this.View.AddSubview(buttonDefaultScan);
            this.View.AddSubview(buttonCustomScan);
        }
Example #16
0
        public void StopScanning()
        {
            ScanStatusChanged?.Invoke(this, new ScanStatusEventArgs {
                ScanStatus = "Stopping Scanning"
            });

            if (_scanner != null)
            {
                try {
                    _scanner?.Cancel();
                    _scanner = null;
                } catch (ObjectDisposedException) {
                }
            }
        }
        public override async void OnBackPressed()
        {
            _barcodeScanner.Cancel();

            if (!_searchView.Iconified)
            {
                _searchView.OnActionViewCollapsed();
                _searchView.Iconified = true;
                return;
            }

            if (_authenticatorSource.CategoryId != null)
            {
                await SwitchCategory(null);

                return;
            }

            Finish();
        }
        public async void AddDataShareAsync()
        {
            var scanner = new MobileBarcodeScanner();
            var result  = await scanner.Scan();

            scanner.Cancel();

            if (result == null || string.IsNullOrEmpty(result.Text))
            {
                return;
            }

            var medicalInstitution = JsonConvert.DeserializeObject <MedicalInstitution>(result.Text);

            if (this.MedicalInstitutions.All(m => m.Name != medicalInstitution.Name))
            {
                this.MedicalInstitutions.Add(medicalInstitution);
                await SecureStorage.SetAsync("MedicalInstitutions", JsonConvert.SerializeObject(this.MedicalInstitutions));
            }
        }
Example #19
0
        private async void HandleScanResult(ZXing.Result result)
        {
            if (result == null)
            {
                return;
            }
            _player.Start();

            var lookupResult = await Http.GetAssetName(result.Text);

            lookupResult = lookupResult.Replace("\"", "");
            RunOnUiThread(() =>
            {
                if (_scannedItems.Contains(lookupResult))
                {
                    _scanner.Cancel();

                    var alert = new AlertDialog.Builder(this);
                    alert.SetTitle("Duplicate Scan");
                    alert.SetMessage($"Are you sure you want to scan {lookupResult} again?");
                    alert.SetPositiveButton("Yes", (senderAlert, args) =>
                    {
                        _scannedItems.Add(lookupResult);
                        UpdateScanListView();
                        _scanner.ScanContinuously(_option, HandleScanResult);
                    });

                    alert.SetNegativeButton("No", (senderAlert, args) => { _scanner.ScanContinuously(_option, HandleScanResult); });

                    Dialog dialog = alert.Create();
                    dialog.Show();
                }
                else
                {
                    _scannedItems.Add(lookupResult);
                    UpdateScanListView();
                }
            });
        }
 private void HandleScanResult(ZXing.Result result)
 {
     if (result != null && !string.IsNullOrEmpty(result.Text))
     {
         if (result.Text == ServerUtils.GetTaskQRCodeData(currentScanTask.Id))
         {
             scanner.Cancel();
             InvokeOnMainThread(() =>
             {
                 Toast.ShowToast("Found!");
                 TaskResultReturned(null, currentScanTask.Id);
             });
         }
         else
         {
             InvokeOnMainThread(() => { Toast.ShowToast("That's not the right code!"); });
         }
     }
     else
     {
         InvokeOnMainThread(() => { Toast.ShowToast("Scan cancelled"); });
     }
 }
Example #21
0
        public async void Scan()
        {
            scanner.UseCustomOverlay = true;
            var options = new MobileBarcodeScanningOptions()
            {
                AutoRotate  = false,
                TryInverted = true
            };

            customscanlayout      = new CustomOverlayView();
            scanner.CustomOverlay = customscanlayout;
            //var options = new MobileBarcodeScanningOptions() { };
            customscanlayout.ButtonTorch.TouchUpInside += delegate {
                if (customscanlayout.ButtonTorch.TitleLabel.Text == "Tắt Flash")
                {
                    customscanlayout.ButtonTorch.SetTitle("Bật Flash", UIControlState.Normal);
                }
                else
                {
                    customscanlayout.ButtonTorch.SetTitle("Tắt Flash", UIControlState.Normal);
                }

                scanner.ToggleTorch();
            };
            customscanlayout.ButtonCancel.TouchUpInside += delegate
            {
                scanner.Cancel();
            };
            //scanner.TopText = "Giữ camera cách mã khoảng 6inch";
            //scanner.BottomText = "Đợi một chút...";

            var result = await scanner.Scan();

            System.Diagnostics.Debug.WriteLine("Đợi két quả");
            HandleScanResult(result);
        }
Example #22
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            UDID = UIDevice.CurrentDevice.IdentifierForVendor.ToString();

            backBn.TouchUpInside += (s, e) =>
            {
                this.NavigationController.PopViewController(true);
            };

            linkStickerBn.TouchUpInside += async(s, e) =>
            {
                _scanner = new MobileBarcodeScanner();
                var customView = new UIView();
                customView.Frame          = View.Frame;
                _scanner.UseCustomOverlay = true;
                _scanner.CustomOverlay    = customView;

                var bottomView = new UIView {
                    BackgroundColor = UIColor.FromRGB(36, 43, 52)
                };
                customView.AddSubview(bottomView);
                bottomView.Frame = new CGRect(0, customView.Frame.Height - 100, View.Frame.Width, 100);

                var cancelBn = new UIButton();
                cancelBn.SetTitle("Отмена", UIControlState.Normal);
                cancelBn.SetTitleColor(UIColor.White, UIControlState.Normal);
                cancelBn.Font = UIFont.FromName(Constants.fira_sans, 15f);
                bottomView.AddSubview(cancelBn);
                cancelBn.Frame          = new CGRect(0, 0, View.Frame.Width / 3, 60);
                cancelBn.TouchUpInside += (s1, e1) =>
                {
                    _scanner.Cancel();
                };

                var flashBn = new UIButton();
                flashBn.SetTitle("Вспышка", UIControlState.Normal);
                flashBn.SetTitleColor(UIColor.White, UIControlState.Normal);
                flashBn.Font = UIFont.FromName(Constants.fira_sans, 15f);
                bottomView.AddSubview(flashBn);
                flashBn.Frame          = new CGRect(View.Frame.Width - View.Frame.Width / 3, 0, View.Frame.Width / 3, 60);
                flashBn.TouchUpInside += (s1, e1) =>
                {
                    _scanner.Torch(!_scanner.IsTorchOn);
                };

                var shotRectangleIv = new UIImageView();
                var rectangleSide   = View.Frame.Width - View.Frame.Width / 3;
                shotRectangleIv.Frame = new CGRect(View.Frame.Width / 6, (customView.Frame.Height - bottomView.Frame.Height) / 2 - rectangleSide / 2, rectangleSide, rectangleSide);
                shotRectangleIv.Image = UIImage.FromBundle("scanner_rectangle.png");
                customView.AddSubview(shotRectangleIv);

                _optionsCustom            = new MobileBarcodeScanningOptions();
                _optionsCustom.AutoRotate = false;

                await LaunchScanner();
            };

            orderStickerBn.TouchUpInside += (s, e) => OpenOrderLink();

            InitElements();
        }
Example #23
0
        public async Task GetQRCodeAsync(bool InOrOut)
        {
            var app = Forms.Context as Activity;

            MobileBarcodeScanner.Initialize(app.Application);

            var scanner = new MobileBarcodeScanner();

            var result = await scanner.Scan();

            if (result != null)
            {
                string[] block = result.Text.Split(',');

                if (InOrOut)
                {
                    blockIn = new Block(block[1], block[2], block[0]);
                    PageAddInBlock.IsEnabled = false;
                    PageAddInBlock.Text      = "Установлен: " + blockIn.GetText();
                }
                else
                {
                    blockOut = new Block(block[1], block[2], block[0]);
                    PageAddOutBlock.IsEnabled = false;
                    PageAddOutBlock.Text      = "Снят: " + blockOut.GetText();
                }

                Console.WriteLine("Scanned Barcode: " + result.Text);

                if ((blockIn != null) && (blockOut != null))
                {
                    Console.WriteLine("Собрана замена: ");
                    bool defect = false;
                    defect = await DisplayAlert("Замена оборудования", "Замененное оборудование вышло из строя?", "Да", "Нет");

                    Replace.CreateReplace(blockIn, blockOut, defect);
                    var str     = Replace.GetReplaces.Last().GetText();
                    var strings = str.Split(';');
                    Label.Text = strings[0].TrimEnd(' ') + "\n" + strings[1].TrimStart(' ').TrimEnd(' ');

                    var childs = new List <View>();
                    foreach (View v in GetLayout.Children)
                    {
                        childs.Add(v);
                    }
                    GetLayout.Children.Clear();

                    var RemoveReplace = new TapGestureRecognizer();
                    RemoveReplace.Tapped += (s, e) =>
                    {
                        Replace.GetReplaces.Remove(Replace.GetReplaces.Last());
                        PageReload();
                    };

                    var ApplyReplace = new TapGestureRecognizer();
                    ApplyReplace.Tapped += (s, e) =>
                    {
                        PageReload();
                    };

                    var ApplyLabel = new Label()
                    {
                        Text                    = "Нажмите сюда чтобы запомнить замену",
                        VerticalOptions         = LayoutOptions.Start,
                        HorizontalOptions       = LayoutOptions.FillAndExpand,
                        HeightRequest           = 70,
                        FontSize                = 18,
                        VerticalTextAlignment   = TextAlignment.Center,
                        HorizontalTextAlignment = TextAlignment.Center,
                        BackgroundColor         = Color.Teal,
                    };
                    ApplyLabel.GestureRecognizers.Add(ApplyReplace);

                    var RemoveLabel = new Label()
                    {
                        Text                    = "Нажмите сюда чтобы сбросить замену",
                        VerticalOptions         = LayoutOptions.End,
                        HorizontalOptions       = LayoutOptions.FillAndExpand,
                        HeightRequest           = 70,
                        FontSize                = 18,
                        VerticalTextAlignment   = TextAlignment.Center,
                        HorizontalTextAlignment = TextAlignment.Center,
                        BackgroundColor         = Color.DarkRed
                    };
                    RemoveLabel.GestureRecognizers.Add(RemoveReplace);

                    GetLayout.Children.Add(ApplyLabel);
                    foreach (View v in childs)
                    {
                        GetLayout.Children.Add(v);
                    }
                    GetLayout.Children.Add(RemoveLabel);
                }
            }
            else
            {
                scanner.Cancel();
            }
        }
Example #24
0
        protected void CreateMiscTests()
        {
            CategoryNames.Add("Miscellaneous Tests");
            CreateTest("QR scanner", async() =>
            {
                UpdateInfo("Testing...");
                MobileBarcodeScanner.Initialize(Application);
                var scanner = new MobileBarcodeScanner()
                {
                    UseCustomOverlay = true
                };

                var customOverlay = LayoutInflater.FromContext(this).Inflate(Resource.Layout.QRoverlay, null);

                customOverlay.FindViewById <ImageButton>(Resource.Id.qr_flashlight_button).Click += (ob, ev) =>
                {
                    scanner.ToggleTorch();
                };
                customOverlay.FindViewById <ImageButton>(Resource.Id.qr_cancel_button).Click += (ob, ev) =>
                {
                    scanner.Cancel();
                };

                scanner.CustomOverlay = customOverlay;

                var opts = new MobileBarcodeScanningOptions()
                {
                    AutoRotate = true, PossibleFormats = new List <BarcodeFormat> {
                        BarcodeFormat.QR_CODE
                    }
                };

                var result = await scanner.Scan(opts);

                string msg = "";

                if (result != null && !string.IsNullOrEmpty(result.Text))
                {
                    msg = "Found QR code: " + result.Text;
                }
                else
                {
                    msg = "Scanning Canceled!";
                }

                this.RunOnUiThread(() => Toast.MakeText(this, msg, ToastLength.Short).Show());
                UpdateInfo($"Test complete. QR code: {result.Text ?? "(Scanning canceled by user)"}");
            });
            CreateTest("NFC Capability", async() =>
            {
                UpdateInfo("Testing; pass device near an NFC tag.");
                var _nfcAdapter = NfcAdapter.GetDefaultAdapter(this);
                if (_nfcAdapter == null)
                {
                    UpdateInfo("Test failed: this device doesn't seem to have NFC capability.");
                    return;
                }

                signalFlag = new AsyncManualResetEvent();

                // Create an intent filter for when an NFC tag is discovered.
                var tagDetected = new IntentFilter(NfcAdapter.ActionTagDiscovered);
                var filters     = new[] { tagDetected };

                // When an NFC tag is detected, Android will use the PendingIntent to come back to this activity.
                // The OnNewIntent method will be invoked by Android.
                var intent        = new Intent(this, this.GetType()).AddFlags(ActivityFlags.SingleTop);
                var pendingIntent = PendingIntent.GetActivity(this, 0, intent, 0);

                Res.AllowNewActivities = false;
                _nfcAdapter.EnableForegroundDispatch(this, pendingIntent, filters, null);

                var token = SetupStopButtonOneShot("Test ended.");
                await Task.WhenAny(token.AsTask(), signalFlag.WaitAsync());
                if (!token.IsCancellationRequested)
                {
                    var text = resultView.Text;
                    stopButton.CallOnClick();
                    while (cts != null)
                    {
                        await Task.Delay(25);
                    }
                    UpdateInfo(text);
                }
            });
            CreateTest("Vibrate", async() =>
            {
                UpdateInfo("Trying to vibrate...");
                Plugin.Vibrate.CrossVibrate.Current.Vibration(1000);
                await Task.Delay(300);
                UpdateInfo("Test complete.");
            });
        }
 void CancelScanning(object sender, EventArgs e)
 {
     Scanner.Cancel();
     BuildDynamicContent(viewModel.Transmission.BuildCompletedMessage());
 }
Example #26
0
 public ScannerView() : base("ScannerView", null)
 {
     _scanner = new MobileBarcodeScanner(NavigationController);
     StartScan();
     _scanner.Cancel();
 }
Example #27
0
        public override void ViewDidLoad()
        {
            //Create a new instance of our scanner
            scanner = new MobileBarcodeScanner(this.NavigationController);

            Root = new RootElement("ZXing.Net.Mobile")
            {
                new Section {
                    new StyledStringElement("Scan with Default View", async() => {
                        //Tell our scanner to use the default overlay
                        scanner.UseCustomOverlay = false;
                        //We can customize the top and bottom text of the default overlay
                        scanner.TopText    = "Hold camera up to barcode to scan";
                        scanner.BottomText = "Barcode will automatically scan";

                        //Start scanning
                        var result = await scanner.Scan();

                        HandleScanResult(result);
                    }),

                    new StyledStringElement("Scan Continuously", () => {
                        //Tell our scanner to use the default overlay
                        scanner.UseCustomOverlay = false;

                        //Tell our scanner to use our custom overlay
                        scanner.UseCustomOverlay = true;
                        scanner.CustomOverlay    = customOverlay;


                        var opt = new MobileBarcodeScanningOptions();
                        opt.DelayBetweenContinuousScans = 3000;

                        //Start scanning
                        scanner.ScanContinuously(opt, true, HandleScanResult);
                    }),

                    new StyledStringElement("Scan with Custom View", async() => {
                        //Create an instance of our custom overlay
                        customOverlay = new CustomOverlayView();
                        //Wireup the buttons from our custom overlay
                        customOverlay.ButtonTorch.TouchUpInside += delegate {
                            scanner.ToggleTorch();
                        };
                        customOverlay.ButtonCancel.TouchUpInside += delegate {
                            scanner.Cancel();
                        };

                        //Tell our scanner to use our custom overlay
                        scanner.UseCustomOverlay = true;
                        scanner.CustomOverlay    = customOverlay;

                        var result = await scanner.Scan();

                        HandleScanResult(result);
                    }),

                    new StyledStringElement("Scan with AVCapture Engine", async() => {
                        //Tell our scanner to use the default overlay
                        scanner.UseCustomOverlay = false;
                        //We can customize the top and bottom text of the default overlay
                        scanner.TopText    = "Hold camera up to barcode to scan";
                        scanner.BottomText = "Barcode will automatically scan";

                        //Start scanning
                        var result = await scanner.Scan(true);

                        HandleScanResult(result);
                    }),

                    new StyledStringElement("Generate Barcode", () => {
                        NavigationController.PushViewController(new ImageViewController(), true);
                    })
                }
            };
        }
Example #28
0
 protected override void OnPause()
 {
     scanner.Cancel();
     base.OnPause();
     Finish();
 }