Back to project page sms-smap-gateway.
The source code is released under:
GNU General Public License
If you think the Android project sms-smap-gateway listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.android.smap.utils; /* www . j a v a 2 s.co m*/ import android.os.Handler; public class Refresher implements Runnable { public interface RefreshListener { public void onRefresh(); } private int mInterval; private final Handler mHandler; private final RefreshListener mListener; /** * @param refreshInterval * The interval to refresh, in milliseconds. * @param listener * The listener that's called when the refresh time is completed. */ public Refresher(int refreshInterval, RefreshListener listener) { if (refreshInterval <= 0) { throw new IllegalArgumentException(); } if (listener == null) { throw new IllegalArgumentException(); } mInterval = refreshInterval; mListener = listener; mHandler = new Handler(); } @Override public void run() { mListener.onRefresh(); start(); } public void start() { mHandler.postDelayed(this, mInterval); } public void stop() { mHandler.removeCallbacks(this); } public void reset() { stop(); start(); } public void setRefreshInterval(int time) { if (time <= 0) { throw new IllegalArgumentException(); } mInterval = time; reset(); } public int getRefreshInterval() { return mInterval; } }