This is what I have done to be able to control the width/height of the scanning window in Nelson's project posted at http://www.b4x.com/android/forum/th...ode-ean-13-ean-8-generator.37447/#post-220973
1. I have set up a project in a folder named FirstLibrary and created sub folders "libs" and "src" to it. I then added files to these folders. The final layout looked like this:
FirstLibrary
libs
zxingscanner.jar
core-zxing.jar
srczxingscanner.jar
core-zxing.jar
com
inforpires
barcodescanner
barcodescanner.java
The zxingscanner.jar comes from the libs.zip in Nelson posting at http://www.b4x.com/android/forum/th...ode-ean-13-ean-8-generator.37447/#post-220973. The core-zxing.jar file was downloaded from the web.inforpires
barcodescanner
barcodescanner.java
barcodescanner.java was generated from Nelson's code posted at http://www.b4x.com/android/forum/th...ode-ean-13-ean-8-generator.37447/#post-220973.
Nelson's original code:
B4X:
/*
Based on the original work of IceFairy333
*/
package com.inforpires.barcodescanner;
import android.content.Intent;
import android.util.Log;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.Events;
import anywheresoftware.b4a.BA.Hide;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import anywheresoftware.b4a.IOnActivityResult;
import anywheresoftware.b4a.BA.DependsOn;
import com.google.zxing.client.android.*;
@ShortName("Zxing_scanner")
@Version(1.0F)
@Author("Nelson Pires")
@Events(values={"result(atype as String,Values as String)","noScan"})
@ActivityObject
@Permissions(values={"android.permission.CAMERA","android.permission.WRITE_EXTERNAL_STORAGE","android.hardware.camera","android.hardware.camera.autofocus","android.permission.VIBRATE","android.permission.FLASHLIGHT"})
@DependsOn(values={"core-zxing","zxingscanner"})
public class barcodescanner {
@Hide
public static BA myba;
private IOnActivityResult ion;
@Hide
public static String en;
public void BeginScan(BA ba,String EventName, String msg) {
myba=ba;
en=EventName.toLowerCase();
Intent izx;
izx=new Intent(BA.applicationContext, CaptureActivity.class);
izx.setAction("com.google.zxing.client.android.SCAN");
izx.putExtra("PROMPT_MESSAGE",msg);
ion=new IOnActivityResult() {
@Override
public void ResultArrived(int arg0, Intent arg1) {
// TODO Auto-generated method stub
if (arg0==-1){
String atype;
String Value;
atype=arg1.getStringExtra("SCAN_RESULT_FORMAT");
Value=arg1.getStringExtra("SCAN_RESULT");
myba.raiseEvent2(null, false, en+"_result", true, new Object[]{atype,Value});
Log.i("B4A", "Got result code:"+Value);
}else{
myba.raiseEvent(null,en+"_noscan");
Log.i("B4A", "Got other result code:"+arg0);
}
}
};
ba.startActivityForResult(ion, izx);
}
}
I then amended the code as follows by making use of Notepad in Windows and saved it as barcodescanner.java in the directory as per the directory tree above:
Amended this:
public void BeginScan(BA ba,String EventName, String msg)
to
public void BeginScan(BA ba,String EventName, String msg, int scan_width, int scan_height)
and
added this:
izx.putExtra("SCAN_WIDTH",scan_width);
izx.putExtra("SCAN_HEIGHT",scan_height);
Nelson's modified/amended code:
B4X:
/*
Based on the original work of IceFairy333
*/
package com.inforpires.barcodescanner;
import android.content.Intent;
import android.util.Log;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.Events;
import anywheresoftware.b4a.BA.Hide;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import anywheresoftware.b4a.IOnActivityResult;
import anywheresoftware.b4a.BA.DependsOn;
import com.google.zxing.client.android.*;
@ShortName("Zxing_scanner")
@Version(1.0F)
@Author("Nelson Pires")
@Events(values={"result(atype as String,Values as String)","noScan"})
@ActivityObject
@Permissions(values={"android.permission.CAMERA","android.permission.WRITE_EXTERNAL_STORAGE","android.hardware.camera","android.hardware.camera.autofocus","android.permission.VIBRATE","android.permission.FLASHLIGHT"})
@DependsOn(values={"core-zxing","zxingscanner"})
public class barcodescanner {
@Hide
public static BA myba;
private IOnActivityResult ion;
@Hide
public static String en;
public void BeginScan(BA ba,String EventName, String msg, int scan_width, int scan_height) {
myba=ba;
en=EventName.toLowerCase();
Intent izx;
izx=new Intent(BA.applicationContext, CaptureActivity.class);
izx.setAction("com.google.zxing.client.android.SCAN");
izx.putExtra("PROMPT_MESSAGE",msg);
izx.putExtra("SCAN_WIDTH",scan_width);
izx.putExtra("SCAN_HEIGHT",scan_height);
ion=new IOnActivityResult() {
@Override
public void ResultArrived(int arg0, Intent arg1) {
// TODO Auto-generated method stub
if (arg0==-1){
String atype;
String Value;
atype=arg1.getStringExtra("SCAN_RESULT_FORMAT");
Value=arg1.getStringExtra("SCAN_RESULT");
myba.raiseEvent2(null, false, en+"_result", true, new Object[]{atype,Value});
Log.i("B4A", "Got result code:"+Value);
}else{
myba.raiseEvent(null,en+"_noscan");
Log.i("B4A", "Got other result code:"+arg0);
}
}
};
ba.startActivityForResult(ion, izx);
}
}
I then started Simple Library Compiler (http://www.b4x.com/android/forum/th...mpiler-build-libraries-without-eclipse.29918/) and set the required parameters as per the attached png file, clicked on button Compile and that was it as far as the compiling was concerned.
The library files Zxing_scanner.jar and Zxing_scanner.xml were generated and added to my additional libraries folder. I copied the two files to the B4A default library folder, opened Nelson's original project, refreshed the libraries, selected baQRCode and Zxing_scanner, amended and added code as per lines 66 to 70 of the project posted at http://www.b4x.com/android/forum/th...ode-ean-13-ean-8-generator.37447/#post-280091
.....and that was it. It worked! Hope this is useful form someone else.
Edit 14 Nov 2014
See attached project originally by Nelson et al. I have added the option to specify the width and height of the scan rectangle when the camera is active. Code in lines 66 to 69 added and code in line 70 amended to accommodate passing the width and height.
1. The library files were created as per above posting i.e with Simple Library Compiler
2. By adding izx.putExtra("SCAN_WIDTH", width) and izx.putExtra("SCAN_HEIGHT",height) and then compiling Nelson's wrapper the width and height can be passed from his B4A project to the zxing library according to the amendments that I have made in lines 66 to 70 of Nelson's project - thanks Nelson!
The library files that you require for this project should be in the /files folder of the attached project (i.e baqrcode.jar, baqrcode.xml, zxing_scanner.jar, and zxing_scanner.xml). Copy them to your default B4A libs folder, refresh the libs in the project (if need be) and select the two libs if they are not already selected.
If you want to change some colors (for eg the laser, the masking window around the viewfinder window, etc) you can do so by editing and changing the color values in /Objects/res/values/colors.xml of the attached project. Then recompile the B4A project for the color changes to take effect.
The scanning part of Project QRCP4 at http://www.b4x.com/android/forum/threads/qr-code-library.41408/#post-259448 is based on the project posted here.
Attachments
Last edited: