Example usage for android.os CountDownTimer onFinish

List of usage examples for android.os CountDownTimer onFinish

Introduction

In this page you can find the example usage for android.os CountDownTimer onFinish.

Prototype

public abstract void onFinish();

Source Link

Document

Callback fired when the time is up.

Usage

From source file:org.messic.android.smartphone.activities.searchmessicservice.SearchMessicServiceActivity.java

public void onSearchServiceClick(View view) {
    this.buttonSearch.setEnabled(false);

    final CountDownTimer cdt = new CountDownTimer(15000, 1000) {
        @Override/* ww  w .  ja v a2 s  .co m*/
        public void onTick(long millisUntilFinished) {

            buttonSearch.setText(getString(R.string.searchMessicService_countdown_searching) + " ("
                    + (millisUntilFinished / 1000) + getString(R.string.searchMessicService_countdown_seconds)
                    + ")");
        }

        @Override
        public void onFinish() {
            buttonSearch.post(new Runnable() {
                public void run() {
                    buttonSearch.setEnabled(true);
                    buttonSearch.setText(R.string.searchMessicService_searchaction);
                }
            });
            presenter.cancelSearch();
        }
    };
    cdt.start();

    presenter.searchMessicServices(new MessicDiscovering.SearchListener() {
        public boolean messicServiceFound(final MDMMessicServerInstance md) {
            // let's see if the instance was found already
            if (!rvListAdapter.existInstance(md)) {
                SearchMessicServiceActivity.this.runOnUiThread(new Runnable() {
                    public void run() {
                        lempty.setVisibility(View.GONE);
                        if (rvListAdapter.addInstance(md)) {
                            rvListAdapter.notifyDataSetChanged();
                        }
                    }
                });

                cdt.cancel();
                cdt.onFinish();
                return true;
            }
            return false;
        }
    });
}