コード例 #1
0
  public void populateViews() {
    final Venue venue; // Venue of the event
    final String description =
        mEvent.getDescription(); // description of the event, must be more than 50 works
    final Contact contact;

    TextView categoryText = (TextView) findViewById(R.id.categorytext);
    TextView timeText = (TextView) findViewById(R.id.timetext);
    TextView venueText = (TextView) findViewById(R.id.venuetext);
    TextView contactText = (TextView) findViewById(R.id.contacttext);
    TextView descriptionText = (TextView) findViewById(R.id.descriptiontext);
    TextView resultText = (TextView) findViewById(R.id.resulttext);
    categoryText.setText(mEvent.getCategory());

    int shour = mEvent.getStart_time().get(Calendar.HOUR_OF_DAY);
    int min = mEvent.getStart_time().get(Calendar.MINUTE);
    String smin;
    if (min == 0) smin = min + "0";
    else smin = min + "";

    String starttime;

    if (shour > 12) {
      shour = shour - 12;
      starttime = shour + ":" + smin + " PM";
    } else {
      starttime = shour + ":" + smin + " AM";
    }
    int ehour = mEvent.getEnd_time().get(Calendar.HOUR_OF_DAY);
    min = mEvent.getStart_time().get(Calendar.MINUTE);
    String emin;
    if (min == 0) emin = min + "0";
    else emin = min + "";

    String endtime;
    if (ehour > 12) {
      ehour = ehour - 12;
      endtime = ehour + ":" + emin + " PM";
    } else {
      endtime = ehour + ":" + emin + " AM";
    }
    String time = starttime + " to " + endtime;
    timeText.setText(time);
    venueText.setText(mEvent.getVenue().getLocation());
    contactText.setText(mEvent.getContact().getName());
    if (description != null && description.length() > 10) {
      descriptionText.setText(description);
    } else {
      descriptionText.setVisibility(View.GONE);
      LinearLayout temp = (LinearLayout) findViewById(R.id.descriptioncontainer);
      temp.setVisibility(View.GONE);
    }
    databaseAccess = DatabaseAccess.getInstance(this);
    databaseAccess.open();
    String result = databaseAccess.getResult(mEvent.getName());
    databaseAccess.close();

    if (result == null) resultText.setText("results not declared yet");
    else resultText.setText(result);
  }
コード例 #2
0
  public void setReminder(int min) {
    long startMillis = 0;
    long endMillis = 0;
    Calendar beginTime = Calendar.getInstance();
    beginTime.set(
        2015,
        mEvent.getStart_time().get(Calendar.MONTH) - 1,
        mEvent.getStart_time().get(Calendar.DATE),
        mEvent.getStart_time().get(Calendar.HOUR),
        mEvent.getStart_time().get(Calendar.MINUTE));
    startMillis = beginTime.getTimeInMillis();
    Calendar endTime = Calendar.getInstance();
    endTime.set(
        2015,
        mEvent.getEnd_time().get(Calendar.MONTH) - 1,
        mEvent.getEnd_time().get(Calendar.DATE),
        mEvent.getEnd_time().get(Calendar.HOUR),
        mEvent.getEnd_time().get(Calendar.MINUTE));
    endMillis = endTime.getTimeInMillis();

    ContentResolver cr = getContentResolver();
    ContentValues values = new ContentValues();
    values.put(CalendarContract.Events.DTSTART, startMillis);
    values.put(CalendarContract.Events.DTEND, endMillis);
    values.put(CalendarContract.Events.TITLE, mEvent.getName());
    values.put(CalendarContract.Events.DESCRIPTION, mEvent.getDescription());
    values.put(CalendarContract.Events.CALENDAR_ID, mGoogleCalendarNumber);
    values.put(CalendarContract.Events.EVENT_TIMEZONE, "Asia/Calcutta");
    Uri uri = cr.insert(CalendarContract.Events.CONTENT_URI, values);
    // get the event ID that is the last element in the Uri
    long eventID = Long.parseLong(uri.getLastPathSegment());
    cr = getContentResolver();
    values = new ContentValues();
    values.put(CalendarContract.Reminders.MINUTES, min);
    values.put(CalendarContract.Reminders.EVENT_ID, eventID);
    values.put(CalendarContract.Reminders.METHOD, CalendarContract.Reminders.METHOD_ALERT);
    uri = cr.insert(CalendarContract.Reminders.CONTENT_URI, values);
    Toast.makeText(this, "Reminder set for " + min + " minutes before event", Toast.LENGTH_SHORT)
        .show();
  }