protected override void OnElementChanged(ElementChangedEventArgs <Page> args) { base.OnElementChanged(args); if (args.OldElement != null || Element == null) { return; } Log.Debug("", "HI"); try { if (view == null) { var activity = Context as Activity; view = activity.LayoutInflater.Inflate(Resource.Layout.ScanLayout, this, false); AddView(view); scanView = view.FindViewById <ScanView>(Resource.Id.scan_view); scanView.Init("mro_config_shipping_container.json", licenseKey); scanView.ScanViewPlugin.AddScanResultListener(this); scanView.CameraOpened += ScanView_CameraOpened; } } catch (Exception e) { // show error } }
protected override void OnElementChanged(ElementChangedEventArgs <Page> args) { base.OnElementChanged(args); if (args.OldElement != null || Element == null) { return; } string configurationFile = (Element as ScanExamplePage).ConfigurationFile.Replace(".json", "") + ".json"; try { if (view == null) { var activity = Context as Activity; view = activity.LayoutInflater.Inflate(Resource.Layout.ScanLayout, this, false); AddView(view); scanView = view.FindViewById <ScanView>(Resource.Id.scan_view); scanView.Init(configurationFile, licenseKey); scanView.ScanViewPlugin.AddScanResultListener(this); scanView.CameraOpened += ScanView_CameraOpened; } } catch (Exception e) { // show error } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); try { SupportActionBar.SetHomeButtonEnabled(true); SupportActionBar.SetDisplayHomeAsUpEnabled(true); // we pass the json path from the previous activity var jsonPath = Intent.GetStringExtra("jsonPath"); // we pass the title from the previous activity Title = Intent.GetStringExtra("title"); Window.SetFlags(WindowManagerFlags.KeepScreenOn, WindowManagerFlags.KeepScreenOn); SetContentView(Resource.Layout.scan_activity); _scanView = FindViewById <ScanView>(Resource.Id.scan_view); // the initialization parses the json configuration and builds the whole use-case _scanView.Init(jsonPath, LICENSE_KEY); /* * Depending on your config/use-case, the ScanViewPlugin is of a different type. * You need to add your implementation of IO.Anyline.Plugin.IScanResultListener to retrieve scan results. */ _scanView.ScanViewPlugin.AddScanResultListener(_scanResultListener); //var myBarcodeListener = new MyBarcodeListener(); //_scanView.CameraView.EnableBarcodeDetection(myBarcodeListener, null); //var bar = new AT.Nineyards.Anyline.Modules.Barcode.NativeBarcodeScanView(ApplicationContext, null); // handle camera open events _scanView.CameraOpened += ScanView_CameraOpened; // handle camera error events _scanView.CameraError += ScanView_CameraError; _isInitialized = true; } catch (Exception e) { Util.ShowError(e.ToString(), this); } }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); // register events if (_anylineScanView != null) { _anylineScanView.CameraView.CameraOpened -= CameraView_CameraOpened; _anylineScanView.CameraView.CameraClosed -= CameraView_CameraClosed; _anylineScanView.CameraView.CameraError -= CameraView_CameraError; _anylineScanView.CameraView.CameraOpened += CameraView_CameraOpened; _anylineScanView.CameraView.CameraClosed += CameraView_CameraClosed; _anylineScanView.CameraView.CameraError += CameraView_CameraError; Window.Current.VisibilityChanged -= Current_VisibilityChanged; Window.Current.VisibilityChanged += Current_VisibilityChanged; } ApplicationView.GetForCurrentView().Title = (e.Parameter as ExamplePlugin).Name; string jsonConfig = (e.Parameter as ExamplePlugin).JSONConfigFile; _anylineScanView?.Init("Assets/jsonConfigs/" + jsonConfig.Replace(".json", "") + ".json", MainPage.LicenseKey); // the correct plugin is loaded according to the .json config file informed _scanViewPlugin = _anylineScanView?.ScanViewPlugin; /// here you need to add this class as a Result Listener for the plugin that you will use (_scanViewPlugin as BarcodeScanViewPlugin)?.AddScanResultListener(this); (_scanViewPlugin as IDScanViewPlugin)?.AddScanResultListener(this); (_scanViewPlugin as LicensePlateScanViewPlugin)?.AddScanResultListener(this); (_scanViewPlugin as MeterScanViewPlugin)?.AddScanResultListener(this); (_scanViewPlugin as OcrScanViewPlugin)?.AddScanResultListener(this); if (_scanViewPlugin is MeterScanViewPlugin) { (_scanViewPlugin as MeterScanViewPlugin).PhotoCaptureListener = this; (_scanViewPlugin as MeterScanViewPlugin).PhotoCaptureTarget = PhotoCaptureTarget.File; } _anylineScanView?.StartCamera(); }