public LayoutInfo getViewLayout(TimeLine timeline) {
GregorianCalendar now = new GregorianCalendar();
final int nowHour = now.get(GregorianCalendar.HOUR_OF_DAY);
final int nowMin = now.get(GregorianCalendar.MINUTE);
TimeLineXml model = timeline.getXmlModel();
ArrayList<Schedule> schedules = new ArrayList<Schedule>(model.getSchedule());
Collections.reverse(schedules);
for (Schedule schedule : schedules) {
boolean before = true;
if (schedule.getStart() != null) {
final GregorianCalendar start = schedule.getStart().toGregorianCalendar();
final int startHour = start.get(GregorianCalendar.HOUR_OF_DAY);
final int startMin = start.get(GregorianCalendar.MINUTE);
before = startHour < nowHour || startHour == nowHour && startMin <= nowMin;
}
boolean after = true;
GregorianCalendar end = now;
end.add(GregorianCalendar.DAY_OF_MONTH, 1);
end.set(GregorianCalendar.HOUR_OF_DAY, 0);
end.set(GregorianCalendar.MINUTE, 0);
end.set(GregorianCalendar.SECOND, 0);
end.set(GregorianCalendar.MILLISECOND, 0);
if (schedule.getEnd() != null) {
end = schedule.getEnd().toGregorianCalendar();
final int endHour = end.get(GregorianCalendar.HOUR_OF_DAY);
final int endMin = end.get(GregorianCalendar.MINUTE);
after = endHour > nowHour || endHour == nowHour && endMin >= nowMin;
}
if (before && after) {
for (Block block : model.getBlock()) {
if (block.getId().equals(schedule.getBlockId())) {
LayoutService layoutService = new LayoutService();
LayoutInfo result = new LayoutInfo();
result.layout = layoutService.get(timeline.getManagerRef().getModel(), Long.parseLong(block.getLayoutId()));
result.reloadTime = end.getTime();