|
@@ -2,13 +2,8 @@ package com.example.informationkanban;
|
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
|
|
-import android.content.BroadcastReceiver;
|
|
|
-import android.content.Context;
|
|
|
-import android.content.Intent;
|
|
|
-import android.content.IntentFilter;
|
|
|
import android.os.Bundle;
|
|
|
import android.text.TextUtils;
|
|
|
-import android.text.format.Time;
|
|
|
import android.util.Log;
|
|
|
import android.view.KeyEvent;
|
|
|
import android.view.View;
|
|
@@ -21,27 +16,16 @@ import android.webkit.WebView;
|
|
|
import android.webkit.WebViewClient;
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-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.utils.GetInformationUtils;
|
|
|
import com.example.informationkanban.utils.LocaleMangerUtils;
|
|
|
import com.example.informationkanban.utils.NetFunctionConfig;
|
|
|
|
|
|
-import org.greenrobot.eventbus.EventBus;
|
|
|
-import org.greenrobot.eventbus.Subscribe;
|
|
|
-import org.greenrobot.eventbus.ThreadMode;
|
|
|
-
|
|
|
public class MainActivity extends AppCompatActivity {
|
|
|
private String TAG = MainActivity.class.getSimpleName();
|
|
|
private WebView webView;
|
|
|
private String MAC = "";
|
|
|
- private static String[] weeks = new String[]{"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
|
|
|
|
|
|
- private int hours = 8;
|
|
|
- private int freeTimes = 0;
|
|
|
private long backClickTime = 0;
|
|
|
|
|
|
@Override
|
|
@@ -60,20 +44,6 @@ public class MainActivity extends AppCompatActivity {
|
|
|
setContentView(R.layout.activity_main);
|
|
|
init();
|
|
|
|
|
|
- //MAC = GetInformationUtils.getMacAddress(this);
|
|
|
- /*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();*/
|
|
|
-
|
|
|
- if (!EventBus.getDefault().isRegistered(this)) {
|
|
|
- EventBus.getDefault().register(this);
|
|
|
- }
|
|
|
-
|
|
|
MAC = GetInformationUtils.getIMEI(this);
|
|
|
|
|
|
String url = NetFunctionConfig.getCBDUrl();
|
|
@@ -87,34 +57,6 @@ public class MainActivity extends AppCompatActivity {
|
|
|
} else {
|
|
|
accessTheWebpage();
|
|
|
}
|
|
|
-
|
|
|
- //连接tcp服务
|
|
|
- //startTcp();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 注册时间变化广播
|
|
|
- */
|
|
|
- private void timeMonitor() {
|
|
|
- IntentFilter filter = new IntentFilter();
|
|
|
- filter.addAction(Intent.ACTION_TIME_TICK);
|
|
|
- filter.addAction(Intent.ACTION_TIME_CHANGED);
|
|
|
- filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
|
|
|
- registerReceiver(broadcastReceiver, filter);
|
|
|
-
|
|
|
- //updataTime();
|
|
|
- }
|
|
|
-
|
|
|
- private void startTcp() {
|
|
|
- Constant.TCP_SERVER_URL = NetFunctionConfig.getServerIp();
|
|
|
- if (Constant.TCP_SERVER_URL != null) {
|
|
|
- new Thread(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- TcpClient.getInstance().init(NetFunctionConfig.getServerIp(), Constant.TCP_PORT, Constant.TCP_HEART_BEAT);
|
|
|
- }
|
|
|
- }).start();
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -148,12 +90,6 @@ public class MainActivity extends AppCompatActivity {
|
|
|
settings.setDomStorageEnabled(true);//DOM Storage
|
|
|
settings.setMediaPlaybackRequiresUserGesture(false);
|
|
|
|
|
|
- //访问网页
|
|
|
- /*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();
|
|
|
|
|
@@ -188,32 +124,8 @@ public class MainActivity extends AppCompatActivity {
|
|
|
public void onProgressChanged(WebView view, int newProgress) { //显示加载进度
|
|
|
|
|
|
Log.d(TAG, "load webview..." + newProgress + "%");
|
|
|
- //loadview.setText(getString(R.string.loading_percent, newProgress));
|
|
|
- //loadview.setVisibility((newProgress > 0 && newProgress < 100) ? View.VISIBLE : View.GONE);
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
- /*webView.setOnKeyListener(new View.OnKeyListener() {
|
|
|
- @Override
|
|
|
- public boolean onKey(View v, int keyCode, KeyEvent event) {
|
|
|
- Log.e(TAG, "webview onkey: " + event.getKeyCode() + ", " + event.getAction() + ", can back: " + webView.canGoBack() + ", can forward: " + webView.canGoForward());
|
|
|
- if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
|
|
- if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT && webView.canGoBack()) {
|
|
|
- //遥控器左键
|
|
|
- webView.goBack();
|
|
|
-
|
|
|
- return true;
|
|
|
- } else if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT && webView.canGoForward()) {
|
|
|
- //遥控器右键
|
|
|
- webView.goForward();
|
|
|
-
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return false;
|
|
|
- }
|
|
|
- });*/
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -239,72 +151,6 @@ public class MainActivity extends AppCompatActivity {
|
|
|
return super.onKeyDown(keyCode, event);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 时间发生改变调用
|
|
|
- */
|
|
|
- private void updateTime() {
|
|
|
- Time time = new Time();
|
|
|
- time.setToNow();
|
|
|
- int year = time.year;
|
|
|
- int month = time.month + 1;
|
|
|
- int date = time.monthDay;
|
|
|
- int hour = time.hour;
|
|
|
- int minute = time.minute;
|
|
|
- int week = time.weekDay;
|
|
|
-
|
|
|
- String monthStr = GetInformationUtils.addZero(month, 2);
|
|
|
- String dateStr = GetInformationUtils.addZero(date, 2);
|
|
|
-
|
|
|
- String hourStr = GetInformationUtils.addZero(hour, 2);
|
|
|
- String minuteStr = GetInformationUtils.addZero(minute, 2);
|
|
|
-
|
|
|
- String weekStr = weeks[week];
|
|
|
-
|
|
|
-// date_tv.setText(monthStr + "月" + dateStr + "日");
|
|
|
-// time_tv.setText(hourStr + ":" + minuteStr);
|
|
|
-// week_tv.setText(weekStr);
|
|
|
-
|
|
|
- //当前时间
|
|
|
- String nowTime = year + "-" + monthStr + "-" + dateStr + " " +
|
|
|
- hourStr + ":" + minuteStr + ":" + "00";
|
|
|
- //保存的时间
|
|
|
- String saveTime = NetFunctionConfig.getTime();
|
|
|
- if (TextUtils.isEmpty(saveTime)) {
|
|
|
- NetFunctionConfig.setTime(nowTime);
|
|
|
- saveTime = NetFunctionConfig.getTime();
|
|
|
- }
|
|
|
-
|
|
|
- Log.e("当前时间",nowTime+"");
|
|
|
- Log.e("保存的时间",saveTime+"");
|
|
|
-
|
|
|
- long nowTimes = Long.parseLong(GetInformationUtils.getTime(nowTime));
|
|
|
- long saveTimes = Long.parseLong(GetInformationUtils.getTime(saveTime));
|
|
|
-
|
|
|
- Log.e("间隔的秒数",(nowTimes / 1000) - (saveTimes / 1000)+"");
|
|
|
-
|
|
|
- if (nowTimes - saveTimes >= 600000 /*(nowTimes / 1000 / 60 / 60) - (saveTimes / 1000 / 60 / 60) >= hours*/) {
|
|
|
- Log.e("updateTime", "free webview..." + freeTimes);
|
|
|
- NetFunctionConfig.setTime(nowTime);
|
|
|
- freeTimes++;
|
|
|
-
|
|
|
- if (webView != null) {
|
|
|
- webView.clearHistory();
|
|
|
- webView.clearFormData();
|
|
|
- webView.clearCache(false);
|
|
|
- webView.freeMemory();
|
|
|
- //webView.loadUrl("http://192.168.101.1:8100/index?mac=" + MAC);
|
|
|
-
|
|
|
- if (freeTimes >= 10) {
|
|
|
- freeTimes = 0;
|
|
|
- webView.reload();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //finish();
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
//销毁Webview
|
|
|
@Override
|
|
|
protected void onDestroy() {
|
|
@@ -316,64 +162,8 @@ public class MainActivity extends AppCompatActivity {
|
|
|
webView.destroy();
|
|
|
webView = null;
|
|
|
}
|
|
|
- if(broadcastReceiver != null){
|
|
|
- unregisterReceiver(broadcastReceiver);
|
|
|
- }
|
|
|
- if (EventBus.getDefault().isRegistered(this)) {
|
|
|
- EventBus.getDefault().unregister(this);
|
|
|
- }
|
|
|
- super.onDestroy();
|
|
|
- }
|
|
|
-
|
|
|
- private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
|
|
|
- @Override
|
|
|
- public void onReceive(Context context, Intent intent) {
|
|
|
- String action = intent.getAction();
|
|
|
- //时间发生改变
|
|
|
- if (Intent.ACTION_TIME_TICK.equals(action)) {
|
|
|
- updateTime();
|
|
|
- }
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
|
|
|
- @Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
- public void onMoonEvent(MessageEvent messageEvent) {
|
|
|
- if (messageEvent.getType() == Constant.EVENT_TCP_MSG) {
|
|
|
- /*TcpModel tcpModel = (TcpModel) messageEvent.getMessage();
|
|
|
- if (tcpModel.getAction() == TcpAction.TimeAction.SYNC) {
|
|
|
- //时间同步
|
|
|
- long time = 0L;
|
|
|
- String timeZone="Asia/Shanghai";
|
|
|
- if(canParseJson(tcpModel.getData().toString())){
|
|
|
- JSONObject json = JSON.parseObject(tcpModel.getData().toString());
|
|
|
- time =json.getLong("time")*1000;
|
|
|
- timeZone=json.getString("time_zone");
|
|
|
- }else{
|
|
|
- time = Long.parseLong(tcpModel.getData().toString()) * 1000;
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- AppUtil.setSystemTime(MyApplication.getInstance(), time, timeZone);
|
|
|
- Log.d("setTime", "set sys time1: " + time + ", " + timeZone);
|
|
|
- } catch (Exception e) {
|
|
|
- //"20211213:092314"
|
|
|
- String timeStr = AppUtil.getDateTime(time, "yyyyMMdd.HHmmss", timeZone);
|
|
|
- AppUtil.setSysTime(timeStr, timeZone);
|
|
|
- Log.d("setTime", "set sys time2: " + timeStr + ", " + timeZone);
|
|
|
- }
|
|
|
- }*/
|
|
|
- }
|
|
|
+ super.onDestroy();
|
|
|
}
|
|
|
|
|
|
- private boolean canParseJson(String str){
|
|
|
- boolean result = false;
|
|
|
- try {
|
|
|
- JSON.parseObject(str);
|
|
|
- result = true;
|
|
|
- }catch (Exception e){
|
|
|
- result = false;
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
}
|