Browse Source

fix: ci

dejiAi
高志龙 8 months ago
parent
commit
56e1fb8799
  1. 78
      app/src/main/java/qianmu/container/activity/H5/WebViewActivity.java
  2. 1
      app/src/main/java/qianmu/container/data/PowerData.java

78
app/src/main/java/qianmu/container/activity/H5/WebViewActivity.java

@ -23,6 +23,8 @@ import android.view.animation.Animation;
import android.webkit.ConsoleMessage;
import android.webkit.JavascriptInterface;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
@ -486,12 +488,31 @@ public class WebViewActivity extends BaseActivity {
@Override
protected void setListener() {
binding.web.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
super.onReceivedHttpError(view, request, errorResponse);
int statusCode = errorResponse.getStatusCode();
if (statusCode != 200) {
Log.e("WebViewError", "错误: ");
handler.sendEmptyMessageDelayed(TYPE_REFURBISH_WEBVIEW,10000);
}
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
if (errorCode != 200) {
Log.e("WebViewError", "错误: ");
handler.sendEmptyMessageDelayed(TYPE_REFURBISH_WEBVIEW,10000);
}
}
});
binding.web.setOnLongClickListener((View v) -> {
@ -711,7 +732,6 @@ public class WebViewActivity extends BaseActivity {
LoggerUtil.e(TAG,"JS调用了Android的方法:startTTS()");
try{
if("sbc".equals(Constant.TTSFac)) {
if (localSocketClient == null) connectLocalSocket(); //-------------------------------
localSocketClient.send(StringUtil.strSplice("{\"method\": \"/tts/start\",\"params\": {\"text\":\"", txt, "\", \"mode\":\"autoPlay\"}}"));
}else{
ttsUtil.startTTs(txt);
@ -726,7 +746,6 @@ public class WebViewActivity extends BaseActivity {
LoggerUtil.e(TAG,"JS调用了Android的方法:stopTTS()");
try{
if("sbc".equals(Constant.TTSFac)){
if (localSocketClient == null) connectLocalSocket(); //-------------------------------
localSocketClient.send(StringUtil.strSplice("{\"method\":\"/tts/stop\"}"));
}else{
ttsUtil.stopTTs();
@ -900,15 +919,16 @@ public class WebViewActivity extends BaseActivity {
if (localSocketClient == null) initLocalSocketClient();
//获取客户端当前的连接状态
ReadyState state = localSocketClient.getReadyState();
LoggerUtil.e("connectLocalSocket", "TTS客户端连接状态:"+ GsonUtil.getGson().toJson(state));
LoggerUtil.e("connectLocalSocket", "socket客户端连接状态:"+ GsonUtil.getGson().toJson(state));
boolean open = localSocketClient.isOpen();
LoggerUtil.e("connectLocalSocket", "TTS客户端连接状态:open="+open);
LoggerUtil.e("connectLocalSocket", "socket客户端连接状态:open="+open);
if (open) return;
//获取客户端当前的连接状态
if (localSocketClient.isOpen()) return;
//未连接状态时 连接服务器
if (state.equals(ReadyState.NOT_YET_CONNECTED)) localSocketClient.connect();
else if (state.equals(ReadyState.CLOSING) || state.equals(ReadyState.CLOSED)) {
if (state.equals(ReadyState.NOT_YET_CONNECTED)) {
LoggerUtil.e("connectLocalSocket", "socket客户端重新链接connect");
localSocketClient.connect();
} else if (state.equals(ReadyState.CLOSING) || state.equals(ReadyState.CLOSED)) {
LoggerUtil.e("connectLocalSocket", "socket客户端重新链接reconnect");
//正在关闭或者关闭状态时 重新连接服务器
localSocketClient.reconnect();
}
@ -960,24 +980,21 @@ public class WebViewActivity extends BaseActivity {
}
}else if("hardware.status".equals(method)){ // 网络变化
LoggerUtil.e("ttsSocket: hardware.status", content.getNetwork().trim());
if("lan".equals(content.getNetwork().trim())) { // 网络断开
destroyLocalSocketClient();
runOnUiThread(new Runnable() {
@Override
public void run() {
binding.web.loadUrl(StringUtil.strSplice("javascript:window.netWorkNot('0');"));
}
});
}else{
destroyLocalSocketClient();
connectLocalSocket();
runOnUiThread(new Runnable() {
@Override
public void run() {
binding.web.loadUrl(StringUtil.strSplice("javascript:window.netWorkNot('1');"));
}
});
}
// if("lan".equals(content.getNetwork().trim())) { // 网络断开
// runOnUiThread(new Runnable() {
// @Override
// public void run() {
// binding.web.loadUrl(StringUtil.strSplice("javascript:window.netWorkNot('0');"));
// }
// });
// }else{
// runOnUiThread(new Runnable() {
// @Override
// public void run() {
// binding.web.loadUrl(StringUtil.strSplice("javascript:window.netWorkNot('1');"));
// }
// });
// }
}
} catch (Throwable t) {
LoggerUtil.e("setOnMessageListener", StringUtil.getThrowableStr(t));
@ -986,13 +1003,12 @@ public class WebViewActivity extends BaseActivity {
localSocketClient.setOnCloseListener((code, reason, remote) -> {
LoggerUtil.e("LocSocCliManager", "onClose:code="+code);
destroyLocalSocketClient();
connectLocalSocket();
});
localSocketClient.setOnErrorListener((ex) -> {
LoggerUtil.e("LocSocCliManager", "onError");
SignWayUtil.reboot();
});
// localSocketClient.setOnErrorListener((ex) -> {
// LoggerUtil.e("LocSocCliManager", ex.getMessage());
// //connectLocalSocket();
// });
}
//销毁当前的客户端
public void destroyLocalSocketClient() {

1
app/src/main/java/qianmu/container/data/PowerData.java

@ -161,7 +161,6 @@ public class PowerData extends BaseData {
LoggerUtil.e("pingNet()", "开机检测网络异常,重启设备");
DeviceData.saveDeviceInfo((DeviceData.DEVICE_RESTART_TIME),format);
SignWayUtil.reboot();
}
} );
}

Loading…
Cancel
Save