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
c88165e3
Commit
c88165e3
authored
Sep 22, 2017
by
Oscar Fuentes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added getDevices function
parent
26ef8e36
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
40 deletions
+54
-40
src/android/com/cocodin/barcodescan/plugin/BarcodeScanChainway.java
+2
-0
src/android/com/cocodin/barcodescan/plugin/PluginHelper.java
+37
-32
www/android/barcode-scan-chainway.js
+15
-8
No files found.
src/android/com/cocodin/barcodescan/plugin/BarcodeScanChainway.java
View file @
c88165e3
...
@@ -24,6 +24,8 @@ public class BarcodeScanChainway extends CordovaPlugin {
...
@@ -24,6 +24,8 @@ public class BarcodeScanChainway extends CordovaPlugin {
Log
.
d
(
TAG
,
"execute: "
+
action
);
Log
.
d
(
TAG
,
"execute: "
+
action
);
if
(
action
.
equalsIgnoreCase
(
"scan"
))
{
if
(
action
.
equalsIgnoreCase
(
"scan"
))
{
PluginHelper
.
scan
(
cordova
,
webView
,
args
,
callbackContext
);
PluginHelper
.
scan
(
cordova
,
webView
,
args
,
callbackContext
);
}
else
if
(
action
.
equalsIgnoreCase
(
"getDevices"
)){
PluginHelper
.
getDevices
(
cordova
,
webView
,
args
,
callbackContext
);
}
}
return
true
;
return
true
;
}
}
...
...
src/android/com/cocodin/barcodescan/plugin/PluginHelper.java
View file @
c88165e3
package
com
.
cocodin
.
barcodescan
.
plugin
;
package
com
.
cocodin
.
barcodescan
.
plugin
;
import
java.util.Objects
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
com.rscja.utility.StringUtility
;
import
com.zebra.adc.decoder.Barcode2DWithSoft
;
import
com.zebra.adc.decoder.Barcode2DWithSoft
;
import
org.apache.cordova.CordovaInterface
;
import
org.apache.cordova.CordovaInterface
;
...
@@ -18,7 +17,6 @@ import org.json.JSONObject;
...
@@ -18,7 +17,6 @@ import org.json.JSONObject;
import
com.phonegap.plugins.barcodescanner.BarcodeScanner
;
import
com.phonegap.plugins.barcodescanner.BarcodeScanner
;
import
android.content.Context
;
import
android.content.Context
;
import
android.os.Message
;
import
android.util.Log
;
import
android.util.Log
;
public
class
PluginHelper
{
public
class
PluginHelper
{
...
@@ -27,9 +25,12 @@ public class PluginHelper {
...
@@ -27,9 +25,12 @@ public class PluginHelper {
private
static
boolean
threadStop
=
true
;
private
static
boolean
threadStop
=
true
;
private
static
ExecutorService
executor
;
private
static
ExecutorService
executor
;
private
static
Barcode2DWithSoft
mInstance
;
private
static
Barcode2DWithSoft
mInstance
;
private
static
JSONArray
Devices
=
new
JSONArray
();
public
static
void
init
(
CordovaInterface
cordova
)
{
public
static
void
init
(
CordovaInterface
cordova
)
{
Context
context
=
cordova
.
getActivity
();
Context
context
=
cordova
.
getActivity
();
Devices
.
put
(
"camera"
);
Devices
.
put
(
"scanner"
);
try
{
try
{
mInstance
=
Barcode2DWithSoft
.
getInstance
();
mInstance
=
Barcode2DWithSoft
.
getInstance
();
if
(
mInstance
!=
null
)
{
if
(
mInstance
!=
null
)
{
...
@@ -45,40 +46,44 @@ public class PluginHelper {
...
@@ -45,40 +46,44 @@ public class PluginHelper {
String
device
=
""
;
String
device
=
""
;
try
{
try
{
device
=
args
.
get
(
0
).
toString
();
device
=
args
.
get
(
0
).
toString
();
}
catch
(
JSONException
e
)
{
if
(
device
.
equalsIgnoreCase
(
Devices
.
getString
(
0
)))
{
e
.
printStackTrace
();
mInstance
.
setScanCallback
(
new
Barcode2DWithSoft
.
ScanCallback
()
{
callbackContext
.
sendPluginResult
(
new
PluginResult
(
Status
.
ERROR
,
""
));
@Override
}
public
void
onScanComplete
(
int
i
,
int
length
,
byte
[]
data
)
{
if
(
device
.
equalsIgnoreCase
(
"scanner"
))
{
Log
.
i
(
TAG
,
"onScanComplete() i="
+
i
);
mInstance
.
setScanCallback
(
new
Barcode2DWithSoft
.
ScanCallback
()
{
@Override
public
void
onScanComplete
(
int
i
,
int
length
,
byte
[]
data
)
{
Log
.
i
(
TAG
,
"onScanComplete() i="
+
i
);
if
(
length
<
1
)
{
if
(
length
<
1
)
{
return
;
return
;
}
}
String
barCode
=
new
String
(
data
);
String
barCode
=
new
String
(
data
);
barCode
=
barCode
.
replaceAll
(
"\u0000"
,
""
);
barCode
=
barCode
.
replaceAll
(
"\u0000"
,
""
);
Log
.
i
(
TAG
,
barCode
);
Log
.
i
(
TAG
,
barCode
);
try
{
try
{
JSONObject
result
=
new
JSONObject
().
put
(
"text"
,
barCode
);
JSONObject
result
=
new
JSONObject
().
put
(
"text"
,
barCode
);
callbackContext
.
sendPluginResult
(
new
PluginResult
(
Status
.
OK
,
result
));
callbackContext
.
sendPluginResult
(
new
PluginResult
(
Status
.
OK
,
result
));
}
catch
(
JSONException
e
)
{
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
callbackContext
.
sendPluginResult
(
new
PluginResult
(
Status
.
ERROR
,
""
));
callbackContext
.
sendPluginResult
(
new
PluginResult
(
Status
.
ERROR
,
""
));
}
}
}
}
});
});
mInstance
.
scan
();
mInstance
.
scan
();
}
else
if
(
device
.
equalsIgnoreCase
(
"camera"
))
{
}
else
if
(
device
.
equalsIgnoreCase
(
Devices
.
getString
(
1
)))
{
BarcodeScanner
barcodeScanner
=
new
BarcodeScanner
();
BarcodeScanner
barcodeScanner
=
new
BarcodeScanner
();
barcodeScanner
.
cordova
=
cordova
;
barcodeScanner
.
cordova
=
cordova
;
barcodeScanner
.
webView
=
webView
;
barcodeScanner
.
webView
=
webView
;
barcodeScanner
.
execute
(
"scan"
,
new
JSONArray
(),
callbackContext
);
barcodeScanner
.
execute
(
"scan"
,
new
JSONArray
(),
callbackContext
);
}
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
callbackContext
.
sendPluginResult
(
new
PluginResult
(
Status
.
ERROR
,
""
));
}
}
}
}
public
static
void
getDevices
(
CordovaInterface
cordova
,
CordovaWebView
webView
,
JSONArray
args
,
final
CallbackContext
callbackContext
){
callbackContext
.
sendPluginResult
(
new
PluginResult
(
Status
.
OK
,
Devices
));
}
}
}
www/android/barcode-scan-chainway.js
View file @
c88165e3
var
exec
=
require
(
'cordova/exec'
);
cordova
.
define
(
"barcode-scan-chainway.BarcodeScanChainway"
,
function
(
require
,
exports
,
module
)
{
var
exec
=
require
(
'cordova/exec'
);
var
PLUGIN_NAME
=
'BarcodeScanChainway'
;
var
PLUGIN_NAME
=
'BarcodeScanChainway'
;
var
BarcodeScanChainway
=
{
var
BarcodeScanChainway
=
{
scan
:
function
(
device
,
cb
,
error
)
{
scan
:
function
(
device
,
cb
,
error
)
{
exec
(
cb
,
error
,
PLUGIN_NAME
,
'scan'
,
[
device
]);
exec
(
cb
,
error
,
PLUGIN_NAME
,
'scan'
,
[
device
]);
}
},
};
getDevices
:
function
(
cb
,
error
)
{
module
.
exports
=
BarcodeScanChainway
;
exec
(
cb
,
error
,
PLUGIN_NAME
,
'getDevices'
,
[]);
}
};
module
.
exports
=
BarcodeScanChainway
;
});
\ No newline at end of file
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