### Add Dependency to build.gradle.kts Source: https://github.com/d4viddf/hyperisland-toolkit/blob/main/README.md Add the HyperIsland ToolKit dependency to your app-level build.gradle.kts file to start using the library. ```kotlin dependencies { implementation("io.github.d4viddf:hyperisland_kit:0.4.0") } ``` -------------------------------- ### BroadcastReceiver Implementation Source: https://github.com/d4viddf/hyperisland-toolkit/wiki/Handling-Actions-&-Intents Example of a BroadcastReceiver for handling actions that do not open an activity. Implement your custom logic within the onReceive method. ```kotlin class NotificationActionReceiver : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { // Your logic here } } ``` -------------------------------- ### Correctly Building Resource Bundle and JSON Param Source: https://github.com/d4viddf/hyperisland-toolkit/wiki/Frequently-Asked-Questions-(FAQ) Use `buildResourceBundle()` and `buildJsonParam()` for notification actions. Adding all extras to `addExtras()` alone is insufficient. ```kotlin val resourceBundle = builder.buildResourceBundle() val jsonParam = builder.buildJsonParam() val notification = NotificationCompat.Builder(context, CHANNEL_ID) .addExtras(resourceBundle) // Step 1 .build() notification.extras.putString("miui.focus.param", jsonParam) // Step 2 ``` -------------------------------- ### Build a Basic HyperIsland Notification Source: https://github.com/d4viddf/hyperisland-toolkit/wiki/Getting-Started Construct a HyperIsland notification by defining resources, building the resource bundle and JSON parameter, creating the base notification, and finally adding the JSON parameter. Send the notification using NotificationManagerCompat. ```kotlin import androidx.core.app.NotificationCompat import io.github.d4viddf.hyperisland_kit.HyperIslandNotification import io.github.d4viddf.hyperisland_kit.HyperPicture import io.github.d4viddf.hyperisland_kit.models.ImageTextInfoLeft import io.github.d4viddf.hyperisland_kit.models.PicInfo import io.github.d4viddf.hyperisland_kit.models.TextInfo // --- 1. Define your resources --- const val PIC_KEY_APP = "pic.app.icon" val appPicture = HyperPicture(PIC_KEY_APP, context, R.drawable.ic_my_app_icon) // Create the builder val hyperIslandBuilder = HyperIslandNotification .Builder(context, "myDemoApp", "My App is running") // 1. Set the expanded panel (in the notification shade) .setBaseInfo( title = "App is Running", content = "Tap to open", pictureKey = PIC_KEY_APP ) // 2. Set the expanded island (when you tap the small island) .setBigIslandInfo( ImageTextInfoLeft( picInfo = PicInfo(type = 1, pic = PIC_KEY_APP), textInfo = TextInfo(title = "App", content = "Running") ) ) // 3. Set the summary island (the small pill) .setSmallIslandIcon(PIC_KEY_APP) // 4. Add all pictures used .addPicture(appPicture) // --- 2. Build the two separate components --- val resourceBundle = hyperIslandBuilder.buildResourceBundle() val jsonParam = hyperIslandBuilder.buildJsonParam() // --- 3. Create the notification --- val notification = NotificationCompat.Builder(context, YOUR_CHANNEL_ID) .setSmallIcon(R.drawable.ic_stat_notification) .setContentTitle("App is Running") .setContentText("Tap to open.") // Add the resource bundle (Actions + Pics) here .addExtras(resourceBundle) .build() // --- 4. (CRITICAL) Add the JSON parameter AFTER building --- notification.extras.putString("miui.focus.param", jsonParam) // --- 5. Send the notification --- NotificationManagerCompat.from(context).notify(123, notification) ``` -------------------------------- ### Create Icon Button HyperAction Source: https://github.com/d4viddf/hyperisland-toolkit/wiki/Handling-Actions-&-Intents Use this to create a standard button with an icon and optional text. Ensure the correct PendingIntent type (1 for Activity) is provided. ```kotlin val openAppIntent = PendingIntent.getActivity( context, 0, Intent(context, MainActivity::class.java), PendingIntent.FLAG_IMMUTABLE ) val appOpenAction = HyperAction( key = "my_app_open_key", title = "Open App", context = context, drawableRes = R.drawable.ic_open_in_new, // Your icon pendingIntent = openAppIntent, actionIntentType = 1 // 1 for Activity ) ``` -------------------------------- ### Create Text-Only Button HyperAction Source: https://github.com/d4viddf/hyperisland-toolkit/wiki/Handling-Actions-&-Intents This snippet creates a button with only text, using a placeholder icon. It utilizes PendingIntent.getBroadcast (type 2) and allows for an optional background color. ```kotlin val closeIntent = PendingIntent.getBroadcast( context, 1, Intent(context, MyReceiver::class.java).setAction("CLOSE_ACTION"), PendingIntent.FLAG_IMMUTABLE ) val closeAction = HyperAction( key = "my_close_key", title = "Close", // The text to show pendingIntent = closeIntent, actionIntentType = 2, // 2 for Broadcast actionBgColor = "#FF3B30" // Optional: set a background color ) ``` -------------------------------- ### Create Progress Button HyperAction Source: https://github.com/d4viddf/hyperisland-toolkit/wiki/Handling-Actions-&-Intents Generates a button with a circular progress ring. The title is ignored, and it uses PendingIntent.getBroadcast (type 2). Configure progress and color as needed. ```kotlin val stopIntent = PendingIntent.getBroadcast( context, 2, Intent(context, MyReceiver::class.java).setAction("STOP_ACTION"), PendingIntent.FLAG_IMMUTABLE ) val stopAction = HyperAction( key = "my_stop_key", title = null, // Title is ignored for progress buttons context = context, drawableRes = R.drawable.ic_stop, // Your icon pendingIntent = stopIntent, actionIntentType = 2, // 2 for Broadcast isProgressButton = true, // This makes it a progress button progress = 40, progressColor = "#FFC700" ) ``` -------------------------------- ### Add HyperIsland Dependency Source: https://github.com/d4viddf/hyperisland-toolkit/wiki/Getting-Started Add the HyperIsland library dependency to your Gradle build file. Replace VERSION with the latest release number. ```gradle implementation("io.github.d4viddf:hyperisland-kit:VERSION") ``` -------------------------------- ### Multi-Action Notification Source: https://github.com/d4viddf/hyperisland-toolkit/wiki/Notification-Types-&-Examples Combines multiple buttons, including a progress button and a text-only button, in a notification. Assumes the two-step build process. ```Kotlin // --- 1. Define Keys --- const val ACTION_KEY_STOP = "action.stop" const val ACTION_KEY_CLOSE = "action.close" const val PIC_KEY_APP = "pic.app" // --- 2. Create PendingIntents (Broadcast) --- val stopIntent = createBroadcastIntent(context, 1, "STOP_ACTION", ...) val closeIntent = createBroadcastIntent(context, 2, "CLOSE_ACTION", ...) // --- 3. Create HyperActions --- val stopAction = HyperAction( key = ACTION_KEY_STOP, title = null, // Progress button context = context, drawableRes = R.drawable.ic_stop, pendingIntent = stopIntent, actionIntentType = 2, // 2 for Broadcast isProgressButton = true, progress = 40 ) val closeAction = HyperAction( key = ACTION_KEY_CLOSE, title = "Close", // Text-only button pendingIntent = closeIntent, actionIntentType = 2, // 2 for Broadcast actionBgColor = "#FF3B30" ) val appPicture = HyperPicture(PIC_KEY_APP, context, R.drawable.ic_app_icon) // --- 4. Build Notification --- val builder = HyperIslandNotification .Builder(context, "demoApp", "Multi-Action") .setChatInfo( title = "Multi-Action Demo", content = "Stop or Close", pictureKey = PIC_KEY_APP, // --- Pass BOTH keys here --- actionKeys = listOf(ACTION_KEY_STOP, ACTION_KEY_CLOSE) ) .setBigIslandInfo( ImageTextInfoLeft(...) // Simple info panel ) .setSmallIslandIcon(PIC_KEY_APP) .addAction(stopAction) // Add first action .addAction(closeAction) // Add second action .addPicture(appPicture) // ... build and send notification ... ``` -------------------------------- ### Register BroadcastReceiver in AndroidManifest.xml Source: https://github.com/d4viddf/hyperisland-toolkit/wiki/Handling-Actions-&-Intents Shows how to register a BroadcastReceiver in the AndroidManifest.xml file, including setting the receiver name and defining an intent filter with a specific action. ```xml ``` -------------------------------- ### Countdown Timer Notification Source: https://github.com/d4viddf/hyperisland-toolkit/wiki/Notification-Types-&-Examples Displays a countdown timer in the chatInfo panel and the bigIsland. Assumes the two-step build process. ```kotlin val countdownTime = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(15) val countdownTimer = TimerInfo( timerType = -1, // -1 for countdown timerWhen = countdownTime, timerTotal = System.currentTimeMillis(), timerSystemCurrent = System.currentTimeMillis() ) val pic = HyperPicture("pic.timer", context, R.drawable.ic_timer) val builder = HyperIslandNotification .Builder(context, "demoApp", "Timer") .setChatInfo( title = "Pizza in oven", timer = countdownTimer, pictureKey = "pic.timer" ) .setBigIslandCountdown(countdownTime, "pic.timer") .setSmallIslandIcon("pic.timer") .addPicture(pic) // ... build and send notification ... ``` -------------------------------- ### Circular Progress Bar Notification Source: https://github.com/d4viddf/hyperisland-toolkit/wiki/Notification-Types-&-Examples Displays a circular progress bar on the island itself. Assumes the two-step build process. ```Kotlin val pic = HyperPicture("pic.download", context, R.drawable.ic_download) val builder = HyperIslandNotification .Builder(context, "demoApp", "Downloading") .setChatInfo( title = "Downloading...", content = "75% complete", pictureKey = "pic.download" ) .setBigIslandProgressCircle( pictureKey = "pic.download", title = "Downloading", progress = 75, color = "#34C759" ) .setSmallIslandCircularProgress( pictureKey = "pic.download", progress = 75, color = "#34C759" ) .addPicture(pic) // ... build and send notification ... ``` -------------------------------- ### Linear Progress Bar Notification Source: https://github.com/d4viddf/hyperisland-toolkit/wiki/Notification-Types-&-Examples Adds a linear progress bar to the chatInfo panel. Assumes the two-step build process. ```Kotlin val pic = HyperPicture("pic.upload", context, R.drawable.ic_upload) val builder = HyperIslandNotification .Builder(context, "demoApp", "Uploading") .setChatInfo( title = "Uploading file...", content = "60% complete", pictureKey = "pic.upload" ) .setProgressBar(60, "#007AFF") // Set progress and color .setBigIslandInfo( ImageTextInfoLeft(...) // A simple info panel ) .setSmallIslandIcon("pic.upload") .addPicture(pic) // ... build and send notification ... ``` -------------------------------- ### Check HyperIsland Support Source: https://github.com/d4viddf/hyperisland-toolkit/wiki/Getting-Started Before sending a HyperIsland notification, verify if the user's device supports the feature. If not, fall back to a standard Android notification. ```kotlin import io.github.d4viddf.hyperisland_kit.HyperIslandNotification if (!HyperIslandNotification.isSupported(context)) { // This device doesn't support HyperIsland. // Send a standard Android notification instead. return } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.