Пример #1
0
 /** 停止计时器 */
 public void stopTimer() {
   if (listener != null) {
     listener.onTimerStop();
   }
   //		Log.w(TAG, "stopTimer<<<<<<<< " + TimeUtil.getTime(System.currentTimeMillis()));
   if (timer != null) {
     timer.cancel();
     timer = null;
   }
   if (task != null) {
     task.cancel();
     task = null;
   }
   //		Log.w(TAG, "stopTimer>>>>>>> " + TimeUtil.getTime(System.currentTimeMillis()));
 }
Пример #2
0
    /** 启动计时器 */
    public void startTimer() {
      if (listener == null) {
        Log.e(TAG, "startTimer  listener == null >> return;");
        return;
      }

      //		Log.w(TAG, "startTimer<<<<<<<< " + TimeUtil.getTime(System.currentTimeMillis()));
      stopTimer();

      listener.onTimerStart();
      if (timer == null) {
        timer = new Timer(true);
      }
      if (task == null) {
        task =
            new TimerTask() {
              public void run() {
                handler.sendEmptyMessage(0);
              }
            };
      }
      timer.schedule(task, 0, duration); // 延时0ms后执行,1000ms执行一次
      //		Log.w(TAG, "startTimer >>>>>>> " + TimeUtil.getTime(System.currentTimeMillis()));
    }
Пример #3
0
 public void handleMessage(Message msg) {
   super.handleMessage(msg);
   listener.onTimerRefresh();
 }