public class BarCodeReader
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
DECODE_STATUS_CANCELED
onDecodeComplete length value indicating that the decode was canceled
|
static int |
DECODE_STATUS_ERROR
onDecodeComplete length value indicating that an error occurred
|
static int |
DECODE_STATUS_MULTI_DEC_COUNT
onDecodeComplete length value indicating a multi-decode event
|
static int |
DECODE_STATUS_TIMEOUT
onDecodeComplete length value indicating that the decode timed out
|
Modifier and Type | Method and Description |
---|---|
void |
addCallbackBuffer(byte[] callbackBuffer)
Adds a pre-allocated buffer to the preview callback buffer queue.
|
void |
autoFocus(com.zebra.adc.decoder.BarCodeReader.AutoFocusCallback cb)
Starts reader auto-focus and registers a callback function to run when
the reader is focused.
|
void |
cancelAutoFocus()
Cancels any auto-focus function in progress.
|
void |
disableAllCodeTypes()
Disables all code types
|
void |
enableAllCodeTypes()
Enables all code types
|
int |
FWUpdate(java.lang.String FilePath,
boolean forceDownload,
boolean IgnoreSignature)
Update the scanner Firmware.
|
int |
getDecodeCount()
Returns the number of barcodes decoded during a multiple barcode decode
session.
|
byte[] |
getLastDecImage()
Get the last decoded image.
|
int |
getNumParameter(int paramNum)
Returns the value of a specified bar code reader numeric parameter or
BCR_ERROR if the specified parameter number is invalid.
|
int |
getNumProperty(int propNum)
Returns the value of a specified bar code reader numeric property or
BCR_ERROR if the specified property number is invalid.
|
com.zebra.adc.decoder.BarCodeReader.Parameters |
getParameters()
Returns the current settings for this BarCodeReader service.
|
com.zebra.adc.decoder.BarCodeReader.Parameters |
getParametersFromString(java.lang.String s) |
java.lang.String |
getStrParameter(int paramNum)
Returns the value of a specified bar code reader string parameter or
BCR_ERROR if the specified parameter number is invalid.
|
java.lang.String |
getStrProperty(int propNum)
Returns the value of a specified bar code reader string property or null
if the specified property number is invalid.
|
void |
lock()
Re-locks the reader to prevent other processes from accessing it.
|
boolean |
previewEnabled()
Return current preview state.
|
void |
reconnect()
Reconnects to the reader service after another process used it.
|
void |
release()
Disconnects and releases the BarCodeReader object resources.
|
void |
setAutoFocusDelay(int initialDelay,
int secondaryDelay)
Specifies whether or not automatic auto-focus should be performed during
decode operations and if so, how many frames to initially wait before
issuing the the first auto-focus request and how many frames to wait
after receiving an auto-focus complete notification before issuing
another request.
|
void |
setDecodeCallback(com.zebra.adc.decoder.BarCodeReader.DecodeCallback cb)
Installs callbacks to be invoked when a decode request completes or a
decoder event occurs.
|
void |
setDecodeCallback2(BarcodeScanCallback cb) |
void |
setDefaultParameters()
Sets all bar code reader parameters to their default values.
|
void |
setDisplayMode() |
void |
setDisplayOrientation(int degrees)
Set the clockwise rotation of preview display in degrees.
|
void |
setErrorCallback(com.zebra.adc.decoder.BarCodeReader.ErrorCallback cb)
Registers a callback to be invoked when an error occurs.
|
void |
setNoDisplayMode() |
void |
setOneShotPreviewCallback(com.zebra.adc.decoder.BarCodeReader.PreviewCallback cb)
Installs a callback to be invoked for the next preview frame in addition
to displaying it on the screen.
|
int |
setParameter(int paramNum,
int paramVal)
Sets the value of a specified bar code reader numeric parameter.
|
int |
setParameter(int paramNum,
java.lang.String paramVal)
Sets the value of a specified bar code reader string parameter.
|
void |
setParameters(com.zebra.adc.decoder.BarCodeReader.Parameters params)
Changes the settings for this BarCodeReader service.
|
void |
setPreviewCallbackWithBuffer(com.zebra.adc.decoder.BarCodeReader.PreviewCallback cb)
Installs a callback to be invoked for every preview frame, using buffers
supplied with
addCallbackBuffer(byte[]) , in addition to
displaying them on the screen. |
void |
setPreviewDisplay(SurfaceHolder holder)
Sets the
Surface to be used for live preview. |
void |
setZoomChangeListener(com.zebra.adc.decoder.BarCodeReader.OnZoomChangeListener listener)
Registers a listener to be notified when the zoom value is updated by the
reader driver during smooth zoom.
|
int |
startDecode()
Starts capturing frames and passes the captured frames to the decoder.
|
int |
startHandsFreeDecode(int mode)
Starts capturing frames and passes the captured frames to the decoder.
|
void |
startPreview()
Starts capturing frames in preview mode.
|
void |
startSmoothZoom(int value)
Zooms to the requested value smoothly.
|
void |
startVideoCapture(com.zebra.adc.decoder.BarCodeReader.VideoCallback cb)
Starts capturing frames in video mode.
|
void |
startViewFinder(com.zebra.adc.decoder.BarCodeReader.VideoCallback cb)
Starts capturing frames in view finder mode in preparation of taking a
snapshot.
|
void |
stopDecode()
Stops capturing and decoding frames.
|
void |
stopPreview()
Stops capturing and drawing preview frames to the surface, and resets the
reader for a future call to
startPreview() . |
void |
stopSmoothZoom()
Stops the smooth zoom.
|
void |
takePicture(com.zebra.adc.decoder.BarCodeReader.PictureCallback cb)
Triggers an asynchronous image capture.
|
void |
unlock()
Unlocks the reader to allow another process to access it.
|
public static final int DECODE_STATUS_TIMEOUT
public static final int DECODE_STATUS_CANCELED
public static final int DECODE_STATUS_ERROR
public static final int DECODE_STATUS_MULTI_DEC_COUNT
public final void lock()
unlock()
is
called. Normally reconnect()
is used instead.
If you are not recording video, you probably do not need this method.
java.lang.RuntimeException
- if the reader cannot be re-locked (for example, if the reader
is still in use by another process).public final void unlock()
release()
is called. To allow rapid handoff between processes,
you can call this method to release the reader temporarily for another
process to use; once the other process is done you can call
reconnect()
to reclaim the reader.
This must be done before calling
android.media.MediaRecorder#setCamera(BarCodeReader)
.
If you are not recording video, you probably do not need this method.
java.lang.RuntimeException
- if the reader cannot be unlocked.public final void reconnect() throws java.io.IOException
unlock()
is called, another process may use the reader; when the
process is done, you must reconnect to the reader, which will re-acquire
the lock and allow you to continue using the reader.
This must be done after android.media.MediaRecorder
is done
recording if android.media.MediaRecorder#setReader(BarCodeReader)
was used.
If you are not recording video, you probably do not need this method.
java.io.IOException
- if a connection cannot be re-established (for example, if the
reader is still in use by another process).public final int getNumProperty(int propNum)
public final java.lang.String getStrProperty(int propNum)
public final int getNumParameter(int paramNum)
public final java.lang.String getStrParameter(int paramNum)
public final int setParameter(int paramNum, int paramVal)
public final int setParameter(int paramNum, java.lang.String paramVal)
paramNum
- The parameter number to setparamVal
- The new value for the parameterpublic com.zebra.adc.decoder.BarCodeReader.Parameters getParametersFromString(java.lang.String s)
public final void setDefaultParameters()
public final void addCallbackBuffer(byte[] callbackBuffer)
The size of the buffer is determined by multiplying the preview image
width, height, and bytes per pixel. The width and height can be read from
BarCodeReader.Parameters.getPreviewSize()
. Bytes per pixel can be
computed from android.graphics.ImageFormat#getBitsPerPixel(int)
/
8, using the image format from
BarCodeReader.Parameters.getPreviewFormat()
.
This method is only necessary when
setPreviewCallbackWithBuffer(PreviewCallback)
is used. When
setOneShotPreviewCallback(PreviewCallback)
is used, buffers are
automatically allocated.
callbackBuffer
- the buffer to add to the queue. The size should be width *
height * bits_per_pixel / 8.setPreviewCallbackWithBuffer(PreviewCallback)
public final int FWUpdate(java.lang.String FilePath, boolean forceDownload, boolean IgnoreSignature)
FilePath
- - Full path with the filenameforceDownload
- - whether to force download or not - recommended trueIgnoreSignature
- - whether to ignore signature - recommended falsepublic final void startVideoCapture(com.zebra.adc.decoder.BarCodeReader.VideoCallback cb)
setPreviewDisplay(SurfaceHolder)
, the frames will be drawn
to the surface.
BarCodeReader.VideoCallback#onVideoFrame(format, width, height, byte[], BarCodeReader)
will be called when preview data becomes available. The data passed will
be in the format and resolution specified by ParamNum.IMG_FILE_FORMAT and
ParamNum.IMG_VIDEOSUB.
public final void startViewFinder(com.zebra.adc.decoder.BarCodeReader.VideoCallback cb)
setPreviewDisplay(SurfaceHolder)
, the frames will be drawn to
the surface.public final void startPreview()
setPreviewDisplay(SurfaceHolder)
, the frames will be drawn
to the surface.
If setOneShotPreviewCallback(BarCodeReader.PreviewCallback)
or
setPreviewCallbackWithBuffer(BarCodeReader.PreviewCallback)
was
called,
BarCodeReader.PreviewCallback.onPreviewFrame(byte[], BarCodeReader)
will be called when preview data becomes available.
If #setImageCallback(BarCodeReader.ImageCallback)
was called,
BarCodeReader.PreviewCallback#onVideoFrame(format, width, height, byte[], BarCodeReader)
will be called when preview data becomes available. The data passed will
be in the format and resolution specified by ParamNum.IMG_FILE_FORMAT and
ParamNum.IMG_VIDEOSUB.
public final void stopPreview()
startPreview()
.public final int startDecode()
setPreviewDisplay(SurfaceHolder)
, the frames will be drawn to
the surface. When a decode occurs or timeout expires and
setDecodeCallback(BarCodeReader.DecodeCallback)
was called,
#BarCodeReader.DecodeCallback.onDecodeComplete(int, int, byte[], BarCodeReader)
will be called with the decode results.public final int startHandsFreeDecode(int mode)
setPreviewDisplay(SurfaceHolder)
, the frames will be drawn to
the surface. If motion is detected, a motion event is generated. If a
decode occurs a decode event is generated. Decoding continues until
stopDecode()
is called.mode
- Indicates the trigger mode to use. It must be either
#ParamVal.HANDSFREE
or #ParamVal.AUTO_AIM
.public final void stopDecode()
public final boolean previewEnabled()
public final void startSmoothZoom(int value)
OnZoomChangeListener
of the zoom value and whether zoom is
stopped at the time. For example, suppose the current zoom is 0 and
startSmoothZoom is called with value 3. The
BarCodeReader.OnZoomChangeListener.onZoomChange(int, boolean, BarCodeReader)
method will be called three times with zoom values 1, 2, and 3.
Applications can call stopSmoothZoom()
to stop the zoom earlier.
Applications should not call startSmoothZoom again or change the zoom
value before zoom stops. If the supplied zoom value equals to the current
zoom value, no zoom callback will be generated. This method is supported
if
BarCodeReader.Parameters.isSmoothZoomSupported()
returns true.value
- zoom value. The valid range is 0 to
BarCodeReader.Parameters.getMaxZoom()
.java.lang.IllegalArgumentException
- if the zoom value is invalid.java.lang.RuntimeException
- if the method fails.setZoomChangeListener(OnZoomChangeListener)
public final void stopSmoothZoom()
OnZoomChangeListener
to know when the zoom is actually stopped.
This method is supported if
BarCodeReader.Parameters.isSmoothZoomSupported()
is true.java.lang.RuntimeException
- if the method fails.public final void setDisplayOrientation(int degrees)
This does not affect the order of byte array passed in
PreviewCallback#onPreviewFrame
, JPEG pictures, or recorded
videos. This method is not allowed to be called during preview.
If you want to make the reader image show in the same orientation as the display, you can use the following code.
#import com.zebra.adc.decoder; static void setReaderDisplayOrientation(Activity activity, int readerId, BarCodeReader reader) { int result; int degrees = 0; int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); BarCodeReader.ReaderInfo info = new BarCodeReader.ReaderInfo(); BarCodeReader.getReaderInfo(readerId, info); switch (rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; default: break; } if ( info.facing == BarCodeReader.ReaderInfo.BCRDR_FACING_FRONT ) { result = (info.orientation + degrees) % 360; result = (360 - result) % 360; // compensate the mirror } else { // back-facing result = (info.orientation - degrees + 360) % 360; } reader.setDisplayOrientation(result); }
degrees
- the angle that the picture will be rotated clockwise. Valid
values are 0, 90, 180, and 270. The starting position is 0
(landscape).setPreviewDisplay(SurfaceHolder)
public final int getDecodeCount()
public final void enableAllCodeTypes()
public final void disableAllCodeTypes()
public final byte[] getLastDecImage()
public void setNoDisplayMode()
public void setDisplayMode()
public final void release()
You must call this as soon as you're done with the BarCodeReader object.
public final void setPreviewDisplay(SurfaceHolder holder) throws java.io.IOException
Surface
to be used for live preview. A surface is
necessary for preview, and preview is necessary to take pictures. The
same surface can be re-set without harm.
The SurfaceHolder
must already contain a surface when this method
is called. If you are using android.view.SurfaceView
, you will
need to register a SurfaceHolder.Callback
with
SurfaceHolder#addCallback(SurfaceHolder.Callback)
and wait for
SurfaceHolder.Callback#surfaceCreated(SurfaceHolder)
before
calling setPreviewDisplay() or starting preview.
This method must be called before startPreview()
. The one
exception is that if the preview surface is not set (or set to null)
before startPreview() is called, then this method may be called once with
a non-null parameter to set the preview surface. (This allows reader
setup and surface creation to happen in parallel, saving time.) The
preview surface may not otherwise change while preview is running.
holder
- containing the Surface on which to place the preview, or null
to remove the preview surfacejava.io.IOException
- if the method fails (for example, if the surface is
unavailable or unsuitable).public final void autoFocus(com.zebra.adc.decoder.BarCodeReader.AutoFocusCallback cb)
Callers should check
BarCodeReader.Parameters.getFocusMode()
to
determine if this method should be called. If the reader does not support
auto-focus, it is a no-op and
AutoFocusCallback#onAutoFocus(boolean, BarCodeReader)
callback
will be called immediately.
If your application should not be installed on devices without auto-focus, you must declare that your application uses auto-focus with the <uses-feature> manifest element.
If the current flash mode is not
BarCodeReader.Parameters.FLASH_MODE_OFF
,
flash may be fired during auto-focus, depending on the driver and reader
hardware.
cb
- the callback to runcancelAutoFocus()
public final void cancelAutoFocus()
public final void setAutoFocusDelay(int initialDelay, int secondaryDelay)
#Parameters.setFocusMode(String)
and
setParameters(Parameters)
to set the focus mode to
#BarCodeReader.Parameters.FOCUS_MODE_AUTO
.
When this function is used to enable automatic auto-focus requests,
auto-focus callbacks are disabled. If an application needs to receive
auto-focus callbacks, it should issue its own
autoFocus(AutoFocusCallback)
requests and should not call this
function.initialDelay
- the number of frames to process when a decode session is
started before issuing the first auto-focus request. If this
parameter is less than one and secondaryDelay is greater than
zero, an auto-focus request will be issued as soon as the
decode session is started. If both initialDelay and
secondaryDelay are both less than one, no auto-focus requests
will be issued.secondaryDelay
- the number of frames to process after receiving an auto-focus
complete notification before issuing another auto-focus
request. If this parameter is less than one, only the initial
auto-focus request, if any, will be performed.public final void setDecodeCallback(com.zebra.adc.decoder.BarCodeReader.DecodeCallback cb)
cb
- a callback object that receives a notification of a completed,
decode request or null to stop receiving decode callbacks.public final void setDecodeCallback2(BarcodeScanCallback cb)
public final void takePicture(com.zebra.adc.decoder.BarCodeReader.PictureCallback cb)
This method is only valid when the decoder is idle or view finder mode is
active (after calling #startViewFinder()
). Image capture will be
stopped after the picture taken callback is called. Callers must call
#startViewFiner()
and/or takePicture() again if they want to
re-start the view finder or take more pictures.
After calling this method, you must not call startPreview()
,
#startViewFinder()
or take another picture until the picture
taken callback has returned.
cb
- the callback for processed image datapublic final void setOneShotPreviewCallback(com.zebra.adc.decoder.BarCodeReader.PreviewCallback cb)
cb
- a callback object that receives a copy of the next preview
frame, or null to stop receiving callbacks.public final void setPreviewCallbackWithBuffer(com.zebra.adc.decoder.BarCodeReader.PreviewCallback cb)
addCallbackBuffer(byte[])
, in addition to
displaying them on the screen. The callback will be repeatedly called for
as long as preview is active and buffers are available. Any other preview
callbacks are overridden.
The purpose of this method is to improve preview efficiency and frame
rate by allowing preview frame memory reuse. You must call
addCallbackBuffer(byte[])
at some point -- before or after
calling this method -- or no callbacks will received.
The buffer queue will be cleared if this method is called with a null
callback or if
setOneShotPreviewCallback(BarCodeReader.PreviewCallback)
is
called.
cb
- a callback object that receives a copy of the preview frame,
or null to stop receiving callbacks and clear the buffer
queue.addCallbackBuffer(byte[])
public final void setZoomChangeListener(com.zebra.adc.decoder.BarCodeReader.OnZoomChangeListener listener)
listener
- the listener to notifystartSmoothZoom(int)
public final void setErrorCallback(com.zebra.adc.decoder.BarCodeReader.ErrorCallback cb)
cb
- The callback to runpublic void setParameters(com.zebra.adc.decoder.BarCodeReader.Parameters params)
params
- the Parameters to use for this BarCodeReader servicejava.lang.RuntimeException
- if any parameter is invalid or not supported.getParameters()
public com.zebra.adc.decoder.BarCodeReader.Parameters getParameters()
setParameters(BarCodeReader.Parameters)
to take effect.setParameters(BarCodeReader.Parameters)