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
774c5e33
authored
Aug 13, 2019
by
patpat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化wifi信息显示
parent
ca258f22
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
20 deletions
+32
-20
app/src/main/java/com/bgycc/smartcanteen/activity/MainActivity.kt
+8
-18
app/src/main/java/com/bgycc/smartcanteen/helper/WifiHelpler.java
+23
-1
app/src/main/res/layout/activity_main.xml
+1
-1
No files found.
app/src/main/java/com/bgycc/smartcanteen/activity/MainActivity.kt
View file @
774c5e33
...
@@ -15,6 +15,7 @@ import com.bgycc.smartcanteen.R
...
@@ -15,6 +15,7 @@ import com.bgycc.smartcanteen.R
import
com.bgycc.smartcanteen.event.LogEvent
import
com.bgycc.smartcanteen.event.LogEvent
import
com.bgycc.smartcanteen.event.PayStateEvent
import
com.bgycc.smartcanteen.event.PayStateEvent
import
com.bgycc.smartcanteen.event.WifiStateEvent
import
com.bgycc.smartcanteen.event.WifiStateEvent
import
com.bgycc.smartcanteen.helper.TimerHelper
import
com.bgycc.smartcanteen.helper.WifiHelpler
import
com.bgycc.smartcanteen.helper.WifiHelpler
import
com.bgycc.smartcanteen.server.websocket.event.ConnectStateEvent
import
com.bgycc.smartcanteen.server.websocket.event.ConnectStateEvent
import
com.bgycc.smartcanteen.server.websocket.MainWebSocket
import
com.bgycc.smartcanteen.server.websocket.MainWebSocket
...
@@ -44,7 +45,6 @@ class MainActivity : BaseActivity() {
...
@@ -44,7 +45,6 @@ class MainActivity : BaseActivity() {
private
var
mBeepSoundId
=
0
private
var
mBeepSoundId
=
0
private
var
mPaySuccessSoundId
=
0
private
var
mPaySuccessSoundId
=
0
private
var
mPayFailSoundId
=
0
private
var
mPayFailSoundId
=
0
private
var
mTimerExec
:
ScheduledExecutorService
?
=
null
private
val
mHandler
=
Handler
()
private
val
mHandler
=
Handler
()
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
...
@@ -69,7 +69,6 @@ class MainActivity : BaseActivity() {
...
@@ -69,7 +69,6 @@ class MainActivity : BaseActivity() {
mBeepSoundId
=
mSoundPool
.
load
(
assets
.
openFd
(
"beep.mp3"
),
1
)
mBeepSoundId
=
mSoundPool
.
load
(
assets
.
openFd
(
"beep.mp3"
),
1
)
mPaySuccessSoundId
=
mSoundPool
.
load
(
assets
.
openFd
(
"pay-success.mp3"
),
1
)
mPaySuccessSoundId
=
mSoundPool
.
load
(
assets
.
openFd
(
"pay-success.mp3"
),
1
)
mPayFailSoundId
=
mSoundPool
.
load
(
assets
.
openFd
(
"pay-fail.mp3"
),
1
)
mPayFailSoundId
=
mSoundPool
.
load
(
assets
.
openFd
(
"pay-fail.mp3"
),
1
)
WifiHelpler
.
connect
(
"BGY-802.1X"
,
"dengquanye"
,
"pat2019@@"
,
"wpa_eap"
)
MainWebSocket
.
initialize
()
MainWebSocket
.
initialize
()
QRCodeTask
.
getInstance
().
start
()
QRCodeTask
.
getInstance
().
start
()
ButtonTask
.
start
()
ButtonTask
.
start
()
...
@@ -88,28 +87,19 @@ class MainActivity : BaseActivity() {
...
@@ -88,28 +87,19 @@ class MainActivity : BaseActivity() {
_setting_img
.
startAnimation
(
anim
)
_setting_img
.
startAnimation
(
anim
)
}
}
_version
.
text
=
"Version: v${App.getVersionName()}(${App.getVersionCode()})"
_version
.
text
=
"Version: v${App.getVersionName()}(${App.getVersionCode()})"
_mac
.
text
=
"Wifi Mac: ${WifiHelpler.getMacAddress()}"
}
}
private
fun
initTimer
()
{
private
fun
initTimer
()
{
if
(
mTimerExec
==
null
)
{
TimerHelper
.
loop
(
Runnable
{
mTimerExec
=
Executors
.
newSingleThreadScheduledExecutor
()
mHandler
.
post
{
mTimerExec
!!
.
scheduleAtFixedRate
({
_wifi
.
text
=
"Wifi Mac: ${WifiHelpler.getMacAddress()} SSID: ${WifiHelpler.getSSID()} IP: ${WifiHelpler.getIpString()}"
try
{
_time
.
text
=
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
,
Locale
.
getDefault
()).
format
(
Date
())
mHandler
.
post
{
}
_time
.
text
=
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
,
Locale
.
getDefault
()).
format
(
Date
())
},
1000
)
}
}
catch
(
e
:
Exception
)
{
Log
.
e
(
TAG
,
"TimerExec error"
)
e
.
printStackTrace
()
}
},
0
,
1000
,
TimeUnit
.
MILLISECONDS
)
}
}
}
private
fun
uninitTimer
()
{
private
fun
uninitTimer
()
{
mTimerExec
?.
shutdown
()
TimerHelper
.
shutdown
()
mTimerExec
=
null
}
}
fun
printQRCode
(
event
:
QRCodeEvent
)
{
fun
printQRCode
(
event
:
QRCodeEvent
)
{
...
...
app/src/main/java/com/bgycc/smartcanteen/helper/WifiHelpler.java
View file @
774c5e33
...
@@ -47,7 +47,7 @@ public class WifiHelpler {
...
@@ -47,7 +47,7 @@ public class WifiHelpler {
try
{
try
{
NetworkInterface
networkInterface
=
NetworkInterface
.
getByName
(
"wlan0"
);
NetworkInterface
networkInterface
=
NetworkInterface
.
getByName
(
"wlan0"
);
byte
[]
data
=
networkInterface
.
getHardwareAddress
();
byte
[]
data
=
networkInterface
.
getHardwareAddress
();
return
String
.
format
(
"%02x:%02x:%02x:%02x:%02x:%02x"
,
data
[
5
],
data
[
4
],
data
[
3
],
data
[
2
],
data
[
1
],
data
[
0
]);
return
String
.
format
(
"%02x:%02x:%02x:%02x:%02x:%02x"
,
data
[
0
],
data
[
1
],
data
[
2
],
data
[
3
],
data
[
4
],
data
[
5
]);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
}
}
...
@@ -81,6 +81,28 @@ public class WifiHelpler {
...
@@ -81,6 +81,28 @@ public class WifiHelpler {
return
false
;
return
false
;
}
}
public
static
String
getSSID
()
{
try
{
return
getWifiInfo
().
getSSID
();
}
catch
(
Exception
e
)
{
return
"02:00:00:00:00:00"
;
}
}
public
static
String
getIpString
()
{
try
{
int
ip
=
getWifiInfo
().
getIpAddress
();
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
ip
&
0xFF
).
append
(
"."
);
sb
.
append
((
ip
>>
8
)
&
0xFF
).
append
(
"."
);
sb
.
append
((
ip
>>
16
)
&
0xFF
).
append
(
"."
);
sb
.
append
((
ip
>>
24
)
&
0xFF
);
return
sb
.
toString
();
}
catch
(
Exception
e
)
{
return
"0.0.0.0"
;
}
}
public
static
WifiConfiguration
getWifiConfiguration
(
String
ssid
)
{
public
static
WifiConfiguration
getWifiConfiguration
(
String
ssid
)
{
try
{
try
{
List
<
WifiConfiguration
>
existingConfigs
=
sWifiManager
.
getConfiguredNetworks
();
List
<
WifiConfiguration
>
existingConfigs
=
sWifiManager
.
getConfiguredNetworks
();
...
...
app/src/main/res/layout/activity_main.xml
View file @
774c5e33
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
<LinearLayout
android:id=
"@+id/_debug"
android:orientation=
"vertical"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:padding=
"5dp"
>
<LinearLayout
android:id=
"@+id/_debug"
android:orientation=
"vertical"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:padding=
"5dp"
>
<TextView
android:id=
"@+id/_version"
android:text=
"Version: v0.0.0"
android:textSize=
"18sp"
android:textColor=
"#888"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
<TextView
android:id=
"@+id/_version"
android:text=
"Version: v0.0.0"
android:textSize=
"18sp"
android:textColor=
"#888"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
<TextView
android:id=
"@+id/_
mac"
android:text=
"Wifi Mac
: unknown"
android:textSize=
"18sp"
android:textColor=
"#888"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
<TextView
android:id=
"@+id/_
wifi"
android:text=
"Wifi SSID
: unknown"
android:textSize=
"18sp"
android:textColor=
"#888"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
<TextView
android:id=
"@+id/_qrcode"
android:text=
"QRCode: 扫描中..."
android:textSize=
"18sp"
android:textColor=
"#888"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
<TextView
android:id=
"@+id/_qrcode"
android:text=
"QRCode: 扫描中..."
android:textSize=
"18sp"
android:textColor=
"#888"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
<TextView
android:id=
"@+id/_server"
android:text=
"Server: 未连接"
android:textSize=
"18sp"
android:textColor=
"#888"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
<TextView
android:id=
"@+id/_server"
android:text=
"Server: 未连接"
android:textSize=
"18sp"
android:textColor=
"#888"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
<TextView
android:id=
"@+id/_send_msg"
android:text=
"Send: null"
android:textSize=
"18sp"
android:textColor=
"#488"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
<TextView
android:id=
"@+id/_send_msg"
android:text=
"Send: null"
android:textSize=
"18sp"
android:textColor=
"#488"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
/>
...
...
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