Repository: dm77/ZBarScanner
Branch: master
Commit: 341d7e486793
Files: 24
Total size: 33.3 KB
Directory structure:
gitextract_uc5gkx59/
├── .gitignore
├── README.md
├── ZBarScannerLibrary/
│ ├── AndroidManifest.xml
│ ├── ant.properties
│ ├── build.properties
│ ├── build.xml
│ ├── default.properties
│ ├── libs/
│ │ └── zbar.jar
│ ├── proguard-project.txt
│ ├── project.properties
│ ├── res/
│ │ └── values/
│ │ └── strings.xml
│ └── src/
│ └── com/
│ └── dm/
│ └── zbar/
│ └── android/
│ └── scanner/
│ ├── CameraPreview.java
│ ├── ZBarConstants.java
│ └── ZBarScannerActivity.java
└── examples/
└── ZBarScannerDemo/
├── AndroidManifest.xml
├── ant.properties
├── build.properties
├── build.xml
├── default.properties
├── proguard-project.txt
├── project.properties
├── res/
│ ├── layout/
│ │ └── main.xml
│ └── values/
│ └── strings.xml
└── src/
└── com/
└── dm/
└── zbar/
└── android/
└── examples/
└── MainActivity.java
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
## Adopted from https://github.com/github/gitignore/blob/master/Android.gitignore
# Built application files
*.apk
*.ap_
# Files for the Dalvik VM
*.dex
# Java class files
*.class
# Generated files
bin/
gen/
# Local configuration file (sdk path, etc)
local.properties
# Our Custom properties file
config.properties
# Eclipse generated files
.classpath
.project
.directory
.settings/
.metadata/
# Idea generated files
*.iml
.idea
out
# Netbeans generated files
private
nbandroid
# MacOSX files
.DS_Store
# Maven
target
gen-external-apklibs
================================================
FILE: README.md
================================================
ATTENTION!
==========
This project will no longer be maintained. Moving forward, I am going to spend my time on development of this project here: https://github.com/dm77/barcodescanner
--------------------------------------------------------------------------------------
This is an Android library project that simplifies the usage of ZBar Android SDK (http://sourceforge.net/projects/zbar/files/AndroidSDK/) for scanning bar codes from within your Android application.
### How to use?
1. Download this project and add it as a library project to your existing Android app.
2. Open the AndroidManifest.xml file in your project and add these lines under the manifest element:
<pre>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" />
</pre>
3. Within the application element, add the activity declaration:
<pre>
<activity android:name="com.dm.zbar.android.scanner.ZBarScannerActivity"
android:screenOrientation="landscape"
android:label="@string/app_name" />
</pre>
4. Now from inside your Android application, you can launch the ZBarScanner from any activity using this intent:
```java
Intent intent = new Intent(this, ZBarScannerActivity.class);
startActivityForResult(intent, ZBAR_SCANNER_REQUEST);
```
To receive the results of the SCAN, add this method to your activity:
```java
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (resultCode == RESULT_OK)
{
// Scan result is available by making a call to data.getStringExtra(ZBarConstants.SCAN_RESULT)
// Type of the scan result is available by making a call to data.getStringExtra(ZBarConstants.SCAN_RESULT_TYPE)
Toast.makeText(this, "Scan Result = " + data.getStringExtra(ZBarConstants.SCAN_RESULT), Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Scan Result Type = " + data.getIntExtra(ZBarConstants.SCAN_RESULT_TYPE, 0), Toast.LENGTH_SHORT).show();
// The value of type indicates one of the symbols listed in Advanced Options below.
} else if(resultCode == RESULT_CANCELED) {
Toast.makeText(this, "Camera unavailable", Toast.LENGTH_SHORT).show();
}
}
```
### Advanced Options
If you are interested in scanning only QR codes, you can specify the SCAN mode in the intent as shown below:
```java
Intent intent = new Intent(this, ZBarScannerActivity.class);
intent.putExtra(ZBarConstants.SCAN_MODES, new int[]{Symbol.QRCODE});
startActivityForResult(intent, ZBAR_SCANNER_REQUEST);
```
You can pass an array or integers for SCAN_MODES. The exact values are specified in net.sourceforge.zbar.Symbol class:
```java
public static final int NONE = 0;
public static final int PARTIAL = 1;
public static final int EAN8 = 8;
public static final int UPCE = 9;
public static final int ISBN10 = 10;
public static final int UPCA = 12;
public static final int EAN13 = 13;
public static final int ISBN13 = 14;
public static final int I25 = 25;
public static final int DATABAR = 34;
public static final int DATABAR_EXP = 35;
public static final int CODABAR = 38;
public static final int CODE39 = 39;
public static final int PDF417 = 57;
public static final int QRCODE = 64;
public static final int CODE93 = 93;
public static final int CODE128 = 128;
```
If you do not specify scan_modes, the scanner processes all the above listed types.
But if you are interested in QRCodes and ISBN, you would setup the intent as follows:
```java
Intent intent = new Intent(this, ZBarScannerActivity.class);
intent.putExtra(ZBarConstants.SCAN_MODES, new int[]{Symbol.QRCODE, Symbol.ISBN10, Symbol.ISBN13});
startActivityForResult(intent, ZBAR_SCANNER_REQUEST);
```
### Example app
There is a ZBarScannerDemo app in the examples folder which demonstrates the use of this library.
### Tests
I have tested the scanner functionality on these devices without any issues so far:
* Motorola Droid running Android 2.2.3
* HTC Thunderbolt running Android 2.3.4
* Samsung Galaxy Nexus running Android 4.0.4
###Credits
Almost all of the code for this library project has been taken from these two places:
1. CameraPreview app from Android SDK APIDemos
2. The ZBar Android SDK: http://sourceforge.net/projects/zbar/files/AndroidSDK/
###License
MIT
--------------------------------------------------------------------------------------
ATTENTION!
==========
This project will no longer be maintained. Moving forward, I am going to spend my time on development of this project here: https://github.com/dm77/barcodescanner
================================================
FILE: ZBarScannerLibrary/AndroidManifest.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dm.zbar.android.scanner"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" />
<uses-sdk android:minSdkVersion="8" />
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
<activity android:name="ZBarScannerActivity"
android:screenOrientation="landscape"
android:label="@string/app_name" />
</application>
</manifest>
================================================
FILE: ZBarScannerLibrary/ant.properties
================================================
# This file is used to override default values used by the Ant build system.
#
# This file must be checked into Version Control Systems, as it is
# integral to the build system of your project.
# This file is only used by the Ant script.
# You can use this to override default values such as
# 'source.dir' for the location of your java source folder and
# 'out.dir' for the location of your output folder.
# You can also use it define how the release builds are signed by declaring
# the following properties:
# 'key.store' for the location of your keystore and
# 'key.alias' for the name of the key to use.
# The password will be asked during the build when you use the 'release' target.
================================================
FILE: ZBarScannerLibrary/build.properties
================================================
================================================
FILE: ZBarScannerLibrary/build.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<project name="ZBarScanner" default="help">
<!-- The local.properties file is created and updated by the 'android' tool.
It contains the path to the SDK. It should *NOT* be checked into
Version Control Systems. -->
<property file="local.properties" />
<!-- The ant.properties file can be created by you. It is only edited by the
'android' tool to add properties to it.
This is the place to change some Ant specific build properties.
Here are some properties you may want to change/update:
source.dir
The name of the source directory. Default is 'src'.
out.dir
The name of the output directory. Default is 'bin'.
For other overridable properties, look at the beginning of the rules
files in the SDK, at tools/ant/build.xml
Properties related to the SDK location or the project target should
be updated using the 'android' tool with the 'update' action.
This file is an integral part of the build system for your
application and should be checked into Version Control Systems.
-->
<property file="ant.properties" />
<!-- if sdk.dir was not set from one of the property file, then
get it from the ANDROID_HOME env var.
This must be done before we load project.properties since
the proguard config can use sdk.dir -->
<property environment="env" />
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
<isset property="env.ANDROID_HOME" />
</condition>
<!-- The project.properties file is created and updated by the 'android'
tool, as well as ADT.
This contains project specific properties such as project target, and library
dependencies. Lower level build properties are stored in ant.properties
(or in .classpath for Eclipse projects).
This file is an integral part of the build system for your
application and should be checked into Version Control Systems. -->
<loadproperties srcFile="project.properties" />
<!-- quick check on sdk.dir -->
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
unless="sdk.dir"
/>
<!--
Import per project custom build rules if present at the root of the project.
This is the place to put custom intermediary targets such as:
-pre-build
-pre-compile
-post-compile (This is typically used for code obfuscation.
Compiled code location: ${out.classes.absolute.dir}
If this is not done in place, override ${out.dex.input.absolute.dir})
-post-package
-post-build
-pre-clean
-->
<import file="custom_rules.xml" optional="true" />
<!-- Import the actual build file.
To customize existing targets, there are two options:
- Customize only one target:
- copy/paste the target into this file, *before* the
<import> task.
- customize it to your needs.
- Customize the whole content of build.xml
- copy/paste the content of the rules files (minus the top node)
into this file, replacing the <import> task.
- customize to your needs.
***********************
****** IMPORTANT ******
***********************
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
in order to avoid having your file be overridden by tools such as "android update project"
-->
<!-- version-tag: 1 -->
<import file="${sdk.dir}/tools/ant/build.xml" />
</project>
================================================
FILE: ZBarScannerLibrary/default.properties
================================================
================================================
FILE: ZBarScannerLibrary/proguard-project.txt
================================================
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
================================================
FILE: ZBarScannerLibrary/project.properties
================================================
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-16
android.library=true
================================================
FILE: ZBarScannerLibrary/res/values/strings.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">ZBar Scanner</string>
</resources>
================================================
FILE: ZBarScannerLibrary/src/com/dm/zbar/android/scanner/CameraPreview.java
================================================
package com.dm.zbar.android.scanner;
import android.content.Context;
import android.hardware.Camera;
import android.hardware.Camera.AutoFocusCallback;
import android.hardware.Camera.PreviewCallback;
import android.hardware.Camera.Size;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import java.io.IOException;
import java.util.List;
class CameraPreview extends ViewGroup implements SurfaceHolder.Callback {
private final String TAG = "CameraPreview";
SurfaceView mSurfaceView;
SurfaceHolder mHolder;
Size mPreviewSize;
List<Size> mSupportedPreviewSizes;
Camera mCamera;
PreviewCallback mPreviewCallback;
AutoFocusCallback mAutoFocusCallback;
CameraPreview(Context context, PreviewCallback previewCallback, AutoFocusCallback autoFocusCb) {
super(context);
mPreviewCallback = previewCallback;
mAutoFocusCallback = autoFocusCb;
mSurfaceView = new SurfaceView(context);
addView(mSurfaceView);
// Install a SurfaceHolder.Callback so we get notified when the
// underlying surface is created and destroyed.
mHolder = mSurfaceView.getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
public void setCamera(Camera camera) {
mCamera = camera;
if (mCamera != null) {
mSupportedPreviewSizes = mCamera.getParameters().getSupportedPreviewSizes();
requestLayout();
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// We purposely disregard child measurements because act as a
// wrapper to a SurfaceView that centers the camera preview instead
// of stretching it.
final int width = resolveSize(getSuggestedMinimumWidth(), widthMeasureSpec);
final int height = resolveSize(getSuggestedMinimumHeight(), heightMeasureSpec);
setMeasuredDimension(width, height);
if (mSupportedPreviewSizes != null) {
mPreviewSize = getOptimalPreviewSize(mSupportedPreviewSizes, width, height);
}
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
if (changed && getChildCount() > 0) {
final View child = getChildAt(0);
final int width = r - l;
final int height = b - t;
int previewWidth = width;
int previewHeight = height;
if (mPreviewSize != null) {
previewWidth = mPreviewSize.width;
previewHeight = mPreviewSize.height;
}
// Center the child SurfaceView within the parent.
if (width * previewHeight > height * previewWidth) {
final int scaledChildWidth = previewWidth * height / previewHeight;
child.layout((width - scaledChildWidth) / 2, 0,
(width + scaledChildWidth) / 2, height);
} else {
final int scaledChildHeight = previewHeight * width / previewWidth;
child.layout(0, (height - scaledChildHeight) / 2,
width, (height + scaledChildHeight) / 2);
}
}
}
public void hideSurfaceView() {
mSurfaceView.setVisibility(View.INVISIBLE);
}
public void showSurfaceView() {
mSurfaceView.setVisibility(View.VISIBLE);
}
public void surfaceCreated(SurfaceHolder holder) {
// The Surface has been created, acquire the camera and tell it where
// to draw.
try {
if (mCamera != null) {
mCamera.setPreviewDisplay(holder);
}
} catch (IOException exception) {
Log.e(TAG, "IOException caused by setPreviewDisplay()", exception);
}
}
public void surfaceDestroyed(SurfaceHolder holder) {
// Surface will be destroyed when we return, so stop the preview.
if (mCamera != null) {
mCamera.cancelAutoFocus();
mCamera.stopPreview();
}
}
private Size getOptimalPreviewSize(List<Size> sizes, int w, int h) {
final double ASPECT_TOLERANCE = 0.1;
double targetRatio = (double) w / h;
if (sizes == null) return null;
Size optimalSize = null;
double minDiff = Double.MAX_VALUE;
int targetHeight = h;
// Try to find an size match aspect ratio and size
for (Size size : sizes) {
double ratio = (double) size.width / size.height;
if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue;
if (Math.abs(size.height - targetHeight) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}
// Cannot find the one match the aspect ratio, ignore the requirement
if (optimalSize == null) {
minDiff = Double.MAX_VALUE;
for (Size size : sizes) {
if (Math.abs(size.height - targetHeight) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}
}
return optimalSize;
}
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
if (holder.getSurface() == null){
// preview surface does not exist
return;
}
if (mCamera != null) {
// Now that the size is known, set up the camera parameters and begin
// the preview.
Camera.Parameters parameters = mCamera.getParameters();
parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height);
requestLayout();
mCamera.setParameters(parameters);
mCamera.setPreviewCallback(mPreviewCallback);
mCamera.startPreview();
mCamera.autoFocus(mAutoFocusCallback);
}
}
}
================================================
FILE: ZBarScannerLibrary/src/com/dm/zbar/android/scanner/ZBarConstants.java
================================================
package com.dm.zbar.android.scanner;
public interface ZBarConstants {
public static final String SCAN_MODES = "SCAN_MODES";
public static final String SCAN_RESULT = "SCAN_RESULT";
public static final String SCAN_RESULT_TYPE = "SCAN_RESULT_TYPE";
public static final String ERROR_INFO = "ERROR_INFO";
}
================================================
FILE: ZBarScannerLibrary/src/com/dm/zbar/android/scanner/ZBarScannerActivity.java
================================================
package com.dm.zbar.android.scanner;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.Window;
import android.view.WindowManager;
import net.sourceforge.zbar.Config;
import net.sourceforge.zbar.Image;
import net.sourceforge.zbar.ImageScanner;
import net.sourceforge.zbar.Symbol;
import net.sourceforge.zbar.SymbolSet;
public class ZBarScannerActivity extends Activity implements Camera.PreviewCallback, ZBarConstants {
private static final String TAG = "ZBarScannerActivity";
private CameraPreview mPreview;
private Camera mCamera;
private ImageScanner mScanner;
private Handler mAutoFocusHandler;
private boolean mPreviewing = true;
static {
System.loadLibrary("iconv");
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(!isCameraAvailable()) {
// Cancel request if there is no rear-facing camera.
cancelRequest();
return;
}
// Hide the window title.
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
mAutoFocusHandler = new Handler();
// Create and configure the ImageScanner;
setupScanner();
// Create a RelativeLayout container that will hold a SurfaceView,
// and set it as the content of our activity.
mPreview = new CameraPreview(this, this, autoFocusCB);
setContentView(mPreview);
}
public void setupScanner() {
mScanner = new ImageScanner();
mScanner.setConfig(0, Config.X_DENSITY, 3);
mScanner.setConfig(0, Config.Y_DENSITY, 3);
int[] symbols = getIntent().getIntArrayExtra(SCAN_MODES);
if (symbols != null) {
mScanner.setConfig(Symbol.NONE, Config.ENABLE, 0);
for (int symbol : symbols) {
mScanner.setConfig(symbol, Config.ENABLE, 1);
}
}
}
@Override
protected void onResume() {
super.onResume();
// Open the default i.e. the first rear facing camera.
mCamera = Camera.open();
if(mCamera == null) {
// Cancel request if mCamera is null.
cancelRequest();
return;
}
mPreview.setCamera(mCamera);
mPreview.showSurfaceView();
mPreviewing = true;
}
@Override
protected void onPause() {
super.onPause();
// Because the Camera object is a shared resource, it's very
// important to release it when the activity is paused.
if (mCamera != null) {
mPreview.setCamera(null);
mCamera.cancelAutoFocus();
mCamera.setPreviewCallback(null);
mCamera.stopPreview();
mCamera.release();
// According to Jason Kuang on http://stackoverflow.com/questions/6519120/how-to-recover-camera-preview-from-sleep,
// there might be surface recreation problems when the device goes to sleep. So lets just hide it and
// recreate on resume
mPreview.hideSurfaceView();
mPreviewing = false;
mCamera = null;
}
}
public boolean isCameraAvailable() {
PackageManager pm = getPackageManager();
return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA);
}
public void cancelRequest() {
Intent dataIntent = new Intent();
dataIntent.putExtra(ERROR_INFO, "Camera unavailable");
setResult(Activity.RESULT_CANCELED, dataIntent);
finish();
}
public void onPreviewFrame(byte[] data, Camera camera) {
Camera.Parameters parameters = camera.getParameters();
Camera.Size size = parameters.getPreviewSize();
Image barcode = new Image(size.width, size.height, "Y800");
barcode.setData(data);
int result = mScanner.scanImage(barcode);
if (result != 0) {
mCamera.cancelAutoFocus();
mCamera.setPreviewCallback(null);
mCamera.stopPreview();
mPreviewing = false;
SymbolSet syms = mScanner.getResults();
for (Symbol sym : syms) {
String symData = sym.getData();
if (!TextUtils.isEmpty(symData)) {
Intent dataIntent = new Intent();
dataIntent.putExtra(SCAN_RESULT, symData);
dataIntent.putExtra(SCAN_RESULT_TYPE, sym.getType());
setResult(Activity.RESULT_OK, dataIntent);
finish();
break;
}
}
}
}
private Runnable doAutoFocus = new Runnable() {
public void run() {
if(mCamera != null && mPreviewing) {
mCamera.autoFocus(autoFocusCB);
}
}
};
// Mimic continuous auto-focusing
Camera.AutoFocusCallback autoFocusCB = new Camera.AutoFocusCallback() {
public void onAutoFocus(boolean success, Camera camera) {
mAutoFocusHandler.postDelayed(doAutoFocus, 1000);
}
};
}
================================================
FILE: examples/ZBarScannerDemo/AndroidManifest.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dm.zbar.android.examples"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-sdk android:minSdkVersion="8" />
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
<activity android:name="MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.dm.zbar.android.scanner.ZBarScannerActivity"
android:screenOrientation="landscape"
android:label="@string/app_name" />
</application>
</manifest>
================================================
FILE: examples/ZBarScannerDemo/ant.properties
================================================
# This file is used to override default values used by the Ant build system.
#
# This file must be checked into Version Control Systems, as it is
# integral to the build system of your project.
# This file is only used by the Ant script.
# You can use this to override default values such as
# 'source.dir' for the location of your java source folder and
# 'out.dir' for the location of your output folder.
# You can also use it define how the release builds are signed by declaring
# the following properties:
# 'key.store' for the location of your keystore and
# 'key.alias' for the name of the key to use.
# The password will be asked during the build when you use the 'release' target.
================================================
FILE: examples/ZBarScannerDemo/build.properties
================================================
================================================
FILE: examples/ZBarScannerDemo/build.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<project name="ZBarScannerDemo" default="help">
<!-- The local.properties file is created and updated by the 'android' tool.
It contains the path to the SDK. It should *NOT* be checked into
Version Control Systems. -->
<property file="local.properties" />
<!-- The ant.properties file can be created by you. It is only edited by the
'android' tool to add properties to it.
This is the place to change some Ant specific build properties.
Here are some properties you may want to change/update:
source.dir
The name of the source directory. Default is 'src'.
out.dir
The name of the output directory. Default is 'bin'.
For other overridable properties, look at the beginning of the rules
files in the SDK, at tools/ant/build.xml
Properties related to the SDK location or the project target should
be updated using the 'android' tool with the 'update' action.
This file is an integral part of the build system for your
application and should be checked into Version Control Systems.
-->
<property file="ant.properties" />
<!-- if sdk.dir was not set from one of the property file, then
get it from the ANDROID_HOME env var.
This must be done before we load project.properties since
the proguard config can use sdk.dir -->
<property environment="env" />
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
<isset property="env.ANDROID_HOME" />
</condition>
<!-- The project.properties file is created and updated by the 'android'
tool, as well as ADT.
This contains project specific properties such as project target, and library
dependencies. Lower level build properties are stored in ant.properties
(or in .classpath for Eclipse projects).
This file is an integral part of the build system for your
application and should be checked into Version Control Systems. -->
<loadproperties srcFile="project.properties" />
<!-- quick check on sdk.dir -->
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
unless="sdk.dir"
/>
<!--
Import per project custom build rules if present at the root of the project.
This is the place to put custom intermediary targets such as:
-pre-build
-pre-compile
-post-compile (This is typically used for code obfuscation.
Compiled code location: ${out.classes.absolute.dir}
If this is not done in place, override ${out.dex.input.absolute.dir})
-post-package
-post-build
-pre-clean
-->
<import file="custom_rules.xml" optional="true" />
<!-- Import the actual build file.
To customize existing targets, there are two options:
- Customize only one target:
- copy/paste the target into this file, *before* the
<import> task.
- customize it to your needs.
- Customize the whole content of build.xml
- copy/paste the content of the rules files (minus the top node)
into this file, replacing the <import> task.
- customize to your needs.
***********************
****** IMPORTANT ******
***********************
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
in order to avoid having your file be overridden by tools such as "android update project"
-->
<!-- version-tag: 1 -->
<import file="${sdk.dir}/tools/ant/build.xml" />
</project>
================================================
FILE: examples/ZBarScannerDemo/default.properties
================================================
================================================
FILE: examples/ZBarScannerDemo/proguard-project.txt
================================================
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
================================================
FILE: examples/ZBarScannerDemo/project.properties
================================================
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-16
android.library.reference.1=../../ZBarScannerLibrary
================================================
FILE: examples/ZBarScannerDemo/res/layout/main.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:padding="5dp"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/scan_btn"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:onClick="launchScanner"
android:text="@string/scan" />
<Button
android:id="@+id/qrscan_btn"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:onClick="launchQRScanner"
android:text="@string/scan_only_qr_codes" />
</LinearLayout>
================================================
FILE: examples/ZBarScannerDemo/res/values/strings.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">ZBar Scanner Demo</string>
<string name="scan">Scan</string>
<string name="scan_only_qr_codes">Scan only QR Codes</string>
</resources>
================================================
FILE: examples/ZBarScannerDemo/src/com/dm/zbar/android/examples/MainActivity.java
================================================
package com.dm.zbar.android.examples;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Toast;
import com.dm.zbar.android.scanner.ZBarConstants;
import com.dm.zbar.android.scanner.ZBarScannerActivity;
import net.sourceforge.zbar.Symbol;
public class MainActivity extends Activity {
private static final int ZBAR_SCANNER_REQUEST = 0;
private static final int ZBAR_QR_SCANNER_REQUEST = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void launchScanner(View v) {
if (isCameraAvailable()) {
Intent intent = new Intent(this, ZBarScannerActivity.class);
startActivityForResult(intent, ZBAR_SCANNER_REQUEST);
} else {
Toast.makeText(this, "Rear Facing Camera Unavailable", Toast.LENGTH_SHORT).show();
}
}
public void launchQRScanner(View v) {
if (isCameraAvailable()) {
Intent intent = new Intent(this, ZBarScannerActivity.class);
intent.putExtra(ZBarConstants.SCAN_MODES, new int[]{Symbol.QRCODE});
startActivityForResult(intent, ZBAR_SCANNER_REQUEST);
} else {
Toast.makeText(this, "Rear Facing Camera Unavailable", Toast.LENGTH_SHORT).show();
}
}
public boolean isCameraAvailable() {
PackageManager pm = getPackageManager();
return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case ZBAR_SCANNER_REQUEST:
case ZBAR_QR_SCANNER_REQUEST:
if (resultCode == RESULT_OK) {
Toast.makeText(this, "Scan Result = " + data.getStringExtra(ZBarConstants.SCAN_RESULT), Toast.LENGTH_SHORT).show();
} else if(resultCode == RESULT_CANCELED && data != null) {
String error = data.getStringExtra(ZBarConstants.ERROR_INFO);
if(!TextUtils.isEmpty(error)) {
Toast.makeText(this, error, Toast.LENGTH_SHORT).show();
}
}
break;
}
}
}
gitextract_uc5gkx59/
├── .gitignore
├── README.md
├── ZBarScannerLibrary/
│ ├── AndroidManifest.xml
│ ├── ant.properties
│ ├── build.properties
│ ├── build.xml
│ ├── default.properties
│ ├── libs/
│ │ └── zbar.jar
│ ├── proguard-project.txt
│ ├── project.properties
│ ├── res/
│ │ └── values/
│ │ └── strings.xml
│ └── src/
│ └── com/
│ └── dm/
│ └── zbar/
│ └── android/
│ └── scanner/
│ ├── CameraPreview.java
│ ├── ZBarConstants.java
│ └── ZBarScannerActivity.java
└── examples/
└── ZBarScannerDemo/
├── AndroidManifest.xml
├── ant.properties
├── build.properties
├── build.xml
├── default.properties
├── proguard-project.txt
├── project.properties
├── res/
│ ├── layout/
│ │ └── main.xml
│ └── values/
│ └── strings.xml
└── src/
└── com/
└── dm/
└── zbar/
└── android/
└── examples/
└── MainActivity.java
SYMBOL INDEX (28 symbols across 4 files)
FILE: ZBarScannerLibrary/src/com/dm/zbar/android/scanner/CameraPreview.java
class CameraPreview (line 16) | class CameraPreview extends ViewGroup implements SurfaceHolder.Callback {
method CameraPreview (line 27) | CameraPreview(Context context, PreviewCallback previewCallback, AutoFo...
method setCamera (line 42) | public void setCamera(Camera camera) {
method onMeasure (line 50) | @Override
method onLayout (line 64) | @Override
method hideSurfaceView (line 92) | public void hideSurfaceView() {
method showSurfaceView (line 96) | public void showSurfaceView() {
method surfaceCreated (line 100) | public void surfaceCreated(SurfaceHolder holder) {
method surfaceDestroyed (line 112) | public void surfaceDestroyed(SurfaceHolder holder) {
method getOptimalPreviewSize (line 121) | private Size getOptimalPreviewSize(List<Size> sizes, int w, int h) {
method surfaceChanged (line 154) | public void surfaceChanged(SurfaceHolder holder, int format, int w, in...
FILE: ZBarScannerLibrary/src/com/dm/zbar/android/scanner/ZBarConstants.java
type ZBarConstants (line 3) | public interface ZBarConstants {
FILE: ZBarScannerLibrary/src/com/dm/zbar/android/scanner/ZBarScannerActivity.java
class ZBarScannerActivity (line 18) | public class ZBarScannerActivity extends Activity implements Camera.Prev...
method onCreate (line 31) | @Override
method setupScanner (line 56) | public void setupScanner() {
method onResume (line 70) | @Override
method onPause (line 88) | @Override
method isCameraAvailable (line 111) | public boolean isCameraAvailable() {
method cancelRequest (line 116) | public void cancelRequest() {
method onPreviewFrame (line 123) | public void onPreviewFrame(byte[] data, Camera camera) {
method run (line 152) | public void run() {
method onAutoFocus (line 161) | public void onAutoFocus(boolean success, Camera camera) {
FILE: examples/ZBarScannerDemo/src/com/dm/zbar/android/examples/MainActivity.java
class MainActivity (line 14) | public class MainActivity extends Activity {
method onCreate (line 19) | @Override
method launchScanner (line 25) | public void launchScanner(View v) {
method launchQRScanner (line 34) | public void launchQRScanner(View v) {
method isCameraAvailable (line 44) | public boolean isCameraAvailable() {
method onActivityResult (line 49) | @Override
Condensed preview — 24 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (37K chars).
[
{
"path": ".gitignore",
"chars": 548,
"preview": "## Adopted from https://github.com/github/gitignore/blob/master/Android.gitignore\n\n# Built application files\n*.apk\n*.ap_"
},
{
"path": "README.md",
"chars": 4576,
"preview": "ATTENTION!\n==========\n\nThis project will no longer be maintained. Moving forward, I am going to spend my time on develop"
},
{
"path": "ZBarScannerLibrary/AndroidManifest.xml",
"chars": 666,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n packag"
},
{
"path": "ZBarScannerLibrary/ant.properties",
"chars": 698,
"preview": "# This file is used to override default values used by the Ant build system.\n#\n# This file must be checked into Version "
},
{
"path": "ZBarScannerLibrary/build.properties",
"chars": 0,
"preview": ""
},
{
"path": "ZBarScannerLibrary/build.xml",
"chars": 3923,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project name=\"ZBarScanner\" default=\"help\">\n\n <!-- The local.properties file i"
},
{
"path": "ZBarScannerLibrary/default.properties",
"chars": 0,
"preview": ""
},
{
"path": "ZBarScannerLibrary/proguard-project.txt",
"chars": 781,
"preview": "# To enable ProGuard in your project, edit project.properties\n# to define the proguard.config property as described in t"
},
{
"path": "ZBarScannerLibrary/project.properties",
"chars": 584,
"preview": "# This file is automatically generated by Android Tools.\n# Do not modify this file -- YOUR CHANGES WILL BE ERASED!\n#\n# T"
},
{
"path": "ZBarScannerLibrary/res/values/strings.xml",
"chars": 114,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n <string name=\"app_name\">ZBar Scanner</string>\n</resources>\n"
},
{
"path": "ZBarScannerLibrary/src/com/dm/zbar/android/scanner/CameraPreview.java",
"chars": 6084,
"preview": "package com.dm.zbar.android.scanner;\n\nimport android.content.Context;\nimport android.hardware.Camera;\nimport android.har"
},
{
"path": "ZBarScannerLibrary/src/com/dm/zbar/android/scanner/ZBarConstants.java",
"chars": 319,
"preview": "package com.dm.zbar.android.scanner;\n\npublic interface ZBarConstants {\n public static final String SCAN_MODES = \"SCAN"
},
{
"path": "ZBarScannerLibrary/src/com/dm/zbar/android/scanner/ZBarScannerActivity.java",
"chars": 5323,
"preview": "package com.dm.zbar.android.scanner;\n\nimport android.app.Activity;\nimport android.content.Intent;\nimport android.content"
},
{
"path": "examples/ZBarScannerDemo/AndroidManifest.xml",
"chars": 1041,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n packag"
},
{
"path": "examples/ZBarScannerDemo/ant.properties",
"chars": 698,
"preview": "# This file is used to override default values used by the Ant build system.\n#\n# This file must be checked into Version "
},
{
"path": "examples/ZBarScannerDemo/build.properties",
"chars": 0,
"preview": ""
},
{
"path": "examples/ZBarScannerDemo/build.xml",
"chars": 3927,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project name=\"ZBarScannerDemo\" default=\"help\">\n\n <!-- The local.properties fi"
},
{
"path": "examples/ZBarScannerDemo/default.properties",
"chars": 0,
"preview": ""
},
{
"path": "examples/ZBarScannerDemo/proguard-project.txt",
"chars": 781,
"preview": "# To enable ProGuard in your project, edit project.properties\n# to define the proguard.config property as described in t"
},
{
"path": "examples/ZBarScannerDemo/project.properties",
"chars": 616,
"preview": "# This file is automatically generated by Android Tools.\n# Do not modify this file -- YOUR CHANGES WILL BE ERASED!\n#\n# T"
},
{
"path": "examples/ZBarScannerDemo/res/layout/main.xml",
"chars": 746,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n andr"
},
{
"path": "examples/ZBarScannerDemo/res/values/strings.xml",
"chars": 223,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n <string name=\"app_name\">ZBar Scanner Demo</string>\n <string na"
},
{
"path": "examples/ZBarScannerDemo/src/com/dm/zbar/android/examples/MainActivity.java",
"chars": 2410,
"preview": "package com.dm.zbar.android.examples;\n\nimport android.app.Activity;\nimport android.content.Intent;\nimport android.conten"
}
]
// ... and 1 more files (download for full content)
About this extraction
This page contains the full source code of the dm77/ZBarScanner GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 24 files (33.3 KB), approximately 8.1k tokens, and a symbol index with 28 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.