Class POBCountdownTimer

  • All Implemented Interfaces:

    
    public abstract class POBCountdownTimer
    
                        

    Schedule a countdown until a time in the future, with regular notifications on intervals along the way.

    Example of showing a 30 second countdown in a text field:

    new POBCountdownTimer(30, 1) {
    
    The calls to onTick are synchronized to this object so that one call to onTick won't ever occur before the previous callback is complete. This is only relevant when the implementation of onTick takes an amount of time to execute that is significant compared to the countdown interval.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      POBCountdownTimer(long secondsInFuture, long countDownIntervalInSeconds, Looper looper)
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final void cancel() Cancel the countdown.
      final synchronized POBCountdownTimer start() Start the countdown.
      long pause() Pause the countdown.
      long resume() Resume the countdown.
      abstract void onTick(long secondsUntilFinished) Callback fired on regular interval.
      abstract void onFinish() Callback fired when the time is up.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • POBCountdownTimer

        POBCountdownTimer(long secondsInFuture, long countDownIntervalInSeconds, Looper looper)
        Parameters:
        secondsInFuture - The number of seconds in the future from the call to start until the countdown is done and onFinish is called.
        countDownIntervalInSeconds - The interval in seconds along the way to receive onTick callbacks.
        looper - the instance of looper, to provide callbacks on provided looper
    • Method Detail

      • cancel

         final void cancel()

        Cancel the countdown.

        Do not call it from inside CountDownTimer threads

      • pause

         long pause()

        Pause the countdown.

      • resume

         long resume()

        Resume the countdown.

      • onTick

         abstract void onTick(long secondsUntilFinished)

        Callback fired on regular interval.

        Parameters:
        secondsUntilFinished - The amount of time until finished.
      • onFinish

         abstract void onFinish()

        Callback fired when the time is up.