protected async override void OnElementChanged(VisualElementChangedEventArgs e) { base.OnElementChanged(e); var view = NativeView; var viewController = ViewController; // Get the device's display for width and height. RectangleF screen = UIScreen.MainScreen.Bounds; // create top label - "Scan QR code to swap contact info" var topLabel = new UILabel(new RectangleF( 0, 0, screen.Width, 30) ); topLabel.Text = "Scan QR code to swap contact info"; topLabel.TextAlignment = UITextAlignment.Center; topLabel.TextColor = UIColor.FromRGB(38, 173, 230); topLabel.Font = UIFont.FromName(Fonts.OpenSansBold, 12); view.Add(topLabel); // create the QR code scanner & add to view SIBarcodePicker scanner = new SIBarcodePicker("EeQ6GjLtEeSWsF/zcFfsWC8RqIt/+skbdZJ/MWpLIR8"); var scannerDelegate = new QrCodeScannerDelegate() { qrScanner = scanner }; scanner.OverlayController.Delegate = scannerDelegate; // disable all codes except QR for scanning scanner.Set1DScanningEnabled(false); scanner.Set2DScanningEnabled(false); scanner.SetCode128Enabled(false); scanner.SetCode39Enabled(false); scanner.SetCode93Enabled(false); scanner.SetDataMatrixEnabled(false); scanner.SetEan13AndUpc12Enabled(false); scanner.SetEan8Enabled(false); scanner.SetItfEnabled(false); scanner.SetMicroDataMatrixEnabled(false); scanner.SetUpceEnabled(false); /* - * - * - * - * - * - * - */ scanner.SetQrEnabled(true); /* - * - * - * - * - * - * - */ // Set the scanner size scanner.Size = new SizeF( screen.Size.Width, screen.Size.Height * 0.45f ); scanner.View.Bounds = new RectangleF( 0, topLabel.Frame.Height, screen.Size.Width, screen.Size.Height * 0.45f ); scanner.View.Frame = new RectangleF( 0, topLabel.Frame.Height, screen.Size.Width, screen.Size.Height * 0.45f ); scanner.OverlayController.SetViewfinderSize(0.5f, 0.5f, 0.5f, 0.5f); scanner.OverlayController.SetTorchEnabled(false); view.Add(scanner.View); scanner.StartScanning(); /* Creating the lower label - "Share your contact info" */ var lowerLabel = new UILabel(new RectangleF( 0, (scanner.View.Frame.Location.Y + scanner.View.Frame.Height), screen.Width, 20) ); lowerLabel.Text = "Share your contact info"; lowerLabel.TextAlignment = UITextAlignment.Center; lowerLabel.TextColor = UIColor.FromRGB(38, 173, 230); lowerLabel.Font = UIFont.FromName(Fonts.OpenSansBold, 12); view.Add(lowerLabel); /* * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* Generating QR code */ var qrWidthHeight = 0; if (screen.Height == 480) // iPhone 4 & 4S -- shorter screens { qrWidthHeight = 150; } else // iPhone 5, 5C, & 5S -- longer screens { qrWidthHeight = 175; } IBarcodeWriter barcodeWriter = new BarcodeWriter { Format = BarcodeFormat.QR_CODE, Options = new ZXing.Common.EncodingOptions { Width = qrWidthHeight, Height = qrWidthHeight } }; // TODO: temp code - move to view model var service = TinyIoC.TinyIoCContainer.Current.Resolve <CouchbaseConnect2014.Services.ICouchbaseService> (); var contactId = service.GetUserId(); var repo = TinyIoC.TinyIoCContainer.Current.Resolve <CouchbaseConnect2014.Services.IRepository> (); var localUser = await repo.GetProfile(); // end of temp code var qrContent = string.Format("{0},{1},{2}", contactId, localUser.First, localUser.Last); var result = barcodeWriter.Write(qrContent); var qrImageView = new UIImageView(new RectangleF( 0, (lowerLabel.Frame.Location.Y + lowerLabel.Frame.Height), result.Size.Width, result.Size.Height )); qrImageView.Image = result; qrImageView.Center = new PointF( view.Center.X, qrImageView.Center.Y ); /* - * - * - * - * - * - * - */ view.Add(qrImageView); }
protected async override void OnElementChanged (VisualElementChangedEventArgs e) { base.OnElementChanged (e); var view = NativeView; var viewController = ViewController; // Get the device's display for width and height. RectangleF screen = UIScreen.MainScreen.Bounds; // create top label - "Scan QR code to swap contact info" var topLabel = new UILabel (new RectangleF ( 0, 0, screen.Width, 30) ); topLabel.Text = "Scan QR code to swap contact info"; topLabel.TextAlignment = UITextAlignment.Center; topLabel.TextColor = UIColor.FromRGB (38, 173, 230); topLabel.Font = UIFont.FromName (Fonts.OpenSansBold, 12); view.Add (topLabel); // create the QR code scanner & add to view SIBarcodePicker scanner = new SIBarcodePicker ("EeQ6GjLtEeSWsF/zcFfsWC8RqIt/+skbdZJ/MWpLIR8"); var scannerDelegate = new QrCodeScannerDelegate () { qrScanner = scanner }; scanner.OverlayController.Delegate = scannerDelegate; // disable all codes except QR for scanning scanner.Set1DScanningEnabled (false); scanner.Set2DScanningEnabled (false); scanner.SetCode128Enabled (false); scanner.SetCode39Enabled (false); scanner.SetCode93Enabled (false); scanner.SetDataMatrixEnabled (false); scanner.SetEan13AndUpc12Enabled (false); scanner.SetEan8Enabled (false); scanner.SetItfEnabled (false); scanner.SetMicroDataMatrixEnabled (false); scanner.SetUpceEnabled (false); /* - * - * - * - * - * - * - */ scanner.SetQrEnabled (true); /* - * - * - * - * - * - * - */ // Set the scanner size scanner.Size = new SizeF( screen.Size.Width, screen.Size.Height * 0.45f ); scanner.View.Bounds = new RectangleF( 0, topLabel.Frame.Height, screen.Size.Width, screen.Size.Height * 0.45f ); scanner.View.Frame = new RectangleF( 0, topLabel.Frame.Height, screen.Size.Width, screen.Size.Height * 0.45f ); scanner.OverlayController.SetViewfinderSize (0.5f, 0.5f, 0.5f, 0.5f); scanner.OverlayController.SetTorchEnabled (false); view.Add (scanner.View); scanner.StartScanning (); /* Creating the lower label - "Share your contact info" */ var lowerLabel = new UILabel (new RectangleF ( 0, (scanner.View.Frame.Location.Y + scanner.View.Frame.Height), screen.Width, 20) ); lowerLabel.Text = "Share your contact info"; lowerLabel.TextAlignment = UITextAlignment.Center; lowerLabel.TextColor = UIColor.FromRGB (38, 173, 230); lowerLabel.Font = UIFont.FromName (Fonts.OpenSansBold, 12); view.Add (lowerLabel); /* * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* Generating QR code */ var qrWidthHeight = 0; if (screen.Height == 480) // iPhone 4 & 4S -- shorter screens qrWidthHeight = 150; else // iPhone 5, 5C, & 5S -- longer screens qrWidthHeight = 175; IBarcodeWriter barcodeWriter = new BarcodeWriter { Format = BarcodeFormat.QR_CODE, Options = new ZXing.Common.EncodingOptions { Width = qrWidthHeight, Height = qrWidthHeight } }; // TODO: temp code - move to view model var service = TinyIoC.TinyIoCContainer.Current.Resolve<CouchbaseConnect2014.Services.ICouchbaseService> (); var contactId = service.GetUserId (); var repo = TinyIoC.TinyIoCContainer.Current.Resolve<CouchbaseConnect2014.Services.IRepository> (); var localUser = await repo.GetProfile (); // end of temp code var qrContent = string.Format ("{0},{1},{2}", contactId, localUser.First, localUser.Last); var result = barcodeWriter.Write (qrContent); var qrImageView = new UIImageView (new RectangleF ( 0, (lowerLabel.Frame.Location.Y + lowerLabel.Frame.Height), result.Size.Width, result.Size.Height )); qrImageView.Image = result; qrImageView.Center = new PointF ( view.Center.X, qrImageView.Center.Y ); /* - * - * - * - * - * - * - */ view.Add (qrImageView); }