|
@@ -26,6 +26,7 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.example.informationkanban.application.MyApplication;
|
|
|
import com.example.informationkanban.common.Constant;
|
|
|
import com.example.informationkanban.common.MessageEvent;
|
|
|
+import com.example.informationkanban.dialog.UrlConfigDialogHelper;
|
|
|
import com.example.informationkanban.tcp.TcpClient;
|
|
|
import com.example.informationkanban.tcp.dto.TcpModel;
|
|
|
import com.example.informationkanban.tcp.enums.TcpAction;
|
|
@@ -46,6 +47,7 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
private int hours = 8;
|
|
|
private int freeTimes = 0;
|
|
|
+ private long clickTime = 0;
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
@@ -62,22 +64,30 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
setContentView(R.layout.activity_main);
|
|
|
init();
|
|
|
+
|
|
|
//MAC = GetInformationUtils.getMacAddress(this);
|
|
|
- MAC = GetInformationUtils.getSerialNo(getApplicationContext());
|
|
|
+ /*MAC = GetInformationUtils.getSerialNo(getApplicationContext());
|
|
|
Log.e(TAG, "MAC地址 " + MAC);
|
|
|
if (!TextUtils.isEmpty(MAC)) {
|
|
|
accessTheWebpage();
|
|
|
} else {
|
|
|
Toast.makeText(this, R.string.tips_device_info_error, Toast.LENGTH_LONG).show();
|
|
|
}
|
|
|
- timeMonitor();
|
|
|
+ timeMonitor();*/
|
|
|
|
|
|
if (!EventBus.getDefault().isRegistered(this)) {
|
|
|
EventBus.getDefault().register(this);
|
|
|
}
|
|
|
|
|
|
+ if (TextUtils.isEmpty(NetFunctionConfig.getCBDUrl())) {
|
|
|
+ //url为空则需要手动配置
|
|
|
+ UrlConfigDialogHelper.showDialog(MainActivity.this);
|
|
|
+ } else {
|
|
|
+ accessTheWebpage();
|
|
|
+ }
|
|
|
+
|
|
|
//连接tcp服务
|
|
|
- startTcp();
|
|
|
+ //startTcp();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -119,7 +129,7 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
private void init() {
|
|
|
//获得控件
|
|
|
- webView = (WebView) findViewById(R.id.wv_webview);
|
|
|
+ webView = findViewById(R.id.wv_webview);
|
|
|
}
|
|
|
|
|
|
private void accessTheWebpage() {
|
|
@@ -127,19 +137,23 @@ public class MainActivity extends AppCompatActivity {
|
|
|
WebSettings settings = webView.getSettings();
|
|
|
settings.setJavaScriptCanOpenWindowsAutomatically(true);//设置js可以直接打开窗口,如window.open(),默认为false
|
|
|
settings.setJavaScriptEnabled(true);//是否允许执行js,默认为false。设置true时,会提醒可能造成XSS漏洞
|
|
|
- settings.setSupportZoom(false);//是否可以缩放,默认true
|
|
|
+ settings.setSupportZoom(true);//是否可以缩放,默认true
|
|
|
settings.setBuiltInZoomControls(false);//是否显示缩放按钮,默认false
|
|
|
- settings.setUseWideViewPort(false);//设置此属性,可任意比例缩放。大视图模式
|
|
|
+ settings.setUseWideViewPort(true);//设置此属性,可任意比例缩放。大视图模式
|
|
|
settings.setLoadWithOverviewMode(true);//和setUseWideViewPort(true)一起解决网页自适应问题
|
|
|
settings.setAppCacheEnabled(false);//是否使用缓存
|
|
|
settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
|
|
|
settings.setDomStorageEnabled(true);//DOM Storage
|
|
|
+ settings.setMediaPlaybackRequiresUserGesture(false);
|
|
|
|
|
|
//访问网页
|
|
|
- String myUrl = "http://" + NetFunctionConfig.getServerIp() + ":" + NetFunctionConfig.getServerPort() + "/index?mac=" + MAC;
|
|
|
+ /*String myUrl = "http://" + NetFunctionConfig.getServerIp() + ":" + NetFunctionConfig.getServerPort() + "/index?mac=" + MAC;
|
|
|
if (NetFunctionConfig.getMode() == 2) {
|
|
|
myUrl = "http://t.wdklchina.com/?partId=" + NetFunctionConfig.getPartId();
|
|
|
- }
|
|
|
+ }*/
|
|
|
+
|
|
|
+ //String myUrl = "192.168.1.196:8080";
|
|
|
+ String myUrl = NetFunctionConfig.getCBDUrl();
|
|
|
|
|
|
Toast.makeText(MainActivity.this, "fetch: " + myUrl, Toast.LENGTH_LONG).show();
|
|
|
|
|
@@ -196,8 +210,12 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
@Override
|
|
|
public void onBackPressed() {
|
|
|
- Log.e(TAG, "not support go back");
|
|
|
- //禁用返回
|
|
|
+ if (System.currentTimeMillis() - clickTime > 2000) {
|
|
|
+ Toast.makeText(MainActivity.this, "再按一次退出", Toast.LENGTH_SHORT).show();
|
|
|
+ } else {
|
|
|
+ super.onBackPressed();
|
|
|
+ }
|
|
|
+ clickTime = System.currentTimeMillis();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -270,8 +288,8 @@ public class MainActivity extends AppCompatActivity {
|
|
|
@Override
|
|
|
protected void onDestroy() {
|
|
|
if (webView != null) {
|
|
|
- webView.loadDataWithBaseURL(null, "", "text/html", "utf-8", null);
|
|
|
- webView.clearHistory();
|
|
|
+ //webView.loadDataWithBaseURL(null, "", "text/html", "utf-8", null);
|
|
|
+ //webView.clearHistory();
|
|
|
|
|
|
((ViewGroup) webView.getParent()).removeView(webView);
|
|
|
webView.destroy();
|
|
@@ -301,7 +319,7 @@ public class MainActivity extends AppCompatActivity {
|
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
public void onMoonEvent(MessageEvent messageEvent) {
|
|
|
if (messageEvent.getType() == Constant.EVENT_TCP_MSG) {
|
|
|
- TcpModel tcpModel = (TcpModel) messageEvent.getMessage();
|
|
|
+ /*TcpModel tcpModel = (TcpModel) messageEvent.getMessage();
|
|
|
if (tcpModel.getAction() == TcpAction.TimeAction.SYNC) {
|
|
|
//时间同步
|
|
|
long time = 0L;
|
|
@@ -323,7 +341,7 @@ public class MainActivity extends AppCompatActivity {
|
|
|
AppUtil.setSysTime(timeStr, timeZone);
|
|
|
Log.d("setTime", "set sys time2: " + timeStr + ", " + timeZone);
|
|
|
}
|
|
|
- }
|
|
|
+ }*/
|
|
|
}
|
|
|
}
|
|
|
|