Android Open Source - android-calendar-drafts Where Query Part Builder






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.util;
//from  www  . j a  v a 2s  .  c o  m
import java.util.ArrayList;

import android.provider.CalendarContract.Events;

/**
 * simplifies the query-building for events and calendar-content-provider.
 * 
 * @author A. Siebert, ask@touchableheroes.com
 */
public class WhereQueryPartBuilder {

  public static WherePart createForEvents(final String title,
      final long begin, final long end, final String location,
      final String description) {
    final StringBuilder builder = new StringBuilder();
    final ArrayList<String> values = new ArrayList<String>(5);

    appendWhere(builder, Events.TITLE, title, values);
    appendWhereLong(builder, Events.DTSTART, begin, values);
    appendWhereLong(builder, Events.DTEND, end, values);
    appendWhere(builder, Events.DESCRIPTION, description, values);

    // TODO: add some other features later!
    // appendWhere(builder, Events.LOCATION, location, values);

    return new WherePart(builder.toString(), values);
  }

  private static void appendWhereLong(StringBuilder builder, String key,
      long value, ArrayList<String> values) {
    final String valStr = String.valueOf(value);
    
    appendWhere(builder, key, valStr, values);
  }

  private static void appendWhere(final StringBuilder builder,
      final String key, final String value, final ArrayList<String> values) {
    if (value == null)
      return;

    if (builder.length() > 0)
      builder.append(" AND ");

    builder.append(key);
    builder.append(" = ? ");

    values.add(value);
  }

}




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