Browse Source

1.系统提示增加消息集合,可以按顺序展示。

20241218TB223FC(测试jar包)
wangwanlei 8 months ago
parent
commit
9fc2400f58

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

20
 import android.net.ConnectivityManager
20
 import android.net.ConnectivityManager
21
 import android.os.Build
21
 import android.os.Build
22
 import android.provider.Settings
22
 import android.provider.Settings
23
+import android.util.TypedValue
23
 import android.view.MotionEvent
24
 import android.view.MotionEvent
24
 import android.view.View
25
 import android.view.View
25
 import android.view.View.OnClickListener
26
 import android.view.View.OnClickListener
130
     private var accountDialog:CustomDialog?=null
131
     private var accountDialog:CustomDialog?=null
131
     private var quitAccountDialog:CustomDialog?=null
132
     private var quitAccountDialog:CustomDialog?=null
132
     private var changeCodeDialog:CustomDialog?=null
133
     private var changeCodeDialog:CustomDialog?=null
133
-
134
     private var tipsDialog:CustomDialog?=null
134
     private var tipsDialog:CustomDialog?=null
135
+    private var systemDialog:AlertDialog?=null
136
+
135
     //创建应用卸载集合,方便获得应用信息
137
     //创建应用卸载集合,方便获得应用信息
136
     private val unInstallAppList= arrayListOf<AppInfo>()
138
     private val unInstallAppList= arrayListOf<AppInfo>()
137
     //标记是否可以点击啊
139
     //标记是否可以点击啊
151
     //标记上次点击时间
153
     //标记上次点击时间
152
     private var lastChangeTime=0L
154
     private var lastChangeTime=0L
153
 
155
 
156
+    private var sysMsgList= arrayListOf<SocketMsgBean>()
157
+
154
     override fun getBinding() = ActivityMainBinding.inflate(layoutInflater)
158
     override fun getBinding() = ActivityMainBinding.inflate(layoutInflater)
155
 
159
 
156
     @SuppressLint("CheckResult")
160
     @SuppressLint("CheckResult")
1490
      * 系统级别的通知
1494
      * 系统级别的通知
1491
      */
1495
      */
1492
     private fun showSystemNoticeDialog(msg: String) {
1496
     private fun showSystemNoticeDialog(msg: String) {
1493
-        val v=View.inflate(this,R.layout.layout_sys_notice_dialog,null)
1494
-        val closeBtn = v.findViewById<Button>(R.id.dialog_close_btn)
1495
-        val titleTv = v.findViewById<TextView>(R.id.dialog_title_tv)
1496
-        val contentTv = v.findViewById<TextView>(R.id.dialog_content_tv)
1497
         try {
1497
         try {
1498
             val msgBean = GsonUtils.parseJsonWithGson(
1498
             val msgBean = GsonUtils.parseJsonWithGson(
1499
                 msg, SocketMsgBean().javaClass
1499
                 msg, SocketMsgBean().javaClass
1500
             ) as SocketMsgBean
1500
             ) as SocketMsgBean
1501
-            titleTv.text = msgBean.title
1502
-            contentTv.text = msgBean.content
1501
+            sysMsgList.add(msgBean)
1503
         } catch (e: Exception) {
1502
         } catch (e: Exception) {
1504
             LogShow("解析失败" + e.toString())
1503
             LogShow("解析失败" + e.toString())
1505
         }
1504
         }
1506
-
1507
-        val dialog =
1508
-            AlertDialog.Builder(this).create()
1509
-        dialog.setView(v)
1510
-        dialog.setCancelable(false)
1511
-        if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O){
1512
-            dialog.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
1513
-            dialog.window?.setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY)
1505
+        if (systemDialog==null){
1506
+            val v=View.inflate(this,R.layout.layout_sys_notice_dialog,null)
1507
+            val closeBtn = v.findViewById<Button>(R.id.dialog_close_btn)
1508
+            val titleTv = v.findViewById<TextView>(R.id.dialog_title_tv)
1509
+            val contentTv = v.findViewById<TextView>(R.id.dialog_content_tv)
1510
+            if (sysMsgList.size>0){
1511
+                val msgBean = sysMsgList[0]
1512
+                titleTv.text = msgBean.title
1513
+                contentTv.text = msgBean.content
1514
+            }
1515
+            if (sysMsgList.size>1){
1516
+                closeBtn.text = getString(R.string.nexttips)
1517
+            }else{
1518
+                closeBtn.text = getString(R.string.close)
1519
+            }
1520
+            closeBtn.setOnClickListener {
1521
+                if (sysMsgList.size>0){
1522
+                    sysMsgList.removeAt(0)
1523
+                    if (sysMsgList.size>0){
1524
+                        val msgBean = sysMsgList[0]
1525
+                        titleTv.text = msgBean.title
1526
+                        contentTv.text = msgBean.content
1527
+                    }
1528
+                    if (sysMsgList.size==1){
1529
+                        closeBtn.text = getString(R.string.close)
1530
+                    }
1531
+                    if (sysMsgList.size==0){
1532
+                        systemDialog?.dismiss()
1533
+                    }
1534
+                }else{
1535
+                    systemDialog?.dismiss()
1536
+                }
1537
+            }
1538
+            systemDialog =
1539
+                AlertDialog.Builder(this).create()
1540
+            systemDialog?.setView(v)
1541
+            systemDialog?.setCancelable(false)
1542
+            if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O){
1543
+                systemDialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
1544
+                systemDialog?.window?.setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY)
1545
+            }else{
1546
+                systemDialog?.window?.setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT)
1547
+            }
1548
+            systemDialog?.show()
1549
+            systemDialog?.window?.let { window ->
1550
+                val attributes = window.attributes
1551
+                 attributes.width=TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,446f,resources.displayMetrics).toInt()
1552
+                 attributes.height=TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,412f,resources.displayMetrics).toInt()
1553
+                 window.attributes=attributes
1554
+            }
1514
         }else{
1555
         }else{
1515
-            dialog.window?.setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT)
1516
-        }
1517
-        dialog.show()
1518
-        closeBtn.setOnClickListener {
1519
-            dialog.dismiss()
1556
+            val closeBtn =systemDialog?.findViewById<Button>(R.id.dialog_close_btn)
1557
+            val titleTv = systemDialog?.findViewById<TextView>(R.id.dialog_title_tv)
1558
+            val contentTv =systemDialog?.findViewById<TextView>(R.id.dialog_content_tv)
1559
+            if (sysMsgList.size>0){
1560
+                val msgBean = sysMsgList[0]
1561
+                titleTv!!.text = msgBean.title
1562
+                contentTv!!.text = msgBean.content
1563
+            }
1564
+            if (sysMsgList.size>1){
1565
+                closeBtn!!.text = getString(R.string.nexttips)
1566
+            }else{
1567
+                closeBtn!!.text = getString(R.string.close)
1568
+            }
1569
+           if (systemDialog?.isShowing == false){
1570
+              systemDialog?.show()
1571
+           }
1520
         }
1572
         }
1521
     }
1573
     }
1522
 
1574
 

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

33
             <androidx.appcompat.widget.LinearLayoutCompat
33
             <androidx.appcompat.widget.LinearLayoutCompat
34
                 android:layout_width="match_parent"
34
                 android:layout_width="match_parent"
35
                 android:layout_height="match_parent"
35
                 android:layout_height="match_parent"
36
+                android:layout_marginLeft="21dp"
37
+                android:layout_marginRight="21dp"
36
                 android:orientation="vertical">
38
                 android:orientation="vertical">
37
 
39
 
38
                 <TextView
40
                 <TextView
49
                     android:layout_width="match_parent"
51
                     android:layout_width="match_parent"
50
                     android:layout_height="wrap_content"
52
                     android:layout_height="wrap_content"
51
                     android:layout_marginTop="10dp"
53
                     android:layout_marginTop="10dp"
52
-                    android:gravity="center"
53
                     android:textColor="#253A70"
54
                     android:textColor="#253A70"
54
                     android:textSize="14sp" />
55
                     android:textSize="14sp" />
55
             </androidx.appcompat.widget.LinearLayoutCompat>
56
             </androidx.appcompat.widget.LinearLayoutCompat>

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

17
     <string name="passcode">密码</string>
17
     <string name="passcode">密码</string>
18
     <string name="exit">退出</string>
18
     <string name="exit">退出</string>
19
     <string name="close">关闭</string>
19
     <string name="close">关闭</string>
20
+    <string name="nexttips">下一条</string>
20
     <string name="clear">清除缓存</string>
21
     <string name="clear">清除缓存</string>
21
     <string name="speed">一键加速</string>
22
     <string name="speed">一键加速</string>
22
     <string name="rotation">自动旋转</string>
23
     <string name="rotation">自动旋转</string>

Loading…
Cancel
Save