public long getTimeReportedBetween(long aStartTime, long anEndTime) { long time = 0; ArrayList thePeriods = getPeriods(aStartTime, anEndTime); Period thePeriod = null; for (int i = 0; i < thePeriods.size(); i++) { thePeriod = (Period) thePeriods.get(i); long theStartTime = thePeriod.getStartTime(); long theEndTime = thePeriod.getEndTime(); if (theStartTime < aStartTime) theStartTime = aStartTime; if (theEndTime == -1) theEndTime = System.currentTimeMillis(); if (theEndTime > anEndTime) theEndTime = anEndTime; time += (theEndTime - theStartTime); } return time; }
public void getPeriods(ArrayList container, long aStartTime, long anEndTime) { if (getChildCount() > 0) { for (int i = 0; i < getChildCount(); i++) { ((Task) getChildAt(i)).getPeriods(container, aStartTime, anEndTime); } } else { Period thePeriod = null; for (int i = 0; i < periods.size(); i++) { thePeriod = (Period) periods.get(i); long theEndTime = thePeriod.getEndTime(); if (theEndTime == -1) theEndTime = System.currentTimeMillis(); if ((anEndTime == -1 || thePeriod.getStartTime() < anEndTime) && (aStartTime == -1 || theEndTime > aStartTime)) { container.add(thePeriod); } } } }