Browse Source

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

master
wangwanlei 8 months ago
parent
commit
4a8fdae133

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

@@ -29,6 +29,9 @@
29 29
     <!--位置权限-->
30 30
     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
31 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 36
     <application
34 37
         android:name=".ManageApplication"

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

@@ -56,6 +56,8 @@ import com.xhly.manageapp.utils.StrategyUtils
56 56
 import com.xhly.manageapp.workmanager.TimingWorker
57 57
 import kotlinx.coroutines.launch
58 58
 import java.util.Calendar
59
+import java.util.Timer
60
+import java.util.TimerTask
59 61
 import java.util.concurrent.TimeUnit
60 62
 
61 63
 
@@ -65,6 +67,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
65 67
     private var mMyInstallReceiver: AppInstallReceiver? = null
66 68
     private var dataList: ArrayList<AppInfo> = arrayListOf()
67 69
     private var userBean: UserBean? = null
70
+    private var timer: Timer?=null
68 71
     override fun getBinding() = ActivityMainBinding.inflate(layoutInflater)
69 72
 
70 73
     override fun initData() {
@@ -83,8 +86,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
83 86
         mBinding.btn.setOnClickListener {
84 87
             startIntentActivity(ManageActivity().javaClass)
85 88
         }
86
-        registerAppInstallReceiver()
87
-        /*
89
+        registerAppInstallReceiver()/*
88 90
          使用情况权限
89 91
          val permissionIntent = Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)
90 92
           startActivity(permissionIntent)*/
@@ -147,17 +149,19 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
147 149
         }
148 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 159
             updateAppRv()
157 160
         }
158 161
         startWorkManager()
159 162
     }
160 163
 
164
+
161 165
     override fun onNewIntent(intent: Intent?) {
162 166
         super.onNewIntent(intent)
163 167
     }
@@ -200,12 +204,6 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
200 204
         updatePadInfo()
201 205
         updateMcApp()
202 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 209
     private fun updateMcApp() {
@@ -274,8 +272,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
274 272
     private fun getLocation() {
275 273
         val rxPermissions = RxPermissions(this)
276 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 276
         ).subscribe({
280 277
             if (it) {
281 278
                 SystemUtil.getLocation(this)
@@ -343,6 +340,52 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
343 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 389
     override fun onUiEvent(uiEvent: UIEvent) {
347 390
         super.onUiEvent(uiEvent)
348 391
         when (uiEvent.getEvent()) {
@@ -474,21 +517,13 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
474 517
 
475 518
     private fun updateAppRv() {
476 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 522
             dataList.clear()
488 523
             var appList = AppUtils.GetAppList(this)
489 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 528
             dataList.addAll(appList)
494 529
             if (adapter == null) {
@@ -559,8 +594,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
559 594
                             dialog.dismiss()
560 595
                             try {
561 596
                                 val userBean = spUtils.getFromJson(
562
-                                    Const.USERINFO,
563
-                                    UserBean().javaClass
597
+                                    Const.USERINFO, UserBean().javaClass
564 598
                                 ) as UserBean
565 599
                                 viewModel.loginOut(userBean.userid.toString(), code.toString())
566 600
                             } catch (e: Exception) {
@@ -584,11 +618,9 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
584 618
                     val titleTv = v.findViewById<TextView>(R.id.dialog_title_tv)
585 619
                     val contentTv = v.findViewById<TextView>(R.id.dialog_content_tv)
586 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 624
                         titleTv.text = msgBean.title
593 625
                         contentTv.text = msgBean.content
594 626
                     } catch (e: Exception) {
@@ -612,6 +644,10 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
612 644
 
613 645
     override fun onDestroy() {
614 646
         super.onDestroy()
647
+        if (timer!=null){
648
+            timer?.cancel()
649
+            timer=null
650
+        }
615 651
         mMyInstallReceiver?.let {
616 652
             unregisterReceiver(it)
617 653
         }

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

@@ -26,6 +26,11 @@ class CustomAppUtils {
26 26
             Const.CUSTOMROTATIONAPP,
27 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 34
         return appList
30 35
     }
31 36
 

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

@@ -258,8 +258,28 @@ object StrategyUtils {
258 258
             if (schoolDeviceSetBean.rotateSetting==0&&appinfo.packageName.equals(Const.CUSTOMROTATIONAPP)){
259 259
                 return@forEach
260 260
             }
261
+            //修改密码
262
+            if (schoolDeviceSetBean.changePwd==0&&appinfo.packageName.equals(Const.CUSTOMCHANGEPSD)){
263
+                return@forEach
264
+            }
261 265
             dataList.add(appinfo)
262 266
         }
263 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,7 +51,7 @@
51 51
             </LinearLayout>
52 52
 
53 53
             <TextView
54
-                android:id="@+id/userschool_iv"
54
+                android:id="@+id/userschool_tv"
55 55
                 android:layout_width="wrap_content"
56 56
                 android:layout_height="wrap_content"
57 57
                 android:layout_marginLeft="21dp"

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

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

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

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

Loading…
Cancel
Save