Exemplo n.º 1
0
  private void updateSplits(long cumulativeTime, int cummulativeDistance, boolean reset) {
    MyLog.i("RaceTimerFragment", "updateSplits for Athlete " + mAthleteNumber);
    List<Split> splits = new ArrayList<>();

    if (reset) {
      tvAthletePace.setText(getActivity().getString(R.string.header_pace));
    } else {
      // gets the splits associated with the race Uuid
      splits = Split.getAllSplits(mRaceUuid, false);

      String paceAndDistance =
          CommonMethods.getAveragePaceString(
              cumulativeTime, cummulativeDistance, mPaceDistance, mPoolLengthUnits);

      if (mIsClockRunning) {
        paceAndDistance =
            paceAndDistance
                + CommonMethods.getEstimatedTotalDistance(
                    cumulativeTime, cummulativeDistance, mEventDurationMs, mPoolLengthUnits);
      }

      tvAthletePace.setText(paceAndDistance);
    }

    mSplitArrayAdapter.setData(splits);
    mSplitArrayAdapter.notifyDataSetChanged();
  }
Exemplo n.º 2
0
  @Override
  public void onClick(View v) {
    switch (v.getId()) {
      case R.id.btnEditAthlete:
        showEditAthleteDialog();
        break;

      case R.id.btnStart:
        // truncate time to tenths of seconds
        mStartTime = (System.currentTimeMillis() / 100) * 100;
        mIsClockRunning = true;
        new buttonVibration().execute();
        EventBus.getDefault().post(new MyEvents.startClock(mStartTime));
        EventBus.getDefault().post(new MyEvents.startRace(mAthleteNumber));
        startRace();
        break;

      case R.id.btnSplit:
        if (mIsClockRunning) {
          MyLog.i("RaceTimerFragment", "btnSplitClick Athlete" + mAthleteNumber);
          // truncate time to tenths of seconds
          long currentTime = (System.currentTimeMillis() / 100) * 100;
          new buttonVibration().execute();
          long mCumulativeTime = currentTime - mStartTime;
          long splitTime = mCumulativeTime - mPreviousCummulativeTime;
          mLapNumber++;
          int mCummulativeDistance = mLapNumber * mLapDistance;
          createSplit(
              mSelectedAthlete,
              mSelectedSwimEvent,
              mLapNumber,
              mCummulativeDistance,
              splitTime,
              mCumulativeTime);
          temporarilyDisableSplitButton();
        }
        break;

      case R.id.btnEmail:
        CommonMethods.sendRaceSummaryEmail(getActivity(), mSwimEventSummary);
        break;
    }
  }
Exemplo n.º 3
0
  private void completeRace(String lastLapDistanceString, String timerName, String eventLocation) {
    int lastLapDistance = Integer.valueOf(lastLapDistanceString);

    // create last split
    int totalDistance = (mLapNumber * mLapDistance) + lastLapDistance;
    String averagePaceString =
        CommonMethods.getAveragePaceString(
            mEventDurationMs, totalDistance, mPaceDistance, mPoolLengthUnits);
    long splitTime = mEventDurationMs - mPreviousCummulativeTime;

    createSplit(
        mSelectedAthlete,
        mSelectedSwimEvent,
        mLapNumber + 1,
        totalDistance,
        splitTime,
        mEventDurationMs);

    // create event summary
    mSwimEventSummary = new SwimEventSummary();
    mSwimEventSummary.newInstance(
        mRaceUuid,
        mSelectedSwimEvent,
        mSelectedAthlete,
        mStartTime,
        timerName,
        eventLocation,
        mPoolLength,
        mPoolLengthUnits,
        totalDistance,
        averagePaceString);
    mSwimEventSummary.pinInBackground();

    // Mark splits as Race Complete
    markSplitsRaceComplete();
    MyLog.i("RaceTimerFragment", "completeRace: for Athlete " + mAthleteNumber);
  }
Exemplo n.º 4
0
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    if (savedInstanceState != null) {
      MyLog.i("RaceTimerFragment", "onActivityCreated: savedInstanceState Not Null");
      if (savedInstanceState.containsKey(ARG_ATHLETE_NUMBER)) {
        mAthleteNumber = savedInstanceState.getInt(ARG_ATHLETE_NUMBER);
      }
      if (savedInstanceState.containsKey(ARG_RACE_UUID)) {
        mRaceUuid = savedInstanceState.getString(ARG_RACE_UUID);
      }
    } else {
      switch (mAthleteNumber) {
        case 1:
          mRaceUuid = MySettings.getAthlete1RaceUuid();
          break;
        case 2:
          mRaceUuid = MySettings.getAthlete2RaceUuid();
          break;
      }
    }

    MyLog.i(
        "RaceTimerFragment",
        "onActivityCreated: Athlete" + mAthleteNumber + "RaceUuid: " + mRaceUuid);
    if (mAthleteNumber == 1) {
      mLapDistance = MySettings.getLapDistance();
      mPaceDistance = MySettings.getPaceDistance();
      mPoolLength = MySettings.getPoolLength();
      mPoolLengthUnits = MySettings.getPoolLengthUnits();
      mEventDurationMs = MySettings.getEventDurationMinutes() * 60000;
      mSplitButtonDisableDurationMs = MySettings.getSplitButtonDisabledSeconds() * 1000;
    }

    int spnAthletesStartingPosition = 0;
    switch (mAthleteNumber) {
      case 1:
        if (!MySettings.getSelectedAthlete1ID().equals(MySettings.NOT_AVAILABLE)) {
          spnAthletesStartingPosition =
              mAthleteSpinnerAdapter.getItemPosition(MySettings.getSelectedAthlete1ID());
        }
        break;

      case 2:
        if (!MySettings.getSelectedAthlete2ID().equals(MySettings.NOT_AVAILABLE)) {
          spnAthletesStartingPosition =
              mAthleteSpinnerAdapter.getItemPosition(MySettings.getSelectedAthlete2ID());
        }
        break;
    }
    mOkToResetLapCounter = false;
    spnAthletes.setSelection(spnAthletesStartingPosition);
    mIsClockRunning = false;

    String pace = getActivity().getString(R.string.header_pace);
    if (mSplitsOfCompletedRace.size() > 0) {
      Split lastSplit = mSplitsOfCompletedRace.get(0);
      long cummulativeDurationMs = lastSplit.getAccumulativeTimeMs();
      int cummulativeDistance = lastSplit.getDistance();
      pace =
          CommonMethods.getAveragePaceString(
              cummulativeDurationMs, cummulativeDistance, mPaceDistance, mPoolLengthUnits);
    }
    tvAthletePace.setText(pace);
  }