Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First call to set text on scanner overlay textview fails #1057

Open
chartierpw opened this issue Sep 22, 2022 · 0 comments
Open

First call to set text on scanner overlay textview fails #1057

chartierpw opened this issue Sep 22, 2022 · 0 comments

Comments

@chartierpw
Copy link

chartierpw commented Sep 22, 2022

I have the following scanner custom overlay:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:minWidth="25px" android:minHeight="25px" android:background="@android:color/transparent"> <LinearLayout android:orientation="horizontal" android:minWidth="25px" android:minHeight="25px" android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/linearLayout1" android:layout_weight="0.3"> <TextView android:text="Place a barcode in the camera viewfinder to scan it. Barcode will scan Automatically." android:layout_width="wrap_content" android:layout_height="fill_parent" android:id="@+id/textView1" android:gravity="center" android:layout_weight="0" android:layout_marginRight="20dp" android:textSize="12sp" android:layout_marginLeft="5dp" android:background="@android:color/transparent" android:textColor="#ffffffff" /> </LinearLayout> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/textView2" android:layout_weight="0.5" /> <LinearLayout android:orientation="vertical" android:minWidth="25px" android:minHeight="25px" android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/linearLayout2" android:layout_weight="0.2" android:layout_gravity="center"> <TextView android:text="Try to avoid shadows and glare. Hold the device back about 6 inches from the barcode." android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/textView3" android:layout_marginLeft="30dp" android:layout_marginRight="30dp" android:layout_gravity="center" android:textColor="#ffffffff" android:textSize="12sp" android:layout_weight="1" android:gravity="center" /> <TextView android:id="@+id/ticketInfo" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="24dp" android:maxLines="5" android:lines="5" android:singleLine="false" android:background="@color/colorWhite" android:textColor="@android:color/black"/> <Button android:text="@string/okButton" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/colorWhite" android:textColor="@android:color/black" android:id="@+id/okButton" /> </LinearLayout> </LinearLayout>
This is the code that starts the scan:

` MyButton_Scan.Click += async (sender, e) =>
{
var selectedEvent = string.Format("{0}", MyEventsSpinner.GetItemAtPosition(MyEventsSpinner.SelectedItemPosition));
if (selectedEvent.ToUpper() != "SELECT EVENT")
{
// Moved this here from mainActivity.cs in the off chance initialization was an issue
MobileBarcodeScanner.Initialize(Application);

                scanner = new MobileBarcodeScanner();

                scanner.UseCustomOverlay = true;

                zxingOverlay = LayoutInflater.FromContext(this).Inflate(Resource.Layout.scanner, null);
                MyTextView = zxingOverlay.FindViewById<TextView>(Resource.Id.ticketInfo);
                MyTextView.Text = "";
                MyScanScreenButton = zxingOverlay.FindViewById<Android.Widget.Button>(Resource.Id.okButton);
                MyScanScreenButton.Text = "Clear";
                MyScanScreenButton.Click += btnOk_Click;
                scanner.CustomOverlay = zxingOverlay;

                var opt = new MobileBarcodeScanningOptions();
                opt.DelayBetweenContinuousScans = 5000;
                
                //Start scanning
                scanner.ScanContinuously(this, opt, HandleScanResult);
            } else
            {
                Utils.showMessage("Please select an event from the drop down list");
            }
        };

`

This is the code that handles the scan result:

` void HandleScanResult(ZXing.Result result)
{
if (!popUpOpen)
{
Boolean ConversionGood = true;
Int32 convertedResult = 0;
Stream successbeepStream = GetType().Assembly.GetManifestResourceStream("eTicket_Scanner.beep.wav");
Stream failbeepStream = GetType().Assembly.GetManifestResourceStream("eTicket_Scanner.buzzer.wav");
try
{
convertedResult = Convert.ToInt32(result.Text);
}
catch (Exception ex)
{
ConversionGood = false;
bool isSuccess = _simpleAudioPlayer.Load(failbeepStream);
_simpleAudioPlayer.Play();
popUpOpen = true;
MyTextView.Text = "Not a valid ticket for this event.\nErrorif applicable): " + ex.Message;
MyTextView.SetBackgroundColor(Color.Red);
}
string scanResult = "";
if (ConversionGood)
{
scanResult = MyEventsService.VerifyScannedCode(MyUser.Username, MyUser.Password, currentEventID, convertedResult);

                    if (scanResult == "Y")
                    {
                        bool isSuccess = _simpleAudioPlayer.Load(successbeepStream);
                        popUpOpen = true;
                        _simpleAudioPlayer.Play();
                        MyTextView.SetBackgroundColor(Color.Green);
                        MyTextView.Text = MyEventsService.GetTicketInfo(MyUser.Username, MyUser.Password, currentEventID, convertedResult);
                        //MyScanScreenButton.Visibility = Android.Views.ViewStates.Visible;
                    }
                    else
                    {
                        bool isSuccess = _simpleAudioPlayer.Load(failbeepStream);
                        popUpOpen = true;
                        _simpleAudioPlayer.Play();
                        string MyMessage = "";
                        MyMessage = MyEventsService.GetFailedScanTicketInfo(MyUser.Username, MyUser.Password, currentEventID, convertedResult);
                        MyTextView.Text = MyMessage;
                        MyTextView.Text = MyTextView.Text + "\nPress Clear to scan another ticket.";
                        MyTextView.SetBackgroundColor(Color.Red);
                    }
                }
            } 
        }

`
Everytime I try to set the MyTextView text, it fails the first time to display anything, every subsequent run succeeds. I try to debug the issue and when I hit the line MyTextView.Text = MyMessage;, the dubugger stops and the program continues running, the second time through the text gets set and the debugger functions as expected. Something is going on with the scanner control. I've been focusing on the else section of the if (scanResult == "Y") and coded it so I could see what the web service was returning and the setting of the text. Again, it ALWAYS fails to set and display anything the first time I try to set it and then every subsequent attempt is successful. Any ideas? Or is this a bug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant