Procházet zdrojové kódy

增加同步服务器时区

weizhengliang před 2 roky
rodič
revize
2215427ef4

+ 29 - 9
callingdoor/src/main/java/com/wdkl/app/ncs/callingdoor/activity/CallingdoorActivity.kt

@@ -11,6 +11,7 @@ import android.util.Log
 import android.view.Gravity
 import android.view.View
 import android.widget.TextView
+import com.alibaba.fastjson.JSON
 import com.alibaba.fastjson.JSONObject
 import com.enation.javashop.android.jrouter.external.annotation.Router
 import com.enation.javashop.net.engine.model.NetState
@@ -191,8 +192,8 @@ class CallingdoorActivity :BaseActivity<CallingdoorActivityPresenter, Callingdoo
             }
 
             //设置默认时区为中国标准时间
-            val alarmManager = getSystemService(ALARM_SERVICE) as AlarmManager
-            alarmManager.setTimeZone("Asia/Shanghai")
+            //val alarmManager = getSystemService(ALARM_SERVICE) as AlarmManager
+            //alarmManager.setTimeZone("Asia/Shanghai")
         }
 
         //tts初始化
@@ -1222,16 +1223,24 @@ class CallingdoorActivity :BaseActivity<CallingdoorActivityPresenter, Callingdoo
                             callControl(tcpModel)
                         }
                     } else if(tcpModel.action == TcpAction.TimeAction.SYNC && tcpModel.type==TcpType.TIME){
-                        val time =  tcpModel.data.toString().toLong()*1000
-                        //设置系统时间
+                        var time = 0L
+                        var timeZone="Asia/Shanghai"
+                        if (canParseJson(tcpModel.data.toString())) {
+                            val json = JSON.parseObject(tcpModel.data.toString())
+                            time = json.getLong("time")*1000
+                            timeZone = json.getString("time_zone")
+                        } else {
+                            time = tcpModel.data.toString().toLong() * 1000
+                        }
+
                         try {
-                            AppUtil.setSystemTime(BaseApplication.appContext, time)
-                            Log.d(TAG, "set sys time1: $time")
+                            AppUtil.setSystemTime(BaseApplication.appContext, time, timeZone)
+                            Log.d("setTime", "set sys time1: $time, $timeZone")
                         } catch (e: Exception) {
                             //"20211213:092314"
-                            val timeStr = TimeHandle.getDateTime(time, "yyyyMMdd.hhmmss")
-                            AppUtil.setSysTime(timeStr)
-                            Log.d(TAG, "set sys time2: $timeStr")
+                            val timeStr = TimeHandle.getDateTime(time, "yyyyMMdd.HHmmss")
+                            AppUtil.setSysTime(timeStr, timeZone)
+                            Log.d("setTime", "set sys time2: $timeStr, $timeZone")
                         }
                     } else if (tcpModel.action == TcpAction.ReinforceAction.RESPONSED) {
                         //SoundPoolManager.getInstance().playSound(4, 1.0f, 1.0f, 0)
@@ -1259,6 +1268,17 @@ class CallingdoorActivity :BaseActivity<CallingdoorActivityPresenter, Callingdoo
         }
     }
 
+    private fun canParseJson(str:String) : Boolean {
+        var result = false
+        try {
+            JSON.parseObject(str)
+            result=true
+        }catch (e:java.lang.Exception){
+            result=false
+        }
+        return result
+    }
+
     private fun callControl(tcpModel: TcpModel) {
         if (tcpModel.action == TcpAction.SideAction.CALL) {
             SerialPortHelper.setDoorLight(1, "200")

+ 0 - 1
callingdoor/src/main/res/layout/view_title_layout.xml

@@ -34,7 +34,6 @@
         android:layout_centerVertical="true"
         android:format12Hour="yyyy-MM-dd HH:mm EEEE"
         android:format24Hour="yyyy-MM-dd HH:mm EEEE"
-        android:timeZone="GMT+8"
         android:textColor="@color/main_color"
         android:textSize="@dimen/font_size_20" />
 

+ 0 - 1
callingdoor/src/main/res/layout/view_title_layout_rk3288.xml

@@ -34,7 +34,6 @@
         android:layout_centerVertical="true"
         android:format12Hour="yyyy-MM-dd HH:mm EEEE"
         android:format24Hour="yyyy-MM-dd HH:mm EEEE"
-        android:timeZone="GMT+8"
         android:textColor="@color/main_color"
         android:textSize="@dimen/font_size_28" />
 

+ 3 - 3
common/src/main/code/com/wdkl/ncs/android/lib/utils/TimeHandle.kt

@@ -66,7 +66,7 @@ object TimeHandle {
     fun getDateTime(format: String): String {
         val date = Date(System.currentTimeMillis())
         val sdf = SimpleDateFormat(format)
-        sdf.timeZone = TimeZone.getTimeZone("GMT+8")
+        //sdf.timeZone = TimeZone.getTimeZone("GMT+8")
         return sdf.format(date)
     }
 
@@ -75,7 +75,7 @@ object TimeHandle {
         if (timeMillis > 0) {
             val date = Date(timeMillis)
             val sdf = SimpleDateFormat(format)
-            sdf.timeZone = TimeZone.getTimeZone("GMT+8")
+            //sdf.timeZone = TimeZone.getTimeZone("GMT+8")
             return sdf.format(date)
         }
         return "null"
@@ -88,7 +88,7 @@ object TimeHandle {
         val simpleDateFormat = SimpleDateFormat(pattern)
         var date: Date? = null
         try {
-            simpleDateFormat.timeZone = TimeZone.getTimeZone("GMT+8")
+            //simpleDateFormat.timeZone = TimeZone.getTimeZone("GMT+8")
             date = simpleDateFormat.parse(s)
 
             return date!!.time

+ 6 - 4
middleware/src/main/code/com/wdkl/ncs/android/middleware/utils/AppUtil.java

@@ -15,12 +15,13 @@ public class AppUtil {
      *
      * @param time
      */
-    public static void setSysTime(String time) {
+    public static void setSysTime(String time, String timeZone) {
         try {
             Process process = Runtime.getRuntime().exec("su");
             if (null == process) return;
             DataOutputStream os = new DataOutputStream(process.getOutputStream());
-            os.writeBytes("setprop persist.sys.timezone Asia/Shanghai\n");
+            //os.writeBytes("setprop persist.sys.timezone Asia/Shanghai\n");
+            os.writeBytes("setprop persist.sys.timezone " + timeZone + "\n");
             if (android.os.Build.VERSION.SDK_INT >= 24) {//7.1以上的系统
                 String datetime = changeTimeForm(time); //20211213:092314  ------  051315372019.00
                 os.writeBytes("/system/bin/date " + datetime + " set\n");
@@ -84,9 +85,10 @@ public class AppUtil {
         }
     }
 
-    public static void setSystemTime(Context context, long timeMills) {
+    public static void setSystemTime(Context context, long timeMills, String timeZone) {
         AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
-        alarmManager.setTimeZone("Asia/Shanghai");
+        //alarmManager.setTimeZone("Asia/Shanghai");
+        alarmManager.setTimeZone(timeZone);
         alarmManager.setTime(timeMills);
     }
 }

+ 1 - 1
resource/src/main/res/values-zh/strings.xml

@@ -70,7 +70,7 @@
     <string name="setting_params_error">获取设置参数异常:</string>
     <string name="support_sent">请求增援已发送</string>
     <string name="net_error">网络异常</string>
-    <string name="no_custom">床位未入住或未绑定设备,无法呼叫</string>
+    <string name="no_custom">设备可能未注册,无法呼叫</string>
     <string name="call_init_error">网络异常或sipId异常,请稍后</string>
     <string name="custom_empty">床位未入住,无法呼叫</string>
     <string name="call_fail">呼叫失败</string>