示例#1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            RequestWindowFeature(WindowFeatures.NoTitle);
            Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen);

            string licenseKey = Intent.GetStringExtra("licenseKey");

            picker = new ScanditSDKBarcodePicker(this, licenseKey, ScanditSDK.CameraFacingBack);

            picker.OverlayView.AddListener(this);

            picker.StartScanning();

            SetContentView(picker);
        }
		protected override async void OnElementChanged (ElementChangedEventArgs<Page> e)
		{
			base.OnElementChanged (e);

			var metrics = Resources.DisplayMetrics;
			var activity = this.Context as Activity;

			relativeLayout = new RelLayout (activity);
			var relativeLayoutParams = new RelLayout.LayoutParams (
				RelLayout.LayoutParams.MatchParent, 
				RelLayout.LayoutParams.MatchParent
			);

			// Create topTextView - "Scan QR code to swap contact info"
			topTextView = new TextView (activity);
			topTextView.Text = "Scan QR code to swap contact info";
			topTextView.Gravity = GravityFlags.Center;
			topTextView.SetTextColor (AColor.Rgb (38, 173, 230));
			topTextView.TextSize = 14f;
			topTextView.Typeface = Typeface.CreateFromAsset (Forms.Context.Assets, "OpenSans-Bold.ttf");

			RelLayout.LayoutParams topTVLayoutParams = new RelLayout.LayoutParams(
				RelLayout.LayoutParams.MatchParent, 
				RelLayout.LayoutParams.MatchParent
			);

			relativeLayout.AddView (topTextView, topTVLayoutParams);
			/* * * * * * * * * * * * * * * * * * * * * * * * * * * */

			/* Create the Barcode Picker View */
			barcodePicker = new ScanditSDKBarcodePicker (activity, "EeQ6GjLtEeSWsF/zcFfsWC8RqIt/+skbdZJ/MWpLIR8");
			barcodePicker.OverlayView.AddListener (this);

			// disable all codes except QR for scanning
			barcodePicker.Set1DScanningEnabled (false);
			barcodePicker.Set2DScanningEnabled (false);
			barcodePicker.SetCode128Enabled (false);
			barcodePicker.SetCode39Enabled (false);
			barcodePicker.SetCode93Enabled (false);
			barcodePicker.SetDataMatrixEnabled (false);
			barcodePicker.SetEan13AndUpc12Enabled (false);
			barcodePicker.SetEan8Enabled (false);
			barcodePicker.SetItfEnabled (false);
			barcodePicker.SetMicroDataMatrixEnabled (false);
			barcodePicker.SetUpceEnabled (false);
			/* - * - * - * - * - * - * - */
			barcodePicker.SetQrEnabled (true);
			/* - * - * - * - * - * - * - */

			RelLayout.LayoutParams bpLayoutParams = new RelLayout.LayoutParams(
				RelLayout.LayoutParams.MatchParent, 
				RelLayout.LayoutParams.MatchParent
			);
			bpLayoutParams.AddRule(LayoutRules.CenterHorizontal);

			relativeLayout.AddView (barcodePicker, bpLayoutParams);
			/* * * * * * * * * * * * * * * * * * * * * * * * * * * */

			/* Create the overlay view -- this is to cover the bottom part of the barcode scanner view */
			overlay = new AView(activity);
			overlay.SetBackgroundColor (AColor.White);

			RelLayout.LayoutParams oLayoutParams = new RelLayout.LayoutParams(
				RelLayout.LayoutParams.MatchParent, 
				RelLayout.LayoutParams.MatchParent
			);
			oLayoutParams.AddRule(LayoutRules.AlignParentBottom);

			relativeLayout.AddView (overlay, oLayoutParams);
			/* * * * * * * * * * * * * * * * * * * * * * * * * * * */

			// Create bottomTextView - "Share your contact info"
			bottomTextView = new TextView (activity);
			bottomTextView.Text = "Share your contact info";
			bottomTextView.Gravity = GravityFlags.Center;
			bottomTextView.SetTextColor (AColor.Rgb (38, 173, 230));
			bottomTextView.TextSize = 14f;
			bottomTextView.Typeface = Typeface.CreateFromAsset (Forms.Context.Assets, "OpenSans-Bold.ttf");

			RelLayout.LayoutParams bottomTVLayoutParams = new RelLayout.LayoutParams(
				RelLayout.LayoutParams.MatchParent, 
				RelLayout.LayoutParams.MatchParent
			);

			relativeLayout.AddView (bottomTextView, bottomTVLayoutParams);
			/* * * * * * * * * * * * * * * * * * * * * * * * * * * */

			/* * * Generating QR code * * */
			IBarcodeWriter barcodeWriter = new BarcodeWriter 
			{ 
				Format = BarcodeFormat.QR_CODE,
				Options = new ZXing.Common.EncodingOptions
				{
					Width = 175,
					Height = 175
				}
			};

			// 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);
			qrImageView = new ImageView (activity);
			qrImageView.SetImageBitmap (result);

			RelLayout.LayoutParams qrLayoutParams = new RelLayout.LayoutParams (
				RelLayout.LayoutParams.MatchParent, 
				RelLayout.LayoutParams.MatchParent
			);
			qrLayoutParams.AddRule (LayoutRules.CenterHorizontal);

			relativeLayout.AddView (qrImageView, qrLayoutParams);
			/* * * * * * * * * * * * * * * * * * * * * * * * * * * */

			AddView (relativeLayout, relativeLayoutParams);

			barcodePicker.SetScanningHotSpot (0.5f, 0.2f);
			barcodePicker.OverlayView.SetViewfinderDimension (0.4f, 0.28f);
			barcodePicker.OverlayView.SetTorchEnabled (false);

			barcodePicker.StartScanning();
		}
示例#3
0
        protected override async void OnElementChanged(ElementChangedEventArgs <Page> e)
        {
            base.OnElementChanged(e);

            var metrics  = Resources.DisplayMetrics;
            var activity = this.Context as Activity;

            relativeLayout = new RelLayout(activity);
            var relativeLayoutParams = new RelLayout.LayoutParams(
                RelLayout.LayoutParams.MatchParent,
                RelLayout.LayoutParams.MatchParent
                );

            // Create topTextView - "Scan QR code to swap contact info"
            topTextView         = new TextView(activity);
            topTextView.Text    = "Scan QR code to swap contact info";
            topTextView.Gravity = GravityFlags.Center;
            topTextView.SetTextColor(AColor.Rgb(38, 173, 230));
            topTextView.TextSize = 14f;
            topTextView.Typeface = Typeface.CreateFromAsset(Forms.Context.Assets, "OpenSans-Bold.ttf");

            RelLayout.LayoutParams topTVLayoutParams = new RelLayout.LayoutParams(
                RelLayout.LayoutParams.MatchParent,
                RelLayout.LayoutParams.MatchParent
                );

            relativeLayout.AddView(topTextView, topTVLayoutParams);
            /* * * * * * * * * * * * * * * * * * * * * * * * * * * */

            /* Create the Barcode Picker View */
            barcodePicker = new ScanditSDKBarcodePicker(activity, "EeQ6GjLtEeSWsF/zcFfsWC8RqIt/+skbdZJ/MWpLIR8");
            barcodePicker.OverlayView.AddListener(this);

            // disable all codes except QR for scanning
            barcodePicker.Set1DScanningEnabled(false);
            barcodePicker.Set2DScanningEnabled(false);
            barcodePicker.SetCode128Enabled(false);
            barcodePicker.SetCode39Enabled(false);
            barcodePicker.SetCode93Enabled(false);
            barcodePicker.SetDataMatrixEnabled(false);
            barcodePicker.SetEan13AndUpc12Enabled(false);
            barcodePicker.SetEan8Enabled(false);
            barcodePicker.SetItfEnabled(false);
            barcodePicker.SetMicroDataMatrixEnabled(false);
            barcodePicker.SetUpceEnabled(false);
            /* - * - * - * - * - * - * - */
            barcodePicker.SetQrEnabled(true);
            /* - * - * - * - * - * - * - */

            RelLayout.LayoutParams bpLayoutParams = new RelLayout.LayoutParams(
                RelLayout.LayoutParams.MatchParent,
                RelLayout.LayoutParams.MatchParent
                );
            bpLayoutParams.AddRule(LayoutRules.CenterHorizontal);

            relativeLayout.AddView(barcodePicker, bpLayoutParams);
            /* * * * * * * * * * * * * * * * * * * * * * * * * * * */

            /* Create the overlay view -- this is to cover the bottom part of the barcode scanner view */
            overlay = new AView(activity);
            overlay.SetBackgroundColor(AColor.White);

            RelLayout.LayoutParams oLayoutParams = new RelLayout.LayoutParams(
                RelLayout.LayoutParams.MatchParent,
                RelLayout.LayoutParams.MatchParent
                );
            oLayoutParams.AddRule(LayoutRules.AlignParentBottom);

            relativeLayout.AddView(overlay, oLayoutParams);
            /* * * * * * * * * * * * * * * * * * * * * * * * * * * */

            // Create bottomTextView - "Share your contact info"
            bottomTextView         = new TextView(activity);
            bottomTextView.Text    = "Share your contact info";
            bottomTextView.Gravity = GravityFlags.Center;
            bottomTextView.SetTextColor(AColor.Rgb(38, 173, 230));
            bottomTextView.TextSize = 14f;
            bottomTextView.Typeface = Typeface.CreateFromAsset(Forms.Context.Assets, "OpenSans-Bold.ttf");

            RelLayout.LayoutParams bottomTVLayoutParams = new RelLayout.LayoutParams(
                RelLayout.LayoutParams.MatchParent,
                RelLayout.LayoutParams.MatchParent
                );

            relativeLayout.AddView(bottomTextView, bottomTVLayoutParams);
            /* * * * * * * * * * * * * * * * * * * * * * * * * * * */

            /* * * Generating QR code * * */
            IBarcodeWriter barcodeWriter = new BarcodeWriter
            {
                Format  = BarcodeFormat.QR_CODE,
                Options = new ZXing.Common.EncodingOptions
                {
                    Width  = 175,
                    Height = 175
                }
            };

            // 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);

            qrImageView = new ImageView(activity);
            qrImageView.SetImageBitmap(result);

            RelLayout.LayoutParams qrLayoutParams = new RelLayout.LayoutParams(
                RelLayout.LayoutParams.MatchParent,
                RelLayout.LayoutParams.MatchParent
                );
            qrLayoutParams.AddRule(LayoutRules.CenterHorizontal);

            relativeLayout.AddView(qrImageView, qrLayoutParams);
            /* * * * * * * * * * * * * * * * * * * * * * * * * * * */

            AddView(relativeLayout, relativeLayoutParams);

            barcodePicker.SetScanningHotSpot(0.5f, 0.2f);
            barcodePicker.OverlayView.SetViewfinderDimension(0.4f, 0.28f);
            barcodePicker.OverlayView.SetTorchEnabled(false);

            barcodePicker.StartScanning();
        }