|
@@ -72,6 +72,7 @@ import com.xhly.manageapp.bean.strategy.StrategyBean
|
72
|
72
|
import com.xhly.manageapp.bean.user.UserBean
|
73
|
73
|
import com.xhly.manageapp.broadcastreceiver.AppInstallReceiver
|
74
|
74
|
import com.xhly.manageapp.broadcastreceiver.NetConnectReceiver
|
|
75
|
+import com.xhly.manageapp.broadcastreceiver.ScreenReceiver
|
75
|
76
|
import com.xhly.manageapp.service.ManageAccessibilityService
|
76
|
77
|
import com.xhly.manageapp.service.websocket.AppSocket
|
77
|
78
|
import com.xhly.manageapp.ui.ManageActivity
|
|
@@ -98,6 +99,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
|
98
|
99
|
|
99
|
100
|
private var mMyInstallReceiver: AppInstallReceiver? = null
|
100
|
101
|
private var netConnectReceiver:NetConnectReceiver?=null
|
|
102
|
+ private var mScreenReceiver:ScreenReceiver?=null
|
101
|
103
|
private var dataList: ArrayList<AppInfo> = arrayListOf()
|
102
|
104
|
private var userBean: UserBean? = null
|
103
|
105
|
private var timer: Timer? = null
|
|
@@ -120,6 +122,9 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
|
120
|
122
|
private var canClickFlag=false
|
121
|
123
|
//百度定位
|
122
|
124
|
private var locationClient:LocationClient?=null
|
|
125
|
+
|
|
126
|
+ //上次提醒时长,用来设置是否重新设置提醒任务
|
|
127
|
+ private var lastTipsTimeLong=0
|
123
|
128
|
override fun getBinding() = ActivityMainBinding.inflate(layoutInflater)
|
124
|
129
|
|
125
|
130
|
@SuppressLint("CheckResult")
|
|
@@ -159,6 +164,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
|
159
|
164
|
// checkAccessibility(this)
|
160
|
165
|
registerAppInstallReceiver()
|
161
|
166
|
registerNetConnectReceiver()
|
|
167
|
+ registerScreenReceiver()
|
162
|
168
|
/*
|
163
|
169
|
使用情况权限
|
164
|
170
|
val permissionIntent = Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)
|
|
@@ -914,8 +920,9 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
|
914
|
920
|
}
|
915
|
921
|
}
|
916
|
922
|
|
917
|
|
- private fun startTimeTask(bean: SchoolDeviceSetBean) {
|
918
|
|
- if (bean.remindDuration == 1 && bean.duration > 0) {
|
|
923
|
+ private fun startTimeTask(bean: SchoolDeviceSetBean,fromBroadcast:Boolean=false) {
|
|
924
|
+ //和上次时长不一致才使用,但是从广播调用时不用和上次时长对比
|
|
925
|
+ if (bean.remindDuration == 1 && bean.duration > 0&&(lastTipsTimeLong!=bean.duration||fromBroadcast)) {
|
919
|
926
|
//如果设置的有时间则执行任务
|
920
|
927
|
try {
|
921
|
928
|
timer?.cancel()
|
|
@@ -923,12 +930,13 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
|
923
|
930
|
} catch (e: Exception) {
|
924
|
931
|
|
925
|
932
|
}
|
|
933
|
+ lastTipsTimeLong=bean.duration
|
926
|
934
|
timer?.let {
|
927
|
935
|
timer?.schedule(object : TimerTask() {
|
928
|
936
|
override fun run() {
|
929
|
937
|
Toast(getString(R.string.durationtips))
|
930
|
938
|
}
|
931
|
|
- }, bean.duration * 60 * 1000L, bean.duration * 60 * 1000L)
|
|
939
|
+ }, bean.duration * 60 * 1000L, bean.duration* 60 * 1000L)
|
932
|
940
|
}
|
933
|
941
|
}
|
934
|
942
|
//如果设置的有时间则取消所有任务
|
|
@@ -1133,6 +1141,23 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
|
1133
|
1141
|
Const.STARTSOCKET -> {
|
1134
|
1142
|
AppSocket.startSocket(this)
|
1135
|
1143
|
}
|
|
1144
|
+
|
|
1145
|
+ Const.ACTION_SCREEN_ON->{
|
|
1146
|
+ StrategyUtils.getSchoolDeviceSetBean(this)?.let {
|
|
1147
|
+ startTimeTask(it,true)
|
|
1148
|
+ }
|
|
1149
|
+ }
|
|
1150
|
+ Const.ACTION_SCREEN_OFF->{
|
|
1151
|
+ //取消定时任务
|
|
1152
|
+ if (timer != null) {
|
|
1153
|
+ timer?.cancel()
|
|
1154
|
+ timer = null
|
|
1155
|
+ }
|
|
1156
|
+ LogShow("关闭任务")
|
|
1157
|
+ }
|
|
1158
|
+ Const.ACCOUNTLOGINOUTSUCESS->{
|
|
1159
|
+ loginOutSucess()
|
|
1160
|
+ }
|
1136
|
1161
|
}
|
1137
|
1162
|
}
|
1138
|
1163
|
|
|
@@ -1268,6 +1293,16 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
|
1268
|
1293
|
registerReceiver(netConnectReceiver, IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION))
|
1269
|
1294
|
}
|
1270
|
1295
|
|
|
1296
|
+ /**
|
|
1297
|
+ * 熄屏注册监听
|
|
1298
|
+ */
|
|
1299
|
+ private fun registerScreenReceiver() {
|
|
1300
|
+ val filter = IntentFilter()
|
|
1301
|
+ filter.addAction(Intent.ACTION_SCREEN_ON)
|
|
1302
|
+ filter.addAction(Intent.ACTION_SCREEN_OFF)
|
|
1303
|
+ mScreenReceiver = ScreenReceiver()
|
|
1304
|
+ registerReceiver(mScreenReceiver, filter)
|
|
1305
|
+ }
|
1271
|
1306
|
|
1272
|
1307
|
private fun showEditDialog() {
|
1273
|
1308
|
if (accountDialog==null){
|
|
@@ -1372,6 +1407,9 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
|
1372
|
1407
|
netConnectReceiver?.let {
|
1373
|
1408
|
unregisterReceiver(it)
|
1374
|
1409
|
}
|
|
1410
|
+ mScreenReceiver?.let {
|
|
1411
|
+ unregisterReceiver(it)
|
|
1412
|
+ }
|
1375
|
1413
|
LogShow("MainActivity被销毁")
|
1376
|
1414
|
}
|
1377
|
1415
|
|