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,6 +20,7 @@ import android.graphics.drawable.Drawable
20 20
 import android.net.ConnectivityManager
21 21
 import android.os.Build
22 22
 import android.provider.Settings
23
+import android.util.TypedValue
23 24
 import android.view.MotionEvent
24 25
 import android.view.View
25 26
 import android.view.View.OnClickListener
@@ -130,8 +131,9 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
130 131
     private var accountDialog:CustomDialog?=null
131 132
     private var quitAccountDialog:CustomDialog?=null
132 133
     private var changeCodeDialog:CustomDialog?=null
133
-
134 134
     private var tipsDialog:CustomDialog?=null
135
+    private var systemDialog:AlertDialog?=null
136
+
135 137
     //创建应用卸载集合,方便获得应用信息
136 138
     private val unInstallAppList= arrayListOf<AppInfo>()
137 139
     //标记是否可以点击啊
@@ -151,6 +153,8 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
151 153
     //标记上次点击时间
152 154
     private var lastChangeTime=0L
153 155
 
156
+    private var sysMsgList= arrayListOf<SocketMsgBean>()
157
+
154 158
     override fun getBinding() = ActivityMainBinding.inflate(layoutInflater)
155 159
 
156 160
     @SuppressLint("CheckResult")
@@ -1490,33 +1494,81 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(),Download
1490 1494
      * 系统级别的通知
1491 1495
      */
1492 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 1497
         try {
1498 1498
             val msgBean = GsonUtils.parseJsonWithGson(
1499 1499
                 msg, SocketMsgBean().javaClass
1500 1500
             ) as SocketMsgBean
1501
-            titleTv.text = msgBean.title
1502
-            contentTv.text = msgBean.content
1501
+            sysMsgList.add(msgBean)
1503 1502
         } catch (e: Exception) {
1504 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 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,6 +33,8 @@
33 33
             <androidx.appcompat.widget.LinearLayoutCompat
34 34
                 android:layout_width="match_parent"
35 35
                 android:layout_height="match_parent"
36
+                android:layout_marginLeft="21dp"
37
+                android:layout_marginRight="21dp"
36 38
                 android:orientation="vertical">
37 39
 
38 40
                 <TextView
@@ -49,7 +51,6 @@
49 51
                     android:layout_width="match_parent"
50 52
                     android:layout_height="wrap_content"
51 53
                     android:layout_marginTop="10dp"
52
-                    android:gravity="center"
53 54
                     android:textColor="#253A70"
54 55
                     android:textSize="14sp" />
55 56
             </androidx.appcompat.widget.LinearLayoutCompat>

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

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

Loading…
Cancel
Save