Skip to content

Instantly share code, notes, and snippets.

View JyotimoyKashyap's full-sized avatar

Jyotimoy Kashyap JyotimoyKashyap

View GitHub Profile
@JyotimoyKashyap
JyotimoyKashyap / ProgressButton.kt
Created June 27, 2025 05:52
Progress Button Implementation in Jetpack Compose
/**
* A custom progress button Composable that displays an animated fill
* from left to right, contained within the button's specified shape.
*
* This button behaves like a standard Material Design button but includes
* a visual progress indicator that animates its width from 0% to 100%
* over a given duration. The progress animation is always clipped to match
* the button's corners, ensuring a seamless visual effect.
*
* Example Usage:
@Composable
fun StackedBarChart(
data: List<Float>,
colors: List<Color>,
) {
val proportions = data.map { it.div(data.sum()) }.filter { it > 0 }.toMutableStateList()
val oldValues = rememberSaveable { mutableListOf<Float>() }
val animatedProportions = List(proportions.size) { remember { Animatable(0f) } }
val visibility = remember { mutableStateOf(false) }
@JyotimoyKashyap
JyotimoyKashyap / DropdownItemSelector.kt
Last active April 13, 2025 06:05
Custom Reusable Widgets
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun <T : DropdownMenuItem> DropdownItemSelector(
preSelectedIndex: Int = 0,
dropdownLabel: String,
menuItemList: List<T>,
onMenuItemChange: (T) -> Unit = {}
) {
var dropDownExpanded by remember { mutableStateOf(false) }
var selectedMenuItem by remember { mutableStateOf(menuItemList.first()) }
@Composable
fun IconItemView(iconItem: IconItem, onIconSelected: (String, ImageVector) -> Unit) {
Column(
modifier = Modifier
.padding(MaterialTheme.spacing.small)
.wrapContentSize()
) {
iconItem.image?.let {
Icon(
imageVector = it,
@JyotimoyKashyap
JyotimoyKashyap / IconPicker.kt
Created April 12, 2025 07:30
Search Bar for Icons
@Composable
fun SearchBar(onTextChange: (String) -> Unit = {}) {
val searchString = remember { mutableStateOf("") }
Row {
OutlinedTextField(
value = searchString.value,
onValueChange = {
searchString.value = it
onTextChange(it)
},
@Composable
fun IconPicker(
onIconSelected: (String, ImageVector) -> Unit,
iconPickerHeight: Float = 1f,
) {
val icons = Util.iconUtil.getListOfIcons(
iconNameList = stringArrayResource(R.array.icon_names)
.toList()
)
val searchText = remember { mutableStateOf("") }
data class IconItem(
val id: String,
val image: ImageVector? = null,
)
@JyotimoyKashyap
JyotimoyKashyap / IconUtil.kt
Created April 12, 2025 07:22
IconUtil Object Class
object IconUtil {
/**
* @param iconId name of the icon from the Icons.Filled class
* @return [ImageVector] object
*/
fun createImageVector(iconId: String): ImageVector {
try {
val className = "androidx.compose.material.icons.filled.${iconId}Kt"
val cl = Class.forName(className)
val method = cl.declaredMethods.first()
@JyotimoyKashyap
JyotimoyKashyap / IconUtil.kt
Last active April 12, 2025 07:21
Icon Picker Code
object IconUtil {
/**
* @param iconId name of the icon from the Icons.Filled class
* @return [ImageVector] object
*/
fun createImageVector(iconId: String): ImageVector {
try {
val className = "androidx.compose.material.icons.filled.${iconId}Kt"
val cl = Class.forName(className)
val method = cl.declaredMethods.first()
@JyotimoyKashyap
JyotimoyKashyap / LiveGraphPlotView.kt
Last active January 28, 2023 12:06
This gist is an example of handling Surface View in Android in Kotlin in a better way
class LiveGraphPlotView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null
) : SurfaceView(context, attrs), SurfaceHolder.Callback, Runnable {
private lateinit var mCanvas: Canvas
private lateinit var mSurfaceHolder: SurfaceHolder
private var mWidth: Int = 0
private var mHeight: Int = 0
private var mRunning: Boolean = false