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,706
  • JohanIcefairyZxingWidthMod.zip
    417.5 KB · Views: 1,142
  • JohanIcefairyZxingWidthModAndTextMod.zip
    418.4 KB · Views: 1,078
  • JohanIcefairyZxingWidthTextBitmap.zip
    421 KB · Views: 1,018
  • JohanIcefairyZxingWidthTextBitmapTouchTorch.zip
    421.5 KB · Views: 1,121
  • JohanIcefairyZxingTimeout.zip
    421.5 KB · Views: 1,144
  • b4aZXINGusingVer1.05.zip
    12.2 KB · Views: 867
  • JhsIceZxing1Ver1.05.zip
    444.1 KB · Views: 883
  • JhsIceZxing1Ver1.06.zip
    444.1 KB · Views: 1,471
Last edited:

bluedude

Well-Known Member
Licensed User
Longtime User
Interesting. Now add:

- cancel reader event
- image/logo above rectangle.

...and it would be great!

On which version of the ZXing library is this based?
 

Johan Schoeman

Expert
Licensed User
Longtime User
Interesting. Now add:

- cancel reader event
- image/logo above rectangle.

...and it would be great!

On which version of the ZXing library is this based?
The base that I am working from is the source code posted by @icefairy333 in post #1 of his original thread. Reverse engineered his V1.5 to add back the landscape / portrait and front / back cameras and then added code for the colors and the torch when using the back camera. Will look into your remaks above and see if I can amend code to accommodate such.
 

Reids

Member
Licensed User
Longtime User
Hello Johan, I will write your name in my last exam project as a credits, this really great!! than previous torch update, but black screen issue still occured on my samsung galaxy S III (I'm using cyanogenmod), black screen will appear when app tried to capture the qr code, then I cancel it, open an cancel then black screen, phone must be restarted to get rid of this problem, maybe need to call camera_close() somewhat? it appear camera still in use

Oh 1 More request. can you display result in bottom of capture screen? so I can capture qr code as batch capture, repositioning rectangle capture also great :)

Thank You Very Much!
you and icefairy have great contribution on my final project
Best Regard from Bali!
 

Johan Schoeman

Expert
Licensed User
Longtime User
I know the below code has a whole lot of additional /unnecessary lines of code in it, but if the attached above project does not work then replace the manifest with the code below. It sorted out a problem that someone else experienced.

B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: http://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="17"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
AddManifestText(<uses-feature android:name="android.hardware.telephony" android:required="false" />)
AddManifestText(<uses-feature android:name="android.hardware.camera" android:required="false" />)
AddManifestText(<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />)
AddManifestText(<uses-feature android:name="android.hardware.camera.flash" android:required="false" />)
'AddPermission("android.permission.ACCESS_COARSE_LOCATION")
AddPermission("android.permission.INTERNET")
AddPermission("android.permission.ACCESS_FINE_LOCATION")
AddPermission("android.permission.WAKE_LOCK")
AddPermission("android.permission.DEVICE_POWER")
'AddPermission("android.permission.ACCESS_COARSE_UPDATES")
AddPermission("android.permission.READ_PHONE_STATE")
AddPermission("android.permission.VIBRATE")
AddPermission("android.permission.CAMERA")
AddPermission("android.permission.FLASHLIGHT")
AddPermission("android.hardware.camera")
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
AddApplicationText(<activity android:name="ice.zxing.CaptureActivity"
            android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
            android:windowSoftInputMode="stateAlwaysHidden">
        </activity>)
 

incendio

Well-Known Member
Licensed User
Longtime User
Hello,

Thanks for the library.

Is it possible to change rectangle capture size?
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hello,

Thanks for the library.

Is it possible to change rectangle capture size?
See update in post #1 that will allow you to change the width / height of the View Finder
 

Johan Schoeman

Expert
Licensed User
Longtime User
See post #1. Added an update (JohanIcefairyZxingWidthModAndTextMod.zip) so that one can
add a prompt message at the top
add a prompt message at the bottom
Specify the color of the text (separately for top and bottom)
Specify the text size (separately for top and bottom)
Specify the position of the top and bottom message relative to the top and the bottom.

This update incorporates all previous updates of this project. New library files are in the /files folder of the project.
 
Last edited:

bluedude

Well-Known Member
Licensed User
Longtime User
Great stuff, you think you could add a cancel event? If not, I need to change some of my code.
 

Johan Schoeman

Expert
Licensed User
Longtime User
Great stuff, you think you could add a cancel event? If not, I need to change some of my code.
Busy adding the bitmap. Will post it in a few minutes. Won't get to cancel event today - project for another day.
 
Last edited:

Reids

Member
Licensed User
Longtime User
Still waiting result displayed at capture screen, after capture complete it don't back to layout but still at capture screen ready for next record
 

Johan Schoeman

Expert
Licensed User
Longtime User
Still waiting result displayed at capture screen, after capture complete it don't back to layout but still at capture screen ready for next record
It is something for future development Edwin.
 

Johan Schoeman

Expert
Licensed User
Longtime User
The attached zipped file contains new library files for the project (jar and xml). It was created on request of one of the members (JTM). It allows you to switch the flash/torch on/off (when making use of the rear camera) by touching the screen. It retains the on/off capability of the flash/torch by making use of the volume up/down button. The two options are working in conjunction with one another (i.e you can switch on by touching the screen and switch off with the volume down button and vice versa). Or switch on/off by touching the screen only or by making use of the volume up/down buttons only.

Replace the lib files with this. The new files retain all previously added capabilities.

Enjoy!
 

Attachments

  • JhsIceZxing1.zip
    410.9 KB · Views: 828

Johan Schoeman

Expert
Licensed User
Longtime User
Interesting. Now add:

- cancel reader event - done
- image/logo above rectangle. - done
See new complete project posted in Post #1. It will timeout if not being able to do a valid scan within 15 seconds from starting the scanner. And raise an event.
 
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
I think it is only fair that I post the amended source code for the library of the projects that I have posted in post #1 of this thread. I have after all inherited the original source code from @icefairy333 in post #1 of his original thread that you can find here. It was a great leaning experience going through this exercise to add additional functionality to his ZXing library. Thank you @icefairy333 for making it available thereby allowing me the opportunity to gain some valuable experience and knowledge. So, I leave this for the B4A community and especially for those that want to add further functionality to the library (although I will be playing around with it a bit more when time permits - holiday has unfortunately now come to an end). I hope that the library as it stands at present is of some value to some of the B4A members.

For what it might be worth (for newbies like me that want to play around with Java and libraries), I have done all the additions and amendments in Notepad (Windows 2007) and compiled the library with @Erel 's Simple Library Compiler. And it was (for me personally) much easier this way than trying to get my head around Eclipse. You only need to set up a very simple directory structure to compile the source code. The whole lot is in the attached src zipped folder and will compile as is into a library that can be used in B4A projects (jar and xml will be generated). The same library as what I have used in the last project that I have posted in post #1. And I mean, the exact same thing. Will gladly assist anyone (newbies to Java such as me) that want to go through the compiling process with SLC.

Thank you @Erel for the entertainment that you provide us with - it makes holidays being far to short!

The java source code of this project is in post #1 of this thread (src.zip)

Edit: see posts #20 and #22 of this thread for how to compile the library.
 
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
Hi, i tried to find the cancel event but couldn't find the name.
Misunderstood you. Thought you were looking for cancel event meaning a timeout. Using the "back" button of your device will in any case return back to B4A project and raise an event in B4A. Do you want to do the cancel from a button on the mask while the scanner is active?
 

bluedude

Well-Known Member
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.
 

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.
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
 
Last edited:
Top