浏览代码

CBD项目大屏看板

wzl 11 月之前
父节点
当前提交
1a389777c2

+ 17 - 6
app/src/main/AndroidManifest.xml

@@ -27,25 +27,36 @@
         android:allowBackup="true"
         android:icon="@drawable/ic_app_launch"
         android:label="@string/app_name"
-        android:roundIcon="@mipmap/ic_launcher_round"
+        android:roundIcon="@drawable/ic_app_launch"
         android:supportsRtl="true"
+        android:hardwareAccelerated="true"
         android:networkSecurityConfig="@xml/network_security_config"
         android:theme="@style/AppTheme">
         <activity android:name=".InitActivity"
+            android:screenOrientation="nosensor"
             android:launchMode="singleTask">
-            <intent-filter android:priority="10">
+            <!--<intent-filter android:priority="10">
                 <action android:name="android.intent.action.MAIN" />
 
                 <category android:name="android.intent.category.LAUNCHER" />
-                <!-- 设置成主题界面 -->
+                &lt;!&ndash; 设置成主题界面 &ndash;&gt;
                 <category android:name="android.intent.category.HOME" />
                 <category android:name="android.intent.category.DEFAULT" />
-            </intent-filter>
+            </intent-filter>-->
         </activity>
+
         <activity android:name=".XwalkMainActivity"
-            android:launchMode="singleInstance"/>
+            android:screenOrientation="nosensor"
+            android:launchMode="singleTask"/>
+
         <activity android:name=".MainActivity"
-            android:launchMode="singleInstance"/>
+            android:screenOrientation="nosensor"
+            android:launchMode="singleTask">
+            <intent-filter android:priority="10">
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
     </application>
 
 </manifest>

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

@@ -85,12 +85,12 @@ public class InitActivity extends AppCompatActivity {
         String screenSize = "screen size: height=" + dm.heightPixels + ", width=" + dm.widthPixels + ", densityDpi=" + dm.densityDpi;
         Log.e("kanban", screenSize);
         Toast.makeText(this, screenSize, Toast.LENGTH_LONG).show();
-        if (dm.heightPixels != 1080 && dm.widthPixels != 1920) {
+        /*if (dm.heightPixels != 1080 && dm.widthPixels != 1920) {
             //设置分辨率为
             Log.e("kanban", "set screen size: 1920x1080");
             AppUtil.setScreenSize(1920, 1080);
             //AppUtil.resetScreenSize();
-        }
+        }*/
 
         tvMac = findViewById(R.id.textView_mac);
         tvIP = findViewById(R.id.textView_ip);

+ 32 - 14
app/src/main/java/com/example/informationkanban/MainActivity.java

@@ -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);
                 }
-            }
+            }*/
         }
     }
 

+ 50 - 0
app/src/main/java/com/example/informationkanban/dialog/UrlConfigDialogHelper.java

@@ -0,0 +1,50 @@
+package com.example.informationkanban.dialog;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.Button;
+import android.widget.EditText;
+
+import com.example.informationkanban.R;
+import com.example.informationkanban.utils.NetFunctionConfig;
+
+public class UrlConfigDialogHelper {
+
+    private static AlertDialog alertDialog;
+
+    public static void showDialog(Activity activity) {
+        if (alertDialog != null) {
+            alertDialog.dismiss();
+        }
+
+        View contentView = LayoutInflater.from(activity).inflate(R.layout.url_config_dialog, null);
+        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
+        builder.setView(contentView);
+
+        EditText url_text = contentView.findViewById(R.id.edit_url);
+        Button cancel = contentView.findViewById(R.id.url_cancel_button);
+        Button save = contentView.findViewById(R.id.url_save_button);
+
+        url_text.setText(NetFunctionConfig.getCBDUrl());
+
+        cancel.setOnClickListener(v -> {
+            if (alertDialog != null) {
+                alertDialog.dismiss();
+            }
+        });
+
+        save.setOnClickListener(v -> {
+            NetFunctionConfig.setCBDUrl(url_text.getText().toString());
+            if (alertDialog != null) {
+                alertDialog.dismiss();
+            }
+        });
+
+        alertDialog = builder.create();
+        alertDialog.setCanceledOnTouchOutside(true);
+        alertDialog.setCancelable(true);
+        alertDialog.show();
+    }
+}

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

@@ -7,6 +7,7 @@ import android.content.Intent;
 import android.text.TextUtils;
 
 import com.example.informationkanban.InitActivity;
+import com.example.informationkanban.MainActivity;
 
 import java.io.DataOutputStream;
 import java.io.IOException;
@@ -113,7 +114,7 @@ public class AppUtil {
 
     public static void restartApp(Context context) {
         //重新启动app
-        Intent mStartActivity = new Intent(context.getApplicationContext(), InitActivity.class);
+        Intent mStartActivity = new Intent(context.getApplicationContext(), MainActivity.class);
         mStartActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
         int mPendingIntentId = 123456;
         PendingIntent mPendingIntent = PendingIntent.getActivity(context.getApplicationContext(), mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT);

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

@@ -28,6 +28,8 @@ public class NetFunctionConfig {
     //private static final String default_server_port = "8101";
     private static final String default_server_port = "8100";
 
+    private static final String KEY_CBD_URL = "KEY_CBD_URL";
+
     private static final String KEY_MODE = "KEY_MODE";
     private static final String KEY_PART_ID = "KEY_PART_ID";
 
@@ -96,6 +98,14 @@ public class NetFunctionConfig {
         getEditor().putString(KEY_PART_ID, partId).apply();
     }
 
+    public static String getCBDUrl() {
+        return getSP().getString(KEY_CBD_URL, "");
+    }
+
+    public static void setCBDUrl(String url) {
+        getEditor().putString(KEY_CBD_URL, url).apply();
+    }
+
 
     private static SharedPreferences getSP() {
         return MyApplication.getInstance().getSharedPreferences(INFORMATION_KAN_BAN_KEY, Context.MODE_PRIVATE);

+ 5 - 0
app/src/main/res/drawable/selector_bottom_btn_text_color.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item android:color="#B4B4B4" android:state_checked="true"/>
+    <item android:color="#FFFFFF"/>
+</selector>

+ 6 - 0
app/src/main/res/drawable/selector_nuser_ed_d.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <item android:drawable="@drawable/shape_n_login_ed_bg" android:state_checked="false" />
+    <item android:drawable="@drawable/shape_n_login_ed_bg2" android:state_checked="true" />
+</selector>

+ 5 - 0
app/src/main/res/drawable/shape_bed_bg.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android">
+    <solid android:color="#FFFFFF" />
+    <corners android:radius="10dp" />
+</shape>

+ 5 - 0
app/src/main/res/drawable/shape_main_hos_txt_bg.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android">
+    <solid android:color="#ff3a78ef" />
+    <corners android:radius="10dp" />
+</shape>

+ 7 - 0
app/src/main/res/drawable/shape_n_login_ed_bg.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <solid android:color="#F7F7F7" />
+    <stroke android:width="2dp" android:color="#F2F2F2" />
+    <corners android:radius="8dp" />
+</shape>

+ 7 - 0
app/src/main/res/drawable/shape_n_login_ed_bg2.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <solid android:color="#F7F8FC" />
+    <stroke android:width="2dp" android:color="#ff3f80f1" />
+    <corners android:radius="8dp" />
+</shape>

+ 5 - 0
app/src/main/res/drawable/shape_password_bt_bg.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android">
+    <solid android:color="#97A2BE" />
+    <corners android:radius="10dp" />
+</shape>

+ 85 - 0
app/src/main/res/layout/url_config_dialog.xml

@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:gravity="center"
+    android:background="@android:color/transparent">
+
+    <LinearLayout
+        android:id="@+id/ll_url_config_view"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:padding="10dp"
+        android:background="@drawable/shape_bed_bg"
+        android:gravity="center"
+        android:orientation="vertical">
+
+        <TextView
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="20dp"
+            android:gravity="center"
+            android:text="URL配置"
+            android:textColor="#000000"
+            android:textSize="18sp"
+            android:textStyle="bold" />
+
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="20dp"
+            android:gravity="center_vertical"
+            android:orientation="horizontal">
+
+            <TextView
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="URL:"
+                android:textColor="#000000"
+                android:textSize="18sp"
+                android:textStyle="bold" />
+
+            <EditText
+                android:id="@+id/edit_url"
+                android:layout_width="match_parent"
+                android:layout_height="40dp"
+                android:layout_marginLeft="20dp"
+                android:background="@drawable/selector_nuser_ed_d"
+                android:paddingLeft="10dp"
+                android:textSize="16sp"
+                android:textStyle="bold" />
+
+        </LinearLayout>
+
+        <LinearLayout
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="20dp"
+            android:layout_marginBottom="40dp"
+            android:gravity="center_vertical"
+            android:orientation="horizontal">
+
+            <Button
+                android:id="@+id/url_cancel_button"
+                android:layout_width="120dp"
+                android:layout_height="wrap_content"
+                android:background="@drawable/shape_password_bt_bg"
+                android:gravity="center"
+                android:text="取消"
+                android:textColor="@drawable/selector_bottom_btn_text_color"
+                android:textSize="16sp" />
+
+            <Button
+                android:id="@+id/url_save_button"
+                android:layout_width="120dp"
+                android:layout_height="wrap_content"
+                android:layout_marginLeft="20dp"
+                android:background="@drawable/shape_main_hos_txt_bg"
+                android:gravity="center"
+                android:text="保存"
+                android:textColor="@drawable/selector_bottom_btn_text_color"
+                android:textSize="16sp" />
+        </LinearLayout>
+    </LinearLayout>
+
+</LinearLayout>

+ 1 - 1
app/src/main/res/values-es/strings.xml

@@ -1,5 +1,5 @@
 <resources>
-    <string name="app_name">InfoBoard2</string>
+    <string name="app_name">CBD</string>
 
     <string name="setting_language">Configuración de idioma</string>
     <string name="setting_change_server">Configuración del servidor</string>

+ 2 - 2
app/src/main/res/values-zh-rCN/strings.xml

@@ -1,5 +1,5 @@
 <resources>
-    <string name="app_name">信息看板2</string>
+    <string name="app_name">CBD看板</string>
     <!--<string name="app_name">输液看板</string>-->
 
     <string name="setting_language">语言设置</string>
@@ -25,5 +25,5 @@
     <string name="server_port">服务器端口:</string>
     <string name="part_id">科室ID:</string>
 
-    <string name="loading_percent">加载中...%d%%</string>
+    <string name="loading_percent">加载中%d%%</string>
 </resources>

+ 2 - 2
app/src/main/res/values/strings.xml

@@ -1,5 +1,5 @@
 <resources>
-    <string name="app_name">InfoBoard2</string>
+    <string name="app_name">CBD</string>
 
     <string name="setting_language">Language set</string>
     <string name="setting_change_server">Change server</string>
@@ -24,5 +24,5 @@
     <string name="server_port">Server port:</string>
     <string name="part_id">Part ID:</string>
 
-    <string name="loading_percent">loading...%d%%</string>
+    <string name="loading_percent">loading%d%%</string>
 </resources>