Android Open Source - libCalendar Instance Utility






From Project

Back to project page libCalendar.

License

The source code is released under:

MIT License

If you think the Android project libCalendar 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.darkrockstudios.libs.calendar;
/*from ww  w  .ja v  a  2 s .  com*/
import java.util.ArrayList;
import java.util.Calendar;

import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.CalendarContract.Instances;

public class InstanceUtility
{
  public static ArrayList< Instance > getVisibleInstances( Context context, int hours )
  {
    ArrayList< Instance > instances = new ArrayList< Instance >();

    // Specify the date range you want to search for recurring
    // event instances
    Calendar startTime = Calendar.getInstance();
    long startMillis = startTime.getTimeInMillis();

    Calendar endTime = Calendar.getInstance();
    endTime.add( Calendar.HOUR, hours );
    long endMillis = endTime.getTimeInMillis();

    // Submit the query
    ContentResolver cr = context.getContentResolver();
    Cursor cur = Instances.query( cr, null, startMillis, endMillis );

    while( cur.moveToNext() )
    {
      instances.add( new Instance( cur ) );
    }

    cur.close();

    return instances;
  }

  public static ArrayList< Instance > getAllInstances( Context context, int hours )
  {
    ArrayList< Instance > instances = new ArrayList< Instance >();

    // Specify the date range you want to search for recurring
    // event instances
    Calendar startTime = Calendar.getInstance();
    long startMillis = startTime.getTimeInMillis();

    Calendar endTime = Calendar.getInstance();
    endTime.add( Calendar.HOUR, hours );
    long endMillis = endTime.getTimeInMillis();

    // Submit the query
    Uri.Builder uriBuilder = Instances.CONTENT_URI.buildUpon();
    ContentUris.appendId( uriBuilder, startMillis );
    ContentUris.appendId( uriBuilder, endMillis );
    Uri uri = uriBuilder.build();

    ContentResolver cr = context.getContentResolver();
    Cursor cur = cr.query( uri, null, null, null, Instances.BEGIN + " ASC" );

    while( cur.moveToNext() )
    {
      instances.add( new Instance( cur ) );
    }

    cur.close();

    return instances;
  }
}




Java Source Code List

com.darkrockstudios.libs.calendar.CalendarUtility.java
com.darkrockstudios.libs.calendar.Calendar.java
com.darkrockstudios.libs.calendar.EventUtility.java
com.darkrockstudios.libs.calendar.Event.java
com.darkrockstudios.libs.calendar.InstanceUtility.java
com.darkrockstudios.libs.calendar.Instance.java
com.darkrockstudios.libs.calendar.iCalUtility.java