protected override async void OnElementChanged(ElementChangedEventArgs <ZXingScannerView> e)
        {
            base.OnElementChanged(e);

            formsView = Element;

            if (zxingSurface == null)
            {
                finishedSetup = new TaskCompletionSource <bool> ();

                // We'll proxy our requests through an intermediate layer that can intercept
                // the scanning so it can ask for permission
                intermediaryScanner = new IntermediaryScanner {
                    Parent = this
                };
                formsView.InternalNativeScannerImplementation = intermediaryScanner;

                var activity = Context as Activity;

                if (activity != null)
                {
                    await PermissionsHandler.RequestPermissions(activity);
                }

                zxingSurface = new ZXingSurfaceView(Xamarin.Forms.Forms.Context as Activity);
                zxingSurface.LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent);

                base.SetNativeControl(zxingSurface);

                finishedSetup.TrySetResult(true);
            }
        }
예제 #2
0
        protected override async void OnElementChanged(ElementChangedEventArgs <ZXingScannerView> e)
        {
            base.OnElementChanged(e);

            formsView = Element;

            if (zxingSurface == null)
            {
                // Process requests for autofocus
                formsView.AutoFocusRequested += (x, y) => {
                    if (zxingSurface != null)
                    {
                        if (x < 0 && y < 0)
                        {
                            zxingSurface.AutoFocus();
                        }
                        else
                        {
                            zxingSurface.AutoFocus(x, y);
                        }
                    }
                };

                var activity = Context as Activity;

                if (activity != null)
                {
                    await PermissionsHandler.RequestPermissions(activity);
                }

                zxingSurface = new ZXingSurfaceView(Xamarin.Forms.Forms.Context as Activity, formsView.Options);
                zxingSurface.LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent);

                base.SetNativeControl(zxingSurface);

                if (formsView.IsScanning)
                {
                    zxingSurface.StartScanning(formsView.RaiseScanResult, formsView.Options);
                }

                if (!formsView.IsAnalyzing)
                {
                    zxingSurface.PauseAnalysis();
                }

                if (formsView.IsTorchOn)
                {
                    zxingSurface.Torch(true);
                }
            }
        }
예제 #3
0
 /*
  * string path = (string)Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DataDirectory.ToString());
  * string pathpackage;
  * string pathtxt;
  */
 public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
 {
     PermissionsHandler.OnRequestPermissionsResult(requestCode, permissions, grantResults);
 }