/**
   * Creates the event.
   *
   * @param event the event
   * @param category_ids the category_ids
   * @return the long
   */
  public long createEvent(Event event, long[] category_ids) {

    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_EVENT_TITLE, event.getTitle());
    values.put(KEY_EVENT_STARTDATE, event.getStartDate());
    values.put(KEY_EVENT_ENDDATE, event.getEndDate());
    values.put(KEY_EVENT_STARTTIME, event.getStartTime());
    values.put(KEY_EVENT_ENDTIME, event.getEndTime());
    values.put(KEY_EVENT_DESCRIPTION, event.getDescription());
    values.put(KEY_EVENT_REPEAT, event.getRepeat());

    // insert row
    long event_id = db.insert(TABLE_EVENT, null, values);

    // assigning categories to events
    for (long category_id : category_ids) {
      createEventCategory(event_id, category_id);
    }
    // for logging
    //	Log.e("createEvent", event.toString());
    //   db.close();

    return event_id;
  }
 public Event getByTitle(String title) {
   for (Event event : list) {
     if (event.getTitle().equals(title)) {
       return event;
     }
   }
   return null;
 }
  public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    int type = getItemViewType(position);
    Event event = events.get(position);

    if (convertView == null) {
      holder = new ViewHolder();
      switch (type) {
        case DAY:
          convertView = mInflater.inflate(R.layout.day_item, null);
          holder.day = (TextView) convertView.findViewById(R.id.day_title);
          break;
        case EVENT:
          convertView = mInflater.inflate(R.layout.search_list_item, null);
          holder.hour = (TextView) convertView.findViewById(R.id.event_hour);
          holder.title = (TextView) convertView.findViewById(R.id.event_title);
          holder.image = (ImageView) convertView.findViewById(R.id.event_favorite);
          holder.row = (LinearLayout) convertView.findViewById(R.id.event_row);
          holder.eventId = event.getId();
          break;
      }
      convertView.setTag(holder);
    } else {
      holder = (ViewHolder) convertView.getTag();
    }

    if (event != null) {
      if (event.getExternalId() == 0) {
        String dayText = BaseActivity.getDateFromTimestamp(event.getDate(), context);
        holder.day.setText(dayText);
      } else {
        // Hour.
        String hour = event.getStartHour();
        if (hour.length() == 0) {
          hour = context.getString(R.string.event_whole_day);
        }
        holder.hour.setText(hour);

        // Title.
        String title = event.getTitle();
        holder.title.setText(title);

        // Favorite.
        if (event.getFavorite() == 0) {
          holder.image.setImageResource(R.drawable.fav_off_small);
        } else {
          holder.image.setImageResource(R.drawable.fav_on_small);
        }

        holder.eventId = event.getId();
        convertView.setOnTouchListener(eventTouch);
      }
    }

    return convertView;
  }
 public boolean createEvent(Event e) {
   if (eventList.contains(e)) return true;
   String query =
       "INSERT INTO tb_events (evn_id, evn_titile, evn_description, evn_location, evn_start_time, evn_end_time, evn_created_time, evn_created_by, evn_contact_info, evn_cat_id, evn_url, evn_count_like, evn_count_dislike, evn_status, evn_tag, evn_tag_id)";
   query =
       query
           + " VALUES (NULL, '"
           + e.getTitle()
           + "', '"
           + e.getDescription()
           + "', '"
           + e.getLocation()
           + "', '"
           + e.getStartDayTime()
           + "', '"
           + e.getEndDayTime()
           + "', '"
           + e.getCreatedDayTime()
           + "', "
           + e.getCreatedBy()
           + ", '"
           + e.getContact()
           + "', "
           + e.getCategory()
           + ", '"
           + e.getUrl()
           + "', "
           + e.getLike()
           + ", "
           + e.getDislike()
           + ", "
           + e.getStatus()
           + ", '"
           + e.getTags()
           + "', NULL)";
   Log.i(LOG_TAG, query);
   List<HashMap<String, String>> result =
       DBComunicationLayer.executeHttpPost(DBComunicationLayer.PHP_INSERT, query);
   e.setId(result.get(0).get("evn_id"));
   eventList.add(e);
   // add all Tags into Tag Table
   /*	for (int i =0; i< e.getTagList().size();i++)
   {
   	String query2 = "INSERT INTO tb_tags (tag_id, tag_name)"+ " VALUES (NULL, '"+e.getTagList().get(i)+"')";
   	List<HashMap<String, String>> result2 = DBComunicationLayer.executeHttpPost( DBComunicationLayer.PHP_INSERT, query2);
   } */
   //	return result.get( 0 ).get( "result" ).equals( "1" );
   return true;
 }
  /**
   * Update event.
   *
   * @param event the event
   * @return the int
   */
  public int updateEvent(Event event) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_EVENT_TITLE, event.getTitle());
    values.put(KEY_EVENT_STARTDATE, event.getStartDate());
    values.put(KEY_EVENT_ENDDATE, event.getEndDate());
    values.put(KEY_EVENT_STARTTIME, event.getStartTime());
    values.put(KEY_EVENT_ENDTIME, event.getEndTime());
    values.put(KEY_EVENT_DESCRIPTION, event.getDescription());
    values.put(KEY_EVENT_REPEAT, event.getRepeat());

    // updating row
    return db.update(
        TABLE_EVENT, values, KEY_ID + " = ?", new String[] {String.valueOf(event.getId())});
  }
  /**
   * Check conflictin update events.
   *
   * @param newEvent the new event
   * @return true, if successful
   * @throws ParseException the parse exception
   */
  @SuppressLint("LongLogTag")
  public boolean checkConflictinUpdateEvents(Event newEvent) throws ParseException {
    SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mm");
    String sTime = newEvent.getStartTime();
    String sDate = newEvent.getStartDate();
    String eTime = newEvent.getEndTime();
    String eDate = newEvent.getEndDate();

    Date parsedStartTime = timeFormat.parse(sTime);
    Timestamp newStartTime = new Timestamp(parsedStartTime.getTime());
    Date parsedEndTime = timeFormat.parse(eTime);
    Timestamp newEndTime = new Timestamp(parsedEndTime.getTime());

    if (sDate.equalsIgnoreCase(eDate)) {
      if (newStartTime.after(newEndTime)) {
        Log.e("Illogiacl Update", "StartTime is greater then EndTime");
        return false;
      }
    }

    List<Event> allEvents = getEvent(sDate, eDate);
    for (Event prevEvent : allEvents) {
      Log.d(
          "Event: " + prevEvent.getTitle(),
          "" + prevEvent.getId() + "  " + prevEvent.getDescription());

      Date parsedPreviousStartTime = timeFormat.parse(prevEvent.getStartTime());
      Timestamp previousStartTime = new Timestamp(parsedPreviousStartTime.getTime());
      Date parsedPreviousEndTime = timeFormat.parse(prevEvent.getEndTime());
      Timestamp previousEndTime = new Timestamp(parsedPreviousEndTime.getTime());

      if (newStartTime.after(previousStartTime) && newStartTime.before(previousEndTime)
          || newEndTime.after(previousStartTime) && newEndTime.before(previousEndTime)
          || previousStartTime.after(newStartTime) && previousStartTime.before(newEndTime)
          || previousEndTime.after(newStartTime) && previousEndTime.before(newEndTime)) {
        if (newEvent.getId() != prevEvent.getId()) {
          Log.e("Conflict with existent event", "Can't update this event");
          return false;
        }
      }
    }
    return true;
  }
  public EventListByDateAdapter(Context c, String startDate, String endDate) {
    eContext = c;
    this.startDate = startDate;
    this.endDate = endDate;
    // this.ctg = ctg;
    //	db = new  MySQLiteHelper(eContext);

    // Getting all Events
    Log.d("Get Events", "Getting All Events");

    dayEvents = new ArrayList<Event>();
    try {
      stDate = dateFormat.parse(startDate);
      eDate = dateFormat.parse(endDate);
    } catch (ParseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    // Getting all Events
    Log.d("Get Events", "Getting All Events");

    allEvents = SimpleCalendarView.db.getAllEvents();
    for (Event event : allEvents) {
      Date eventStartDate = new Date();
      // Date eventEndDate = new Date();
      try {
        eventStartDate = dateFormat.parse(event.getStartDate());
        // eventEndDate = dateFormat.parse(event.getEndDate());
      } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      if (((eventStartDate.compareTo(stDate) >= 0) && (eventStartDate.compareTo(eDate) <= 0))) {

        dayEvents.add(event);
        Log.d(
            "Event:" + event.getTitle(),
            "ID:" + event.getId() + "Description:" + event.getDescription());
      }
    }
  }
예제 #8
0
  /**
   * This is the constructor which initializes the instance variables and the components. Also at
   * last it will display the initial screen.
   *
   * @param m is the model and HAS-A relationship gets constructed here.
   */
  public MonthlyView(Model m) {
    // CHANGING THE FONT AND SIZE
    java.io.InputStream is = DailyView.class.getResourceAsStream("Raleway-Regular.ttf");
    try {
      Font font = Font.createFont(Font.TRUETYPE_FONT, is);
      railWay = font.deriveFont(Font.PLAIN, 12);
      railWayMed = font.deriveFont(Font.PLAIN, 20);
      railWayBigBold = font.deriveFont(Font.BOLD, 26);
      railWayHuge = font.deriveFont(Font.PLAIN, 100);

    } catch (FontFormatException e1) {
      e1.printStackTrace();
    } catch (IOException e1) {
      e1.printStackTrace();
    }

    // MAIN MONTH VIEW PANEL
    // --------------------------------------------------------------------
    this.setLayout(new FlowLayout());
    monthViewPanel = new JPanel();
    monthViewPanel.setBackground(Color.WHITE);
    model = m;

    ghettoCurrDate =
        new int[] {
          MONTHS.valueOf(model.getCurrentMonth() + "").ordinal(),
          model.getCurrentDay(),
          model.getCurrentYear()
        }; // {month, day,
    // year}
    // (Derick)

    currDate = model.getCurrentDate();
    temp = new GregorianCalendar();
    temp.set(currDate.get(Calendar.YEAR), currDate.get(Calendar.MONTH), 1);
    firstdayoftheweek = temp.get(Calendar.DAY_OF_WEEK);
    daysInMonth = currDate.getActualMaximum(Calendar.DATE);
    dayButton = new JButton[31];

    // UPPER HALF PANEL
    // --------------------------------------------------------------------------
    JPanel upperPanel = new JPanel();
    upperPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
    upperPanel.setBackground(Color.WHITE);

    // CURRENT MONTH & YEAR PANEL

    dateLabelOfMonthPanel.setBackground(Color.WHITE);
    // JLabel dateLabelOfMonth = new JLabel("");
    // JLabel dateLabelOfYear = new JLabel("");
    dateLabelOfMonth.setText(model.getCurrentMonth() + " ");
    dateLabelOfYear.setText(Integer.toString(model.getCurrentYear()));
    dateLabelOfMonth.setFont(railWayHuge);
    dateLabelOfYear.setFont(railWayHuge);
    dateLabelOfMonth.setForeground(Color.BLACK);
    dateLabelOfYear.setForeground(babyTeal);
    dateLabelOfMonthPanel.add(dateLabelOfMonth);
    dateLabelOfMonthPanel.add(dateLabelOfYear);

    upperPanel.add(dateLabelOfMonthPanel, BorderLayout.CENTER);

    // PREVIOUS & NEXT BUTTON PANEL
    // JPanel previousNextButtonPanel = new JPanel(new GridLayout(1, 2));
    // JPanel previousButtonLeftPanel = new JPanel();
    // JButton previousButton = new JButton();
    // try
    // {
    // Image img = ImageIO.read(getClass().getResource("pre1.png"));
    // previousButton.setIcon(new ImageIcon(img));
    // Image newimg = img.getScaledInstance(50, 50,
    // java.awt.Image.SCALE_SMOOTH);
    // previousButton.setIcon(new ImageIcon(newimg));
    // } catch (IOException ex)
    // {
    // }
    // previousButton.setOpaque(false);
    // previousButton.setBorderPainted(false);
    // previousButton.addActionListener(new ActionListener()
    // {
    // public void actionPerformed(ActionEvent e)
    // {
    // model.prevMonth();;
    // }
    // });
    // dateLabelOfMonthPanel.add(previousButton);
    // previousButtonLeftPanel.add(previousButton);
    // previousNextButtonPanel.add(previousButtonLeftPanel, new
    // FlowLayout(FlowLayout.LEFT));
    // upperPanel.add(previousNextButtonPanel);
    //
    // // Creates the next button
    // JButton nextButton = new JButton();
    // try
    // {
    // Image img = ImageIO.read(getClass().getResource("next1.png"));
    // Image newimg = img.getScaledInstance(50, 50,
    // java.awt.Image.SCALE_SMOOTH);
    // nextButton.setIcon(new ImageIcon(newimg));
    // } catch (IOException ex)
    // {
    // }
    // nextButton.setOpaque(false);
    // nextButton.setBorderPainted(false);
    // nextButton.setPreferredSize(new Dimension(50, 50));
    // nextButton.addActionListener(new ActionListener()
    // {
    // public void actionPerformed(ActionEvent e)
    // {
    // model.nextDay();
    // }
    // });

    // JPanel daysOftheWeekPanel = new JPanel();
    JLabel daysOftheWeek = new JLabel("");
    daysOftheWeekPanel.setLayout(new GridLayout());
    daysOftheWeekPanel.setBackground(babyTeal);

    String[] days = {"SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY"};
    for (int i = 0; i < days.length; i++) {
      final String label = days[i];
      JLabel dayLabel = new JLabel(label);
      dayLabel.setForeground(Color.BLACK);
      dayLabel.setBackground(lightBlue);
      dayLabel.setHorizontalAlignment(SwingConstants.CENTER);
      daysOftheWeekPanel.add(dayLabel);

      dayLabel.setFont(railWayMed);
      daysOftheWeekPanel.add(dayLabel);
    }
    dayDayPanel.setLayout(new GridLayout(0, 7));
    for (int i = 1; i < firstdayoftheweek; i++) {
      JLabel dayLabell = new JLabel("");
      dayDayPanel.add(dayLabell);
    }
    for (int i = 0; i < dayButton.length; i++) {
      final int counter = i + 1;

      GregorianCalendar foo = new GregorianCalendar();
      foo.set(model.getCurrentYear(), model.getCurrentDate().get(Calendar.MONTH), i + 1);
      String star = "";
      if (model.findEvent(foo) == true) star = " *";
      dayButton[i] = new JButton(Integer.toString(i + 1) + star);
      dayButton[i].setOpaque(true);
      dayButton[i].setBorder(dayBorder);
      dayButton[i].setBackground(lightBlue);
      dayButton[i].setPreferredSize(new Dimension(205, 90));
      dayButton[i].addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              daynumber = counter;
              model.changeDay(daynumber);
              DailyView.createAndShowDailyViewGUI(model);
            }
          });
    }
    for (int i = 0; i <= daysInMonth; i++) {
      dayDayPanel.add(dayButton[i]);
      dayButton[i].setPreferredSize(new Dimension(205, 90));
      dayButton[i].setBackground(Color.WHITE);
      dayButton[i].setHorizontalAlignment(SwingConstants.LEFT);
      dayButton[i].setVerticalAlignment(SwingConstants.NORTH);
      // set the current date to a certain color
      if (i + 1 == model.getCurrentDay()) {
        dayButton[i].setBackground(lightBlue);
      }
    }
    dayViewPanel = new JPanel();
    dayViewPanel.setLayout(new BorderLayout());
    dayLabel = new JLabel();
    dayViewPanel.setBackground(Color.WHITE);

    dayLabel.setText(
        model.getCurrentDayoftheWeek()
            + " "
            + (model.getCurrentDate().get(Calendar.MONTH) + 1)
            + "/"
            + model.getCurrentDay());
    // JTextArea dayViewArea = new JTextArea(20,50);

    ArrayList<Event> listofE = new ArrayList<Event>();
    listofE = model.getEventsOfToday();
    if (listofE != null) {
      Collections.sort(listofE);
    }
    String s = "";

    for (int i = 0; i <= 24; i++) {
      if (i < 10) {
        s += ("0" + i);
        s += ("-------\n");

        if (listofE != null) {
          for (Event ev : listofE) {
            if (ev.getStartingTime().get(GregorianCalendar.HOUR_OF_DAY) == i) {
              s += ev.getTitle();
              s += " at " + ev.getStartingTime().get(Calendar.HOUR) + ":";
              if (ev.getStartingTime().get(Calendar.MINUTE) < 10) {
                s += "0" + ev.getStartingTime().get(Calendar.MINUTE);
              } else s += ev.getStartingTime().get(Calendar.MINUTE);
              if (ev.getStartingTime().get(Calendar.AM_PM) == 0) {
                s += "AM";
              } else s += "PM";

              s += " to " + ev.getEndingTime().get(Calendar.HOUR) + ":";
              if (ev.getEndingTime().get(Calendar.MINUTE) < 10) {
                s += "0" + ev.getEndingTime().get(Calendar.MINUTE);
              } else s += ev.getEndingTime().get(Calendar.MINUTE);
              if (ev.getEndingTime().get(Calendar.AM_PM) == 0) {
                s += "AM";
              } else s += "PM";
            }
          }
        }

        s += "\n\n";
      } else {
        s += i;
        s += ("-------\n");

        if (listofE != null) {
          for (Event ev : listofE) {
            if (ev.getStartingTime().get(GregorianCalendar.HOUR_OF_DAY) == i) {
              s += ev.getTitle();
              s += " at " + ev.getStartingTime().get(Calendar.HOUR) + ":";
              if (ev.getStartingTime().get(Calendar.MINUTE) < 10) {
                s += "0" + ev.getStartingTime().get(Calendar.MINUTE);
              } else s += ev.getStartingTime().get(Calendar.MINUTE);
              if (ev.getStartingTime().get(Calendar.AM_PM) == 0) {
                s += "AM";
              } else s += "PM";

              s += " to " + ev.getEndingTime().get(Calendar.HOUR) + ":";
              if (ev.getEndingTime().get(Calendar.MINUTE) < 10) {
                s += "0" + ev.getEndingTime().get(Calendar.MINUTE);
              } else s += ev.getEndingTime().get(Calendar.MINUTE);
              if (ev.getEndingTime().get(Calendar.AM_PM) == 0) {
                s += "AM";
              } else s += "PM";
            }
          }
        }
        s += "\n\n";
      }
    }
    /*
     * dayViewArea.setText(s); dayViewScrollPane = new
     * JScrollPane(dayViewArea); dayViewPanel.add(dayLabel,
     * BorderLayout.NORTH); dayViewPanel.add(dayViewScrollPane,
     * BorderLayout.CENTER);
     */

    monthViewPanel.setLayout(new BoxLayout(monthViewPanel, BoxLayout.Y_AXIS));
    monthViewPanel.add(dateLabelOfMonthPanel);
    monthViewPanel.add(daysOftheWeekPanel);
    monthViewPanel.add(dayDayPanel);
    monthViewPanel.setAlignmentX(Component.CENTER_ALIGNMENT);
    dayDayPanel.setBackground(Color.WHITE);

    add(monthViewPanel);
  }
예제 #9
0
    protected void onPostExecute(List<Event> eventList) {
      setContentView(R.layout.activity_event);
      SupportMapFragment mapFragment =
          (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.event_marker);
      mapFragment.getMapAsync(EventActivity.this);
      dialog.hide();

      final Button b = (Button) findViewById(R.id.join);
      for (Event event : eventList) {
        if (event.attendees.contains(userID)) {
          b.setText("Leave Event");
        }
        if (event.creator.equals(userID)) {
          b.setText("Delete Event");
        }
      }

      b.setOnClickListener(
          new View.OnClickListener() {
            public void onClick(View v) {
              if (b.getText().equals("I'm up!")) {
                System.out.println("Joining");
                new attendEvent()
                    .execute("https://protected-ocean-61024.herokuapp.com/event/join/", id);
                dialog.setCancelable(false);
                dialog.setMessage("Submitting request");
                dialog.setInverseBackgroundForced(false);
                dialog.show();

              } else if (b.getText().equals("Leave Event")) {
                System.out.println("Leaving");
                new attendEvent()
                    .execute("https://protected-ocean-61024.herokuapp.com/event/leave/", id);
                dialog.setCancelable(false);
                dialog.setMessage("Submitting request");
                dialog.setInverseBackgroundForced(false);
                dialog.show();
              } else if (b.getText().equals("Delete Event")) {
                new attendEvent()
                    .execute("https://protected-ocean-61024.herokuapp.com/event/delete/", id);
                dialog.setCancelable(false);
                dialog.setMessage("Deleting event");
                dialog.setInverseBackgroundForced(false);
                dialog.show();
              }
            }
          });

      final Event e = eventList.get(0);

      title = (TextView) findViewById(R.id.event_info_title);
      date = (TextView) findViewById(R.id.event_info_date);
      img = (ImageView) findViewById(R.id.event_info_image);

      title.setText(e.getTitle());
      date.setText(e.getFullDate());

      String category = e.getCategory();
      Bitmap largeIcon =
          BitmapFactory.decodeResource(getApplicationContext().getResources(), getImage(category));
      largeIcon = hlp.getRoundedCornerBitmap(largeIcon, 500);
      img.setImageBitmap(largeIcon);

      String str = e.getLocation();
      List<String> strList = Arrays.asList(str.split(","));
      coords.add(0, Double.parseDouble(strList.get(1)));
      coords.add(1, Double.parseDouble(strList.get(0)));
    }