From 62ca31e2fba401767bf0326da4771228c7a10fd1 Mon Sep 17 00:00:00 2001 From: ajp_anton Date: Thu, 23 Jul 2026 11:53:11 +0000 Subject: [PATCH] Expand notification test helper scenarios --- .../ajpanton/notificationlog/helper/MainActivity.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test-helper/src/main/java/se/ajpanton/notificationlog/helper/MainActivity.kt b/test-helper/src/main/java/se/ajpanton/notificationlog/helper/MainActivity.kt index 693e4af..ae943d5 100644 --- a/test-helper/src/main/java/se/ajpanton/notificationlog/helper/MainActivity.kt +++ b/test-helper/src/main/java/se/ajpanton/notificationlog/helper/MainActivity.kt @@ -8,7 +8,16 @@ import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() { private val manager by lazy { getSystemService(NotificationManager::class.java) } - override fun onCreate(state: Bundle?) { super.onCreate(state); manager.createNotificationChannel(NotificationChannel("test", "Test", NotificationManager.IMPORTANCE_DEFAULT)); setContentView(LinearLayout(this).apply { orientation=LinearLayout.VERTICAL; listOf("Post text" to { post("Text message") }, "Edit text" to { post("Edited message") }, "Post image" to { image() }, "Cancel" to { manager.cancel(1) }).forEach { (label, action) -> addView(Button(this@MainActivity).apply { text=label; setOnClickListener { action() } }) } }) } + override fun onCreate(state: Bundle?) { super.onCreate(state); manager.createNotificationChannel(NotificationChannel("test", "Test", NotificationManager.IMPORTANCE_DEFAULT)); setContentView(LinearLayout(this).apply { orientation=LinearLayout.VERTICAL; listOf("Post text" to { post("Text message") }, "Edit text" to { post("Edited message") }, "Post messaging" to { messaging() }, "Post image" to { image() }, "Post dismissible" to { dismissible() }, "Cancel text" to { manager.cancel(1) }).forEach { (label, action) -> addView(Button(this@MainActivity).apply { text=label; setOnClickListener { action() } }) } }) } private fun post(text:String)=manager.notify(1, Notification.Builder(this,"test").setSmallIcon(android.R.drawable.ic_dialog_info).setContentTitle("Helper").setContentText(text).build()) + private fun messaging() { + val me = android.app.Person.Builder().setName("Me").build() + val alice = android.app.Person.Builder().setName("Alice").build() + val style = Notification.MessagingStyle(me) + .addMessage("Hello from Alice", 1, alice) + .addMessage("A reply from me", 2, null as android.app.Person?) + manager.notify(3, Notification.Builder(this, "test").setSmallIcon(android.R.drawable.ic_dialog_email).setStyle(style).build()) + } private fun image(){ val b=Bitmap.createBitmap(20,20,Bitmap.Config.ARGB_8888).apply{eraseColor(0xffff0000.toInt())}; manager.notify(2,Notification.Builder(this,"test").setSmallIcon(android.R.drawable.ic_menu_gallery).setStyle(Notification.BigPictureStyle().bigPicture(b)).build()) } + private fun dismissible()=manager.notify(4, Notification.Builder(this,"test").setSmallIcon(android.R.drawable.ic_dialog_info).setContentTitle("Dismiss me manually").setContentText("Swipe this notification away to test user dismissal.").setAutoCancel(true).build()) }