Bladeren bron

定时休眠模式优化

weizhengliang 1 jaar geleden
bovenliggende
commit
0c75549ff0

+ 38 - 24
android_bed/src/main/h7_3128/java/com/wdkl/app/ncs/callingbed/activity/CallingbedActivity.kt

@@ -225,7 +225,7 @@ class CallingbedActivity :BaseActivity<CallingbedActivityPresenter, Callingbed2M
 
 
         //亮屏
         //亮屏
         AppUtil.wakeUp(activity)
         AppUtil.wakeUp(activity)
-        setScreenOffTime()
+        setScreenOffTime(Constant.day_state)
 
 
         checkServer()
         checkServer()
 
 
@@ -322,12 +322,25 @@ class CallingbedActivity :BaseActivity<CallingbedActivityPresenter, Callingbed2M
                         }
                         }
                     }
                     }
 
 
-                    if (Constant.CUSTOM_ID == -1) {
-                        //床位未入住,设备休眠
-                        AppUtil.goToSleep(activity)
-                    } else if (Constant.NIGHT_BRIGHTNESS == 0 && Constant.day_state == 1 && !Constant.IS_RECORDING && skyCallFragment == null) {
-                        //当前为夜晚熄屏模式,设备休眠
-                        AppUtil.goToSleep(activity)
+
+                    runOnUiThread {
+                        updateSettings(false)
+                        updateNetState()
+                        if (initialized) {
+                            updateTcpState()
+
+                            if (Constant.LATER_RESTART && Constant.CALL_STATE == Constant.CALL_STANDBY) {
+                                AppUpdateHelper.restartApp(activity)
+                            }
+                        }
+
+                        if (Constant.CUSTOM_ID == -1) {
+                            //床位未入住,设备休眠
+                            AppUtil.goToSleep(activity)
+                        } else if (Constant.NIGHT_BRIGHTNESS == 0 && Constant.day_state == 1 && !Constant.IS_RECORDING && skyCallFragment == null) {
+                            //当前为夜晚熄屏模式,设备休眠
+                            AppUtil.goToSleep(activity)
+                        }
                     }
                     }
                 } catch (e: Exception) {
                 } catch (e: Exception) {
                     //
                     //
@@ -956,7 +969,7 @@ class CallingbedActivity :BaseActivity<CallingbedActivityPresenter, Callingbed2M
                     initDevice()
                     initDevice()
 
 
                     //容错处理,设置熄屏时间
                     //容错处理,设置熄屏时间
-                    setScreenOffTime()
+                    setScreenOffTime(Constant.day_state)
                 } catch (e: Exception) {
                 } catch (e: Exception) {
                     //
                     //
                 }
                 }
@@ -982,7 +995,7 @@ class CallingbedActivity :BaseActivity<CallingbedActivityPresenter, Callingbed2M
     private fun regReceiver() {
     private fun regReceiver() {
         receiver = TimeReceiver()
         receiver = TimeReceiver()
         val intentFilter = IntentFilter()
         val intentFilter = IntentFilter()
-        intentFilter.addAction(Intent.ACTION_TIME_TICK)
+        //intentFilter.addAction(Intent.ACTION_TIME_TICK)
         intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION)
         intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION)
         registerReceiver(receiver, intentFilter)
         registerReceiver(receiver, intentFilter)
     }
     }
@@ -1183,7 +1196,7 @@ class CallingbedActivity :BaseActivity<CallingbedActivityPresenter, Callingbed2M
                 }, 2000)
                 }, 2000)
 
 
                 //退出通话,重新设置熄屏时间
                 //退出通话,重新设置熄屏时间
-                setScreenOffTime()
+                setScreenOffTime(Constant.day_state)
             }
             }
 
 
             //Sip注册状态
             //Sip注册状态
@@ -1636,6 +1649,9 @@ class CallingbedActivity :BaseActivity<CallingbedActivityPresenter, Callingbed2M
                 VoiceManagerUtil.setMusicVoice(this, SettingConfig.getExtensionDaytimeSystemVolume(this))
                 VoiceManagerUtil.setMusicVoice(this, SettingConfig.getExtensionDaytimeSystemVolume(this))
                 view_title_layout_iv_day_night.setImageResource(R.mipmap.ic_daylight)
                 view_title_layout_iv_day_night.setImageResource(R.mipmap.ic_daylight)
 
 
+                //白天模式
+                setScreenOffTime(0)
+
                 //灭掉紧急按钮灯
                 //灭掉紧急按钮灯
                 AppTool.Time.delay(2000) {
                 AppTool.Time.delay(2000) {
                     SerialPortHelper.setSosLight("0")
                     SerialPortHelper.setSosLight("0")
@@ -1652,6 +1668,9 @@ class CallingbedActivity :BaseActivity<CallingbedActivityPresenter, Callingbed2M
                 VoiceManagerUtil.setMusicVoice(this, SettingConfig.getExtensionNightSystemVolume(this))
                 VoiceManagerUtil.setMusicVoice(this, SettingConfig.getExtensionNightSystemVolume(this))
                 view_title_layout_iv_day_night.setImageResource(R.mipmap.ic_night)
                 view_title_layout_iv_day_night.setImageResource(R.mipmap.ic_night)
 
 
+                //夜晚模式
+                setScreenOffTime(1)
+
                 //打开紧急按钮灯
                 //打开紧急按钮灯
                 AppTool.Time.delay(2000) {
                 AppTool.Time.delay(2000) {
                     SerialPortHelper.setSosLight("1")
                     SerialPortHelper.setSosLight("1")
@@ -1677,29 +1696,20 @@ class CallingbedActivity :BaseActivity<CallingbedActivityPresenter, Callingbed2M
             //当前是白天且床位有入住才亮屏
             //当前是白天且床位有入住才亮屏
             AppUtil.wakeUp(activity)
             AppUtil.wakeUp(activity)
         }
         }
-
-        if (forceSet) {
-            setScreenOffTime()
-        }
     }
     }
 
 
     inner class TimeReceiver: BroadcastReceiver() {
     inner class TimeReceiver: BroadcastReceiver() {
         override fun onReceive(context: Context, intent: Intent) {
         override fun onReceive(context: Context, intent: Intent) {
-            if (intent.action == Intent.ACTION_TIME_TICK) {
+            /*if (intent.action == Intent.ACTION_TIME_TICK) {
                 updateNetState()
                 updateNetState()
                 if (initialized) {
                 if (initialized) {
-                    updateSettings(false)
                     updateTcpState()
                     updateTcpState()
 
 
                     if (Constant.LATER_RESTART && Constant.CALL_STATE == Constant.CALL_STANDBY) {
                     if (Constant.LATER_RESTART && Constant.CALL_STATE == Constant.CALL_STANDBY) {
                         AppUpdateHelper.restartApp(activity)
                         AppUpdateHelper.restartApp(activity)
                     }
                     }
-                } /*else if (TextUtils.isEmpty(Constant.TCP_SERVER_URL)) {
-                    //还未连接tcp服务器
-                    presenter.loadTcpServerHost()
-                }*/
-                //checkNet()
-            } else if (intent.action == ConnectivityManager.CONNECTIVITY_ACTION) {
+                }
+            } else*/ if (intent.action == ConnectivityManager.CONNECTIVITY_ACTION) {
                 updateNetState()
                 updateNetState()
             }
             }
         }
         }
@@ -1709,9 +1719,13 @@ class CallingbedActivity :BaseActivity<CallingbedActivityPresenter, Callingbed2M
         return false
         return false
     }
     }
 
 
-    private fun setScreenOffTime() {
+    /**
+     * @description
+     * @param state 1:夜晚,其他:白天
+     */
+    private fun setScreenOffTime(state: Int) {
         //如果当前是夜晚模式且亮度为0则设置自动熄屏
         //如果当前是夜晚模式且亮度为0则设置自动熄屏
-        if (Constant.NIGHT_BRIGHTNESS == 0 && Constant.day_state == 1 && !Constant.IS_RECORDING && skyCallFragment == null) {
+        if (Constant.NIGHT_BRIGHTNESS == 0 && state == 1 && !Constant.IS_RECORDING && skyCallFragment == null) {
             //根据服务器设置自动熄屏时间
             //根据服务器设置自动熄屏时间
             Log.d(TAG, "set screen off timeout: ${Constant.SLEEP_MINUTE}")
             Log.d(TAG, "set screen off timeout: ${Constant.SLEEP_MINUTE}")
             AppTool.Setting.setScreenOffTimeOut(applicationContext, Constant.SLEEP_MINUTE)
             AppTool.Setting.setScreenOffTimeOut(applicationContext, Constant.SLEEP_MINUTE)