Android Open Source - android-calendar-drafts Delete 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;
//w w  w . j av  a 2s . c  om
import java.util.ArrayList;

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

import android.annotation.TargetApi;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.CalendarContract.Events;
import android.util.Log;

/**
 * @author asiebert
 */
@TargetApi(14)
public class DeleteEventByHeaderCmd extends DeleteEventCmd {

  public DeleteEventByHeaderCmd(Context ctx) {
    super(ctx);
  }

  public boolean exec(final String title, final long begin, final long end) {
    final ContentResolver cr = getContentResolver();

    final String where = Events.TITLE + " = ? ";
    final String[] projection = { Events.TITLE, Events._ID };
    final String[] values = new String[] { title };

    final Cursor cursor = cr.query(Events.CONTENT_URI, projection, where,
        values, null);
    
    final int count = cursor.getCount();

    final ArrayList<Uri> ids = new ArrayList<Uri>();
    while (cursor.moveToNext()) {
      final int idIdx = cursor.getColumnIndex(Events._ID);
      final int titleIdx = cursor.getColumnIndex(Events.TITLE);
       
      Log.d("calendar-drafts", "-- ## title : " + cursor.getString(titleIdx));
      final long id = cursor.getLong(idIdx);
      final Uri idUri = EventId.createUri(id);
      
      ids.add(idUri);
    }
    
    cursor.close();
    
    int deletedSum = 0;
    for( final Uri idUri : ids ) {
      final int deleted = cr.delete(idUri, null, null);
      deletedSum += deleted;
    }
    
    return (count == deletedSum);
  }

}




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