Hey, I'm implementing this by using view binding but I can't figure out where I go wrong as background isn't visible on every text view. Basically I think I won't able to access both views in "CountDownClock". I m showing the script of how I access the multiple view using view binding. Please Can you provide me any direction where I go wrong? Thanks.
Here is what my code is
class CountDownClock : LinearLayout {
private var countDownTimer: CountDownTimer? = null
private var countdownListener: CountdownCallBack? = null
private var countdownTickInterval = 1000
private lateinit var bindingCountDownClock: ViewCountdownClockDigitBinding
private lateinit var bindingSimpleClock: ViewSimpleClockBinding
private var almostFinishedCallbackTimeInSeconds: Int = 5
private var resetSymbol: String = "8"
constructor(context: Context?) : this(context, null)
constructor(context: Context?, attrs: AttributeSet?) : this(context, attrs, 0)
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
context,
attrs,
defStyleAttr
) {
bindingCountDownClock =
ViewCountdownClockDigitBinding.inflate(LayoutInflater.from(context), this, true)
bindingSimpleClock =
ViewSimpleClockBinding.inflate(LayoutInflater.from(context), this, true)
attrs?.let {
val typedArray =
context?.obtainStyledAttributes(attrs, R.styleable.CountDownClock, defStyleAttr, 0)
val resetSymbol = typedArray?.getString(R.styleable.CountDownClock_resetSymbol)
if (resetSymbol != null) {
setResetSymbol(resetSymbol)
}
val digitTopDrawable =
typedArray?.getDrawable(R.styleable.CountDownClock_digitTopDrawable)
setDigitTopDrawable(digitTopDrawable)
val digitBottomDrawable =
typedArray?.getDrawable(R.styleable.CountDownClock_digitBottomDrawable)
setDigitBottomDrawable(digitBottomDrawable)
val digitDividerColor =
typedArray?.getColor(R.styleable.CountDownClock_digitDividerColor, 0)
setDigitDividerColor(digitDividerColor ?: 0)
val digitSplitterColor =
typedArray?.getColor(R.styleable.CountDownClock_digitSplitterColor, 0)
setDigitSplitterColor(digitSplitterColor ?: 0)
val digitTextColor = typedArray?.getColor(R.styleable.CountDownClock_digitTextColor, 0)
setDigitTextColor(digitTextColor ?: 0)
val digitTextSize =
typedArray?.getDimension(R.styleable.CountDownClock_digitTextSize, 0f)
setDigitTextSize(digitTextSize ?: 0f)
setSplitterDigitTextSize(digitTextSize ?: 0f)
/* val digitPadding = typedArray?.getDimension(R.styleable.CountDownClock_digitPadding, 0f)
setDigitPadding(digitPadding?.toInt() ?: 0)*/
val splitterPadding =
typedArray?.getDimension(R.styleable.CountDownClock_splitterPadding, 0f)
setSplitterPadding(splitterPadding?.toInt() ?: 0)
val halfDigitHeight =
typedArray?.getDimensionPixelSize(R.styleable.CountDownClock_halfDigitHeight, 0)
val digitWidth =
typedArray?.getDimensionPixelSize(R.styleable.CountDownClock_digitWidth, 0)
setHalfDigitHeightAndDigitWidth(halfDigitHeight ?: 0, digitWidth ?: 0)
val animationDuration =
typedArray?.getInt(R.styleable.CountDownClock_animationDuration, 0)
setAnimationDuration(animationDuration ?: 600)
val almostFinishedCallbackTimeInSeconds = typedArray?.getInt(
R.styleable.CountDownClock_almostFinishedCallbackTimeInSeconds,
5
)
setAlmostFinishedCallbackTimeInSeconds(almostFinishedCallbackTimeInSeconds ?: 5)
val countdownTickInterval =
typedArray?.getInt(R.styleable.CountDownClock_countdownTickInterval, 1000)
this.countdownTickInterval = countdownTickInterval ?: 1000
invalidate()
typedArray?.recycle()
}
}
////////////////
// Public methods
////////////////
private var milliLeft: Long = 0
fun startCountDown(timeToNextEvent: Long) {
countDownTimer?.cancel()
var hasCalledAlmostFinished = false
countDownTimer = object : CountDownTimer(timeToNextEvent, countdownTickInterval.toLong()) {
override fun onTick(millisUntilFinished: Long) {
milliLeft = millisUntilFinished
if (millisUntilFinished / 1000 <= almostFinishedCallbackTimeInSeconds && !hasCalledAlmostFinished) {
hasCalledAlmostFinished = true
countdownListener?.countdownAboutToFinish()
}
setCountDownTime(millisUntilFinished)
}
override fun onFinish() {
hasCalledAlmostFinished = false
countdownListener?.countdownFinished()
}
}
countDownTimer?.start()
}
fun resetCountdownTimer() {
countDownTimer?.cancel()
bindingSimpleClock.apply {
firstDigitDays.setNewText(resetSymbol)
secondDigitDays.setNewText(resetSymbol)
firstDigitHours.setNewText(resetSymbol)
secondDigitHours.setNewText(resetSymbol)
firstDigitMinute.setNewText(resetSymbol)
secondDigitMinute.setNewText(resetSymbol)
firstDigitSecond.setNewText(resetSymbol)
secondDigitSecond.setNewText(resetSymbol)
}
}
////////////////
// Private methods
////////////////
private fun setCountDownTime(timeToStart: Long) {
val days = TimeUnit.MILLISECONDS.toDays(timeToStart)
val hours = TimeUnit.MILLISECONDS.toHours(timeToStart - TimeUnit.DAYS.toMillis(days))
val minutes = TimeUnit.MILLISECONDS.toMinutes(
timeToStart - (TimeUnit.DAYS.toMillis(days) + TimeUnit.HOURS.toMillis(hours))
)
val seconds = TimeUnit.MILLISECONDS.toSeconds(
timeToStart - (TimeUnit.DAYS.toMillis(days) + TimeUnit.HOURS.toMillis(hours) + TimeUnit.MINUTES.toMillis(
minutes
))
)
val daysString = days.toString()
val hoursString = hours.toString()
val minutesString = minutes.toString()
val secondsString = seconds.toString()
bindingSimpleClock.apply {
when {
daysString.length == 2 -> {
firstDigitDays.animateTextChange((daysString[0].toString()))
secondDigitDays.animateTextChange((daysString[1].toString()))
}
daysString.length == 1 -> {
firstDigitDays.animateTextChange(("0"))
secondDigitDays.animateTextChange((daysString[0].toString()))
}
else -> {
firstDigitDays.animateTextChange(("3"))
secondDigitDays.animateTextChange(("0"))
}
}
when {
hoursString.length == 2 -> {
firstDigitHours.animateTextChange((hoursString[0].toString()))
secondDigitHours.animateTextChange((hoursString[1].toString()))
}
hoursString.length == 1 -> {
firstDigitHours.animateTextChange(("0"))
secondDigitHours.animateTextChange((hoursString[0].toString()))
}
else -> {
firstDigitHours.animateTextChange(("1"))
secondDigitHours.animateTextChange(("1"))
}
}
when {
minutesString.length == 2 -> {
firstDigitMinute.animateTextChange((minutesString[0].toString()))
secondDigitMinute.animateTextChange((minutesString[1].toString()))
}
minutesString.length == 1 -> {
firstDigitMinute.animateTextChange(("0"))
secondDigitMinute.animateTextChange((minutesString[0].toString()))
}
else -> {
firstDigitMinute.animateTextChange(("5"))
secondDigitMinute.animateTextChange(("9"))
}
}
when {
secondsString.length == 2 -> {
firstDigitSecond.animateTextChange((secondsString[0].toString()))
secondDigitSecond.animateTextChange((secondsString[1].toString()))
}
secondsString.length == 1 -> {
firstDigitSecond.animateTextChange(("0"))
secondDigitSecond.animateTextChange((secondsString[0].toString()))
}
else -> {
firstDigitSecond.animateTextChange((secondsString[secondsString.length - 2].toString()))
secondDigitSecond.animateTextChange((secondsString[secondsString.length - 1].toString()))
}
}
}
}
private fun setResetSymbol(resetSymbol: String?) {
resetSymbol?.let {
if (it.isNotEmpty()) {
this.resetSymbol = resetSymbol
} else {
this.resetSymbol = ""
}
} ?: kotlin.run {
this.resetSymbol = ""
}
}
private fun setDigitTopDrawable(digitTopDrawable: Drawable?) {
if (digitTopDrawable != null) {
bindingSimpleClock.firstDigitDays.also {
bindingCountDownClock.frontUpper.background = digitTopDrawable
bindingCountDownClock.backUpper.background = digitTopDrawable
}
bindingSimpleClock.secondDigitDays.also {
bindingCountDownClock.frontUpper.background = digitTopDrawable
bindingCountDownClock.backUpper.background = digitTopDrawable
}
bindingSimpleClock.firstDigitHours.also {
bindingCountDownClock.frontUpper.background = digitTopDrawable
bindingCountDownClock.backUpper.background = digitTopDrawable
}
bindingSimpleClock.secondDigitHours.also {
bindingCountDownClock.frontUpper.background = digitTopDrawable
bindingCountDownClock.backUpper.background = digitTopDrawable
}
bindingSimpleClock.firstDigitMinute.also {
bindingCountDownClock.frontUpper.background = digitTopDrawable
bindingCountDownClock.backUpper.background = digitTopDrawable
}
bindingSimpleClock.secondDigitMinute.also {
bindingCountDownClock.frontUpper.background = digitTopDrawable
bindingCountDownClock.backUpper.background = digitTopDrawable
}
bindingSimpleClock.firstDigitSecond.also {
bindingCountDownClock.frontUpper.background = digitTopDrawable
bindingCountDownClock.backUpper.background = digitTopDrawable
}
bindingSimpleClock.secondDigitSecond.also {
bindingCountDownClock.frontUpper.background = digitTopDrawable
bindingCountDownClock.backUpper.background = digitTopDrawable
}
} else {
setTransparentBackgroundColor()
}
}
private fun setDigitBottomDrawable(digitBottomDrawable: Drawable?) {
if (digitBottomDrawable != null) {
bindingSimpleClock.firstDigitDays.also {
bindingCountDownClock.frontUpper.background = digitBottomDrawable
bindingCountDownClock.backUpper.background = digitBottomDrawable
}
bindingSimpleClock.secondDigitDays.also {
bindingCountDownClock.frontUpper.background = digitBottomDrawable
bindingCountDownClock.backUpper.background = digitBottomDrawable
}
bindingSimpleClock.firstDigitHours.also {
bindingCountDownClock.frontUpper.background = digitBottomDrawable
bindingCountDownClock.backUpper.background = digitBottomDrawable
}
bindingSimpleClock.secondDigitHours.also {
bindingCountDownClock.frontUpper.background = digitBottomDrawable
bindingCountDownClock.backUpper.background = digitBottomDrawable
}
bindingSimpleClock.firstDigitMinute.also {
bindingCountDownClock.frontUpper.background = digitBottomDrawable
bindingCountDownClock.backUpper.background = digitBottomDrawable
}
bindingSimpleClock.secondDigitMinute.also {
bindingCountDownClock.frontUpper.background = digitBottomDrawable
bindingCountDownClock.backUpper.background = digitBottomDrawable
}
bindingSimpleClock.firstDigitSecond.also {
bindingCountDownClock.frontUpper.background = digitBottomDrawable
bindingCountDownClock.backUpper.background = digitBottomDrawable
}
bindingSimpleClock.secondDigitSecond.also {
bindingCountDownClock.frontUpper.background = digitBottomDrawable
bindingCountDownClock.backUpper.background = digitBottomDrawable
}
/* frontLower.background = digitBottomDrawable
backLower.background = digitBottomDrawable
frontLower.background = digitBottomDrawable
backLower.background = digitBottomDrawable
frontLower.background = digitBottomDrawable
backLower.background = digitBottomDrawable
frontLower.background = digitBottomDrawable
backLower.background = digitBottomDrawable
frontLower.background = digitBottomDrawable
backLower.background = digitBottomDrawable
frontLower.background = digitBottomDrawable
backLower.background = digitBottomDrawable
frontLower.background = digitBottomDrawable
backLower.background = digitBottomDrawable
frontLower.background = digitBottomDrawable
backLower.background = digitBottomDrawable*/
} else {
setTransparentBackgroundColor()
}
}
private fun setDigitDividerColor(digitDividerColor: Int) {
var dividerColor = digitDividerColor
if (dividerColor == 0) {
dividerColor = ContextCompat.getColor(context, R.color.transparent)
}
}
private fun setDigitSplitterColor(digitsSplitterColor: Int) {
if (digitsSplitterColor != 0) {
} else {
}
}
private fun setSplitterDigitTextSize(digitsTextSize: Float) {
}
private fun setDigitPadding(digitPadding: Int) {
bindingSimpleClock.apply {
firstDigitDays.setPadding(digitPadding, digitPadding, digitPadding, digitPadding)
secondDigitDays.setPadding(digitPadding, digitPadding, digitPadding, digitPadding)
firstDigitHours.setPadding(digitPadding, digitPadding, digitPadding, digitPadding)
secondDigitHours.setPadding(digitPadding, digitPadding, digitPadding, digitPadding)
firstDigitMinute.setPadding(digitPadding, digitPadding, digitPadding, digitPadding)
secondDigitMinute.setPadding(digitPadding, digitPadding, digitPadding, digitPadding)
firstDigitSecond.setPadding(digitPadding, digitPadding, digitPadding, digitPadding)
secondDigitSecond.setPadding(digitPadding, digitPadding, digitPadding, digitPadding)
}
}
private fun setSplitterPadding(splitterPadding: Int) {
}
private fun setDigitTextColor(digitsTextColor: Int) {
var textColor = digitsTextColor
if (textColor == 0) {
textColor = ContextCompat.getColor(context, R.color.transparent)
}
bindingSimpleClock.firstDigitDays.also {
bindingCountDownClock.apply {
frontUpperText.setTextColor(textColor)
backUpperText.setTextColor(textColor)
}
}
bindingSimpleClock.firstDigitHours .also {
bindingCountDownClock.apply {
frontUpperText.setTextColor(textColor)
backUpperText.setTextColor(textColor)
}
}
bindingSimpleClock.secondDigitDays.also {
bindingCountDownClock.apply {
frontUpperText.setTextColor(textColor)
backUpperText.setTextColor(textColor)
}
}
bindingSimpleClock.secondDigitHours.also {
bindingCountDownClock.apply {
frontUpperText.setTextColor(textColor)
backUpperText.setTextColor(textColor)
}
}
bindingSimpleClock.firstDigitMinute.also {
bindingCountDownClock.apply {
frontUpperText.setTextColor(textColor)
backUpperText.setTextColor(textColor)
}
}
bindingSimpleClock.secondDigitMinute.also {
bindingCountDownClock.apply {
frontUpperText.setTextColor(textColor)
backUpperText.setTextColor(textColor)
}
}
bindingSimpleClock.firstDigitSecond.also {
bindingCountDownClock.apply {
frontUpperText.setTextColor(textColor)
backUpperText.setTextColor(textColor)
}
}
bindingSimpleClock.secondDigitSecond.also {
bindingCountDownClock.apply {
frontUpperText.setTextColor(textColor)
backUpperText.setTextColor(textColor)
}
}
bindingSimpleClock.firstDigitDays.also {
bindingCountDownClock.apply {
frontLowerText.setTextColor(textColor)
backLowerText.setTextColor(textColor)
}
}
bindingSimpleClock.secondDigitDays.also {
bindingCountDownClock.apply {
frontLowerText.setTextColor(textColor)
backLowerText.setTextColor(textColor)
}
}
bindingSimpleClock.firstDigitHours.also {
bindingCountDownClock.apply {
frontLowerText.setTextColor(textColor)
backLowerText.setTextColor(textColor)
}
}
bindingSimpleClock.secondDigitHours.also {
bindingCountDownClock.apply {
frontLowerText.setTextColor(textColor)
backLowerText.setTextColor(textColor)
}
}
bindingSimpleClock.firstDigitMinute.also {
bindingCountDownClock.apply {
frontLowerText.setTextColor(textColor)
backLowerText.setTextColor(textColor)
}
}
bindingSimpleClock.secondDigitMinute.also {
bindingCountDownClock.apply {
frontLowerText.setTextColor(textColor)
backLowerText.setTextColor(textColor)
}
}
bindingSimpleClock.firstDigitSecond.also {
bindingCountDownClock.apply {
frontLowerText.setTextColor(textColor)
backLowerText.setTextColor(textColor)
}
}
bindingSimpleClock.secondDigitSecond.also {
bindingCountDownClock.apply {
frontLowerText.setTextColor(textColor)
backLowerText.setTextColor(textColor)
}
}
}
private fun setDigitTextSize(digitsTextSize: Float) {
bindingSimpleClock.firstDigitDays.also {
bindingCountDownClock.apply {
frontUpperText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
backUpperText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
frontLowerText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
backLowerText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
}
}
bindingSimpleClock.secondDigitDays.also {
bindingCountDownClock.apply {
frontUpperText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
backUpperText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
frontLowerText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
backLowerText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
}
}
bindingSimpleClock.firstDigitHours.also {
bindingCountDownClock.apply {
frontUpperText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
backUpperText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
frontLowerText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
backLowerText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
}
}
bindingSimpleClock.secondDigitHours.also {
bindingCountDownClock.apply {
frontUpperText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
backUpperText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
frontLowerText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
backLowerText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
}
}
bindingSimpleClock.firstDigitMinute.also {
bindingCountDownClock.apply {
frontUpperText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
backUpperText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
frontLowerText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
backLowerText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
}
}
bindingSimpleClock.secondDigitMinute.also {
bindingCountDownClock.apply {
frontUpperText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
backUpperText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
frontLowerText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
backLowerText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
}
}
bindingSimpleClock.firstDigitSecond.also {
bindingCountDownClock.apply {
frontUpperText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
backUpperText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
frontLowerText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
backLowerText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
}
}
bindingSimpleClock.secondDigitSecond.also {
bindingCountDownClock.apply {
frontUpperText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
backUpperText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
frontLowerText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
backLowerText.setTextSize(TypedValue.COMPLEX_UNIT_PX, digitsTextSize)
}
}
}
private fun setHalfDigitHeightAndDigitWidth(halfDigitHeight: Int, digitWidth: Int) {
bindingSimpleClock.firstDigitDays.also {
bindingCountDownClock.apply {
setHeightAndWidthToView(frontUpper, halfDigitHeight, digitWidth)
setHeightAndWidthToView(backUpper, halfDigitHeight, digitWidth)
setHeightAndWidthToView(frontLower, halfDigitHeight, digitWidth)
setHeightAndWidthToView(backLower, halfDigitHeight, digitWidth)
}
}
bindingSimpleClock.secondDigitDays.also {
bindingCountDownClock.apply {
setHeightAndWidthToView(frontUpper, halfDigitHeight, digitWidth)
setHeightAndWidthToView(backUpper, halfDigitHeight, digitWidth)
setHeightAndWidthToView(frontLower, halfDigitHeight, digitWidth)
setHeightAndWidthToView(backLower, halfDigitHeight, digitWidth)
}
}
bindingSimpleClock.firstDigitHours.also {
bindingCountDownClock.apply {
setHeightAndWidthToView(frontUpper, halfDigitHeight, digitWidth)
setHeightAndWidthToView(backUpper, halfDigitHeight, digitWidth)
setHeightAndWidthToView(frontLower, halfDigitHeight, digitWidth)
setHeightAndWidthToView(backLower, halfDigitHeight, digitWidth)
}
}
bindingSimpleClock.secondDigitHours.also {
bindingCountDownClock.apply {
setHeightAndWidthToView(frontUpper, halfDigitHeight, digitWidth)
setHeightAndWidthToView(backUpper, halfDigitHeight, digitWidth)
setHeightAndWidthToView(frontLower, halfDigitHeight, digitWidth)
setHeightAndWidthToView(backLower, halfDigitHeight, digitWidth)
}
}
bindingSimpleClock.firstDigitMinute.also {
bindingCountDownClock.apply {
setHeightAndWidthToView(frontUpper, halfDigitHeight, digitWidth)
setHeightAndWidthToView(backUpper, halfDigitHeight, digitWidth)
setHeightAndWidthToView(frontLower, halfDigitHeight, digitWidth)
setHeightAndWidthToView(backLower, halfDigitHeight, digitWidth)
}
}
bindingSimpleClock.secondDigitMinute.also {
bindingCountDownClock.apply {
setHeightAndWidthToView(frontUpper, halfDigitHeight, digitWidth)
setHeightAndWidthToView(backUpper, halfDigitHeight, digitWidth)
setHeightAndWidthToView(frontLower, halfDigitHeight, digitWidth)
setHeightAndWidthToView(backLower, halfDigitHeight, digitWidth)
}
}
bindingSimpleClock.firstDigitSecond.also {
bindingCountDownClock.apply {
setHeightAndWidthToView(frontUpper, halfDigitHeight, digitWidth)
setHeightAndWidthToView(backUpper, halfDigitHeight, digitWidth)
setHeightAndWidthToView(frontLower, halfDigitHeight, digitWidth)
setHeightAndWidthToView(backLower, halfDigitHeight, digitWidth)
}
}
bindingSimpleClock.secondDigitSecond.also {
bindingCountDownClock.apply {
setHeightAndWidthToView(frontUpper, halfDigitHeight, digitWidth)
setHeightAndWidthToView(backUpper, halfDigitHeight, digitWidth)
setHeightAndWidthToView(frontLower, halfDigitHeight, digitWidth)
setHeightAndWidthToView(backLower, halfDigitHeight, digitWidth)
}
}
}
private fun setHeightAndWidthToView(view: View, halfDigitHeight: Int, digitWidth: Int) {
val firstDigitMinuteFrontUpperLayoutParams = view.layoutParams
firstDigitMinuteFrontUpperLayoutParams.height = halfDigitHeight
firstDigitMinuteFrontUpperLayoutParams.width = digitWidth
bindingSimpleClock.firstDigitDays.also {
bindingCountDownClock.frontUpper.layoutParams = firstDigitMinuteFrontUpperLayoutParams
}
}
private fun setAnimationDuration(animationDuration: Int) {
bindingSimpleClock.apply {
firstDigitDays.setAnimationDuration(animationDuration.toLong())
secondDigitDays.setAnimationDuration(animationDuration.toLong())
firstDigitHours.setAnimationDuration(animationDuration.toLong())
secondDigitHours.setAnimationDuration(animationDuration.toLong())
firstDigitMinute.setAnimationDuration(animationDuration.toLong())
secondDigitMinute.setAnimationDuration(animationDuration.toLong())
firstDigitSecond.setAnimationDuration(animationDuration.toLong())
secondDigitSecond.setAnimationDuration(animationDuration.toLong())
}
}
private fun setAlmostFinishedCallbackTimeInSeconds(almostFinishedCallbackTimeInSeconds: Int) {
this.almostFinishedCallbackTimeInSeconds = almostFinishedCallbackTimeInSeconds
}
private fun setTransparentBackgroundColor() {
val transparent = ContextCompat.getColor(context, R.color.transparent)
bindingSimpleClock.firstDigitDays.apply {
bindingCountDownClock.apply {
frontLower.setBackgroundColor(transparent)
backLower.setBackgroundColor(transparent)
}
}
bindingSimpleClock.secondDigitDays.apply {
bindingCountDownClock.apply {
frontLower.setBackgroundColor(transparent)
backLower.setBackgroundColor(transparent)
}
}
bindingSimpleClock.firstDigitHours.apply {
bindingCountDownClock.apply {
frontLower.setBackgroundColor(transparent)
backLower.setBackgroundColor(transparent)
}
}
bindingSimpleClock.firstDigitHours.apply {
bindingCountDownClock.apply {
frontLower.setBackgroundColor(transparent)
backLower.setBackgroundColor(transparent)
}
}
bindingSimpleClock.firstDigitMinute.apply {
bindingCountDownClock.apply {
frontLower.setBackgroundColor(transparent)
backLower.setBackgroundColor(transparent)
}
}
bindingSimpleClock.secondDigitMinute.apply {
bindingCountDownClock.apply {
frontLower.setBackgroundColor(transparent)
backLower.setBackgroundColor(transparent)
}
}
bindingSimpleClock.firstDigitSecond.apply {
bindingCountDownClock.apply {
frontLower.setBackgroundColor(transparent)
backLower.setBackgroundColor(transparent)
}
}
bindingSimpleClock.secondDigitSecond.apply {
bindingCountDownClock.apply {
frontLower.setBackgroundColor(transparent)
backLower.setBackgroundColor(transparent)
}
}
}
////////////////
// Listeners
////////////////
fun setCountdownListener(countdownListener: CountdownCallBack) {
this.countdownListener = countdownListener
}
interface CountdownCallBack {
fun countdownAboutToFinish()
fun countdownFinished()
}
fun pauseCountDownTimer() {
countDownTimer?.cancel()
}
fun resumeCountDownTimer() {
startCountDown(milliLeft)
}
fun setCustomTypeface(typeface: Typeface) {
bindingSimpleClock.apply {
firstDigitDays.setTypeFace(typeface)
firstDigitDays.setTypeFace(typeface)
secondDigitDays.setTypeFace(typeface)
secondDigitDays.setTypeFace(typeface)
firstDigitHours.setTypeFace(typeface)
firstDigitHours.setTypeFace(typeface)
secondDigitHours.setTypeFace(typeface)
secondDigitHours.setTypeFace(typeface)
firstDigitMinute.setTypeFace(typeface)
firstDigitMinute.setTypeFace(typeface)
secondDigitMinute.setTypeFace(typeface)
secondDigitMinute.setTypeFace(typeface)
firstDigitSecond.setTypeFace(typeface)
firstDigitSecond.setTypeFace(typeface)
secondDigitSecond.setTypeFace(typeface)
secondDigitSecond.setTypeFace(typeface)
}
}
}
This is the layout I m getting
Below is the output when application is running.