예제 #1
0
  /**
   * * Handle action when user presses the lap button
   *
   * @param time - in hundredth of a second
   */
  private void addLapTime(long time) {
    // The total elapsed time
    final long curTime = time - mStartTime + mAccumulatedTime;
    int size = mLapsAdapter.getCount();
    if (size == 0) {
      // Create and add the first lap
      Lap firstLap = new Lap(curTime, curTime);
      mLapsAdapter.addLap(firstLap);
      // Create the first active lap
      mLapsAdapter.addLap(new Lap(0, curTime));
      // Update the interval on the clock and check the lap and total time formatting
      mTime.setIntervalTime(curTime);
      mLapsAdapter.updateTimeFormats(firstLap);
    } else {
      // Finish active lap
      final long lapTime = curTime - mLapsAdapter.getItem(1).mTotalTime;
      mLapsAdapter.getItem(0).mLapTime = lapTime;
      mLapsAdapter.getItem(0).mTotalTime = curTime;
      // Create a new active lap
      mLapsAdapter.addLap(new Lap(0, curTime));
      // Update marker on clock and check that formatting for the lap number
      mTime.setMarkerTime(lapTime);
      mLapsAdapter.updateLapFormat();
    }
    // Repaint the laps list
    mLapsAdapter.notifyDataSetChanged();

    // Start lap animation starting from the second lap
    mTime.stopIntervalAnimation();
    if (!reachedMaxLaps()) {
      mTime.startIntervalAnimation();
    }
  }
예제 #2
0
  /** Show or hide the laps-list */
  private void showLaps() {
    if (DEBUG)
      Log.v(
          LOG_TAG, String.format("StopwatchFragment.showLaps: count=%d", mLapsAdapter.getCount()));

    boolean lapsVisible = mLapsAdapter.getCount() > 0;

    // Layout change animations will start upon the first add/hide view. Temporarily disable
    // the layout transition animation for the spacers, make the changes, then re-enable
    // the animation for the add/hide laps-list
    if (mSpacersUsed) {
      int spacersVisibility = lapsVisible ? View.GONE : View.VISIBLE;
      ViewGroup rootView = (ViewGroup) getView();
      if (rootView != null) {
        rootView.setLayoutTransition(null);
        if (mStartSpace != null) {
          mStartSpace.setVisibility(spacersVisibility);
        }
        if (mEndSpace != null) {
          mEndSpace.setVisibility(spacersVisibility);
        }
        rootView.setLayoutTransition(mLayoutTransition);
      }
    }

    if (lapsVisible) {
      // There are laps - show the laps-list
      // No delay for the CircleButtonsLayout changes - start immediately so that the
      // circle has shifted before the laps-list starts appearing.
      mCircleLayoutTransition.setStartDelay(LayoutTransition.CHANGING, 0);

      mLapsList.setVisibility(View.VISIBLE);
    } else {
      // There are no laps - hide the laps list

      // Delay the CircleButtonsLayout animation until after the laps-list disappears
      long startDelay =
          mLayoutTransition.getStartDelay(LayoutTransition.DISAPPEARING)
              + mLayoutTransition.getDuration(LayoutTransition.DISAPPEARING);
      mCircleLayoutTransition.setStartDelay(LayoutTransition.CHANGING, startDelay);
      mLapsList.setVisibility(View.GONE);
    }
  }
예제 #3
0
 @Override
 public void run() {
   long curTime = Utils.getTimeNow();
   long totalTime = mAccumulatedTime + (curTime - mStartTime);
   if (mTime != null) {
     mTimeText.setTime(totalTime, true, true);
   }
   if (mLapsAdapter.getCount() > 0) {
     updateCurrentLap(totalTime);
   }
   mTime.postDelayed(mTimeUpdateThread, 10);
 }
예제 #4
0
 private void updateCurrentLap(long totalTime) {
   // There are either 0, 2 or more Laps in the list See {@link #addLapTime}
   if (mLapsAdapter.getCount() > 0) {
     Lap curLap = mLapsAdapter.getItem(0);
     curLap.mLapTime = totalTime - mLapsAdapter.getItem(1).mTotalTime;
     curLap.mTotalTime = totalTime;
     // If this lap has caused a change in the format for total and/or lap time, all of
     // the rows need a fresh print. The simplest way to refresh all of the rows is
     // calling notifyDataSetChanged.
     if (mLapsAdapter.updateTimeFormats(curLap)) {
       mLapsAdapter.notifyDataSetChanged();
     } else {
       curLap.updateView();
     }
   }
 }
예제 #5
0
  /**
   * Make the final display setup.
   *
   * <p>If the fragment is starting with an existing list of laps, shows the laps list and if the
   * spacers around the clock exist, hide them. If there are not laps at the start, hide the laps
   * list and show the clock spacers if they exist.
   */
  @Override
  public void onStart() {
    super.onStart();

    boolean lapsVisible = mLapsAdapter.getCount() > 0;

    mLapsList.setVisibility(lapsVisible ? View.VISIBLE : View.GONE);
    if (mSpacersUsed) {
      int spacersVisibility = lapsVisible ? View.GONE : View.VISIBLE;
      if (mStartSpace != null) {
        mStartSpace.setVisibility(spacersVisibility);
      }
      if (mEndSpace != null) {
        mEndSpace.setVisibility(spacersVisibility);
      }
    }
    ((ViewGroup) getView()).setLayoutTransition(mLayoutTransition);
    mCircleLayout.setLayoutTransition(mCircleLayoutTransition);
  }
예제 #6
0
 private boolean reachedMaxLaps() {
   return mLapsAdapter.getCount() >= Stopwatches.MAX_LAPS;
 }