Exemplo n.º 1
0
 @Override
 protected void onPostExecute(final Boolean success) {
   if (events == null || events.getResult() == null || events.getResult().isEmpty()) {
     AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create();
     alertDialog.setTitle("Status");
     alertDialog.setMessage(getResources().getString(R.string.event_retrieve_empty));
     alertDialog.setButton(
         AlertDialog.BUTTON_NEUTRAL,
         "OK",
         new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int which) {
             dialog.dismiss();
           }
         });
     alertDialog.show();
     showProgress(false);
   } else {
     addToGoogle(events);
   }
 }
Exemplo n.º 2
0
 @Override
 protected Boolean doInBackground(Void... params) {
   try {
     events = Parser.retreiveAllEvents(searchObject.getEmail(), searchObject.getPassword());
     return true ? events.getSuccess() == 1 : false;
   } catch (IllegalAccessException illegalException) {
     illegalException.printStackTrace();
   } catch (InvocationTargetException exception) {
     exception.printStackTrace();
   }
   return Boolean.FALSE;
 }
Exemplo n.º 3
0
  private void addToGoogle(EventSearchObject events) {
    Uri.Builder eventsUriBuilder = CalendarContract.Events.CONTENT_URI.buildUpon();
    // ContentUris.appendId(eventsUriBuilder, timeNow);
    // ContentUris.appendId(eventsUriBuilder, endOfToday);
    Uri eventsUri = eventsUriBuilder.build();
    ContentValues[] values;
    if (MAX_TO_EXPORT >= events.getResult().size()) {
      values = new ContentValues[events.getResult().size()];
    } else {
      values = new ContentValues[MAX_TO_EXPORT];
    }

    long calendar_id = getCalendarId();
    int i = 0;
    for (EventObject eventObject : events.getResult()) {
      if (i >= MAX_TO_EXPORT) break;
      ContentValues value = new ContentValues();
      TimeZone timeZone = TimeZone.getDefault();
      if (eventObject.getTitle() != null) {
        value.put(CalendarContract.Events.TITLE, eventObject.getTitle());
      }
      if (eventObject.getDescription() != null) {
        value.put(CalendarContract.Events.DESCRIPTION, eventObject.getDescription());
      }
      if (eventObject.getStart() != null) {
        value.put(CalendarContract.Events.DTSTART, eventObject.getStart());
      }
      if (eventObject.getEnd() != null) {
        value.put(CalendarContract.Events.DTEND, eventObject.getEnd());
      }
      if (timeZone.getID() != null) {
        value.put(CalendarContract.Events.EVENT_TIMEZONE, timeZone.getID());
      }
      if (eventObject.getLocation() != null) {
        value.put(CalendarContract.Events.EVENT_LOCATION, eventObject.getLocation());
      }
      value.put(CalendarContract.Events.CALENDAR_ID, calendar_id);

      System.out.println("Event title = " + eventObject.getTitle());
      System.out.println("Event Start Date = " + new Date(eventObject.getStart()).toString());

      values[i++] = value;
    }
    int result = getContentResolver().bulkInsert(eventsUri, values);

    System.out.println("Result is " + result);

    AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setTitle("Status");
    alertDialog.setMessage(
        values.length + " " + getResources().getString(R.string.event_synToGoogle_success));
    alertDialog.setButton(
        AlertDialog.BUTTON_NEUTRAL,
        "OK",
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
          }
        });
    alertDialog.show();
    showProgress(false);
  }