Android Open Source - TextCounter Counter






From Project

Back to project page TextCounter.

License

The source code is released under:

MIT License

If you think the Android project TextCounter listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.github.premnirmal.textcounter;
/*from www. j  a va2 s .c  o m*/
/**
 * Created by prem on 10/28/14.
 *
 * Class that handles the counting up/down of the text value
 */
class Counter implements Runnable {

    final CounterView view;
    final float increment, startValue, endValue;
    final long interval;
    float currentValue, newValue;

    Counter(CounterView view, float startValue, float endValue, long interval, float increment) {
        this.view = view;
        this.startValue = startValue;
        this.endValue = endValue;
        this.interval = interval;
        this.increment = increment;
        this.newValue = this.startValue;
        this.currentValue = this.startValue - increment;
    }

    @Override
    public void run() {
        if (valuesAreCorrect()) {
            float valueToSet;
            if (newValue <= endValue) {
                valueToSet = newValue;
            } else {
                valueToSet = endValue;
            }
            view.setCurrentTextValue(valueToSet);
            currentValue = newValue;
            newValue += increment;
            view.removeCallbacks(Counter.this);
            view.postDelayed(Counter.this, interval);
        }
    }

    private boolean valuesAreCorrect() {
        if(increment >= 0) {
            return newValue >= currentValue;
        } else {
            return newValue <= currentValue;
        }
    }
}




Java Source Code List

com.github.premnirmal.textcounter.CounterType.java
com.github.premnirmal.textcounter.CounterView.java
com.github.premnirmal.textcounter.Counter.java
com.github.premnirmal.textcounter.Formatter.java
com.github.premnirmal.textcounter.formatters.CommaSeparatedDecimalFormatter.java
com.github.premnirmal.textcounter.formatters.DecimalFormatter.java
com.github.premnirmal.textcounter.formatters.IntegerFormatter.java
com.github.premnirmal.textcounter.formatters.NoFormatter.java
com.github.premnirmal.textcounterdemo.ParanormalActivity.java