Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hls-plugin-barcode
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
hlsplugin
hls-plugin-barcode
Commits
bcc9e0cf
Commit
bcc9e0cf
authored
Mar 07, 2018
by
JingChao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
'update'
parent
cc15978b
Changes
33
Show whitespace changes
Inline
Side-by-side
Showing
33 changed files
with
58 additions
and
3502 deletions
+58
-3502
README.md
README.md
+20
-46
plugin.xml
plugin.xml
+37
-37
android-install.js
scripts/android-install.js
+1
-1
BarcodePlugin.java
...droid/src/com/jieweifu/plugins/barcode/BarcodePlugin.java
+0
-152
CaptureActivity.java
...oid/src/com/jieweifu/plugins/barcode/CaptureActivity.java
+0
-513
CapturePresenter.java
...id/src/com/jieweifu/plugins/barcode/CapturePresenter.java
+0
-257
ICaptureActivity.java
...id/src/com/jieweifu/plugins/barcode/ICaptureActivity.java
+0
-20
NoSSLv3SocketFactory.java
...m/jieweifu/plugins/barcode/Util/NoSSLv3SocketFactory.java
+0
-407
Util.java
src/android/src/com/jieweifu/plugins/barcode/Util/Util.java
+0
-21
ZbarManager.java
...android/src/com/jieweifu/plugins/barcode/ZbarManager.java
+0
-10
DialogToast.java
...rc/com/jieweifu/plugins/barcode/activity/DialogToast.java
+0
-75
IUnOpenWebActivity.java
...jieweifu/plugins/barcode/activity/IUnOpenWebActivity.java
+0
-12
NetWorkErrorActivity.java
...eweifu/plugins/barcode/activity/NetWorkErrorActivity.java
+0
-67
UnOpenWebActivity.java
.../jieweifu/plugins/barcode/activity/UnOpenWebActivity.java
+0
-135
UnOpenWebActivityPresenter.java
.../plugins/barcode/activity/UnOpenWebActivityPresenter.java
+0
-61
ArgsBean.java
...droid/src/com/jieweifu/plugins/barcode/bean/ArgsBean.java
+0
-80
ArgsBiz.java
...ndroid/src/com/jieweifu/plugins/barcode/bean/ArgsBiz.java
+0
-97
CodeInfoBean.java
...d/src/com/jieweifu/plugins/barcode/bean/CodeInfoBean.java
+0
-49
HttpInfoBean.java
...d/src/com/jieweifu/plugins/barcode/bean/HttpInfoBean.java
+0
-194
PageInfoBean.java
...d/src/com/jieweifu/plugins/barcode/bean/PageInfoBean.java
+0
-228
AutoFocusCallback.java
...om/jieweifu/plugins/barcode/camera/AutoFocusCallback.java
+0
-32
CameraConfigurationManager.java
...fu/plugins/barcode/camera/CameraConfigurationManager.java
+0
-242
CameraManager.java
...rc/com/jieweifu/plugins/barcode/camera/CameraManager.java
+0
-134
FlashlightManager.java
...om/jieweifu/plugins/barcode/camera/FlashlightManager.java
+0
-118
PreviewCallback.java
.../com/jieweifu/plugins/barcode/camera/PreviewCallback.java
+0
-43
CaptureActivityHandler.java
...eweifu/plugins/barcode/decode/CaptureActivityHandler.java
+0
-73
DecodeHandler.java
...rc/com/jieweifu/plugins/barcode/decode/DecodeHandler.java
+0
-60
DecodeThread.java
...src/com/jieweifu/plugins/barcode/decode/DecodeThread.java
+0
-38
FinishListener.java
...c/com/jieweifu/plugins/barcode/decode/FinishListener.java
+0
-27
InactivityTimer.java
.../com/jieweifu/plugins/barcode/decode/InactivityTimer.java
+0
-49
HttpManager.java
...id/src/com/jieweifu/plugins/barcode/http/HttpManager.java
+0
-100
HttpUtil.java
...droid/src/com/jieweifu/plugins/barcode/http/HttpUtil.java
+0
-113
ResultCallback.java
...src/com/jieweifu/plugins/barcode/http/ResultCallback.java
+0
-11
No files found.
README.md
View file @
bcc9e0cf
...
@@ -8,57 +8,31 @@ This plugin implements barcode scanner on Cordova 4.0
...
@@ -8,57 +8,31 @@ This plugin implements barcode scanner on Cordova 4.0
*
iOS 7.0.0 or above
*
iOS 7.0.0 or above
## Usage
## Usage
cordova plugin add https://github.com/
MrLiZ/HuiLianYi-barC
ode.git
cordova plugin add https://github.com/
nature2104/hls-plugin-barc
ode.git
## JS
## JS
```
js
```
js
com
.
jieweifu
.
plugins
.
barcode
.
startScan
({
com
.
hls
.
plugins
.
barcode
.
startScan
({
message
:{
message
:{
barTitle
:
'标题栏文案'
,
barTitle
:
"扫描二维码"
,
//扫码页面标题
explainFlag
:
false
,
//是否显示说明按钮
explainFlag
:
false
,
title
:
'扫码上方描述'
,
title
:
""
,
tipScan
:
'扫码下方描述'
,
tipScan
:
"对准发票二维码进行扫码"
,
inputFlag
:
true
,
//是否显示输入按钮
inputFlag
:
false
,
lightFlag
:
true
,
//是否显示照亮按钮
lightFlag
:
true
,
tipInput
:
'输入单号提示'
,
tipInput
:
"手工输入"
,
tipLightOn
:
'打开照亮提示'
,
tipLightOn
:
"打开照亮"
,
tipLightOff
:
'关闭照亮提示'
,
tipLightOff
:
"关闭照亮"
,
tipLoading
:
'调接口的过程中的提示'
,
tipLoading
:
"正在处理中... "
,
tipNetworkError
:
'网络错误时的提示'
,
tipNetworkError
:
"当前网络不可用, 请检查网络设置"
tipOffline
:
'没有打开web时的提示'
,
openButton
:
'我已打开按钮文字'
,
footerFirst
:
'底部提示第一行,可空'
,
footerSecond
:
'底部提示第二行,可空'
,
delayTime
:
'1000'
},
operationType
:
'REVIEW'
,
requests
:[
{
url
:
'www.huilianyi.com'
,
method
:
'POST'
,
headers
:{
Authorization
:
'Bearer xxxxx'
,
Content
-
Type
:
'xxxx'
},
config
:
{
timeout
:
10000
(
单位是毫秒
)
},
},
operationType
:
'SCAN'
,
data
:{
requests
:[]
code
:
'xxxx-xxxx'
,
operate
:
'xxxx'
}
},
...
]
},
function
(
success
){
},
function
(
success
){
alert
(
JSON
.
stringify
(
success
));
alert
(
JSON
.
stringify
(
success
));
},
function
(
error
){
},
function
(
error
){
alert
(
JSON
.
stringify
(
error
));
alert
(
JSON
.
stringify
(
error
));
});
});
;
```
```
...
...
plugin.xml
View file @
bcc9e0cf
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<plugin
id=
"com.
jieweifu
.plugins.barcode"
version=
"0.0.1"
xmlns=
"http://apache.org/cordova/ns/plugins/1.0"
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<plugin
id=
"com.
hls
.plugins.barcode"
version=
"0.0.1"
xmlns=
"http://apache.org/cordova/ns/plugins/1.0"
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<name>
barcode
</name>
<name>
barcode
</name>
<description>
JieWeiFu
barcode cordova plugin
</description>
<description>
hls
barcode cordova plugin
</description>
<engines>
<engines>
<engine
name=
"cordova"
version=
">=3.4.0"
/>
<engine
name=
"cordova"
version=
">=3.4.0"
/>
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
<dependency
id=
"cordova-plugin-compat"
></dependency>
<dependency
id=
"cordova-plugin-compat"
></dependency>
<js-module
src=
"www/barcode.js"
>
<js-module
src=
"www/barcode.js"
>
<clobbers
target=
"com.
jieweifu
.plugins.barcode"
/>
<clobbers
target=
"com.
hls
.plugins.barcode"
/>
</js-module>
</js-module>
<platform
name=
"android"
>
<platform
name=
"android"
>
...
@@ -21,18 +21,18 @@
...
@@ -21,18 +21,18 @@
<config-file
target=
"res/xml/config.xml"
parent=
"/*"
>
<config-file
target=
"res/xml/config.xml"
parent=
"/*"
>
<feature
name=
"Barcode"
>
<feature
name=
"Barcode"
>
<param
name=
"android-package"
value=
"com.
jieweifu
.plugins.barcode.BarcodePlugin"
/>
<param
name=
"android-package"
value=
"com.
hls
.plugins.barcode.BarcodePlugin"
/>
</feature>
</feature>
</config-file>
</config-file>
<config-file
target=
"AndroidManifest.xml"
parent=
"/manifest/application"
>
<config-file
target=
"AndroidManifest.xml"
parent=
"/manifest/application"
>
<activity
<activity
android:name=
"com.
jieweifu
.plugins.barcode.CaptureActivity"
android:name=
"com.
hls
.plugins.barcode.CaptureActivity"
android:screenOrientation=
"portrait"
android:screenOrientation=
"portrait"
android:theme=
"@android:style/Theme.Light.NoTitleBar"
>
android:theme=
"@android:style/Theme.Light.NoTitleBar"
>
</activity>
</activity>
<activity
android:name=
"com.
jieweifu
.plugins.barcode.activity.NetWorkErrorActivity"
android:screenOrientation=
"portrait"
/>
<activity
android:name=
"com.
hls
.plugins.barcode.activity.NetWorkErrorActivity"
android:screenOrientation=
"portrait"
/>
<activity
android:name=
"com.
jieweifu
.plugins.barcode.activity.UnOpenWebActivity"
android:screenOrientation=
"portrait"
/>
<activity
android:name=
"com.
hls
.plugins.barcode.activity.UnOpenWebActivity"
android:screenOrientation=
"portrait"
/>
</config-file>
</config-file>
<config-file
target=
"AndroidManifest.xml"
parent=
"/manifest"
>
<config-file
target=
"AndroidManifest.xml"
parent=
"/manifest"
>
...
@@ -50,41 +50,41 @@
...
@@ -50,41 +50,41 @@
<source-file
src=
"src/android/libs/armeabi-v7a/libzbar.so"
target-dir=
"libs/armeabi-v7a"
/>
<source-file
src=
"src/android/libs/armeabi-v7a/libzbar.so"
target-dir=
"libs/armeabi-v7a"
/>
<source-file
src=
"src/android/libs/x86/libzbar.so"
target-dir=
"libs/x86"
/>
<source-file
src=
"src/android/libs/x86/libzbar.so"
target-dir=
"libs/x86"
/>
<source-file
src=
"src/android/libs/x86_64/libzbar.so"
target-dir=
"libs/x86_64"
/>
<source-file
src=
"src/android/libs/x86_64/libzbar.so"
target-dir=
"libs/x86_64"
/>
<source-file
src=
"src/android/src/com/
jieweifu/plugins/barcode/BarcodePlugin.java"
target-dir=
"src/com/jieweifu
/plugins/barcode"
/>
<source-file
src=
"src/android/src/com/
hls/plugins/barcode/BarcodePlugin.java"
target-dir=
"src/com/hls
/plugins/barcode"
/>
<source-file
src=
"src/android/src/com/
jieweifu/plugins/barcode/CaptureActivity.java"
target-dir=
"src/com/jieweifu
/plugins/barcode"
/>
<source-file
src=
"src/android/src/com/
hls/plugins/barcode/CaptureActivity.java"
target-dir=
"src/com/hls
/plugins/barcode"
/>
<source-file
src=
"src/android/src/com/
jieweifu
/plugins/barcode/ZbarManager.java"
target-dir=
"src/com/zbar/lib"
/>
<source-file
src=
"src/android/src/com/
hls
/plugins/barcode/ZbarManager.java"
target-dir=
"src/com/zbar/lib"
/>
<source-file
src=
"src/android/src/com/
jieweifu/plugins/barcode/camera/AutoFocusCallback.java"
target-dir=
"src/com/jieweifu
/plugins/barcode/camera"
/>
<source-file
src=
"src/android/src/com/
hls/plugins/barcode/camera/AutoFocusCallback.java"
target-dir=
"src/com/hls
/plugins/barcode/camera"
/>
<source-file
src=
"src/android/src/com/
jieweifu/plugins/barcode/camera/CameraConfigurationManager.java"
target-dir=
"src/com/jieweifu
/plugins/barcode/camera"
/>
<source-file
src=
"src/android/src/com/
hls/plugins/barcode/camera/CameraConfigurationManager.java"
target-dir=
"src/com/hls
/plugins/barcode/camera"
/>
<source-file
src=
"src/android/src/com/
jieweifu/plugins/barcode/camera/CameraManager.java"
target-dir=
"src/com/jieweifu
/plugins/barcode/camera"
/>
<source-file
src=
"src/android/src/com/
hls/plugins/barcode/camera/CameraManager.java"
target-dir=
"src/com/hls
/plugins/barcode/camera"
/>
<source-file
src=
"src/android/src/com/
jieweifu/plugins/barcode/camera/FlashlightManager.java"
target-dir=
"src/com/jieweifu
/plugins/barcode/camera"
/>
<source-file
src=
"src/android/src/com/
hls/plugins/barcode/camera/FlashlightManager.java"
target-dir=
"src/com/hls
/plugins/barcode/camera"
/>
<source-file
src=
"src/android/src/com/
jieweifu/plugins/barcode/camera/PreviewCallback.java"
target-dir=
"src/com/jieweifu
/plugins/barcode/camera"
/>
<source-file
src=
"src/android/src/com/
hls/plugins/barcode/camera/PreviewCallback.java"
target-dir=
"src/com/hls
/plugins/barcode/camera"
/>
<source-file
src=
"src/android/src/com/
jieweifu/plugins/barcode/decode/CaptureActivityHandler.java"
target-dir=
"src/com/jieweifu
/plugins/barcode/decode"
/>
<source-file
src=
"src/android/src/com/
hls/plugins/barcode/decode/CaptureActivityHandler.java"
target-dir=
"src/com/hls
/plugins/barcode/decode"
/>
<source-file
src=
"src/android/src/com/
jieweifu/plugins/barcode/decode/DecodeHandler.java"
target-dir=
"src/com/jieweifu
/plugins/barcode/decode"
/>
<source-file
src=
"src/android/src/com/
hls/plugins/barcode/decode/DecodeHandler.java"
target-dir=
"src/com/hls
/plugins/barcode/decode"
/>
<source-file
src=
"src/android/src/com/
jieweifu/plugins/barcode/decode/DecodeThread.java"
target-dir=
"src/com/jieweifu
/plugins/barcode/decode"
/>
<source-file
src=
"src/android/src/com/
hls/plugins/barcode/decode/DecodeThread.java"
target-dir=
"src/com/hls
/plugins/barcode/decode"
/>
<source-file
src=
"src/android/src/com/
jieweifu/plugins/barcode/decode/FinishListener.java"
target-dir=
"src/com/jieweifu
/plugins/barcode/decode"
/>
<source-file
src=
"src/android/src/com/
hls/plugins/barcode/decode/FinishListener.java"
target-dir=
"src/com/hls
/plugins/barcode/decode"
/>
<source-file
src=
"src/android/src/com/
jieweifu/plugins/barcode/decode/InactivityTimer.java"
target-dir=
"src/com/jieweifu
/plugins/barcode/decode"
/>
<source-file
src=
"src/android/src/com/
hls/plugins/barcode/decode/InactivityTimer.java"
target-dir=
"src/com/hls
/plugins/barcode/decode"
/>
<source-file
src=
"src/android/src/com/
jieweifu/plugins/barcode/activity/DialogToast.java"
target-dir=
"src/com/jieweifu
/plugins/barcode/activity"
/>
<source-file
src=
"src/android/src/com/
hls/plugins/barcode/activity/DialogToast.java"
target-dir=
"src/com/hls
/plugins/barcode/activity"
/>
<source-file
src=
"src/android/src/com/
jieweifu/plugins/barcode/activity/IUnOpenWebActivity.java"
target-dir=
"src/com/jieweifu
/plugins/barcode/activity"
/>
<source-file
src=
"src/android/src/com/
hls/plugins/barcode/activity/IUnOpenWebActivity.java"
target-dir=
"src/com/hls
/plugins/barcode/activity"
/>
<source-file
src=
"src/android/src/com/
jieweifu/plugins/barcode/activity/NetWorkErrorActivity.java"
target-dir=
"src/com/jieweifu
/plugins/barcode/activity"
/>
<source-file
src=
"src/android/src/com/
hls/plugins/barcode/activity/NetWorkErrorActivity.java"
target-dir=
"src/com/hls
/plugins/barcode/activity"
/>
<source-file
src=
"src/android/src/com/
jieweifu/plugins/barcode/activity/UnOpenWebActivity.java"
target-dir=
"src/com/jieweifu
/plugins/barcode/activity"
/>
<source-file
src=
"src/android/src/com/
hls/plugins/barcode/activity/UnOpenWebActivity.java"
target-dir=
"src/com/hls
/plugins/barcode/activity"
/>
<source-file
src=
"src/android/src/com/
jieweifu/plugins/barcode/activity/UnOpenWebActivityPresenter.java"
target-dir=
"src/com/jieweifu
/plugins/barcode/activity"
/>
<source-file
src=
"src/android/src/com/
hls/plugins/barcode/activity/UnOpenWebActivityPresenter.java"
target-dir=
"src/com/hls
/plugins/barcode/activity"
/>
<source-file
src=
"src/android/src/com/
jieweifu/plugins/barcode/bean/ArgsBean.java"
target-dir=
"src/com/jieweifu
/plugins/barcode/bean"
/>
<source-file
src=
"src/android/src/com/
hls/plugins/barcode/bean/ArgsBean.java"
target-dir=
"src/com/hls
/plugins/barcode/bean"
/>
<source-file
src=
"src/android/src/com/
jieweifu/plugins/barcode/bean/ArgsBiz.java"
target-dir=
"src/com/jieweifu
/plugins/barcode/bean"
/>
<source-file
src=
"src/android/src/com/
hls/plugins/barcode/bean/ArgsBiz.java"
target-dir=
"src/com/hls
/plugins/barcode/bean"
/>
<source-file
src=
"src/android/src/com/
jieweifu/plugins/barcode/bean/CodeInfoBean.java"
target-dir=
"src/com/jieweifu
/plugins/barcode/bean"
/>
<source-file
src=
"src/android/src/com/
hls/plugins/barcode/bean/CodeInfoBean.java"
target-dir=
"src/com/hls
/plugins/barcode/bean"
/>
<source-file
src=
"src/android/src/com/
jieweifu/plugins/barcode/bean/HttpInfoBean.java"
target-dir=
"src/com/jieweifu
/plugins/barcode/bean"
/>
<source-file
src=
"src/android/src/com/
hls/plugins/barcode/bean/HttpInfoBean.java"
target-dir=
"src/com/hls
/plugins/barcode/bean"
/>
<source-file
src=
"src/android/src/com/
jieweifu/plugins/barcode/bean/PageInfoBean.java"
target-dir=
"src/com/jieweifu
/plugins/barcode/bean"
/>
<source-file
src=
"src/android/src/com/
hls/plugins/barcode/bean/PageInfoBean.java"
target-dir=
"src/com/hls
/plugins/barcode/bean"
/>
<source-file
src=
"src/android/src/com/
jieweifu/plugins/barcode/http/HttpManager.java"
target-dir=
"src/com/jieweifu
/plugins/barcode/http"
/>
<source-file
src=
"src/android/src/com/
hls/plugins/barcode/http/HttpManager.java"
target-dir=
"src/com/hls
/plugins/barcode/http"
/>
<source-file
src=
"src/android/src/com/
jieweifu/plugins/barcode/http/HttpUtil.java"
target-dir=
"src/com/jieweifu
/plugins/barcode/http"
/>
<source-file
src=
"src/android/src/com/
hls/plugins/barcode/http/HttpUtil.java"
target-dir=
"src/com/hls
/plugins/barcode/http"
/>
<source-file
src=
"src/android/src/com/
jieweifu/plugins/barcode/http/ResultCallback.java"
target-dir=
"src/com/jieweifu
/plugins/barcode/http"
/>
<source-file
src=
"src/android/src/com/
hls/plugins/barcode/http/ResultCallback.java"
target-dir=
"src/com/hls
/plugins/barcode/http"
/>
<source-file
src=
"src/android/src/com/
jieweifu/plugins/barcode/Util/Util.java"
target-dir=
"src/com/jieweifu
/plugins/barcode/Util"
/>
<source-file
src=
"src/android/src/com/
hls/plugins/barcode/Util/Util.java"
target-dir=
"src/com/hls
/plugins/barcode/Util"
/>
<source-file
src=
"src/android/src/com/
jieweifu/plugins/barcode/Util/NoSSLv3SocketFactory.java"
target-dir=
"src/com/jieweifu
/plugins/barcode/Util"
/>
<source-file
src=
"src/android/src/com/
hls/plugins/barcode/Util/NoSSLv3SocketFactory.java"
target-dir=
"src/com/hls
/plugins/barcode/Util"
/>
<source-file
src=
"src/android/src/com/
jieweifu/plugins/barcode/CapturePresenter.java"
target-dir=
"src/com/jieweifu
/plugins/barcode"
/>
<source-file
src=
"src/android/src/com/
hls/plugins/barcode/CapturePresenter.java"
target-dir=
"src/com/hls
/plugins/barcode"
/>
<source-file
src=
"src/android/src/com/
jieweifu/plugins/barcode/ICaptureActivity.java"
target-dir=
"src/com/jieweifu
/plugins/barcode"
/>
<source-file
src=
"src/android/src/com/
hls/plugins/barcode/ICaptureActivity.java"
target-dir=
"src/com/hls
/plugins/barcode"
/>
...
...
scripts/android-install.js
View file @
bcc9e0cf
...
@@ -19,7 +19,7 @@ module.exports = function (context) {
...
@@ -19,7 +19,7 @@ module.exports = function (context) {
return
;
return
;
}
}
var
targetDir
=
path
.
join
(
projectRoot
,
"platforms"
,
"android"
,
"src"
,
"com"
,
"
jieweifu
"
,
"plugins"
,
"barcode"
);
var
targetDir
=
path
.
join
(
projectRoot
,
"platforms"
,
"android"
,
"src"
,
"com"
,
"
hls
"
,
"plugins"
,
"barcode"
);
var
targetFiles
=
[
"CaptureActivity.java"
,
"decode/DecodeHandler.java"
,
"decode/CaptureActivityHandler.java"
,
"activity/DialogToast.java"
,
"activity/NetWorkErrorActivity.java"
,
"activity/UnOpenWebActivity.java"
];
var
targetFiles
=
[
"CaptureActivity.java"
,
"decode/DecodeHandler.java"
,
"decode/CaptureActivityHandler.java"
,
"activity/DialogToast.java"
,
"activity/NetWorkErrorActivity.java"
,
"activity/UnOpenWebActivity.java"
];
if
([
'after_plugin_add'
,
'after_plugin_install'
,
'after_platform_add'
].
indexOf
(
context
.
hook
)
===
-
1
)
{
if
([
'after_plugin_add'
,
'after_plugin_install'
,
'after_platform_add'
].
indexOf
(
context
.
hook
)
===
-
1
)
{
...
...
src/android/src/com/jieweifu/plugins/barcode/BarcodePlugin.java
deleted
100644 → 0
View file @
cc15978b
package
com
.
jieweifu
.
plugins
.
barcode
;
import
org.apache.cordova.CallbackContext
;
import
org.apache.cordova.CordovaPlugin
;
import
org.apache.cordova.PermissionHelper
;
import
org.apache.cordova.PluginResult
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
android.Manifest
;
import
android.content.Intent
;
import
android.content.pm.PackageManager
;
import
android.hardware.Camera
;
import
android.util.Log
;
import
android.widget.Toast
;
import
com.jieweifu.plugins.barcode.Util.Util
;
import
com.jieweifu.plugins.barcode.activity.NetWorkErrorActivity
;
import
com.jieweifu.plugins.barcode.activity.UnOpenWebActivity
;
import
com.jieweifu.plugins.barcode.bean.ArgsBean
;
import
com.jieweifu.plugins.barcode.bean.ArgsBiz
;
/**
* Created by Administrator on 2016/3/16.
*/
public
class
BarcodePlugin
extends
CordovaPlugin
{
public
static
CallbackContext
cbContext
=
null
;
private
static
final
String
LOG_TAG
=
"BarcodeScanner"
;
private
String
[]
permissions
=
{
Manifest
.
permission
.
CAMERA
};
private
JSONArray
args
;
@Override
public
boolean
execute
(
String
action
,
final
JSONArray
args
,
CallbackContext
callbackContext
)
throws
JSONException
{
cbContext
=
callbackContext
;
if
(
action
.
equals
(
"startScan"
))
{
this
.
args
=
args
;
if
(!
hasPermission
())
{
requestPermissions
(
0
);
}
else
{
scan
(
args
);
}
}
else
if
(
action
.
equals
(
"hasPermission"
))
{
if
(!
hasPermission
())
{
requestPermissions
(
0
);
}
cbContext
.
success
(
hasPermission
()
+
""
);
return
true
;
}
return
true
;
}
/**
* Starts an intent to scan and decode a barcode.
*/
public
void
scan
(
final
JSONArray
args
)
{
try
{
ArgsBiz
argsBiz
=
new
ArgsBiz
();
ArgsBean
argsBean
;
argsBean
=
argsBiz
.
getArgsBeanByJSONObject
(
args
.
getJSONObject
(
0
));
if
(!
Util
.
isNetworkAvailable
(
cordova
.
getActivity
()))
{
Intent
intent
=
new
Intent
(
cordova
.
getActivity
(),
NetWorkErrorActivity
.
class
);
intent
.
putExtra
(
"ARGS"
,
argsBean
);
this
.
cordova
.
getActivity
().
startActivity
(
intent
);
return
;
}
if
(
argsBean
!=
null
)
{
Intent
intentScan
=
new
Intent
(
this
.
cordova
.
getActivity
().
getApplicationContext
(),
CaptureActivity
.
class
);
intentScan
.
putExtra
(
"ARGS"
,
argsBean
);
this
.
cordova
.
getActivity
().
startActivity
(
intentScan
);
}
else
{
cbContext
.
success
(
"请检查参数"
);
}
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
cbContext
.
success
(
"请检查参数"
);
}
}
/**
* check application's permissions
*/
public
boolean
hasPermission
()
{
for
(
String
p
:
permissions
)
{
if
(!
PermissionHelper
.
hasPermission
(
this
,
p
))
{
return
false
;
}
else
{
boolean
isCanUse
=
true
;
Camera
mCamera
=
null
;
try
{
mCamera
=
Camera
.
open
();
Camera
.
Parameters
mParameters
=
mCamera
.
getParameters
();
// 针对魅族手机
mCamera
.
setParameters
(
mParameters
);
}
catch
(
Exception
e
)
{
isCanUse
=
false
;
}
if
(
mCamera
!=
null
)
{
try
{
mCamera
.
release
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
isCanUse
;
}
}
return
isCanUse
;
}
}
return
true
;
}
/**
* We override this so that we can access the permissions variable, which no
* longer exists in the parent class, since we can't initialize it reliably
* in the constructor!
*
* @param requestCode The code to get request action
*/
public
void
requestPermissions
(
int
requestCode
)
{
PermissionHelper
.
requestPermissions
(
this
,
requestCode
,
permissions
);
}
/**
* processes the result of permission request
*
* @param requestCode The code to get request action
* @param permissions The collection of permissions
* @param grantResults The result of grant
*/
public
void
onRequestPermissionResult
(
int
requestCode
,
String
[]
permissions
,
int
[]
grantResults
)
throws
JSONException
{
PluginResult
result
;
// Toast.makeText(this.cordova.getActivity().getApplicationContext(), grantResults.toString(), 3).show();
for
(
int
r
:
grantResults
)
{
if
(
r
==
PackageManager
.
PERMISSION_DENIED
)
{
Log
.
d
(
LOG_TAG
,
"Permission Denied!"
);
result
=
new
PluginResult
(
PluginResult
.
Status
.
ILLEGAL_ACCESS_EXCEPTION
);
cbContext
.
sendPluginResult
(
result
);
return
;
}
}
if
(
args
!=
null
){
scan
(
args
);
}
}
}
src/android/src/com/jieweifu/plugins/barcode/CaptureActivity.java
deleted
100644 → 0
View file @
cc15978b
package
com
.
jieweifu
.
plugins
.
barcode
;
import
java.io.IOException
;
import
java.util.Timer
;
import
java.util.TimerTask
;
import
__ANDROID_PACKAGE__.R
;
import
com.jieweifu.plugins.barcode.Util.Util
;
import
com.jieweifu.plugins.barcode.activity.DialogToast
;
import
com.jieweifu.plugins.barcode.activity.NetWorkErrorActivity
;
import
com.jieweifu.plugins.barcode.activity.UnOpenWebActivity
;
import
com.jieweifu.plugins.barcode.bean.ArgsBean
;
import
com.jieweifu.plugins.barcode.camera.CameraManager
;
import
com.jieweifu.plugins.barcode.decode.CaptureActivityHandler
;
import
com.jieweifu.plugins.barcode.decode.InactivityTimer
;
import
com.jieweifu.plugins.barcode.http.HttpManager
;
import
com.jieweifu.plugins.barcode.http.ResultCallback
;
import
android.app.Activity
;
import
android.app.ProgressDialog
;
import
android.content.DialogInterface
;
import
android.content.Intent
;
import
android.content.res.AssetFileDescriptor
;
import
android.graphics.Color
;
import
android.graphics.Point
;
import
android.media.AudioManager
;
import
android.media.MediaPlayer
;
import
android.media.MediaPlayer.OnCompletionListener
;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.os.Vibrator
;
import
android.util.Log
;
import
android.view.Gravity
;
import
android.view.SurfaceHolder
;
import
android.view.SurfaceHolder.Callback
;
import
android.view.SurfaceView
;
import
android.view.View
;
import
android.view.animation.Animation
;
import
android.view.animation.LinearInterpolator
;
import
android.view.animation.ScaleAnimation
;
import
android.widget.ImageView
;
import
android.widget.LinearLayout
;
import
android.widget.RelativeLayout
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
public
class
CaptureActivity
extends
Activity
implements
Callback
,
ICaptureActivity
,
View
.
OnClickListener
{
private
final
static
String
TAG
=
"CaptureActivity"
;
private
ProgressDialog
progressDialog
;
private
CaptureActivityHandler
handler
;
private
boolean
hasSurface
;
private
InactivityTimer
inactivityTimer
;
private
MediaPlayer
mediaPlayer
;
private
boolean
playBeep
;
private
static
final
float
BEEP_VOLUME
=
0.50f
;
private
boolean
vibrate
;
private
int
x
=
0
;
private
int
y
=
0
;
private
int
cropWidth
=
0
;
private
int
cropHeight
=
0
;
private
RelativeLayout
mContainer
=
null
;
private
RelativeLayout
mCropLayout
=
null
;
private
TextView
tv_type
=
null
;
private
TextView
tv_lable1
=
null
;
private
TextView
tv_lable2
=
null
;
private
TextView
tv_scanTip
=
null
;
private
LinearLayout
lytInput
=
null
;
private
LinearLayout
lytLight
=
null
;
private
TextView
mTipLight
;
private
ImageView
mImgLight
;
private
ImageView
imgTip
=
null
;
private
CapturePresenter
capturePresenter
;
private
ArgsBean
argsBean
;
private
DialogToast
dialogToast
;
private
boolean
finishFlag
;
public
int
getX
()
{
return
x
;
}
public
void
setX
(
int
x
)
{
this
.
x
=
x
;
}
public
int
getY
()
{
return
y
;
}
public
void
setY
(
int
y
)
{
this
.
y
=
y
;
}
public
int
getCropWidth
()
{
return
cropWidth
;
}
public
void
setCropWidth
(
int
cropWidth
)
{
this
.
cropWidth
=
cropWidth
;
}
public
int
getCropHeight
()
{
return
cropHeight
;
}
public
void
setCropHeight
(
int
cropHeight
)
{
this
.
cropHeight
=
cropHeight
;
}
/**
* Called when the activity is first created.
*/
@Override
public
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_qr_scan
);
capturePresenter
=
new
CapturePresenter
(
this
,
this
);
readIntent
();
// 初始化 CameraManager
CameraManager
.
init
(
getApplication
());
hasSurface
=
false
;
inactivityTimer
=
new
InactivityTimer
(
this
);
mContainer
=
(
RelativeLayout
)
findViewById
(
R
.
id
.
capture_containter
);
mCropLayout
=
(
RelativeLayout
)
findViewById
(
R
.
id
.
capture_crop_layout
);
tv_type
=
(
TextView
)
findViewById
(
R
.
id
.
tv_type
);
tv_lable1
=
(
TextView
)
findViewById
(
R
.
id
.
txt_tip1
);
tv_lable2
=
(
TextView
)
findViewById
(
R
.
id
.
txt_tip2
);
tv_scanTip
=
(
TextView
)
findViewById
(
R
.
id
.
txtScanTip
);
lytInput
=
(
LinearLayout
)
findViewById
(
R
.
id
.
lyt_input
);
lytLight
=
(
LinearLayout
)
findViewById
(
R
.
id
.
lyt_light
);
imgTip
=
(
ImageView
)
findViewById
(
R
.
id
.
img_tip
);
mTipLight
=
(
TextView
)
findViewById
(
R
.
id
.
txt_light
);
mImgLight
=
(
ImageView
)
findViewById
(
R
.
id
.
img_light
);
initData
();
ImageView
mQrLineView
=
(
ImageView
)
findViewById
(
R
.
id
.
capture_scan_line
);
ScaleAnimation
animation
=
new
ScaleAnimation
(
1.0f
,
1.0f
,
0.0f
,
1.0f
);
animation
.
setRepeatCount
(-
1
);
animation
.
setRepeatMode
(
Animation
.
RESTART
);
animation
.
setInterpolator
(
new
LinearInterpolator
());
animation
.
setDuration
(
1200
);
mQrLineView
.
startAnimation
(
animation
);
setButtonListeners
();
}
private
void
readIntent
()
{
argsBean
=
getIntent
().
getParcelableExtra
(
"ARGS"
);
flag
=
getIntent
().
getBooleanExtra
(
"light"
,
true
);
if
(!
flag
)
{
new
Handler
(
getMainLooper
()).
post
(
new
Runnable
()
{
@Override
public
void
run
()
{
CameraManager
.
get
().
openLight
();
}
});
}
}
private
void
initData
()
{
tv_type
.
setText
(
argsBean
.
getPageInfoBean
().
getTitle
());
tv_lable1
.
setText
(
argsBean
.
getPageInfoBean
().
getFooterFirst
());
tv_lable2
.
setText
(
argsBean
.
getPageInfoBean
().
getFooterSecond
());
tv_scanTip
.
setText
(
argsBean
.
getPageInfoBean
().
getTipScan
());
if
(
argsBean
.
getPageInfoBean
().
isExplainFlag
())
{
imgTip
.
setVisibility
(
View
.
VISIBLE
);
}
else
{
imgTip
.
setVisibility
(
View
.
GONE
);
}
((
TextView
)
findViewById
(
R
.
id
.
txt_title
)).
setText
(
argsBean
.
getPageInfoBean
().
getBarTitle
());
if
(
argsBean
.
getPageInfoBean
().
isInputFlag
())
{
lytInput
.
setVisibility
(
View
.
VISIBLE
);
}
else
{
lytInput
.
setVisibility
(
View
.
GONE
);
}
if
(
argsBean
.
getPageInfoBean
().
isLightFlag
())
{
lytLight
.
setVisibility
(
View
.
VISIBLE
);
}
else
{
lytLight
.
setVisibility
(
View
.
GONE
);
}
((
TextView
)
findViewById
(
R
.
id
.
txt_input
)).
setText
(
argsBean
.
getPageInfoBean
().
getTipInput
());
mTipLight
.
setText
(
argsBean
.
getPageInfoBean
().
getTipLightOn
()
+
""
);
}
boolean
flag
=
true
;
protected
void
light
()
{
if
(
flag
==
true
)
{
flag
=
false
;
CameraManager
.
get
().
openLight
();
mTipLight
.
setText
(
argsBean
.
getPageInfoBean
().
getTipLightOff
()
+
""
);
mImgLight
.
setImageDrawable
(
getResources
().
getDrawable
(
R
.
drawable
.
light_close
));
mTipLight
.
setTextColor
(
Color
.
parseColor
(
"#1978d2"
));
}
else
{
flag
=
true
;
CameraManager
.
get
().
offLight
();
mTipLight
.
setText
(
argsBean
.
getPageInfoBean
().
getTipLightOn
()
+
""
);
mImgLight
.
setImageDrawable
(
getResources
().
getDrawable
(
R
.
drawable
.
light
));
mTipLight
.
setTextColor
(
Color
.
parseColor
(
"#FFFFFF"
));
}
}
protected
void
setButtonListeners
()
{
findViewById
(
R
.
id
.
imgBtnBack
).
setOnClickListener
(
this
);
lytInput
.
setOnClickListener
(
this
);
lytLight
.
setOnClickListener
(
this
);
findViewById
(
R
.
id
.
rel_tip
).
setOnClickListener
(
this
);
}
@SuppressWarnings
(
"deprecation"
)
@Override
protected
void
onResume
()
{
super
.
onResume
();
SurfaceView
surfaceView
=
(
SurfaceView
)
findViewById
(
R
.
id
.
capture_preview
);
SurfaceHolder
surfaceHolder
=
surfaceView
.
getHolder
();
if
(
hasSurface
)
{
initCamera
(
surfaceHolder
);
}
else
{
surfaceHolder
.
addCallback
(
this
);
surfaceHolder
.
setType
(
SurfaceHolder
.
SURFACE_TYPE_PUSH_BUFFERS
);
}
playBeep
=
true
;
AudioManager
audioService
=
(
AudioManager
)
getSystemService
(
AUDIO_SERVICE
);
if
(
audioService
.
getRingerMode
()
!=
AudioManager
.
RINGER_MODE_NORMAL
)
{
playBeep
=
false
;
}
initBeepSound
();
vibrate
=
true
;
}
@Override
protected
void
onPause
()
{
super
.
onPause
();
if
(
handler
!=
null
)
{
handler
.
quitSynchronously
();
handler
=
null
;
}
CameraManager
.
get
().
closeDriver
();
}
@Override
public
void
onBackPressed
()
{
super
.
onBackPressed
();
JSONObject
object
=
new
JSONObject
();
try
{
object
.
put
(
"type"
,
"CLOSE"
);
object
.
put
(
"message"
,
"{}"
);
BarcodePlugin
.
cbContext
.
success
(
object
);
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
Log
.
e
(
"huangjie"
,
"回掉"
);
BarcodePlugin
.
cbContext
.
success
(
object
);
finish
();
}
@Override
public
void
onDestroy
()
{
inactivityTimer
.
shutdown
();
super
.
onDestroy
();
}
public
void
handleDecode
(
final
String
result
)
{
inactivityTimer
.
onActivity
();
playBeepSoundAndVibrate
();
if
(
ArgsBean
.
SCAN
.
equals
(
argsBean
.
getOperateMethod
()))
{
JSONObject
object
=
new
JSONObject
();
try
{
object
.
put
(
"type"
,
ArgsBean
.
SCAN
);
JSONObject
messageObject
=
new
JSONObject
();
messageObject
.
put
(
"code"
,
result
);
object
.
put
(
"message"
,
messageObject
);
Log
.
e
(
TAG
,
object
.
toString
()
+
""
);
scanFinish
(
object
);
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
return
;
}
else
if
(
argsBean
.
getHttpInfos
()
==
null
)
{
BarcodePlugin
.
cbContext
.
success
(
result
);
finish
();
return
;
}
else
capturePresenter
.
toValidation
(
argsBean
,
result
);
}
private
void
initCamera
(
SurfaceHolder
surfaceHolder
)
{
try
{
CameraManager
.
get
().
openDriver
(
surfaceHolder
);
Point
point
=
CameraManager
.
get
().
getCameraResolution
();
int
width
=
point
.
y
;
int
height
=
point
.
x
;
int
x
=
mCropLayout
.
getLeft
()
*
width
/
mContainer
.
getWidth
();
int
y
=
mCropLayout
.
getTop
()
*
height
/
mContainer
.
getHeight
();
int
cropWidth
=
mCropLayout
.
getWidth
()
*
width
/
mContainer
.
getWidth
();
int
cropHeight
=
mCropLayout
.
getHeight
()
*
height
/
mContainer
.
getHeight
();
setX
(
x
);
setY
(
y
);
setCropWidth
(
cropWidth
);
setCropHeight
(
cropHeight
);
}
catch
(
IOException
ioe
)
{
return
;
}
catch
(
RuntimeException
e
)
{
return
;
}
if
(
handler
==
null
)
{
handler
=
new
CaptureActivityHandler
(
CaptureActivity
.
this
);
}
}
@Override
public
void
surfaceChanged
(
SurfaceHolder
holder
,
int
format
,
int
width
,
int
height
)
{
}
@Override
public
void
surfaceCreated
(
SurfaceHolder
holder
)
{
if
(!
hasSurface
)
{
hasSurface
=
true
;
initCamera
(
holder
);
}
}
@Override
public
void
surfaceDestroyed
(
SurfaceHolder
holder
)
{
hasSurface
=
false
;
}
public
Handler
getHandler
()
{
return
handler
;
}
private
void
initBeepSound
()
{
if
(
playBeep
&&
mediaPlayer
==
null
)
{
setVolumeControlStream
(
AudioManager
.
STREAM_MUSIC
);
mediaPlayer
=
new
MediaPlayer
();
mediaPlayer
.
setAudioStreamType
(
AudioManager
.
STREAM_MUSIC
);
mediaPlayer
.
setOnCompletionListener
(
beepListener
);
AssetFileDescriptor
file
=
getResources
().
openRawResourceFd
(
R
.
raw
.
beep
);
try
{
mediaPlayer
.
setDataSource
(
file
.
getFileDescriptor
(),
file
.
getStartOffset
(),
file
.
getLength
());
file
.
close
();
mediaPlayer
.
setVolume
(
BEEP_VOLUME
,
BEEP_VOLUME
);
mediaPlayer
.
prepare
();
}
catch
(
IOException
e
)
{
mediaPlayer
=
null
;
}
}
}
private
static
final
long
VIBRATE_DURATION
=
200L
;
private
void
playBeepSoundAndVibrate
()
{
if
(
playBeep
&&
mediaPlayer
!=
null
)
{
mediaPlayer
.
start
();
}
if
(
vibrate
)
{
Vibrator
vibrator
=
(
Vibrator
)
getSystemService
(
VIBRATOR_SERVICE
);
vibrator
.
vibrate
(
VIBRATE_DURATION
);
}
}
private
final
OnCompletionListener
beepListener
=
new
OnCompletionListener
()
{
public
void
onCompletion
(
MediaPlayer
mediaPlayer
)
{
mediaPlayer
.
seekTo
(
0
);
}
};
/**
* 将后端数据返回给前端并退出
*
* @param result
*/
@Override
public
void
scanFinish
(
final
JSONObject
result
)
{
Handler
handler
=
new
Handler
(
getMainLooper
());
handler
.
postDelayed
(
new
Runnable
()
{
@Override
public
void
run
()
{
BarcodePlugin
.
cbContext
.
success
(
result
);
finish
();
}
},
700
);
}
@Override
public
void
ToastCenter
(
String
msg
)
{
Toast
toast
=
Toast
.
makeText
(
getApplicationContext
(),
msg
,
Toast
.
LENGTH_SHORT
);
toast
.
setGravity
(
Gravity
.
CENTER
,
0
,
0
);
toast
.
show
();
}
@Override
public
void
showProgressDialog
(
boolean
isShow
)
{
if
(
dialogToast
==
null
&&
isShow
)
{
DialogToast
.
Builder
builder
=
new
DialogToast
.
Builder
(
this
);
dialogToast
=
builder
.
setMsg
(
argsBean
.
getPageInfoBean
().
getTipLoading
())
.
setOnClickListener
(
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialogInterface
,
int
i
)
{
dialogInterface
.
dismiss
();
reStartActivity
();
}
}).
create
();
dialogToast
.
show
();
}
else
if
(
isShow
)
{
dialogToast
.
show
();
}
else
if
(!
isShow
&&
dialogToast
!=
null
)
{
dialogToast
.
dismiss
();
}
}
@Override
public
void
goNetworkErrorPage
()
{
Intent
intent
=
new
Intent
(
this
,
NetWorkErrorActivity
.
class
);
intent
.
putExtra
(
"ARGS"
,
argsBean
);
startActivity
(
intent
);
}
@Override
public
void
goUnOpenWebPage
()
{
Intent
intent
=
new
Intent
(
this
,
UnOpenWebActivity
.
class
);
intent
.
putExtra
(
"ARGS"
,
argsBean
);
startActivity
(
intent
);
}
@Override
public
void
reStartActivity
()
{
Intent
intent
=
getIntent
();
intent
.
putExtra
(
"light"
,
flag
);
overridePendingTransition
(
0
,
0
);
intent
.
addFlags
(
Intent
.
FLAG_ACTIVITY_NO_ANIMATION
);
finish
();
overridePendingTransition
(
0
,
0
);
startActivity
(
intent
);
}
private
void
input
()
{
JSONObject
object
=
new
JSONObject
();
try
{
object
.
put
(
"type"
,
"INPUT"
);
object
.
put
(
"message"
,
"{}"
);
BarcodePlugin
.
cbContext
.
success
(
object
);
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
finish
();
}
@Override
public
void
finish
()
{
if
(
argsBean
.
getPageInfoBean
().
getDelayTime
()
!=
0
&&
!
finishFlag
)
{
TimerTask
task
=
new
TimerTask
()
{
@Override
public
void
run
()
{
finishFlag
=
true
;
CaptureActivity
.
this
.
finish
();
}
};
Timer
timer
=
new
Timer
();
timer
.
schedule
(
task
,
argsBean
.
getPageInfoBean
().
getDelayTime
());
}
else
{
super
.
finish
();
}
}
@Override
public
void
onClick
(
View
view
)
{
int
id
=
view
.
getId
();
switch
(
id
)
{
case
R
.
id
.
imgBtnBack
:
onBackPressed
();
break
;
case
R
.
id
.
lyt_input
:
input
();
break
;
case
R
.
id
.
lyt_light
:
light
();
break
;
case
R
.
id
.
rel_tip
:
JSONObject
object
=
new
JSONObject
();
try
{
object
.
put
(
"type"
,
"EXPLAIN"
);
object
.
put
(
"message"
,
new
JSONObject
());
scanFinish
(
object
);
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
break
;
default
:
break
;
}
}
}
src/android/src/com/jieweifu/plugins/barcode/CapturePresenter.java
deleted
100644 → 0
View file @
cc15978b
package
com
.
jieweifu
.
plugins
.
barcode
;
import
android.content.Context
;
import
android.util.Log
;
import
android.widget.Toast
;
import
com.jieweifu.plugins.barcode.Util.Util
;
import
com.jieweifu.plugins.barcode.bean.ArgsBean
;
import
com.jieweifu.plugins.barcode.bean.CodeInfoBean
;
import
com.jieweifu.plugins.barcode.http.HttpManager
;
import
com.jieweifu.plugins.barcode.http.ResultCallback
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
/**
* Created by panx on 2017/3/16.
*/
public
class
CapturePresenter
{
private
ICaptureActivity
iCaptureActivity
;
private
Context
context
;
private
final
static
String
TAG
=
"CapturePresenter"
;
private
ArgsBean
argsBean
;
public
CapturePresenter
(
ICaptureActivity
iCaptureActivity
,
Context
context
)
{
this
.
iCaptureActivity
=
iCaptureActivity
;
this
.
context
=
context
;
}
/**
* 向后端发送验证请求
* @param argsBean
* @param code
*/
public
void
toValidation
(
ArgsBean
argsBean
,
final
String
code
)
{
this
.
argsBean
=
makeArguments
(
argsBean
,
code
);
if
(
argsBean
==
null
)
return
;
iCaptureActivity
.
showProgressDialog
(
true
);
HttpManager
.
post
(
argsBean
.
getHttpInfos
().
get
(
0
),
new
ResultCallback
<
String
>()
{
//条码处理失败
@Override
public
void
onError
(
Exception
e
,
String
error
)
{
iCaptureActivity
.
showProgressDialog
(
false
);
iCaptureActivity
.
ToastCenter
(
error
);
if
(!
Util
.
isNetworkAvailable
(
context
)){
iCaptureActivity
.
goNetworkErrorPage
();
}
else
{
iCaptureActivity
.
reStartActivity
();
}
}
//条码处理成功
@Override
public
void
onResponse
(
String
response
,
String
extra
)
{
iCaptureActivity
.
showProgressDialog
(
false
);
CodeInfoBean
codeInfoBean
=
doCodeResult
(
response
);
if
(
codeInfoBean
!=
null
)
{
doResultBiz
(
codeInfoBean
,
response
,
code
);
}
else
{
iCaptureActivity
.
ToastCenter
(
HttpManager
.
NETWORK_ERROR
);
}
}
});
}
/**
* 处理网络请求参数
* @param argsBean
* @param code
* @return
*/
private
ArgsBean
makeArguments
(
ArgsBean
argsBean
,
String
code
)
{
String
data
=
argsBean
.
getHttpInfos
().
get
(
0
).
getData
();
try
{
JSONObject
object
=
new
JSONObject
(
data
);
object
.
put
(
"code"
,
code
);
object
.
put
(
"operate"
,
argsBean
.
getOperateMethod
());
argsBean
.
getHttpInfos
().
get
(
0
).
setData
(
object
.
toString
());
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
Log
.
e
(
TAG
,
"wrog arguments for http data"
);
return
null
;
}
return
argsBean
;
}
/**
* 处理扫码结果
*/
private
CodeInfoBean
doCodeResult
(
String
response
)
{
Log
.
e
(
TAG
,
response
);
try
{
JSONObject
object
=
new
JSONObject
(
response
);
CodeInfoBean
codeInfoBean
=
new
CodeInfoBean
();
codeInfoBean
.
setCode
(
object
.
getString
(
CodeInfoBean
.
CODE
));
codeInfoBean
.
setMsg
(
object
.
getString
(
CodeInfoBean
.
MSG
));
codeInfoBean
.
setOnline
(
object
.
optString
(
CodeInfoBean
.
ONLINE
));
codeInfoBean
.
setExpenseReport
(
object
.
optString
(
CodeInfoBean
.
EXPENSE_REPORT
));
return
codeInfoBean
;
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
/**
* 根据扫码结果做出相应的反馈
*/
private
void
doResultBiz
(
CodeInfoBean
codeInfoBean
,
String
response
,
String
code
)
{
String
operateMethod
=
argsBean
.
getOperateMethod
();
if
(
operateMethod
!=
null
&&
operateMethod
.
equals
(
ArgsBean
.
REVIEW
))
{
doReviewBiz
(
codeInfoBean
,
response
);
}
else
if
(
operateMethod
!=
null
&&
operateMethod
.
equals
(
ArgsBean
.
AUDIT_PASS
))
{
doAuditPassBiz
(
codeInfoBean
,
response
);
}
else
if
(
operateMethod
!=
null
&&
operateMethod
.
equals
(
ArgsBean
.
AUDIT
))
{
doAuditBiz
(
codeInfoBean
,
response
,
code
);
}
else
if
(
operateMethod
!=
null
&&
operateMethod
.
equals
(
ArgsBean
.
BACK
))
{
doBackBiz
(
codeInfoBean
,
response
,
code
);
}
else
if
(
operateMethod
!=
null
&&
operateMethod
.
equals
(
ArgsBean
.
RECEIVE
))
{
doReceiveBiz
(
codeInfoBean
,
response
);
}
else
if
(
operateMethod
!=
null
&&
operateMethod
.
equals
(
ArgsBean
.
INVOICE
)){
doInvoiceBiz
(
codeInfoBean
,
response
,
code
);
}
}
/**
* 处理REVIEW的业务逻辑
*/
private
void
doReviewBiz
(
CodeInfoBean
codeInfoBean
,
String
response
)
{
if
(
codeInfoBean
.
getCode
()
!=
null
&&
codeInfoBean
.
getCode
().
equals
(
CodeInfoBean
.
SUCCESS
))
{
//审核成功
JSONObject
object
=
new
JSONObject
();
try
{
object
.
put
(
"type"
,
ArgsBean
.
REVIEW
);
JSONObject
responseObject
=
new
JSONObject
(
response
);
object
.
put
(
"message"
,
responseObject
);
iCaptureActivity
.
ToastCenter
(
codeInfoBean
.
getMsg
());
iCaptureActivity
.
scanFinish
(
object
);
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
}
else
if
(
codeInfoBean
.
getOnline
()
==
null
||
!
codeInfoBean
.
getOnline
().
equals
(
"1"
))
{
iCaptureActivity
.
goUnOpenWebPage
();
//未打开中控页面
}
else
{
//审核没有成功
iCaptureActivity
.
ToastCenter
(
codeInfoBean
.
getMsg
());
iCaptureActivity
.
reStartActivity
();
}
}
/**
* 处理ADDIT_PASS逻辑
*/
private
void
doAuditPassBiz
(
CodeInfoBean
codeInfoBean
,
String
response
)
{
if
(
codeInfoBean
.
getCode
()!=
null
&&
codeInfoBean
.
getCode
().
equals
(
CodeInfoBean
.
SUCCESS
)){
try
{
JSONObject
object
=
new
JSONObject
(
codeInfoBean
.
getExpenseReport
());
String
applicantName
=
object
.
getString
(
"applicantName"
);
String
businessCode
=
object
.
getString
(
"businessCode"
);
String
msg
=
String
.
format
(
"%s\n%s\n%s"
,
applicantName
,
businessCode
,
codeInfoBean
.
getMsg
());
iCaptureActivity
.
ToastCenter
(
msg
);
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
iCaptureActivity
.
reStartActivity
();
}
else
{
iCaptureActivity
.
ToastCenter
(
codeInfoBean
.
getMsg
());
iCaptureActivity
.
reStartActivity
();
}
}
/**
* 处理AUDIT逻辑
*/
private
void
doAuditBiz
(
CodeInfoBean
codeInfoBean
,
String
response
,
String
code
)
{
if
(
codeInfoBean
.
getCode
()!=
null
&&
codeInfoBean
.
getCode
().
equals
(
CodeInfoBean
.
SUCCESS
)){
JSONObject
object
=
new
JSONObject
();
try
{
object
.
put
(
"type"
,
"AUDIT"
);
JSONObject
msgObject
=
new
JSONObject
();
msgObject
.
put
(
"code"
,
code
);
JSONObject
responseObject
=
new
JSONObject
(
response
);
msgObject
.
put
(
"response"
,
responseObject
);
object
.
put
(
"message"
,
msgObject
);
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
iCaptureActivity
.
ToastCenter
(
codeInfoBean
.
getMsg
());
iCaptureActivity
.
scanFinish
(
object
);
}
else
{
iCaptureActivity
.
ToastCenter
(
codeInfoBean
.
getMsg
());
iCaptureActivity
.
reStartActivity
();
}
}
/**
* 处理BACK逻辑
*/
private
void
doBackBiz
(
CodeInfoBean
codeInfoBean
,
String
response
,
String
code
)
{
if
(
codeInfoBean
.
getCode
()!=
null
&&
codeInfoBean
.
getCode
().
equals
(
CodeInfoBean
.
SUCCESS
)){
JSONObject
object
=
new
JSONObject
();
try
{
object
.
put
(
"type"
,
"BACK"
);
JSONObject
msgObject
=
new
JSONObject
();
msgObject
.
put
(
"code"
,
code
);
JSONObject
responseObject
=
new
JSONObject
(
response
);
msgObject
.
put
(
"response"
,
responseObject
);
object
.
put
(
"message"
,
msgObject
);
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
iCaptureActivity
.
ToastCenter
(
codeInfoBean
.
getMsg
());
iCaptureActivity
.
scanFinish
(
object
);
}
else
{
iCaptureActivity
.
ToastCenter
(
codeInfoBean
.
getMsg
());
iCaptureActivity
.
reStartActivity
();
}
}
/**
* 处理INVOICE逻辑
*/
private
void
doInvoiceBiz
(
CodeInfoBean
codeInfoBean
,
String
response
,
String
code
)
{
if
(
codeInfoBean
.
getCode
()!=
null
&&
codeInfoBean
.
getCode
().
equals
(
CodeInfoBean
.
SUCCESS
)){
JSONObject
object
=
new
JSONObject
();
try
{
object
.
put
(
"type"
,
ArgsBean
.
INVOICE
);
JSONObject
msgObject
=
new
JSONObject
();
msgObject
.
put
(
"code"
,
code
);
JSONObject
responseObject
=
new
JSONObject
(
response
);
msgObject
.
put
(
"response"
,
responseObject
);
object
.
put
(
"message"
,
msgObject
);
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
iCaptureActivity
.
ToastCenter
(
codeInfoBean
.
getMsg
());
iCaptureActivity
.
scanFinish
(
object
);
}
else
{
iCaptureActivity
.
ToastCenter
(
codeInfoBean
.
getMsg
());
iCaptureActivity
.
reStartActivity
();
}
}
/**
* 处理RECEIVE逻辑
*/
private
void
doReceiveBiz
(
CodeInfoBean
codeInfoBean
,
String
response
)
{
iCaptureActivity
.
ToastCenter
(
codeInfoBean
.
getMsg
());
iCaptureActivity
.
reStartActivity
();
}
}
src/android/src/com/jieweifu/plugins/barcode/ICaptureActivity.java
deleted
100644 → 0
View file @
cc15978b
package
com
.
jieweifu
.
plugins
.
barcode
;
import
org.json.JSONObject
;
/**
* Created by panx on 2017/3/16.
*/
public
interface
ICaptureActivity
{
void
goNetworkErrorPage
();
void
goUnOpenWebPage
();
void
reStartActivity
();
void
scanFinish
(
JSONObject
result
);
void
ToastCenter
(
String
msg
);
void
showProgressDialog
(
boolean
flag
);
}
src/android/src/com/jieweifu/plugins/barcode/Util/NoSSLv3SocketFactory.java
deleted
100644 → 0
View file @
cc15978b
package
com
.
jieweifu
.
plugins
.
barcode
.
Util
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.net.InetAddress
;
import
java.net.Socket
;
import
java.net.SocketAddress
;
import
java.net.SocketException
;
import
java.nio.channels.SocketChannel
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
javax.net.ssl.HandshakeCompletedListener
;
import
javax.net.ssl.HttpsURLConnection
;
import
javax.net.ssl.SSLSession
;
import
javax.net.ssl.SSLSocket
;
import
javax.net.ssl.SSLSocketFactory
;
public
class
NoSSLv3SocketFactory
extends
SSLSocketFactory
{
private
final
SSLSocketFactory
delegate
;
public
NoSSLv3SocketFactory
()
{
this
.
delegate
=
HttpsURLConnection
.
getDefaultSSLSocketFactory
();
}
public
NoSSLv3SocketFactory
(
SSLSocketFactory
delegate
)
{
this
.
delegate
=
delegate
;
}
@Override
public
String
[]
getDefaultCipherSuites
()
{
return
delegate
.
getDefaultCipherSuites
();
}
@Override
public
String
[]
getSupportedCipherSuites
()
{
return
delegate
.
getSupportedCipherSuites
();
}
private
Socket
makeSocketSafe
(
Socket
socket
)
{
if
(
socket
instanceof
SSLSocket
)
{
socket
=
new
NoSSLv3SSLSocket
((
SSLSocket
)
socket
);
}
return
socket
;
}
@Override
public
Socket
createSocket
(
Socket
s
,
String
host
,
int
port
,
boolean
autoClose
)
throws
IOException
{
return
makeSocketSafe
(
delegate
.
createSocket
(
s
,
host
,
port
,
autoClose
));
}
@Override
public
Socket
createSocket
(
String
host
,
int
port
)
throws
IOException
{
return
makeSocketSafe
(
delegate
.
createSocket
(
host
,
port
));
}
@Override
public
Socket
createSocket
(
String
host
,
int
port
,
InetAddress
localHost
,
int
localPort
)
throws
IOException
{
return
makeSocketSafe
(
delegate
.
createSocket
(
host
,
port
,
localHost
,
localPort
));
}
@Override
public
Socket
createSocket
(
InetAddress
host
,
int
port
)
throws
IOException
{
return
makeSocketSafe
(
delegate
.
createSocket
(
host
,
port
));
}
@Override
public
Socket
createSocket
(
InetAddress
address
,
int
port
,
InetAddress
localAddress
,
int
localPort
)
throws
IOException
{
return
makeSocketSafe
(
delegate
.
createSocket
(
address
,
port
,
localAddress
,
localPort
));
}
private
class
NoSSLv3SSLSocket
extends
DelegateSSLSocket
{
private
NoSSLv3SSLSocket
(
SSLSocket
delegate
)
{
super
(
delegate
);
}
@Override
public
void
setEnabledProtocols
(
String
[]
protocols
)
{
if
(
protocols
!=
null
&&
protocols
.
length
==
1
&&
"SSLv3"
.
equals
(
protocols
[
0
]))
{
List
<
String
>
enabledProtocols
=
new
ArrayList
<
String
>(
Arrays
.
asList
(
delegate
.
getEnabledProtocols
()));
if
(
enabledProtocols
.
size
()
>
1
)
{
enabledProtocols
.
remove
(
"SSLv3"
);
System
.
out
.
println
(
"Removed SSLv3 from enabled protocols"
);
}
else
{
System
.
out
.
println
(
"SSL stuck with protocol available for "
+
String
.
valueOf
(
enabledProtocols
));
}
protocols
=
enabledProtocols
.
toArray
(
new
String
[
enabledProtocols
.
size
()]);
}
super
.
setEnabledProtocols
(
new
String
[]{
"TLSv1.2"
,
"TLSv1.1"
,
"TLSv1"
});
}
}
public
class
DelegateSSLSocket
extends
SSLSocket
{
protected
final
SSLSocket
delegate
;
DelegateSSLSocket
(
SSLSocket
delegate
)
{
this
.
delegate
=
delegate
;
}
@Override
public
String
[]
getSupportedCipherSuites
()
{
return
delegate
.
getSupportedCipherSuites
();
}
@Override
public
String
[]
getEnabledCipherSuites
()
{
return
delegate
.
getEnabledCipherSuites
();
}
@Override
public
void
setEnabledCipherSuites
(
String
[]
suites
)
{
delegate
.
setEnabledCipherSuites
(
suites
);
}
@Override
public
String
[]
getSupportedProtocols
()
{
return
delegate
.
getSupportedProtocols
();
}
@Override
public
String
[]
getEnabledProtocols
()
{
return
delegate
.
getEnabledProtocols
();
}
@Override
public
void
setEnabledProtocols
(
String
[]
protocols
)
{
delegate
.
setEnabledProtocols
(
protocols
);
}
@Override
public
SSLSession
getSession
()
{
return
delegate
.
getSession
();
}
@Override
public
void
addHandshakeCompletedListener
(
HandshakeCompletedListener
listener
)
{
delegate
.
addHandshakeCompletedListener
(
listener
);
}
@Override
public
void
removeHandshakeCompletedListener
(
HandshakeCompletedListener
listener
)
{
delegate
.
removeHandshakeCompletedListener
(
listener
);
}
@Override
public
void
startHandshake
()
throws
IOException
{
delegate
.
startHandshake
();
}
@Override
public
void
setUseClientMode
(
boolean
mode
)
{
delegate
.
setUseClientMode
(
mode
);
}
@Override
public
boolean
getUseClientMode
()
{
return
delegate
.
getUseClientMode
();
}
@Override
public
void
setNeedClientAuth
(
boolean
need
)
{
delegate
.
setNeedClientAuth
(
need
);
}
@Override
public
void
setWantClientAuth
(
boolean
want
)
{
delegate
.
setWantClientAuth
(
want
);
}
@Override
public
boolean
getNeedClientAuth
()
{
return
delegate
.
getNeedClientAuth
();
}
@Override
public
boolean
getWantClientAuth
()
{
return
delegate
.
getWantClientAuth
();
}
@Override
public
void
setEnableSessionCreation
(
boolean
flag
)
{
delegate
.
setEnableSessionCreation
(
flag
);
}
@Override
public
boolean
getEnableSessionCreation
()
{
return
delegate
.
getEnableSessionCreation
();
}
@Override
public
void
bind
(
SocketAddress
localAddr
)
throws
IOException
{
delegate
.
bind
(
localAddr
);
}
@Override
public
synchronized
void
close
()
throws
IOException
{
delegate
.
close
();
}
@Override
public
void
connect
(
SocketAddress
remoteAddr
)
throws
IOException
{
delegate
.
connect
(
remoteAddr
);
}
@Override
public
void
connect
(
SocketAddress
remoteAddr
,
int
timeout
)
throws
IOException
{
delegate
.
connect
(
remoteAddr
,
timeout
);
}
@Override
public
SocketChannel
getChannel
()
{
return
delegate
.
getChannel
();
}
@Override
public
InetAddress
getInetAddress
()
{
return
delegate
.
getInetAddress
();
}
@Override
public
InputStream
getInputStream
()
throws
IOException
{
return
delegate
.
getInputStream
();
}
@Override
public
boolean
getKeepAlive
()
throws
SocketException
{
return
delegate
.
getKeepAlive
();
}
@Override
public
InetAddress
getLocalAddress
()
{
return
delegate
.
getLocalAddress
();
}
@Override
public
int
getLocalPort
()
{
return
delegate
.
getLocalPort
();
}
@Override
public
SocketAddress
getLocalSocketAddress
()
{
return
delegate
.
getLocalSocketAddress
();
}
@Override
public
boolean
getOOBInline
()
throws
SocketException
{
return
delegate
.
getOOBInline
();
}
@Override
public
OutputStream
getOutputStream
()
throws
IOException
{
return
delegate
.
getOutputStream
();
}
@Override
public
int
getPort
()
{
return
delegate
.
getPort
();
}
@Override
public
synchronized
int
getReceiveBufferSize
()
throws
SocketException
{
return
delegate
.
getReceiveBufferSize
();
}
@Override
public
SocketAddress
getRemoteSocketAddress
()
{
return
delegate
.
getRemoteSocketAddress
();
}
@Override
public
boolean
getReuseAddress
()
throws
SocketException
{
return
delegate
.
getReuseAddress
();
}
@Override
public
synchronized
int
getSendBufferSize
()
throws
SocketException
{
return
delegate
.
getSendBufferSize
();
}
@Override
public
int
getSoLinger
()
throws
SocketException
{
return
delegate
.
getSoLinger
();
}
@Override
public
synchronized
int
getSoTimeout
()
throws
SocketException
{
return
delegate
.
getSoTimeout
();
}
@Override
public
boolean
getTcpNoDelay
()
throws
SocketException
{
return
delegate
.
getTcpNoDelay
();
}
@Override
public
int
getTrafficClass
()
throws
SocketException
{
return
delegate
.
getTrafficClass
();
}
@Override
public
boolean
isBound
()
{
return
delegate
.
isBound
();
}
@Override
public
boolean
isClosed
()
{
return
delegate
.
isClosed
();
}
@Override
public
boolean
isConnected
()
{
return
delegate
.
isConnected
();
}
@Override
public
boolean
isInputShutdown
()
{
return
delegate
.
isInputShutdown
();
}
@Override
public
boolean
isOutputShutdown
()
{
return
delegate
.
isOutputShutdown
();
}
@Override
public
void
sendUrgentData
(
int
value
)
throws
IOException
{
delegate
.
sendUrgentData
(
value
);
}
@Override
public
void
setKeepAlive
(
boolean
keepAlive
)
throws
SocketException
{
delegate
.
setKeepAlive
(
keepAlive
);
}
@Override
public
void
setOOBInline
(
boolean
oobinline
)
throws
SocketException
{
delegate
.
setOOBInline
(
oobinline
);
}
@Override
public
void
setPerformancePreferences
(
int
connectionTime
,
int
latency
,
int
bandwidth
)
{
delegate
.
setPerformancePreferences
(
connectionTime
,
latency
,
bandwidth
);
}
@Override
public
synchronized
void
setReceiveBufferSize
(
int
size
)
throws
SocketException
{
delegate
.
setReceiveBufferSize
(
size
);
}
@Override
public
void
setReuseAddress
(
boolean
reuse
)
throws
SocketException
{
delegate
.
setReuseAddress
(
reuse
);
}
@Override
public
synchronized
void
setSendBufferSize
(
int
size
)
throws
SocketException
{
delegate
.
setSendBufferSize
(
size
);
}
@Override
public
void
setSoLinger
(
boolean
on
,
int
timeout
)
throws
SocketException
{
delegate
.
setSoLinger
(
on
,
timeout
);
}
@Override
public
synchronized
void
setSoTimeout
(
int
timeout
)
throws
SocketException
{
delegate
.
setSoTimeout
(
timeout
);
}
@Override
public
void
setTcpNoDelay
(
boolean
on
)
throws
SocketException
{
delegate
.
setTcpNoDelay
(
on
);
}
@Override
public
void
setTrafficClass
(
int
value
)
throws
SocketException
{
delegate
.
setTrafficClass
(
value
);
}
@Override
public
void
shutdownInput
()
throws
IOException
{
delegate
.
shutdownInput
();
}
@Override
public
void
shutdownOutput
()
throws
IOException
{
delegate
.
shutdownOutput
();
}
@Override
public
String
toString
()
{
return
delegate
.
toString
();
}
@Override
public
boolean
equals
(
Object
o
)
{
return
delegate
.
equals
(
o
);
}
}
}
src/android/src/com/jieweifu/plugins/barcode/Util/Util.java
deleted
100644 → 0
View file @
cc15978b
package
com
.
jieweifu
.
plugins
.
barcode
.
Util
;
import
android.content.Context
;
import
android.net.ConnectivityManager
;
import
android.net.NetworkInfo
;
/**
* Created by panx on 2017/3/15.
*/
public
class
Util
{
public
static
boolean
isNetworkAvailable
(
Context
context
){
ConnectivityManager
cm
=
(
ConnectivityManager
)
context
.
getSystemService
(
Context
.
CONNECTIVITY_SERVICE
);
NetworkInfo
networkInfo
=
cm
.
getActiveNetworkInfo
();
if
(
networkInfo
!=
null
&&
networkInfo
.
isAvailable
()){
return
true
;
}
return
false
;
}
}
src/android/src/com/jieweifu/plugins/barcode/ZbarManager.java
deleted
100644 → 0
View file @
cc15978b
package
com
.
zbar
.
lib
;
public
class
ZbarManager
{
static
{
System
.
loadLibrary
(
"zbar"
);
}
public
native
String
decode
(
byte
[]
data
,
int
width
,
int
height
,
boolean
isCrop
,
int
x
,
int
y
,
int
cwidth
,
int
cheight
);
}
src/android/src/com/jieweifu/plugins/barcode/activity/DialogToast.java
deleted
100644 → 0
View file @
cc15978b
package
com
.
jieweifu
.
plugins
.
barcode
.
activity
;
import
android.app.Dialog
;
import
android.content.Context
;
import
android.content.DialogInterface
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.WindowManager
;
import
android.widget.ImageView
;
import
android.widget.TextView
;
import
__ANDROID_PACKAGE__.R
;
/**
* Created by panx on 2017/3/17.
*/
public
class
DialogToast
extends
Dialog
{
public
DialogToast
(
Context
context
)
{
super
(
context
);
}
protected
DialogToast
(
Context
context
,
boolean
cancelable
,
OnCancelListener
cancelListener
)
{
super
(
context
,
cancelable
,
cancelListener
);
}
public
DialogToast
(
Context
context
,
int
themeResId
)
{
super
(
context
,
themeResId
);
}
public
static
class
Builder
{
private
Context
context
;
private
String
msg
;
private
OnClickListener
onClickListener
;
public
Builder
(
Context
context
)
{
this
.
context
=
context
;
}
public
Builder
setMsg
(
String
msg
){
this
.
msg
=
msg
;
return
this
;
}
public
Builder
setOnClickListener
(
OnClickListener
onClickListener
){
this
.
onClickListener
=
onClickListener
;
return
this
;
}
public
DialogToast
create
(){
LayoutInflater
inflater
=
LayoutInflater
.
from
(
context
);
final
DialogToast
dialogToast
=
new
DialogToast
(
context
,
R
.
style
.
Custom_Progress
);
View
view
=
inflater
.
inflate
(
R
.
layout
.
dialog_cancel_layout
,
null
);
dialogToast
.
setContentView
(
view
);
TextView
txtMsg
=(
TextView
)
view
.
findViewById
(
R
.
id
.
txt_msg
);
ImageView
imgCancel
=
(
ImageView
)
view
.
findViewById
(
R
.
id
.
txt_cancel
);
if
(
msg
!=
null
){
txtMsg
.
setText
(
msg
);
}
imgCancel
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
onClickListener
.
onClick
(
dialogToast
,
DialogInterface
.
BUTTON_NEGATIVE
);
}
});
WindowManager
.
LayoutParams
lp
=
dialogToast
.
getWindow
().
getAttributes
();
// 设置背景层透明度
lp
.
dimAmount
=
0.0f
;
dialogToast
.
getWindow
().
setAttributes
(
lp
);
dialogToast
.
setCancelable
(
false
);
return
dialogToast
;
}
}
}
src/android/src/com/jieweifu/plugins/barcode/activity/IUnOpenWebActivity.java
deleted
100644 → 0
View file @
cc15978b
package
com
.
jieweifu
.
plugins
.
barcode
.
activity
;
/**
* Created by panx on 2017/3/16.
*/
public
interface
IUnOpenWebActivity
{
void
stillUnOpen
();
void
hasOpen
();
void
ToastCenter
(
String
msg
);
void
showProgressDialog
(
boolean
flag
);
void
goNetworkErrorPage
();
}
src/android/src/com/jieweifu/plugins/barcode/activity/NetWorkErrorActivity.java
deleted
100644 → 0
View file @
cc15978b
package
com
.
jieweifu
.
plugins
.
barcode
.
activity
;
import
android.app.Activity
;
import
android.os.Bundle
;
import
android.view.View
;
import
android.view.Window
;
import
android.widget.Button
;
import
android.widget.ImageView
;
import
android.widget.TextView
;
import
__ANDROID_PACKAGE__.R
;
import
com.jieweifu.plugins.barcode.bean.ArgsBean
;
/**
* Created by panx on 2017/3/15.
*/
public
class
NetWorkErrorActivity
extends
Activity
implements
View
.
OnClickListener
{
private
ArgsBean
argsBean
;
private
TextView
txtTipNetworkError
;
private
TextView
txtTip1
;
private
TextView
txtTip2
;
private
ImageView
imgBtnBack
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
requestWindowFeature
(
Window
.
FEATURE_NO_TITLE
);
setContentView
(
R
.
layout
.
activity_network_error
);
readIntent
();
initView
();
initListener
();
initData
();
}
private
void
readIntent
(){
argsBean
=
getIntent
().
getParcelableExtra
(
"ARGS"
);
}
private
void
initView
(){
txtTipNetworkError
=
(
TextView
)
findViewById
(
R
.
id
.
txt_tipNetworkError
);
txtTip1
=
(
TextView
)
findViewById
(
R
.
id
.
txt_tip1
);
txtTip2
=
(
TextView
)
findViewById
(
R
.
id
.
txt_tip2
);
imgBtnBack
=
(
ImageView
)
findViewById
(
R
.
id
.
imgBtnBack
);
}
private
void
initListener
(){
imgBtnBack
.
setOnClickListener
(
this
);
}
private
void
initData
(){
txtTipNetworkError
.
setText
(
argsBean
.
getPageInfoBean
().
getTipNetworkError
());
txtTip1
.
setText
(
argsBean
.
getPageInfoBean
().
getFooterFirst
());
txtTip2
.
setText
(
argsBean
.
getPageInfoBean
().
getFooterSecond
());
}
@Override
public
void
onClick
(
View
view
)
{
int
id
=
view
.
getId
();
switch
(
id
){
case
R
.
id
.
imgBtnBack
:{
onBackPressed
();
break
;
}
default
:
break
;
}
}
}
src/android/src/com/jieweifu/plugins/barcode/activity/UnOpenWebActivity.java
deleted
100644 → 0
View file @
cc15978b
package
com
.
jieweifu
.
plugins
.
barcode
.
activity
;
import
android.app.Activity
;
import
android.content.DialogInterface
;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.view.Gravity
;
import
android.view.View
;
import
android.view.Window
;
import
android.widget.Button
;
import
android.widget.ImageView
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
__ANDROID_PACKAGE__.R
;
import
com.jieweifu.plugins.barcode.Util.Util
;
import
com.jieweifu.plugins.barcode.bean.ArgsBean
;
/**
* Created by panx on 2017/3/15.
*/
public
class
UnOpenWebActivity
extends
Activity
implements
View
.
OnClickListener
,
IUnOpenWebActivity
{
private
ImageView
imgBtnBack
;
private
TextView
txtTipOffline
;
private
TextView
txtOpen
;
private
TextView
txtTip1
;
private
TextView
txtTip2
;
private
TextView
scanTitile
;
private
ArgsBean
argsBean
;
private
DialogToast
dialogToast
;
private
UnOpenWebActivityPresenter
unOpenWebActivityPresenter
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
requestWindowFeature
(
Window
.
FEATURE_NO_TITLE
);
setContentView
(
R
.
layout
.
activity_unopen_web
);
unOpenWebActivityPresenter
=
new
UnOpenWebActivityPresenter
(
this
,
this
);
readIntent
();
initView
();
initData
();
initListener
();
}
private
void
readIntent
()
{
argsBean
=
getIntent
().
getParcelableExtra
(
"ARGS"
);
}
private
void
initView
()
{
txtTipOffline
=
(
TextView
)
findViewById
(
R
.
id
.
txt_tipOffLine
);
txtOpen
=
(
TextView
)
findViewById
(
R
.
id
.
txt_open
);
txtTip1
=
(
TextView
)
findViewById
(
R
.
id
.
txt_tip1
);
txtTip2
=
(
TextView
)
findViewById
(
R
.
id
.
txt_tip2
);
imgBtnBack
=
(
ImageView
)
findViewById
(
R
.
id
.
imgBtnBack
);
scanTitile
=(
TextView
)
findViewById
(
R
.
id
.
scanTitile
);
}
private
void
initData
()
{
txtTipOffline
.
setText
(
argsBean
.
getPageInfoBean
().
getTipOffline
());
txtOpen
.
setText
(
argsBean
.
getPageInfoBean
().
getOpenButton
());
txtTip1
.
setText
(
argsBean
.
getPageInfoBean
().
getFooterFirst
());
txtTip2
.
setText
(
argsBean
.
getPageInfoBean
().
getFooterSecond
());
scanTitile
.
setText
(
argsBean
.
getPageInfoBean
().
getBarTitle
());
}
private
void
initListener
(){
txtOpen
.
setOnClickListener
(
this
);
imgBtnBack
.
setOnClickListener
(
this
);
}
@Override
public
void
onClick
(
View
view
)
{
int
id
=
view
.
getId
();
switch
(
id
){
case
R
.
id
.
imgBtnBack
:
onBackPressed
();
break
;
case
R
.
id
.
txt_open
:
unOpenWebActivityPresenter
.
toValidation
(
argsBean
);
break
;
default
:
break
;
}
}
/**
* 扔未打开
*/
@Override
public
void
stillUnOpen
(){
ToastCenter
(
argsBean
.
getPageInfoBean
().
getTipOffline
());
}
@Override
public
void
hasOpen
(){
onBackPressed
();
}
@Override
public
void
ToastCenter
(
String
msg
)
{
Toast
toast
=
Toast
.
makeText
(
getApplicationContext
(),
msg
,
Toast
.
LENGTH_SHORT
);
toast
.
setGravity
(
Gravity
.
CENTER
,
0
,
0
);
toast
.
show
();
}
@Override
public
void
showProgressDialog
(
boolean
isShow
)
{
if
(
dialogToast
==
null
&&
isShow
){
DialogToast
.
Builder
builder
=
new
DialogToast
.
Builder
(
this
);
dialogToast
=
builder
.
setMsg
(
argsBean
.
getPageInfoBean
().
getTipLoading
())
.
setOnClickListener
(
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialogInterface
,
int
i
)
{
dialogInterface
.
dismiss
();
}
}).
create
();
dialogToast
.
show
();
}
else
if
(
isShow
){
dialogToast
.
show
();
}
else
if
(!
isShow
&&
dialogToast
!=
null
){
dialogToast
.
dismiss
();
}
}
@Override
public
void
goNetworkErrorPage
()
{
Intent
intent
=
new
Intent
(
this
,
NetWorkErrorActivity
.
class
);
intent
.
putExtra
(
"ARGS"
,
argsBean
);
startActivity
(
intent
);
}
}
src/android/src/com/jieweifu/plugins/barcode/activity/UnOpenWebActivityPresenter.java
deleted
100644 → 0
View file @
cc15978b
package
com
.
jieweifu
.
plugins
.
barcode
.
activity
;
import
android.content.Context
;
import
com.jieweifu.plugins.barcode.Util.Util
;
import
com.jieweifu.plugins.barcode.bean.ArgsBean
;
import
com.jieweifu.plugins.barcode.http.HttpManager
;
import
com.jieweifu.plugins.barcode.http.ResultCallback
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
/**
* Created by panx on 2017/3/16.
*/
public
class
UnOpenWebActivityPresenter
{
private
IUnOpenWebActivity
iUnOpenWebActivity
;
private
Context
context
;
public
UnOpenWebActivityPresenter
(
IUnOpenWebActivity
iUnOpenWebActivity
,
Context
context
)
{
this
.
iUnOpenWebActivity
=
iUnOpenWebActivity
;
this
.
context
=
context
;
}
public
void
toValidation
(
ArgsBean
argsBean
){
iUnOpenWebActivity
.
showProgressDialog
(
true
);
HttpManager
.
get
(
argsBean
.
getHttpInfos
().
get
(
1
),
new
ResultCallback
<
String
>()
{
@Override
public
void
onError
(
Exception
e
,
String
error
)
{
iUnOpenWebActivity
.
showProgressDialog
(
false
);
if
(!
Util
.
isNetworkAvailable
(
context
)){
iUnOpenWebActivity
.
goNetworkErrorPage
();
}
else
{
iUnOpenWebActivity
.
ToastCenter
(
error
);
}
}
@Override
public
void
onResponse
(
String
response
,
String
result
)
{
iUnOpenWebActivity
.
showProgressDialog
(
false
);
doResultBiz
(
response
);
}
});
}
private
void
doResultBiz
(
String
response
){
try
{
JSONObject
object
=
new
JSONObject
(
response
);
int
online
=
object
.
getInt
(
"online"
);
if
(
online
!=
1
){
iUnOpenWebActivity
.
stillUnOpen
();
}
else
{
iUnOpenWebActivity
.
hasOpen
();
}
}
catch
(
JSONException
e
)
{
iUnOpenWebActivity
.
ToastCenter
(
HttpManager
.
NETWORK_ERROR
);
e
.
printStackTrace
();
}
}
}
src/android/src/com/jieweifu/plugins/barcode/bean/ArgsBean.java
deleted
100644 → 0
View file @
cc15978b
package
com
.
jieweifu
.
plugins
.
barcode
.
bean
;
import
android.os.Parcel
;
import
android.os.Parcelable
;
import
java.util.ArrayList
;
/**
* Created by panx on 2017/3/15.
*/
public
class
ArgsBean
implements
Parcelable
{
public
final
static
String
REVIEW
=
"REVIEW"
;
public
final
static
String
AUDIT
=
"AUDIT"
;
public
final
static
String
BACK
=
"BACK"
;
public
final
static
String
AUDIT_PASS
=
"AUDIT_PASS"
;
public
final
static
String
RECEIVE
=
"RECEIVE"
;
public
final
static
String
SCAN
=
"SCAN"
;
public
final
static
String
INVOICE
=
"INVOICE"
;
private
PageInfoBean
pageInfoBean
;
private
String
operateMethod
;
private
ArrayList
<
HttpInfoBean
>
httpInfos
;
public
ArgsBean
()
{
}
protected
ArgsBean
(
Parcel
in
)
{
pageInfoBean
=
in
.
readParcelable
(
PageInfoBean
.
class
.
getClassLoader
());
operateMethod
=
in
.
readString
();
httpInfos
=
in
.
createTypedArrayList
(
HttpInfoBean
.
CREATOR
);
}
@Override
public
void
writeToParcel
(
Parcel
dest
,
int
flags
)
{
dest
.
writeParcelable
(
pageInfoBean
,
flags
);
dest
.
writeString
(
operateMethod
);
dest
.
writeTypedList
(
httpInfos
);
}
@Override
public
int
describeContents
()
{
return
0
;
}
public
static
final
Creator
<
ArgsBean
>
CREATOR
=
new
Creator
<
ArgsBean
>()
{
@Override
public
ArgsBean
createFromParcel
(
Parcel
in
)
{
return
new
ArgsBean
(
in
);
}
@Override
public
ArgsBean
[]
newArray
(
int
size
)
{
return
new
ArgsBean
[
size
];
}
};
public
PageInfoBean
getPageInfoBean
()
{
return
pageInfoBean
;
}
public
void
setPageInfoBean
(
PageInfoBean
pageInfoBean
)
{
this
.
pageInfoBean
=
pageInfoBean
;
}
public
String
getOperateMethod
()
{
return
operateMethod
;
}
public
void
setOperateMethod
(
String
operateMethod
)
{
this
.
operateMethod
=
operateMethod
;
}
public
ArrayList
<
HttpInfoBean
>
getHttpInfos
()
{
return
httpInfos
;
}
public
void
setHttpInfos
(
ArrayList
<
HttpInfoBean
>
httpInfos
)
{
this
.
httpInfos
=
httpInfos
;
}
}
src/android/src/com/jieweifu/plugins/barcode/bean/ArgsBiz.java
deleted
100644 → 0
View file @
cc15978b
package
com
.
jieweifu
.
plugins
.
barcode
.
bean
;
import
android.util.Log
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
java.util.ArrayList
;
/**
* Created by panx on 2017/3/15.
*/
public
class
ArgsBiz
{
private
final
static
String
TAG
=
"ArgsBiz"
;
public
ArgsBean
getArgsBeanByJSONObject
(
JSONObject
object
)
{
ArgsBean
argsBean
=
new
ArgsBean
();
try
{
JSONObject
pageObject
=
object
.
getJSONObject
(
"message"
);
argsBean
.
setPageInfoBean
(
getPageInfoBeanByJsonObject
(
pageObject
));
String
operateMethod
=
object
.
optString
(
"operationType"
,
""
);
argsBean
.
setOperateMethod
(
operateMethod
);
JSONArray
httpArray
=
object
.
optJSONArray
(
"requests"
);
argsBean
.
setHttpInfos
(
getHttpInfosByJsonArray
(
httpArray
));
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
return
null
;
}
return
argsBean
;
}
private
PageInfoBean
getPageInfoBeanByJsonObject
(
JSONObject
object
)
{
PageInfoBean
pageInfoBean
=
new
PageInfoBean
();
pageInfoBean
.
setTitle
(
object
.
optString
(
"title"
,
""
));
pageInfoBean
.
setTipScan
(
object
.
optString
(
"tipScan"
,
""
));
pageInfoBean
.
setTipInput
(
object
.
optString
(
"tipInput"
,
""
));
pageInfoBean
.
setTipLoading
(
object
.
optString
(
"tipLoading"
,
""
));
pageInfoBean
.
setTipNetworkError
(
object
.
optString
(
"tipNetworkError"
,
""
));
pageInfoBean
.
setTipOffline
(
object
.
optString
(
"tipOffline"
,
""
));
pageInfoBean
.
setOpenButton
(
object
.
optString
(
"openButton"
,
""
));
pageInfoBean
.
setFooterFirst
(
object
.
optString
(
"footerFirst"
,
""
));
pageInfoBean
.
setFooterSecond
(
object
.
optString
(
"footerSecond"
,
""
));
pageInfoBean
.
setBarTitle
(
object
.
optString
(
"barTitle"
,
""
));
pageInfoBean
.
setExplainFlag
(
object
.
optBoolean
(
"explainFlag"
,
false
));
pageInfoBean
.
setInputFlag
(
object
.
optBoolean
(
"inputFlag"
,
true
));
pageInfoBean
.
setLightFlag
(
object
.
optBoolean
(
"lightFlag"
,
true
));
pageInfoBean
.
setTipLightOff
(
object
.
optString
(
"tipLightOff"
,
""
));
pageInfoBean
.
setTipLightOn
(
object
.
optString
(
"tipLightOn"
,
""
));
pageInfoBean
.
setDelayTime
(
object
.
optLong
(
"delayTime"
));
return
pageInfoBean
;
}
private
ArrayList
<
HttpInfoBean
>
getHttpInfosByJsonArray
(
JSONArray
array
)
{
if
(
array
==
null
)
return
null
;
ArrayList
<
HttpInfoBean
>
httpInfos
=
new
ArrayList
<
HttpInfoBean
>();
try
{
for
(
int
i
=
0
;
i
<
array
.
length
();
i
++)
{
HttpInfoBean
httpInfoBean
=
getHttpInfoBeanByJsonObject
(
array
.
getJSONObject
(
i
));
httpInfos
.
add
(
httpInfoBean
);
}
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
Log
.
e
(
TAG
,
"wrong arguments http infos"
);
return
null
;
}
return
httpInfos
;
}
private
HttpInfoBean
getHttpInfoBeanByJsonObject
(
JSONObject
object
)
{
HttpInfoBean
httpInfoBean
=
new
HttpInfoBean
();
HttpInfoBean
.
Config
config
=
new
HttpInfoBean
.
Config
();
HttpInfoBean
.
Headers
headers
=
new
HttpInfoBean
.
Headers
();
try
{
httpInfoBean
.
setUrl
(
object
.
getString
(
"url"
));
httpInfoBean
.
setMethod
(
object
.
getString
(
"method"
));
JSONObject
headerObject
=
object
.
getJSONObject
(
"headers"
);
JSONObject
configObject
=
object
.
getJSONObject
(
"config"
);
JSONObject
dataObject
=
object
.
optJSONObject
(
"data"
);
if
(
dataObject
==
null
)
{
dataObject
=
new
JSONObject
();
}
headers
.
setAuthorization
(
headerObject
.
getString
(
"Authorization"
));
headers
.
setContentType
(
headerObject
.
getString
(
"Content-Type"
));
config
.
setTimeout
(
configObject
.
getInt
(
"timeout"
));
httpInfoBean
.
setConfig
(
config
);
httpInfoBean
.
setData
(
dataObject
.
toString
());
httpInfoBean
.
setHeaders
(
headers
);
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
Log
.
e
(
TAG
,
"wrong arguments http info"
);
return
null
;
}
return
httpInfoBean
;
}
}
src/android/src/com/jieweifu/plugins/barcode/bean/CodeInfoBean.java
deleted
100644 → 0
View file @
cc15978b
package
com
.
jieweifu
.
plugins
.
barcode
.
bean
;
/**
* Created by panx on 2017/3/9.
*/
public
class
CodeInfoBean
{
public
final
static
String
SUCCESS
=
"0000"
;
public
final
static
String
CODE
=
"code"
;
public
final
static
String
MSG
=
"msg"
;
public
final
static
String
ONLINE
=
"online"
;
public
final
static
String
EXPENSE_REPORT
=
"expenseReport"
;
private
String
code
;
private
String
msg
;
private
String
online
;
private
String
expenseReport
;
public
String
getCode
()
{
return
code
;
}
public
void
setCode
(
String
code
)
{
this
.
code
=
code
;
}
public
String
getMsg
()
{
return
msg
;
}
public
void
setMsg
(
String
msg
)
{
this
.
msg
=
msg
;
}
public
String
getOnline
()
{
return
online
;
}
public
void
setOnline
(
String
online
)
{
this
.
online
=
online
;
}
public
String
getExpenseReport
()
{
return
expenseReport
;
}
public
void
setExpenseReport
(
String
expenseReport
)
{
this
.
expenseReport
=
expenseReport
;
}
}
src/android/src/com/jieweifu/plugins/barcode/bean/HttpInfoBean.java
deleted
100644 → 0
View file @
cc15978b
package
com
.
jieweifu
.
plugins
.
barcode
.
bean
;
import
android.os.Parcel
;
import
android.os.Parcelable
;
/**
* Created by panx on 2017/3/15.
*/
public
class
HttpInfoBean
implements
Parcelable
{
private
String
url
;
private
String
method
;
private
Headers
headers
;
private
String
data
;
private
Config
config
;
public
HttpInfoBean
()
{
}
/**
* 请求头
*/
public
static
class
Headers
implements
Parcelable
{
private
String
authorization
;
private
String
contentType
;
public
Headers
()
{
}
protected
Headers
(
Parcel
in
)
{
authorization
=
in
.
readString
();
contentType
=
in
.
readString
();
}
@Override
public
void
writeToParcel
(
Parcel
dest
,
int
flags
)
{
dest
.
writeString
(
authorization
);
dest
.
writeString
(
contentType
);
}
@Override
public
int
describeContents
()
{
return
0
;
}
public
static
final
Creator
<
Headers
>
CREATOR
=
new
Creator
<
Headers
>()
{
@Override
public
Headers
createFromParcel
(
Parcel
in
)
{
return
new
Headers
(
in
);
}
@Override
public
Headers
[]
newArray
(
int
size
)
{
return
new
Headers
[
size
];
}
};
public
String
getAuthorization
()
{
return
authorization
;
}
public
void
setAuthorization
(
String
authorization
)
{
this
.
authorization
=
authorization
;
}
public
String
getContentType
()
{
return
contentType
;
}
public
void
setContentType
(
String
contentType
)
{
this
.
contentType
=
contentType
;
}
}
/**
* 配置
*/
public
static
class
Config
implements
Parcelable
{
private
int
timeout
;
public
Config
()
{
}
protected
Config
(
Parcel
in
)
{
timeout
=
in
.
readInt
();
}
public
static
final
Creator
<
Config
>
CREATOR
=
new
Creator
<
Config
>()
{
@Override
public
Config
createFromParcel
(
Parcel
in
)
{
return
new
Config
(
in
);
}
@Override
public
Config
[]
newArray
(
int
size
)
{
return
new
Config
[
size
];
}
};
public
int
getTimeout
()
{
return
timeout
;
}
public
void
setTimeout
(
int
timeout
)
{
this
.
timeout
=
timeout
;
}
@Override
public
int
describeContents
()
{
return
0
;
}
@Override
public
void
writeToParcel
(
Parcel
parcel
,
int
i
)
{
parcel
.
writeInt
(
timeout
);
}
}
protected
HttpInfoBean
(
Parcel
in
)
{
url
=
in
.
readString
();
method
=
in
.
readString
();
headers
=
in
.
readParcelable
(
Headers
.
class
.
getClassLoader
());
data
=
in
.
readString
();
config
=
in
.
readParcelable
(
Config
.
class
.
getClassLoader
());
}
@Override
public
void
writeToParcel
(
Parcel
dest
,
int
flags
)
{
dest
.
writeString
(
url
);
dest
.
writeString
(
method
);
dest
.
writeParcelable
(
headers
,
flags
);
dest
.
writeString
(
data
);
dest
.
writeParcelable
(
config
,
flags
);
}
@Override
public
int
describeContents
()
{
return
0
;
}
public
static
final
Creator
<
HttpInfoBean
>
CREATOR
=
new
Creator
<
HttpInfoBean
>()
{
@Override
public
HttpInfoBean
createFromParcel
(
Parcel
in
)
{
return
new
HttpInfoBean
(
in
);
}
@Override
public
HttpInfoBean
[]
newArray
(
int
size
)
{
return
new
HttpInfoBean
[
size
];
}
};
public
String
getUrl
()
{
return
url
;
}
public
void
setUrl
(
String
url
)
{
this
.
url
=
url
;
}
public
String
getMethod
()
{
return
method
;
}
public
void
setMethod
(
String
method
)
{
this
.
method
=
method
;
}
public
Config
getConfig
()
{
return
config
;
}
public
void
setConfig
(
Config
config
)
{
this
.
config
=
config
;
}
public
Headers
getHeaders
()
{
return
headers
;
}
public
void
setHeaders
(
Headers
headers
)
{
this
.
headers
=
headers
;
}
public
String
getData
()
{
return
data
;
}
public
void
setData
(
String
data
)
{
this
.
data
=
data
;
}
}
src/android/src/com/jieweifu/plugins/barcode/bean/PageInfoBean.java
deleted
100644 → 0
View file @
cc15978b
package
com
.
jieweifu
.
plugins
.
barcode
.
bean
;
import
android.os.Parcel
;
import
android.os.Parcelable
;
import
android.util.Log
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
/**
* Created by panx on 2017/3/15.
*/
public
class
PageInfoBean
implements
Parcelable
{
private
final
static
String
TAG
=
"PageInfoBean"
;
private
String
title
;
private
String
tipScan
;
private
String
tipInput
;
private
String
tipLoading
;
private
String
tipNetworkError
;
private
String
tipOffline
;
private
String
openButton
;
private
String
footerFirst
;
private
String
footerSecond
;
private
String
barTitle
;
private
boolean
explainFlag
;
private
boolean
inputFlag
;
private
boolean
lightFlag
;
private
String
tipLightOn
;
private
String
tipLightOff
;
private
long
delayTime
;
public
PageInfoBean
()
{
}
protected
PageInfoBean
(
Parcel
in
)
{
title
=
in
.
readString
();
tipScan
=
in
.
readString
();
tipInput
=
in
.
readString
();
tipLoading
=
in
.
readString
();
tipNetworkError
=
in
.
readString
();
tipOffline
=
in
.
readString
();
openButton
=
in
.
readString
();
footerFirst
=
in
.
readString
();
footerSecond
=
in
.
readString
();
barTitle
=
in
.
readString
();
explainFlag
=
in
.
readByte
()
!=
0
;
inputFlag
=
in
.
readByte
()
!=
0
;
lightFlag
=
in
.
readByte
()
!=
0
;
tipLightOn
=
in
.
readString
();
tipLightOff
=
in
.
readString
();
delayTime
=
in
.
readLong
();
}
@Override
public
void
writeToParcel
(
Parcel
dest
,
int
flags
)
{
dest
.
writeString
(
title
);
dest
.
writeString
(
tipScan
);
dest
.
writeString
(
tipInput
);
dest
.
writeString
(
tipLoading
);
dest
.
writeString
(
tipNetworkError
);
dest
.
writeString
(
tipOffline
);
dest
.
writeString
(
openButton
);
dest
.
writeString
(
footerFirst
);
dest
.
writeString
(
footerSecond
);
dest
.
writeString
(
barTitle
);
dest
.
writeByte
((
byte
)
(
explainFlag
?
1
:
0
));
dest
.
writeByte
((
byte
)
(
inputFlag
?
1
:
0
));
dest
.
writeByte
((
byte
)
(
lightFlag
?
1
:
0
));
dest
.
writeString
(
tipLightOn
);
dest
.
writeString
(
tipLightOff
);
dest
.
writeLong
(
delayTime
);
}
@Override
public
int
describeContents
()
{
return
0
;
}
public
static
final
Creator
<
PageInfoBean
>
CREATOR
=
new
Creator
<
PageInfoBean
>()
{
@Override
public
PageInfoBean
createFromParcel
(
Parcel
in
)
{
return
new
PageInfoBean
(
in
);
}
@Override
public
PageInfoBean
[]
newArray
(
int
size
)
{
return
new
PageInfoBean
[
size
];
}
};
public
static
String
getTAG
()
{
return
TAG
;
}
public
String
getTitle
()
{
return
title
;
}
public
void
setTitle
(
String
title
)
{
this
.
title
=
title
;
}
public
String
getTipScan
()
{
return
tipScan
;
}
public
void
setTipScan
(
String
tipScan
)
{
this
.
tipScan
=
tipScan
;
}
public
String
getTipInput
()
{
return
tipInput
;
}
public
void
setTipInput
(
String
tipInput
)
{
this
.
tipInput
=
tipInput
;
}
public
String
getTipLoading
()
{
return
tipLoading
;
}
public
void
setTipLoading
(
String
tipLoading
)
{
this
.
tipLoading
=
tipLoading
;
}
public
String
getTipNetworkError
()
{
return
tipNetworkError
;
}
public
void
setTipNetworkError
(
String
tipNetworkError
)
{
this
.
tipNetworkError
=
tipNetworkError
;
}
public
String
getTipOffline
()
{
return
tipOffline
;
}
public
void
setTipOffline
(
String
tipOffline
)
{
this
.
tipOffline
=
tipOffline
;
}
public
String
getOpenButton
()
{
return
openButton
;
}
public
void
setOpenButton
(
String
openButton
)
{
this
.
openButton
=
openButton
;
}
public
String
getFooterFirst
()
{
return
footerFirst
;
}
public
void
setFooterFirst
(
String
footerFirst
)
{
this
.
footerFirst
=
footerFirst
;
}
public
String
getFooterSecond
()
{
return
footerSecond
;
}
public
void
setFooterSecond
(
String
footerSecond
)
{
this
.
footerSecond
=
footerSecond
;
}
public
String
getBarTitle
()
{
return
barTitle
;
}
public
void
setBarTitle
(
String
barTitle
)
{
this
.
barTitle
=
barTitle
;
}
public
boolean
isExplainFlag
()
{
return
explainFlag
;
}
public
void
setExplainFlag
(
boolean
explainFlag
)
{
this
.
explainFlag
=
explainFlag
;
}
public
boolean
isInputFlag
()
{
return
inputFlag
;
}
public
void
setInputFlag
(
boolean
inputFlag
)
{
this
.
inputFlag
=
inputFlag
;
}
public
boolean
isLightFlag
()
{
return
lightFlag
;
}
public
void
setLightFlag
(
boolean
lightFlag
)
{
this
.
lightFlag
=
lightFlag
;
}
public
String
getTipLightOn
()
{
return
tipLightOn
;
}
public
void
setTipLightOn
(
String
tipLightOn
)
{
this
.
tipLightOn
=
tipLightOn
;
}
public
String
getTipLightOff
()
{
return
tipLightOff
;
}
public
void
setTipLightOff
(
String
tipLightOff
)
{
this
.
tipLightOff
=
tipLightOff
;
}
public
long
getDelayTime
()
{
return
delayTime
;
}
public
void
setDelayTime
(
long
delayTime
)
{
this
.
delayTime
=
delayTime
;
}
public
static
Creator
<
PageInfoBean
>
getCREATOR
()
{
return
CREATOR
;
}
}
src/android/src/com/jieweifu/plugins/barcode/camera/AutoFocusCallback.java
deleted
100644 → 0
View file @
cc15978b
package
com
.
jieweifu
.
plugins
.
barcode
.
camera
;
import
android.hardware.Camera
;
import
android.os.Handler
;
import
android.os.Message
;
import
android.util.Log
;
final
class
AutoFocusCallback
implements
Camera
.
AutoFocusCallback
{
private
static
final
String
TAG
=
AutoFocusCallback
.
class
.
getSimpleName
();
private
static
final
long
AUTOFOCUS_INTERVAL_MS
=
1500L
;
private
Handler
autoFocusHandler
;
private
int
autoFocusMessage
;
void
setHandler
(
Handler
autoFocusHandler
,
int
autoFocusMessage
)
{
this
.
autoFocusHandler
=
autoFocusHandler
;
this
.
autoFocusMessage
=
autoFocusMessage
;
}
public
void
onAutoFocus
(
boolean
success
,
Camera
camera
)
{
if
(
autoFocusHandler
!=
null
)
{
Message
message
=
autoFocusHandler
.
obtainMessage
(
autoFocusMessage
,
success
);
autoFocusHandler
.
sendMessageDelayed
(
message
,
AUTOFOCUS_INTERVAL_MS
);
autoFocusHandler
=
null
;
}
else
{
Log
.
d
(
TAG
,
"Got auto-focus callback, but no handler for it"
);
}
}
}
src/android/src/com/jieweifu/plugins/barcode/camera/CameraConfigurationManager.java
deleted
100644 → 0
View file @
cc15978b
package
com
.
jieweifu
.
plugins
.
barcode
.
camera
;
import
java.util.regex.Pattern
;
import
android.content.Context
;
import
android.graphics.Point
;
import
android.hardware.Camera
;
import
android.os.Build
;
import
android.util.Log
;
import
android.view.Display
;
import
android.view.WindowManager
;
final
class
CameraConfigurationManager
{
private
static
final
String
TAG
=
CameraConfigurationManager
.
class
.
getSimpleName
();
private
static
final
int
TEN_DESIRED_ZOOM
=
27
;
private
static
final
Pattern
COMMA_PATTERN
=
Pattern
.
compile
(
","
);
private
final
Context
context
;
private
Point
screenResolution
;
private
Point
cameraResolution
;
private
int
previewFormat
;
private
String
previewFormatString
;
CameraConfigurationManager
(
Context
context
)
{
this
.
context
=
context
;
}
@SuppressWarnings
(
"deprecation"
)
void
initFromCameraParameters
(
Camera
camera
)
{
Camera
.
Parameters
parameters
=
camera
.
getParameters
();
previewFormat
=
parameters
.
getPreviewFormat
();
previewFormatString
=
parameters
.
get
(
"preview-format"
);
WindowManager
manager
=
(
WindowManager
)
context
.
getSystemService
(
Context
.
WINDOW_SERVICE
);
Display
display
=
manager
.
getDefaultDisplay
();
screenResolution
=
new
Point
(
display
.
getWidth
(),
display
.
getHeight
());
Point
screenResolutionForCamera
=
new
Point
();
screenResolutionForCamera
.
x
=
screenResolution
.
x
;
screenResolutionForCamera
.
y
=
screenResolution
.
y
;
if
(
screenResolution
.
x
<
screenResolution
.
y
)
{
screenResolutionForCamera
.
x
=
screenResolution
.
y
;
screenResolutionForCamera
.
y
=
screenResolution
.
x
;
}
cameraResolution
=
getCameraResolution
(
parameters
,
screenResolutionForCamera
);
}
void
setDesiredCameraParameters
(
Camera
camera
)
{
Camera
.
Parameters
parameters
=
camera
.
getParameters
();
parameters
.
setPreviewSize
(
cameraResolution
.
x
,
cameraResolution
.
y
);
setFlash
(
parameters
);
setZoom
(
parameters
);
camera
.
setDisplayOrientation
(
90
);
camera
.
setParameters
(
parameters
);
}
Point
getCameraResolution
()
{
return
cameraResolution
;
}
Point
getScreenResolution
()
{
return
screenResolution
;
}
int
getPreviewFormat
()
{
return
previewFormat
;
}
String
getPreviewFormatString
()
{
return
previewFormatString
;
}
private
static
Point
getCameraResolution
(
Camera
.
Parameters
parameters
,
Point
screenResolution
)
{
String
previewSizeValueString
=
parameters
.
get
(
"preview-size-values"
);
if
(
previewSizeValueString
==
null
)
{
previewSizeValueString
=
parameters
.
get
(
"preview-size-value"
);
}
Point
cameraResolution
=
null
;
if
(
previewSizeValueString
!=
null
)
{
cameraResolution
=
findBestPreviewSizeValue
(
previewSizeValueString
,
screenResolution
);
}
if
(
cameraResolution
==
null
)
{
cameraResolution
=
new
Point
((
screenResolution
.
x
>>
3
)
<<
3
,
(
screenResolution
.
y
>>
3
)
<<
3
);
}
return
cameraResolution
;
}
private
static
Point
findBestPreviewSizeValue
(
CharSequence
previewSizeValueString
,
Point
screenResolution
)
{
int
bestX
=
0
;
int
bestY
=
0
;
int
diff
=
Integer
.
MAX_VALUE
;
for
(
String
previewSize
:
COMMA_PATTERN
.
split
(
previewSizeValueString
))
{
previewSize
=
previewSize
.
trim
();
int
dimPosition
=
previewSize
.
indexOf
(
'x'
);
if
(
dimPosition
<
0
)
{
continue
;
}
int
newX
;
int
newY
;
try
{
newX
=
Integer
.
parseInt
(
previewSize
.
substring
(
0
,
dimPosition
));
newY
=
Integer
.
parseInt
(
previewSize
.
substring
(
dimPosition
+
1
));
}
catch
(
NumberFormatException
nfe
)
{
continue
;
}
int
newDiff
=
Math
.
abs
(
newX
-
screenResolution
.
x
)
+
Math
.
abs
(
newY
-
screenResolution
.
y
);
if
(
newDiff
==
0
)
{
bestX
=
newX
;
bestY
=
newY
;
break
;
}
else
if
(
newDiff
<
diff
)
{
bestX
=
newX
;
bestY
=
newY
;
diff
=
newDiff
;
}
}
if
(
bestX
>
0
&&
bestY
>
0
)
{
return
new
Point
(
bestX
,
bestY
);
}
return
null
;
}
private
static
int
findBestMotZoomValue
(
CharSequence
stringValues
,
int
tenDesiredZoom
)
{
int
tenBestValue
=
0
;
for
(
String
stringValue
:
COMMA_PATTERN
.
split
(
stringValues
))
{
stringValue
=
stringValue
.
trim
();
double
value
;
try
{
value
=
Double
.
parseDouble
(
stringValue
);
}
catch
(
NumberFormatException
nfe
)
{
return
tenDesiredZoom
;
}
int
tenValue
=
(
int
)
(
10.0
*
value
);
if
(
Math
.
abs
(
tenDesiredZoom
-
value
)
<
Math
.
abs
(
tenDesiredZoom
-
tenBestValue
))
{
tenBestValue
=
tenValue
;
}
}
return
tenBestValue
;
}
private
void
setFlash
(
Camera
.
Parameters
parameters
)
{
if
(
Build
.
MODEL
.
contains
(
"Behold II"
)
&&
CameraManager
.
SDK_INT
==
3
)
{
// 3
parameters
.
set
(
"flash-value"
,
1
);
}
else
{
parameters
.
set
(
"flash-value"
,
2
);
}
parameters
.
set
(
"flash-mode"
,
"off"
);
}
private
void
setZoom
(
Camera
.
Parameters
parameters
)
{
String
zoomSupportedString
=
parameters
.
get
(
"zoom-supported"
);
if
(
zoomSupportedString
!=
null
&&
!
Boolean
.
parseBoolean
(
zoomSupportedString
))
{
return
;
}
int
tenDesiredZoom
=
TEN_DESIRED_ZOOM
;
String
maxZoomString
=
parameters
.
get
(
"max-zoom"
);
if
(
maxZoomString
!=
null
)
{
try
{
int
tenMaxZoom
=
(
int
)
(
10.0
*
Double
.
parseDouble
(
maxZoomString
));
if
(
tenDesiredZoom
>
tenMaxZoom
)
{
tenDesiredZoom
=
tenMaxZoom
;
}
}
catch
(
NumberFormatException
nfe
)
{
Log
.
w
(
TAG
,
"Bad max-zoom: "
+
maxZoomString
);
}
}
String
takingPictureZoomMaxString
=
parameters
.
get
(
"taking-picture-zoom-max"
);
if
(
takingPictureZoomMaxString
!=
null
)
{
try
{
int
tenMaxZoom
=
Integer
.
parseInt
(
takingPictureZoomMaxString
);
if
(
tenDesiredZoom
>
tenMaxZoom
)
{
tenDesiredZoom
=
tenMaxZoom
;
}
}
catch
(
NumberFormatException
nfe
)
{
Log
.
w
(
TAG
,
"Bad taking-picture-zoom-max: "
+
takingPictureZoomMaxString
);
}
}
String
motZoomValuesString
=
parameters
.
get
(
"mot-zoom-values"
);
if
(
motZoomValuesString
!=
null
)
{
tenDesiredZoom
=
findBestMotZoomValue
(
motZoomValuesString
,
tenDesiredZoom
);
}
String
motZoomStepString
=
parameters
.
get
(
"mot-zoom-step"
);
if
(
motZoomStepString
!=
null
)
{
try
{
double
motZoomStep
=
Double
.
parseDouble
(
motZoomStepString
.
trim
());
int
tenZoomStep
=
(
int
)
(
10.0
*
motZoomStep
);
if
(
tenZoomStep
>
1
)
{
tenDesiredZoom
-=
tenDesiredZoom
%
tenZoomStep
;
}
}
catch
(
NumberFormatException
nfe
)
{
// continue
}
}
// Set zoom. This helps encourage the user to pull back.
// Some devices like the Behold have a zoom parameter
if
(
maxZoomString
!=
null
||
motZoomValuesString
!=
null
)
{
parameters
.
set
(
"zoom"
,
String
.
valueOf
(
tenDesiredZoom
/
10.0
));
}
// Most devices, like the Hero, appear to expose this zoom parameter.
// It takes on values like "27" which appears to mean 2.7x zoom
if
(
takingPictureZoomMaxString
!=
null
)
{
parameters
.
set
(
"taking-picture-zoom"
,
tenDesiredZoom
);
}
}
}
src/android/src/com/jieweifu/plugins/barcode/camera/CameraManager.java
deleted
100644 → 0
View file @
cc15978b
package
com
.
jieweifu
.
plugins
.
barcode
.
camera
;
import
java.io.IOException
;
import
android.content.Context
;
import
android.graphics.Point
;
import
android.hardware.Camera
;
import
android.hardware.Camera.Parameters
;
import
android.os.Handler
;
import
android.view.SurfaceHolder
;
public
final
class
CameraManager
{
private
static
CameraManager
cameraManager
;
static
final
int
SDK_INT
;
static
{
int
sdkInt
;
try
{
sdkInt
=
android
.
os
.
Build
.
VERSION
.
SDK_INT
;
}
catch
(
NumberFormatException
nfe
)
{
sdkInt
=
10000
;
}
SDK_INT
=
sdkInt
;
}
private
final
CameraConfigurationManager
configManager
;
private
Camera
camera
;
private
boolean
initialized
;
private
boolean
previewing
;
private
final
boolean
useOneShotPreviewCallback
;
private
final
PreviewCallback
previewCallback
;
private
final
AutoFocusCallback
autoFocusCallback
;
private
Parameters
parameter
;
public
static
void
init
(
Context
context
)
{
if
(
cameraManager
==
null
)
{
cameraManager
=
new
CameraManager
(
context
);
}
}
public
static
CameraManager
get
()
{
return
cameraManager
;
}
private
CameraManager
(
Context
context
)
{
this
.
configManager
=
new
CameraConfigurationManager
(
context
);
useOneShotPreviewCallback
=
SDK_INT
>
3
;
previewCallback
=
new
PreviewCallback
(
configManager
,
useOneShotPreviewCallback
);
autoFocusCallback
=
new
AutoFocusCallback
();
}
public
void
openDriver
(
SurfaceHolder
holder
)
throws
IOException
{
if
(
camera
==
null
)
{
camera
=
Camera
.
open
();
if
(
camera
==
null
)
{
throw
new
IOException
();
}
camera
.
setPreviewDisplay
(
holder
);
if
(!
initialized
)
{
initialized
=
true
;
configManager
.
initFromCameraParameters
(
camera
);
}
configManager
.
setDesiredCameraParameters
(
camera
);
FlashlightManager
.
enableFlashlight
();
}
}
public
Point
getCameraResolution
()
{
return
configManager
.
getCameraResolution
();
}
public
void
closeDriver
()
{
if
(
camera
!=
null
)
{
FlashlightManager
.
disableFlashlight
();
camera
.
release
();
camera
=
null
;
}
}
public
void
startPreview
()
{
if
(
camera
!=
null
&&
!
previewing
)
{
camera
.
startPreview
();
previewing
=
true
;
}
}
public
void
stopPreview
()
{
if
(
camera
!=
null
&&
previewing
)
{
if
(!
useOneShotPreviewCallback
)
{
camera
.
setPreviewCallback
(
null
);
}
camera
.
stopPreview
();
previewCallback
.
setHandler
(
null
,
0
);
autoFocusCallback
.
setHandler
(
null
,
0
);
previewing
=
false
;
}
}
public
void
requestPreviewFrame
(
Handler
handler
,
int
message
)
{
if
(
camera
!=
null
&&
previewing
)
{
previewCallback
.
setHandler
(
handler
,
message
);
if
(
useOneShotPreviewCallback
)
{
camera
.
setOneShotPreviewCallback
(
previewCallback
);
}
else
{
camera
.
setPreviewCallback
(
previewCallback
);
}
}
}
public
void
requestAutoFocus
(
Handler
handler
,
int
message
)
{
if
(
camera
!=
null
&&
previewing
)
{
autoFocusCallback
.
setHandler
(
handler
,
message
);
camera
.
autoFocus
(
autoFocusCallback
);
}
}
public
void
openLight
()
{
if
(
camera
!=
null
)
{
parameter
=
camera
.
getParameters
();
parameter
.
setFlashMode
(
Parameters
.
FLASH_MODE_TORCH
);
camera
.
setParameters
(
parameter
);
}
}
public
void
offLight
()
{
if
(
camera
!=
null
)
{
parameter
=
camera
.
getParameters
();
parameter
.
setFlashMode
(
Parameters
.
FLASH_MODE_OFF
);
camera
.
setParameters
(
parameter
);
}
}
}
src/android/src/com/jieweifu/plugins/barcode/camera/FlashlightManager.java
deleted
100644 → 0
View file @
cc15978b
package
com
.
jieweifu
.
plugins
.
barcode
.
camera
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
android.os.IBinder
;
import
android.util.Log
;
final
class
FlashlightManager
{
private
static
final
String
TAG
=
FlashlightManager
.
class
.
getSimpleName
();
private
static
final
Object
iHardwareService
;
private
static
final
Method
setFlashEnabledMethod
;
static
{
iHardwareService
=
getHardwareService
();
setFlashEnabledMethod
=
getSetFlashEnabledMethod
(
iHardwareService
);
if
(
iHardwareService
==
null
)
{
Log
.
v
(
TAG
,
"This device does supports control of a flashlight"
);
}
else
{
Log
.
v
(
TAG
,
"This device does not support control of a flashlight"
);
}
}
private
FlashlightManager
()
{
}
private
static
Object
getHardwareService
()
{
Class
<?>
serviceManagerClass
=
maybeForName
(
"android.os.ServiceManager"
);
if
(
serviceManagerClass
==
null
)
{
return
null
;
}
Method
getServiceMethod
=
maybeGetMethod
(
serviceManagerClass
,
"getService"
,
String
.
class
);
if
(
getServiceMethod
==
null
)
{
return
null
;
}
Object
hardwareService
=
invoke
(
getServiceMethod
,
null
,
"hardware"
);
if
(
hardwareService
==
null
)
{
return
null
;
}
Class
<?>
iHardwareServiceStubClass
=
maybeForName
(
"android.os.IHardwareService$Stub"
);
if
(
iHardwareServiceStubClass
==
null
)
{
return
null
;
}
Method
asInterfaceMethod
=
maybeGetMethod
(
iHardwareServiceStubClass
,
"asInterface"
,
IBinder
.
class
);
if
(
asInterfaceMethod
==
null
)
{
return
null
;
}
return
invoke
(
asInterfaceMethod
,
null
,
hardwareService
);
}
private
static
Method
getSetFlashEnabledMethod
(
Object
iHardwareService
)
{
if
(
iHardwareService
==
null
)
{
return
null
;
}
Class
<?>
proxyClass
=
iHardwareService
.
getClass
();
return
maybeGetMethod
(
proxyClass
,
"setFlashlightEnabled"
,
boolean
.
class
);
}
private
static
Class
<?>
maybeForName
(
String
name
)
{
try
{
return
Class
.
forName
(
name
);
}
catch
(
ClassNotFoundException
cnfe
)
{
// OK
return
null
;
}
catch
(
RuntimeException
re
)
{
Log
.
w
(
TAG
,
"Unexpected error while finding class "
+
name
,
re
);
return
null
;
}
}
private
static
Method
maybeGetMethod
(
Class
<?>
clazz
,
String
name
,
Class
<?>...
argClasses
)
{
try
{
return
clazz
.
getMethod
(
name
,
argClasses
);
}
catch
(
NoSuchMethodException
nsme
)
{
// OK
return
null
;
}
catch
(
RuntimeException
re
)
{
Log
.
w
(
TAG
,
"Unexpected error while finding method "
+
name
,
re
);
return
null
;
}
}
private
static
Object
invoke
(
Method
method
,
Object
instance
,
Object
...
args
)
{
try
{
return
method
.
invoke
(
instance
,
args
);
}
catch
(
IllegalAccessException
e
)
{
Log
.
w
(
TAG
,
"Unexpected error while invoking "
+
method
,
e
);
return
null
;
}
catch
(
InvocationTargetException
e
)
{
Log
.
w
(
TAG
,
"Unexpected error while invoking "
+
method
,
e
.
getCause
());
return
null
;
}
catch
(
RuntimeException
re
)
{
Log
.
w
(
TAG
,
"Unexpected error while invoking "
+
method
,
re
);
return
null
;
}
}
static
void
enableFlashlight
()
{
setFlashlight
(
true
);
}
static
void
disableFlashlight
()
{
setFlashlight
(
false
);
}
private
static
void
setFlashlight
(
boolean
active
)
{
if
(
iHardwareService
!=
null
)
{
invoke
(
setFlashEnabledMethod
,
iHardwareService
,
active
);
}
}
}
src/android/src/com/jieweifu/plugins/barcode/camera/PreviewCallback.java
deleted
100644 → 0
View file @
cc15978b
package
com
.
jieweifu
.
plugins
.
barcode
.
camera
;
import
android.graphics.Point
;
import
android.hardware.Camera
;
import
android.os.Handler
;
import
android.os.Message
;
import
android.util.Log
;
final
class
PreviewCallback
implements
Camera
.
PreviewCallback
{
private
static
final
String
TAG
=
PreviewCallback
.
class
.
getSimpleName
();
private
final
CameraConfigurationManager
configManager
;
private
final
boolean
useOneShotPreviewCallback
;
private
Handler
previewHandler
;
private
int
previewMessage
;
PreviewCallback
(
CameraConfigurationManager
configManager
,
boolean
useOneShotPreviewCallback
)
{
this
.
configManager
=
configManager
;
this
.
useOneShotPreviewCallback
=
useOneShotPreviewCallback
;
}
void
setHandler
(
Handler
previewHandler
,
int
previewMessage
)
{
this
.
previewHandler
=
previewHandler
;
this
.
previewMessage
=
previewMessage
;
}
public
void
onPreviewFrame
(
byte
[]
data
,
Camera
camera
)
{
Point
cameraResolution
=
configManager
.
getCameraResolution
();
if
(!
useOneShotPreviewCallback
)
{
camera
.
setPreviewCallback
(
null
);
}
if
(
previewHandler
!=
null
)
{
Message
message
=
previewHandler
.
obtainMessage
(
previewMessage
,
cameraResolution
.
x
,
cameraResolution
.
y
,
data
);
message
.
sendToTarget
();
previewHandler
=
null
;
}
else
{
Log
.
d
(
TAG
,
"Got preview callback, but no handler for it"
);
}
}
}
src/android/src/com/jieweifu/plugins/barcode/decode/CaptureActivityHandler.java
deleted
100644 → 0
View file @
cc15978b
package
com
.
jieweifu
.
plugins
.
barcode
.
decode
;
import
android.os.Handler
;
import
android.os.Message
;
import
__ANDROID_PACKAGE__.R
;
import
com.jieweifu.plugins.barcode.CaptureActivity
;
import
com.jieweifu.plugins.barcode.camera.CameraManager
;
public
final
class
CaptureActivityHandler
extends
Handler
{
DecodeThread
decodeThread
=
null
;
CaptureActivity
activity
=
null
;
private
State
state
;
private
enum
State
{
PREVIEW
,
SUCCESS
,
DONE
}
public
CaptureActivityHandler
(
CaptureActivity
activity
)
{
this
.
activity
=
activity
;
decodeThread
=
new
DecodeThread
(
activity
);
decodeThread
.
start
();
state
=
State
.
SUCCESS
;
CameraManager
.
get
().
startPreview
();
restartPreviewAndDecode
();
}
@Override
public
void
handleMessage
(
Message
message
)
{
switch
(
message
.
what
)
{
case
R
.
id
.
auto_focus
:
if
(
state
==
State
.
PREVIEW
)
{
CameraManager
.
get
().
requestAutoFocus
(
this
,
R
.
id
.
auto_focus
);
}
break
;
case
R
.
id
.
restart_preview
:
restartPreviewAndDecode
();
break
;
case
R
.
id
.
decode_succeeded
:
state
=
State
.
SUCCESS
;
activity
.
handleDecode
((
String
)
message
.
obj
);
// 解析成功,回调
break
;
case
R
.
id
.
decode_failed
:
state
=
State
.
PREVIEW
;
CameraManager
.
get
().
requestPreviewFrame
(
decodeThread
.
getHandler
(),
R
.
id
.
decode
);
break
;
}
}
public
void
quitSynchronously
()
{
state
=
State
.
DONE
;
CameraManager
.
get
().
stopPreview
();
removeMessages
(
R
.
id
.
decode_succeeded
);
removeMessages
(
R
.
id
.
decode_failed
);
removeMessages
(
R
.
id
.
decode
);
removeMessages
(
R
.
id
.
auto_focus
);
}
private
void
restartPreviewAndDecode
()
{
if
(
state
==
State
.
SUCCESS
)
{
state
=
State
.
PREVIEW
;
CameraManager
.
get
().
requestPreviewFrame
(
decodeThread
.
getHandler
(),
R
.
id
.
decode
);
CameraManager
.
get
().
requestAutoFocus
(
this
,
R
.
id
.
auto_focus
);
}
}
}
src/android/src/com/jieweifu/plugins/barcode/decode/DecodeHandler.java
deleted
100644 → 0
View file @
cc15978b
package
com
.
jieweifu
.
plugins
.
barcode
.
decode
;
import
android.os.Handler
;
import
android.os.Looper
;
import
android.os.Message
;
import
__ANDROID_PACKAGE__.R
;
import
com.jieweifu.plugins.barcode.CaptureActivity
;
import
com.zbar.lib.ZbarManager
;
final
class
DecodeHandler
extends
Handler
{
CaptureActivity
activity
=
null
;
DecodeHandler
(
CaptureActivity
activity
)
{
this
.
activity
=
activity
;
}
@Override
public
void
handleMessage
(
Message
message
)
{
switch
(
message
.
what
)
{
case
R
.
id
.
decode
:
decode
((
byte
[])
message
.
obj
,
message
.
arg1
,
message
.
arg2
);
break
;
case
R
.
id
.
quit
:
Looper
.
myLooper
().
quit
();
break
;
}
}
private
void
decode
(
byte
[]
data
,
int
width
,
int
height
)
{
byte
[]
rotatedData
=
new
byte
[
data
.
length
];
for
(
int
y
=
0
;
y
<
height
;
y
++)
{
for
(
int
x
=
0
;
x
<
width
;
x
++)
rotatedData
[
x
*
height
+
height
-
y
-
1
]
=
data
[
x
+
y
*
width
];
}
int
tmp
=
width
;
// Here we are swapping, that's the difference to #11
width
=
height
;
height
=
tmp
;
ZbarManager
manager
=
new
ZbarManager
();
String
result
=
manager
.
decode
(
rotatedData
,
width
,
height
,
true
,
activity
.
getX
(),
activity
.
getY
(),
activity
.
getCropWidth
(),
activity
.
getCropHeight
());
if
(
result
!=
null
)
{
if
(
null
!=
activity
.
getHandler
()){
Message
msg
=
new
Message
();
msg
.
obj
=
result
;
msg
.
what
=
R
.
id
.
decode_succeeded
;
activity
.
getHandler
().
sendMessage
(
msg
);
}
}
else
{
if
(
null
!=
activity
.
getHandler
())
{
activity
.
getHandler
().
sendEmptyMessage
(
R
.
id
.
decode_failed
);
}
}
}
}
src/android/src/com/jieweifu/plugins/barcode/decode/DecodeThread.java
deleted
100644 → 0
View file @
cc15978b
package
com
.
jieweifu
.
plugins
.
barcode
.
decode
;
import
java.util.concurrent.CountDownLatch
;
import
com.jieweifu.plugins.barcode.CaptureActivity
;
import
android.os.Handler
;
import
android.os.Looper
;
final
class
DecodeThread
extends
Thread
{
CaptureActivity
activity
;
private
Handler
handler
;
private
final
CountDownLatch
handlerInitLatch
;
DecodeThread
(
CaptureActivity
activity
)
{
this
.
activity
=
activity
;
handlerInitLatch
=
new
CountDownLatch
(
1
);
}
Handler
getHandler
()
{
try
{
handlerInitLatch
.
await
();
}
catch
(
InterruptedException
ie
)
{
// continue?
}
return
handler
;
}
@Override
public
void
run
()
{
Looper
.
prepare
();
handler
=
new
DecodeHandler
(
activity
);
handlerInitLatch
.
countDown
();
Looper
.
loop
();
}
}
src/android/src/com/jieweifu/plugins/barcode/decode/FinishListener.java
deleted
100644 → 0
View file @
cc15978b
package
com
.
jieweifu
.
plugins
.
barcode
.
decode
;
import
android.app.Activity
;
import
android.content.DialogInterface
;
public
final
class
FinishListener
implements
DialogInterface
.
OnClickListener
,
DialogInterface
.
OnCancelListener
,
Runnable
{
private
final
Activity
activityToFinish
;
public
FinishListener
(
Activity
activityToFinish
)
{
this
.
activityToFinish
=
activityToFinish
;
}
public
void
onCancel
(
DialogInterface
dialogInterface
)
{
run
();
}
public
void
onClick
(
DialogInterface
dialogInterface
,
int
i
)
{
run
();
}
public
void
run
()
{
activityToFinish
.
finish
();
}
}
src/android/src/com/jieweifu/plugins/barcode/decode/InactivityTimer.java
deleted
100644 → 0
View file @
cc15978b
package
com
.
jieweifu
.
plugins
.
barcode
.
decode
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.ScheduledFuture
;
import
java.util.concurrent.ThreadFactory
;
import
java.util.concurrent.TimeUnit
;
import
android.app.Activity
;
public
final
class
InactivityTimer
{
private
static
final
int
INACTIVITY_DELAY_SECONDS
=
5
*
60
;
private
final
ScheduledExecutorService
inactivityTimer
=
Executors
.
newSingleThreadScheduledExecutor
(
new
DaemonThreadFactory
());
private
final
Activity
activity
;
private
ScheduledFuture
<?>
inactivityFuture
=
null
;
public
InactivityTimer
(
Activity
activity
)
{
this
.
activity
=
activity
;
onActivity
();
}
public
void
onActivity
()
{
cancel
();
inactivityFuture
=
inactivityTimer
.
schedule
(
new
FinishListener
(
activity
),
INACTIVITY_DELAY_SECONDS
,
TimeUnit
.
SECONDS
);
}
private
void
cancel
()
{
if
(
inactivityFuture
!=
null
)
{
inactivityFuture
.
cancel
(
true
);
inactivityFuture
=
null
;
}
}
public
void
shutdown
()
{
cancel
();
inactivityTimer
.
shutdown
();
}
private
static
final
class
DaemonThreadFactory
implements
ThreadFactory
{
public
Thread
newThread
(
Runnable
runnable
)
{
Thread
thread
=
new
Thread
(
runnable
);
thread
.
setDaemon
(
true
);
return
thread
;
}
}
}
src/android/src/com/jieweifu/plugins/barcode/http/HttpManager.java
deleted
100644 → 0
View file @
cc15978b
package
com
.
jieweifu
.
plugins
.
barcode
.
http
;
import
android.os.Handler
;
import
android.os.Looper
;
import
android.util.Log
;
import
com.jieweifu.plugins.barcode.bean.ArgsBean
;
import
com.jieweifu.plugins.barcode.bean.CodeInfoBean
;
import
com.jieweifu.plugins.barcode.bean.HttpInfoBean
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
/**
* Created by panx on 2017/3/8.
*/
public
class
HttpManager
{
public
static
final
String
TAG
=
"HttpManager"
;
public
static
final
String
NETWORK_ERROR
=
"请求发生错误,请稍后再试!"
;
public
static
Handler
handler
=
new
Handler
(
Looper
.
getMainLooper
());
public
static
void
get
(
final
HttpInfoBean
httpInfoBean
,
final
ResultCallback
<
String
>
callback
){
new
Thread
(){
@Override
public
void
run
()
{
super
.
run
();
doGet
(
httpInfoBean
,
callback
);
}
}.
start
();
}
private
static
void
doGet
(
HttpInfoBean
httpInfoBean
,
final
ResultCallback
<
String
>
callback
){
HttpUtil
.
get
(
httpInfoBean
,
new
ResultCallback
<
String
>()
{
@Override
public
void
onError
(
Exception
e
,
String
error
)
{
handlerError
(
e
,
callback
);
}
@Override
public
void
onResponse
(
String
response
,
String
result
)
{
handlerSuccess
(
response
,
callback
);
}
});
}
public
static
void
post
(
final
HttpInfoBean
httpInfoBean
,
final
ResultCallback
<
String
>
callback
)
{
new
Thread
()
{
@Override
public
void
run
()
{
super
.
run
();
doPost
(
httpInfoBean
,
callback
);
}
}.
start
();
}
private
static
void
doPost
(
HttpInfoBean
httpInfoBean
,
final
ResultCallback
<
String
>
callback
)
{
HttpUtil
.
post
(
httpInfoBean
,
new
ResultCallback
<
String
>()
{
@Override
public
void
onError
(
Exception
e
,
String
error
)
{
handlerError
(
e
,
callback
);
}
@Override
public
void
onResponse
(
String
response
,
String
result
)
{
handlerSuccess
(
response
,
callback
);
}
});
}
/**
* 网络请求成功时的处理
* @param response
* @param callback
*/
private
static
void
handlerSuccess
(
final
String
response
,
final
ResultCallback
callback
)
{
handler
.
post
(
new
Runnable
()
{
@Override
public
void
run
()
{
callback
.
onResponse
(
response
,
""
);
}
});
}
/**
* 网络请求失败的处理
* @param e
* @param callback
*/
private
static
void
handlerError
(
final
Exception
e
,
final
ResultCallback
callback
)
{
handler
.
post
(
new
Runnable
()
{
@Override
public
void
run
()
{
callback
.
onError
(
e
,
NETWORK_ERROR
);
}
});
}
}
src/android/src/com/jieweifu/plugins/barcode/http/HttpUtil.java
deleted
100644 → 0
View file @
cc15978b
package
com
.
jieweifu
.
plugins
.
barcode
.
http
;
import
android.content.Intent
;
import
android.util.Log
;
import
com.jieweifu.plugins.barcode.Util.NoSSLv3SocketFactory
;
import
com.jieweifu.plugins.barcode.bean.ArgsBean
;
import
com.jieweifu.plugins.barcode.bean.HttpInfoBean
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
java.io.BufferedInputStream
;
import
java.io.BufferedReader
;
import
java.io.ByteArrayOutputStream
;
import
java.io.DataOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.io.PrintWriter
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
javax.net.ssl.HttpsURLConnection
;
import
javax.net.ssl.SSLSocketFactory
;
import
javax.net.ssl.TrustManager
;
/**
* Created by panx on 2017/3/8.
*/
public
class
HttpUtil
{
/**
* 从网络获取json数据,(String byte[})
*
* @param httpInfoBean
* @return
*/
public
static
String
get
(
HttpInfoBean
httpInfoBean
,
ResultCallback
<
String
>
callback
)
{
try
{
URL
url
=
new
URL
(
httpInfoBean
.
getUrl
());
//打开连接
HttpsURLConnection
urlConnection
=
(
HttpsURLConnection
)
url
.
openConnection
();
urlConnection
.
setRequestMethod
(
"GET"
);
urlConnection
.
setSSLSocketFactory
(
new
NoSSLv3SocketFactory
());
urlConnection
.
setRequestProperty
(
"Authorization"
,
httpInfoBean
.
getHeaders
().
getAuthorization
());
urlConnection
.
setRequestProperty
(
"Content-Type"
,
httpInfoBean
.
getHeaders
().
getContentType
());
if
(
200
==
urlConnection
.
getResponseCode
())
{
//得到输入流
InputStream
is
=
urlConnection
.
getInputStream
();
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
1024
];
int
len
=
0
;
while
(-
1
!=
(
len
=
is
.
read
(
buffer
)))
{
baos
.
write
(
buffer
,
0
,
len
);
baos
.
flush
();
}
System
.
out
.
println
(
baos
.
toString
());
baos
.
close
();
urlConnection
.
disconnect
();
callback
.
onResponse
(
baos
.
toString
(),
""
);
return
baos
.
toString
(
"utf-8"
);
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
callback
.
onError
(
e
,
null
);
}
return
null
;
}
//获取其他页面的数据
/**
* POST请求获取数据
*/
public
static
String
post
(
HttpInfoBean
httpInfoBean
,
ResultCallback
<
String
>
callback
)
{
URL
url
=
null
;
try
{
url
=
new
URL
(
httpInfoBean
.
getUrl
());
HttpsURLConnection
connection
=
(
HttpsURLConnection
)
url
.
openConnection
();
connection
.
setRequestMethod
(
"POST"
);
connection
.
setConnectTimeout
(
httpInfoBean
.
getConfig
().
getTimeout
());
connection
.
setReadTimeout
(
30000
);
connection
.
setDoOutput
(
true
);
// 是否输入参数
connection
.
setDoInput
(
true
);
connection
.
setSSLSocketFactory
(
new
NoSSLv3SocketFactory
());
connection
.
setRequestProperty
(
"Authorization"
,
httpInfoBean
.
getHeaders
().
getAuthorization
());
connection
.
setRequestProperty
(
"Content-Type"
,
httpInfoBean
.
getHeaders
().
getContentType
());
connection
.
connect
();
DataOutputStream
out
=
new
DataOutputStream
(
connection
.
getOutputStream
());
out
.
writeBytes
(
httpInfoBean
.
getData
());
out
.
flush
();
out
.
close
();
//读取响应
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
connection
.
getInputStream
()));
String
lines
;
StringBuffer
sb
=
new
StringBuffer
(
""
);
while
((
lines
=
reader
.
readLine
())
!=
null
)
{
lines
=
new
String
(
lines
.
getBytes
(),
"utf-8"
);
sb
.
append
(
lines
);
}
callback
.
onResponse
(
sb
.
toString
(),
null
);
reader
.
close
();
// 断开连接
connection
.
disconnect
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
callback
.
onError
(
e
,
null
);
}
return
null
;
}
}
src/android/src/com/jieweifu/plugins/barcode/http/ResultCallback.java
deleted
100644 → 0
View file @
cc15978b
package
com
.
jieweifu
.
plugins
.
barcode
.
http
;
/**
* Created by panx on 2017/3/8.
*/
public
abstract
class
ResultCallback
<
T
>
{
public
abstract
void
onError
(
Exception
e
,
String
error
);
public
abstract
void
onResponse
(
T
response
,
String
result
);
}
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