Git Product home page Git Product logo

textcounter's Introduction

Maven Central Android Arsenal

TextCounter

A simple subclass of android's TextView that counts up or down. Customize the counting using the attributes below.

See the demo project for more implementation details.

![] (img/counter.gif)

Download

<dependency>
  <groupId>com.github.premnirmal</groupId>
  <artifactId>TextCounter</artifactId>
  <version>1.0.1</version>
  <type>aar</type>
</dependency>

Usage

Xml

  <com.github.premnirmal.textcounter.CounterView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20dp"
        android:textSize="30dp"
        android:textColor="@color/orange"
        counter:autoStart="true"
        counter:startValue="100"
        counter:endValue="5000"
        counter:incrementValue="100"
        counter:timeInterval="2"
        counter:prefix="$"
        counter:suffix=" moneys"
        counter:type="integer | decimal | both"
        />

Java

final CounterView counterView = new CounterView(context);
counterView.setFormatter(new Formatter() {
    @Override
    public String format(String prefix, String suffix, float value) {
    return prefix 
        + NumberFormat.getNumberInstance(Locale.US).format(value) 
        + suffix;
    }
});
counterView.setAutoStart(false);
counterView.setStartValue(200f);
counterView.setEndValue(1000f);
counterView.setIncrement(5f); // the amount the number increments at each time interval
counterView.setTimeInterval(2); // the time interval (ms) at which the text changes
counterView.setPrefix("You have ");
counterView.setSuffix(" points!");
counterView.start(); // you can start anytime if autostart is set to false

Formatter

You can control the text formatting by providing a Formatter. Simply implement the interface com.github.premnirmal.textcounter.Formatter or use one of the formatters under the com.github.premnirmal.textcounter.formatters package.

API Requirements

  • The minimum supported Android version is Android 4.0.0 IceCreamSandwich (API Level 14)

Contributing

Please fork this repository and contribute back using pull requests.

License

MIT

Author

Prem Nirmal | illegalstate.com | twitter

textcounter's People

Contributors

premnirmal avatar

Watchers

James Cloos avatar ScriptGO 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.