Skip to content

Instantly share code, notes, and snippets.

@maulikhirani
maulikhirani / TextWithHighlights.kt
Created January 17, 2024 05:10
Highlight the words between curly braces
private fun getTextWithHighlights(text: String): CharSequence {
// Initialize spannable string without any formatting
val spannableString = SpannableStringBuilder(text)
// Regex to find words between curly braces i.e {test}
val regex = Regex("\\{(.*?)\\}")
// List of index for the curly braces which needs to be removed after formatting
val symbolsToRemoveIndices = mutableListOf<Int>()
// iterate over all the words within curly braces
regex.findAll(spannableString).forEach {
@maulikhirani
maulikhirani / BoxShadow.kt
Created July 15, 2023 13:25
Helper extension to use drop shadow in Jetpack Compose
import android.graphics.BlurMaskFilter
import android.graphics.ColorMatrix
import android.graphics.ColorMatrixColorFilter
import androidx.compose.runtime.Stable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.drawWithCache
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Canvas
import androidx.compose.ui.graphics.ClipOp
@maulikhirani
maulikhirani / DateTimeDurationHelper.kt
Last active February 3, 2021 06:43
Format Date-Time Duration in words with Kotlin
/**
* Number of milliseconds in a standard second.
*/
const val MILLIS_PER_SECOND: Long = 1000
/**
* Number of milliseconds in a standard minute.
*/
const val MILLIS_PER_MINUTE = 60 * MILLIS_PER_SECOND