private Event cursorToEvent(Cursor cursor) {
    Event event = new EventImpl();
    event.setID(cursor.getLong(0));

    long ts = cursor.getLong(1);
    Timestamp timestamp = new Timestamp(ts);
    event.setTimestamp(timestamp);

    event.setTitle(cursor.getString(2));
    event.setUser(cursor.getString(3));

    ts = cursor.getLong(4);
    timestamp = new Timestamp(ts);
    event.setStartTime(timestamp);

    ts = cursor.getLong(5);
    timestamp = new Timestamp(ts);
    event.setEndTime(timestamp);

    event.setDescription(cursor.getString(6));

    event.setProfilePicURI(cursor.getString(7));

    return event;
  }
  /**
   * Gets the all events.
   *
   * @return the all events
   */
  public List<Event> getAllEvents() {
    List<Event> events = new ArrayList<Event>();
    String selectQuery = "SELECT  * FROM " + TABLE_EVENT;

    Log.e(LOG, selectQuery);

    SQLiteDatabase db = this.getReadableDatabase();
    Cursor c = db.rawQuery(selectQuery, null);

    // looping through all rows and adding to list
    if (c.moveToFirst()) {
      do {
        Event ev = new Event();
        ev.setId(c.getInt((c.getColumnIndex(KEY_ID))));
        ev.setTitle((c.getString(c.getColumnIndex(KEY_EVENT_TITLE))));
        ev.setStartDate((c.getString(c.getColumnIndex(KEY_EVENT_STARTDATE))));
        ev.setEndDate((c.getString(c.getColumnIndex(KEY_EVENT_ENDDATE))));
        ev.setStartTime((c.getString(c.getColumnIndex(KEY_EVENT_STARTTIME))));
        ev.setEndTime((c.getString(c.getColumnIndex(KEY_EVENT_ENDTIME))));
        ev.setDescription((c.getString(c.getColumnIndex(KEY_EVENT_DESCRIPTION))));
        ev.setRepeat((c.getString(c.getColumnIndex(KEY_EVENT_REPEAT))));

        // adding to event list
        events.add(ev);
      } while (c.moveToNext());
    }
    return events;
  }
Exemplo n.º 3
0
  public static Event createEvent() {
    Event event = new Event();

    event.setDateCreated(new Date());
    event.setDescription(randomString("description", 2000));
    event.setCategory(randomString("category", 50));

    return event;
  }
 /*
  * get top 3 (today and tomorrow) events that most people are attending
  */
 public ArrayList<Event> getDayHotEvent() {
   ArrayList<Event> list = new ArrayList<Event>();
   String query = " SELECT a.att_evn_id, e.* , COUNT(att_evn_id) AS count ";
   query += " FROM tb_events e JOIN tb_attending a ON e.evn_id = a.att_evn_id ";
   query += " WHERE evn_start_time BETWEEN now() AND DATE_ADD(NOW(), INTERVAL 1 DAY) ";
   query += " GROUP BY a.att_evn_id ";
   query += " ORDER BY COUNT(att_evn_id) DESC LIMIT 3";
   List<HashMap<String, String>> result =
       DBComunicationLayer.executeHttpPost(DBComunicationLayer.PHP_SELECT, query);
   Log.i(LOG_TAG, query);
   for (int i = 1; i < result.size(); i++) {
     Event e = new Event();
     for (Map.Entry<String, String> item : result.get(i).entrySet()) {
       if (item.getKey().equalsIgnoreCase("evn_id")) {
         e.setId(item.getValue().trim());
       } else if (item.getKey().equalsIgnoreCase("evn_titile")) {
         e.setTitle(item.getValue().trim());
       } else if (item.getKey().equalsIgnoreCase("evn_description")) {
         e.setDescription(item.getValue().trim());
       } else if (item.getKey().equalsIgnoreCase("evn_location")) {
         e.setLocation(item.getValue().trim());
       } else if (item.getKey().equalsIgnoreCase("evn_start_time")) {
         e.setStartDayTime(item.getValue().trim());
       } else if (item.getKey().equalsIgnoreCase("evn_end_time")) {
         e.setEndDayTime(item.getValue().trim());
       } else if (item.getKey().equalsIgnoreCase("evn_created_time")) {
         e.setCreatedDayTime(item.getValue().trim());
       } else if (item.getKey().equalsIgnoreCase("evn_contact_info")) {
         e.setContact(item.getValue().trim());
       } else if (item.getKey().equalsIgnoreCase("evn_cat_id")) {
         e.setCategory(item.getValue().trim());
       } else if (item.getKey().equalsIgnoreCase("evn_url")) {
         e.setUrl(item.getValue().trim());
       } else if (item.getKey().equalsIgnoreCase("evn_count_like")) {
         e.setLike(item.getValue().trim());
       } else if (item.getKey().equalsIgnoreCase("evn_count_dislike")) {
         e.setDislike(item.getValue().trim());
       } else if (item.getKey().equalsIgnoreCase("evn_status")) {
         e.setStatus(item.getValue().trim());
       } else if (item.getKey().equalsIgnoreCase("evn_tag")) {
         e.setTags(item.getValue().trim());
       } else if (item.getKey().equalsIgnoreCase("evn_tag_id")) {
         e.setTagId(item.getValue().trim());
       } else if (item.getKey().equalsIgnoreCase("count")) {
         e.setCount(Integer.parseInt(item.getValue().trim()));
       }
     }
     list.add(e);
   } // eventList now holds all events
   return list;
 }
 /*
  * get top 3 (today and tomorrow) events that most people are attending
  */
 public ArrayList<Event> getEventById(String id) {
   ArrayList<Event> list = new ArrayList<Event>();
   String query = " SELECT * FROM tb_events ";
   query += " WHERE env_id = '" + id + "'";
   List<HashMap<String, String>> result =
       DBComunicationLayer.executeHttpPost(DBComunicationLayer.PHP_SELECT, query);
   Log.i(LOG_TAG, query);
   for (int i = 1; i < result.size(); i++) {
     Event e = new Event();
     for (Map.Entry<String, String> item : result.get(i).entrySet()) {
       if (item.getKey().equalsIgnoreCase("evn_id")) {
         e.setId(item.getValue().trim());
       } else if (item.getKey().equalsIgnoreCase("evn_titile")) {
         e.setTitle(item.getValue().trim());
       } else if (item.getKey().equalsIgnoreCase("evn_description")) {
         e.setDescription(item.getValue().trim());
       } else if (item.getKey().equalsIgnoreCase("evn_location")) {
         e.setLocation(item.getValue().trim());
       } else if (item.getKey().equalsIgnoreCase("evn_start_time")) {
         e.setStartDayTime(item.getValue().trim());
       } else if (item.getKey().equalsIgnoreCase("evn_end_time")) {
         e.setEndDayTime(item.getValue().trim());
       } else if (item.getKey().equalsIgnoreCase("evn_created_time")) {
         e.setCreatedDayTime(item.getValue().trim());
       } else if (item.getKey().equalsIgnoreCase("evn_contact_info")) {
         e.setContact(item.getValue().trim());
       } else if (item.getKey().equalsIgnoreCase("evn_cat_id")) {
         e.setCategory(item.getValue().trim());
       } else if (item.getKey().equalsIgnoreCase("evn_url")) {
         e.setUrl(item.getValue().trim());
       } else if (item.getKey().equalsIgnoreCase("evn_count_like")) {
         e.setLike(item.getValue().trim());
       } else if (item.getKey().equalsIgnoreCase("evn_count_dislike")) {
         e.setDislike(item.getValue().trim());
       } else if (item.getKey().equalsIgnoreCase("evn_status")) {
         e.setStatus(item.getValue().trim());
       } else if (item.getKey().equalsIgnoreCase("evn_tag")) {
         e.setTags(item.getValue().trim());
       } else if (item.getKey().equalsIgnoreCase("evn_tag_id")) {
         e.setTagId(item.getValue().trim());
       } else if (item.getKey().equalsIgnoreCase("count")) {
         e.setCount(Integer.parseInt(item.getValue().trim()));
       }
     }
     list.add(e);
   } // eventList now holds all events
   return list;
 }
  public boolean getAllEvents() {
    resetEventList();
    String query = "SELECT * FROM tb_events";
    List<HashMap<String, String>> result =
        DBComunicationLayer.executeHttpPost(DBComunicationLayer.PHP_SELECT, query);
    for (int i = 1; i < result.size(); i++) {
      Event e = new Event();
      for (Map.Entry<String, String> item : result.get(i).entrySet()) {

        if (item.getKey().equalsIgnoreCase("evn_id")) {
          e.setId(item.getValue().trim());
        } else if (item.getKey().equalsIgnoreCase("evn_titile")) {
          e.setTitle(item.getValue().trim());
        } else if (item.getKey().equalsIgnoreCase("evn_description")) {
          e.setDescription(item.getValue().trim());
        } else if (item.getKey().equalsIgnoreCase("evn_location")) {
          e.setLocation(item.getValue().trim());
        } else if (item.getKey().equalsIgnoreCase("evn_start_time")) {
          e.setStartDayTime(item.getValue().trim());
        } else if (item.getKey().equalsIgnoreCase("evn_end_time")) {
          e.setEndDayTime(item.getValue().trim());
        } else if (item.getKey().equalsIgnoreCase("evn_created_time")) {
          e.setCreatedDayTime(item.getValue().trim());
        } else if (item.getKey().equalsIgnoreCase("evn_contact_info")) {
          e.setContact(item.getValue().trim());
        } else if (item.getKey().equalsIgnoreCase("evn_cat_id")) {
          e.setCategory(item.getValue().trim());
        } else if (item.getKey().equalsIgnoreCase("evn_url")) {
          e.setUrl(item.getValue().trim());
        } else if (item.getKey().equalsIgnoreCase("evn_count_like")) {
          e.setLike(item.getValue().trim());
        } else if (item.getKey().equalsIgnoreCase("evn_count_dislike")) {
          e.setDislike(item.getValue().trim());
        } else if (item.getKey().equalsIgnoreCase("evn_status")) {
          e.setStatus(item.getValue().trim());
        } else if (item.getKey().equalsIgnoreCase("evn_tag")) {
          e.setTags(item.getValue().trim());
        } else if (item.getKey().equalsIgnoreCase("evn_tag_id")) {
          e.setTagId(item.getValue().trim());
        }
      }
      if (!eventList.contains(e)) eventList.add(e);
    }
    //	return Integer.parseInt( result.get( 0 ).get( "result" ) ) == 1;
    return true;
  }
  /**
   * Gets the event.
   *
   * @param title the title
   * @return the event
   */
  public Event getEvent(String title) {
    SQLiteDatabase db = this.getReadableDatabase();
    String selectQuery =
        "SELECT  * FROM " + TABLE_EVENT + " WHERE " + KEY_EVENT_TITLE + " = '" + title + "'";

    Log.e(LOG, selectQuery);
    Cursor c = db.rawQuery(selectQuery, null);
    if (c != null) c.moveToFirst();

    Event ev = new Event();
    ev.setId(c.getInt(c.getColumnIndex(KEY_ID)));
    ev.setTitle((c.getString(c.getColumnIndex(KEY_EVENT_TITLE))));
    ev.setStartDate((c.getString(c.getColumnIndex(KEY_EVENT_STARTDATE))));
    ev.setEndDate((c.getString(c.getColumnIndex(KEY_EVENT_ENDDATE))));
    ev.setStartTime((c.getString(c.getColumnIndex(KEY_EVENT_STARTTIME))));
    ev.setEndTime((c.getString(c.getColumnIndex(KEY_EVENT_ENDTIME))));
    ev.setDescription((c.getString(c.getColumnIndex(KEY_EVENT_DESCRIPTION))));
    ev.setRepeat((c.getString(c.getColumnIndex(KEY_EVENT_REPEAT))));

    return ev;
  }
Exemplo n.º 8
0
  private Event makeEvent(Properties p, boolean fetchAlarm) {
    Event event = null;
    String id = p.getProperty("eventID");
    String start = p.getProperty("startDateTime");
    String end = p.getProperty("endDateTime");
    String location = p.getProperty("location");
    String description = p.getProperty("description");
    String isMeeting = p.getProperty("isMeeting");

    if (isMeeting.equals(BIT_FALSE)) {
      event = new Appointment();
    } else if (isMeeting.equals(BIT_TRUE)) {
      event = new Meeting();
    }
    event.setId(Integer.parseInt(id));
    event.setStartDateTime(start);
    event.setEndDateTime(end);
    event.setLocation(location);
    event.setDescription(description);
    if (fetchAlarm) {
      event.setAlarm(queryAlarm(currentUser, Integer.parseInt(id)));
    }
    event.setRoom(queryReservedRoom(Integer.parseInt(id)));
    if (event instanceof Appointment) {
      ((Appointment) event).setOwner(queryOwner(Integer.parseInt(id)));
    } else if (event instanceof Meeting) {
      ((Meeting) event).setLeader(queryOwner(Integer.parseInt(id)));
      ArrayList<User> invited = queryParticipants(Integer.parseInt(id), PARTICIPANT_STATUS_INVITED);
      ArrayList<User> accepted =
          queryParticipants(Integer.parseInt(id), PARTICIPANT_STATUS_ACCEPTED);
      ArrayList<User> declined =
          queryParticipants(Integer.parseInt(id), PARTICIPANT_STATUS_DECLINED);
      ((Meeting) event).setUsersInvited(invited);
      ((Meeting) event).setUsersAccepted(accepted);
      ((Meeting) event).setUsersDeclined(declined);
    }
    return event;
  }
Exemplo n.º 9
0
  @Override
  public void populate(Resource resource) throws LocalStorageException {
    Event e = (Event) resource;

    try {
      @Cleanup
      Cursor cursor =
          providerClient.query(
              ContentUris.withAppendedId(entriesURI(), e.getLocalID()),
              new String[] {
                /*  0 */ Events.TITLE,
                Events.EVENT_LOCATION,
                Events.DESCRIPTION,
                /*  3 */ Events.DTSTART,
                Events.DTEND,
                Events.EVENT_TIMEZONE,
                Events.EVENT_END_TIMEZONE,
                Events.ALL_DAY,
                /*  8 */ Events.STATUS,
                Events.ACCESS_LEVEL,
                /* 10 */ Events.RRULE,
                Events.RDATE,
                Events.EXRULE,
                Events.EXDATE,
                /* 14 */ Events.HAS_ATTENDEE_DATA,
                Events.ORGANIZER,
                Events.SELF_ATTENDEE_STATUS,
                /* 17 */ entryColumnUID(),
                Events.DURATION,
                Events.AVAILABILITY
              },
              null,
              null,
              null);
      if (cursor != null && cursor.moveToNext()) {
        e.setUid(cursor.getString(17));

        e.setSummary(cursor.getString(0));
        e.setLocation(cursor.getString(1));
        e.setDescription(cursor.getString(2));

        boolean allDay = cursor.getInt(7) != 0;
        long tsStart = cursor.getLong(3), tsEnd = cursor.getLong(4);
        String duration = cursor.getString(18);

        String tzId = null;
        if (allDay) {
          e.setDtStart(tsStart, null);
          // provide only DTEND and not DURATION for all-day events
          if (tsEnd == 0) {
            Dur dur = new Dur(duration);
            java.util.Date dEnd = dur.getTime(new java.util.Date(tsStart));
            tsEnd = dEnd.getTime();
          }
          e.setDtEnd(tsEnd, null);

        } else {
          // use the start time zone for the end time, too
          // because apps like Samsung Planner allow the user to change "the" time zone but change
          // the start time zone only
          tzId = cursor.getString(5);
          e.setDtStart(tsStart, tzId);
          if (tsEnd != 0) e.setDtEnd(tsEnd, tzId);
          else if (!StringUtils.isEmpty(duration)) e.setDuration(new Duration(new Dur(duration)));
        }

        // recurrence
        try {
          String strRRule = cursor.getString(10);
          if (!StringUtils.isEmpty(strRRule)) e.setRrule(new RRule(strRRule));

          String strRDate = cursor.getString(11);
          if (!StringUtils.isEmpty(strRDate)) {
            RDate rDate = new RDate();
            rDate.setValue(strRDate);
            e.setRdate(rDate);
          }

          String strExRule = cursor.getString(12);
          if (!StringUtils.isEmpty(strExRule)) {
            ExRule exRule = new ExRule();
            exRule.setValue(strExRule);
            e.setExrule(exRule);
          }

          String strExDate = cursor.getString(13);
          if (!StringUtils.isEmpty(strExDate)) {
            // ignored, see https://code.google.com/p/android/issues/detail?id=21426
            ExDate exDate = new ExDate();
            exDate.setValue(strExDate);
            e.setExdate(exDate);
          }
        } catch (ParseException ex) {
          Log.w(TAG, "Couldn't parse recurrence rules, ignoring", ex);
        } catch (IllegalArgumentException ex) {
          Log.w(TAG, "Invalid recurrence rules, ignoring", ex);
        }

        // status
        switch (cursor.getInt(8)) {
          case Events.STATUS_CONFIRMED:
            e.setStatus(Status.VEVENT_CONFIRMED);
            break;
          case Events.STATUS_TENTATIVE:
            e.setStatus(Status.VEVENT_TENTATIVE);
            break;
          case Events.STATUS_CANCELED:
            e.setStatus(Status.VEVENT_CANCELLED);
        }

        // availability
        e.setOpaque(cursor.getInt(19) != Events.AVAILABILITY_FREE);

        // attendees
        if (cursor.getInt(14) != 0) { // has attendees
          try {
            e.setOrganizer(new Organizer(new URI("mailto", cursor.getString(15), null)));
          } catch (URISyntaxException ex) {
            Log.e(TAG, "Error when creating ORGANIZER URI, ignoring", ex);
          }
          populateAttendees(e);
        }

        // classification
        switch (cursor.getInt(9)) {
          case Events.ACCESS_CONFIDENTIAL:
          case Events.ACCESS_PRIVATE:
            e.setForPublic(false);
            break;
          case Events.ACCESS_PUBLIC:
            e.setForPublic(true);
        }

        populateReminders(e);
      } else throw new RecordNotFoundException();
    } catch (RemoteException ex) {
      throw new LocalStorageException(ex);
    }
  }
Exemplo n.º 10
0
  public static void modifyRecord(Event event) {

    event.setDateCreated(new Date());
    event.setDescription(randomString("description", 2000));
    event.setCategory(randomString("category", 50));
  }