Hi Guys, Welcome to Proto Coders Point, In the Android Tutorial, we are implementing the GitHub android circular countdown timer library, TICKER by using which we can build an android studio countdown timer app.
Ticker Library countdowntimer android
Ticker a android library which can be used for different count down timer activities, and Progress Loaders.
DEMO
Let’s begin implementing count down timer in android.
Adding CountDown Timer android in your android Project
I assume that you already have created a new project in android studio(IDE).
Android Studio > Files > New > New Project > give a name to project
SetUp the ticker library
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
maven { url 'https://jitpack.io' } // add this line
}
}
You should add the Maven url in build.gradle( project level).
Add the dependency:
Then, add the ticker count down dependencies in build.gradle( module : app ).
dependencies {
implementation 'com.github.rehmanmuradali:ticker:1.0.0' // add this line
}
and then its done with adding library into the android project.
UI of Ticker Circular countdown timer view – XML android timer
Create a circularView object that point the UI of the View.
CircularView.OptionsBuilder builderWithTimer =
new CircularView.OptionsBuilder()
.shouldDisplayText(true)
.setCounterInSeconds(30)
.setCircularViewCallback(new CircularViewCallback() {
@Override
public void onTimerFinish() {
// Will be called if times up of countdown timer
Toast.makeText(MainActivity.this, "CircularCallback: Timer Finished ", Toast.LENGTH_SHORT).show();
}
@Override
public void onTimerCancelled() {
// Will be called if stopTimer is called
Toast.makeText(MainActivity.this, "CircularCallback: Timer Cancelled ", Toast.LENGTH_SHORT).show();
}
});
circularView.setOptions(builderWithTimer);
Create a builder for the circularView Timer
.shouldDisplayText(true) is used to Display a text inside the Ticker Circular View timer
.setCounterInSeconds(30) set the timer for 30 sec or more as per your requirement but it should be in seconds.
onTimerFinish() : This will get called when timer will get finished.
onTimerCancelled() : When user stops the timer.
How to start, stop, pause, resume the count down timer?
//start circular view to rotate
circularView.startTimer();
// pause circular view and timer
circularView.pauseTimer()
// resume circular view and timer
circularView.resumeTimer();
// stop circular view and timer
circularView.stopTimer();