/** * * 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(); } }
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(); } } }