Skip to content

BetterTimer is the best way to implement a timer in your app, that comes with an API to interface with the timer. No more dealing with CountDownTimer!

License

Notifications You must be signed in to change notification settings

gitryder/better-timer

Repository files navigation

BetterTimer

BetterTimer is the fastest way to implement a timer in Android. It solves some of CountDownTimer's problems 1 and provides a robust API for interfacing 2 with the timer

👨‍🔧 Installation

Add this to your app's project-level build.gradle file:

repositories {
  maven { url 'https://jitpack.io' }
}

And this to your app's module-level build.gradle file:

dependencies {
  implementation 'com.github.gitryder:better-timer:v0.2-alpha'
}

🚀 Usage

  1. Have your Activity implement BetterTimer.OnTimerTickListener
- class MainActivity : AppCompatActivity() { ... }
+ class MainActivity : AppCompatActivity(), BetterTimer.OnTimerTickListener { ... }
  1. Create an instance of BetterTimer
  • Pass the time (in minutes)
  • Pass the activity context (this) to receive callbacks
val timer = BetterTimer(25, this)
  1. Call the timer methods as you please
timerStartButton.setOnClickListener { 
    timer.start()  
    // Update UI Logic
}
timerPauseButton.setOnClickListener { 
    timer.pause()
    // Update UI Logic
}
timerResetButton.setOnClickListener { 
    timer.reset()         
    // Update UI Logic
}
  1. Update the view that displays the time, in the onTimerTick() callback
override fun onTimerTick(timeUntilFinished: String) {
    timerDisplayTextview.text = timeUntilFinished
}

🌄 Contribute to this project

  1. Fork this repo (git clone https://github.com/gitryder/better-timer.git)
  2. Create a feature branch (git checkout -b a-new-feature)
  3. Commit your work (git commit -am 'Add new feature')
  4. Push to your branch (git push origin a-new-feature)
  5. Create a shiny new Pull Request
  6. Pat yourself on the back!

👨‍💻 Developer

Built with ❤︎ by Danyl Fernandes

✳️ Citations

  1. Not a "problem" per se, but every tick of the CountDownTimer is calculated using the duration of the previous tick, which is what makes the ticks inaccurate as the timer run-time goes up.
  2. BetterTimer provides convenience methods (timer.start(), timer.pause(), timer.reset()) to make setting up a timer in your app AS EASY AS CAN BE.

📑 License

Copyright 2020 Danyl Fernandes

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

BetterTimer is the best way to implement a timer in your app, that comes with an API to interface with the timer. No more dealing with CountDownTimer!

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages