예제 #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();
   }
 }