Browse Source

1.增加学校设备设置使用。

master
wangwanlei 8 months ago
parent
commit
4a8fdae133

+ 3
- 0
app/src/main/AndroidManifest.xml View File

29
     <!--位置权限-->
29
     <!--位置权限-->
30
     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
30
     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
31
     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
31
     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
32
+    <!--护眼模式权限,只有系统app可以使用-->
33
+    <uses-permission android:name="android.permission.CONTROL_DISPLAY_COLOR_TRANSFORMS"
34
+        tools:ignore="ProtectedPermissions" />
32
 
35
 
33
     <application
36
     <application
34
         android:name=".ManageApplication"
37
         android:name=".ManageApplication"

+ 69
- 33
app/src/main/java/com/xhly/manageapp/ui/main/activity/MainActivity.kt View File

56
 import com.xhly.manageapp.workmanager.TimingWorker
56
 import com.xhly.manageapp.workmanager.TimingWorker
57
 import kotlinx.coroutines.launch
57
 import kotlinx.coroutines.launch
58
 import java.util.Calendar
58
 import java.util.Calendar
59
+import java.util.Timer
60
+import java.util.TimerTask
59
 import java.util.concurrent.TimeUnit
61
 import java.util.concurrent.TimeUnit
60
 
62
 
61
 
63
 
65
     private var mMyInstallReceiver: AppInstallReceiver? = null
67
     private var mMyInstallReceiver: AppInstallReceiver? = null
66
     private var dataList: ArrayList<AppInfo> = arrayListOf()
68
     private var dataList: ArrayList<AppInfo> = arrayListOf()
67
     private var userBean: UserBean? = null
69
     private var userBean: UserBean? = null
70
+    private var timer: Timer?=null
68
     override fun getBinding() = ActivityMainBinding.inflate(layoutInflater)
71
     override fun getBinding() = ActivityMainBinding.inflate(layoutInflater)
69
 
72
 
70
     override fun initData() {
73
     override fun initData() {
83
         mBinding.btn.setOnClickListener {
86
         mBinding.btn.setOnClickListener {
84
             startIntentActivity(ManageActivity().javaClass)
87
             startIntentActivity(ManageActivity().javaClass)
85
         }
88
         }
86
-        registerAppInstallReceiver()
87
-        /*
89
+        registerAppInstallReceiver()/*
88
          使用情况权限
90
          使用情况权限
89
          val permissionIntent = Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)
91
          val permissionIntent = Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)
90
           startActivity(permissionIntent)*/
92
           startActivity(permissionIntent)*/
147
         }
149
         }
148
         viewModel.updateInfoData.observe(this) {
150
         viewModel.updateInfoData.observe(this) {
149
             //成功则保存不在提交
151
             //成功则保存不在提交
150
-            if (it){
151
-                spUtils.setParam(Const.PADUPDATETIMEKEY,System.currentTimeMillis())
152
+            if (it) {
153
+                spUtils.setParam(Const.PADUPDATETIMEKEY, System.currentTimeMillis())
152
             }
154
             }
153
         }
155
         }
154
-        viewModel.schoolSetData.observe(this){
155
-            spUtils.saveJson(Const.SCHOOLSETDEVICE,it)
156
+        viewModel.schoolSetData.observe(this) {
157
+            spUtils.saveJson(Const.SCHOOLSETDEVICE, it)
158
+            initSchoolSet(it)
156
             updateAppRv()
159
             updateAppRv()
157
         }
160
         }
158
         startWorkManager()
161
         startWorkManager()
159
     }
162
     }
160
 
163
 
164
+
161
     override fun onNewIntent(intent: Intent?) {
165
     override fun onNewIntent(intent: Intent?) {
162
         super.onNewIntent(intent)
166
         super.onNewIntent(intent)
163
     }
167
     }
200
         updatePadInfo()
204
         updatePadInfo()
201
         updateMcApp()
205
         updateMcApp()
202
         getLocation()
206
         getLocation()
203
-        try {
204
-            var s =
205
-                "厂商" + CustomOSUtils.getSystemBrand() + ",型号" + CustomOSUtils.getSystemDevice() + ",系统版本" + CustomOSUtils.getSystemDisplay()
206
-        } catch (e: Exception) {
207
-            LogShow("没有数据")
208
-        }
209
     }
207
     }
210
 
208
 
211
     private fun updateMcApp() {
209
     private fun updateMcApp() {
274
     private fun getLocation() {
272
     private fun getLocation() {
275
         val rxPermissions = RxPermissions(this)
273
         val rxPermissions = RxPermissions(this)
276
         rxPermissions.request(
274
         rxPermissions.request(
277
-            Manifest.permission.ACCESS_FINE_LOCATION,
278
-            Manifest.permission.ACCESS_COARSE_LOCATION
275
+            Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION
279
         ).subscribe({
276
         ).subscribe({
280
             if (it) {
277
             if (it) {
281
                 SystemUtil.getLocation(this)
278
                 SystemUtil.getLocation(this)
343
                 ManageApplication.removeInstallPackageWhiteList(removeList)*/
340
                 ManageApplication.removeInstallPackageWhiteList(removeList)*/
344
     }
341
     }
345
 
342
 
343
+    private fun initSchoolSet(schoolDeviceSetBean: SchoolDeviceSetBean? = null) {
344
+        schoolDeviceSetBean?.let {bean->
345
+            //是否启用截屏:1是0否
346
+            ManageApplication.enableCaptureScreen(schoolDeviceSetBean.screenshots == 1)
347
+            if (bean.forceBind == 1) {
348
+                //TODO 设备端如何操作
349
+            }
350
+            if (bean.schoolClass == 1) {
351
+                mBinding.userschoolTv.visibility = View.VISIBLE
352
+            } else {
353
+                mBinding.userschoolTv.visibility = View.INVISIBLE
354
+            }
355
+            //设置护眼模式
356
+            CustomOSUtils.openOrCloseNightMode(this, bean.protectedEyes == 1)
357
+            startTimeTask(bean)
358
+        }
359
+    }
360
+
361
+    private fun startTimeTask(bean: SchoolDeviceSetBean) {
362
+        if (bean.remindDuration==1){
363
+            //如果设置的有时间则执行任务
364
+            if (timer==null){
365
+                timer= Timer()
366
+            }else{
367
+                timer?.cancel()
368
+            }
369
+            timer?.let {
370
+                timer?.schedule( object : TimerTask() {
371
+                    override fun run() {
372
+                        // 在这里编写您的定时任务代码
373
+                        Toast(getString(R.string.durationtips))
374
+                        startTimeTask(bean)
375
+                    }
376
+                },0L,bean.duration*60*1000L)
377
+            }
378
+        }
379
+        //如果设置的有时间则取消所有任务
380
+        if (bean.remindDuration!=1){
381
+            if (timer!=null){
382
+                timer?.cancel()
383
+                timer=null
384
+            }
385
+        }
386
+    }
387
+
388
+
346
     override fun onUiEvent(uiEvent: UIEvent) {
389
     override fun onUiEvent(uiEvent: UIEvent) {
347
         super.onUiEvent(uiEvent)
390
         super.onUiEvent(uiEvent)
348
         when (uiEvent.getEvent()) {
391
         when (uiEvent.getEvent()) {
474
 
517
 
475
     private fun updateAppRv() {
518
     private fun updateAppRv() {
476
         try {
519
         try {
477
-            var schoolDeviceSetBean:SchoolDeviceSetBean?=null
478
-            try {
479
-                val beanStr =
480
-                    spUtils.getFromJson(Const.SCHOOLSETDEVICE, SchoolDeviceSetBean().javaClass)
481
-                if (beanStr!=null){
482
-                    schoolDeviceSetBean=beanStr as SchoolDeviceSetBean
483
-                }
484
-            }catch (e:Exception){
485
-                //为了不影响列表显示
486
-            }
520
+            var schoolDeviceSetBean: SchoolDeviceSetBean? = null
521
+            schoolDeviceSetBean = StrategyUtils.getSchoolDeviceSetBean(this)
487
             dataList.clear()
522
             dataList.clear()
488
             var appList = AppUtils.GetAppList(this)
523
             var appList = AppUtils.GetAppList(this)
489
             appList.addAll(CustomAppUtils().getCustomAppList(this))
524
             appList.addAll(CustomAppUtils().getCustomAppList(this))
490
-            if (schoolDeviceSetBean!=null){
491
-                appList=StrategyUtils.setSchoolSetDevice(schoolDeviceSetBean,appList)
525
+            if (schoolDeviceSetBean != null) {
526
+                appList = StrategyUtils.setSchoolSetDevice(schoolDeviceSetBean, appList)
492
             }
527
             }
493
             dataList.addAll(appList)
528
             dataList.addAll(appList)
494
             if (adapter == null) {
529
             if (adapter == null) {
559
                             dialog.dismiss()
594
                             dialog.dismiss()
560
                             try {
595
                             try {
561
                                 val userBean = spUtils.getFromJson(
596
                                 val userBean = spUtils.getFromJson(
562
-                                    Const.USERINFO,
563
-                                    UserBean().javaClass
597
+                                    Const.USERINFO, UserBean().javaClass
564
                                 ) as UserBean
598
                                 ) as UserBean
565
                                 viewModel.loginOut(userBean.userid.toString(), code.toString())
599
                                 viewModel.loginOut(userBean.userid.toString(), code.toString())
566
                             } catch (e: Exception) {
600
                             } catch (e: Exception) {
584
                     val titleTv = v.findViewById<TextView>(R.id.dialog_title_tv)
618
                     val titleTv = v.findViewById<TextView>(R.id.dialog_title_tv)
585
                     val contentTv = v.findViewById<TextView>(R.id.dialog_content_tv)
619
                     val contentTv = v.findViewById<TextView>(R.id.dialog_content_tv)
586
                     try {
620
                     try {
587
-                        val msgBean =
588
-                            GsonUtils.parseJsonWithGson(
589
-                                msg,
590
-                                SocketMsgBean().javaClass
591
-                            ) as SocketMsgBean
621
+                        val msgBean = GsonUtils.parseJsonWithGson(
622
+                            msg, SocketMsgBean().javaClass
623
+                        ) as SocketMsgBean
592
                         titleTv.text = msgBean.title
624
                         titleTv.text = msgBean.title
593
                         contentTv.text = msgBean.content
625
                         contentTv.text = msgBean.content
594
                     } catch (e: Exception) {
626
                     } catch (e: Exception) {
612
 
644
 
613
     override fun onDestroy() {
645
     override fun onDestroy() {
614
         super.onDestroy()
646
         super.onDestroy()
647
+        if (timer!=null){
648
+            timer?.cancel()
649
+            timer=null
650
+        }
615
         mMyInstallReceiver?.let {
651
         mMyInstallReceiver?.let {
616
             unregisterReceiver(it)
652
             unregisterReceiver(it)
617
         }
653
         }

+ 5
- 0
app/src/main/java/com/xhly/manageapp/utils/CustomAppUtils.kt View File

26
             Const.CUSTOMROTATIONAPP,
26
             Const.CUSTOMROTATIONAPP,
27
             AppCompatResources.getDrawable(context,R.drawable.icon_speed)!!
27
             AppCompatResources.getDrawable(context,R.drawable.icon_speed)!!
28
         ))
28
         ))
29
+        appList.add(getCusomAppBean(
30
+            context.getString(R.string.changepsd),
31
+            Const.CUSTOMROTATIONAPP,
32
+            AppCompatResources.getDrawable(context,R.drawable.icon_speed)!!
33
+        ))
29
         return appList
34
         return appList
30
     }
35
     }
31
 
36
 

+ 20
- 0
app/src/main/java/com/xhly/manageapp/utils/StrategyUtils.kt View File

258
             if (schoolDeviceSetBean.rotateSetting==0&&appinfo.packageName.equals(Const.CUSTOMROTATIONAPP)){
258
             if (schoolDeviceSetBean.rotateSetting==0&&appinfo.packageName.equals(Const.CUSTOMROTATIONAPP)){
259
                 return@forEach
259
                 return@forEach
260
             }
260
             }
261
+            //修改密码
262
+            if (schoolDeviceSetBean.changePwd==0&&appinfo.packageName.equals(Const.CUSTOMCHANGEPSD)){
263
+                return@forEach
264
+            }
261
             dataList.add(appinfo)
265
             dataList.add(appinfo)
262
         }
266
         }
263
         return dataList
267
         return dataList
264
     }
268
     }
269
+
270
+    //获得存储的学校设备设置
271
+    public fun getSchoolDeviceSetBean(context: Context):SchoolDeviceSetBean?{
272
+        val spUtils = SharedPreferencesUtils.getInstance(context)
273
+        var schoolDeviceSetBean: SchoolDeviceSetBean? = null
274
+        try {
275
+            val beanStr =
276
+                spUtils.getFromJson(Const.SCHOOLSETDEVICE, SchoolDeviceSetBean().javaClass)
277
+            if (beanStr != null) {
278
+                schoolDeviceSetBean = beanStr as SchoolDeviceSetBean
279
+            }
280
+        } catch (e: Exception) {
281
+            //为了不影响列表显示
282
+        }
283
+        return schoolDeviceSetBean
284
+    }
265
 }
285
 }

+ 1
- 1
app/src/main/res/layout/activity_main.xml View File

51
             </LinearLayout>
51
             </LinearLayout>
52
 
52
 
53
             <TextView
53
             <TextView
54
-                android:id="@+id/userschool_iv"
54
+                android:id="@+id/userschool_tv"
55
                 android:layout_width="wrap_content"
55
                 android:layout_width="wrap_content"
56
                 android:layout_height="wrap_content"
56
                 android:layout_height="wrap_content"
57
                 android:layout_marginLeft="21dp"
57
                 android:layout_marginLeft="21dp"

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

20
     <string name="clear">清除缓存</string>
20
     <string name="clear">清除缓存</string>
21
     <string name="speed">一键加速</string>
21
     <string name="speed">一键加速</string>
22
     <string name="rotation">自动旋转</string>
22
     <string name="rotation">自动旋转</string>
23
+    <string name="changepsd">修改密码</string>
23
     <string name="locktips">您的设备已违规或者被管理员限制使用,请联系管理员</string>
24
     <string name="locktips">您的设备已违规或者被管理员限制使用,请联系管理员</string>
25
+    <string name="durationtips">当前使用时间过长,请休息后再使用。\n</string>
24
 </resources>
26
 </resources>

+ 4
- 0
corelib/src/main/java/com/xhly/corelib/Const.kt View File

160
      *标记自定义的自动旋转名称
160
      *标记自定义的自动旋转名称
161
      */
161
      */
162
     const val CUSTOMROTATIONAPP="CUSTOMROTATIONAPP"
162
     const val CUSTOMROTATIONAPP="CUSTOMROTATIONAPP"
163
+    /**
164
+     *标记自定义的修改密码
165
+     */
166
+    const val CUSTOMCHANGEPSD="CUSTOMCHANGEPSD"
163
 }
167
 }

Loading…
Cancel
Save