Android Open Source - android-calendar-drafts Update Event By Header Cmd






From Project

Back to project page android-calendar-drafts.

License

The source code is released under:

Apache License

If you think the Android project android-calendar-drafts listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.touchableheroes.drafts.calendar.cmd;
// www  .j av a  2  s  . c  o  m
import java.util.List;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.provider.CalendarContract.Events;
import android.util.Log;

import com.touchableheroes.drafts.calendar.dao.Event;


/**
 * Simple implementation of Update (one-by-one update)
 * Is not optimized for batch-updates.
 * 
 * @author A. Siebert, ask@touchableheroes.com
 */
public class UpdateEventByHeaderCmd extends ContextCmd {

  private final LoadEventsCmd load;
  
  public UpdateEventByHeaderCmd(final Context ctx) {
    super(ctx);
    
    this.load = new LoadEventsCmd(ctx);
  }

  /**
   * @param title part of the query, skip param if value null.
   * @param begin part of the query, skip param if value null.
   * @param end part of the query, skip param if value null.
   * 
   * @param newTitle don't update if null passed
   * @param newBegin don't update if null passed
   * @param newEnd don't update if null passed
   * @param newDescription don't update if null passed
   * @param newLocation don't update if null passed
   * 
   * @return true if operation is successful.
   */
  public boolean exec(final String title, final long begin, final long end,
      final String newTitle, final long newBegin, final long newEnd,
      final String newDescription, final String newLocation) {
    
    final List<Event> events = this.load.exec(title, begin, end, null, null);
    
    int sum = 0;
    for (final Event event : events) {
      final ContentResolver cr = getContentResolver();
      final ContentValues values = event.newUpdateContentValues(newTitle, newBegin, newEnd,
          newDescription, newLocation);
      
      final int count = cr.update(event.getId().getUri(), values, null, null);
      Log.d("phonegap-calendar-plugin", "updated: " + count + " events in calendar." );
      
      sum += count;
    }
    
    

    return events.size() == sum;
  }

}




Java Source Code List

com.touchableheroes.drafts.calendar.Start.java
com.touchableheroes.drafts.calendar.cmd.ContextCmd.java
com.touchableheroes.drafts.calendar.cmd.DeleteEventByHeaderCmd.java
com.touchableheroes.drafts.calendar.cmd.DeleteEventCmd.java
com.touchableheroes.drafts.calendar.cmd.ExistsEventCmd.java
com.touchableheroes.drafts.calendar.cmd.InsertDaylyRepeatableEventCmd.java
com.touchableheroes.drafts.calendar.cmd.InsertEventCmd.java
com.touchableheroes.drafts.calendar.cmd.InsertReminderCmd.java
com.touchableheroes.drafts.calendar.cmd.InsertRepeatableEventCmd.java
com.touchableheroes.drafts.calendar.cmd.LoadEventByIdCmd.java
com.touchableheroes.drafts.calendar.cmd.LoadEventsCmd.java
com.touchableheroes.drafts.calendar.cmd.ModifyEventCmd.java
com.touchableheroes.drafts.calendar.cmd.UpdateEventByHeaderCmd.java
com.touchableheroes.drafts.calendar.cursor.GetValueFacade.java
com.touchableheroes.drafts.calendar.dao.EventId.java
com.touchableheroes.drafts.calendar.dao.Event.java
com.touchableheroes.drafts.calendar.dao.EventsDAO.java
com.touchableheroes.drafts.calendar.util.WherePart.java
com.touchableheroes.drafts.calendar.util.WhereQueryPartBuilder.java