Android Question Blutooth Barcode Reader, problem with cursor movement

incendio

Well-Known Member
Licensed User
Longtime User
Hi all,

I have app that use bluetooth barcode reader - set as a HID.
On my layout, there are 3 object :
1) txt1 - Edit Text
2) txt2 - Edit Text
3) btn1 - Button

I want to put cursor always on txt2 after do the scan, so this the code in txt2
B4X:
Sub txt2_EnterPressed
   If(txt2.Text = "") Then Return
   txt2.Text = ""
   txt2.RequestFocus
End Sub

When cursor placed in txt2, after the scan, something strange happen with cursor.

If i put this code on Activity_Create
B4X:
FieldOrder.Initialize(Array As Object(txt1,txt2),True)
Cursor jump to txt1.

change code on Activity_Create to
B4X:
FieldOrder.Initialize(Array As Object(txt1,txt2),False)
Cursor disappear, and while cursor not visible, do the scan again, raised clicked event in btn1.

It seem that the barcode sent twice Enter/Tab keys. Can someone help me to fix this?

Thanks in advance.
 

incendio

Well-Known Member
Licensed User
Longtime User
Try to use the HandleAction event from the IME library instead of EnterPressed: https://www.b4x.com/android/forum/t...-keyboard-with-the-ime-library.14832/#content

This will allow you consume the "enter event".
Still not working.

I am using this code on Activity_Create
B4X:
   FieldOrder.Initialize(Array As Object(txt1,txt2),False)
   KYB.Initialize("KYB")
   KYB.AddHandleActionEvent(txt2)

Remove codes on txt2_EnterPressed replaced it with
B4X:
Sub KYB_HandleAction As Boolean
    Dim e As EditText
    Dim Barcode As String
    e = Sender

    Barcode = e.Text

    If(Barcode = "") Then Return False
   
    If(InputNotOk(Barcode)) Then
        MsgBox("Not Valid Input","")
    else
       SaveBarcode(Barcode)
       e.Text = ""
    End If   
   Return True
End Sub

Cursor disappear, do the scan again, clicked event on btn1 raised.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
Yes.

After the scan, cursor dissapper, and without do nothing, do a scan again, has an effect like touching btn1.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
Don't think that timer would be applicable.

This is a bulk scan operation. On a normal situation, barcode reading is very fast, less than 1 sec and users don't looks at a screen after do the scan.

Users scan right away after a beep from a barcode. If user must looks every time at a screen after doing a scan ( to make sure that cursor has focus on text field), it is really slow down the operation.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
I have implemented other solution. Still in testing now, if it is fail will try using timer.

Thanks anyway for your idea.
 
Upvote 0

Jose Cuevas

Member
Licensed User
Longtime User
I have implemented other solution. Still in testing now, if it is fail will try using timer.

Thanks anyway for your idea.

Hi incendio, did you find any solution for this? because I'm having the same problem. I will appreciate any help you can give me.

Thanks in advance.
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Did you try to use it with SPP mode? (BT & AsyncStreams). Benefit is that you have much more control as you receive the scanned data directly. Here you can filter it or can do some other stuff like checks against a database or similar before you show it.
 
Upvote 0

Jose Cuevas

Member
Licensed User
Longtime User
Hi KMatle, thanks for your response. My problem is not with the BT Read, but with the cursor position.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
It was a long time ago, I don't have the barcode reader right now, so I don't know if these codes still work or not.

On Activity Create
B4X:
Sub Activity_Create(FirstTime As Boolean)
    FieldOrder.Initialize(Array As Object(txt1,txt2),True)
End Sub

There is a label on my designer, I put these codes, really don't know & understand why this codes exist :)
B4X:
Sub Label4_Click
    If(Label4.TextColor = -4276546) Then
        Label4.TextColor = Colors.Magenta
    Else
        Label4.TextColor = -4276546
    End If
End Sub

On txt2
B4X:
Sub txt2_EnterPressed
   If(txt2.Text = "") Then Return
End Sub

Sub txt2_FocusChanged (HasFocus As Boolean)
    If(Not(HasFocus)) Then 
        If(Label4.TextColor = Colors.Magenta) Then txt2.RequestFocus    
    End If
End Sub

My guest is, before users use barcode scanner, users must click Label4 to change its colors.
 
Upvote 0

Jose Cuevas

Member
Licensed User
Longtime User
Thank you very much Incendio, there are a couple of things in your code that I have not tried and they can help me.

Regards,
 
Upvote 0
Top