https://github.com/happysingh23828/HappyTimer
This is an android lib which helps you to implement Timer in your android app. This is 100% written in Kotlin.
https://github.com/happysingh23828/HappyTimer
android android-app android-countdown android-countdownview android-library android-timer android-timeview androidtimer timer-application
Last synced: about 1 year ago
JSON representation
This is an android lib which helps you to implement Timer in your android app. This is 100% written in Kotlin.
- Host: GitHub
- URL: https://github.com/happysingh23828/HappyTimer
- Owner: happysingh23828
- License: apache-2.0
- Created: 2020-01-04T20:21:05.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-10-10T09:30:46.000Z (over 4 years ago)
- Last Synced: 2024-08-01T16:44:09.635Z (over 1 year ago)
- Topics: android, android-app, android-countdown, android-countdownview, android-library, android-timer, android-timeview, androidtimer, timer-application
- Language: Kotlin
- Homepage:
- Size: 842 KB
- Stars: 53
- Watchers: 3
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# HappyTimer- An Android Timer UI Library
[](https://www.android.com)
[](https://android-arsenal.com/api?level=21)
[](https://www.apache.org/licenses/LICENSE-2.0.html)
[](https://jitpack.io/#happysingh23828/HappyTimer)
## Prerequisites
Add this in your root `build.gradle` file (**not** your module `build.gradle` file):
```gradle
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):
```gradle
dependencies {
...
implementation 'com.github.happysingh23828:HappyTimer:1.0.1'
}
```
## Demo Video
[Click here to see demo video](https://www.youtube.com/watch?v=ItdbO-yLDnY)
## Usage
In this library all the UI widgets are using a common [HappyTimer](https://github.com/happysingh23828/HappyTimer/blob/master/HappyTimer/src/main/java/com/androchef/happytimer/countdowntimer/HappyTimer.kt) class for implementing timer.
### HappyTimer.kt
```kotlin
//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)
```xml
```
#### Activity Or Fragment
**You can set these properties in your java or kotlin code as well.**
```kotlin
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)
```xml
```
#### Activity Or Fragment
**You can set these properties in your java or kotlin code as well.**
```kotlin
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)
```xml
```
#### Activity Or Fragment
**You can set these properties in your java or kotlin code as well.**
```kotlin
class NormalCountDownActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_normal_count_down)
normalCountDownView.timerTextColor = ContextCompat.getColor(this, R.color.colorLightBlue)
normalCountDownView.timerTextLabelColor = ContextCompat.getColor(this, R.color.colorLightBlue)
normalCountDownView.timerTextIsBold = false
normalCountDownView.timerTextLabelIsBold = false
normalCountDownView.timerTextSize = 15f //this will automatically converted to sp value.
normalCountDownView.timerTextLabelSize = 12f //this will automatically converted to sp value.
normalCountDownView.showHour = true
normalCountDownView.showMinutes = true
normalCountDownView.showSeconds = true
normalCountDownView.timerType = HappyTimer.Type.COUNT_DOWN
//Initialize Your Timer with seconds
normalCountDownView.initTimer(60)
//set OnTickListener for getting updates on time. [Optional]
normalCountDownView.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]
normalCountDownView.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
normalCountDownView.startTimer()
//Pause Timer
normalCountDownView.pauseTimer()
//Resume Timer
normalCountDownView.resumeTimer()
//Stop Timer
normalCountDownView.stopTimer()
//Reset Timer
normalCountDownView.resetTimer()
}
}
```
## If this project helps you in anyway, show your love :heart: by putting a :star: on this project :v:
## Donation
If this project help you reduce time to develop, you can give me a cup of coffee :)
## Contributing
Please fork this repository and contribute back using
[pull requests](https://github.com/happysingh23828/HappyTimer/pulls).
Any contributions, large or small, major features, bug fixes, are welcomed and appreciated
but will be thoroughly reviewed .
### - Contact - Let's become friend
- [Blog](http://happysingh.dev/)
- [Youtube](https://www.youtube.com/channel/UCILhpbLSFkGzsiCYAeR30DA)
- [Github](https://github.com/happysingh23828)
- [Linkedin](https://www.linkedin.com/in/happpysingh23828/)
## License
* [Apache Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html)
```
Copyright 2019 Happy Singh
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.
