Example usage for android.database Cursor isFirst

List of usage examples for android.database Cursor isFirst

Introduction

In this page you can find the example usage for android.database Cursor isFirst.

Prototype

boolean isFirst();

Source Link

Document

Returns whether the cursor is pointing to the first row.

Usage

From source file:pandroid.agent.PandroidAgentListener.java

/**
 *  Retrieves the number of incoming, missed and outgoing calls
 *//*www.j  av  a2s .  c  o m*/
private void getCalls() {
    Cursor c = getApplicationContext().getContentResolver().query(android.provider.CallLog.Calls.CONTENT_URI,
            null, null, null, null);
    c.moveToFirst();
    int typeColumn = c.getColumnIndex(android.provider.CallLog.Calls.TYPE);
    int incoming = 0;
    int outgoing = 0;
    int missed = 0;

    if (c.isFirst()) {

        while (c.isAfterLast() == false) {
            int callType = c.getInt(typeColumn);

            switch (callType) {
            case android.provider.CallLog.Calls.INCOMING_TYPE:
                incoming++;
                break;
            case android.provider.CallLog.Calls.MISSED_TYPE:
                missed++;
                break;
            case android.provider.CallLog.Calls.OUTGOING_TYPE:
                outgoing++;
                break;
            }
            c.moveToNext();
        }

        putSharedData("PANDROID_DATA", "incomingCalls", "" + incoming, "integer");
        putSharedData("PANDROID_DATA", "missedCalls", "" + missed, "integer");
        putSharedData("PANDROID_DATA", "outgoingCalls", "" + outgoing, "integer");
    }

    c.close();
}

From source file:com.android.email.activity.MessageView.java

/**
 * Update the arrows based on the current position of the older/newer cursor.
 *///  w  ww .ja v a2 s  .  c o m
private void updateNavigationArrows(Cursor cursor) {
    if (cursor != null) {
        boolean hasNewer, hasOlder;
        if (cursor.isAfterLast() || cursor.isBeforeFirst()) {
            // The cursor not being on a message means that the current message was not found.
            // While this should not happen, simply disable prev/next arrows in that case.
            hasNewer = hasOlder = false;
        } else {
            hasNewer = !cursor.isFirst();
            hasOlder = !cursor.isLast();
        }
        mMoveToNewer.setVisibility(hasNewer ? View.VISIBLE : View.INVISIBLE);
        mMoveToOlder.setVisibility(hasOlder ? View.VISIBLE : View.INVISIBLE);
    }
}

From source file:nl.sogeti.android.gpstracker.viewer.LoggerMap.java

/**
 * For the current track identifier the route of that track is drawn by
 * adding a OverLay for each segments in the track
 *///from   w w  w .  j  a v a  2  s  .c  om
private void createDataOverlays() {
    mLastSegmentOverlay = null;
    resetOverlay();
    setupHardwareAcceleration();

    ContentResolver resolver = this.getContentResolver();
    Cursor segments = null;
    int trackColoringMethod = Integer.valueOf(mSharedPreferences.getString(Constants.TRACKCOLORING, "2"))
            .intValue();

    try {
        Uri segmentsUri = Uri.withAppendedPath(Tracks.CONTENT_URI, this.mTrackId + "/segments");
        segments = resolver.query(segmentsUri, new String[] { Segments._ID }, null, null, null);
        if (segments != null && segments.moveToFirst()) {
            do {
                long segmentsId = segments.getLong(0);
                Uri segmentUri = ContentUris.withAppendedId(segmentsUri, segmentsId);
                SegmentOverlay segmentOverlay = new SegmentOverlay(this, segmentUri, trackColoringMethod,
                        mAverageSpeed, this.mMapView, mHandler);
                mMapView.getOverlays().add(segmentOverlay);
                mLastSegmentOverlay = segmentOverlay;
                if (segments.isFirst()) {
                    segmentOverlay.addPlacement(SegmentOverlay.FIRST_SEGMENT);
                }
                if (segments.isLast()) {
                    segmentOverlay.addPlacement(SegmentOverlay.LAST_SEGMENT);
                }
                mLastSegment = segmentsId;
            } while (segments.moveToNext());
        }
    } finally {
        if (segments != null) {
            segments.close();
        }
    }

    Uri lastSegmentUri = Uri.withAppendedPath(Tracks.CONTENT_URI,
            mTrackId + "/segments/" + mLastSegment + "/waypoints");
    resolver.unregisterContentObserver(this.mSegmentWaypointsObserver);
    resolver.registerContentObserver(lastSegmentUri, false, this.mSegmentWaypointsObserver);
}