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
b5c02b12
Commit
b5c02b12
authored
Sep 21, 2017
by
Oscar Fuentes
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'development'
parents
60e57475
26ef8e36
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
82 deletions
+36
-82
src/android/com/cocodin/barcodescan/plugin/PluginHelper.java
+34
-80
www/android/barcode-scan-chainway.js
+2
-2
No files found.
src/android/com/cocodin/barcodescan/plugin/PluginHelper.java
View file @
b5c02b12
...
...
@@ -12,6 +12,10 @@ import org.apache.cordova.CallbackContext;
import
org.apache.cordova.PluginResult
;
import
org.apache.cordova.PluginResult.Status
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
com.phonegap.plugins.barcodescanner.BarcodeScanner
;
import
android.content.Context
;
import
android.os.Message
;
...
...
@@ -38,93 +42,43 @@ public class PluginHelper {
public
static
void
scan
(
CordovaInterface
cordova
,
CordovaWebView
webView
,
JSONArray
args
,
final
CallbackContext
callbackContext
)
{
mInstance
.
setScanCallback
(
new
Barcode2DWithSoft
.
ScanCallback
()
{
@Override
public
void
onScanComplete
(
int
i
,
int
length
,
byte
[]
data
)
{
Log
.
i
(
TAG
,
"onScanComplete() i="
+
i
);
if
(
length
<
1
)
{
return
;
}
String
barCode
=
new
String
(
data
);
barCode
=
barCode
.
replaceAll
(
"\u0000"
,
""
);
Log
.
i
(
TAG
,
barCode
);
callbackContext
.
sendPluginResult
(
new
PluginResult
(
Status
.
OK
,
barCode
));
}
});
mInstance
.
scan
();
//
// boolean bContinuous = false;
// Log.i("ErDActivity", "scan() ");
//
// executor = cordova.getThreadPool();
//
// if (threadStop) {
//
// int iBetween = 0;
//
// // thread = new Thread(new GetBarcode(bContinuous, iBetween));
// // thread.start();
//
// executor.execute(new GetBarcode(bContinuous, iBetween));
//
// } else {
// threadStop = true;
// }
}
private
static
class
GetBarcode
implements
Runnable
{
private
boolean
isContinuous
=
false
;
String
barCode
=
""
;
private
long
sleepTime
=
1000
;
Message
msg
=
null
;
public
GetBarcode
(
boolean
isContinuous
)
{
this
.
isContinuous
=
isContinuous
;
}
public
GetBarcode
(
boolean
isContinuous
,
int
sleep
)
{
this
.
isContinuous
=
isContinuous
;
this
.
sleepTime
=
sleep
;
String
device
=
""
;
try
{
device
=
args
.
get
(
0
).
toString
();
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
callbackContext
.
sendPluginResult
(
new
PluginResult
(
Status
.
ERROR
,
""
));
}
if
(
device
.
equalsIgnoreCase
(
"scanner"
))
{
mInstance
.
setScanCallback
(
new
Barcode2DWithSoft
.
ScanCallback
()
{
@Override
public
void
onScanComplete
(
int
i
,
int
length
,
byte
[]
data
)
{
Log
.
i
(
TAG
,
"onScanComplete() i="
+
i
);
if
(
length
<
1
)
{
return
;
}
@Override
public
void
run
()
{
do
{
mInstance
.
scan
();
Log
.
i
(
"MY"
,
"barCode "
+
barCode
.
trim
());
msg
=
new
Message
();
if
(
StringUtility
.
isEmpty
(
barCode
))
{
msg
.
arg1
=
0
;
msg
.
obj
=
""
;
}
else
{
msg
.
arg1
=
1
;
msg
.
obj
=
barCode
;
}
String
barCode
=
new
String
(
data
);
barCode
=
barCode
.
replaceAll
(
"\u0000"
,
""
);
Log
.
i
(
TAG
,
barCode
);
if
(
isContinuous
)
{
try
{
Thread
.
sleep
(
sleepTime
);
}
catch
(
InterruptedException
e
)
{
JSONObject
result
=
new
JSONObject
().
put
(
"text"
,
barCode
);
callbackContext
.
sendPluginResult
(
new
PluginResult
(
Status
.
OK
,
result
));
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
callbackContext
.
sendPluginResult
(
new
PluginResult
(
Status
.
ERROR
,
""
));
}
}
}
while
(
isContinuous
&&
!
threadStop
);
});
mInstance
.
scan
();
}
else
if
(
device
.
equalsIgnoreCase
(
"camera"
))
{
BarcodeScanner
barcodeScanner
=
new
BarcodeScanner
();
barcodeScanner
.
cordova
=
cordova
;
barcodeScanner
.
webView
=
webView
;
barcodeScanner
.
execute
(
"scan"
,
new
JSONArray
(),
callbackContext
);
}
}
}
www/android/barcode-scan-chainway.js
View file @
b5c02b12
...
...
@@ -3,8 +3,8 @@ var exec = require('cordova/exec');
var
PLUGIN_NAME
=
'BarcodeScanChainway'
;
var
BarcodeScanChainway
=
{
scan
:
function
(
cb
,
error
)
{
exec
(
cb
,
error
,
PLUGIN_NAME
,
'scan'
,
[]);
scan
:
function
(
device
,
cb
,
error
)
{
exec
(
cb
,
error
,
PLUGIN_NAME
,
'scan'
,
[
device
]);
}
};
module
.
exports
=
BarcodeScanChainway
;
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