Skip to content

🎯 Digi-Timer for use timer with millisecond in three mode Timer-Up, Timer-Down and Timer Up With Limit

License

Notifications You must be signed in to change notification settings

hamidfathi1998/Digi-Timer

Repository files navigation

Digi Timer- An Android Timer Logic Library

platform API

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 :

dependencies {
  ...
  implementation 'com.github.hamidfathi1998:Digi-Timer:$VERSION'
}

Usage

We have three mode of timer in this library

  • Timer Up
  • Timer Up With Limit
  • Timer Down

MainActivity.kt

    companion object{
        const val TIMER_DOWN_LIMIT_VALUE = 12_000L // 12 sec
        const val TIMER_UP_WITH_LIMIT_VALUE = 70_100L // 1 min, 10sec, 10 mill
        const val TIMER_DATE_FORMAT_VALUE = "mm : ss.SS" // 12 : 25.79
    }
    
        //Initialize Timer with Timer up
        val mTimer = TimerFactory()
            .getInstance(TimerMode.TIMER_UP) // or Timer Down, Timer Up With Limit
            // .setLimitToTimer(TIMER_DOWN_LIMIT_VALUE) usage in Timer Down and Timer Up With Limit for set limit 
            .setDateFormatPattern(TIMER_DATE_FORMAT_VALUE)
            .timerTick { timerValue ->
                runOnUiThread {
                    binding.txtTimerUpValue.text = timerValue
                }
            }.finishTimer {
                runOnUiThread {
                    Toast.makeText(
                        this,
                        getString(R.string.finish_timer_up_with_limit),
                        Toast.LENGTH_SHORT
                    ).show()
                }
            }
        
        binding.btnTimerUpStart.setOnClickListener {
            mTimer.start()
        }

        binding.btnTimerUpStop.setOnClickListener {
            mTimer.stop()
        }

        binding.btnTimerUpPause.setOnClickListener {
            mTimer.pause()
        }

        binding.btnTimerUpResume.setOnClickListener {
            mTimer.resume()
        }

Another method :

    val mTimer = TimerFactory()
    .getInstance(TimerMode.TIMER_DOWN) // or Timer Down, Timer Up With Limit
    .setLimitToTimer(8_000) usage in Timer Down and Timer Up With Limit for set limit 
    .setDateFormatPattern(TIMER_DATE_FORMAT_VALUE)
    if you want when tap on stop method invoke finishTimer method pass treu ( default value is false)
    .setTapStopFinishInvoke(true)
    .timerTick { timerValue ->
        runOnUiThread {
            binding.txtTimerUpValue.text = timerValue
        }
    }.finishTimer {
        runOnUiThread {
            Toast.makeText(
                this,
                getString(R.string.finish_timer_up_with_limit),
                Toast.LENGTH_SHORT
            ).show()
        }
    }
    
    // get timer value if you want to use timer value another place
    mTimer.getTimerNowValue()
    
    // To avoid MemoryLeaks always stop the timer in onDestroy().
    mTimer.destroyTimer()
    
    

If this project helps you in anyway, show your love ❤️ by putting a ⭐ on this project ✌️

Contributing

Please fork this repository and contribute back using pull requests.

Any contributions, large or small, major features, bug fixes, are welcomed and appreciated but will be thoroughly reviewed .

- Contact - Let's become friend

About

🎯 Digi-Timer for use timer with millisecond in three mode Timer-Up, Timer-Down and Timer Up With Limit

Resources

License

Stars

Watchers

Forks

Languages