Developed by scan service: Difference between revisions

From wizarPOS
 
(2 intermediate revisions by the same user not shown)
Line 34: Line 34:
|}
|}


==== startScan ====
==== StartScan ====
   <syntaxhighlight lang="java">void startScan(ScanParameter parameter, IScanCallBack callBack);</syntaxhighlight >
   <syntaxhighlight lang="java">void startScan(ScanParameter parameter, IScanCallBack callBack);</syntaxhighlight >
startScan is an asynchronous call interface and indicating the continuous scanning is started.
startScan is an asynchronous call interface and indicating the continuous scanning is started.
Line 49: Line 49:
|}
|}


 
==== StopScan ====
==== stopScan ====
   <syntaxhighlight lang="java">boolean stopScan();</syntaxhighlight >
   <syntaxhighlight lang="java">boolean stopScan();</syntaxhighlight >
This interface Stops the continuous scan, and closes  the scan service's UI.
This interface Stops the continuous scan, and closes  the scan service's UI.
Line 62: Line 61:
| boolean || true / false.
| boolean || true / false.
|}
|}


=== IScanCallBack ===
=== IScanCallBack ===
==== foundBarcode ====
==== FoundBarcode ====
   <syntaxhighlight lang="java">void foundBarcode(ScanResult result);</syntaxhighlight >
   <syntaxhighlight lang="java">void foundBarcode(ScanResult result);</syntaxhighlight >
foundBarcode is a function of IScanCallBack that is a parameter of previous interface.  
foundBarcode is a function of IScanCallBack that is a parameter of previous interface.  

Latest revision as of 03:18, 19 November 2018

The scan service, allows an Android device with imaging hardware (camera) to scan barcodes or 2-D "graphical barcodes" and retrieve the data encoded. Information encoded often includes web addresses, geographical coordinates, and small pieces of text, in addition to commercial product codes. The Android-based system is given similar functionality to a hardware barcode reader.

This application supports many different types of barcode, including those used to identify products in commerce. The Barcode Scanner can automatically search the Web to identify a product with a barcode and use, for example, price-comparison information.

The application can decode several 2-D codes including the widely-used QR and Data Matrix codes. QR codes are often embedded in websites; Barcode Scanner can open a browser at the encoded site, for example, facilitating the download of an application.

API Overview

There are many applications are developed based on smart POS. In one thing, many of the Smart POS developers also have POS industry background,but not professional Android developers. So when they start developing applications, they want to be provided with a convenient scan API by WizarPOS, instead of learning Zxing/Zbar themselves.In other thing,from the hardware point of view, the scan parts used on smart POS, are not necessarily the standard camera, there will be some transformation. In some cases, the scan part will be required to be a specialized hardware. Therefore, the direct use of Zxing/Zbar is not really applicable for WizarPOS smart POS, but need some modification and customization. For the reasons above, we consider to develop WizarPOS Scan Services to facilitate the third party developers in developing applications with scan function.

IScanService

ScanBarcode

ScanResult scanBarcode(ScanParameter parameter);

scanBarcode is a synchronous calling interface.

After the application calls the interface, the scan service opens the camera defined by the scan parameter and then starts the scan. Once getting the result of scanning, the camera is closes and the results are returned immediately.

Parameters
parameter ScanParameter: Scan Parameter
Returns
ScanResult Scan result.

StartScan

void startScan(ScanParameter parameter, IScanCallBack callBack);

startScan is an asynchronous call interface and indicating the continuous scanning is started.

After the application calls this interface, the scan service opens the camera defined by the scan parameter and starts the scan. After every single scanning, the results will be returned during the callback. After each callback is done, the next scanning continue to run starts.

Parameters
parameter ScanParameter: Scan Parameter
callBack IScanCallBack: callback

StopScan

boolean stopScan();

This interface Stops the continuous scan, and closes the scan service's UI.

After stop, other callers can call startScan, or scanBarcode interface.

Returns
boolean true / false.

IScanCallBack

FoundBarcode

void foundBarcode(ScanResult result);

foundBarcode is a function of IScanCallBack that is a parameter of previous interface.

The caller can get the Scan Result through this interface. When this interface is called, the scan service is in the pause state, and when the call in returned, then the next scanning will be continued. You can turn off the scan service that is in pause with “stopScan” that is another interface .

Parameters
ScanResult ScanResult: Scan Result

Scan Parameter

Scan Parameter is a parameter object, it defines the parameters that need by the scan service. method: set(String key, String value) (Value Not case sensitive)

Key Value Type Value Description
window_top int Default: 0,Range: >0 The distance to the screen top. Effect in overlaymode.(dp)
window_left int Default: 0,Range: >0 The distance to the screen left. Effect in overlaymode.(dp)
window_width int Default: screen width,Range: >0 Screen width. Effect in overlaymode.(dp)
window_height int Default: screen ,Range: >0 Screen hight. Effect in overlaymode.(dp)
enable_scan_section boolean Default: true False: all the display window is the area for scanner, remove the scanner frame.

True: customize the area of the scanner, has a scanner frame, the other part is semitransparent, the scanner frame is in center, can adjust the width or the height of the scanner frame.

scan_section_width int Default: 300dip,Range: >0 The width of the scanner frame.
scan_section_height int Default: 300dip,Range: >0 The height of the scanner frame.
display_scan_line String Default: moving,Range: No/fixed/moving Display the red line in scanner area.

NO: Not display Fixed: In center Moving: Move up and down.(dp)

enable_flash_icon boolean Q1): (T|F) Whether to display the hover button of controlling the flash.
enable_switch_icon boolean Default: T Whether to display the hover button of switching camera.
enable_indicator_light boolean Default: F Whether to display the indicator light button, only supported in Q1.
decodeformat String Default: BARCODE_ALL Decode format range.Default is BARCODE_ALL,the formats are separated by “,”.
decoder_mode int Default: 2,Range:0-2 Decode mode:

0: mode1 1: mode2 2: mode3

enable_return_image boolean Default: F Whether to return the scanned image.
camera_index int Default: 0,Range:0-2 0: fixed camera.

1:zomm camera. 2:customer display camera

scan_time_out long (ms) Default: -1,Range: >0 <=0:scan forever

>0:scan with timeout,when timeout, return timeout error, only effected in synchronized interface.

scan_section_border_color int Default: Color.WHITE The color of scan border, use Color.argb
scan_section_corner_color int Default: Color.argb(0xFF,0x21, 0xDB, 0xD5) The color of the scan corner
scan_section_line_color int Default: Color.RED The color of the scan line
scan_tip_textSize int Default: 15 The size of the tip text Unit: sp
scan_tip_textColor int Default: Color.WHITE The distance between the tip text and the bottom of the screen Unit: dp
scan_tip_textMargin int Default: 30 The distance between thetip text and the bottom of the screen Unit: dp
flash_light_state boolean Default: F Initial state of indicator light

true: opened false: closed

indicator_light_state iboolean Default: F Initial state of indicator light

true: opened false: closed

scan_mode String Default: dialog Scanner window mode dialog: activity with specified UI

overlay:only has scanner window, without UItitles, UI buttons, the scanner window on top of other UI activities

scan_camera_exposure int Default: 0 Camera exposure compensation for zoom camera
scan_time_limit int Default: 50 The max decode time
enable_mirror_scan boolean Default: T Enable mirror scan Default is true, opened

Scan Result

Field Type Description
resultCode int >=0: Success

<0: Failure (See also Error Code)

text String The text result, return null when error occurred, the format of the text is UTF-8, if need the other format, please get the raw buffer and change by yourself.
rawBuffer Byte[] The raw buffer
bitmap Bitmap The scanned image, it will return when set the parameter enable_return_image is true.
barcodeFormat String barcodeFormat, see Appendix

Error Code

Value Description


1 Success
0 Cancel
2 The scan UI fully display
-1 The service has been occupied
-2 Can not open the camera
-3 Scan timeout
-3 Illegal parameter

Scan Mode

In dialog mode, the scanner UI has drawed by the camera scanner service, the third app don’t need to consider about the UI.

In overlay mode, the camera scanner service only provide the scanner window, the window will display on top of the third app UI. So the third app can draw the UI by itself, such as the title, the buttons. In this mode, if the app need to switch the camera, the flash light, the indicator light, it must use the broadcast like belows:

  • Camera:

Broadcast Action : com.wizarpos.scanner.setcamera

Broadcast Key: overlay_config

Value: 0 Fixed camera;1 zoom camera; 2 customer display* camera

  • Flash light:

Broadcast Action : com.wizarpos.scanner.setflashlight

Broadcast Key: overlay_config

Value: true opened; false closed

  • Indicator light:

Broadcast Action : com.wizarpos.scanner.setindicator

Broadcast Key : overlay_config

Value: true opened; false closed

Sample Code:

// open the flash light
Intent intent = new Intent();
intent.setAction(ScanParameter.BROADCAST_SET_FLASHLIGHT);
intent.putExtra(ScanParameter.BROADCAST_VALUE, true);
sendBroadcast(intent);

Getting Started

The scan service use AIDL, so the third app must include the AIDL files which provided by WizarPOS.

Bind service

Sample code:

AidlController.getInstance().startScanService(this, this);
.
.
private IScannService scanService; //Scanner service
private ServiceConnection scanConn;
@Override
public void serviceConnected(Object objService, ServiceConnection connection) {
if(objService instanceof IScannService){
scanService = (IScannService) objService;
scanConn = connection;
}
}
.
.
if(scanService != null){
this.unbindService(scanConn);
scanService = null;
scanConn = null;
}

Appendix

Barcode Format

Example:

ScanParameter parameter = new ScanParameter();
parameter.set(ScanParameter.KEY_DECODEFORMAT, " SymbologyType_Aztec, ITF ");

compound barcode format

BARCODE_ALL Includes all the barcodes in the table
BARCODE_1D Includes all the 1D barcodes in the table
BARCODE_2D Includes all the 2D barcodes in the table

Barcode format

AZTEC 2D barcode
DATAMATRIX 2D barcode
QR 2D barcode
MAXICODE 2D barcode
PDF417 2D barcode
CODABAR 1D barcode
CODE39 1D barcode
CODE93 1D barcode
CODE128 1D barcode
EAN8 1D barcode
EAN13 1D barcode
ITF 1D barcode(Interleaved Two of Five)
RSS_14 1D barcode
RSS_EXPANDED 1D barcode
UPCA 1D barcode
UPCE 1D barcode
CODE11 1D barcode