public async void OnClick(View v) { if (!(View is ViewGroup root)) { return; } CloseKeyboard(); TextView results = root.FindViewById <TextView>(Resource.Id.resultData); _details = ""; _barcodeImage = null; _showResultsLabel = false; results.Text = _details; TextView resultLabel = root.FindViewById <TextView>(Resource.Id.resultLabel); resultLabel.Visibility = ViewStates.Gone; switch (_item.Id) { case "1": var barcode = root.FindViewById <ImageView>(Resource.Id.barcode); barcode.SetImageBitmap(_barcodeImage); var barcodeText = root.FindViewById <EditText>(Resource.Id.barcodeText); var includeText = root.FindViewById <CheckBox>(Resource.Id.includeText); var barcodeType = root.FindViewById <Spinner>(Resource.Id.barcodeTypes); var symbology = Enum.Parse <Symbology>(barcodeType.SelectedItem.ToString().Replace('-', '_')); try { // Call to external Zebra Create Barcode API var barcodeBytes = await CreateBarcode.CreateAsync(symbology, barcodeText.Text, _density * 3, Rotation.Normal, includeText.Checked); OnPostExecute(barcodeBytes); } catch (Exception e) { OnPostExecute(e); } return; case "2": EditText searchText = root.FindViewById <EditText>(Resource.Id.fdaSearchTerm); try { // Call to external Zebra FDA Device Recall Search API var deviceSearchJson = await FDARecall.DeviceSearchAsync(searchText.Text); OnPostExecute(JToken.Parse(deviceSearchJson).ToString(Formatting.Indented)); } catch (Exception e) { OnPostExecute(e); } try { // Call to external Zebra FDA Drug Recall Search API var drugSearchJson = await FDARecall.DrugSearchAsync(searchText.Text); OnPostExecute(JToken.Parse(drugSearchJson).ToString(Formatting.Indented)); } catch (Exception e) { OnPostExecute(e); } return; case "3": EditText lookupText = root.FindViewById <EditText>(Resource.Id.upc); try { // Call to external Zebra UPC Lookup API var upcLookupJson = await UPCLookup.LookupAsync(lookupText.Text); OnPostExecute(JToken.Parse(upcLookupJson).ToString(Formatting.Indented)); } catch (Exception e) { OnPostExecute(e); } return; } }
public async void RouteScanData(string barcode, string symbology) { if (!(View is ViewGroup root)) { return; } CloseKeyboard(); TextView results = root.FindViewById <TextView>(Resource.Id.resultData); const string typePrefix = "label-type-"; const string gs1Prefix = "gs1-"; if (symbology.StartsWith(typePrefix)) { symbology = symbology.Substring(typePrefix.Length); } if (symbology.StartsWith(gs1Prefix) && !Enum.TryParse(symbology.Replace('-', '_'), out Symbology _)) { symbology = symbology.Substring(gs1Prefix.Length); } string upcA = null; if (symbology.StartsWith("upce")) { symbology = "upce"; // Calculate UPC-A code for product lookup upcA = EAN8ToUPCA(barcode); } if (symbology == "databar") { symbology += barcode.Length > 16 || !long.TryParse(barcode, out _) ? "expanded" : "stackedomni"; } TextView resultLabel; switch (_item.Id) { case "1": EditText barcodeText = root.FindViewById <EditText>(Resource.Id.barcodeText); barcodeText.Text = barcode; Spinner barcodeType = root.FindViewById <Spinner>(Resource.Id.barcodeTypes); int index = Array.IndexOf(Enum.GetValues(typeof(Symbology)), Enum.Parse <Symbology>(symbology.Replace('-', '_'))); if (index > -1) { barcodeType.SetSelection(index + 1); } return; case "2": _details = ""; results.Text = _details; resultLabel = root.FindViewById <TextView>(Resource.Id.resultLabel); resultLabel.Visibility = ViewStates.Gone; _showResultsLabel = false; try { // Call to external Zebra FDA Food Recall API var foodUpcJson = await FDARecall.FoodUpcAsync(barcode); OnPostExecute(JToken.Parse(foodUpcJson).ToString(Formatting.Indented)); } catch (Exception e) { OnPostExecute(e); } try { // Call to external Zebra FDA Drug Recall API var drugUpcJson = await FDARecall.DrugUpcAsync(barcode); OnPostExecute(JToken.Parse(drugUpcJson).ToString(Formatting.Indented)); } catch (Exception e) { OnPostExecute(e); } return; case "3": _details = ""; results.Text = _details; resultLabel = root.FindViewById <TextView>(Resource.Id.resultLabel); resultLabel.Visibility = ViewStates.Gone; _showResultsLabel = false; EditText upc = root.FindViewById <EditText>(Resource.Id.upc); upc.Text = upcA ?? barcode; try { // Call to external Zebra UPC Lookup API var upcLookupJson = await UPCLookup.LookupAsync(upcA ?? barcode); OnPostExecute(JToken.Parse(upcLookupJson).ToString(Formatting.Indented)); } catch (Exception e) { OnPostExecute(e); } return; } }