Giter VIP home page Giter VIP logo

timerx's Introduction

TimerX

A simple timer & stowatch library for android which allows you build customizable timer or stopwatch, set custom formats, and schedule actions.

TimerX provides a simple api to apply different format to a timer or a stopwatch. For instance, you can create stopwatch, specify format as HH:MM:SS or SS.LL and time in the stopwatch will be formatted according to this format.

See wiki for more detailed explanation.

Gradle Setup

Make sure you have jcenter added in your top-level build.gradle file:

allprojects {
  repositories {
    google()
  }
}

And then, add following lines in your module-level build.gradle file:

dependencies {
    implementation 'com.github.Paget96:TimerX:3.0.1'
}

Examples:

Stopwatch:

val stopwatch: Stopwatch = buildStopwatch {
    // Set the initial format
    startFormat("MM:SS")

    // Set the tick listener for displaying time
    onTick { time -> textViewStopwatch.setText(time) }

    // When time is equal to one hour, change format to "HH:MM:SS"
    changeFormatWhen(1, TimeUnit.HOURS, "HH:MM:SS")
}
      
// Start the stopwatch
stopwatch.start()
...
Stopwatch stopwatch = new StopwatchBuilder()
      // Set the initial format
      .startFormat("MM:SS")
      // Set the tick listener for displaying time
      .onTick(time -> textViewStopwatch.setText(time)) 
      // When time is equal to one hour, change format to "HH:MM:SS"
      .changeFormatWhen(1, TimeUnit.HOURS, "HH:MM:SS")
      .build();
      
// Start the stopwatch
stopwatch.start()
...

Timer:

Timer timer = new TimerBuilder()
      // Set start time
      .startTime(5, TimeUnit.MINUTES)
      // Set the initial format
      .startFormat("MM:SS")
      // Set the tick listener that receives formatted time
      .onTick(time -> textViewTimer.setText(time))
      // Run an action when the remaining time is 30 seсonds
      .actionWhen(30, TimeUnit.SECONDS, () -> {
          Toast.makeText(context, "30 seconds left!", Toast.LENGTH_SHORT).show();
      })
      .build();
      
// Start the timer
timer.start()
...

timerx's People

Contributors

arsvechkarev avatar mrresc avatar paget96 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.