SkillAgentSearch skills...

HappyTimer

This is an android lib which helps you to implement Timer in your android app. This is 100% written in Kotlin.

Install / Use

/learn @happysingh23828/HappyTimer

README

HappyTimer- An Android Timer UI Library

platform API License

<p align="center"> <center><img width="100%%" src="screenshots/Happytimer.png"></a></center> </p>

Prerequisites

Add this in your root build.gradle file (not your module build.gradle file):

allprojects {
	repositories {
		...
		maven { url "https://jitpack.io" }
	}
}

Dependency

Add this to your module's build.gradle file (make sure the version matches the JitPack badge above):

dependencies {
	...
	implementation 'com.github.happysingh23828:HappyTimer:1.0.1'
}

Demo Video

Click here to see demo video

Usage

In this library all the UI widgets are using a common HappyTimer class for implementing timer.

HappyTimer.kt

        //Initialize Timer with seconds
        val happyTimer = HappyTimer(60)
        
        //set OnTickListener for getting updates on time. [Optional]
        happyTimer.setOnTickListener(object :HappyTimer.OnTickListener{

            //OnTick
            override fun onTick(completedSeconds: Int, remainingSeconds: Int) {

            }

            //OnTimeUp
            override fun onTimeUp() {

            }
        })

        //set OnStateChangeListener [RUNNING, FINISHED, PAUSED, RESUMED, UNKNOWN, RESET, STOPPED] [Optional]
        happyTimer.setOnStateChangeListener(object : HappyTimer.OnStateChangeListener{
            override fun onStateChange(state: HappyTimer.State, completedSeconds: Int, remainingSeconds: Int) {
                // write your code here for State Changes
            }
        })

        //Start Timer
        happyTimer.start()

        //Pause Timer
        happyTimer.pause()

        //Resume Timer
        happyTimer.resume()

        //Stop Timer
        happyTimer.stop()

        //Reset Timer
        happyTimer.resetTimer()

Note : To avoid MemoryLeaks always stop the timer in onDestroy().

CircularCountDownView

Layout(XML)

<com.androchef.happytimer.countdowntimer.CircularCountDownView
            android:id="@+id/circularCountDownView"
            android:layout_width="200dp"
            android:layout_height="200dp"
            app:stroke_foreground_color="@color/colorLightBlue"
            app:stroke_background_color="@color/colorPrimaryDark"
            app:stroke_background_thickness="31dp"
            app:stroke_foreground_thickness="40dp"
            app:timer_text_color="@color/colorLightBlue"
            app:timer_text_shown="true"
            app:timer_text_isBold="true"
            app:timer_text_format="HOUR_MINUTE_SECOND"
            app:timer_text_size="20sp"
            app:timer_type="COUNT_UP"
            />

Activity Or Fragment

You can set these properties in your java or kotlin code as well.

class DemoCircularCountDownActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_demo_circular_count_down)

        //Set configuration for timer UI
        circularCountDownView.isTimerTextShown = true
        circularCountDownView.timerType = HappyTimer.Type.COUNT_UP
        circularCountDownView.timerTextFormat = CircularCountDownView.TextFormat.HOUR_MINUTE_SECOND
        circularCountDownView.strokeThicknessForeground = 10f
        circularCountDownView.strokeThicknessBackground = 10f
        circularCountDownView.strokeColorBackground = ContextCompat.getColor(this, R.color.colorGrey)
        circularCountDownView.strokeColorForeground = ContextCompat.getColor(this, R.color.colorLightBlue)
        circularCountDownView.timerTextColor = ContextCompat.getColor(this, R.color.colorPrimaryDark)
        circularCountDownView.timerTextIsBold = true
        circularCountDownView.timerTextSize = 13f //this will automatically converted to sp value.

        //Initialize Your Timer with seconds
        circularCountDownView.initTimer(60)

        //set OnTickListener for getting updates on time. [Optional]
        circularCountDownView.setOnTickListener(object : HappyTimer.OnTickListener {

            //OnTick
            override fun onTick(completedSeconds: Int, remainingSeconds: Int) {

            }

            //OnTimeUp
            override fun onTimeUp() {

            }
        })

        //set OnStateChangeListener [RUNNING, FINISHED, PAUSED, RESUMED, UNKNOWN, RESET, STOPPED] [Optional]
        circularCountDownView.setStateChangeListener(object : HappyTimer.OnStateChangeListener {
            override fun onStateChange(
                state: HappyTimer.State,
                completedSeconds: Int,
                remainingSeconds: Int
            ) {
                // write your code here for State Changes
            }
        })
        
        //Call these functions to perform actions
        //Start Timer
        circularCountDownView.startTimer()

        //Pause Timer
        circularCountDownView.pauseTimer()

        //Resume Timer
        circularCountDownView.resumeTimer()

        //Stop Timer
        circularCountDownView.stopTimer()

        //Reset Timer
        circularCountDownView.resetTimer()

        //get Total Seconds
        val totalSeconds = circularCountDownView.getTotalSeconds()

    }

}

DynamicCountDownView

Layout(XML)

<com.androchef.happytimer.countdowntimer.DynamicCountDownView
            android:id="@+id/dynamicCountDownView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:dynamic_timer_text_color="@android:color/white"
            app:dynamic_timer_text_separator_color="@color/colorGrey"
            app:dynamic_timer_text_size="12sp"
            app:dynamic_timer_separator_text_size="15sp"
            app:dynamic_timer_text_isBold="true"
            app:dynamic_timer_text__separator_isBold="true"
            app:dynamic_timer_text_separator=":"
            app:dynamic_show_hour="true"
            app:dynamic_show_labels="true"
            app:dynamic_show_minutes="true"
            app:dynamic_show_seconds="true"
            />

Activity Or Fragment

You can set these properties in your java or kotlin code as well.

class DemoDynamicCountDownActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_demo_dynamic_count_down)

        dynamicCountDownView.separatorString = ":"
        dynamicCountDownView.timerTextColor = ContextCompat.getColor(this, R.color.colorGrey)
        dynamicCountDownView.timerTextSeparatorColor = ContextCompat.getColor(this, R.color.colorAccent)
        dynamicCountDownView.timerTextSeparatorSize = 15f //this will automatically converted to sp value.
        dynamicCountDownView.timerTextSize = 15f //this will automatically converted to sp value.
        dynamicCountDownView.showHour = true
        dynamicCountDownView.showMinutes = true
        dynamicCountDownView.showSeconds = true
        dynamicCountDownView.showSeparators = true
        dynamicCountDownView.timerTextIsBold = true
        dynamicCountDownView.timerTextSeparatorIsBold = true
        dynamicCountDownView.timerType = HappyTimer.Type.COUNT_UP

        //Set timer text background as a rectangle
        dynamicCountDownView.setRectangularBackground()

        //Set timer text background as a circle
        dynamicCountDownView.setRoundedBackground()

        //set custom background for timer text
        dynamicCountDownView.customBackgroundDrawable =
            ContextCompat.getDrawable(this, R.drawable.bg_textview_count_down_circle)

        //Initialize Your Timer with seconds
        dynamicCountDownView.initTimer(60)

        //set OnTickListener for getting updates on time. [Optional]
        dynamicCountDownView.setOnTickListener(object : HappyTimer.OnTickListener {

            //OnTick
            override fun onTick(completedSeconds: Int, remainingSeconds: Int) {

            }

            //OnTimeUp
            override fun onTimeUp() {

            }
        })

        //set OnStateChangeListener [RUNNING, FINISHED, PAUSED, RESUMED, UNKNOWN, RESET, STOPPED] [Optional]
        dynamicCountDownView.setStateChangeListener(object : HappyTimer.OnStateChangeListener {
            override fun onStateChange(
                state: HappyTimer.State,
                completedSeconds: Int,
                remainingSeconds: Int
            ) {
                // write your code here for State Changes
            }
        })

        //Call these functions to perform actions
        //Start Timer
        dynamicCountDownView.startTimer()

        //Pause Timer
        dynamicCountDownView.pauseTimer()

        //Resume Timer
        dynamicCountDownView.resumeTimer()

        //Stop Timer
        dynamicCountDownView.stopTimer()

        //Reset Timer
        dynamicCountDownView.resetTimer()

    }

}

NormalCountDownView

Layout(XML)

<com.androchef.happytimer.countdowntimer.NormalCountDownView
            android:id="@+id/normalCountDownView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:normal_timer_text_size="30sp"
            app:normal_timer_label_text_size="18sp"
            app:nor
View on GitHub
GitHub Stars52
CategoryDevelopment
Updated3mo ago
Forks4

Languages

Kotlin

Security Score

97/100

Audited on Dec 4, 2025

No findings