B4A Library QRCodeReaderView - new release

Discussion in 'Additional libraries, classes and official updates' started by Johan Schoeman, Jul 30, 2017.

  1. Johan Schoeman

    Johan Schoeman Expert Licensed User

    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:
    Code:
    #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
     

    Attached Files:

    Last edited: Jul 30, 2017
    lualfito, asales, fabricio and 15 others like this.
  2. fishwolf

    fishwolf Active Member Licensed User

    is it possibile change the 4 red point with the classic square angle?
     
  3. fishwolf

    fishwolf Active Member Licensed User

    If i ONLY include the AppCompat library 3.53 into the example, i have this compile error from B4A 7.01
    Code:
    B4A version: 7.01
    Parsing code.    (
    0.00s)
    Compiling code.    (
    0.37s)
    Compiling layouts code.    (
    0.00s)
    Organizing libraries.    (
    7.11s)
    Generating R 
    file.    (5.11s)
    Compiling debugger engine code.    (
    3.73s)
    Compiling generated Java code.    (
    3.82s)
    Convert byte code - optimized dex.    Error
    Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/AnimRes;
    Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/AnimatorRes;
    Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/AnyRes;
    Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/ArrayRes;
    Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/AttrRes;
    Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/BinderThread;
    Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/BoolRes;
    Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/CallSuper;
    Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/CheckResult;
    UNEXPECTED TOP-LEVEL 
    EXCEPTION:
    java.lang.RuntimeException: Translation has been interrupted
        at com.android.dx.command.dexer.Main.processAllFiles(Main.java:
    689)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:
    313)
        at com.android.dx.command.dexer.Main.run(Main.java:
    279)
        at com.android.dx.command.dexer.Main.main(Main.java:
    247)
        at com.android.dx.command.Main.main(Main.java:
    106)
    Caused by: java.lang.InterruptedException: Too many errors
        at com.android.dx.command.dexer.Main.processAllFiles(Main.java:
    681)
        ... 
    4 more
     
  4. Johan Schoeman

    Johan Schoeman Expert Licensed User

    Use the attached library files when you have the AppCompat library enabled
     

    Attached Files:

  5. Sandman

    Sandman Well-Known Member Licensed User

    Hi @Johan Schoeman , sorry to revisit such an old thread, but I just realized this is a newer version than the one I'm using for my project. Have you got a changelog somewhere? Or perhaps simpler: I have not seen any problems at all with version 1.0.0, nor am I missing any wanted features. Would you still recommend me to update to 1.0.1?
     
  6. Johan Schoeman

    Johan Schoeman Expert Licensed User

    If it is working for you then no need to change it.
     
  7. Keith Yong

    Keith Yong Active Member Licensed User

    Hi Johan Schoeman , I'm new to B4A.

    i downloaded the sample files given above, i manage to run and work perfectly. But when i create another program and follow exactly the same (code, layout, manifest), it doesn't work at all. At first, it doesn't allow to install if "targetSdkVersion=19". After that i change it to targetSdkVersion = 26 and it can install but it given error "java.lang.RuntimeException: Fail to connect to camera service"

    May i know anything that i miss out?
     

    Attached Files:

    Last edited: Jun 2, 2018
  8. Johan Schoeman

    Johan Schoeman Expert Licensed User

    1. Change your B4A code to the below code
    2. You will need to enable the RuntimePermission Library in the libs tab of the IDE when using target SDK = 26

    Code:
    #Region  Project Attributes
        
    #ApplicationLabel: Golfapp
        
    #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
        
    Dim rp As RuntimePermissions

    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
        
        
    Dim Result As Boolean = True
        
    If Not(rp.Check(rp.PERMISSION_CAMERA)) Then
            rp.CheckAndRequest(rp.PERMISSION_CAMERA)
            
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
        
    End If
        
        
    If Result Then
            nqrcrv.Visible = 
    True
            nqrcrv.setBackCamera
            nqrcrv.startCamera
        
    End If   
        
    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
     
  9. Keith Yong

    Keith Yong Active Member Licensed User

    Thanks, it works perfectly. :):)
     
    Johan Schoeman likes this.
  10. Dey

    Dey Active Member Licensed User

    Hello
    I'm trying your library in an android tablet 5.1
    I get this result

    Code:
    Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
        at libcore.io.Posix.open(Native Method)
        at libcore.io.BlockGuardOs.open(BlockGuardOs.java:
    186)
        at libcore.io.IoBridge.open(IoBridge.java:
    442)
        ... 
    16 more
    Copying updated assets files (
    1)
    java.lang.RuntimeException: Unable 
    to create service JHS.NewQRCodeReaderView.starter: java.lang.RuntimeException: java.io.FileNotFoundException: /storage/emulated/0/Android/data/JHS.NewQRCodeReaderView/files/virtual_assets/main.bal: open failed: ENOENT (No such file or directory)
        at android.app.ActivityThread.handleCreateService(ActivityThread.java:
    2771)
        at android.app.ActivityThread.access$
    1800(ActivityThread.java:151)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:
    1386)
        at android.os.Handler.dispatchMessage(Handler.java:
    102)
        at android.os.Looper.loop(Looper.java:
    135)
        at android.app.ActivityThread.main(ActivityThread.java:
    5254)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:
    372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:
    903)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:
    698)
    Caused by: java.lang.RuntimeException: java.io.FileNotFoundException: /storage/emulated/
    0/Android/data/JHS.NewQRCodeReaderView/files/virtual_assets/main.bal: open failed: ENOENT (No such file or directory)
        at anywheresoftware.b4a.shell.Shell.virtualAssets(
    Shell.java:169)
        at anywheresoftware.b4a.shell.Shell.start(
    Shell.java:102)
        at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:
    92)
        at JHS.NewQRCodeReaderView.starter.onCreate(starter.java:
    34)
        at android.app.ActivityThread.handleCreateService(ActivityThread.java:
    2761)
        ... 
    9 more
    Caused by: java.io.FileNotFoundException: /storage/emulated/
    0/Android/data/JHS.NewQRCodeReaderView/files/virtual_assets/main.bal: open failed: ENOENT (No such file or directory)
        at libcore.io.IoBridge.open(IoBridge.java:
    456)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:
    87)
        at anywheresoftware.b4a.objects.streams.File.OpenOutput(
    File.java:448)
        at anywheresoftware.b4a.shell.Shell.virtualAssets(
    Shell.java:156)
        ... 
    13 more
    Caused by: android.system.ErrnoException: open failed: ENOENT (No such 
    file or directory)
        at libcore.io.Posix.open(Native Method)
        at libcore.io.BlockGuardOs.open(BlockGuardOs.java:
    186)
        at libcore.io.IoBridge.open(IoBridge.java:
    442)
        ... 
    16 more
    Thanks for your help
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice