Commit a1da2f7d by pye52

优化debug模式的日志输出

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