B4A Library ZXingLib by icefairy333 - modified by Johan Schoeman (Scan QR Codes and other 1D/2D Barcodes)

ScannerActive.png


See the attached project (with library files in the /files folder of the project). This is based on the original work of @icefairy333. I have modified @icefairy333's library so that it can do the following:

1. Set the color of the border of the framing rectangle from B4A code
2. Set the color of the laser from B4A code
3. Set the color of the mask around the framing rectangle from B4A code
4. Set the color of the result points from B4A code
5. Set the color of the final panel being displayed before control is being returned to the B4A project from B4A code
6. Ability to switch on/off the torch when making use of the back camera scanner by means of the volume up/down buttons. Use the volume up/down buttons to toggle the torch on/off when the scanner is active.

a. It retains the Portrait /Landscape option as per @icefairy333 's version 1.5 posted in post #1 of his original post.
b. It retains use of the front / back camera (not sure if it supports all types of devices)

See post #5 for changes that might be required to the Manifest of the project.

Edit: Posting JohanIceFairyZxingWidthMod.zip that will allow you to change the width / height of the ViewFinder. New library files are in the /files folder of the attached project. Replace the old lib files with the new ones.

Edit: Posting JohanIceFairyZxingWidthModAndTextMod.zip that will allow you also add text to the mask around the viewfinder of the scanner.

Edit: Posting JohanIceFairyZxingWidthTextBitmap.zip that will allow you to also add a bitmap to the mask around the viewfinder of the scanner.

Edit: Posting JohanIcefairyZxingWidthTextBitmapTouchTorch.zip that retains all previously added functionality but you can now also switch on/off the flash when using the back camera by either using the volume up/down buttons or just touch the screen while the scanner is active.

Edit: attached file src.zip contains the java source code. It can be compiled into a B4A library with Simple Library Compiler (SLC) as is, provided you set up the directory structure correctly and you set up SLC correctly. See elsewhere in this thread how to do it.

Edit: Attached JohanIcefairyZxingTimeout.zip with all the previously added functionality but adding an option to specify a timeout duration. Default timeout duration is 15 seconds (should you not specify any timeout duration). Also posting src_2.zip with the amended java source code

eg of Button1_Click for project in JohanIcefairyZxingTimeout.zip
B4X:
Sub Button1_Click
  zx.isportrait = True
  zx.useFrontCam = False

  'set the timeoutDuration to a very high value (such as 2000000000) if you dont want it to time out
  '2000000000 = 63 years+
  zx.timeoutDuration = 30

  'change these factors between 0 and 1 to change the size of the viewfinder rectangle
  'the library will limit the minimum size to 240 x 240 pixels and the maximum to (screen width) x   (screen height) pixels
  zx.theViewFinderXfactor = 0.7
  zx.theViewFinderYfactor = 0.5

  zx.theFrameColor = Colors.Blue
  zx.theLaserColor = Colors.Yellow
  zx.theMaskColor = Colors.argb(95, 0, 0, 255)
  zx.theResultColor = Colors.Green
  zx.theResultPointColor = Colors.Red

  'set the prompt messages
  zx.theTopPromptMessage = "This was done......"
  zx.theTopPromptTextSize = 5%y'text size in pixels
  zx.topPromptColor = Colors.Red
  zx.topPromptDistanceFromTop = 1%y'pixel distance from top

  zx.theBottomPromptMessage = "Just for fun......"
  zx.theBottomPromptTextSize = 5%y'text size in pixels
  zx.bottomPromptColor = Colors.Blue
  zx.bottomPromptDistanceFromBottom = 5%y'pixel distance from top

  'add a bitmap
  zx.theBitMap = bm
  zx.theBitMapLeft = 40%x
  zx.theBitMapTop = 10%y
  zx.theBitMapWidth = 20%x
  zx.theBitMapHeight = 20%x

  zx.BeginScan("myzx")
End Sub

Enjoy!
 

Attachments

  • JohanIcefairyZxing.zip
    416.8 KB · Views: 1,984
  • JohanIcefairyZxingWidthMod.zip
    417.5 KB · Views: 1,339
  • JohanIcefairyZxingWidthModAndTextMod.zip
    418.4 KB · Views: 1,271
  • JohanIcefairyZxingWidthTextBitmap.zip
    421 KB · Views: 1,206
  • JohanIcefairyZxingWidthTextBitmapTouchTorch.zip
    421.5 KB · Views: 1,320
  • JohanIcefairyZxingTimeout.zip
    421.5 KB · Views: 1,355
  • b4aZXINGusingVer1.05.zip
    12.2 KB · Views: 1,063
  • JhsIceZxing1Ver1.05.zip
    444.1 KB · Views: 1,100
  • JhsIceZxing1Ver1.06.zip
    444.1 KB · Views: 1,711
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
Mm, one of the old versions had a cancel event generated when the back button was pressed. Sure I can do it in resume.

Other questions, do you have the settings you use when compiling with SLC? Cannot get the correct result when creating the folder structure.
Cancel and timeout will both return a "null" in Sub myzx_noscan - in both cases nothing was found. But we can add to the code in order to raise a separate event when the back button is pressed.
 

Johan Schoeman

Expert
Licensed User
Longtime User
OK - set up your project as follows (for eg):
Create a directory structure on your c: or d: or whatever drive that looks as follows:

BlueDudeZxingLib
src
......all the files and directories in the src folder​

Then copy all the files and directories as is into the src folder (else just drop the complete src folder - once unzipped - into the BlueDudeZxingLib folder without making an additional src folder.

Then start Simple Library Compiler (SLC)

1. In the first line of SLC you browse to the BlueDudeZxingLib folder
2. In the second line you put the name of whatever you want the library to be (this is the name that will appear in you B4A project library list). Put in for eg BlueDudeZxingLib if that is the name that you want it to be
3. In the -b4aignore field you enter com

Click on compile and then sit back and relax for a few seconds. The jar and xml will be added to you additional library folder.

No pics required - it is as simple as this. Give it a try and let me know

See pics attached
 

Attachments

  • BlueDude1.jpg
    BlueDude1.jpg
    135.6 KB · Views: 413
  • BlueDude2.jpg
    BlueDude2.jpg
    82.7 KB · Views: 390
  • BlueDude3.jpg
    BlueDude3.jpg
    81.5 KB · Views: 388
  • BlueDude4.jpg
    BlueDude4.jpg
    73.1 KB · Views: 384

Johan Schoeman

Expert
Licensed User
Longtime User
The attached project keeps all previously added functionality but adds the option of beep and vibrate upon a successful scan. New lib files are in the /files folder of the attached project. Also posting the updated java source files (complete src folder)

B4X:
zx.mustBeep = True
zx.mustVibrate = True

Also note that:
B4X:
zx.theBitMapLeft = 40%x
zx.theBitMapTop = 10%y
zx.theBitMapWidth = 20%x
zx.theBitMapHeight = 20%x

are now replaced by:
B4X:
zx.theBitmapPosition(40%x, 10%y, 20%x, 20%x)
 

Attachments

  • src_3.zip
    470.3 KB · Views: 418
  • JohanIcefairyZxingBeepVibrate.zip
    423.4 KB · Views: 450
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
Aztec.png


This update adds back the ability to scan Aztec codes too (see attached pic) - it was missing from the original Icefaire333 java source code.

Just posting the zipped library files (jar and xml). Use them with the project posted in post #24 above (i.e replace your current jar and xml files with this in case you have down loaded the project(s). Also posting src_4.zip - the updated java source code. It will compile as is with SLC.
 

Attachments

  • src_4.zip
    470.5 KB · Views: 412
  • JhsIceZxing1.zip
    412.9 KB · Views: 398
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
PDF417.png


This update adds back the ability to also scan PDF417 codes (see attached pic) - it was also missing from the original Icefaire333 java source code. I am of the opinion that there is an error in the original Zxing code (core library) as far as the decoding of PDF417 codes are concerned. It sometimes generates a NPE error and for the same PDF417 code NeoReader returns a "?" - basically an invalid code but this version of the Zxing core library does not seem to handle an invalid PDF417 code correctly. It nevertheless scans valid codes perfectly. This error to be investigated and corrected so that the scanner does not "hang" due to the NPE error.

Just posting the zipped library files (jar and xml). Use them with the project posted in post #24 above (i.e replace your current jar and xml files with this in case you have down loaded the project(s)). Also posting src_5.zip - the updated java source code. It will compile as is with SLC.
 

Attachments

  • src_5.zip
    470.6 KB · Views: 354
  • JhsIceZxing1.zip
    413 KB · Views: 382
Last edited:

bluedude

Well-Known Member
Licensed User
Longtime User
In the latest version the bottom text is suddenly Italic :) I can probably fix and compile myself but just informing.
 

Johan Schoeman

Expert
Licensed User
Longtime User
In the latest version the bottom text is suddenly Italic :) I can probably fix and compile myself but just informing.
Yes, that is correct. Was playing around with the text. Look in the view folder for ViewFinderView.java and see where I have made the changes for italic. Just comment it out and text will revert back to normal.
 
Last edited:

chaiwatt

Member
Licensed User
Longtime User
I'm not sure is method 'zx.isportrait = False' work. It immediately display on portrait layout once scan executed. Although I set Module Attributes to '#SupportedOrientations: landscape'. Regarding help to check, Thanks.
 

Johan Schoeman

Expert
Licensed User
Longtime User
This update fixes the "hanging" issue (NPE error) experienced with scanning of some PDF417 codes (see issue reported on in post #26 above). Have tested it by scanning various PDF417 codes that used to generate the NPE error. It was an error in the older version of the PDF417 java code. I have replaced the java class that generated the error with the latest version of that class that is posted on GitHub. Posting the updated zipped library files (jar and xml) and the updated zipped src folder. Replace your library files or recompile the attached src folder to generate the same library files.
 

Attachments

  • src_6.zip
    470.6 KB · Views: 328
  • JhsIceZxing1.zip
    418 KB · Views: 355

TheMightySwe

Active Member
Licensed User
Longtime User
Hi,

a question. It seems that the 'zx.isportrait = False' is a bit strange, the camera output seems to be 90 degrees fault, but the text shows OK.

The picture is also distorted like it's a portrait picture in landscape with Gravity.FILL
 

Johan Schoeman

Expert
Licensed User
Longtime User
This update returns a bitmap image of the scanned barcode to the B4A project. You can add the necessary code in the B4A project to save it or manipulate it or whatever else it is that you want to do with the bitmap image. All previously added functionality that was added to the library is maintained. Posting the updated B4A project, the zipped jar and xml files (jar and xml are also in the /files folder of the attached project), and the zipped src folder (the java code).
 

Attachments

  • src_7.zip
    470.8 KB · Views: 374
  • JohanIcefairyZxingReturnImage.zip
    424.3 KB · Views: 358
  • JhsIceZxing1.zip
    413.4 KB · Views: 362

Johan Schoeman

Expert
Licensed User
Longtime User
Hi,

a question. It seems that the 'zx.isportrait = False' is a bit strange, the camera output seems to be 90 degrees fault, but the text shows OK.

The picture is also distorted like it's a portrait picture in landscape with Gravity.FILL
I am aware of it - it is how the original code of this specific library seems to have been created. I have only added some additional functionality/appearances to it. Will look into it at some stage and see if it can be resolved. Best to use it in portrait mode for now. I am posting the updated source code as I go along - so, if someone wants to look into this issue they are more than welcome. Please just post the amended source code if someone manages to fix it so that the source code can be available for all B4A members that want to make use of it.
 
Last edited:

TheMightySwe

Active Member
Licensed User
Longtime User
I am aware of it - it is how the original code of this specific library seems to have been created. I have only added some additional functionality/appearances to it. Will look into it at some stage and see if it can be resolved. Best to use it in portrait mode for now. I am posting the updated source code as I go along - so, if someone wants to look into this issue they are more than welcome. Please just post the amended source code if someone manages to fix it so that the source code can be available for all B4A members that want to make use of it.


I found some code online, you can check it out if you want.

http://www.wenda.io/questions/3311875/zxing-camera-portrait-mode-and-landscape-on-android.html
 

Johan Schoeman

Expert
Licensed User
Longtime User
Will look into it. The code in the (base) java source files that I am working from is very different to the standard Zxing files. It has been adapted to suite a specific purpose. On first view the code in your link can't just be copied in. (Base) code needs some serious "surgery" to accommodate it. There might be an easier approach to this rather than trying to do a heart transplant.
 

TheMightySwe

Active Member
Licensed User
Longtime User
Have you any idea why I don't come back to my project when Scanning a QR-Code? The ZXing-screen gets green and then I don't come back to the program.
 

Johan Schoeman

Expert
Licensed User
Longtime User
Have you any idea why I don't come back to my project when Scanning a QR-Code? The ZXing-screen gets green and then I don't come back to the program.
No, have not experienced it. What does the project in post #32 do when you run it on your device? Does it behave the same or does it return back to the B4A project?
 

TheMightySwe

Active Member
Licensed User
Longtime User
No, have not experienced it. What does the project in post #32 do when you run it on your device? Does it behave the same or does it return back to the B4A project?

I used the lib in #32, same. problem. I'll look in to it deeper this afternoon.
 

bluedude

Well-Known Member
Licensed User
Longtime User
If mustBeep and mustVibrate are set to false there are no results returned, must be a bug.
 
Top