Example #1
0
        /// <summary>
        /// Callback method that processes results returned by the WP7BarcodeManager. 
        /// Results are also stored at WP7BarcodeManager.LastCaptureResults.
        /// </summary>
        /// <param name="results">Object that holds all the results of processing the barcode. 
        /// Results are also stored at WP7BarcodeManager.LastCaptureResults.</param>
        public void BarcodeResults(BarcodeCaptureResult results)
        {
            StopProgress();

            if (Microsoft.Devices.Environment.DeviceType == Microsoft.Devices.DeviceType.Emulator)
            {
                NavigationService.Navigate(new Uri("/AddProduct/" + "020356363307",
                                   UriKind.RelativeOrAbsolute));
            }
            else
            {

                if (results.State == CaptureState.Success)
                {
                    txtResults.Text = results.BarcodeText;
                    txtResults.Text += "  Processing...";

                    NavigationService.Navigate(new Uri("/AddProduct/" + results.BarcodeText,
                                                       UriKind.RelativeOrAbsolute));
                }
                else if (results.State == CaptureState.Canceled)
                {
                    txtResults.Text = "Cancelled";
                    NavigationService.Navigate(new Uri("/AddProduct/" + "020356363307",
                   UriKind.RelativeOrAbsolute));

                }
                else
                {
                    txtResults.Text = results.ErrorMessage;
                    NavigationService.Navigate(new Uri("/AddProduct/", UriKind.RelativeOrAbsolute));
                }
            }
        }
        public void ScanBarcode_Completed(BarcodeCaptureResult e)
        {
            if (e.State == WP7_Barcode_Library.CaptureState.Success)
            {
                string str = e.BarcodeText;
                str = str.Replace("otpauth://totp/", "");
                string[] splitString = str.Split(Convert.ToChar("?"));
                splitString[1] = splitString[1].Replace("secret=", "");

                txtAccountName.Text = splitString[0];
                txtSecretKey.Text = splitString[1];
            }
            else
            {
                MessageBox.Show("The barcode for your account could not be read. Please try again.", "Error", MessageBoxButton.OK);
            }
        }
Example #3
0
 public void BarcodeResults_Finished(BarcodeCaptureResult BCResults)
 {
     try
     {
         if (BCResults.State == CaptureState.Success && !string.IsNullOrEmpty(BCResults.BarcodeText))
         {
             NavigationService.Navigate(new Uri("/Detalle.xaml?isbn=" + BCResults.BarcodeText, UriKind.Relative));
         }
         else
         {
             Debug.WriteLine(BCResults.ErrorMessage);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(String.Format("Barcode Processing Error: {0}", ex.Message));
     }
 }
 public void BarcodeResults_Finished(BarcodeCaptureResult BCResults)
 {
     try
     {
         if (WP7BarcodeManager.LastCaptureResults.BarcodeImage != null)
         {
             this.QRCodeImage.Source = WP7BarcodeManager.LastCaptureResults.BarcodeImage; //Display image
         }
         if (BCResults.State == WP7_Barcode_Library.CaptureState.Success)
         {
             ServiceLocator.Current.GetInstance<NewDownloadViewModel>().URL = BCResults.BarcodeText;
         }
         else
         {
             MessageBox.Show(NewDownload.QRCodeFailed, NewDownload.Error, MessageBoxButton.OK);
         }
     }
     catch (Exception)
     {
         MessageBox.Show(NewDownload.QRCodeFailed, NewDownload.Error, MessageBoxButton.OK);
     }
 }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            if (State.ContainsKey("txtAccountName") && newPageInstance == true)
            {
                txtAccountName.Text = (string)State["txtAccountName"];
                txtSecretKey.Text = (string)State["txtSecretKey"];
            }

            if ((App.Current as App).QRCode != null)
            {
                //QR code has been received

                BarcodeCaptureResult scan_e = new BarcodeCaptureResult();
                scan_e.State = WP7_Barcode_Library.CaptureState.Success;
                scan_e.BarcodeText = (App.Current as App).QRCode;
                (App.Current as App).QRCode = null;

                ScanBarcode_Completed(scan_e);
            }

            base.OnNavigatedTo(e);
        }
Example #6
0
 /// <summary>
 /// Initializes static variables
 /// </summary>
 static WP7BarcodeManager()
 {
     LastCaptureResults = new BarcodeCaptureResult(); //Load blank results when initialized
     ScanMode = com.google.zxing.BarcodeFormat.UPC_EAN; //Set default scan mode
 }
Example #7
0
 /// <summary>
 /// Callback method for processing camera results.
 /// NOTE: This method will be called before the Main Page OnNavigatedTo method.
 /// Sets PhoneApplicationService.Current.State["ReturnFromCameraCapture"] flag to track loading from camera.
 /// Flag should be removed once data has been processed by main thread callback (Ex: PhoneApplicationService.Current.State.Remove("ReturnFromCameraCapture");)
 /// </summary>
 private static void PhotoTask_Completed(object sender, Microsoft.Phone.Tasks.PhotoResult e)
 {
     StartProgress();
     try
     {
         PhoneApplicationService.Current.State["ReturnFromCameraCapture"] = true; //Set flag to indicate we are returning from camera capture
         if (e != null && e.TaskResult == Microsoft.Phone.Tasks.TaskResult.OK)//Code from:http://blogs.msdn.com/b/coding4fun/archive/2010/08/09/10048007.aspx
         {
             LastCaptureResults = new BarcodeCaptureResult(e.ChosenPhoto);
             ThreadPool.QueueUserWorkItem(func => ProcessImage()); //Process image for barcode on background thread
         }
         else
         {
             LastCaptureResults.State = CaptureState.Canceled;
             LastCaptureResults.ErrorMessage = "Error: Photo capture canceled";
             ExecuteCallback();
         }
     }
     catch (Exception ex)
     {
         LastCaptureResults.ExceptionThrown = ex;
         if (ex is com.google.zxing.ReaderException)//Common error thrown when image cannot be recognized
         {
             LastCaptureResults.ErrorMessage = "Error: Cannot scan barcode. Please try again or enter manually in textbox.";
             LastCaptureResults.State = CaptureState.ScanFailed;
         }
         else
         {
             LastCaptureResults.ErrorMessage = String.Format("PhotoTask_Completed Error: {0}\r\n{1}", ex.GetType(), ex.Message);
             LastCaptureResults.State = CaptureState.UnknownError;
         }
         ExecuteCallback();
     }
 }
Example #8
0
 /// <summary>
 /// Overloaded method for processing existing BitmatImage.
 /// NOTE: only use this for existing images. If you have access to the URI where the photo came from (camera, resource, or content file) use other methods instead.
 /// </summary>
 /// <param name="imgBarcode">Barcode Image for processing</param>
 /// <param name="Finished_Processing">Callback</param>
 public static void ScanBarcode(BitmapImage imgBarcode, Action<BarcodeCaptureResult> Finished_Processing)
 {
     aFinished = Finished_Processing; //Store return callback
     LastCaptureResults = new BarcodeCaptureResult(imgBarcode);
     ThreadPool.QueueUserWorkItem(func => ProcessImage());
 }
Example #9
0
        /// <summary>
        /// Overloaded method that processes an existing Uri instead of using the phone's camera
        /// WP7Manager.LastCaptureResults will be set to the captured image and text results.
        /// </summary>
        /// <param name="Finished_Processing">Action method to call when processing is finished</param>
        /// <param name="UriBarcode">URI to barcode image</param>
        public static void ScanBarcode(Uri UriBarcode, Action<BarcodeCaptureResult> Finished_Processing)
        {
            StartProgress();
            aFinished = Finished_Processing; //Store return callback
            var bi = new BitmapImage(UriBarcode);
            bi.CreateOptions = BitmapCreateOptions.None; //Fixes issue with null pointer reference
            if (bi.PixelHeight == 0 || bi.PixelWidth == 0)
            {
                LastCaptureResults.ExceptionThrown = new ArgumentException(String.Format("Cannot load selected image. Please make sure URI path is correct.\r\nURI '{0}' cannot be loaded. Try using overloaded ScanBarcode with BitmapImage parameter instead.", UriBarcode.OriginalString));
                throw LastCaptureResults.ExceptionThrown;
            }

            LastCaptureResults = new BarcodeCaptureResult(bi);
            ThreadPool.QueueUserWorkItem(func => ProcessImage());
        }
Example #10
0
        /// <summary>
        /// Starts the phone camera so that the user can capture a photo.
        /// WP7Manager.LastCaptureResults will be set to the captured image and text results.
        /// Sets PhoneApplicationService.Current.State["ReturnFromCameraCapture"] flag when application is navigated to after loading photo from camera.
        /// Flag should be removed once data has been processed by main thread callback (Ex: PhoneApplicationService.Current.State.Remove("ReturnFromCameraCapture");)
        /// </summary>
        /// <param name="Finished_Processing">Action method to call when processing is finished</param>
        public static void ScanBarcode(Action<BarcodeCaptureResult> Finished_Processing)
        {
            StartProgress();
            aFinished = Finished_Processing; //Store return callback

            LastCaptureResults = new BarcodeCaptureResult(); //Create new result object

            Microsoft.Phone.Tasks.CameraCaptureTask aTask = new Microsoft.Phone.Tasks.CameraCaptureTask();
            aTask.Completed += new EventHandler<Microsoft.Phone.Tasks.PhotoResult>(PhotoTask_Completed);
            aTask.Show(); //Load camera task
        }
Example #11
0
        public void Result(BarcodeCaptureResult e)
        {
            bool lecturaExitosa = false;
            if (e.BarcodeImage != null)
            {
                if (e.State == WP7_Barcode_Library.CaptureState.Success)
                {
                    lecturaExitosa = true;
                }
            }

            if (scanCompleted != null)
                scanCompleted(e.BarcodeText, lecturaExitosa, e.BarcodeImage);
        }