Browse Source

增加服务器地址修改功能。
1.默认服务器地址:192.168.101.1,端口:8100
2.点击“修改服务器地址”按钮,进入修改界面,可以修改服务器地址和端口,修改完成后点击保存,然后再点击下方的”进入信息看板“按钮,进入信息看板主界面。
3.同时支持webview版本切换
以上所有修改都将保存在本地,只需要修改一次即可,下次启动会使用上次的配置参数。

weizhengliang 3 năm trước cách đây
mục cha
commit
224f74f5bf

+ 6 - 1
app/build.gradle

@@ -8,7 +8,7 @@ android {
         minSdkVersion 15
         targetSdkVersion 30
         versionCode 1
-        versionName "1.54"
+        versionName "1.6"
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
     }
     buildTypes {
@@ -23,6 +23,11 @@ android {
             jniLibs.srcDirs = ['libs']
         }
     }
+
+    lintOptions {
+        checkReleaseBuilds false
+        abortOnError false
+    }
 }
 
 dependencies {

BIN
app/release/kanban_v1.6_20211108.apk


+ 127 - 4
app/src/main/java/com/example/informationkanban/InitActivity.java

@@ -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

+ 2 - 1
app/src/main/java/com/example/informationkanban/MainActivity.java

@@ -97,7 +97,8 @@ public class MainActivity extends AppCompatActivity {
         settings.setDomStorageEnabled(true);//DOM Storage
 
         //访问网页
-        webView.loadUrl("http://192.168.101.1:8100/index?mac=" + MAC);
+        String myUrl = "http://" + NetFunctionConfig.getServerIp() + ":" + NetFunctionConfig.getServerPort() + "/index?mac=" + MAC;
+        webView.loadUrl(myUrl);
         //系统默认会通过手机浏览器打开网页,为了能够直接通过WebView显示网页,则必须设置
         webView.setWebViewClient(new WebViewClient() {
             @Override

+ 2 - 1
app/src/main/java/com/example/informationkanban/XwalkMainActivity.java

@@ -150,7 +150,8 @@ public class XwalkMainActivity extends XWalkActivity {
 
         });
 
-        xwalkview.loadUrl("http://192.168.101.1:8100/index?mac=" + MAC);
+        String myUrl = "http://" + NetFunctionConfig.getServerIp() + ":" + NetFunctionConfig.getServerPort() + "/index?mac=" + MAC;
+        xwalkview.loadUrl(myUrl);
     }
 
     @Override

+ 20 - 0
app/src/main/java/com/example/informationkanban/utils/NetFunctionConfig.java

@@ -12,6 +12,10 @@ public class NetFunctionConfig {
 
     private static final String WEBVIEW_TYPE = "WEBVIEW_TYPE";
 
+    private static final String SERVER_IP = "SERVER_IP";
+
+    private static final String SERVER_PORT = "SERVER_PORT";
+
     public static void setWebviewType(int type) {
         getEditor().putInt(WEBVIEW_TYPE, type).apply();
     }
@@ -28,6 +32,22 @@ public class NetFunctionConfig {
         return getSP().getString(GIT_TIME, "");
     }
 
+    public static void setServerIp(String serverIp) {
+        getEditor().putString(SERVER_IP, serverIp).apply();
+    }
+
+    public static String getServerIp() {
+        return getSP().getString(SERVER_IP, "192.168.101.1");
+    }
+
+    public static void setServerPort(String serverPort) {
+        getEditor().putString(SERVER_PORT, serverPort).apply();
+    }
+
+    public static String getServerPort() {
+        return getSP().getString(SERVER_PORT, "8100");
+    }
+
     private static SharedPreferences getSP() {
         return MyApplication.getInstance().getSharedPreferences(INFORMATION_KAN_BAN_KEY, Context.MODE_PRIVATE);
     }

+ 38 - 0
app/src/main/res/layout/dialog_edit_ip.xml

@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:padding="20dp">
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content">
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="服务器IP: "/>
+        <EditText
+            android:id="@+id/edit_server_ip"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:inputType="number"
+            android:digits="0123456789."/>
+    </LinearLayout>
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content">
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:text="服务器端口: "/>
+        <EditText
+            android:id="@+id/edit_server_port"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:inputType="number"
+            android:digits="0123456789."/>
+    </LinearLayout>
+
+</LinearLayout>

+ 43 - 27
app/src/main/res/layout/init_layout.xml

@@ -1,6 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical"
@@ -12,35 +11,50 @@
         android:layout_height="wrap_content"
         android:layout_marginTop="40dp"
         android:text="mac地址"
-        android:textSize="28sp"
-        app:layout_constraintBottom_toTopOf="@+id/textView_ip"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toTopOf="parent" />
+        android:textSize="28sp" />
 
     <TextView
         android:id="@+id/textView_ip"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_marginTop="40dp"
-        android:text="IP地址"
-        android:textSize="28sp"
-        app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toTopOf="parent" />
+        android:layout_marginTop="20dp"
+        android:text="本机IP地址"
+        android:textSize="28sp" />
+
+    <TextView
+        android:id="@+id/textView_server_ip"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="20dp"
+        android:text="服务器IP"
+        android:textSize="28sp" />
+
+    <TextView
+        android:id="@+id/textView_server_status"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="10dp"
+        android:textSize="24sp" />
+
+    <Button
+        android:id="@+id/btn_change_ip"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="20dp"
+        android:text="修改服务器地址"
+        android:textSize="20sp"/>
 
     <RadioGroup
         android:id="@+id/group_webview_type"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_marginTop="40dp"
+        android:layout_marginTop="20dp"
         android:orientation="horizontal">
         <RadioButton
             android:id="@+id/radio_webview"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:text="使用原生Webview"
+            android:text="使用系统Webview"
             android:textSize="20sp"/>
         <RadioButton
             android:id="@+id/radio_xwalk"
@@ -48,31 +62,33 @@
             android:layout_height="wrap_content"
             android:layout_marginLeft="20dp"
             android:layout_marginStart="20dp"
-            android:text="使用内置Xwalk"
+            android:text="使用内置Webview"
             android:textSize="20sp"/>
     </RadioGroup>
 
+    <Button
+        android:id="@+id/btn_enter_main"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="10dp"
+        android:text="进入信息看板"
+        android:textSize="20sp"
+        android:visibility="invisible"/>
+
     <TextView
         android:id="@+id/textView_countdown"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginTop="40dp"
         android:text="倒计时"
-        android:textSize="28sp"
-        app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toTopOf="parent" />
+        android:textColor="#ff0000"
+        android:textSize="28sp" />
 
     <TextView
         android:id="@+id/textView_version"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_marginTop="80dp"
+        android:layout_marginTop="40dp"
         android:text="APP版本"
-        android:textSize="28sp"
-        app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toBottomOf="@+id/textView_ip" />
+        android:textSize="28sp" />
 </LinearLayout>

+ 1 - 1
build.gradle

@@ -7,7 +7,7 @@ buildscript {
         
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:3.4.0'
+        classpath 'com.android.tools.build:gradle:3.0.1'
         
         // NOTE: Do not place your application dependencies here; they belong
         // in the individual module build.gradle files

+ 1 - 1
gradle/wrapper/gradle-wrapper.properties

@@ -1,6 +1,6 @@
 #Tue Dec 22 18:05:20 CST 2020
 distributionBase=GRADLE_USER_HOME
 distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-bin.zip
 zipStoreBase=GRADLE_USER_HOME
 zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip