Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
huangzhicong
/
SmartCanteen
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
2683985d
authored
Nov 05, 2019
by
patpat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调整超时逻辑,超时后自动转为离线支付
parent
4a2f1ade
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
50 additions
and
18 deletions
+50
-18
.idea/misc.xml
+1
-1
app/build.gradle
+2
-2
app/src/main/java/com/bgycc/smartcanteen/App.kt
+2
-0
app/src/main/java/com/bgycc/smartcanteen/action/PayOnlineAction.java
+9
-3
app/src/main/java/com/bgycc/smartcanteen/activity/MainActivity.kt
+16
-4
app/src/main/java/com/bgycc/smartcanteen/server/websocket/MainWebSocket.java
+0
-1
app/src/main/java/com/bgycc/smartcanteen/task/QRCodeTask.java
+20
-7
No files found.
.idea/misc.xml
View file @
2683985d
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_1_
8
"
project-jdk-name=
"JDK"
project-jdk-type=
"JavaSDK"
>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_1_
7
"
project-jdk-name=
"JDK"
project-jdk-type=
"JavaSDK"
>
<output
url=
"file://$PROJECT_DIR$/build/classes"
/>
</component>
<component
name=
"ProjectType"
>
...
...
app/build.gradle
View file @
2683985d
...
...
@@ -10,8 +10,8 @@ android {
applicationId
"com.bgycc.smartcanteen"
minSdkVersion
21
targetSdkVersion
22
versionCode
5
versionName
"1.0.
5
"
versionCode
6
versionName
"1.0.
6
"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes
{
...
...
app/src/main/java/com/bgycc/smartcanteen/App.kt
View file @
2683985d
...
...
@@ -24,6 +24,8 @@ class App : Application() {
private
var
sVersionName
=
"0.0.0"
private
var
sVersionCode
=
0
var
testQRCode
=
""
fun
getDefault
():
App
{
return
sDefault
}
...
...
app/src/main/java/com/bgycc/smartcanteen/action/PayOnlineAction.java
View file @
2683985d
...
...
@@ -59,7 +59,6 @@ public class PayOnlineAction extends Action {
break
;
case
RESQUEST_FAIL:
case
RESPONSE_FAIL:
case
TIMEOUT:
EventBus
.
getDefault
().
post
(
new
PayStateEvent
(
PayStateEvent
.
StateEnum
.
FAIL
,
message
));
cancelTimeout
();
mPayCode
=
""
;
...
...
@@ -71,12 +70,18 @@ public class PayOnlineAction extends Action {
}
},
3000
);
break
;
case
TIMEOUT:
cancelTimeout
();
mPayCode
=
""
;
fail
(
message
);
setState
(
State
.
INITED
);
return
;
}
}
setState
(
state
);
}
public
void
exec
(
String
payCode
,
String
payCodeType
,
ActionResult
result
)
{
public
void
exec
(
final
String
payCode
,
final
String
payCodeType
,
ActionResult
result
)
{
if
(
getState
()
!=
State
.
INITED
)
{
if
(
result
!=
null
)
{
result
.
onFail
(
"正在忙"
);
...
...
@@ -93,13 +98,14 @@ public class PayOnlineAction extends Action {
public
void
run
(
long
id
,
boolean
isLastTime
)
{
if
(
isLastTime
)
{
setState
(
State
.
TIMEOUT
,
"交易超时"
);
PayOfflineAction
.
getDefault
().
exec
(
payCode
,
payCodeType
);
}
else
{
if
(
mActionRunnable
!=
null
)
{
mActionRunnable
.
run
();
}
}
}
},
10000
,
4
,
10
000
);
},
5000
,
2
,
5
000
);
final
MainWebSocket
.
Response
response
=
new
MainWebSocket
.
Response
()
{
@Override
...
...
app/src/main/java/com/bgycc/smartcanteen/activity/MainActivity.kt
View file @
2683985d
...
...
@@ -12,8 +12,11 @@ import android.view.animation.Animation
import
android.view.animation.RotateAnimation
import
com.bgycc.smartcanteen.App
import
com.bgycc.smartcanteen.AppConfig
import
com.bgycc.smartcanteen.BuildConfig
import
com.bgycc.smartcanteen.R
import
com.bgycc.smartcanteen.action.ActionEnum
import
com.bgycc.smartcanteen.action.ActionResult
import
com.bgycc.smartcanteen.action.PayOnlineAction
import
com.bgycc.smartcanteen.action.UpdateAction
import
com.bgycc.smartcanteen.event.*
import
com.bgycc.smartcanteen.helper.EthernetHelper
...
...
@@ -87,11 +90,7 @@ class MainActivity : BaseActivity() {
}
private
fun
initView
()
{
if
(!
AppConfig
.
DEBUG
)
{
_debug
.
visibility
=
View
.
GONE
}
else
{
_logo
.
visibility
=
View
.
GONE
}
_setting
.
alpha
=
0f
_setting_img
.
post
{
val
anim
=
RotateAnimation
(
0f
,
360f
,
0.5f
*
_setting_img
.
width
,
0.5f
*
_setting_img
.
height
)
...
...
@@ -103,6 +102,19 @@ class MainActivity : BaseActivity() {
_version
.
text
=
"Version: v${App.getVersionName()}(${App.getVersionCode()})"
_eth
.
text
=
"Ethernet Mac: ${EthernetHelper.getMacAddress()}"
_sn
.
text
=
"SN: ${App.getDeviceSN()}"
if
(
BuildConfig
.
DEBUG
)
{
_message
.
setOnClickListener
{
App
.
testQRCode
=
"380000000000000000"
}
_debug
.
setOnClickListener
{
_debug
.
visibility
=
View
.
GONE
_logo
.
visibility
=
View
.
VISIBLE
}
_logo
.
setOnClickListener
{
_debug
.
visibility
=
View
.
VISIBLE
_logo
.
visibility
=
View
.
GONE
}
}
}
private
fun
initTimer
()
{
...
...
app/src/main/java/com/bgycc/smartcanteen/server/websocket/MainWebSocket.java
View file @
2683985d
...
...
@@ -165,7 +165,6 @@ public class MainWebSocket extends WebSocketClient {
public
void
onOpen
(
ServerHandshake
handshakeData
)
{
LogUtil
.
i
(
TAG
,
String
.
format
(
"onOpen: %d %s"
,
handshakeData
.
getHttpStatus
(),
handshakeData
.
getHttpStatusMessage
()));
EventBus
.
getDefault
().
post
(
new
ConnectStateEvent
(
ConnectStateEvent
.
CONNECTED
));
PayOfflineAction
.
getDefault
().
upload
();
}
@Override
...
...
app/src/main/java/com/bgycc/smartcanteen/task/QRCodeTask.java
View file @
2683985d
package
com
.
bgycc
.
smartcanteen
.
task
;
import
android_serialport_api.SerialPort
;
import
com.bgycc.smartcanteen.App
;
import
com.bgycc.smartcanteen.event.QRCodeEvent
;
import
com.bgycc.smartcanteen.action.*
;
import
com.bgycc.smartcanteen.event.LogEvent
;
...
...
@@ -36,6 +37,7 @@ public class QRCodeTask {
private
ScanAsyncTask
mScanAsyncTask
;
private
SerialPort
mSerial
;
private
long
mTimerId
=
-
1
;
private
long
mOfflineUpdateDelay
=
0
;
private
QRCodeTask
()
{}
...
...
@@ -48,18 +50,24 @@ public class QRCodeTask {
if
(
mScanAsyncTask
==
null
)
{
mSerial
=
SerialPort
.
build
(
new
File
(
"/dev/ttyS6"
),
115200
,
0
);
if
(
mSerial
!=
null
)
{
mScanAsyncTask
=
new
ScanAsyncTask
();
mTimerId
=
TimerHelper
.
INSTANCE
.
loop
(
new
TimerHelper
.
LoopTask
()
{
@Override
public
void
run
(
long
id
,
boolean
isLastTime
)
{
if
(
mScanAsyncTask
==
null
)
return
;
if
(
mScanAsyncTask
!=
null
)
{
mScanAsyncTask
.
run
();
}
},
200
,
-
1
);
if
(
mOfflineUpdateDelay
>=
30000
)
{
if
(
MainWebSocket
.
isConnected
())
{
PayOfflineAction
.
getDefault
().
upload
();
mOfflineUpdateDelay
=
0
;
}
}
else
{
mOfflineUpdateDelay
+=
200
;
}
}
},
200
,
-
1
);
}
}
public
void
stop
()
{
...
...
@@ -85,10 +93,9 @@ public class QRCodeTask {
// Log.i(TAG, String.format("step: %d progress: %d", step, progress));
switch
(
step
)
{
case
0
:
if
(
progress
!=
0
)
break
;
LogUtils
.
file
(
TAG
,
"QRCode wait"
);
String
str
=
null
;
if
(
mSerial
!=
null
)
{
byte
[]
buf
=
null
;
int
len
=
0
;
while
(
true
)
{
...
...
@@ -107,8 +114,14 @@ public class QRCodeTask {
break
;
}
}
if
(
str
==
null
)
break
;
}
if
(!
App
.
Companion
.
getTestQRCode
().
isEmpty
())
{
str
=
App
.
Companion
.
getTestQRCode
();
App
.
Companion
.
setTestQRCode
(
""
);
}
if
(
progress
!=
0
||
str
==
null
)
break
;
mOfflineUpdateDelay
=
0
;
LogUtils
.
file
(
TAG
,
"QRCode: "
+
str
);
QRCodeEvent
event
=
new
QRCodeEvent
(
str
.
getBytes
(),
str
,
checkPayCodeType
(
str
));
EventBus
.
getDefault
().
post
(
event
);
...
...
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