|
@@ -1,10 +1,17 @@
|
|
|
package com.example.informationkanban;
|
|
|
|
|
|
+import android.app.AlertDialog;
|
|
|
+import android.content.DialogInterface;
|
|
|
import android.content.Intent;
|
|
|
+import android.graphics.Color;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.CountDownTimer;
|
|
|
import android.text.TextUtils;
|
|
|
import android.util.Log;
|
|
|
+import android.view.LayoutInflater;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.Button;
|
|
|
+import android.widget.EditText;
|
|
|
import android.widget.RadioButton;
|
|
|
import android.widget.RadioGroup;
|
|
|
import android.widget.TextView;
|
|
@@ -20,12 +27,18 @@ public class InitActivity extends AppCompatActivity {
|
|
|
|
|
|
private TextView tvMac;
|
|
|
private TextView tvIP;
|
|
|
+ private TextView tvServer;
|
|
|
+ private TextView tvServerStatus;
|
|
|
private TextView tvVersion;
|
|
|
private TextView tvTime;
|
|
|
private RadioGroup group;
|
|
|
private RadioButton btnWebview;
|
|
|
private RadioButton btnXwalk;
|
|
|
+ private Button btnChangeIp;
|
|
|
+ private Button btnEnterMain;
|
|
|
+
|
|
|
private boolean loop = true;
|
|
|
+ private boolean connected = false;
|
|
|
|
|
|
private CountDownTimer countDownTimer;
|
|
|
|
|
@@ -36,12 +49,16 @@ public class InitActivity extends AppCompatActivity {
|
|
|
|
|
|
tvMac = findViewById(R.id.textView_mac);
|
|
|
tvIP = findViewById(R.id.textView_ip);
|
|
|
+ tvServer = findViewById(R.id.textView_server_ip);
|
|
|
+ tvServerStatus = findViewById(R.id.textView_server_status);
|
|
|
tvVersion = findViewById(R.id.textView_version);
|
|
|
tvVersion.setText("版本: V" + BuildConfig.VERSION_NAME);
|
|
|
tvTime = findViewById(R.id.textView_countdown);
|
|
|
group = findViewById(R.id.group_webview_type);
|
|
|
btnWebview = findViewById(R.id.radio_webview);
|
|
|
btnXwalk = findViewById(R.id.radio_xwalk);
|
|
|
+ btnChangeIp = findViewById(R.id.btn_change_ip);
|
|
|
+ btnEnterMain = findViewById(R.id.btn_enter_main);
|
|
|
|
|
|
//webview类型,默认为原生webview
|
|
|
if (NetFunctionConfig.getWebviewType() == 1) {
|
|
@@ -49,6 +66,9 @@ public class InitActivity extends AppCompatActivity {
|
|
|
} else {
|
|
|
btnXwalk.setChecked(true);
|
|
|
}
|
|
|
+
|
|
|
+ tvServer.setText("服务器IP: " + NetFunctionConfig.getServerIp() + ":" + NetFunctionConfig.getServerPort());
|
|
|
+
|
|
|
group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
|
|
|
@Override
|
|
|
public void onCheckedChanged(RadioGroup group, int checkedId) {
|
|
@@ -64,6 +84,63 @@ public class InitActivity extends AppCompatActivity {
|
|
|
|
|
|
initCountDownTimer();
|
|
|
|
|
|
+ btnChangeIp.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ //取消倒计时
|
|
|
+ if (countDownTimer != null) {
|
|
|
+ countDownTimer.cancel();
|
|
|
+ }
|
|
|
+ btnEnterMain.setVisibility(View.VISIBLE);
|
|
|
+ tvTime.setVisibility(View.INVISIBLE);
|
|
|
+
|
|
|
+ loop = false;
|
|
|
+ //进入IP编辑界面
|
|
|
+ startChangeIp();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ btnEnterMain.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ loop = true;
|
|
|
+ checkNetwork();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //检查服务器连接情况
|
|
|
+ checkServer();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void startChangeIp() {
|
|
|
+ View contentView = LayoutInflater.from(InitActivity.this).inflate(R.layout.dialog_edit_ip, null);
|
|
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(InitActivity.this);
|
|
|
+ builder.setView(contentView);
|
|
|
+ final EditText editIp = contentView.findViewById(R.id.edit_server_ip);
|
|
|
+ editIp.setText(NetFunctionConfig.getServerIp());
|
|
|
+ final EditText editPort = contentView.findViewById(R.id.edit_server_port);
|
|
|
+ editPort.setText(NetFunctionConfig.getServerPort());
|
|
|
+ builder.setTitle("设置服务器IP和端口");
|
|
|
+ builder.setPositiveButton("保存", new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ String newIp = editIp.getText().toString();
|
|
|
+ String newPort = editPort.getText().toString();
|
|
|
+ NetFunctionConfig.setServerIp(newIp);
|
|
|
+ NetFunctionConfig.setServerPort(newPort);
|
|
|
+ tvServer.setText("服务器IP: " + newIp + ":" + newPort);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ //
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ AlertDialog dialog = builder.create();
|
|
|
+ dialog.show();
|
|
|
}
|
|
|
|
|
|
private void initCountDownTimer() {
|
|
@@ -77,6 +154,7 @@ public class InitActivity extends AppCompatActivity {
|
|
|
@Override
|
|
|
public void onFinish() {
|
|
|
checkNetwork();
|
|
|
+ tvTime.setVisibility(View.INVISIBLE);
|
|
|
}
|
|
|
};
|
|
|
countDownTimer.start();
|
|
@@ -88,12 +166,18 @@ public class InitActivity extends AppCompatActivity {
|
|
|
public void run() {
|
|
|
while (loop) {
|
|
|
updateView();
|
|
|
- if (NetworkUtils.isAvailableByPing("192.168.101.1")) {
|
|
|
+ if (NetworkUtils.isAvailableByPing(NetFunctionConfig.getServerIp())) {
|
|
|
loop = false;
|
|
|
- startMain();
|
|
|
+ showServerStatus(true);
|
|
|
+ if (!connected) {
|
|
|
+ connected = true;
|
|
|
+ startMain();
|
|
|
+ }
|
|
|
} else {
|
|
|
+ showServerStatus(false);
|
|
|
+ showMessage();
|
|
|
try {
|
|
|
- Thread.sleep(5000);
|
|
|
+ Thread.sleep(6000);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@@ -103,18 +187,57 @@ public class InitActivity extends AppCompatActivity {
|
|
|
}).start();
|
|
|
}
|
|
|
|
|
|
+ private void checkServer() {
|
|
|
+ new Thread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ if (NetworkUtils.isAvailableByPing(NetFunctionConfig.getServerIp())) {
|
|
|
+ showServerStatus(true);
|
|
|
+ } else {
|
|
|
+ showServerStatus(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }).start();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void showServerStatus(final boolean status) {
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ if (status) {
|
|
|
+ tvServerStatus.setTextColor(Color.GREEN);
|
|
|
+ tvServerStatus.setText("服务器连接成功");
|
|
|
+ } else {
|
|
|
+ tvServerStatus.setTextColor(Color.RED);
|
|
|
+ tvServerStatus.setText("服务器连接失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
private void updateView() {
|
|
|
runOnUiThread(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
if (tvMac != null && tvIP != null) {
|
|
|
tvMac.setText("MAC地址: " + GetInformationUtils.getMacAddress(InitActivity.this));
|
|
|
- tvIP.setText("IP地址: " + GetInformationUtils.getLocalIP());
|
|
|
+ tvIP.setText("本机IP地址: " + GetInformationUtils.getLocalIP());
|
|
|
+ tvServer.setText("服务器IP: " + NetFunctionConfig.getServerIp() + ":" + NetFunctionConfig.getServerPort());
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ private void showMessage() {
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ Toast.makeText(InitActivity.this, "连接服务器失败,请检查网络", Toast.LENGTH_SHORT).show();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
private void startMain() {
|
|
|
runOnUiThread(new Runnable() {
|
|
|
@Override
|