Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
barcode-scan
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Andrés Branas
barcode-scan
Commits
31d3a16f
Commit
31d3a16f
authored
Oct 25, 2017
by
Alberto Doval
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added initialize method to BaseScan class.
Refactored EDA500K implementation.
parent
63828a3b
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
116 additions
and
47 deletions
+116
-47
plugin.xml
+7
-3
src/android/com/cocodin/barcodescan/plugin/BarcodeScan.java
+51
-24
src/android/com/cocodin/barcodescan/plugin/BaseScan.java
+6
-0
src/android/com/cocodin/barcodescan/plugin/devices/C4050.java
+11
-1
src/android/com/cocodin/barcodescan/plugin/devices/Camera.java
+11
-0
src/android/com/cocodin/barcodescan/plugin/devices/EDA50K.java
+20
-19
src/android/com/cocodin/barcodescan/plugin/devices/NQuire300.java
+10
-0
No files found.
plugin.xml
View file @
31d3a16f
...
...
@@ -24,10 +24,14 @@
<config-file
target=
"res/xml/config.xml"
parent=
"/*"
>
<feature
name=
"BarcodeScan"
>
<param
name=
"android-package"
value=
"com.cocodin.barcodescan.plugin.BarcodeScan"
/>
<param
name=
"onload"
value=
"true"
/>
<param
name=
"android-package"
value=
"com.cocodin.barcodescan.plugin.BarcodeScan"
/>
<param
name=
"onload"
value=
"true"
/>
</feature>
</config-file>
</config-file>
<config-file
target=
"AndroidManifest.xml"
parent=
"/manifest"
>
<uses-permission
android:name=
"android.permission.CAMERA"
/>
<uses-permission
android:name=
"com.honeywell.decode.permission.DECODE"
/>
</config-file>
<source-file
src=
"src/android/com/cocodin/barcodescan/plugin/BarcodeScan.java"
target-dir=
"src/com/cocodin/barcodescan/plugin"
/>
<source-file
src=
"src/android/com/cocodin/barcodescan/plugin/BaseScan.java"
target-dir=
"src/com/cocodin/barcodescan/plugin"
/>
...
...
src/android/com/cocodin/barcodescan/plugin/BarcodeScan.java
View file @
31d3a16f
...
...
@@ -13,6 +13,10 @@ import org.apache.cordova.PluginResult;
import
org.apache.cordova.PluginResult.Status
;
import
org.json.JSONArray
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.Map
;
import
static
android
.
R
.
attr
.
action
;
public
class
BarcodeScan
extends
CordovaPlugin
{
...
...
@@ -30,46 +34,69 @@ public class BarcodeScan extends CordovaPlugin {
private
BaseScan
mDevice
;
public
void
initialize
(
CordovaInterface
cordova
,
CordovaWebView
webView
)
{
private
Map
<
String
,
BaseScan
>
mDevices
=
new
HashMap
<
String
,
BaseScan
>();
public
void
initialize
(
final
CordovaInterface
cordova
,
final
CordovaWebView
webView
)
{
super
.
initialize
(
cordova
,
webView
);
cordova
.
getThreadPool
().
execute
(
new
Runnable
()
{
@Override
public
void
run
()
{
init
(
cordova
,
webView
);
}
});
Log
.
d
(
TAG
,
"Initializing BarcodeScan Plugin"
);
}
public
boolean
execute
(
String
action
,
JSONArray
args
,
final
CallbackContext
callbackContext
)
{
Log
.
d
(
TAG
,
"execute: "
+
action
);
if
(
action
.
equalsIgnoreCase
(
"scan"
)
)
{
public
void
init
(
CordovaInterface
cordova
,
CordovaWebView
webView
)
{
for
(
int
i
=
0
;
i
<
jaDevices
.
length
();
i
++
)
{
try
{
String
deviceName
=
args
.
get
(
0
).
toString
();
//ensure device is created and is the correct device (user could change the device in mobile UI)
if
(
mDevice
==
null
||
!
mDevice
.
getDeviceName
().
equalsIgnoreCase
(
deviceName
))
{
mDevice
=
selectDevice
(
deviceName
);
String
deviceName
=
jaDevices
.
getString
(
i
);
if
(
EDA50K
.
equalsIgnoreCase
(
deviceName
))
{
mDevices
.
put
(
EDA50K
,
new
com
.
cocodin
.
barcodescan
.
plugin
.
devices
.
EDA50K
(
cordova
,
webView
));
}
else
if
(
C4050
.
equalsIgnoreCase
(
deviceName
))
{
mDevices
.
put
(
C4050
,
new
com
.
cocodin
.
barcodescan
.
plugin
.
devices
.
C4050
(
cordova
,
webView
));
}
else
if
(
NQUIRE300
.
equalsIgnoreCase
(
deviceName
))
{
mDevices
.
put
(
NQUIRE300
,
new
com
.
cocodin
.
barcodescan
.
plugin
.
devices
.
NQuire300
(
cordova
,
webView
));
}
else
{
mDevices
.
put
(
CAMERA
,
new
com
.
cocodin
.
barcodescan
.
plugin
.
devices
.
Camera
(
cordova
,
webView
));
}
mDevice
.
scan
(
cordova
,
webView
,
args
,
callbackContext
);
}
catch
(
Exception
e
)
{
Log
.
e
(
TAG
,
e
.
getMessage
());
callbackContext
.
sendPluginResult
(
new
PluginResult
(
Status
.
ERROR
,
e
.
getMessage
()));
}
}
else
if
(
action
.
equalsIgnoreCase
(
"getDevices"
))
{
callbackContext
.
sendPluginResult
(
new
PluginResult
(
PluginResult
.
Status
.
OK
,
jaDevices
));
}
return
true
;
}
public
BaseScan
selectDevice
(
String
deviceName
)
{
if
(
EDA50K
.
equalsIgnoreCase
(
deviceName
))
{
return
new
com
.
cocodin
.
barcodescan
.
plugin
.
devices
.
EDA50K
();
}
else
if
(
C4050
.
equalsIgnoreCase
(
deviceName
))
{
return
new
com
.
cocodin
.
barcodescan
.
plugin
.
devices
.
C4050
();
}
else
if
(
NQUIRE300
.
equalsIgnoreCase
(
deviceName
))
{
return
new
com
.
cocodin
.
barcodescan
.
plugin
.
devices
.
NQuire300
();
public
boolean
execute
(
final
String
action
,
final
JSONArray
args
,
final
CallbackContext
callbackContext
)
{
Log
.
d
(
TAG
,
"execute: "
+
action
);
if
(
action
.
equalsIgnoreCase
(
"scan"
))
{
cordova
.
getThreadPool
().
execute
(
new
Runnable
()
{
@Override
public
void
run
()
{
try
{
String
deviceName
=
args
.
get
(
0
).
toString
();
//ensure device is created and is the correct device (user could change the device in mobile UI)
if
(
mDevice
==
null
||
!
mDevice
.
getDeviceName
().
equalsIgnoreCase
(
deviceName
))
{
mDevice
=
selectDevice
(
deviceName
);
}
mDevice
.
scan
(
cordova
,
webView
,
args
,
callbackContext
);
}
catch
(
Exception
e
)
{
Log
.
e
(
TAG
,
e
.
getMessage
());
callbackContext
.
sendPluginResult
(
new
PluginResult
(
Status
.
ERROR
,
e
.
getMessage
()));
}
}
});
}
else
{
return
new
com
.
cocodin
.
barcodescan
.
plugin
.
devices
.
Camera
(
);
else
if
(
action
.
equalsIgnoreCase
(
"getDevices"
))
{
callbackContext
.
sendPluginResult
(
new
PluginResult
(
PluginResult
.
Status
.
OK
,
jaDevices
)
);
}
return
true
;
}
public
BaseScan
selectDevice
(
String
deviceName
)
{
return
mDevices
.
get
(
deviceName
);
}
@Override
...
...
src/android/com/cocodin/barcodescan/plugin/BaseScan.java
View file @
31d3a16f
...
...
@@ -11,6 +11,12 @@ import org.json.JSONArray;
public
abstract
class
BaseScan
{
public
BaseScan
(
CordovaInterface
cordova
,
CordovaWebView
webView
)
{
};
public
abstract
void
initialize
(
CordovaInterface
cordova
,
CordovaWebView
webView
);
public
abstract
String
getDeviceName
();
public
abstract
void
scan
(
final
CordovaInterface
cordova
,
CordovaWebView
webView
,
JSONArray
args
,
final
CallbackContext
callbackContext
);
...
...
src/android/com/cocodin/barcodescan/plugin/devices/C4050.java
View file @
31d3a16f
...
...
@@ -26,6 +26,16 @@ public class C4050 extends BaseScan {
private
static
Barcode2DWithSoft
mInstance
;
public
C4050
(
CordovaInterface
cordova
,
CordovaWebView
webView
)
{
super
(
cordova
,
webView
);
initialize
(
cordova
,
webView
);
}
@Override
public
void
initialize
(
CordovaInterface
cordova
,
CordovaWebView
webView
)
{
}
@Override
public
String
getDeviceName
()
{
return
TAG
;
...
...
@@ -81,7 +91,7 @@ public class C4050 extends BaseScan {
public
void
onDestroy
()
{
}
@Override
public
void
onResume
(
boolean
multitasking
)
{
...
...
src/android/com/cocodin/barcodescan/plugin/devices/Camera.java
View file @
31d3a16f
...
...
@@ -20,6 +20,17 @@ public class Camera extends BaseScan {
public
String
getDeviceName
()
{
return
TAG
;
}
public
Camera
(
CordovaInterface
cordova
,
CordovaWebView
webView
)
{
super
(
cordova
,
webView
);
initialize
(
cordova
,
webView
);
}
@Override
public
void
initialize
(
CordovaInterface
cordova
,
CordovaWebView
webView
)
{
}
@Override
public
void
scan
(
CordovaInterface
cordova
,
CordovaWebView
webView
,
JSONArray
args
,
CallbackContext
callbackContext
)
{
BarcodeScanner
barcodeScanner
=
new
BarcodeScanner
();
...
...
src/android/com/cocodin/barcodescan/plugin/devices/EDA50K.java
View file @
31d3a16f
...
...
@@ -36,21 +36,24 @@ public class EDA50K extends BaseScan implements BarcodeListener {
private
CallbackContext
currentCallbackContext
=
null
;
public
EDA50K
(
CordovaInterface
cordova
,
CordovaWebView
webView
)
{
super
(
cordova
,
webView
);
initialize
(
cordova
,
webView
);
}
@Override
public
String
getDeviceName
()
{
return
TAG
;
}
@Override
public
void
scan
(
final
CordovaInterface
cordova
,
CordovaWebView
webView
,
JSONArray
args
,
final
CallbackContext
callbackContext
)
{
public
void
initialize
(
final
CordovaInterface
cordova
,
CordovaWebView
webView
)
{
if
(
manager
==
null
)
{
AidcManager
.
create
(
cordova
.
getActivity
(),
new
CreatedCallback
()
{
@Override
public
void
onCreated
(
AidcManager
aidcManager
)
{
manager
=
aidcManager
;
barcodeReader
=
manager
.
createBarcodeReader
(
"dcs.scanner.ring"
);
barcodeReader
=
manager
.
createBarcodeReader
();
if
(
barcodeReader
!=
null
)
{
...
...
@@ -97,19 +100,20 @@ public class EDA50K extends BaseScan implements BarcodeListener {
barcodeReader
.
setProperties
(
properties
);
//Perform first read after initialization
readBarcode
(
callbackContext
);
claim
(
);
}
else
{
callbackContext
.
error
(
"Failed to open barcode reader"
);
}
};
}
});
}
else
{
readBarcode
(
callbackContext
);
}
}
@Override
public
void
scan
(
final
CordovaInterface
cordova
,
CordovaWebView
webView
,
JSONArray
args
,
final
CallbackContext
callbackContext
)
{
this
.
currentCallbackContext
=
callbackContext
;
}
@Override
public
void
onStart
()
{
}
...
...
@@ -139,18 +143,16 @@ public class EDA50K extends BaseScan implements BarcodeListener {
}
}
private
void
readBarcode
(
CallbackContext
callbackContext
)
{
private
void
claim
(
)
{
if
(
barcodeReader
!=
null
)
{
try
{
barcodeReader
.
claim
();
callbackContext
.
success
();
Log
.
d
(
TAG
,
"Claim OK"
);
}
catch
(
ScannerUnavailableException
e
)
{
e
.
printStackTrace
();
callbackContext
.
error
(
"Unable to claim reader"
);
Log
.
e
(
TAG
,
e
.
getMessage
());
}
}
else
{
callbackContext
.
error
(
"Reader not open
"
);
Log
.
e
(
TAG
,
"Barcode reader not opened
"
);
}
}
...
...
@@ -176,9 +178,7 @@ public class EDA50K extends BaseScan implements BarcodeListener {
if
(
currentCallbackContext
!=
null
)
{
try
{
JSONObject
obj
=
new
JSONObject
();
obj
.
put
(
"success"
,
true
);
obj
.
put
(
"data"
,
barcodeReadEvent
.
getBarcodeData
());
obj
.
put
(
"text"
,
barcodeReadEvent
.
getBarcodeData
());
PluginResult
result
=
new
PluginResult
(
PluginResult
.
Status
.
OK
,
obj
);
result
.
setKeepCallback
(
true
);
currentCallbackContext
.
sendPluginResult
(
result
);
...
...
@@ -190,6 +190,7 @@ public class EDA50K extends BaseScan implements BarcodeListener {
@Override
public
void
onFailureEvent
(
BarcodeFailureEvent
barcodeFailureEvent
)
{
Log
.
i
(
TAG
,
"Error reading barcode."
);
if
(
currentCallbackContext
!=
null
)
{
try
{
JSONObject
obj
=
new
JSONObject
();
...
...
src/android/com/cocodin/barcodescan/plugin/devices/NQuire300.java
View file @
31d3a16f
...
...
@@ -28,6 +28,16 @@ public class NQuire300 extends BaseScan {
return
TAG
;
}
public
NQuire300
(
CordovaInterface
cordova
,
CordovaWebView
webView
)
{
super
(
cordova
,
webView
);
initialize
(
cordova
,
webView
);
}
@Override
public
void
initialize
(
CordovaInterface
cordova
,
CordovaWebView
webView
)
{
}
@Override
public
void
scan
(
CordovaInterface
cordova
,
CordovaWebView
webView
,
JSONArray
args
,
CallbackContext
callbackContext
)
{
Context
context
=
cordova
.
getActivity
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment