コード例 #1
0
ファイル: ScanLayerView.cs プロジェクト: Zebra/iFactr-iOS
            public ScanController(ScanLayer scanLayer)
            {
                _layer = scanLayer;
                string fontName = null;
                double fontSize = 12;

                if (_layer.LayerStyle != null && _layer.LayerStyle.DefaultLabelStyle != null)
                {
                    fontName = _layer.LayerStyle.DefaultLabelStyle.FontFamily;
                    fontSize = _layer.LayerStyle.DefaultLabelStyle.FontSize;
                }
                if (!string.IsNullOrEmpty(fontName))
                {
                    float size;
                    if (!float.TryParse(fontSize.ToString(), out size))
                    {
                        TouchFactory.Instance.Logger.Warn("Could not parse " + fontSize + "(double) to a float value");
                        size = 12;
                    }
                    _layerFont = TouchStyle.ToFont(UIFont.FromName(fontName, size));
                }

                callback               = scanLayer.Callback;
                barcodeKey             = ScanLayer.BarcodeKey;
                completeButtonText     = scanLayer.Callback.Text ?? iApp.Factory.GetResourceString("Done");
                backgroundColor        = _layer.LayerStyle.LayerBackgroundColor;
                barcodeSeparatorChar   = ScanLayer.BarcodeSeparatorChar;
                ModalPresentationStyle = UIModalPresentationStyle.FormSheet;
            }
コード例 #2
0
ファイル: ScanLayerView.cs プロジェクト: Zebra/iFactr-iOS
            public LastValueScanOverlay(nfloat yLoc, Font font)
            {
                BackgroundColor = UIColor.FromRGBA(0xFF, 0xFF, 0xFF, 0xF0);
                Frame           = new CGRect(0, yLoc, UIScreen.MainScreen.Bounds.Width, ViewHeight);

                _imageMaxCount = TouchStyle.ImageFromResource("barcode-icon-max-count.png");
                _image         = TouchStyle.ImageFromResource("barcode-icon.png");
                _imageView     = new UIImageView(new CGRect(0, 0, 80, 64)) // frame matches icon size
                {
                    Image = _image,
                };
                this.Add(_imageView);

                const float padding     = 4;
                var         label_xLoc  = _imageView.Frame.Right;
                var         label_yLoc  = (Frame.Height - LabelFontSize) / 2;
                var         labelWidth  = Frame.Width - label_xLoc - padding;
                var         labelHeight = LabelFontSize;

                _barcodeLabel = new UILabel()
                {
                    Font = TouchStyle.ToUIFont(font),
                    AdjustsFontSizeToFitWidth = true,
                    TextAlignment             = UITextAlignment.Left,
                    Frame = new CGRect(label_xLoc, label_yLoc, labelWidth, labelHeight),
                };
                _barcodeLabel.Text = string.Empty;
                this.Add(_barcodeLabel);
            }
コード例 #3
0
ファイル: ScanLayerView.cs プロジェクト: Zebra/iFactr-iOS
            public void SetBarcodeLabel(string barcode, int occurrences)
            {
                if (occurrences <= 20)
                {
                    UIImage image            = null;
                    string  imageResouceName = string.Concat("barcode-icon", occurrences, ".png");
                    try { image = TouchStyle.ImageFromResource(imageResouceName); }
                    catch (Exception e)
                    {
                        iApp.Log.Debug("Exception loading barcode-icon:\r\n" + e);
                        image = _image;
                    }
                    _imageView.Image = image;
                }
                else
                {
                    _imageView.Image = _imageMaxCount;
                }

                _barcodeLabel.Text = barcode;
            }
コード例 #4
0
ファイル: ScanLayerView.cs プロジェクト: Zebra/iFactr-iOS
            public CameraScanController(CameraScanLayer layer, Link callback, string parametersKey)
            {
                _layer           = layer;
                _callback        = callback;
                _barcodeValueKey = parametersKey;
                DuplicateWait    = layer.DuplicateTimeout;
                //				Autorotate = TouchFactory.Instance.Platform == MobilePlatform.iPad;
                ModalPresentationStyle = UIModalPresentationStyle.FormSheet;

                string fontName = null;
                double fontSize = 12;

                if (_layer.LayerStyle != null && _layer.LayerStyle.DefaultLabelStyle != null)
                {
                    fontName = _layer.LayerStyle.DefaultLabelStyle.FontFamily;
                    fontSize = _layer.LayerStyle.DefaultLabelStyle.FontSize;
                }
                if (!string.IsNullOrEmpty(fontName))
                {
                    _layerFont = TouchStyle.ToFont(UIFont.FromName(fontName, LastValueScanOverlay.LabelFontSize));
                }
            }
コード例 #5
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            this.View.BackgroundColor = UIColor.White;
            int v = 0;

            if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0))
            {
                v = 20;
            }
            nfloat  height = this.View.Frame.Height / 2 - v;
            CGRect  frame  = new CGRect(0, v, this.View.Frame.Width, height);
            UIImage image  = TouchStyle.ImageFromResource("barcode-overlay-sm.png");

            this._imageOverlay = new UIImageView(image)
            {
                Frame            = frame,
                ContentMode      = UIViewContentMode.Center,
                AutoresizingMask = (UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleBottomMargin)
            };
            this.View.Add(this._imageOverlay);
            UIImage image2 = TouchStyle.ImageFromResource("barcode-scanblocked-sm.png");

            this._imageOverlayScanBlocked = new UIImageView(image2)
            {
                Frame            = frame,
                ContentMode      = UIViewContentMode.Center,
                AutoresizingMask = (UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleBottomMargin),
                Hidden           = true
            };
            this.View.Add(this._imageOverlayScanBlocked);
            this._cameraView = new UIView
            {
                AutoresizingMask = (UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleBottomMargin)
            };
            this._cameraView.Frame = frame;

            AVAuthorizationStatus authorizationStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video);

            if (authorizationStatus == AVAuthorizationStatus.Authorized)
            {
                AVCaptureDevice      device = AVCaptureDevice.GetDefaultDevice(AVMediaType.Video); // update for iOS 13
                NSError              nSError;
                AVCaptureDeviceInput aVCaptureDeviceInput = AVCaptureDeviceInput.FromDevice(device, out nSError);
                if (aVCaptureDeviceInput != null)
                {
                    this._captureSession = new AVCaptureSession();
                    this._captureSession.AddInput(aVCaptureDeviceInput);
                    AVCaptureMetadataOutput aVCaptureMetadataOutput = new AVCaptureMetadataOutput();
                    this._captureSession.AddOutput(aVCaptureMetadataOutput);
                    this._cameraMetaDataDelegate = new CameraScannerSplitView.CameraMetaDataDelegate(this);
                    aVCaptureMetadataOutput.SetDelegate(this._cameraMetaDataDelegate, DispatchQueue.MainQueue);
                    //aVCaptureMetadataOutput.MetadataObjectTypes = aVCaptureMetadataOutput.AvailableMetadataObjectTypes;
                    aVCaptureMetadataOutput.MetadataObjectTypes = AVMetadataObjectType.QRCode | AVMetadataObjectType.Code128Code | AVMetadataObjectType.UPCECode | AVMetadataObjectType.EAN13Code;
                }
            }
            else if (authorizationStatus == AVAuthorizationStatus.NotDetermined)
            {
                AVCaptureDevice.RequestAccessForMediaType(AVMediaType.Video, (granted) =>
                {
                    if (!granted)
                    {
                        Device.Log.Error("ViewDidLoadBase ScanLayer RequestAccessForMediaType not granted!");
                    }
                    else
                    {
                        Device.Log.Error("ViewDidLoadBase ScanLayer RequestAccessForMediaType granted!");
                    }
                });
            }
            else
            {
                Device.Log.Error("Not Authorized! Status: " + authorizationStatus.ToString());
            }


            if (authorizationStatus >= AVAuthorizationStatus.NotDetermined && authorizationStatus <= AVAuthorizationStatus.Authorized)
            {
                switch ((int)authorizationStatus)
                {
                case 0:
                    AVCaptureDevice.RequestAccessForMediaType(AVMediaType.Video, delegate(bool result)
                    {
                        Device.Thread.ExecuteOnMainThread(delegate
                        {
                            if (result)
                            {
                                this.SetupVideoPreviewLayer();
                            }
                            else
                            {
                                this.AddNoCameraAccessLabels();
                            }
                        });
                    });
                    break;

                case 1:
                    Device.Log.Warn("Camera Access is restricted", new object[0]);
                    this.AddNoCameraAccessLabels();
                    break;

                case 2:
                    this.AddNoCameraAccessLabels();
                    break;

                case 3:
                    this.SetupVideoPreviewLayer();
                    break;
                }
            }
            this.View.InsertSubviewBelow(this._cameraView, this._imageOverlay);
            CGRect frame2 = new CGRect(0, frame.Bottom, this.View.Frame.Width, this.View.Frame.Height - frame.Height);

            this._resultsView = new UITableView(frame2, UITableViewStyle.Plain)
            {
                AutoresizingMask = (UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleHeight)
            };
            this._resultsView.Source = new CameraScannerSplitView.CameraListSource(this);
            this.View.Add(this._resultsView);
            this.NavigationItem.LeftBarButtonItem = new UIBarButtonItem("Done", UIBarButtonItemStyle.Done, delegate
            {
                string text = string.Empty;
                if (this._resultsView.Source != null)
                {
                    try
                    {
                        string text2       = string.Empty;
                        List <string> list = (this._resultsView.Source as CameraScannerSplitView.CameraListSource).ScannedBarcodes();
                        foreach (string current in list)
                        {
                            if (!string.IsNullOrEmpty(current))
                            {
                                text2 = text2 + current + "\r\n";
                            }
                        }
                        text = text2;
                    }
                    catch (Exception arg)
                    {
                        Device.Log.Error("This error occurred while parsing barcodes scanned: \r\n" + arg, new object[0]);
                    }
                }
                if (this._callback.Parameters == null)
                {
                    this._callback.Parameters = new Dictionary <string, string>();
                }
                this._callback.Parameters[this._barcodeValueKey] = text;
                iApp.Navigate(this._callback);
                ModalManager.EnqueueModalTransition(TouchFactory.Instance.TopViewController, null, true);
            });
        }
コード例 #6
0
        void ReconfigureForMasterInPopover(bool inPopover)
        {
            if (inPopover)
            {
                AdjustingMaster = true;
            }

            UIViewController       masterViewController = viewControllers[0];
            UINavigationController detailViewController = viewControllers[1] as UINavigationController;

            reconfigurePopup = false;

            if ((inPopover && hiddenPopoverController != null) || (!inPopover && hiddenPopoverController == null) ||
                masterViewController == null)
            {
                // Nothing to do.
                return;
            }

            if (inPopover && hiddenPopoverController == null && barButtonItem == null)
            {
                // Create and configure popover for our masterViewController.
                masterViewController.ViewWillDisappear(false);
                hiddenPopoverController             = new UIPopoverController(masterViewController);
                hiddenPopoverController.DidDismiss += delegate
                {
                    var frame = hiddenPopoverController.ContentViewController.View.Frame;
                    frame.Height = hiddenPopoverController.PopoverContentSize.Height;
                    hiddenPopoverController.ContentViewController.View.Frame = frame;
                    AdjustingMaster = true;
                };
                masterViewController.ViewDidDisappear(false);

                barButtonItem = new UIBarButtonItem(TouchStyle.ImageFromResource("menuIcon.png"), UIBarButtonItemStyle.Plain, delegate { ShowMasterPopover(); });
                detailViewController.VisibleViewController.NavigationItem.SetLeftBarButtonItem(barButtonItem, true);
                detailViewController.VisibleViewController.NavigationItem.LeftItemsSupplementBackButton = true;
                // Inform delegate of this state of affairs.
//				if (splitViewDelegate && [splitViewDelegate respondsToSelector:@selector(splitViewController:willHideViewController:withBarButtonItem:forPopoverController:)]) {
//					[(NSObject <MGSplitViewControllerDelegate> *)splitViewDelegate splitViewController:self
//																		willHideViewController:self.masterViewController
//																			 withBarButtonItem:_barButtonItem
//																		  forPopoverController:_hiddenPopoverController];
//				}
//				ShowMasterPopover();
            }
            else if (!inPopover && hiddenPopoverController != null && barButtonItem != null)
            {
                // I know this looks strange, but it fixes a bizarre issue with UIPopoverController leaving masterViewController's views in disarray.
                hiddenPopoverController.PresentFromRect(CGRect.Empty, View, UIPopoverArrowDirection.Any, false);

                // Remove master from popover and destroy popover, if it exists.
                hiddenPopoverController.Dismiss(false);
                hiddenPopoverController = null;

                // Inform delegate that the _barButtonItem will become invalid.
//				if (splitViewDelegate && [splitViewDelegate respondsToSeCGPoint:@selector(splitViewController:willShowViewController:invalidatingBarButtonItem:)]) {
//					[(NSObject <MGSplitViewControllerDelegate> *)splitViewDelegate splitViewController:self
//																		willShowViewController:self.masterViewCCGPointler
//																	 invalidatingBarButtonItem:_barButtonItem];
//				}

                // Destroy _barButtonItem.
                detailViewController.VisibleViewController.NavigationItem.SetLeftBarButtonItem(null, true);
                barButtonItem = null;

                // Move master view.
                UIView masterView = masterViewController.View;
                if (masterView != null && masterView.Superview != View)
                {
                    masterView.RemoveFromSuperview();
                }
            }
        }
コード例 #7
0
        internal static void Display(this LoginLayer layer)
        {
            UIViewController controller = new ViewController()
            {
                View = UIDevice.CurrentDevice.CheckSystemVersion(8, 1) && UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone ?
                       new LoginView(UIScreen.MainScreen.ApplicationFrame) : new UIView(UIScreen.MainScreen.ApplicationFrame),
                ModalPresentationStyle = UIModalPresentationStyle.FullScreen,
                ModalTransitionStyle   = UIModalTransitionStyle.CrossDissolve,
                Autorotate             = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad
            };

            if (!string.IsNullOrEmpty(layer.LayerStyle.LayerBackgroundImage))
            {
                controller.View.InsertSubview(new UIImageView()
                {
                    Image            = UIImage.FromBundle(layer.LayerStyle.LayerBackgroundImage),
                    AutoresizingMask = UIViewAutoresizing.FlexibleMargins,
                    Frame            = controller.View.Frame,
                    ContentMode      = UIViewContentMode.Center
                }, 0);
            }
            else if (!layer.LayerStyle.LayerBackgroundColor.IsDefaultColor)
            {
                controller.View.BackgroundColor = layer.LayerStyle.LayerBackgroundColor.ToUIColor();
            }

            UIView container = new UIView()
            {
                AutoresizingMask = UIViewAutoresizing.FlexibleMargins
            };

            ModalManager.EnqueueModalTransition(TouchFactory.Instance.TopViewController, controller, true);

            List <UITextField> textFields = new List <UITextField>();

            foreach (TextField field in layer.Items.OfType <Fieldset>().SelectMany(i => i).OfType <TextField>())
            {
                UITextField previous = textFields.LastOrDefault();
                if (previous != null)
                {
                    previous.ReturnKeyType = UIReturnKeyType.Next;
                    previous.ShouldReturn += delegate
                    {
                        textFields[textFields.IndexOf(previous) + 1].BecomeFirstResponder();
                        return(false);
                    };
                }

                textFields.Add(CreateTextField(field, (DefaultHeight + 10) * (textFields.Count + 1)));
            }

            UIButton button = new UIButton();

            button.TouchUpInside += (sender, e) => Submit(layer, controller, container, textFields);

            UIImage buttonImage = null;

            if (TouchFactory.Instance.Settings.ContainsKey("LoginButtonImage"))
            {
                buttonImage = UIImage.FromBundle(TouchFactory.Instance.Settings["LoginButtonImage"]);
            }

            if (buttonImage == null)
            {
                buttonImage = TouchStyle.ImageFromResource("loginButton.png");
                button.SetTitle(layer.ActionButtons.FirstOrDefault() == null ?
                                TouchFactory.Instance.GetResourceString("Login") :
                                layer.ActionButtons.First().Text, UIControlState.Normal);

                button.SetTitleColor(UIColor.White, UIControlState.Normal);
            }

            button.SetBackgroundImage(buttonImage, UIControlState.Normal);
            button.Frame = new CGRect(DefaultWidth - buttonImage.Size.Width,
                                      (DefaultHeight + 10) * (textFields.Count + 1), buttonImage.Size.Width, buttonImage.Size.Height);

            container.Frame  = new CGRect(0, 0, DefaultWidth, button.Frame.Bottom);
            container.Center = new CGPoint(controller.View.Center.X, controller.View.Center.Y - (button.Frame.Bottom / 2 + 24));
            container.AddSubviews(textFields.ToArray());
            container.AddSubview(button);

            if (layer.BrandImage != null)
            {
                container.AddSubview(new UIImageView()
                {
                    Image       = UIImage.FromBundle(layer.BrandImage.Location ?? string.Empty),
                    Center      = new CGPoint(container.Frame.Width / 2, DefaultHeight + 10),
                    ContentMode = UIViewContentMode.Bottom
                });
            }

            UITextField last = textFields.LastOrDefault();

            if (last != null)
            {
                last.ReturnKeyType = UIReturnKeyType.Go;
                last.ShouldReturn += delegate
                {
                    Submit(layer, controller, container, textFields);
                    return(false);
                };
            }

            authLabel.RemoveFromSuperview();
            authLabel.SizeToFit();
            authLabel.Center    = new CGPoint((container.Frame.Width / 2) - (21 / 2), button.Center.Y);
            authLabel.Alpha     = 0;
            authLabel.TextColor = layer.LayerStyle.TextColor.IsDefaultColor ? UIColor.Black : layer.LayerStyle.TextColor.ToUIColor();

            authActivity.Frame = new CGRect(authLabel.Frame.Right, authLabel.Frame.Y, 21, 21);
            authActivity.Alpha = 0;
            if (authActivity.RespondsToSelector(new Selector(Selector.GetHandle("color"))))
            {
                authActivity.Color = layer.LayerStyle.TextColor.IsDefaultColor ? UIColor.Black : layer.LayerStyle.TextColor.ToUIColor();
            }

            container.AddSubviews(authLabel, authActivity);
            controller.View.AddSubview(container);
        }
コード例 #8
0
ファイル: ScanLayerView.cs プロジェクト: Zebra/iFactr-iOS
            public override void ViewDidLoad()
            {
                base.ViewDidLoad();
                View.BackgroundColor = UIColor.Black;

                NSError error = null;

                _captureSession = new AVCaptureSession();
                CameraMetaDataDelegate del = null;

                var             authStatus    = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video);
                AVCaptureDevice captureDevice = null;

                // check authorization status
                if (authStatus == AVAuthorizationStatus.Authorized)
                {
                    captureDevice = AVCaptureDevice.GetDefaultDevice(AVMediaType.Video); // update for iOS 13
                }
                else if (authStatus == AVAuthorizationStatus.NotDetermined)
                {
                    AVCaptureDevice.RequestAccessForMediaType(AVMediaType.Video, (granted) =>
                    {
                        if (!granted)
                        {
                            iApp.Log.Error("ViewDidLoadBase ScanLayer RequestAccessForMediaType not granted!");
                        }
                        else
                        {
                            iApp.Log.Error("ViewDidLoadBase ScanLayer RequestAccessForMediaType granted!");
                        }
                    });
                }
                else
                {
                    iApp.Log.Error("Not Authorized! Status: " + authStatus.ToString());
                }
                if (captureDevice != null)
                {
                    var videoInput = AVCaptureDeviceInput.FromDevice(captureDevice, out error);
                    if (videoInput != null)
                    {
                        _captureSession.AddInput(videoInput);
                    }
                    else
                    {
                        iApp.Log.Error("Video capture error: " + error.LocalizedDescription);
                    }

                    var metaDataOutput = new AVCaptureMetadataOutput();
                    _captureSession.AddOutput(metaDataOutput);

                    del = new CameraMetaDataDelegate(this, _layer);
                    metaDataOutput.SetDelegate(del, CoreFoundation.DispatchQueue.MainQueue);

                    //metaDataOutput.MetadataObjectTypes = metaDataOutput.AvailableMetadataObjectTypes;

                    metaDataOutput.MetadataObjectTypes = AVMetadataObjectType.QRCode | AVMetadataObjectType.Code128Code | AVMetadataObjectType.UPCECode | AVMetadataObjectType.EAN13Code;


                    _videoPreviewLayer = new AVCaptureVideoPreviewLayer(_captureSession)
                    {
                        Frame       = View.Bounds,
                        Orientation = (AVCaptureVideoOrientation)InterfaceOrientation,
                    };
                    View.Layer.AddSublayer(_videoPreviewLayer);
                    var image = TouchStyle.ImageFromResource("barcode-overlay-sm.png");
                    _imageOverlay = new UIImageView(image)
                    {
                        Frame            = View.Frame,
                        ContentMode      = UIViewContentMode.Center,
                        AutoresizingMask = UIViewAutoresizing.FlexibleMargins,
                    };
                    View.Add(_imageOverlay);

                    // preload this, and display when scan event occurs
                    var imageScanBlocked = TouchStyle.ImageFromResource("barcode-scanblocked-sm.png");
                    _imageOverlayScanBlocked = new UIImageView(imageScanBlocked)
                    {
                        Frame            = View.Frame,
                        ContentMode      = UIViewContentMode.Center,
                        AutoresizingMask = UIViewAutoresizing.FlexibleMargins,
                        Hidden           = true,
                    };
                    View.Add(_imageOverlayScanBlocked);
                }
                else
                {
                    //TODO: Add "Scanner currently not active overlay Image"
                    iApp.Log.Error("null capture device!");
                }

                nfloat startVerticalLoc = UIScreen.MainScreen.Bounds.Height - LastValueScanOverlay.ViewHeight;

                _lastScanOverlay = new LastValueScanOverlay(startVerticalLoc, _layerFont);
                View.Add(_lastScanOverlay);

                NavigationItem.LeftBarButtonItem = new UIBarButtonItem("Done", UIBarButtonItemStyle.Done, delegate {
                    string scannedBarcodes = string.Empty;
                    if (del != null && del.Buffer != null && del.Buffer.CurrentBuffer != null)
                    {
                        foreach (var s in del.Buffer.CurrentBuffer)
                        {
                            scannedBarcodes += s + "\r\n";
                        }
                    }
                    if (_callback.Parameters == null)
                    {
                        _callback.Parameters = new Dictionary <string, string>();
                    }
                    _callback.Parameters[_barcodeValueKey] = scannedBarcodes;
                    iApp.Navigate(_callback);
                    ModalManager.EnqueueModalTransition(TouchFactory.Instance.TopViewController, null, true);
                });
            }