protected override void OnCreate(Bundle savedInstanceState) { ScannerCode.Log("OnCreate..."); ScannerCode.ScanCount = 0; base.OnCreate(savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); selectScanner = FindViewById <Spinner>(Resource.Id.openReaderSpinner); openScanner = FindViewById <Android.Widget.Switch>(Resource.Id.openScannerSwitch); scanData = FindViewById <TextView>(Resource.Id.scanDataView); scanButton = FindViewById <Button>(Resource.Id.scanButton); symConfig = FindViewById <Button>(Resource.Id.config_symbologies); symConfig.Click += SymConfig_Click; scanButton.Click += ScanButton_Click; selectScanner.ItemSelected += SelectScanner_ItemSelected; openScanner.CheckedChange += OpenScanner_CheckedChange; //pass the context of this activity to the ScannCode class ScannerCode.AppContext = this.context; // Register ScanCode events from static instance ScannerCode.Log("Attach Scan_Result_Event..."); getReaderList(); }
/// <summary> /// Allows you to pass the scanned data form the ScannerCode.cs to the TextView on this Activity /// </summary> /// <param name="Result"></param> public void On_Result_Event(string Result)//Changed Scan Result event from static instance { ScannerCode.Log("Called On_Result_Event..., ScanCount=" + ScannerCode.ScanCount.ToString()); this.RunOnUiThread(() => {//Changed Invoke UI Thread scanData.SetText(Result, TextView.BufferType.Normal); }); }
/// <summary> /// When the ScanPage is about to go to the background, release the /// scanner. /// </summary> protected override void OnPause() { ScannerCode.Log("OnPause()..."); base.OnPause(); ScannerCode.CloseBarcodeScanner(); ScannerCode.Update_Event -= On_Update_Event; ScannerCode.Scan_Result_Event -= On_Result_Event; }
/// <summary> /// When the ScanPage is about to go to the foreground, claim the /// scanner. /// </summary> protected override void OnResume() { ScannerCode.Log("OnResume()..."); base.OnResume(); ScannerCode.OpenBarcodeReader(); ScannerCode.Scan_Result_Event += new ScannerCode.ScanResult(On_Result_Event); ScannerCode.Update_Event += new ScannerCode.UpdateControls(On_Update_Event); //lock the orientationt to Portrait this.RequestedOrientation = Android.Content.PM.ScreenOrientation.Portrait; }
/// <summary> /// Allows Updates to the UI controls from the ScanCode class /// </summary> /// <param name="bscanButton"></param> /// <param name="bscanSpinner"></param> /// <param name="strViewText"></param> public void On_Update_Event(bool bscanButton, bool bscanSpinner, bool syConfig, bool bOpenbtn, string strViewText) { ScannerCode.Log("On_Update_Event..."); this.RunOnUiThread(() => { scanButton.Enabled = bscanButton; selectScanner.Enabled = bscanSpinner; symConfig.Enabled = syConfig; openScanner.Checked = bOpenbtn; }); }
private static BarcodeReader GetBarcodeReader(string readerName) { ScannerCode.Log("GetBarcodeReader..."); BarcodeReader reader = null; if (readerName == DEFAULT_READER_KEY) { // This name was added to the Open Reader picker list if the // query for connected barcode readers failed. It is not a // valid reader name. Set the readerName to null to default // to internal scanner. readerName = null; } if (null == readerName) { if (mBarcodeReaders.ContainsKey(DEFAULT_READER_KEY)) { reader = mBarcodeReaders[DEFAULT_READER_KEY]; } } else { if (mBarcodeReaders.ContainsKey(readerName)) { reader = mBarcodeReaders[readerName]; } } if (null == reader) { // Create an instance of BarcodeReader. reader = new BarcodeReader(readerName, AppContext); // Add an event handler to receive barcode data. // Even though we may have multiple reader sessions, we only // have one event handler. In this app, no matter which reader // the data come frome it will update the same UI controls. // Add the BarcodeReader object to mBarcodeReaders collection. if (null == readerName) { mBarcodeReaders.Add(DEFAULT_READER_KEY, reader); } else { mBarcodeReaders.Add(readerName, reader); } } return(reader); }