示例#1
0
 /** Resets the timer. */
 public void reset() {
   mStartTimeMillis = 0;
   mPauseTimeMillis = 0;
   if (mListener != null) {
     mListener.onPause();
     mListener.onReset();
   }
 }
示例#2
0
 /** Pauses the timer. */
 public void pause() {
   if (isStarted()) {
     mPauseTimeMillis = getElapsedRealtime();
     if (mListener != null) {
       mListener.onPause();
     }
   }
 }
示例#3
0
  /** Starts the timer. */
  public void start() {
    long elapsedTime = mPauseTimeMillis - mStartTimeMillis;

    mStartTimeMillis = getElapsedRealtime() - elapsedTime;
    mPauseTimeMillis = 0;
    if (mListener != null) {
      mListener.onStart();
    }
  }
示例#4
0
 @Override
 public void onClick(View view) {
   Log.v("TIMER FRAGMENT", "Start Indicator Boolean " + startIndicatorBool);
   if (!startIndicatorBool) {
     createTime();
   } else {
     Intent intent = new Intent();
     intent.setAction(TimerService.BundleKey.UPDATE_TIMER_SETTINGS);
     intent.putExtra(TimerService.BundleKey.START, true);
     getActivity().sendBroadcast(intent);
     if (mCallback != null) // TODO MAYBE CAN REMOVE NULL CHECK .put as precaution
     {
       mCallback.onTimerStarted();
     }
   }
 }
示例#5
0
  public void run() {
    boolean timeoutIsReached = false;
    logger.info("Starting process with timeout=" + timeout + " s");

    try {
      int elapsedTimeInSecond = 0;
      while ((elapsedTimeInSecond < timeout) && (isRunning == true)) {
        sleep(StreamListener.PRINTING_PERIOD_IN_MILLIS);
        elapsedTimeInSecond++;
      }
      timeoutIsReached = true;
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    if (timeoutIsReached) {
      logger.info("Ending process with timeout=" + timeout + " s");
      listener.onTimeout();
    } else {
      logger.info("Ending process upon InterruptedException");
    }
    logger.debug("ProcessTimer: end of run()");
  }
 /**
  * Notify all the listeners from this collection. This method should be called whenever the given
  * timer's delay period elapses.
  *
  * @param sender The timer who has generated the event.
  */
 public void fireTimer(Timer sender) {
   for (TimerListener listener : this) {
     listener.onElapsed(sender);
   }
 }
示例#7
0
 /** Sets the timer's duration in milliseconds. */
 public void setDurationMillis(long durationMillis) {
   mDurationMillis = durationMillis;
   if (mListener != null) {
     mListener.onReset();
   }
 }