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
9849a1c2
Commit
9849a1c2
authored
Sep 20, 2017
by
Oscar Fuentes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test camera scan
parent
a278f8bf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
46 deletions
+33
-46
src/android/com/cocodin/barcodescan/plugin/BarcodeScanChainway.java
+2
-12
src/android/com/cocodin/barcodescan/plugin/PluginHelper.java
+31
-34
No files found.
src/android/com/cocodin/barcodescan/plugin/BarcodeScanChainway.java
View file @
9849a1c2
...
...
@@ -9,8 +9,6 @@ import org.apache.cordova.CordovaInterface;
import
org.apache.cordova.CordovaPlugin
;
import
org.apache.cordova.CordovaWebView
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
com.phonegap.plugins.barcodescanner.BarcodeScanner
;
public
class
BarcodeScanChainway
extends
CordovaPlugin
{
...
...
@@ -24,16 +22,8 @@ public class BarcodeScanChainway extends CordovaPlugin {
public
boolean
execute
(
String
action
,
JSONArray
args
,
final
CallbackContext
callbackContext
)
{
PluginHelper
.
init
(
cordova
);
Log
.
d
(
TAG
,
"execute: "
+
action
);
try
{
String
device
=
args
.
get
(
0
).
toString
();
if
(
action
.
equalsIgnoreCase
(
"scan"
)
&&
device
.
equalsIgnoreCase
(
"scanner"
))
{
PluginHelper
.
scan
(
cordova
,
webView
,
args
,
callbackContext
);
}
else
if
(
action
.
equalsIgnoreCase
(
"scan"
)
&&
device
.
equalsIgnoreCase
(
"mobile"
))
{
BarcodeScanner
barcodeScanner
=
new
BarcodeScanner
();
barcodeScanner
.
scan
(
args
);
}
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
if
(
action
.
equalsIgnoreCase
(
"scan"
))
{
PluginHelper
.
scan
(
cordova
,
webView
,
args
,
callbackContext
);
}
return
true
;
}
...
...
src/android/com/cocodin/barcodescan/plugin/PluginHelper.java
View file @
9849a1c2
...
...
@@ -12,6 +12,8 @@ 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
com.phonegap.plugins.barcodescanner.BarcodeScanner
;
import
android.content.Context
;
import
android.os.Message
;
...
...
@@ -38,43 +40,38 @@ public class PluginHelper {
public
static
void
scan
(
CordovaInterface
cordova
,
CordovaWebView
webView
,
JSONArray
args
,
final
CallbackContext
callbackContext
)
{
String
device
=
""
;
try
{
device
=
args
.
get
(
0
).
toString
();
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
callbackContext
.
sendPluginResult
(
new
PluginResult
(
Status
.
ERROR
,
""
));
}
if
(
device
==
"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
;
}
mInstance
.
setScanCallback
(
new
Barcode2DWithSoft
.
ScanCallback
()
{
@Override
public
void
onScanComplete
(
int
i
,
int
length
,
byte
[]
data
)
{
Log
.
i
(
TAG
,
"onScanComplete() i="
+
i
);
String
barCode
=
new
String
(
data
);
barCode
=
barCode
.
replaceAll
(
"\u0000"
,
""
);
Log
.
i
(
TAG
,
barCode
);
if
(
length
<
1
)
{
return
;
callbackContext
.
sendPluginResult
(
new
PluginResult
(
Status
.
OK
,
barCode
));
}
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;
// }
});
mInstance
.
scan
();
}
else
if
(
device
==
"camera"
)
{
BarcodeScanner
barcodeScanner
=
new
BarcodeScanner
();
barcodeScanner
.
cordova
=
cordova
;
barcodeScanner
.
webView
=
webView
;
barcodeScanner
.
execute
(
"scan"
,
new
JSONArray
(),
callbackContext
);
}
}
private
static
class
GetBarcode
implements
Runnable
{
...
...
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