Example usage for android.database Cursor isBeforeFirst

List of usage examples for android.database Cursor isBeforeFirst

Introduction

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

Prototype

boolean isBeforeFirst();

Source Link

Document

Returns whether the cursor is pointing to the position before the first row.

Usage

From source file:net.sf.sprockets.database.Cursors.java

/**
 * True if the cursor position is between first and last (inclusive).
 *
 * @since 3.0.0//from  ww  w .  j a v a  2  s.  co m
 */
public static boolean isActive(Cursor cursor) {
    return !cursor.isClosed() && !cursor.isBeforeFirst() && !cursor.isAfterLast();
}

From source file:com.aboveware.sms.ui.MessageListAdapter.java

private boolean isCursorValid(Cursor cursor) {
    // Check whether the cursor is valid or not.
    if (cursor == null || cursor.isClosed() || cursor.isBeforeFirst() || cursor.isAfterLast()) {
        return false;
    }//from  www  .jav a2  s.  c om
    return true;
}

From source file:com.andrew.apollo.ui.activities.SearchActivity.java

/**
 * {@inheritDoc}//  w w w .j  a va 2 s.c  o m
 */
@Override
public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) {
    Cursor cursor = mAdapter.getCursor();
    cursor.moveToPosition(position);
    if (cursor.isBeforeFirst() || cursor.isAfterLast()) {
        return;
    }
    // Get the MIME type
    final String mimeType = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.MIME_TYPE));

    // If it's an artist, open the artist profile
    if ("artist".equals(mimeType)) {
        NavUtils.openArtistProfile(this,
                cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.ARTIST)));
    } else if ("album".equals(mimeType)) {
        // If it's an album, open the album profile
        NavUtils.openAlbumProfile(this,
                cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM)),
                cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ARTIST)));
    } else if (position >= 0 && id >= 0) {
        // If it's a song, play it and leave
        final long[] list = new long[] { id };
        MusicUtils.playAll(this, list, 0, false);
    }

    // Close it up
    cursor.close();
    cursor = null;
    // All done
    finish();
}

From source file:com.ksharkapps.musicnow.ui.activities.SearchActivity.java

/**
 * {@inheritDoc}//from ww  w.ja  v  a2s  . com
 */
@Override
public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) {
    Cursor cursor = mAdapter.getCursor();
    cursor.moveToPosition(position);
    if (cursor.isBeforeFirst() || cursor.isAfterLast()) {
        return;
    }
    // Get the MIME type
    final String mimeType = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.MIME_TYPE));

    // If it's an artist, open the artist profile
    if ("artist".equals(mimeType)) {
        NavUtils.openArtistProfile(this,
                cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.ARTIST)));
    } else if ("album".equals(mimeType)) {
        // If it's an album, open the album profile
        NavUtils.openAlbumProfile(this,
                cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM)),
                cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ARTIST)),
                cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums._ID)));
    } else if (position >= 0 && id >= 0) {
        // If it's a song, play it and leave
        final long[] list = new long[] { id };
        MusicUtils.playAll(this, list, 0, false);
    }

    // Close it up
    cursor.close();
    cursor = null;
    // All done
    finish();
}

From source file:info.guardianproject.otr.app.im.app.MessageView.java

protected String convertMediaUriToPath(Uri uri) {
    String path = null;//from w w w .  j  av a 2  s . c  om

    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = getContext().getContentResolver().query(uri, proj, null, null, null);
    if (cursor != null && (!cursor.isClosed())) {
        if (cursor.isBeforeFirst()) {
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();
            path = cursor.getString(column_index);
        }

        cursor.close();
    }

    return path;
}

From source file:com.silentcircle.contacts.list.PhoneNumberListAdapter.java

@Override
protected void bindView(View itemView, int partition, Cursor cursor, int position) {
    ContactListItemView view = (ContactListItemView) itemView;

    view.setHighlightedPrefix(isSearchMode() ? getUpperCaseQueryString() : null);

    // Look at elements before and after this position, checking if contact IDs are same.
    // If they have one same contact ID, it means they can be grouped.
    ///*  w w  w .  ja v a 2 s  .com*/
    // In one group, only the first entry will show its photo and its name, and the other
    // entries in the group show just their data (e.g. phone number, email address).
    cursor.moveToPosition(position);
    boolean isFirstEntry = true;
    boolean showBottomDivider = true;
    final long currentContactId = cursor.getLong(PhoneQuery.PHONE_CONTACT_ID);
    if (cursor.moveToPrevious() && !cursor.isBeforeFirst()) {
        final long previousContactId = cursor.getLong(PhoneQuery.PHONE_CONTACT_ID);
        if (currentContactId == previousContactId) {
            isFirstEntry = false;
        }
    }
    cursor.moveToPosition(position);
    if (cursor.moveToNext() && !cursor.isAfterLast()) {
        final long nextContactId = cursor.getLong(PhoneQuery.PHONE_CONTACT_ID);
        if (currentContactId == nextContactId) {
            // The following entry should be in the same group, which means we don't want a
            // divider between them.
            // TODO: we want a different divider than the divider between groups. Just hiding
            // this divider won't be enough.
            showBottomDivider = false;
        }
    }
    cursor.moveToPosition(position);

    bindSectionHeaderAndDivider(view, position);
    if (isFirstEntry) {
        bindName(view, cursor);
        if (isQuickContactEnabled()) {
            // No need for photo uri here, because we can not have directory results. If we
            // ever do, we need to add photo uri to the query
            bindQuickContact(view, partition, cursor, PhoneQuery.PHONE_PHOTO_ID, -1,
                    PhoneQuery.PHONE_CONTACT_ID);
        } else {
            bindPhoto(view, cursor);
        }
    } else {
        unbindName(view);

        view.removePhotoView(true, false);
    }
    bindPhoneNumber(view, cursor);
    view.setDividerVisible(showBottomDivider);
}

From source file:org.restcomm.app.qoslib.Services.Events.EventUploader.java

/**
 * This method gets a cursor that contains all the location objects that are associated with the
 * given event.//w w w .  java2s .c  om
 * @return
 */
private Cursor getLocationsAssociatedWithEvent(EventObj _event, String accuracy) {

    long startTime = _event.getEventTimestamp();
    //MMCLogger.logToFile(MMCLogger.Level.DEBUG, TAG, "getLocationsAssociatedWithEvent", "startTime="+startTime);
    Cursor cursor = owner.getDBProvider().query(UriMatch.LOCATIONS.getContentUri(), null,
            Tables.Locations.TIMESTAMP + ">=?" + accuracy, new String[] { String.valueOf(startTime) },
            Tables.Locations.TIMESTAMP + " ASC");
    cursor.moveToFirst();
    long gpsTime = 0;
    if (!cursor.isBeforeFirst()) {
        gpsTime = cursor.getLong(1);
        //MMCLogger.logToFile(MMCLogger.Level.DEBUG, TAG, "getLocationsAssociatedWithEvent", "time="+gpsTime);

    }
    return cursor;
}

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

/**
 * Update the arrows based on the current position of the older/newer cursor.
 *//*from w  w w .  ja v  a 2s  .  c om*/
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:com.android.mms.ui.ComposeMessageActivity.java

private boolean isCursorValid() {
    // Check whether the cursor is valid or not.
    Cursor cursor = mMsgListAdapter.getCursor();
    if (cursor.isClosed() || cursor.isBeforeFirst() || cursor.isAfterLast()) {
        Log.e(TAG, "Bad cursor.", new RuntimeException());
        return false;
    }//from   ww  w . j  av  a  2  s.  c om
    return true;
}