Skip to content

A countdown timer composable which can show multiple countdown based on the provided list

License

Notifications You must be signed in to change notification settings

raipankaj/countdowntimer

Repository files navigation

Jetpack Compose Countdown Timer

A Jetpack Compose countdown timer library that allows you to easily add a customizable countdown timer to your Android app.

Features

  • Change the color of the dialer background
  • Set the color of the progress indicator to match your app's theme
  • Change the color of the dialer border
  • Display the countdown time in the center of the dialer
  • Display a label text just below the time

    Installation

    Add the following dependency to your app's build.gradle file:
    allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }
    
    dependencies {
        implementation 'com.github.raipankaj:countdowntimer:1.0.2'
    }

    Usage

    To use the countdown timer in your app, simply add the CountDownTimer composable to your Jetpack Compose layout:
    CountDownTimer(
        actionList = listOf(
            Action(45.seconds.inWholeMilliseconds, "Inhale"),
            Action(30.seconds.inWholeMilliseconds, "Exhale"),
            Action(45.seconds.inWholeMilliseconds, "Inhale"),
            Action(30.seconds.inWholeMilliseconds, "Exhale"),
            Action(45.seconds.inWholeMilliseconds, "Inhale"),
            Action(30.seconds.inWholeMilliseconds, "Exhale"),
        ),
        dialerSize = 240.dp,
        dialerBackgroundColor = MaterialTheme.colorScheme.primary,
        dialerProgressColor = Color.White,
        dialerBorderColor = MaterialTheme.colorScheme.tertiary,
        onTimerExpired = {
    
        }
    )

    This creates a CountDownTimer instance with the following settings:

  • actionList: A list of Action objects, each representing a time interval and a label to display during that interval.
  • dialerSize: The size of the countdown timer dialer.
  • dialerBackgroundColor: The background color of the countdown timer dialer.
  • dialerProgressColor: The color of the progress indicator on the countdown timer dialer.
  • dialerBorderColor: The color of the border around the countdown timer dialer.
  • onTimerExpired: A lambda function to call when the countdown timer expires. This is where you can add any logic to handle the timer expiration event.

    Example

    Here's an example of how to use the countdown timer in a Jetpack Compose layout:
    @Composable
    fun ExerciseTimer() {
        CountDownTimer(
            actionList = listOf(
                Action(45.seconds.inWholeMilliseconds, "Inhale"),
                Action(30.seconds.inWholeMilliseconds, "Exhale"),
                Action(45.seconds.inWholeMilliseconds, "Inhale"),
                Action(30.seconds.inWholeMilliseconds, "Exhale"),
                Action(45.seconds.inWholeMilliseconds, "Inhale"),
                Action(30.seconds.inWholeMilliseconds, "Exhale"),
            ),
            dialerSize = 240.dp,
            dialerBackgroundColor = MaterialTheme.colorScheme.primary,
            dialerProgressColor = Color.White,
            dialerBorderColor = MaterialTheme.colorScheme.tertiary,
            onTimerExpired = {
    
            }
        )
    }

    Demo
    Action with two duration - 10 seconds, inhale and 10 seconds, exhale

    License

    This library is licensed under the MIT License. See the LICENSE file for details.
  • About

    A countdown timer composable which can show multiple countdown based on the provided list

    Resources

    License

    Stars

    Watchers

    Forks

    Packages

    No packages published

    Languages