-
Notifications
You must be signed in to change notification settings - Fork 6
Programmatically
To begin, if you prefer you can define the style programmatically:
circularCountdown.setProgressBackgroundColor(R.color.colorAccent)
circularCountdown.setProgressForegroundColor(R.color.colorPrimary)
circularCountdown.setProgressTextColor(R.color.colorPrimaryDark)
circularCountdown.setProgressTextSize(24f)You have two types of Countdown: Circular Countdown and Circular Cascade Countdown.
This is the simple way, just one countdown running.
circularCountdown.create(3, 10, CircularCountdown.TYPE_SECOND).start()You need to call .create() with three params: pastTime, endTime and timeType and .start() to start the countdown.
-
pastTimeis the time that was already passed on the countdown; -
endTimeis the max value of the timer; -
timeTypeis the type of the countdown (TYPE_SECOND,TYPE_MINUTE,TYPE_HOURorTYPE_DAY);
In the example above the Countdown will have 10 positions and start at 7 (because already past 3 of 10). The type define the duration that each position will take, so, every one second one position will be advanced.
You can stop the Countdown anytime you want:
circularCountdown.stop()You can add a listener too:
circularCountdown.create(3, 10, CircularCountdown.TYPE_SECOND)
.listener(object : CircularListener {
override fun onTick(progress: Int) {
}
override fun onFinish(newCycle: Boolean, cycleCount: Int) {
}
})
.start()In the listener you have onTick and onFinish.
-
onTickis called everytime that your countdown advance one position and it returns the current position; -
onFinishis called everytime that one cycle is done and returns if have a new cycle or not and the count of cycles that was runned.
You can definy more rules using .maxCyles() and .loop():
circularCountdown.create(3, 10, CircularCountdown.TYPE_SECOND).maxCycles(3).start()
circularCountdown.create(3, 10, CircularCountdown.TYPE_SECOND).loop(false).start()In the first one the Countdown will run three times and stop and in the second one will run just once. The loop is enabled as default.
You can use other functions to change/check and the names are self explanatory:
circularCountdown.isLoopEnable()
circularCountdown.enableLoop()
circularCountdown.disableLoop()
circularCountdown.getMaxCycles()
circularCountdown.isRunning()Here you can create a Cascade Countdown connecting two to four Countdowns.
CircularCascadeCountdown(86405000,
circularCountdownSeconds,
circularCountdownMinutes,
circularCountdownHours,
circularCountdownDays)
.listener(object : CascadeListener {
override fun onFinish() {
}
})
.start()You need to call CircularCascadeCountdown() with two to five params: remainTime, countdownSeconds, countdownMinutes, countdownHours and countdownDays and .start() to start the countdown.
-
remainTimeis the total time (in miliseconds) that the Countdown will run; -
countdownSecondsthe countdown view referent of seconds (can be styled before); -
countdownMinutesthe countdown view referent of minutes (can be styled before); -
countdownHoursthe countdown view referent of hours (can be styled before); -
countdownDaysthe countdown view referent of days (can be styled before);
In that case the countdown will run based on seconds.
If you want to manipulate it you can attribute to a variable:
val circularCascadeCountdown = CircularCascadeCountdown(86405000,
circularCountdownSeconds,
circularCountdownMinutes,
circularCountdownHours,
circularCountdownDays)
.start()You can stop the Countdown anytime you want:
circularCascadeCountdown.stop()And check if is running:
circularCascadeCountdown.isRunning()