FileDocCategorySizeDatePackage
EventLoader.javaAPI DocAndroid 1.5 API9736Wed May 06 22:42:42 BST 2009com.android.calendar

EventLoader

public class EventLoader extends Object

Fields Summary
private android.content.Context
mContext
private android.os.Handler
mHandler
private AtomicInteger
mSequenceNumber
private LinkedBlockingQueue
mLoaderQueue
private LoaderThread
mLoaderThread
private android.content.ContentResolver
mResolver
Constructors Summary
public EventLoader(android.content.Context context)

        mContext = context;
        mLoaderQueue = new LinkedBlockingQueue<LoadRequest>();
        mResolver = context.getContentResolver();
    
Methods Summary
voidloadBusyBitsInBackground(int startDay, int numDays, int[] busybits, int[] allDayCounts, java.lang.Runnable uiCallback)

        // Send the load request to the background thread
        LoadBusyBitsRequest request = new LoadBusyBitsRequest(startDay, numDays, busybits,
                allDayCounts, uiCallback);

        try {
            mLoaderQueue.put(request);
        } catch (InterruptedException ex) {
            // The put() method fails with InterruptedException if the
            // queue is full. This should never happen because the queue
            // has no limit.
            Log.e("Cal", "loadBusyBitsInBackground() interrupted!");
        }
    
voidloadEventsInBackground(int numDays, java.util.ArrayList events, long start, java.lang.Runnable successCallback, java.lang.Runnable cancelCallback)
Loads "numDays" days worth of events, starting at start, into events. Posts uiCallback to the {@link Handler} for this view, which will run in the UI thread. Reuses an existing background thread, if events were already being loaded in the background. NOTE: events and uiCallback are not used if an existing background thread gets reused -- the ones that were passed in on the call that results in the background thread getting created are used, and the most recent call's worth of data is loaded into events and posted via the uiCallback.

        
        // Increment the sequence number for requests.  We don't care if the
        // sequence numbers wrap around because we test for equality with the
        // latest one.
        int id = mSequenceNumber.incrementAndGet();

        // Send the load request to the background thread
        LoadEventsRequest request = new LoadEventsRequest(id, start, numDays,
                events, successCallback, cancelCallback);

        try {
            mLoaderQueue.put(request);
        } catch (InterruptedException ex) {
            // The put() method fails with InterruptedException if the
            // queue is full. This should never happen because the queue
            // has no limit.
            Log.e("Cal", "loadEventsInBackground() interrupted!");
        }
    
public voidstartBackgroundThread()
Call this from the activity's onResume()

        mLoaderThread = new LoaderThread(mLoaderQueue, this);
        mLoaderThread.start();
    
public voidstopBackgroundThread()
Call this from the activity's onPause()

        mLoaderThread.shutdown();