Example #1
0
 public boolean compareTime(TimeObject startTime, TimeObject endTime) {
   if (startTime.getYear() > endTime.getYear()) return false;
   if (startTime.getMonth() > endTime.getMonth()) return false;
   if (startTime.getDay() > endTime.getDay()) return false;
   if (startTime.getHour() > endTime.getHour()) return false;
   if (startTime.getMinute() > endTime.getMinute()) return false;
   return true;
 }
Example #2
0
 private void setEndTime(final TimeObject startTime) {
   LinearLayout layout = new LinearLayout(PlayBackActivity.this);
   layout.setOrientation(LinearLayout.VERTICAL);
   layout.setBackgroundColor(getResources().getColor(R.color.white));
   final TimePicker mTimePicker = new TimePicker(PlayBackActivity.this);
   final DatePicker mDatePicker = new DatePicker(PlayBackActivity.this);
   mTimePicker.setDescendantFocusability(TimePicker.FOCUS_BLOCK_DESCENDANTS);
   mTimePicker.setIs24HourView(true);
   mDatePicker.setDescendantFocusability(DatePicker.FOCUS_BLOCK_DESCENDANTS);
   final TextView tv = new TextView(PlayBackActivity.this);
   String time = String.format("%02d:%02d", startTime.getHour(), startTime.getMinute());
   String date =
       String.valueOf(startTime.getYear())
           + "年"
           + String.format("%02d", startTime.getMonth())
           + "月"
           + String.format("%02d", startTime.getDay())
           + "日";
   tv.setText("开始时间:" + date + "  " + time);
   int version = Integer.valueOf(android.os.Build.VERSION.SDK);
   if (version >= 11) mDatePicker.setCalendarViewShown(false);
   layout.addView(tv, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
   layout.addView(
       mDatePicker, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
   layout.addView(
       mTimePicker, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
   new AlertDialog.Builder(PlayBackActivity.this)
       .setTitle("请选择结束时间:")
       .setView(layout)
       .setPositiveButton(
           android.R.string.ok,
           new DialogInterface.OnClickListener() {
             @Override
             public void onClick(DialogInterface arg0, int arg1) {
               TimeObject endTime =
                   new TimeObject(
                       mTimePicker.getCurrentMinute(),
                       mTimePicker.getCurrentHour(),
                       mDatePicker.getDayOfMonth(),
                       mDatePicker.getMonth() + 1,
                       mDatePicker.getYear());
               System.out.println("时间:" + endTime.getMinute() + "  " + startTime.getMinute());
               onTimeSearch(startTime, endTime);
             }
           })
       .setNegativeButton(
           android.R.string.cancel,
           new DialogInterface.OnClickListener() {
             @Override
             public void onClick(DialogInterface arg0, int arg1) {}
           })
       .create()
       .show();
 }
Example #3
0
  public void loadXml(Element root) throws Exception {
    if (!root.getName().equalsIgnoreCase("roomSharing")) {
      throw new Exception("Given XML file is not a Room Sharing load file.");
    }
    try {
      beginTransaction();

      String campus = root.attributeValue("campus");
      String year = root.attributeValue("year");
      String term = root.attributeValue("term");
      iTimeFormat = root.attributeValue("timeFormat");
      if (iTimeFormat == null) iTimeFormat = "HHmm";

      Session session = Session.getSessionUsingInitiativeYearTerm(campus, year, term);
      if (session == null) {
        throw new Exception("No session found for the given campus, year, and term.");
      }

      if (!"true".equals(root.attributeValue("force"))
          && Solution.hasTimetable(session.getUniqueId())) {
        info(
            "Note: set the attribute force='true' of the root element to override the following import eligibility check.");
        throw new Exception(
            "Room sharing import is disabled: "
                + session.getLabel()
                + " already has a committed timetable.");
      }

      info("Loading rooms...");
      Set<String> avoidRoomId = new HashSet<String>();
      Set<String> avoidRoomName = new HashSet<String>();
      Map<String, Location> id2location = new HashMap<String, Location>();
      Map<String, Location> name2location = new HashMap<String, Location>();
      for (Location location :
          (List<Location>)
              getHibSession()
                  .createQuery("from Location where session.uniqueId = :sessionId")
                  .setLong("sessionId", session.getUniqueId())
                  .list()) {
        if (location.getExternalUniqueId() != null && !avoidRoomId.contains(avoidRoomId)) {
          Location old = id2location.put(location.getExternalUniqueId(), location);
          if (old != null) {
            warn(
                "There are two or more rooms with the same external id "
                    + location.getExternalUniqueId()
                    + ": "
                    + location.getLabel()
                    + " and "
                    + old.getLabel()
                    + ".");
            avoidRoomId.add(location.getExternalUniqueId());
          }
        }
        if (!avoidRoomName.contains(location.getLabel())) {
          Location old = name2location.put(location.getLabel(), location);
          if (old != null) {
            warn("There are two or more rooms with the same name " + location.getLabel() + ".");
            avoidRoomName.add(location.getLabel());
          }
        }
      }

      info("Loading departments...");
      Map<String, Department> id2department = new HashMap<String, Department>();
      Map<String, Department> code2department = new HashMap<String, Department>();
      for (Department dept :
          (List<Department>)
              getHibSession()
                  .createQuery("from Department where session.uniqueId = :sessionId")
                  .setLong("sessionId", session.getUniqueId())
                  .list()) {
        if (dept.getExternalUniqueId() != null) {
          Department old = id2department.put(dept.getExternalUniqueId(), dept);
          if (old != null) {
            warn(
                "There are two departments with the same external id "
                    + dept.getExternalUniqueId()
                    + ": "
                    + dept.getLabel()
                    + " and "
                    + old.getLabel()
                    + ".");
          }
        }
        Department old = code2department.put(dept.getDeptCode(), dept);
        if (old != null) {
          warn(
              "There are two rooms with the same code "
                  + dept.getDeptCode()
                  + ": "
                  + dept.getName()
                  + " and "
                  + old.getName()
                  + ".");
        }
      }

      info("Importing room sharing...");
      int nrChanged = 0;
      for (Iterator i = root.elementIterator("location"); i.hasNext(); ) {
        Element locEl = (Element) i.next();
        Location location = null;

        String locId = locEl.attributeValue("id");
        if (locId != null && !avoidRoomId.contains(locId)) {
          location = id2location.get(locId);
          if (location == null) warn("Location of id " + locId + " does not exist.");
        }

        if (location == null) {
          String building = locEl.attributeValue("building");
          String roomNbr = locEl.attributeValue("roomNbr");
          if (building != null
              && roomNbr != null
              && !avoidRoomName.contains(building + " " + roomNbr)) {
            location = name2location.get(building + " " + roomNbr);
            if (location == null)
              warn(
                  "Location of building "
                      + building
                      + " and room number "
                      + roomNbr
                      + " does not exist.");
          }
        }

        if (location == null) {
          String name = locEl.attributeValue("name");
          if (name != null && !avoidRoomName.contains(name)) {
            location = name2location.get(name);
            if (location == null) warn("Location of name " + name + " does not exist.");
          }
        }

        if (location == null) continue;

        Set<RoomDept> existing = new HashSet<RoomDept>(location.getRoomDepts());
        Set<Department> departments = new HashSet<Department>();
        boolean changed = false;

        String note = locEl.attributeValue("note");
        if (note == null && location.getShareNote() != null) {
          location.setShareNote(null);
          info(location.getLabel() + ": share note removed.");
          changed = true;
        } else if (note != null && !note.equals(location.getShareNote())) {
          location.setShareNote(note);
          info(location.getLabel() + ": share note changed to '" + note + "'.");
          changed = true;
        }

        department:
        for (Iterator j = locEl.elementIterator("department"); j.hasNext(); ) {
          Element deptEl = (Element) j.next();
          Department dept = null;

          String deptId = deptEl.attributeValue("id");
          if (deptId != null) {
            dept = id2department.get(deptId);
            if (dept == null)
              warn(location.getLabel() + ": Department of id " + deptId + " does not exist.");
          }

          String deptCode = deptEl.attributeValue("code");
          if (deptCode != null) {
            dept = code2department.get(deptCode);
            if (dept == null)
              warn(location.getLabel() + ": Department of code " + deptCode + " does not exist.");
          }

          if (dept == null) continue;
          Boolean control = "true".equals(deptEl.attributeValue("control"));

          for (Iterator<RoomDept> k = existing.iterator(); k.hasNext(); ) {
            RoomDept rd = k.next();
            if (rd.getDepartment().equals(dept)) {
              if (!control.equals(rd.getControl())) {
                rd.setControl(control);
                getHibSession().update(rd);
                info(
                    location.getLabel()
                        + ": "
                        + (control
                            ? " control moved to " + dept.getLabel()
                            : " control removed from " + dept.getLabel()));
                changed = true;
              }
              k.remove();
              departments.add(dept);
              continue department;
            }
          }

          RoomDept rd = new RoomDept();
          rd.setControl(control);
          rd.setDepartment(dept);
          rd.setRoom(location);
          location.getRoomDepts().add(rd);
          dept.getRoomDepts().add(rd);
          getHibSession().save(rd);
          departments.add(dept);
          info(
              location.getLabel()
                  + ": added "
                  + (control ? "controlling " : "")
                  + " department"
                  + dept.getLabel());
          changed = true;
        }

        for (RoomDept rd : existing) {
          info(
              location.getLabel()
                  + ": removed "
                  + (rd.isControl() ? "controlling " : "")
                  + " department"
                  + rd.getDepartment().getLabel());
          location.getRoomDepts().remove(rd);
          rd.getDepartment().getRoomDepts().remove(rd);
          getHibSession().delete(rd);
          changed = true;
        }

        RoomSharingModel model = location.getRoomSharingModel();
        String oldModel = model.toString();
        model.setPreferences(null);

        Element sharingEl = locEl.element("sharing");
        if (sharingEl != null) {
          for (Iterator j = sharingEl.elementIterator(); j.hasNext(); ) {
            Element el = (Element) j.next();
            TimeObject time =
                new TimeObject(
                    el.attributeValue("start"),
                    el.attributeValue("end"),
                    el.attributeValue("days"));

            String pref = null;
            if ("unavailable".equals(el.getName())) {
              pref = RoomSharingModel.sNotAvailablePref.toString();
            } else if ("assigned".equals(el.getName())) {
              Department dept = null;

              String deptId = el.attributeValue("id");
              if (deptId != null) {
                dept = id2department.get(deptId);
                if (dept == null)
                  warn(location.getLabel() + ": Department of id " + deptId + " does not exist.");
              }

              String deptCode = el.attributeValue("code");
              if (deptCode != null) {
                dept = code2department.get(deptCode);
                if (dept == null)
                  warn(
                      location.getLabel()
                          + ": Department of code "
                          + deptCode
                          + " does not exist.");
              }

              if (dept == null) continue;
              if (!departments.contains(dept)) {
                warn(
                    location.getLabel()
                        + ": Department "
                        + dept.getLabel()
                        + " is not among the room sharing departments.");
                continue;
              }

              pref = dept.getUniqueId().toString();
            }

            if (pref == null) continue;

            if (time.hasDays()) {
              for (int d : time.getDays())
                for (int t = time.getStartPeriod(); t < time.getEndPeriod(); t++)
                  model.setPreference(d, t, pref);
            } else {
              for (int d = 0; d < model.getNrDays(); d++)
                for (int t = time.getStartPeriod(); t < time.getEndPeriod(); t++)
                  model.setPreference(d, t, pref);
            }
          }
        }

        String newModel = model.toString();
        if (!oldModel.equals(newModel)) {
          info(
              location.getLabel()
                  + ": room sharing changed to "
                  + (newModel.isEmpty() ? "free for all" : newModel));
          changed = true;
        }

        location.setRoomSharingModel(model);
        getHibSession().update(location);

        if (changed) nrChanged++;
      }

      if (nrChanged == 0) {
        info("No change detected.");
      } else {
        info(nrChanged + " locations have changed.");
      }
      info("All done.");

      commitTransaction();
    } catch (Exception e) {
      fatal("Exception: " + e.getMessage(), e);
      rollbackTransaction();
      throw e;
    }
  }
Example #4
0
 private void onTimeSearch(TimeObject startTime, TimeObject endTime) {
   // mFileDataList = new ArrayList<FileData>();
   FindInfo findInfo = new FindInfo();
   findInfo.startTime.year = startTime.getYear();
   findInfo.startTime.month = startTime.getMonth();
   findInfo.startTime.day = startTime.getDay();
   findInfo.startTime.hour = startTime.getHour();
   findInfo.startTime.minute = startTime.getMinute();
   findInfo.startTime.second = 0;
   findInfo.endTime.year = endTime.getYear();
   findInfo.endTime.month = endTime.getMonth();
   findInfo.endTime.day = endTime.getDay();
   findInfo.endTime.hour = endTime.getHour();
   findInfo.endTime.minute = endTime.getMinute();
   findInfo.endTime.second = 0;
   findInfo.nChannelN0 = 0;
   findInfo.nFileType = 0;
   findInfo.szFileName = "";
   if (mWndSelected >= channelNum) findInfo.nChannelN0 = 0;
   else findInfo.nChannelN0 = mWndSelected;
   int position = 0;
   for (int i : Channel) {
     if (i == findInfo.nChannelN0) {
       onStopChn(position);
     }
     position++;
   }
   mlPlayHandle[mWndSelected] = mNetSdk.PlayBackByTime(mWndSelected, mLoginId, findInfo, 1, 1);
   if (mlPlayHandle[mWndSelected] > 0 && compareTime(startTime, endTime)) {
     mPlayState = PlayState.MPS_PLAYING;
     getMySurface(mWndSelected).initData();
     ReviewState[mWndSelected] = 1;
     Channel[mWndSelected] = findInfo.nChannelN0;
     Toast.makeText(getApplicationContext(), "打开成功", Toast.LENGTH_SHORT).show();
     mStartTime[mWndSelected] =
         findInfo.startTime.hour * 3600
             + findInfo.startTime.minute * 60
             + findInfo.startTime.second;
     mEndTime[mWndSelected] =
         findInfo.endTime.hour * 3600 + findInfo.endTime.minute * 60 + findInfo.endTime.second;
     mTotalTime[mWndSelected] = (mEndTime[mWndSelected] - mStartTime[mWndSelected]);
     timeSeek.setMax(mTotalTime[mWndSelected]);
     timeSeek.setProgress(0);
     getMySurface(mWndSelected).setOnPlayBackPosListener(onPlayBackPosLs);
     System.out.println(
         "录像长度:"
             + mTotalTime[mWndSelected]
             + " "
             + mStartTime[mWndSelected]
             + " "
             + mEndTime[mWndSelected]);
     myListPart.setVisibility(View.INVISIBLE);
   } else {
     Toast.makeText(getApplicationContext(), "打开失败,请检查输入时间是否正确...", Toast.LENGTH_SHORT).show();
   }
 }