Code Monkey home page Code Monkey logo

timer's Introduction

Timer

============================ 一个倒计时类,除了可以开始取消倒计时,还可以暂停恢复倒计时,虽说时间一去不复返,我丫停停它总可以吧!为什么有暂停时间这种需求呢?一般来说,我们发送验证码,会有倒计时,一般都是90秒,这种一般只要开始,等结束就可以了。然后没收到,我们在重发!但是像玩游戏倒计时,有时候你有120秒玩游戏,中途比如你有别的任务,也就是支线要玩,但你又不想结束主线,毕竟都快把boss打到半条血了,所以,如果有个暂停时间,在恢复时间的,那就比较人性化了,这只是一个例子,其实可用的场景很多,啊哈哈。

使用说明

(1) 首先实例化DownTimer ,设置总的倒计时数字和多少秒后回调。

 DownTimer timer = new DownTimer();//实例化
        timer.setTotalTime(60*1000);//设置毫秒数
        timer.setIntervalTime(1000);//设置间隔数
        timer.setTimerLiener(new DownTimer.TimeListener() {
            @Override
            public void onFinish() {
                Toast.makeText(MainActivity.this, "完成倒计时", Toast.LENGTH_SHORT).show();
            }
            @Override
            public void onInterval(long remainTime) {
                tv_scend.setText("还剩" + remainTime / 1000+"秒就完成了");//剩余多少毫秒
            }
        });

(2) 然后就可以开始,结束,暂停,恢复 timer 了

            timer.start();
            
            timer.pause();
            
            timer.cancel();
            
            timer.resume();

timer's People

Contributors

android-cjj avatar

Watchers

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