private static void doTest(String contents, String title, String[] names, String pronunciation, String[] addresses, String[] emails, String[] phoneNumbers, String[] phoneTypes, String org, String[] urls, String birthday, String note) { ZXing.Result fakeResult = new ZXing.Result(contents, null, null, BarcodeFormat.QR_CODE); ParsedResult result = ResultParser.parseResult(fakeResult); Assert.AreEqual(ParsedResultType.ADDRESSBOOK, result.Type); AddressBookParsedResult addressResult = (AddressBookParsedResult)result; Assert.AreEqual(title, addressResult.Title); Assert.IsTrue(AreEqual(names, addressResult.Names)); Assert.AreEqual(pronunciation, addressResult.Pronunciation); Assert.IsTrue(AreEqual(addresses, addressResult.Addresses)); Assert.IsTrue(AreEqual(emails, addressResult.Emails)); Assert.IsTrue(AreEqual(phoneNumbers, addressResult.PhoneNumbers)); Assert.AreEqual(phoneTypes, addressResult.PhoneTypes); Assert.AreEqual(org, addressResult.Org); Assert.IsTrue(AreEqual(urls, addressResult.URLs)); Assert.AreEqual(birthday, addressResult.Birthday); Assert.AreEqual(note, addressResult.Note); }
private static void DrawTo(ICanvas2D dc, ZXing.Result result, Point2 offset) { if (result == null) { return; } if (result.ResultPoints == null || result.ResultPoints.Length == 0) { return; } /* TODO: the ResultPoints interpretation depends on BarcodeFormat * switch (Result.BarcodeFormat) * { * case ZXing.BarcodeFormat.AZTEC: * }*/ var points = result.ResultPoints .Select(item => (Point2)(new Point2(item.X, item.Y) + offset)) .ToArray(); dc.DrawPolygon((Color.Red, 4), points); var center = Point2.Centroid(points); dc.DrawTextLine(center, result.Text, 20, Color.Red); }
void HandleScanResult(ZXing.Result result) { string msg = ""; if (result != null && !string.IsNullOrEmpty(result.Text)) { msg = result.Text; } else { msg = "-1"; } RunOnUiThread(() => { if (msg != "-1") { Intent ActBookList = new Intent(this, typeof(BookListViewAdmin)); ActBookList.PutExtra("SearchInfo", msg); StartActivity(ActBookList); } else { Toast.MakeText(this, "ɨÃèÈ¡Ïû", ToastLength.Short).Show(); } }); }
void HandleResult(ZXing.Result result) { string msg = "No Barcode"; if (result != null) { msg = result.Text; try { Intent intent = new Intent(this, typeof(ResultActivity)); transaction = JsonConvert.DeserializeObject <TransactionObject>(msg); intent.PutExtra("User", JsonConvert.SerializeObject(user)); intent.PutExtra("Token", JsonConvert.SerializeObject(transaction)); this.StartActivity(intent); } catch { AlertDialog.Builder dialog = new AlertDialog.Builder(this); dialog.SetTitle("Invalid QR"); dialog.SetMessage("This is an invalid QR code"); dialog.SetNeutralButton("Ok", delegate { dialog.Dispose(); }); dialog.Show(); } } }
private void QRCodeTimer_Tick(object sender, EventArgs e) { ShowScore(); if (QRCodeBitmap == null) { return; } //把ColorFrame的wbData的資料從WriteableBitmap格式,轉成Bitmap格式,才能符合QRcode格式 ZXing.Result result = reader.Decode(BitmapToWriteableBitmap.BitmapFromWriteableBitmap(QRCodeBitmap)); if (result != null) { Console.WriteLine(result.Text); if (vocabulary.Give_Vocabulary(posture_number).ToLower().Contains(result.Text.ToLower())) { Success_Change_word(this, new EventArgs()); Console.WriteLine("成功" + result.Text); FirebaseUpload.Upload(ActivityTitle, "正確", new ORcodeObject(result.Text, txtVocabulary.Text, 1)); } else { SoundPlay.PlaySoundFailed(); Console.WriteLine("失敗" + result.Text); FirebaseUpload.Upload(ActivityTitle, "錯誤", new ORcodeObject(result.Text, txtVocabulary.Text, 1)); } } }
public void HandleScanResult(ZXing.Result result) { if (result == null) { Toast.MakeText(this, "Ocorreu um erro durante o escaneamento. Por favor, tente novamente", ToastLength.Short).Show(); txtCodigoNF.Error = null; } if (result != null && !string.IsNullOrEmpty(result.Text) && result.Text.Length == 44) { txtCodigoNF.Text = result.Text; Substring_Helper sub = new Substring_Helper(); lblCNPJ.Text = "CNPJ Emissor: " + sub.Substring_CNPJ(result.Text.ToString()); lblNumeroNF.Text = "Número NF: " + sub.Substring_NumeroNF(result.Text.ToString()) + "/" + sub.Substring_SerieNota(result.Text.ToString()); txtCodigoNF.Error = null; } else { txtCodigoNF.Error = "Código inválido! O código de barras deve ter 44 caracteres!"; lblCNPJ.Text = "CNPJ Emissor: "; lblNumeroNF.Text = "Número NF: "; txtCodigoNF.Text = ""; } }
/// <summary> /// ScanCode /// Scan a QR Code using the ZXing library /// </summary> /// <returns></returns> private async Task ScanCode() { Scanner.UseCustomOverlay = false; Scanner.TopText = "Hold camera up to QR code"; Scanner.BottomText = "Camera will automatically scan QR code\r\n\rPress the 'Back' button to cancel"; ZXing.Result result = await Scanner.Scan().ConfigureAwait(true); if (result == null || (string.IsNullOrEmpty(result.Text))) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { MessageDialog dialog = new MessageDialog("An error occured while scanning the QRCode. Try again"); await dialog.ShowAsync(); }); } else { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { TBConnectionString.Text = result.Text; TBDeviceName.Text = CTD.ExtractDeviceIdFromConnectionString(result.Text); }); } }
private static void doTestIsPossiblyMalicious(String uri, bool malicious) { var fakeResult = new ZXing.Result(uri, null, null, BarcodeFormat.QR_CODE); ParsedResult result = ResultParser.parseResult(fakeResult); Assert.AreEqual(malicious ? ParsedResultType.TEXT : ParsedResultType.URI, result.Type); }
override public ParsedResult parse(ZXing.Result result) { String rawText = result.Text; if (!(rawText.StartsWith("smtp:") || rawText.StartsWith("SMTP:"))) { return(null); } String emailAddress = rawText.Substring(5); String subject = null; String body = null; int colon = emailAddress.IndexOf(':'); if (colon >= 0) { subject = emailAddress.Substring(colon + 1); emailAddress = emailAddress.Substring(0, colon); colon = subject.IndexOf(':'); if (colon >= 0) { body = subject.Substring(colon + 1); subject = subject.Substring(0, colon); } } String mailtoURI = "mailto:" + emailAddress; return(new EmailAddressParsedResult(emailAddress, subject, body, mailtoURI)); }
/// <summary> /// attempt to parse the raw result to the specific type /// </summary> /// <param name="result"></param> /// <returns></returns> public override ParsedResult parse(ZXing.Result result) { var rawText = result.Text; if (!rawText.StartsWith("WIFI:")) { return(null); } rawText = rawText.Substring("WIFI:".Length); var ssid = matchSinglePrefixedField("S:", rawText, ';', false); if (string.IsNullOrEmpty(ssid)) { return(null); } var pass = matchSinglePrefixedField("P:", rawText, ';', false); var type = matchSinglePrefixedField("T:", rawText, ';', false) ?? "nopass"; bool hidden = false; #if WindowsCE try { hidden = Boolean.Parse(matchSinglePrefixedField("H:", rawText, ';', false)); } catch { } #else Boolean.TryParse(matchSinglePrefixedField("H:", rawText, ';', false), out hidden); #endif var identity = matchSinglePrefixedField("I:", rawText, ';', false); var anonymousIdentity = matchSinglePrefixedField("A:", rawText, ';', false); var eapMethod = matchSinglePrefixedField("E:", rawText, ';', false); var phase2Method = matchSinglePrefixedField("H:", rawText, ';', false); return(new WifiParsedResult(type, ssid, pass, hidden, identity, anonymousIdentity, eapMethod, phase2Method)); }
public void testRSSExpanded() { IDictionary <String, String> uncommonAIs = new Dictionary <String, String>(); uncommonAIs["123"] = "544654"; ZXing.Result result = new ZXing.Result("(01)66546(13)001205(3932)4455(3102)6544(123)544654", null, null, BarcodeFormat.RSS_EXPANDED); var o = (ExpandedProductParsedResult) new ExpandedProductResultParser().parse(result); Assert.IsNotNull(o); Assert.AreEqual("66546", o.ProductID); Assert.IsNull(o.Sscc); Assert.IsNull(o.LotNumber); Assert.IsNull(o.ProductionDate); Assert.AreEqual("001205", o.PackagingDate); Assert.IsNull(o.BestBeforeDate); Assert.IsNull(o.ExpirationDate); Assert.AreEqual("6544", o.Weight); Assert.AreEqual("KG", o.WeightType); Assert.AreEqual("2", o.WeightIncrement); Assert.AreEqual("5", o.Price); Assert.AreEqual("2", o.PriceIncrement); Assert.AreEqual("445", o.PriceCurrency); Assert.AreEqual(uncommonAIs, o.UncommonAIs); }
private async void ImgbtnScanBarCode_Clicked(object sender, EventArgs e) { try { ShowLoading(true); var scanner = new MobileBarcodeScanner(); scanner.UseCustomOverlay = true; ZXing.Result result = await scanner.Scan(); if (result != null) { labelBARCode.Text = result.Text; if (!string.IsNullOrEmpty(labelBARCode.Text) && labelBARCode.Text.Contains(":")) { labelBARCode.Text = labelBARCode.Text.Replace(":", ""); } } else { labelBARCode.Text = string.Empty; } ShowLoading(false); } catch (Exception ex) { ShowLoading(false); await DisplayAlert("Alert", ex.Message, "Ok"); dal_Exceptionlog.InsertException(Convert.ToString(App.Current.Properties["apitoken"]), "Operator App", ex.Message, "ActivatePassPage.xaml.cs", "", "ImgbtnScanBarCode_Clicked"); } }
void ZXingScannerView_OnScanResult(ZXing.Result result) { Device.BeginInvokeOnMainThread(() => { scanResultText.Text = result.Text + $"(type: {result.BarcodeFormat})"; }); }
void HandleScanResult(ZXing.Result result) { if (result != null && !string.IsNullOrEmpty(result.Text)) { string barcode_result = result.Text; string endpoint_value = getQrcodeNode("<Endpoint>", "</Endpoint>", barcode_result); string code_value = getQrcodeNode("<Code>", "</Code>", barcode_result); string valid_value = getQrcodeNode("<Valid>", "</Valid>", barcode_result); string createdby_value = getQrcodeNode("<CreatedBy>", "</CreatedBy>", barcode_result); if (endpoint_value != null && code_value != null && valid_value != null && createdby_value != null) { LocalStorage.SaveSet("activation_barcode", barcode_result); LocalStorage.SaveSet("customer", code_value); scanner.Cancel(); this.ActivationViewModel.Valid_activation = true; this.ActivationViewModel.func(); this.Finish(); } else { this.ActivationViewModel.Valid_activation = false; this.Finish(); } } }
private static void doTest(String contents, String wmi, String vds, String vis, String country, String attributes, int year, char plant, String sequential) { var fakeResult = new ZXing.Result(contents, null, null, BarcodeFormat.CODE_39); var result = ResultParser.parseResult(fakeResult); Assert.AreEqual(ParsedResultType.VIN, result.Type); var vinResult = (VINParsedResult)result; Assert.AreEqual(wmi, vinResult.WorldManufacturerID); Assert.AreEqual(vds, vinResult.VehicleDescriptorSection); Assert.AreEqual(vis, vinResult.VehicleIdentifierSection); Assert.AreEqual(country, vinResult.CountryCode); Assert.AreEqual(attributes, vinResult.VehicleAttributes); Assert.AreEqual(year, vinResult.ModelYear); Assert.AreEqual(plant, vinResult.PlantCode); Assert.AreEqual(sequential, vinResult.SequentialNumber); }
private async void Button_Clicked(object sender, EventArgs e) { try { var app = new Android.App.Application(); MobileBarcodeScanner.Initialize(app); var scanner = new MobileBarcodeScanner(); scanner.TopText = "Hold the camera up to the QR code\nAbout 6 inches away"; scanner.BottomText = "Wait for the QR code to automatically scan!"; //This will start scanning ZXing.Result result = await scanner.Scan(); string[] lines = result.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.None); ProductsModel productsModel = new ProductsModel() { ProductId = lines[0].Substring(lines[0].IndexOf('-') + 1), SerialNo = "1", ProductDescription = lines[1].Substring(lines[1].IndexOf('-') + 1), UnitPrice = lines[2].Substring(lines[2].IndexOf('-') + 1), SellPrice = lines[3].Substring(lines[3].IndexOf('-') + 1), Quantity = lines[4].Substring(lines[4].IndexOf('-') + 1) }; await Navigation.PushAsync(new ProductListPage(productsModel, UserId)); } catch (Exception ex) { //await DisplayAlert("Error", ex.Message, "Ok"); } }
private async void Sucess(IEnumerable <Reservation> reservation, Result result) { if (reservation == null || !reservation.Any()) { string body = string.Format("Комната: {0} \n От: {1:hh\\:mm} \n До: {2:hh\\:mm}", result.Text, DateTime.Now, DateTime.Now.AddHours(1)); bool saveOrNot = await DisplayAlert("Забронировать комнату?", body, "Да", "Нет"); if (saveOrNot) { StatusCode savStatusCode = (await this.manager.AddReservationInHour(result.Text)).Status; if (savStatusCode == StatusCode.Ok) { await this.DisplayAlert("Успешно", "Комната успешно занята", Ok); } else { await this.DisplayAlert(HeadError, BodyErrorInternetOrServer, Ok); } } } else { await this.DisplayAlert(HeadError, RoomIsBook, Ok); } }
override public ParsedResult parse(ZXing.Result result) { String rawText = result.Text; if (rawText.Length < 5 || String.Compare(rawText.Substring(0, 5).ToUpper(), "WIFI:") != 0) { return(null); } // Don't remove leading or trailing whitespace bool trim = false; String ssid = matchSinglePrefixedField("S:", rawText, ';', trim); if (ssid == null || ssid.Length == 0) { return(null); } String pass = matchSinglePrefixedField("P:", rawText, ';', trim); String type = matchSinglePrefixedField("T:", rawText, ';', trim); if (type == null) { type = "nopass"; } return(new WifiParsedResult(type, ssid, pass)); }
/// <summary> /// Start the QR-scan page (ZXing library). Will add the scan result to history and execute the Javascript-function on the webpage. /// </summary> public void StartScan() { //////////////// TEST CustomScanPage customPage = new CustomScanPage(); customPage.Disappearing += (s, e) => { ZXing.Result result = customPage.result; if (result != null) { ScanHistory.Add(result.Text); InjectJSQRCode(result.Text); if (Parameters.Options.UseLocation) { OpenJSFunctionLocation(); } } Parameters.TemporaryOptions.ResetOptions(); }; if (Parameters.Options.UseLocation) { QRLocation.InitLocation(); } NavigateTo(customPage); //await App.Current.MainPage.Navigation.PushModalAsync(customPage); }
void HandleScanResultReturn(ZXing.Result result) { string msg = ""; if (result != null && !string.IsNullOrEmpty(result.Text)) { msg = "Found Barcode: " + result.Text; } else { msg = "Scanning Canceled!"; } this.RunOnUiThread(() => Toast.MakeText(this, msg, ToastLength.Short).Show()); _QrCode = result.Text; BookResponse bookResponse = _RequestSender.SendUpdateCopiesRequest(_QrCode, false, user.UserInfo.Id); if (bookResponse != null && bookResponse.WasUpdated) { foreach (var book in user.BorrowedBooks) { if (book.QRCode.ToString() == _QrCode) { user.BorrowedBooks.Remove(book); break; } } Refresh(); } }
private void ScanPage_OnScanResult(ZXing.Result result) { scanPage.IsScanning = false; Device.BeginInvokeOnMainThread(async() => { var product = await ProductService.GetProductByBarcode(result.Text); if (product != null) { var p = Products.FirstOrDefault(d => d.Id == product.Id); if (p != null) { p.ShowDetail = false; UpdownDetail(p); MessagingCenter.Send <ProductViewModel, Product>(this, "ScanProduct", p); } else { EmbellishSingleProduct(product); product.ShowDetail = true; Products.Insert(0, product); MessagingCenter.Send <ProductViewModel, Product>(this, "ScanProduct", product); } await Navigation.PopAsync(); } else { await Navigation.PopAsync(); await App.Current.MainPage.DisplayAlert("Sorry", "There is not barcode:" + result.Text, "Ok"); } }); }
// triggers when scanner reads a qr code **NOTE**: ADD INVALID PARSING AND REOPEN SCANNER ON FAILURE public void scanView_OnScanResult(ZXing.Result result) { //check if scanner hasnt already read something if (!noMoreScan) { //CLOSE SCANNER noMoreScan = true; //PARSE QR DATA AND SEND TO BACKEND string[] newRMData = result.Text.Split('|'); //check if label data fits if (newRMData.Length < 3) { Device.BeginInvokeOnMainThread(async() => { await App.Current.MainPage.DisplayAlert("Scanned result", "Invalid Label", "OK"); //open scanner noMoreScan = false; }); } else { sendData(newRMData); } } }
void HandleScanResult(ZXing.Result result) { if (result != null && !string.IsNullOrEmpty(result.Text)) { if (result.Text.Length == 13) { libro = Service.SearchBook(result.Text); if (libro != null) { edtISBN.Text = libro.ISBN; edtTitulo.Text = libro.Titulo; } else { Toast.MakeText(this, "El libro no existe", ToastLength.Long).Show(); } } else { Toast.MakeText(this, "Error en los datos", ToastLength.Long).Show(); } } else { Toast.MakeText(this, "Vuelva a escanear", ToastLength.Long).Show(); } }
private static void doTest(String contents, String description, String summary, String location, String startString, String endString, String organizer, String[] attendees, double latitude, double longitude) { ZXing.Result fakeResult = new ZXing.Result(contents, null, null, BarcodeFormat.QR_CODE); ParsedResult result = ResultParser.parseResult(fakeResult); Assert.AreEqual(ParsedResultType.CALENDAR, result.Type); CalendarParsedResult calResult = (CalendarParsedResult)result; Assert.AreEqual(description, calResult.Description); Assert.AreEqual(summary, calResult.Summary); Assert.AreEqual(location, calResult.Location); Assert.AreEqual(startString, calResult.Start.ToString(DATE_TIME_FORMAT)); Assert.AreEqual(endString, calResult.End == null ? null : calResult.End.Value.ToString(DATE_TIME_FORMAT)); Assert.AreEqual(organizer, calResult.Organizer); Assert.IsTrue((attendees == null && calResult.Attendees == null) || Equals(attendees, calResult.Attendees)); assertEqualOrNaN(latitude, calResult.Latitude); assertEqualOrNaN(longitude, calResult.Longitude); }
private void ZXingScannerView_OnScanResult(ZXing.Result result) { Device.BeginInvokeOnMainThread(() => { MessagingCenter.Send(result.Text, "ScanQRCode"); }); }
private async void Window_Captured(ZXing.Result obj) { if (Core.Helper.QRParser.TryParse(obj.Text, out var game)) { await StartGame(game); } }
private void DecodeFrame(FastJavaByteArray fastArray) { var cameraParameters = _cameraController.Camera.GetParameters(); var width = cameraParameters.PreviewSize.Width; var height = cameraParameters.PreviewSize.Height; var barcodeReader = _scannerHost.ScanningOptions.BuildBarcodeReader(); var rotate = false; var newWidth = width; var newHeight = height; // use last value for performance gain var cDegrees = _cameraController.LastCameraDisplayOrientationDegree; //if (cDegrees == 90 || cDegrees == 270) //{ // rotate = true; // newWidth = height; // newHeight = width; //} ZXing.Result result = null; var start = PerformanceCounter.Start(); //LuminanceSource fast = new FastJavaByteArrayYUVLuminanceSource(fastArray, width, height, 0, 0, width, height); // _area.Left, _area.Top, _area.Width, _area.Height); // cut square in the middle LuminanceSource fast = new FastJavaByteArrayYUVLuminanceSource( fastArray, width, height, (width - Math.Min(width, height)) / 2, (height - Math.Min(width, height)) / 2, Math.Min(width, height), Math.Min(width, height) ); if (rotate) { fast = fast.rotateCounterClockwise(); } result = barcodeReader.Decode(fast); fastArray.Dispose(); fastArray = null; PerformanceCounter.Stop(start, "Decode Time: {0} ms (width: " + width + ", height: " + height + ", degrees: " + cDegrees + ", rotate: " + rotate + ")"); if (result != null) { Android.Util.Log.Debug(MobileBarcodeScanner.TAG, "Barcode Found: " + result.Text); _wasScanned = true; BarcodeFound?.Invoke(this, result); return; } }
override sealed public ParsedResult parse(ZXing.Result result) { var rawText = result.Text; if (!rawText.StartsWith("WIFI:")) { return(null); } var ssid = matchSinglePrefixedField("S:", rawText, ';', false); if (string.IsNullOrEmpty(ssid)) { return(null); } var pass = matchSinglePrefixedField("P:", rawText, ';', false); var type = matchSinglePrefixedField("T:", rawText, ';', false) ?? "nopass"; bool hidden = false; #if WindowsCE try { hidden = Boolean.Parse(matchSinglePrefixedField("H:", rawText, ';', false)); } catch { } #else Boolean.TryParse(matchSinglePrefixedField("H:", rawText, ';', false), out hidden); #endif return(new WifiParsedResult(type, ssid, pass, hidden)); }
private void QRCodeTimer_Tick(object sender, EventArgs e) { if (QRCodeBitmap == null) { return; } //把ColorFrame的wbData的資料從WriteableBitmap格式,轉成Bitmap格式,才能符合QRcode格式 ZXing.Result result = reader.Decode(BitmapToWriteableBitmap.BitmapFromWriteableBitmap(QRCodeBitmap)); if (result != null) { Console.WriteLine(result.Text); //這邊要檢查 List裡有包含單字的陣列 if (TaskWords.Contains(result.Text)) { ReturnPostureWords returnPostureWords = new ReturnPostureWords() { PostureWords = result.Text }; Success_Change_word(this, returnPostureWords); Console.WriteLine("成功" + result.Text); FirebaseUpload.Upload(ActivityTitle, "正確", new ORcodeObject(result.Text, txtVocabulary.Text, 1)); } else { SoundPlay.PlaySoundFailed(); //System.Windows.Forms.MessageBox.Show(result.Text); Console.WriteLine("失敗" + result.Text); FirebaseUpload.Upload(ActivityTitle, "錯誤", new ORcodeObject(result.Text, txtVocabulary.Text, 1)); } } }
private void OnScanResult(ZXing.Result result) { // Stop analysis until we navigate away so we don't keep reading barcodes _zxing.IsAnalyzing = false; _zxing.IsScanning = false; var text = result?.Text; if (!string.IsNullOrWhiteSpace(text)) { if (text.StartsWith("otpauth://totp")) { _callback(text); return; } else if (Uri.TryCreate(text, UriKind.Absolute, out Uri uri) && !string.IsNullOrWhiteSpace(uri?.Query)) { var queryParts = uri.Query.Substring(1).ToLowerInvariant().Split('&'); foreach (var part in queryParts) { if (part.StartsWith("secret=")) { _callback(part.Substring(7)?.ToUpperInvariant()); return; } } } } _callback(null); }
private static void doTest(String contents) { ZXing.Result fakeResult = new ZXing.Result(contents, null, null, BarcodeFormat.EAN_13); ParsedResult result = ResultParser.parseResult(fakeResult); Assert.AreEqual(ParsedResultType.ISBN, result.Type); ISBNParsedResult isbnResult = (ISBNParsedResult)result; Assert.AreEqual(contents, isbnResult.ISBN); }
public void testNotVIN() { var fakeResult = new ZXing.Result("1M8GDM9A1KP042788", null, null, BarcodeFormat.CODE_39); var result = ResultParser.parseResult(fakeResult); Assert.AreEqual(ParsedResultType.TEXT, result.Type); fakeResult = new ZXing.Result("1M8GDM9AXKP042788", null, null, BarcodeFormat.CODE_128); result = ResultParser.parseResult(fakeResult); Assert.AreEqual(ParsedResultType.TEXT, result.Type); }
private static void doTest(String contents, String normalized, BarcodeFormat format) { ZXing.Result fakeResult = new ZXing.Result(contents, null, null, format); ParsedResult result = ResultParser.parseResult(fakeResult); Assert.AreEqual(ParsedResultType.PRODUCT, result.Type); ProductParsedResult productResult = (ProductParsedResult)result; Assert.AreEqual(contents, productResult.ProductID); Assert.AreEqual(normalized, productResult.NormalizedProductID); }
private static void doTest(String contents, String number, String title) { ZXing.Result fakeResult = new ZXing.Result(contents, null, null, BarcodeFormat.QR_CODE); ParsedResult result = ResultParser.parseResult(fakeResult); Assert.AreEqual(ParsedResultType.TEL, result.Type); TelParsedResult telResult = (TelParsedResult)result; Assert.AreEqual(number, telResult.Number); Assert.AreEqual(title, telResult.Title); Assert.AreEqual("tel:" + number, telResult.TelURI); }
private async void HandleScanResult(Result result) { if (result != null && !string.IsNullOrEmpty(result.Text)) { await _client.AddBarCode(result.Text); return; } Toast.MakeText(this, "Scanning Canceled!", ToastLength.Short).Show(); }
private static void doTest(String contents, String email, String subject, String body) { ZXing.Result fakeResult = new ZXing.Result(contents, null, null, BarcodeFormat.QR_CODE); ParsedResult result = ResultParser.parseResult(fakeResult); Assert.AreEqual(ParsedResultType.EMAIL_ADDRESS, result.Type); EmailAddressParsedResult emailResult = (EmailAddressParsedResult)result; Assert.AreEqual(email, emailResult.EmailAddress); Assert.AreEqual("mailto:" + email, emailResult.MailtoURI); Assert.AreEqual(subject, emailResult.Subject); Assert.AreEqual(body, emailResult.Body); }
private static void doTest(String contents, String[] numbers, String subject, String body, String[] vias) { ZXing.Result fakeResult = new ZXing.Result(contents, null, null, BarcodeFormat.QR_CODE); ParsedResult result = ResultParser.parseResult(fakeResult); Assert.AreEqual(ParsedResultType.SMS, result.Type); SMSParsedResult smsResult = (SMSParsedResult)result; Assert.IsTrue(AddressBookParsedResultTestCase.AreEqual(numbers, smsResult.Numbers)); Assert.AreEqual(subject, smsResult.Subject); Assert.AreEqual(body, smsResult.Body); Assert.IsTrue(AddressBookParsedResultTestCase.AreEqual(vias, smsResult.Vias)); }
private static void doTest(String contents, double latitude, double longitude, double altitude, String query) { ZXing.Result fakeResult = new ZXing.Result(contents, null, null, BarcodeFormat.QR_CODE); ParsedResult result = ResultParser.parseResult(fakeResult); Assert.AreEqual(ParsedResultType.GEO, result.Type); GeoParsedResult geoResult = (GeoParsedResult)result; Assert.AreEqual(latitude, geoResult.Latitude, EPSILON); Assert.AreEqual(longitude, geoResult.Longitude, EPSILON); Assert.AreEqual(altitude, geoResult.Altitude, EPSILON); Assert.AreEqual(query, geoResult.Query); }
/// <summary> /// Given the string contents for the barcode, check that it matches our expectations /// </summary> private static void doTest(String contents, String ssid, String password, String type) { var fakeResult = new ZXing.Result(contents, null, null, BarcodeFormat.QR_CODE); var result = ResultParser.parseResult(fakeResult); // Ensure it is a wifi code Assert.AreEqual(ParsedResultType.WIFI, result.Type); var wifiResult = (WifiParsedResult)result; Assert.AreEqual(ssid, wifiResult.Ssid); Assert.AreEqual(password, wifiResult.Password); Assert.AreEqual(type, wifiResult.NetworkEncryption); }
private static void doTest(String contents, String wmi, String vds, String vis, String country, String attributes, int year, char plant, String sequential) { var fakeResult = new ZXing.Result(contents, null, null, BarcodeFormat.CODE_39); var result = ResultParser.parseResult(fakeResult); Assert.AreEqual(ParsedResultType.VIN, result.Type); var vinResult = (VINParsedResult) result; Assert.AreEqual(wmi, vinResult.WorldManufacturerID); Assert.AreEqual(vds, vinResult.VehicleDescriptorSection); Assert.AreEqual(vis, vinResult.VehicleIdentifierSection); Assert.AreEqual(country, vinResult.CountryCode); Assert.AreEqual(attributes, vinResult.VehicleAttributes); Assert.AreEqual(year, vinResult.ModelYear); Assert.AreEqual(plant, vinResult.PlantCode); Assert.AreEqual(sequential, vinResult.SequentialNumber); }
public void test_RSSExpanded() { IDictionary<String, String> uncommonAIs = new Dictionary<String, String>(); uncommonAIs["123"] = "544654"; ZXing.Result result = new ZXing.Result("(01)66546(13)001205(3932)4455(3102)6544(123)544654", null, null, BarcodeFormat.RSS_EXPANDED); var o = (ExpandedProductParsedResult)new ExpandedProductResultParser().parse(result); Assert.IsNotNull(o); Assert.AreEqual("66546", o.ProductID); Assert.IsNull(o.Sscc); Assert.IsNull(o.LotNumber); Assert.IsNull(o.ProductionDate); Assert.AreEqual("001205", o.PackagingDate); Assert.IsNull(o.BestBeforeDate); Assert.IsNull(o.ExpirationDate); Assert.AreEqual("6544", o.Weight); Assert.AreEqual("KG", o.WeightType); Assert.AreEqual("2", o.WeightIncrement); Assert.AreEqual("5", o.Price); Assert.AreEqual("2", o.PriceIncrement); Assert.AreEqual("445", o.PriceCurrency); Assert.AreEqual(uncommonAIs, o.UncommonAIs); }
private bool IsAllowed(ZXing.BarcodeFormat type) { bool result = false; ZXing.BarcodeFormat[] Allowed2DTypes = { ZXing.BarcodeFormat.PDF_417, ZXing.BarcodeFormat.DATA_MATRIX, ZXing.BarcodeFormat.MAXICODE }; if (Allowed2DTypes.Where(t => t == type).Count() > 0) { result = true; // it's an allowed 2D type } else { if (type != ZXing.BarcodeFormat.UPC_E) result = true; // It's a 1D type that is not UPC_E } return result; }
public void testBadGeo() { // Not parsed as VEVENT var fakeResult = new ZXing.Result("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\n" + "GEO:-12.345\r\n" + "END:VEVENT\r\nEND:VCALENDAR", null, null, BarcodeFormat.QR_CODE); var result = ResultParser.parseResult(fakeResult); Assert.AreEqual(ParsedResultType.URI, result.Type); }
async private void beginCapture() { ZXing.Mobile.MobileBarcodeScanningOptions ScanningOptions = MobileBarcodeScanningOptions.Default; var zxing = ScanningOptions.BuildBarcodeReader(); SoftwareBitmapLuminanceSource luminanceSource = null; // Capture the preview frame, analyzem repeat until a result or cancel while (result == null && !hasBeenCancelled) { var videoFrame = new VideoFrame(BitmapPixelFormat.Bgra8, (int)capturePreview.ActualWidth, (int)capturePreview.ActualHeight); using (var frame = await mediaCapture.GetPreviewFrameAsync(videoFrame)) { try { // Create our luminance source luminanceSource = new SoftwareBitmapLuminanceSource(frame.SoftwareBitmap); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("GetPreviewFrame Failed: {0}", ex); } try { zxing.Options.TryHarder = true; // Try decoding the image if (luminanceSource != null) result = zxing.Decode(luminanceSource); } catch (Exception ex) { } } if (result != null) { if(App.APP_SETTINGS.UPCFormatsEnabled.Where(f => f == result.BarcodeFormat).Count() > 0 || App.APP_SETTINGS.UPCFormatsEnabled.Where(f => f == ZXing.BarcodeFormat.All_1D).Count() > 0) alert.Play(); } } }
private static void doTestNotUri(String text) { ZXing.Result fakeResult = new ZXing.Result(text, null, null, BarcodeFormat.QR_CODE); ParsedResult result = ResultParser.parseResult(fakeResult); Assert.AreEqual(ParsedResultType.TEXT, result.Type); Assert.AreEqual(text, result.DisplayResult); }
private static void doTest(String contents, String uri, String title) { ZXing.Result fakeResult = new ZXing.Result(contents, null, null, BarcodeFormat.QR_CODE); ParsedResult result = ResultParser.parseResult(fakeResult); Assert.AreEqual(ParsedResultType.URI, result.Type); URIParsedResult uriResult = (URIParsedResult)result; Assert.AreEqual(uri, uriResult.URI); Assert.AreEqual(title, uriResult.Title); }
private static void doTest(String contents, String[] tos, String[] ccs, String[] bccs, String subject, String body) { var fakeResult = new ZXing.Result(contents, null, null, BarcodeFormat.QR_CODE); var result = ResultParser.parseResult(fakeResult); Assert.AreEqual(ParsedResultType.EMAIL_ADDRESS, result.Type); var emailResult = (EmailAddressParsedResult)result; Assert.AreEqual(tos, emailResult.Tos); Assert.AreEqual(ccs, emailResult.CCs); Assert.AreEqual(bccs, emailResult.BCCs); Assert.AreEqual(subject, emailResult.Subject); Assert.AreEqual(body, emailResult.Body); }
private static void doTestResult(String contents, String goldenResult, ParsedResultType type, BarcodeFormat format) { ZXing.Result fakeResult = new ZXing.Result(contents, null, null, format); ParsedResult result = ResultParser.parseResult(fakeResult); Assert.IsNotNull(result); Assert.AreEqual(type, result.Type); String displayResult = result.DisplayResult; Assert.AreEqual(goldenResult, displayResult); }
protected override void OnNavigatedTo(NavigationEventArgs e) { scanResult = (ZXing.Result)e.Parameter; if (NameError.Visibility == Visibility.Visible) NameError.Visibility = Visibility.Collapsed; }