예제 #1
0
  public void refreshData(Room room) {
    calendarFrame = (FrameLayout) findViewById(R.id.frameLayout1);
    calendarFrame.removeAllViews();
    List<Reservation> reservations = new ArrayList<Reservation>();

    DateTime startOfToday = new DateTime().setTime(0, 0, 0);
    TimeSpan day =
        new TimeSpan(
            startOfToday.add(Calendar.MINUTE, DAY_START_TIME),
            startOfToday.add(Calendar.MINUTE, DAY_END_TIME));

    for (int i = 0; i < NUMBER_OF_DAYS_TO_SHOW; i++) {
      List<Reservation> dayReservations = room.getReservationsForTimeSpan(day);
      List<Reservation> boundDayReservations = new ArrayList<Reservation>(dayReservations.size());

      // Change multi-day reservations to span only this day
      for (Reservation res : dayReservations) {
        if (res.getStartTime().before(day.getStart()) || res.getEndTime().after(day.getEnd())) {
          boundDayReservations.add(
              new Reservation(
                  res.getId() + "-" + day.getStart(),
                  res.getSubject(),
                  new TimeSpan(
                      res.getStartTime().before(day.getStart())
                          ? day.getStart()
                          : res.getStartTime(),
                      res.getEndTime().after(day.getEnd()) ? day.getEnd() : res.getEndTime())));
        } else {
          boundDayReservations.add(res);
        }
      }

      reservations.addAll(boundDayReservations);

      // Advance to next day
      day =
          new TimeSpan(
              day.getStart().add(Calendar.DAY_OF_YEAR, 1),
              day.getEnd().add(Calendar.DAY_OF_YEAR, 1));
    }

    CalendarVisualizer cv = new CalendarVisualizer(getContext(), DAY_START_TIME, DAY_END_TIME);
    cv.setReservations(reservations);
    calendarFrame.addView(cv, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    cv.setOnClickListener(this);
    return;
  }
  private void setReservationInfo(Reservation r, TimeSpan nextFreeSlot) {
    if (r == null) {
      roomStatusInfoView.setVisibility(GONE);
    } else {
      roomStatusInfoView.setText(r.getSubject());
      roomStatusInfoView.setVisibility(VISIBLE);
    }

    if (nextFreeSlot == null) {
      // More than a day away
      reservationInfoView.setVisibility(GONE);
    } else {
      reservationInfoView.setText(
          Html.fromHtml(
              String.format(
                  "Free at <b>%02d:%02d</b>",
                  nextFreeSlot.getStart().get(Calendar.HOUR_OF_DAY),
                  nextFreeSlot.getStart().get(Calendar.MINUTE))));
      reservationInfoView.setVisibility(VISIBLE);
    }
  }