protected override void OnElementChanged(VisualElementChangedEventArgs e) { base.OnElementChanged(e); if (e.OldElement != null || Element == null) { return; } try { // Initializing the energy module. _frame = UIScreen.MainScreen.ApplicationFrame; // Search for the navigation controller UINavigationController nav = null; foreach (var vc in UIApplication.SharedApplication.Windows[0].RootViewController.ChildViewControllers) { if (vc is UINavigationController) { nav = (UINavigationController)vc; } } _frame = new CGRect(_frame.X, _frame.Y + nav.NavigationBar.Frame.Size.Height, _frame.Width, _frame.Height - nav.NavigationBar.Frame.Size.Height); _scanView = new AnylineEnergyModuleView(_frame); _error = null; var success = _scanView.SetupWithLicenseKey(LicenseKey, Self, out _error); if (!success) { (_alert = new UIAlertView("Error", _error.DebugDescription, (IUIAlertViewDelegate)null, "OK", null)).Show(); } _scanView.CancelOnResult = true; // After setup, add the scanView to the view View.AddSubview(_scanView); _error = null; _scanView.SetScanMode(ALScanMode.AnalogMeter, out _error); if (_error != null) { (_alert = new UIAlertView("Error", _error.DebugDescription, (IUIAlertViewDelegate)null, "OK", null)).Show(); } // Start scanning StartScanning(); } catch (Exception ex) { Debug.WriteLine(@"ERROR: ", ex.Message); } }
public override void ViewDidDisappear(bool animated) { base.ViewDidDisappear(animated); //don't clean up objects, if we want the controller to be kept alive if (keepScanViewControllerAlive) { return; } //we have to un-register the event handlers because else the whole viewcontroller will be kept in the garbage collector. if (meterTypeSegment != null) { meterTypeSegment.ValueChanged -= HandleSegmentChange; } if (meterTypeSegment != null) { meterTypeSegment.Dispose(); } meterTypeSegment = null; if (selectionLabel != null) { selectionLabel.Dispose(); } selectionLabel = null; if (infoLabel != null) { infoLabel.Dispose(); } infoLabel = null; segmentItems = null; if (alert != null) { alert.Dispose(); } alert = null; if (error != null) { error.Dispose(); } error = null; //we have to erase the scan view so that there are no dependencies for the viewcontroller left. anylineEnergyView.RemoveFromSuperview(); anylineEnergyView.Dispose(); anylineEnergyView = null; base.Dispose(); }
void IAnylineEnergyModuleDelegate.DidFindResult(AnylineEnergyModuleView anylineEnergyModuleView, ALEnergyResult scanResult) { Debug.WriteLine(scanResult.Result.ToString(), @"Result: "); _alert = new UIAlertView("Result", scanResult.Result.ToString(), (IUIAlertViewDelegate)null, "OK", null); _alert.Clicked += (e, a) => { StartScanning(); }; _alert.Show(); }
/* * This is the main delegate method Anyline uses to report its scanned codes */ void IAnylineEnergyModuleDelegate.DidFindScanResult(AnylineEnergyModuleView anylineEnergyModuleView, string scanResult, UIImage image, UIImage fullImage, ALScanMode scanMode) { StopAnyline(); //we'll go to a temporary new view controller, so we keep this one alive keepScanViewControllerAlive = true; try { AnylineEnergyScanViewResultController vc = new AnylineEnergyScanViewResultController(scanResult, scanMode); vc.MeterImage = image; NavigationController.PushViewController(vc, true); } catch (Exception) { } }
/* * This is the main delegate method Anyline uses to report its scanned codes */ void IAnylineEnergyModuleDelegate.DidFindResult(AnylineEnergyModuleView anylineEnergyModuleView, ALEnergyResult scanResult) { StopAnyline(); //we'll go to a temporary new view controller, so we keep this one alive _keepScanViewControllerAlive = true; try { AnylineEnergyScanViewResultController vc = new AnylineEnergyScanViewResultController(scanResult.Result.ToString(), scanResult.ScanMode, _barcodeResult); vc.MeterImage = scanResult.Image; NavigationController.PushViewController(vc, true); } catch (Exception) { // ignored } }
new void Dispose() { //we have to un-register the event handlers because else the whole viewcontroller will be kept in the garbage collector. if (_meterTypeSegment != null) { _meterTypeSegment.ValueChanged -= HandleSegmentChange; } _meterTypeSegment?.Dispose(); _selectionLabel?.Dispose(); _toggleBarcodeLabel.RemoveFromSuperview(); _toggleBarcodeLabel?.Dispose(); _toggleBarcodeSwitch.ValueChanged -= OnValueChanged; _toggleBarcodeSwitch.RemoveFromSuperview(); _toggleBarcodeSwitch?.Dispose(); _toggleBarcodeView.RemoveFromSuperview(); _toggleBarcodeView?.Dispose(); _segmentItems = null; _alert?.Dispose(); _error?.Dispose(); //we have to erase the scan view so that there are no dependencies for the viewcontroller left. _anylineEnergyView?.RemoveFromSuperview(); _anylineEnergyView?.Dispose(); _anylineEnergyView = null; GC.Collect(GC.MaxGeneration); base.Dispose(); }
public override void ViewDidLoad() { base.ViewDidLoad(); // Initializing the energy module. _frame = UIScreen.MainScreen.ApplicationFrame; _frame = new CGRect(_frame.X, _frame.Y + NavigationController.NavigationBar.Frame.Size.Height, _frame.Width, _frame.Height - NavigationController.NavigationBar.Frame.Size.Height); _anylineEnergyView = new AnylineEnergyModuleView(_frame); _error = null; _success = _anylineEnergyView.SetupWithLicenseKey(_licenseKey, Self, out _error); if (!_success) { (_alert = new UIAlertView("Error", _error.DebugDescription, (IUIAlertViewDelegate)null, "OK", null)).Show(); } // We'll stop scanning manually _anylineEnergyView.CancelOnResult = false; // After setup is complete we add the module to the view of this view controller View.AddSubview(_anylineEnergyView); _error = null; _anylineEnergyView.SetScanMode(_segmentItems.ElementAt(_defaultIndex).Value, out _error); if (_error != null) { (_alert = new UIAlertView("Error", _error.DebugDescription, (IUIAlertViewDelegate)null, "OK", null)).Show(); } // Create a subview for toggling native barcode scanning: _toggleBarcodeView = new UIView(new CGRect(0, 0, 150, 50)); _toggleBarcodeLabel = new UILabel(new CGRect(0, 0, 100, 30)); _toggleBarcodeLabel.Text = "Detect Barcodes"; _toggleBarcodeLabel.TextColor = UIColor.White; _toggleBarcodeLabel.SizeToFit(); _toggleBarcodeSwitch = new UISwitch(); _toggleBarcodeSwitch.On = false; _toggleBarcodeSwitch.TintColor = UIColor.White; _toggleBarcodeSwitch.OnTintColor = new UIColor(0, 153 / 255, 1, 1); _toggleBarcodeSwitch.ValueChanged += OnValueChanged; _toggleBarcodeView.AddSubview(_toggleBarcodeLabel); _toggleBarcodeView.AddSubview(_toggleBarcodeSwitch); if (Title != "Heat Meter Scan") { View.AddSubview(_toggleBarcodeView); } // We don't need a segment control for only one option: if (_segmentItems.Count > 1) { List <string> list = new List <string>(); foreach (var key in _segmentItems.Keys) { list.Add(key); } var obj = list.ToArray <object>(); _meterTypeSegment = new UISegmentedControl(obj); //adjust the segmentcontrol size so all elements fit to the view if (_meterTypeSegment.NumberOfSegments > 3) { for (int i = 0; i < _meterTypeSegment.NumberOfSegments; i++) { _meterTypeSegment.SetWidth(View.Frame.Width / (_meterTypeSegment.NumberOfSegments + 1), i); } _meterTypeSegment.ApportionsSegmentWidthsByContent = true; } _meterTypeSegment.Center = new CGPoint(View.Center.X, View.Frame.Size.Height - 40); _meterTypeSegment.SelectedSegment = _defaultIndex; _meterTypeSegment.ValueChanged += HandleSegmentChange; View.AddSubview(_meterTypeSegment); _selectionLabel = new UILabel(new CGRect(_meterTypeSegment.Frame.X, _meterTypeSegment.Frame.Y - 35, _meterTypeSegment.Frame.Width, 35)); _selectionLabel.TextColor = UIColor.White; _selectionLabel.Text = _labelText; View.AddSubview(_selectionLabel); } }
public override void ViewDidLoad() { base.ViewDidLoad(); // Initializing the energy module. frame = UIScreen.MainScreen.ApplicationFrame; frame = new CGRect(frame.X, frame.Y + NavigationController.NavigationBar.Frame.Size.Height, frame.Width, frame.Height - NavigationController.NavigationBar.Frame.Size.Height); anylineEnergyView = new AnylineEnergyModuleView(frame); error = null; success = anylineEnergyView.SetupWithLicenseKey(licenseKey, this.Self, out error); if (!success) { (alert = new UIAlertView("Error", error.DebugDescription, null, "OK", null)).Show(); } //we'll stop scanning manually anylineEnergyView.CancelOnResult = false; // After setup is complete we add the module to the view of this view controller View.AddSubview(anylineEnergyView); anylineEnergyView.ScanMode = segmentItems.ElementAt(defaultIndex).Value; //we don't need a segment control for only one option: if (segmentItems.Count > 1) { meterTypeSegment = new UISegmentedControl(segmentItems.Keys.ToArray()); //adjust the segmentcontrol size so all elements fit to the view if (meterTypeSegment.NumberOfSegments > 3) { for (int i = 0; i < meterTypeSegment.NumberOfSegments; i++) { meterTypeSegment.SetWidth(View.Frame.Width / (meterTypeSegment.NumberOfSegments + 1), i); } meterTypeSegment.ApportionsSegmentWidthsByContent = true; } meterTypeSegment.Center = new CGPoint(View.Center.X, View.Frame.Size.Height - 40); meterTypeSegment.SelectedSegment = this.defaultIndex; meterTypeSegment.ValueChanged += HandleSegmentChange; View.AddSubview(meterTypeSegment); selectionLabel = new UILabel(new CGRect(meterTypeSegment.Frame.X, meterTypeSegment.Frame.Y - 35, meterTypeSegment.Frame.Width, 35)); selectionLabel.TextColor = UIColor.White; selectionLabel.Text = labelText; View.AddSubview(selectionLabel); infoLabel = new UILabel(new CGRect(0, View.Frame.Y + NavigationController.NavigationBar.Frame.Size.Height + 13, View.Frame.Width, 35)); infoLabel.TextColor = UIColor.White; infoLabel.Text = ""; infoLabel.TextAlignment = UITextAlignment.Center; View.AddSubview(infoLabel); UpdateInfoLabel(anylineEnergyView.ScanMode); } }