Awesome Open Source
Awesome Open Source

CountDownTask

CountDownTask is a countdown library. It can work with a single view or a adapter view, etc.

中文: http://mo0n1andin.github.io/android-case-abslistview-count-down

Gradle

compile 'com.github.erehmi:countdowntask:1.0.1'

Usage

Create a countdown task:

CountDownTask countDownTask = CountDownTask.create()

Build the target time since the system was booted, and include deep sleep. For example, 6 seconds later:

long targetMillis = CountDownTask.elapsedRealtime() + 1000 * 60;

Apply the countdown to a view, e.g. a TextView, and 1 second countdown interval:

final int CD_INTERVAL = 1000;

countDownTask.until(textView, targetMillis, CD_INTERVAL, new OnCountDownListener() {
    @Override
    public void onTick(View view, long millisUntilFinished) {
        ((TextView)view).setText(String.valueOf(millisUntilFinished / CD_INTERVAL));
    }
    @Override
    public void onFinish(View view) {
        ((TextView)view).setText("DONE.");
    }
});

When the count task is no longer needed, cancel it:

countDownTask.cancel(textView);

or

countDownTask.cancel();

Example

License

Copyright 2016, mo0n1andin

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
java (31,347
android (6,290
recyclerview (252
timer (87
utils (79
listview (68
countdown (26
gridview (16