FileDocCategorySizeDatePackage
UsageEvents.javaAPI DocAndroid 5.1 API10993Thu Mar 12 22:22:10 GMT 2015android.app.usage

UsageEvents

public final class UsageEvents extends Object implements android.os.Parcelable
A result returned from {@link android.app.usage.UsageStatsManager#queryEvents(long, long)} from which to read {@link android.app.usage.UsageEvents.Event} objects.

Fields Summary
private List
mEventsToWrite
private android.os.Parcel
mParcel
private final int
mEventCount
private int
mIndex
private String[]
mStringPool
public static final Creator
CREATOR
Constructors Summary
public UsageEvents(android.os.Parcel in)
Construct the iterator from a parcel. {@hide}


                
       
        mEventCount = in.readInt();
        mIndex = in.readInt();
        if (mEventCount > 0) {
            mStringPool = in.createStringArray();

            final int listByteLength = in.readInt();
            final int positionInParcel = in.readInt();
            mParcel = Parcel.obtain();
            mParcel.setDataPosition(0);
            mParcel.appendFrom(in, in.dataPosition(), listByteLength);
            mParcel.setDataSize(mParcel.dataPosition());
            mParcel.setDataPosition(positionInParcel);
        }
    
UsageEvents()
Create an empty iterator. {@hide}

        mEventCount = 0;
    
public UsageEvents(List events, String[] stringPool)
Construct the iterator in preparation for writing it to a parcel. {@hide}

        mStringPool = stringPool;
        mEventCount = events.size();
        mEventsToWrite = events;
    
Methods Summary
public intdescribeContents()

        return 0;
    
protected voidfinalize()


    
         
        super.finalize();
        if (mParcel != null) {
            mParcel.recycle();
            mParcel = null;
        }
    
private intfindStringIndex(java.lang.String str)

        final int index = Arrays.binarySearch(mStringPool, str);
        if (index < 0) {
            throw new IllegalStateException("String '" + str + "' is not in the string pool");
        }
        return index;
    
public booleangetNextEvent(android.app.usage.UsageEvents$Event eventOut)
Retrieve the next {@link android.app.usage.UsageEvents.Event} from the collection and put the resulting data into {@code eventOut}.

param
eventOut The {@link android.app.usage.UsageEvents.Event} object that will receive the next event data.
return
true if an event was available, false if there are no more events.

        if (mIndex >= mEventCount) {
            return false;
        }

        readEventFromParcel(mParcel, eventOut);

        mIndex++;
        if (mIndex >= mEventCount) {
            mParcel.recycle();
            mParcel = null;
        }
        return true;
    
public booleanhasNextEvent()
Returns whether or not there are more events to read using {@link #getNextEvent(android.app.usage.UsageEvents.Event)}.

return
true if there are more events, false otherwise.

        return mIndex < mEventCount;
    
private voidreadEventFromParcel(android.os.Parcel p, android.app.usage.UsageEvents$Event eventOut)
Reads a single event from the parcel. Modify this when updating {@link Event}.

        final int packageIndex = p.readInt();
        if (packageIndex >= 0) {
            eventOut.mPackage = mStringPool[packageIndex];
        } else {
            eventOut.mPackage = null;
        }

        final int classIndex = p.readInt();
        if (classIndex >= 0) {
            eventOut.mClass = mStringPool[classIndex];
        } else {
            eventOut.mClass = null;
        }
        eventOut.mEventType = p.readInt();
        eventOut.mTimeStamp = p.readLong();

        // Extract the configuration for configuration change events.
        if (eventOut.mEventType == Event.CONFIGURATION_CHANGE) {
            eventOut.mConfiguration = Configuration.CREATOR.createFromParcel(p);
        } else {
            eventOut.mConfiguration = null;
        }
    
public voidresetToStart()
Resets the collection so that it can be iterated over from the beginning.

hide
When this object is iterated to completion, the parcel is destroyed and so resetToStart doesn't work.

        mIndex = 0;
        if (mParcel != null) {
            mParcel.setDataPosition(0);
        }
    
private voidwriteEventToParcel(android.app.usage.UsageEvents$Event event, android.os.Parcel p, int flags)
Writes a single event to the parcel. Modify this when updating {@link Event}.

        final int packageIndex;
        if (event.mPackage != null) {
            packageIndex = findStringIndex(event.mPackage);
        } else {
            packageIndex = -1;
        }

        final int classIndex;
        if (event.mClass != null) {
            classIndex = findStringIndex(event.mClass);
        } else {
            classIndex = -1;
        }
        p.writeInt(packageIndex);
        p.writeInt(classIndex);
        p.writeInt(event.mEventType);
        p.writeLong(event.mTimeStamp);

        if (event.mEventType == Event.CONFIGURATION_CHANGE) {
            event.mConfiguration.writeToParcel(p, flags);
        }
    
public voidwriteToParcel(android.os.Parcel dest, int flags)

        dest.writeInt(mEventCount);
        dest.writeInt(mIndex);
        if (mEventCount > 0) {
            dest.writeStringArray(mStringPool);

            if (mEventsToWrite != null) {
                // Write out the events
                Parcel p = Parcel.obtain();
                try {
                    p.setDataPosition(0);
                    for (int i = 0; i < mEventCount; i++) {
                        final Event event = mEventsToWrite.get(i);
                        writeEventToParcel(event, p, flags);
                    }

                    final int listByteLength = p.dataPosition();

                    // Write the total length of the data.
                    dest.writeInt(listByteLength);

                    // Write our current position into the data.
                    dest.writeInt(0);

                    // Write the data.
                    dest.appendFrom(p, 0, listByteLength);
                } finally {
                    p.recycle();
                }

            } else if (mParcel != null) {
                // Write the total length of the data.
                dest.writeInt(mParcel.dataSize());

                // Write out current position into the data.
                dest.writeInt(mParcel.dataPosition());

                // Write the data.
                dest.appendFrom(mParcel, 0, mParcel.dataSize());
            } else {
                throw new IllegalStateException(
                        "Either mParcel or mEventsToWrite must not be null");
            }
        }