public static double calculateTouchedTime( float touchPos, int startX, int graphWidth, WindData firstWindData, WindData lastWindData) { double translatedPos = touchPos - startX; double time = 24 * translatedPos / graphWidth; if (time < 0) time = 0; if (time > 24) time = 24; if (firstWindData != null && time < firstWindData.getStartTime()) { time = firstWindData.getStartTime() + 0.02; } if (lastWindData != null && time > lastWindData.getEndTime()) { time = lastWindData.getEndTime() - 0.02; } return time; }