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
a1da2f7d
authored
Mar 09, 2020
by
pye52
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化debug模式的日志输出
1、现在会在Socket链接成功时输出服务器地址 2、现在会完整输出扫码信息
parent
57ae0b72
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
11 deletions
+31
-11
app/build.gradle
+1
-1
app/src/main/java/com/bgycc/smartcanteen/MainActivity.java
+5
-3
app/src/main/java/com/bgycc/smartcanteen/socket/SCWebSocketClient.java
+5
-3
app/src/main/java/com/bgycc/smartcanteen/state/ConnectState.java
+18
-2
app/src/main/res/values/strings.xml
+2
-2
No files found.
app/build.gradle
View file @
a1da2f7d
...
...
@@ -8,7 +8,7 @@ android {
minSdkVersion
22
targetSdkVersion
22
versionCode
13
versionName
"1.3.
2
"
versionName
"1.3.
3
"
testInstrumentationRunner
"androidx.test.runner.AndroidJUnitRunner"
ndk
{
abiFilters
"armeabi"
,
"armeabi-v7a"
,
"x86"
,
"mips"
...
...
app/src/main/java/com/bgycc/smartcanteen/MainActivity.java
View file @
a1da2f7d
...
...
@@ -38,6 +38,7 @@ import com.bgycc.smartcanteen.viewModel.PayOnlineViewModel;
import
com.bgycc.smartcanteen.viewModel.QRCodeViewModel
;
import
com.bgycc.smartcanteen.viewModel.ViewModelFactory
;
import
com.blankj.utilcode.util.LogUtils
;
import
com.google.gson.Gson
;
import
java.net.URI
;
import
java.net.URISyntaxException
;
...
...
@@ -73,6 +74,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
private
TextView
message
;
private
AudioManager
audioManager
;
private
Gson
gson
=
Injection
.
provideGson
();
private
Handler
handler
=
new
Handler
();
private
SimpleDateFormat
payDateFormat
=
new
SimpleDateFormat
(
"HH:mm:ss.SSS"
,
Locale
.
getDefault
());
private
SimpleDateFormat
socketConnectedTimeDateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
,
Locale
.
getDefault
());
...
...
@@ -127,7 +129,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
msg
=
String
.
format
(
getString
(
R
.
string
.
connect_connecting
),
networkType
);
break
;
case
ConnectState
.
CONNECTED
:
msg
=
String
.
format
(
getString
(
R
.
string
.
connect_connected
),
networkType
);
msg
=
String
.
format
(
getString
(
R
.
string
.
connect_connected
),
event
.
getHost
(),
networkType
);
// socket链接成功后刷新wifi及eth的ip地址信息
refreshEthInfo
();
refreshWifiInfo
();
...
...
@@ -136,7 +138,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
msg
=
String
.
format
(
getString
(
R
.
string
.
connect_reconnecting
),
networkType
);
break
;
case
ConnectState
.
CHANGE_NETWORK
:
msg
=
String
.
format
(
getString
(
R
.
string
.
connect_change_network
),
networkType
);
msg
=
String
.
format
(
getString
(
R
.
string
.
connect_change_network
),
event
.
getHost
(),
networkType
);
break
;
default
:
msg
=
""
;
...
...
@@ -210,7 +212,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
}
if
(
debugVs
!=
null
)
return
;
String
msg
=
String
.
format
(
Locale
.
getDefault
(),
getString
(
R
.
string
.
qrcode_text
),
data
.
getPayCode
(
));
String
msg
=
String
.
format
(
Locale
.
getDefault
(),
getString
(
R
.
string
.
qrcode_text
),
gson
.
toJson
(
data
));
if
(
data
.
getTerminalType
()
!=
null
)
{
msg
+=
String
.
format
(
Locale
.
getDefault
(),
getString
(
R
.
string
.
terminal_type_text
),
data
.
getTerminalType
());
}
...
...
app/src/main/java/com/bgycc/smartcanteen/socket/SCWebSocketClient.java
View file @
a1da2f7d
...
...
@@ -49,6 +49,7 @@ public class SCWebSocketClient extends WebSocketClient {
private
Gson
gson
;
private
String
deviceSN
;
private
URI
host
;
private
ScheduledFuture
<?>
heartbeatFuture
;
private
ScheduledFuture
<?>
reconnectFuture
;
private
boolean
forceStop
=
false
;
...
...
@@ -85,6 +86,7 @@ public class SCWebSocketClient extends WebSocketClient {
private
SCWebSocketClient
(
URI
serverUri
,
String
deviceSN
,
Gson
gson
)
{
super
(
serverUri
);
this
.
host
=
serverUri
;
this
.
gson
=
gson
;
this
.
deviceSN
=
deviceSN
;
LogUtils
.
d
(
TAG
,
"WebSocket初始化, 服务器地址: "
+
serverUri
.
toString
()
+
", 设备SN号: "
+
deviceSN
);
...
...
@@ -136,7 +138,7 @@ public class SCWebSocketClient extends WebSocketClient {
@Override
public
void
onOpen
(
ServerHandshake
data
)
{
connectState
.
postValue
(
new
ConnectState
(
ConnectState
.
CONNECTED
));
connectState
.
postValue
(
new
ConnectState
(
ConnectState
.
CONNECTED
,
host
.
toString
()
));
LogUtils
.
d
(
TAG
,
"已链接服务器, \n"
+
"http状态: "
+
data
.
getHttpStatus
()
+
"\n"
+
"http状态消息:"
+
data
.
getHttpStatusMessage
());
...
...
@@ -219,7 +221,7 @@ public class SCWebSocketClient extends WebSocketClient {
}
lastSwitchTime
=
currentTime
;
connectState
.
postValue
(
new
ConnectState
(
ConnectState
.
CHANGE_NETWORK
));
connectState
.
postValue
(
new
ConnectState
(
ConnectState
.
CHANGE_NETWORK
,
host
.
toString
()
));
NetworkUtils
.
switchNetwork
(
callback
);
}
...
...
@@ -242,7 +244,7 @@ public class SCWebSocketClient extends WebSocketClient {
private
Runnable
reconnectRunnable
=
()
->
{
LogUtils
.
d
(
TAG
,
"开始尝试重连"
);
connectState
.
postValue
(
new
ConnectState
(
ConnectState
.
RECONNECTING
));
connectState
.
postValue
(
new
ConnectState
(
ConnectState
.
RECONNECTING
,
host
.
toString
()
));
for
(
SCWebSocketListener
l
:
listener
)
{
l
.
onReconnect
();
}
...
...
app/src/main/java/com/bgycc/smartcanteen/state/ConnectState.java
View file @
a1da2f7d
...
...
@@ -18,11 +18,17 @@ public class ConnectState {
}
private
@CONNECT_STATE
int
state
;
private
String
host
;
public
ConnectState
(
@CONNECT_STATE
int
state
)
{
this
.
state
=
state
;
}
public
ConnectState
(
@CONNECT_STATE
int
state
,
String
host
)
{
this
.
state
=
state
;
this
.
host
=
host
;
}
public
int
getState
()
{
return
state
;
}
...
...
@@ -31,23 +37,33 @@ public class ConnectState {
this
.
state
=
state
;
}
public
String
getHost
()
{
return
host
;
}
public
void
setHost
(
String
host
)
{
this
.
host
=
host
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
return
false
;
ConnectState
that
=
(
ConnectState
)
o
;
return
state
==
that
.
state
;
return
state
==
that
.
state
&&
Objects
.
equals
(
host
,
that
.
host
);
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
state
);
return
Objects
.
hash
(
state
,
host
);
}
@Override
public
String
toString
()
{
return
"ConnectState{"
+
"state="
+
state
+
", host='"
+
host
+
'\''
+
'}'
;
}
}
app/src/main/res/values/strings.xml
View file @
a1da2f7d
...
...
@@ -24,7 +24,7 @@
<string
name=
"connect_offline"
>
%s 未连接
</string>
<string
name=
"connect_connecting"
>
%s 正在连接…
</string>
<string
name=
"connect_connected"
>
Socket已连接
,网络类型: %s
</string>
<string
name=
"connect_reconnecting"
>
%s 正在重连…
</string>
<string
name=
"connect_connected"
>
服务器: %s
,网络类型: %s
</string>
<string
name=
"connect_reconnecting"
>
服务器: %s,正在重连… %s
</string>
<string
name=
"connect_change_network"
>
%s 正在切换…
</string>
</resources>
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