B4A Library QRCodeReaderView - new release

It is a wrap for this Github project. It is 100% embedded in B4A. I have wrapped and posted this project before somewhere else in this forum (here) but this is the latest update of this project that seems to have some major changes. Please note the checkbox setting - it controls a Boolean variable that will determine if the scanned result will be returned to the B4A project or not.

The new Github project has two views - the one is supposed to overlay the other in order to display/highlight the result points. As I was not sure how to wrap the two views so that the one could overlay the other, I have changed the code in the original Github project in order to incorporate the one view within the other view.

It only shows the 3 or 4 most outlaying result points (based on the version of the QR code)

Posting the following:
1. B4A library files
2. B4A sample project

Note that it only scans QR Codes.

Sample code:
B4X:
#Region  Project Attributes
    #ApplicationLabel: b4NewQRCodeReaderView
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
#End Region


#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim nativeMe As JavaObject

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private nqrcrv As NewQRCodeReaderView
    Private Button1 As Button
    Private torchOn As Boolean = False
  
    Private Button2 As Button
    Private Button3 As Button
  
    Private prevscan As String  = ""
    Private Label1 As Label
    Private CheckBox1 As CheckBox
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("main")
    nativeMe.InitializeContext
  
    nqrcrv.QRDecodingEnabled = True
    nqrcrv.AutofocusInterval = 500
    nqrcrv.ScanNow = False
    nqrcrv.Visible = False
    nqrcrv.ResultPointColor = Colors.Red
    CheckBox1.Checked = False
  

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
  
    torchOn = False
    CheckBox1.Checked = False
    nqrcrv.stopCamera
    prevscan = ""

End Sub


Sub nqrcrv_result_found(retval As String)
  
    If prevscan = retval Then
       'Log("same scan")
       prevscan = retval
    Else
       Log("b4aResult = " & retval)
        prevscan = retval
        nativeMe.RunMethod("playTone", Null)
    End If 
  
End Sub

Sub Button1_Click
    If nqrcrv.Visible = True Then
        If torchOn = False Then
            nqrcrv.TorchEnabled = True
            torchOn = True
        Else
            nqrcrv.TorchEnabled = False
            torchOn = False
          
        End If  
    End If
  
End Sub

Sub Button2_Click
  
    nqrcrv.Visible = True
    nqrcrv.setBackCamera
    nqrcrv.startCamera
  
End Sub

Sub Button3_Click
  
    nqrcrv.Visible = False
    CheckBox1.Checked = False
    nqrcrv.stopCamera
    prevscan = ""
  
End Sub

Sub CheckBox1_CheckedChange(Checked As Boolean)
  
    If Checked = True Then
        nqrcrv.ScanNow = True
    Else
        nqrcrv.ScanNow = False
    End If
  
End Sub


#if Java

import android.media.ToneGenerator;
import android.media.AudioManager;

  public void playTone() {
      final ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100);
      tg.startTone(ToneGenerator.TONE_PROP_BEEP);
  }    

#End If

Library:
NewQRCodeReaderView
Author:
Github: David Lazaro, Wrapped by: Johan Schoeman
Version: 1.01
  • NewQRCodeReaderView
    Events:
    • result_found (retval As String)
    Fields:
    • ba As BA
    Methods:
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • Initialize (EventName As String)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
    • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    • forceAutoFocus
      Trigger an auto focus
    • setBackCamera
      Camera preview from device back camera
    • setFrontCamera
      Camera preview from device front camera
    • startCamera
      Starts camera preview and decoding
    • stopCamera
      Stop camera preview and decoding
    Permissions:
    • android.hardware.camera
    • android.hardware.camera.autofocus
    • android.permission.CAMERA
    Properties:
    • AutofocusInterval As Long [write only]
      Set Camera autofocus interval value
      default value is 5000 ms.
    • Background As Drawable
    • Color As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • Left As Int
    • Padding()() As Int
    • Parent As Object [read only]
    • PreviewCameraId As Int [write only]
      Allows user to specify the camera ID, rather than determine
      it automatically based on available cameras and their orientation.
    • QRDecodingEnabled As Boolean [write only]
    • ResultPointColor As Int [write only]
    • ScanNow As Boolean [write only]
    • Tag As Object
    • Top As Int
    • TorchEnabled As Boolean [write only]
      Set Torch enabled/disabled.
      default value is false
    • Visible As Boolean
    • Width As Int

1.png
 

Attachments

  • b4aNewQRCodeReaderView.zip
    9.1 KB · Views: 1,574
  • b4aLibraryFiles.zip
    488.3 KB · Views: 1,793
Last edited:

Justmer Rivera

New Member
the new Lib. Release seems to have a problem when AutofocusInterval is set to something, the scanning is also affected relative to the ms value,

like for example, I put AutofocusInterval = 6000, then scanning qr code takes about that much time as well, is this an intended behavior?

Running it on Android 6.0
 
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
the new Lib. Release seems to have a problem when AutofocusInterval is set to something, the scanning is also affected relative to the ms value,

like for example, I put AutofocusInterval = 6000, then scanning qr code takes about that much time as well, is this an intended behavior?

Running it on Android 6.0
It is such an old lib. I suggest you use @Erel mobile vision scanner.
 

biometrics

Active Member
Licensed User
Longtime User
It is such an old lib. I suggest you use @Erel mobile vision scanner.
Hi Johan,

Would you please link to @erel’s thread for the mobile vision scanner.

edit: this one?

 
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
Hi Johan,

Would you please link to @erel’s thread for the mobile vision scanner.

edit: this one?

Yes
 

Pawan_91

Member
Torchenabled is not working.
Does it require any other permissions to turn on the flash while scanning.
Has anyone tried setting Torchenabled to True and confirm if flashlight works along with scanner?
 

Johan Schoeman

Expert
Licensed User
Longtime User
Torchenabled is not working.
Does it require any other permissions to turn on the flash while scanning.
Has anyone tried setting Torchenabled to True and confirm if flashlight works along with scanner?
I am using B4A V13.0 on an Android 13 device with target SDK set to 34 and the flash/torch is working. Attached the B4A sample project and the library files. Copy the library files to your B4A additional library folder.

What device are you using and what Android version do you have on your device?

Note that the torch/flash will only work once the scanner is active.
 

Attachments

  • NewQRCodeReaderViewLibFiles.zip
    26.4 KB · Views: 33
  • b4aNewQRCodeReaderView.zip
    10.6 KB · Views: 22
Last edited:

Pawan_91

Member
I am using B4A V13.0 on an Android 13 device with target SDK set to 34 and the flash/torch is working. Attached the B4A sample project and the library files. Copy the library files to your B4A additional library folder.

What device are you using and what Android version do you have on your device?

Note that the torch/flash will only work once the scanner is active.
Thanks a lot Johan it is working now :)
After referring your code I found I was missing the below manifest entries : -

XML:
AddManifestText(<uses-feature android:name="android.hardware.camera" android:required="true" />)
AddManifestText(<uses-feature android:name="android.hardware.camera.autofocus" android:required="true" />)
AddManifestText(<uses-feature android:name="android.hardware.camera.flash" android:required="true" />)
 

Johan Schoeman

Expert
Licensed User
Longtime User
Torchenabled is not working.
Does it require any other permissions to turn on the flash while scanning.
Has anyone tried setting Torchenabled to True and confirm if flashlight works along with scanner?
So, I guess you got it working.
 
Top