Browse Source

1.锁屏弹窗强制横屏

2025_1_17_tb223fc
wangwanlei 1 week ago
parent
commit
a06170ed9d

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

12
 import android.content.Context
12
 import android.content.Context
13
 import android.content.Intent
13
 import android.content.Intent
14
 import android.content.IntentFilter
14
 import android.content.IntentFilter
15
+import android.content.pm.ActivityInfo
15
 import android.content.pm.PackageManager
16
 import android.content.pm.PackageManager
16
 import android.graphics.Color
17
 import android.graphics.Color
17
 import android.graphics.drawable.BitmapDrawable
18
 import android.graphics.drawable.BitmapDrawable
157
     private var changeCodeDialog: CustomDialog? = null
158
     private var changeCodeDialog: CustomDialog? = null
158
     private var tipsDialog: CustomDialog? = null
159
     private var tipsDialog: CustomDialog? = null
159
     private var systemDialog: AlertDialog? = null
160
     private var systemDialog: AlertDialog? = null
160
-
161
+    //用于创建锁屏弹窗
161
     private var lockDialog: AlertDialog?=null
162
     private var lockDialog: AlertDialog?=null
163
+    private var lockDialogTv:TextView?=null
164
+    private var lockDialogEt:EditText?=null
165
+    private var lockversionTv:TextView?=null
166
+    private var lockDialogNetset:View?=null
167
+    //表示是否是设置wifi是的话,暂时隐藏锁屏弹窗
168
+    private var goWifiFlag=false
162
 
169
 
163
     //创建应用卸载集合,方便获得应用信息
170
     //创建应用卸载集合,方便获得应用信息
164
     private val unInstallAppList = arrayListOf<AppInfo>()
171
     private val unInstallAppList = arrayListOf<AppInfo>()
335
         viewModel.lockResultData.observe(this) {
342
         viewModel.lockResultData.observe(this) {
336
             if (it) {
343
             if (it) {
337
                 //获得违规状态后,锁定桌面
344
                 //获得违规状态后,锁定桌面
338
-                spUtils.setParam(Const.DISABLEPAD, true)
345
+                /*spUtils.setParam(Const.DISABLEPAD, true)
339
                 startIntentActivity(MainActivity().javaClass)
346
                 startIntentActivity(MainActivity().javaClass)
340
-                val appList = AppUtils.GetAppList(this)
341
-                StrategyUtils.clearMemory(this, appList)
347
+                clearAllMemory()*/
348
+                lockScreen()
342
             }
349
             }
343
         }
350
         }
344
         viewModel.resetlResultData.observe(this) {
351
         viewModel.resetlResultData.observe(this) {
630
 
637
 
631
                             3 -> {
638
                             3 -> {
632
                                 //远程socket消息后,回调执行锁定
639
                                 //远程socket消息后,回调执行锁定
633
-                                val appList = AppUtils.GetAppList(this@MainActivity)
634
-                                StrategyUtils.clearMemory(this@MainActivity, appList)
640
+                                /*clearAllMemory()
635
                                 spUtils.setParam(Const.DISABLEPAD, true)
641
                                 spUtils.setParam(Const.DISABLEPAD, true)
636
-                                startIntentActivity(MainActivity().javaClass)
642
+                                startIntentActivity(MainActivity().javaClass)*/
643
+                                lockScreen()
637
                             }
644
                             }
638
 
645
 
639
                             4 -> {
646
                             4 -> {
689
                     withContext(Dispatchers.IO) {
696
                     withContext(Dispatchers.IO) {
690
                         delay(3000)
697
                         delay(3000)
691
                     }
698
                     }
692
-                    /*mBinding.flayoutRoot.visibility = View.GONE*/
693
                     canClickFlag = true
699
                     canClickFlag = true
694
                     mBinding.userinfoLlayout.visibility = View.VISIBLE
700
                     mBinding.userinfoLlayout.visibility = View.VISIBLE
695
                     mBinding.rv.visibility = View.VISIBLE
701
                     mBinding.rv.visibility = View.VISIBLE
696
                 }
702
                 }
697
                 it?.let {
703
                 it?.let {
698
                     //连接不为空,并且应用已安装则跳转应用
704
                     //连接不为空,并且应用已安装则跳转应用
699
-                    /* it.authUrl="com.xhkjedu.xh_control_browser.MainActivity"
700
-                     it.appPackage="com.xhkjedu.xh_control_browser"*/
701
                     LogShow("锁定了吧" + mainLockFlag)
705
                     LogShow("锁定了吧" + mainLockFlag)
702
                     //未锁定则执行跳转,锁定则跳转主页再次锁定并且不在请求接口
706
                     //未锁定则执行跳转,锁定则跳转主页再次锁定并且不在请求接口
703
                     if (!mainLockFlag) {
707
                     if (!mainLockFlag) {
704
-                        //如果地址为空并且请求为true则不跳转,否则跳转
708
+                        //如果地址为空并且请求为true则不跳转,否则跳转,如果现在为空则判断之前是否存在数据,存在则可能走了本地拉起,所以直接清除线程,把拉起清理掉
705
                         try {
709
                         try {
706
-                            Log.d("网络跳转","自动拉起111")
707
                             if ((it.authUrl.isNullOrEmpty() || it.appPackage.isNullOrEmpty()) && it.netSucessFlag) {
710
                             if ((it.authUrl.isNullOrEmpty() || it.appPackage.isNullOrEmpty()) && it.netSucessFlag) {
711
+                                val autoAppBean = spUtils.getFromJson(
712
+                                    Const.AUTOAPPKEY,
713
+                                    AutoAppBean().javaClass
714
+                                ) as AutoAppBean
715
+                                //判断之前是否为空,不为空则清理之前的数据并且杀掉应用
716
+                                if ((!autoAppBean.authUrl.isNullOrEmpty() && !autoAppBean.appPackage.isNullOrEmpty())){
717
+                                    val appList = AppUtils.GetAppList(this@MainActivity)
718
+                                    StrategyUtils.clearMemory(this@MainActivity, appList)
719
+                                }
708
                                 //请求成功但地址为空,不跳转
720
                                 //请求成功但地址为空,不跳转
709
                                 canClickFlag = true
721
                                 canClickFlag = true
710
                                 autoAppFlag = false
722
                                 autoAppFlag = false
843
             } catch (e: Exception) {
855
             } catch (e: Exception) {
844
 
856
 
845
             }
857
             }
858
+
846
             val launchIntent = Intent()
859
             val launchIntent = Intent()
847
             launchIntent.setComponent(
860
             launchIntent.setComponent(
848
                 ComponentName(
861
                 ComponentName(
858
             if (isDestroyFlag) {
871
             if (isDestroyFlag) {
859
                 return
872
                 return
860
             }
873
             }
874
+            //启动之前清除其他应用
875
+            clearAllMemory()
876
+
861
             startActivity(launchIntent)
877
             startActivity(launchIntent)
862
         } catch (e: Exception) {
878
         } catch (e: Exception) {
863
             canClickFlag = true
879
             canClickFlag = true
927
         mBinding.codeenterCv.setOnClickListener {
943
         mBinding.codeenterCv.setOnClickListener {
928
             //如果密码一致,则解锁
944
             //如果密码一致,则解锁
929
             val code = mBinding.lockEt.text.toString()
945
             val code = mBinding.lockEt.text.toString()
930
-            if (code.isNullOrBlank()) {
931
-                return@setOnClickListener
932
-            }
933
-            ManageApplication.getDeviceInfo()?.let {
934
-                viewModel.postPwdDetail(code, it)
935
-            }
946
+            postPwdDetail(code)
936
         }
947
         }
937
         mBinding.loginoutLlayout.setOnClickListener {
948
         mBinding.loginoutLlayout.setOnClickListener {
938
             userBean?.let {
949
             userBean?.let {
941
             }
952
             }
942
         }
953
         }
943
         mBinding.netsetLlayout.setOnClickListener {
954
         mBinding.netsetLlayout.setOnClickListener {
944
-            val intent = Intent(Settings.ACTION_WIFI_SETTINGS)
945
-            intent.putExtra("full_screen", true)
946
-            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
947
-            startActivity(intent)
955
+             goWifiActivity()
948
         }
956
         }
949
         onBackPressedDispatcher.addCallback {
957
         onBackPressedDispatcher.addCallback {
950
             //屏蔽返回键
958
             //屏蔽返回键
955
             }
963
             }
956
         }
964
         }
957
     }
965
     }
966
+    private fun postPwdDetail(code: String) {
967
+        if (!NetworkUtils.isAvailable(this)) {
968
+
969
+            return
970
+        }
971
+        if (code.isNullOrBlank()) {
972
+            return
973
+        }
974
+        ManageApplication.getDeviceInfo()?.let {
975
+            viewModel.postPwdDetail(code, it)
976
+        }
977
+    }
978
+
979
+    private fun goWifiActivity() {
980
+        val intent = Intent(Settings.ACTION_WIFI_SETTINGS)
981
+        intent.putExtra("full_screen", true)
982
+        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
983
+        startActivity(intent)
984
+    }
958
 
985
 
959
     //解锁屏幕
986
     //解锁屏幕
960
     private fun unBindBlock() {
987
     private fun unBindBlock() {
1134
     override fun onResume() {
1161
     override fun onResume() {
1135
         super.onResume()
1162
         super.onResume()
1136
         userBean?.let {
1163
         userBean?.let {
1164
+            goWifiFlag=false
1137
             StrategyUtils.initMainResume()
1165
             StrategyUtils.initMainResume()
1138
             val name = StringBuffer()
1166
             val name = StringBuffer()
1139
             if (!it.schoolName.isNullOrBlank()) {
1167
             if (!it.schoolName.isNullOrBlank()) {
1150
             updateResumeStrategy()
1178
             updateResumeStrategy()
1151
             updatePadInfo()
1179
             updatePadInfo()
1152
             updateMcApp()
1180
             updateMcApp()
1153
-            val appVersionCode = SystemUtil.getAppVersionCode(this, packageName)
1154
-            val appVersionName = SystemUtil.getAppVersionName(this, packageName)
1155
-            mBinding.versionTv.text = if (com.xhkjedu.manageapp.BuildConfig.IS_DEBUG) {
1156
-                "版本 v${appVersionName} (Build ${appVersionCode})测试版"
1157
-            } else {
1158
-                "版本 v${appVersionName} (Build ${appVersionCode})正式版"
1159
-            }
1181
+            setVersionText(mBinding.versionTv)
1160
             if (SystemUtil.isSuEnable()) {
1182
             if (SystemUtil.isSuEnable()) {
1161
                 //root了则调用接口
1183
                 //root了则调用接口
1162
                 val data = LogdOperateBean()
1184
                 val data = LogdOperateBean()
1174
         }
1196
         }
1175
     }
1197
     }
1176
 
1198
 
1199
+    private fun setVersionText(tv: TextView){
1200
+        val appVersionCode = SystemUtil.getAppVersionCode(this, packageName)
1201
+        val appVersionName = SystemUtil.getAppVersionName(this, packageName)
1202
+        tv.text = if (com.xhkjedu.manageapp.BuildConfig.IS_DEBUG) {
1203
+            "版本 v${appVersionName} (Build ${appVersionCode})测试版"
1204
+        } else {
1205
+            "版本 v${appVersionName} (Build ${appVersionCode})正式版"
1206
+        }
1207
+    }
1208
+
1177
     override fun onPause() {
1209
     override fun onPause() {
1178
         super.onPause()
1210
         super.onPause()
1179
-        LogShow("锁定了吧显示弹窗吗222")
1180
-        if (userBean!=null){
1181
-            if (mainLockFlag){
1182
-                showLockDialog(true)
1183
-            }else{
1184
-                showLockDialog(false)
1211
+        if (!goWifiFlag){
1212
+            if (userBean!=null){
1213
+                if (mainLockFlag){
1214
+                    showLockDialog(true)
1215
+                }else{
1216
+                    showLockDialog(false)
1217
+                }
1185
             }
1218
             }
1186
         }
1219
         }
1187
     }
1220
     }
1552
                 }
1585
                 }
1553
             }*/
1586
             }*/
1554
             //没有单点登录所以不再判断
1587
             //没有单点登录所以不再判断
1555
-            LogShow("锁定了吧打开app拉起请求,type==$type")
1588
+            LogShow("锁定了吧打开app拉起请求,type==$type"+(userBean==null))
1556
             userBean?.let {
1589
             userBean?.let {
1557
                 netAutoAppFlag = true
1590
                 netAutoAppFlag = true
1558
                 viewModel.postAutoAppDetail(it.regionid)
1591
                 viewModel.postAutoAppDetail(it.regionid)
2086
         }
2119
         }
2087
     }
2120
     }
2088
 
2121
 
2089
-    private fun showLockDialog(showFlag:Boolean) {
2122
+    private fun showLockDialog(showFlag:Boolean,timeBlockFlag:Boolean?=null,codeBlockFlag:Boolean?=null) {
2123
+        //根据锁定类型,显示不同的文本
2124
+        var codeText=""
2125
+        if (showFlag){
2126
+            if (timeBlockFlag!=null&&codeBlockFlag!=null){
2127
+                if (codeBlockFlag) {
2128
+                    codeText=getString(R.string.locktips)
2129
+                } else if (timeBlockFlag) {
2130
+                    codeText=getString(R.string.timelocktips)
2131
+                }
2132
+            }else{
2133
+                var block = false
2134
+                val strategyBean =
2135
+                    spUtils.getFromJson(Const.STRATEGYBEANKEY, StrategyBean::class.java) as StrategyBean
2136
+                strategyBean?.let { bean ->
2137
+                    //获得是否在使用时间范围
2138
+                    block = StrategyUtils.getPadTimeStrategy(bean)
2139
+                }
2140
+                val param = spUtils.getParam(Const.DISABLEPAD, false) as Boolean
2141
+                if (param) {
2142
+                    codeText=getString(R.string.locktips)
2143
+                } else if (block) {
2144
+                    codeText=getString(R.string.timelocktips)
2145
+                }else{
2146
+                    codeText=getString(R.string.locktips)
2147
+                }
2148
+            }
2149
+        }
2090
          if (lockDialog==null){
2150
          if (lockDialog==null){
2091
              val v = View.inflate(this, R.layout.dialog_locklayout, null)
2151
              val v = View.inflate(this, R.layout.dialog_locklayout, null)
2092
              val lockllayout=v.findViewById<View>(R.id.lock_llayout)
2152
              val lockllayout=v.findViewById<View>(R.id.lock_llayout)
2093
              val codeenter_cv=v.findViewById<View>(R.id.codeenter_cv)
2153
              val codeenter_cv=v.findViewById<View>(R.id.codeenter_cv)
2094
-             val lock_et=v.findViewById<EditText>(R.id.lock_et)
2095
-             val locktips_tv=v.findViewById<TextView>(R.id.locktips_tv)
2096
-             locktips_tv.text="这是弹窗"
2154
+             lockDialogEt=v.findViewById<EditText>(R.id.lock_et)
2155
+             lockDialogTv=v.findViewById<TextView>(R.id.locktips_tv)
2156
+             lockversionTv=v.findViewById<TextView>(R.id.version_tv)
2157
+             lockDialogNetset=v.findViewById<View>(R.id.netset_llayout)
2097
              lockllayout.setOnClickListener {
2158
              lockllayout.setOnClickListener {
2098
                  //限制最多1分钟请求一次策略,
2159
                  //限制最多1分钟请求一次策略,
2099
                  if (lastTimeLong + 1 * 60 * 1000 < System.currentTimeMillis()) {
2160
                  if (lastTimeLong + 1 * 60 * 1000 < System.currentTimeMillis()) {
2101
                      updateAllStrategy()
2162
                      updateAllStrategy()
2102
                  }
2163
                  }
2103
              }
2164
              }
2165
+             lockDialogNetset?.setOnClickListener {
2166
+                 goWifiActivity()
2167
+                 goWifiFlag=true
2168
+                 lockDialog?.dismiss()
2169
+             }
2104
              codeenter_cv.setOnClickListener {
2170
              codeenter_cv.setOnClickListener {
2105
                  //如果密码一致,则解锁
2171
                  //如果密码一致,则解锁
2106
-                 val code = lock_et.text.toString()
2107
-                 if (code.isNullOrBlank()) {
2108
-                     return@setOnClickListener
2109
-                 }
2110
-                 ManageApplication.getDeviceInfo()?.let {
2111
-                     viewModel.postPwdDetail(code, it)
2112
-                 }
2172
+                 val code = lockDialogEt?.text.toString()
2173
+                 postPwdDetail(code)
2113
              }
2174
              }
2114
              lockDialog =
2175
              lockDialog =
2115
                  AlertDialog.Builder(this).create()
2176
                  AlertDialog.Builder(this).create()
2122
                  lockDialog?.window?.setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT)
2183
                  lockDialog?.window?.setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT)
2123
              }
2184
              }
2124
          }
2185
          }
2125
-        LogShow("锁定了吧显示弹窗吗"+showFlag+"|||"+mainLockFlag + "|||" + autoAppFlag)
2186
+        //强制弹窗横屏
2187
+        val attributes = lockDialog?.window?.attributes
2188
+        attributes?.screenOrientation= ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
2189
+        lockDialog?.window?.attributes = attributes
2190
+
2191
+
2126
         lockDialog?.apply {
2192
         lockDialog?.apply {
2193
+            lockDialogEt?.setText("")
2127
             if (showFlag){
2194
             if (showFlag){
2195
+                lockversionTv?.apply {
2196
+                    setVersionText(this)
2197
+                }
2198
+                lockDialogTv?.text=codeText
2128
                 if (!isShowing) {
2199
                 if (!isShowing) {
2129
                     show()
2200
                     show()
2130
                 }
2201
                 }
2493
     }
2564
     }
2494
 
2565
 
2495
     private fun loginOutSucess() {
2566
     private fun loginOutSucess() {
2496
-        val appList = AppUtils.GetAppList(this@MainActivity)
2497
-        StrategyUtils.clearMemory(this@MainActivity, appList)
2567
+        clearAllMemory()
2498
         spUtils.setParam(Const.DISABLEPAD, false)
2568
         spUtils.setParam(Const.DISABLEPAD, false)
2499
         WorkManager.getInstance(this).cancelAllWork()
2569
         WorkManager.getInstance(this).cancelAllWork()
2500
         spUtils.clearData()
2570
         spUtils.clearData()
2505
         finish()
2575
         finish()
2506
     }
2576
     }
2507
 
2577
 
2578
+    //已经确定执行锁定屏幕的回调方法
2579
+    private fun lockScreen(){
2580
+        spUtils.setParam(Const.DISABLEPAD, true)
2581
+        showLockDialog(true)
2582
+        startIntentActivity(MainActivity().javaClass)
2583
+        clearAllMemory()
2584
+    }
2585
+
2586
+    private fun clearAllMemory(){
2587
+        try {
2588
+            //清除所有缓存
2589
+            val appList = AppUtils.GetAppList(this@MainActivity)
2590
+            StrategyUtils.clearMemory(this@MainActivity, appList)
2591
+        } catch (e: Exception) {
2592
+
2593
+        }
2594
+    }
2595
+
2508
 
2596
 
2509
     override fun onDestroy() {
2597
     override fun onDestroy() {
2510
         super.onDestroy()
2598
         super.onDestroy()
2513
             timer?.cancel()
2601
             timer?.cancel()
2514
             timer = null
2602
             timer = null
2515
         }
2603
         }
2516
-        try {
2517
-            //销毁时清除所有缓存
2518
-            val appList = AppUtils.GetAppList(this@MainActivity)
2519
-            StrategyUtils.clearMemory(this@MainActivity, appList)
2520
-        } catch (e: Exception) {
2521
-
2522
-        }
2604
+        //销毁时清除所有缓存
2605
+        clearAllMemory()
2523
         locationClient?.stop()
2606
         locationClient?.stop()
2524
         AppSocket.onDestroy()
2607
         AppSocket.onDestroy()
2525
         DownLoadUtils.removeCallback(this)
2608
         DownLoadUtils.removeCallback(this)

+ 41
- 0
app/src/main/res/layout/dialog_locklayout.xml View File

56
         android:text="@string/locktips"
56
         android:text="@string/locktips"
57
         android:textColor="@color/codetipscolor"
57
         android:textColor="@color/codetipscolor"
58
         android:textSize="17sp" />
58
         android:textSize="17sp" />
59
+   <RelativeLayout
60
+       android:layout_width="match_parent"
61
+       android:layout_height="match_parent">
62
+       <TextView
63
+           android:id="@+id/version_tv"
64
+           android:layout_width="wrap_content"
65
+           android:layout_height="wrap_content"
66
+           android:layout_gravity="bottom|left"
67
+           android:layout_alignParentBottom="true"
68
+           android:layout_marginLeft="10dp"
69
+           android:layout_marginBottom="10dp"
70
+           android:textColor="#253A70"
71
+           android:textSize="8sp" />
72
+
73
+       <LinearLayout
74
+           android:id="@+id/netset_llayout"
75
+           android:layout_width="wrap_content"
76
+           android:layout_height="wrap_content"
77
+           android:layout_alignParentRight="true"
78
+           android:layout_marginRight="10dp"
79
+           android:layout_alignParentBottom="true"
80
+           android:layout_marginBottom="10dp"
81
+           android:paddingLeft="10dp"
82
+           android:paddingTop="10dp"
83
+           android:gravity="center"
84
+           android:orientation="horizontal">
85
+
86
+           <ImageView
87
+               android:layout_width="10dp"
88
+               android:layout_height="10dp"
89
+               android:layout_marginRight="3dp"
90
+               android:src="@drawable/icon_wifiset" />
91
+
92
+           <TextView
93
+               android:layout_width="wrap_content"
94
+               android:layout_height="wrap_content"
95
+               android:text="@string/netset"
96
+               android:textColor="#253A70"
97
+               android:textSize="8sp" />
98
+       </LinearLayout>
99
+   </RelativeLayout>
59
 </LinearLayout>
100
 </LinearLayout>

Loading…
Cancel
Save