Commit 774c5e33 by patpat

优化wifi信息显示

parent ca258f22
...@@ -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) {
......
...@@ -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();
......
...@@ -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" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment