Removed all whitespace-only lines from the source code to stop myself from going crazy...
This commit is contained in:
parent
4ef4dfb51f
commit
889be2cc3a
@ -13,7 +13,7 @@ import android.content.Context;
|
|||||||
import org.cloudsky.cordovaPlugins.ZBarScannerActivity;
|
import org.cloudsky.cordovaPlugins.ZBarScannerActivity;
|
||||||
|
|
||||||
public class ZBar extends CordovaPlugin {
|
public class ZBar extends CordovaPlugin {
|
||||||
|
|
||||||
// Configuration ---------------------------------------------------
|
// Configuration ---------------------------------------------------
|
||||||
|
|
||||||
private static int SCAN_CODE = 1;
|
private static int SCAN_CODE = 1;
|
||||||
@ -52,7 +52,7 @@ public class ZBar extends CordovaPlugin {
|
|||||||
|
|
||||||
|
|
||||||
// External results handler ----------------------------------------
|
// External results handler ----------------------------------------
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult (int requestCode, int resultCode, Intent result)
|
public void onActivityResult (int requestCode, int resultCode, Intent result)
|
||||||
{
|
{
|
||||||
|
@ -31,17 +31,17 @@ public class ZBarScannerActivity extends Activity
|
|||||||
implements SurfaceHolder.Callback {
|
implements SurfaceHolder.Callback {
|
||||||
|
|
||||||
// Config ----------------------------------------------------------
|
// Config ----------------------------------------------------------
|
||||||
|
|
||||||
private static int autoFocusInterval = 500; // Interval between AFcallback and next AF attempt.
|
private static int autoFocusInterval = 500; // Interval between AFcallback and next AF attempt.
|
||||||
|
|
||||||
// Public Constants ------------------------------------------------
|
// Public Constants ------------------------------------------------
|
||||||
|
|
||||||
public static final String EXTRA_QRVALUE = "qrValue";
|
public static final String EXTRA_QRVALUE = "qrValue";
|
||||||
public static final String EXTRA_PARAMS = "params";
|
public static final String EXTRA_PARAMS = "params";
|
||||||
public static final int RESULT_ERROR = RESULT_FIRST_USER + 1;
|
public static final int RESULT_ERROR = RESULT_FIRST_USER + 1;
|
||||||
|
|
||||||
// State -----------------------------------------------------------
|
// State -----------------------------------------------------------
|
||||||
|
|
||||||
private Camera camera;
|
private Camera camera;
|
||||||
private Handler autoFocusHandler;
|
private Handler autoFocusHandler;
|
||||||
private SurfaceView scannerSurface;
|
private SurfaceView scannerSurface;
|
||||||
@ -59,12 +59,12 @@ implements SurfaceHolder.Callback {
|
|||||||
private Resources resources;
|
private Resources resources;
|
||||||
|
|
||||||
// Static initialisers (class) -------------------------------------
|
// Static initialisers (class) -------------------------------------
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// Needed by ZBar??
|
// Needed by ZBar??
|
||||||
System.loadLibrary("iconv");
|
System.loadLibrary("iconv");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Activity Lifecycle ----------------------------------------------
|
// Activity Lifecycle ----------------------------------------------
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -87,7 +87,7 @@ implements SurfaceHolder.Callback {
|
|||||||
scanner = new ImageScanner();
|
scanner = new ImageScanner();
|
||||||
scanner.setConfig(0, Config.X_DENSITY, 3);
|
scanner.setConfig(0, Config.X_DENSITY, 3);
|
||||||
scanner.setConfig(0, Config.Y_DENSITY, 3);
|
scanner.setConfig(0, Config.Y_DENSITY, 3);
|
||||||
|
|
||||||
// Set content view
|
// Set content view
|
||||||
setContentView(getResourceId("layout/cszbarscanner"));
|
setContentView(getResourceId("layout/cszbarscanner"));
|
||||||
|
|
||||||
@ -112,18 +112,18 @@ implements SurfaceHolder.Callback {
|
|||||||
Gravity.CENTER
|
Gravity.CENTER
|
||||||
));
|
));
|
||||||
scannerSurface.getHolder().addCallback(this);
|
scannerSurface.getHolder().addCallback(this);
|
||||||
|
|
||||||
// Add preview SurfaceView to the screen
|
// Add preview SurfaceView to the screen
|
||||||
((FrameLayout) findViewById(getResourceId("id/csZbarScannerView"))).addView(scannerSurface);
|
((FrameLayout) findViewById(getResourceId("id/csZbarScannerView"))).addView(scannerSurface);
|
||||||
findViewById(getResourceId("id/csZbarScannerTitle")).bringToFront();
|
findViewById(getResourceId("id/csZbarScannerTitle")).bringToFront();
|
||||||
findViewById(getResourceId("id/csZbarScannerInstructions")).bringToFront();
|
findViewById(getResourceId("id/csZbarScannerInstructions")).bringToFront();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume ()
|
public void onResume ()
|
||||||
{
|
{
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if(whichCamera.equals("front")) {
|
if(whichCamera.equals("front")) {
|
||||||
int numCams = Camera.getNumberOfCameras();
|
int numCams = Camera.getNumberOfCameras();
|
||||||
@ -149,14 +149,14 @@ implements SurfaceHolder.Callback {
|
|||||||
|
|
||||||
tryStartPreview();
|
tryStartPreview();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause ()
|
public void onPause ()
|
||||||
{
|
{
|
||||||
releaseCamera();
|
releaseCamera();
|
||||||
super.onPause();
|
super.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy ()
|
public void onDestroy ()
|
||||||
{
|
{
|
||||||
@ -174,7 +174,7 @@ implements SurfaceHolder.Callback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SurfaceHolder.Callback implementation ---------------------------
|
// SurfaceHolder.Callback implementation ---------------------------
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void surfaceCreated (SurfaceHolder hld)
|
public void surfaceCreated (SurfaceHolder hld)
|
||||||
{
|
{
|
||||||
@ -182,31 +182,31 @@ implements SurfaceHolder.Callback {
|
|||||||
holder = hld;
|
holder = hld;
|
||||||
tryStartPreview();
|
tryStartPreview();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void surfaceDestroyed (SurfaceHolder holder)
|
public void surfaceDestroyed (SurfaceHolder holder)
|
||||||
{
|
{
|
||||||
// No surface == no preview == no point being in this Activity.
|
// No surface == no preview == no point being in this Activity.
|
||||||
die("The camera surface was destroyed");
|
die("The camera surface was destroyed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void surfaceChanged (SurfaceHolder hld, int fmt, int w, int h)
|
public void surfaceChanged (SurfaceHolder hld, int fmt, int w, int h)
|
||||||
{
|
{
|
||||||
// Sanity check - holder must have a surface...
|
// Sanity check - holder must have a surface...
|
||||||
if(hld.getSurface() == null) die("There is no camera surface");
|
if(hld.getSurface() == null) die("There is no camera surface");
|
||||||
|
|
||||||
surfW = w;
|
surfW = w;
|
||||||
surfH = h;
|
surfH = h;
|
||||||
matchSurfaceToPreviewRatio();
|
matchSurfaceToPreviewRatio();
|
||||||
|
|
||||||
tryStopPreview();
|
tryStopPreview();
|
||||||
holder = hld;
|
holder = hld;
|
||||||
tryStartPreview();
|
tryStartPreview();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Continuously auto-focus -----------------------------------------
|
// Continuously auto-focus -----------------------------------------
|
||||||
|
|
||||||
private AutoFocusCallback autoFocusCb = new AutoFocusCallback()
|
private AutoFocusCallback autoFocusCb = new AutoFocusCallback()
|
||||||
{
|
{
|
||||||
public void onAutoFocus(boolean success, Camera camera) {
|
public void onAutoFocus(boolean success, Camera camera) {
|
||||||
@ -220,9 +220,9 @@ implements SurfaceHolder.Callback {
|
|||||||
if(camera != null) camera.autoFocus(autoFocusCb);
|
if(camera != null) camera.autoFocus(autoFocusCb);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Camera callbacks ------------------------------------------------
|
// Camera callbacks ------------------------------------------------
|
||||||
|
|
||||||
// Receives frames from the camera and checks for barcodes.
|
// Receives frames from the camera and checks for barcodes.
|
||||||
private PreviewCallback previewCb = new PreviewCallback()
|
private PreviewCallback previewCb = new PreviewCallback()
|
||||||
{
|
{
|
||||||
@ -235,24 +235,24 @@ implements SurfaceHolder.Callback {
|
|||||||
|
|
||||||
if (scanner.scanImage(barcode) != 0) {
|
if (scanner.scanImage(barcode) != 0) {
|
||||||
String qrValue = "";
|
String qrValue = "";
|
||||||
|
|
||||||
SymbolSet syms = scanner.getResults();
|
SymbolSet syms = scanner.getResults();
|
||||||
for (Symbol sym : syms) {
|
for (Symbol sym : syms) {
|
||||||
qrValue = sym.getData();
|
qrValue = sym.getData();
|
||||||
|
|
||||||
// Return 1st found QR code value to the calling Activity.
|
// Return 1st found QR code value to the calling Activity.
|
||||||
Intent result = new Intent ();
|
Intent result = new Intent ();
|
||||||
result.putExtra(EXTRA_QRVALUE, qrValue);
|
result.putExtra(EXTRA_QRVALUE, qrValue);
|
||||||
setResult(Activity.RESULT_OK, result);
|
setResult(Activity.RESULT_OK, result);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Misc ------------------------------------------------------------
|
// Misc ------------------------------------------------------------
|
||||||
|
|
||||||
// finish() due to error
|
// finish() due to error
|
||||||
private void die (String msg)
|
private void die (String msg)
|
||||||
{
|
{
|
||||||
@ -266,7 +266,7 @@ implements SurfaceHolder.Callback {
|
|||||||
if(resources == null) resources = getApplication().getResources();
|
if(resources == null) resources = getApplication().getResources();
|
||||||
return resources.getIdentifier(typeAndName, null, package_name);
|
return resources.getIdentifier(typeAndName, null, package_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Release the camera resources and state.
|
// Release the camera resources and state.
|
||||||
private void releaseCamera ()
|
private void releaseCamera ()
|
||||||
{
|
{
|
||||||
@ -277,19 +277,19 @@ implements SurfaceHolder.Callback {
|
|||||||
camera = null;
|
camera = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Match the aspect ratio of the preview SurfaceView with the camera's preview aspect ratio,
|
// Match the aspect ratio of the preview SurfaceView with the camera's preview aspect ratio,
|
||||||
// so that the displayed preview is not stretched/squashed.
|
// so that the displayed preview is not stretched/squashed.
|
||||||
private void matchSurfaceToPreviewRatio () {
|
private void matchSurfaceToPreviewRatio () {
|
||||||
if(camera == null) return;
|
if(camera == null) return;
|
||||||
if(surfW == 0 || surfH == 0) return;
|
if(surfW == 0 || surfH == 0) return;
|
||||||
|
|
||||||
// Resize SurfaceView to match camera preview ratio (avoid stretching).
|
// Resize SurfaceView to match camera preview ratio (avoid stretching).
|
||||||
Camera.Parameters params = camera.getParameters();
|
Camera.Parameters params = camera.getParameters();
|
||||||
Camera.Size size = params.getPreviewSize();
|
Camera.Size size = params.getPreviewSize();
|
||||||
float previewRatio = (float) size.height / size.width; // swap h and w as the preview is rotated 90 degrees
|
float previewRatio = (float) size.height / size.width; // swap h and w as the preview is rotated 90 degrees
|
||||||
float surfaceRatio = (float) surfW / surfH;
|
float surfaceRatio = (float) surfW / surfH;
|
||||||
|
|
||||||
if(previewRatio > surfaceRatio) {
|
if(previewRatio > surfaceRatio) {
|
||||||
scannerSurface.setLayoutParams(new FrameLayout.LayoutParams(
|
scannerSurface.setLayoutParams(new FrameLayout.LayoutParams(
|
||||||
surfW,
|
surfW,
|
||||||
@ -304,7 +304,7 @@ implements SurfaceHolder.Callback {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop the camera preview safely.
|
// Stop the camera preview safely.
|
||||||
private void tryStopPreview () {
|
private void tryStopPreview () {
|
||||||
// Stop camera preview before making changes.
|
// Stop camera preview before making changes.
|
||||||
@ -314,7 +314,7 @@ implements SurfaceHolder.Callback {
|
|||||||
// Preview was not running. Ignore the error.
|
// Preview was not running. Ignore the error.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the camera preview if possible.
|
// Start the camera preview if possible.
|
||||||
// If start is attempted but fails, exit with error message.
|
// If start is attempted but fails, exit with error message.
|
||||||
private void tryStartPreview () {
|
private void tryStartPreview () {
|
||||||
@ -322,7 +322,7 @@ implements SurfaceHolder.Callback {
|
|||||||
try {
|
try {
|
||||||
// 90 degrees rotation for Portrait orientation Activity.
|
// 90 degrees rotation for Portrait orientation Activity.
|
||||||
camera.setDisplayOrientation(90);
|
camera.setDisplayOrientation(90);
|
||||||
|
|
||||||
camera.setPreviewDisplay(holder);
|
camera.setPreviewDisplay(holder);
|
||||||
camera.setPreviewCallback(previewCb);
|
camera.setPreviewCallback(previewCb);
|
||||||
camera.startPreview();
|
camera.startPreview();
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="@color/csZbarScannerBackground" >
|
android:background="@color/csZbarScannerBackground" >
|
||||||
|
|
||||||
<TextView android:id="@+id/csZbarScannerTitle"
|
<TextView android:id="@+id/csZbarScannerTitle"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
Loading…
Reference in New Issue
Block a user