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
1fb75bf1
authored
Aug 16, 2019
by
patpat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改TimerHelper回调
parent
6fe0f7d4
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
21 additions
and
21 deletions
+21
-21
app/src/main/java/com/bgycc/smartcanteen/action/WifiAction.kt
+2
-3
app/src/main/java/com/bgycc/smartcanteen/activity/MainActivity.kt
+1
-1
app/src/main/java/com/bgycc/smartcanteen/helper/TimerHelper.kt
+12
-10
app/src/main/java/com/bgycc/smartcanteen/server/websocket/MainWebSocket.java
+2
-2
app/src/main/java/com/bgycc/smartcanteen/task/ButtonTask.kt
+1
-1
app/src/main/java/com/bgycc/smartcanteen/task/QRCodeTask.java
+3
-4
No files found.
app/src/main/java/com/bgycc/smartcanteen/action/WifiAction.kt
View file @
1fb75bf1
...
...
@@ -76,7 +76,7 @@ class WifiAction private constructor() : Action(ActionEnum.CONFIG_WIFI.name) {
}
EventBus
.
getDefault
().
post
(
WifiStateEvent
(
30
,
"正在连接Wifi"
))
TimerHelper
.
loop
({
_
,
isLastTime
->
TimerHelper
.
loop
({
id
,
isLastTime
->
if
(
isLastTime
)
{
if
(
state
==
State
.
STARTED
)
{
state
=
State
.
FAIL
...
...
@@ -97,11 +97,10 @@ class WifiAction private constructor() : Action(ActionEnum.CONFIG_WIFI.name) {
state
=
State
.
INITED
EventBus
.
getDefault
().
post
(
WifiStateEvent
(-
1
))
},
3000
)
return
@loop
false
TimerHelper
.
cancel
(
id
)
}
}
}
return
@loop
true
},
1000
,
10
)
}
catch
(
e
:
Exception
)
{
...
...
app/src/main/java/com/bgycc/smartcanteen/activity/MainActivity.kt
View file @
1fb75bf1
...
...
@@ -93,7 +93,7 @@ class MainActivity : BaseActivity() {
}
private
fun
initTimer
()
{
TimerHelper
.
loop
(
Runnable
{
TimerHelper
.
loop
(
{
_
,
_
->
mHandler
.
post
{
_wifi
.
text
=
"Wifi Mac: ${WifiHelpler.getMacAddress()} SSID: ${WifiHelpler.getSSID()} IP: ${WifiHelpler.getIpString()}"
_time
.
text
=
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
,
Locale
.
getDefault
()).
format
(
Date
())
...
...
app/src/main/java/com/bgycc/smartcanteen/helper/TimerHelper.kt
View file @
1fb75bf1
...
...
@@ -47,18 +47,17 @@ object TimerHelper {
return
id
}
fun
loop
(
runnable
:
Runnable
,
period
:
Long
):
Long
{
return
loop
(
runnable
,
period
,
-
1
)
fun
loop
(
task
:
LoopTask
,
period
:
Long
):
Long
{
return
loop
(
task
,
period
,
-
1
)
}
fun
loop
(
runnable
:
Runnable
,
period
:
Long
,
times
:
Int
):
Long
{
return
loop
({
_
:
Long
,
_
:
Boolean
->
runnable
.
run
()
true
fun
loop
(
task
:
LoopTask
,
period
:
Long
,
times
:
Int
):
Long
{
return
loop
({
id
:
Long
,
isLastTime
:
Boolean
->
task
.
run
(
id
,
isLastTime
)
},
period
,
times
)
}
fun
loop
(
runnable
:
(
id
:
Long
,
isLastTime
:
Boolean
)
->
Boolean
,
period
:
Long
,
times
:
Int
=
-
1
):
Long
{
fun
loop
(
runnable
:
(
id
:
Long
,
isLastTime
:
Boolean
)
->
Unit
,
period
:
Long
,
times
:
Int
=
-
1
):
Long
{
val
id
=
mId
mFutureList
.
put
(
id
,
mScheduledExecutorService
.
scheduleAtFixedRate
(
object
:
Runnable
{
var
vTimes
=
0
...
...
@@ -71,9 +70,7 @@ object TimerHelper {
}
}
try
{
if
(!
runnable
(
id
,
vTimes
==
times
))
{
cancel
(
id
)
}
runnable
(
id
,
vTimes
==
times
)
}
catch
(
e
:
Exception
)
{
Log
.
w
(
TAG
,
"loop id: $id times: $vTimes error: ${e.message}"
)
}
...
...
@@ -81,4 +78,8 @@ object TimerHelper {
},
0
,
period
,
TimeUnit
.
MILLISECONDS
))
return
id
}
interface
LoopTask
{
fun
run
(
id
:
Long
,
isLastTime
:
Boolean
)
}
}
\ No newline at end of file
app/src/main/java/com/bgycc/smartcanteen/server/websocket/MainWebSocket.java
View file @
1fb75bf1
...
...
@@ -59,9 +59,9 @@ public class MainWebSocket extends WebSocketClient {
EventBus
.
getDefault
().
post
(
new
ConnectStateEvent
(
ConnectStateEvent
.
CONNECTING
));
sInstance
=
new
MainWebSocket
(
new
URI
(
String
.
format
(
AppConfig
.
getMainWebSocketServerUrl
(),
sDeviceSN
)));
sInstance
.
connect
();
TimerHelper
.
INSTANCE
.
loop
(
new
Runnable
()
{
TimerHelper
.
INSTANCE
.
loop
(
new
TimerHelper
.
LoopTask
()
{
@Override
public
void
run
()
{
public
void
run
(
long
id
,
boolean
isLastTime
)
{
if
(
sInstance
.
isClosed
())
{
sInstance
.
reconnect
();
EventBus
.
getDefault
().
post
(
new
ConnectStateEvent
(
ConnectStateEvent
.
RECONNECTING
));
...
...
app/src/main/java/com/bgycc/smartcanteen/task/ButtonTask.kt
View file @
1fb75bf1
...
...
@@ -17,7 +17,7 @@ object ButtonTask {
fun
start
()
{
if
(
mTimerId
<
0
)
{
mAudioManager
=
App
.
getDefault
().
getSystemService
(
Context
.
AUDIO_SERVICE
)
as
AudioManager
mTimerId
=
TimerHelper
.
loop
(
Runnable
{
mTimerId
=
TimerHelper
.
loop
(
{
_
,
_
->
val
buf
=
ByteArray
(
5
)
libszxb
.
devicekey
(
buf
)
// Log.i(TAG, String.format("%02x %02x %02x %02x", buf[0], buf[1], buf[2], buf[3]));
...
...
app/src/main/java/com/bgycc/smartcanteen/task/QRCodeTask.java
View file @
1fb75bf1
...
...
@@ -46,13 +46,12 @@ public class QRCodeTask {
if
(
mScanAsyncTask
==
null
)
{
mScanAsyncTask
=
new
ScanAsyncTask
();
TimerHelper
.
INSTANCE
.
loop
(
new
Function2
<
Long
,
Boolean
,
Boolean
>
()
{
TimerHelper
.
INSTANCE
.
loop
(
new
TimerHelper
.
LoopTask
()
{
@Override
public
Boolean
invoke
(
Long
id
,
B
oolean
isLastTime
)
{
if
(
mScanAsyncTask
==
null
)
return
false
;
public
void
run
(
long
id
,
b
oolean
isLastTime
)
{
if
(
mScanAsyncTask
==
null
)
return
;
mScanAsyncTask
.
run
();
return
true
;
}
},
200
,
-
1
);
}
...
...
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