Example usage for android.database Cursor isAfterLast

List of usage examples for android.database Cursor isAfterLast

Introduction

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

Prototype

boolean isAfterLast();

Source Link

Document

Returns whether the cursor is pointing to the position after the last row.

Usage

From source file:com.google.android.apps.iosched.ui.tablet.TracksDropdownFragment.java

/** {@inheritDoc} */
public void onQueryComplete(int token, Object cookie, Cursor cursor) {
    if (getActivity() == null || cursor == null) {
        return;/*w  ww .j  ava  2s.  c o m*/
    }

    mCursor = cursor;
    getActivity().startManagingCursor(mCursor);

    // If there was a last-opened track, load it. Otherwise load the first track.
    cursor.moveToFirst();
    String lastTrackID = UIUtils.getLastUsedTrackID(getActivity());
    if (lastTrackID != null) {
        while (!cursor.isAfterLast()) {
            if (lastTrackID.equals(cursor.getString(TracksAdapter.TracksQuery.TRACK_ID))) {
                break;
            }
            cursor.moveToNext();
        }

        if (cursor.isAfterLast()) {
            loadTrack(null, mAutoloadTarget);
        } else {
            loadTrack(cursor, mAutoloadTarget);
        }
    } else {
        loadTrack(null, mAutoloadTarget);
    }

    mAdapter.setHasAllItem(true);
    mAdapter.setIsSessions(TracksFragment.NEXT_TYPE_SESSIONS.equals(mNextType));
    mAdapter.changeCursor(mCursor);
}

From source file:curso.android.DAO.PerguntaDAO.java

public static List<Pergunta> getPerguntasUsuario() {
    Cursor cursor = null;
    try {// ww  w  .  j  a  v a 2s. c o m
        List<Pergunta> questions = new ArrayList<Pergunta>();

        cursor = Const.db.rawQuery("SELECT * FROM pergunta WHERE user_id =" + Const.config.idUser, null);

        if (cursor.getCount() > 0) {
            int idIndex = cursor.getColumnIndex("ask_id");
            int userIndex = cursor.getColumnIndex("user_id");
            int perguntaIndex = cursor.getColumnIndex("ask_pergunta");
            int nameIndex = cursor.getColumnIndex("user_name");
            int statusIndex = cursor.getColumnIndex("status");

            cursor.moveToFirst();
            do {
                Long id = Long.valueOf(cursor.getInt(idIndex));
                Long user = Long.valueOf(cursor.getString(userIndex));
                String pergunta = cursor.getString(perguntaIndex);
                String user_name = cursor.getString(nameIndex);
                String status = cursor.getString(statusIndex);

                Pergunta ask = new Pergunta();
                ask.setAsk_id(id);
                ask.setUser_id(user);
                ask.setAsk_pergunta(pergunta);
                ask.setUser_name(user_name);
                ask.setStatus(Integer.valueOf(status) == 1);

                questions.add(ask);

                cursor.moveToNext();
            } while (!cursor.isAfterLast());
        }

        return questions;
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}

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

/**
 * {@inheritDoc}/*w  w  w.  ja v  a2  s .  c om*/
 */
@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:org.musicmod.android.dialog.PlaylistDialog.java

private String nameForId(long id) {

    Cursor cursor = MusicUtils.query(this, MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
            new String[] { MediaStore.Audio.Playlists.NAME }, MediaStore.Audio.Playlists._ID + "=?",
            new String[] { Long.valueOf(id).toString() }, MediaStore.Audio.Playlists.NAME);
    String name = null;/*  w  ww. ja  va  2s . co  m*/
    if (cursor != null) {
        cursor.moveToFirst();
        if (!cursor.isAfterLast()) {
            name = cursor.getString(0);
        }
        cursor.close();
    }
    return name;
}

From source file:org.benetech.secureapp.activities.MainActivity.java

public void exportRecordAllRecords() {
    Cursor cursor = getContentResolver().query(InstanceProviderAPI.InstanceColumns.CONTENT_URI, null, null,
            null, null);//from w w w  .  j  ava2s  .c o m
    cursor.moveToFirst();

    for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
        int formLabelColumnIndex = cursor.getColumnIndex(InstanceProviderAPI.InstanceColumns.DISPLAY_NAME);
        int displaySubTextColumnIndex = cursor
                .getColumnIndex(InstanceProviderAPI.InstanceColumns.DISPLAY_SUBTEXT);
        int instancefilepathColumnIndex = cursor
                .getColumnIndex(InstanceProviderAPI.InstanceColumns.INSTANCE_FILE_PATH);
        int formIdColumnIndex = cursor.getColumnIndex(InstanceProviderAPI.InstanceColumns._ID);

        SharedPreferences sharedPref = getApplicationContext()
                .getSharedPreferences(AccountInformationActivity.PRFERENCES_FILE_NAME, Context.MODE_PRIVATE);
        String authorName = sharedPref.getString(AccountInformationActivity.AUTHOR_PREFERENCES_KEY, "");
        String organizationName = sharedPref.getString(AccountInformationActivity.ORGANIZATION_PREFRENCES_KEY,
                "");

        Intent intent = new Intent(this, BulletinToMbaFileExporter.class);
        intent.putExtra(MartusUploadManager.BULLETIN_DISPLAY_NAME_TAG, cursor.getString(formLabelColumnIndex));
        intent.putExtra(MartusUploadManager.BULLETIN_SUB_DISPLAY_NAME_TAG,
                cursor.getString(displaySubTextColumnIndex));
        intent.putExtra(MartusUploadManager.BULLETIN_ISTANCE_FILE_PATH_TAG,
                cursor.getString(instancefilepathColumnIndex));
        intent.putExtra(MartusUploadManager.BULLETIN_FORM_ID_TAG, cursor.getString(formIdColumnIndex));
        intent.putExtra(MartusUploadManager.BULLETIN_AUTHOR_TAG, authorName);
        intent.putExtra(MartusUploadManager.BULLETIN_ORGANIZATION_TAG, organizationName);
        startActivityForResult(intent, EXPORT_RECORDS_REQUEST_CODE);
    }
}

From source file:org.dalmasso.ietfsched.ui.tablet.TracksDropdownFragment.java

/** {@inheritDoc} */
public void onQueryComplete(int token, Object cookie, Cursor cursor) {
    if (getActivity() == null || cursor == null) {
        return;/* ww  w.  j  a  v  a2  s.c  om*/
    }

    mCursor = cursor;
    getActivity().startManagingCursor(mCursor);

    // If there was a last-opened track, load it. Otherwise load the first track.
    cursor.moveToFirst();
    String lastTrackID = UIUtils.getLastUsedTrackID(getActivity());
    if (lastTrackID != null) {
        while (!cursor.isAfterLast()) {
            if (lastTrackID.equals(cursor.getString(TracksAdapter.TracksQuery.TRACK_ID))) {
                break;
            }
            cursor.moveToNext();
        }

        if (cursor.isAfterLast()) {
            loadTrack(null, mAutoloadTarget, false);
        } else {
            loadTrack(cursor, mAutoloadTarget, false);
        }
    } else {
        loadTrack(null, mAutoloadTarget, false);
    }

    mAdapter.setHasAllItem(true);
    mAdapter.setIsSessions(TracksFragment.NEXT_TYPE_SESSIONS.equals(mNextType));
    mAdapter.changeCursor(mCursor);
}

From source file:edu.auburn.ppl.cyclecolumbus.TripUploader.java

@Override
protected Boolean doInBackground(Long... tripid) {
    // First, send the trip user asked for:
    Boolean result = true;//from   w  ww  .ja  va  2 s .co  m
    if (tripid.length != 0) {
        result = uploadOneTrip(tripid[0]);
    }

    // Then, automatically try and send previously-completed trips
    // that were not sent successfully.
    Vector<Long> unsentTrips = new Vector<Long>();

    mDb.openReadOnly();
    Cursor cur = mDb.fetchUnsentTrips();
    if (cur != null && cur.getCount() > 0) {
        // Reades all unsent trips
        while (!cur.isAfterLast()) {
            unsentTrips.add(Long.valueOf(cur.getLong(0)));
            cur.moveToNext();
        }
        cur.close();
    }
    mDb.close();

    for (Long trip : unsentTrips) {
        result &= uploadOneTrip(trip);
    }
    return result;
}

From source file:org.opensmc.mytracks.cyclesmc.TripUploader.java

@Override
protected Boolean doInBackground(Long... tripid) {
    // First, send the trip user asked for:
    Boolean result = uploadOneTrip(tripid[0]);

    // TODO: not always working?
    //Log.d("uploading trip", tripid[0].toString());
    //////////////////////////////////////////////

    // Then, automatically try and send previously-completed trips
    // that were not sent successfully.
    Vector<Long> unsentTrips = new Vector<Long>();

    mDb.openReadOnly();/*from w w w . j a v a  2  s  .c om*/
    Cursor cur = mDb.fetchUnsentTrips();
    if (cur != null && cur.getCount() > 0) {
        //pd.setMessage("Sent. You have previously unsent trips; submitting those now.");

        ////////////
        //Log.d("previously unsent count", cur.getCount() + " previously unsent trips");
        ////////////

        while (!cur.isAfterLast()) {
            unsentTrips.add(Long.valueOf(cur.getLong(0)));
            cur.moveToNext();
        }
        cur.close();
    }
    mDb.close();

    for (Long trip : unsentTrips) {
        result &= uploadOneTrip(trip);
        ///////////////
        //Log.d("uploading unsent trip", trip.toString());
        ///////////////

    }
    return result;
}

From source file:gov.wa.wsdot.android.wsdot.service.MountainPassesSyncService.java

/** 
 * Check the mountain pass table for any starred entries. If we find some, save them
 * to a list so we can re-star those passes after we flush the database.
 *//* w  w w  .ja  v a  2 s . co  m*/
private List<Integer> getStarred() {
    ContentResolver resolver = getContentResolver();
    Cursor cursor = null;
    List<Integer> starred = new ArrayList<Integer>();

    try {
        cursor = resolver.query(MountainPasses.CONTENT_URI, new String[] { MountainPasses.MOUNTAIN_PASS_ID },
                MountainPasses.MOUNTAIN_PASS_IS_STARRED + "=?", new String[] { "1" }, null);

        if (cursor != null && cursor.moveToFirst()) {
            while (!cursor.isAfterLast()) {
                starred.add(cursor.getInt(0));
                cursor.moveToNext();
            }
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }

    return starred;
}

From source file:ch.ethz.twimight.net.tds.TDSRequestMessage.java

public void createDisTweetsObject(Cursor tweets) throws JSONException {

    if (tweets != null && tweets.getCount() > 0) {

        tweets.moveToFirst();/* ww  w .ja v a 2 s.  co  m*/
        disTweetsObject = new JSONObject();
        JSONArray disTweetsArray = new JSONArray();
        CertificateManager cm = new CertificateManager(context.getApplicationContext());

        while (!tweets.isAfterLast()) {

            if (!tweets.isNull(tweets.getColumnIndex(Tweets.COL_SIGNATURE))) {
                JSONObject row = new JSONObject();
                row.put(Tweets.COL_TEXT_PLAIN, tweets.getString(tweets.getColumnIndex(Tweets.COL_TEXT_PLAIN)));
                row.put(Tweets.COL_USER_TID, tweets.getLong(tweets.getColumnIndex(Tweets.COL_USER_TID)));
                row.put(Tweets.COL_DISASTER_ID, tweets.getLong(tweets.getColumnIndex(Tweets.COL_DISASTER_ID)));
                row.put(Tweets.COL_SIGNATURE, tweets.getString(tweets.getColumnIndex(Tweets.COL_SIGNATURE)));

                SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                row.put(Tweets.COL_CREATED_AT + "_phone", simpleFormat
                        .format(new Date(tweets.getLong(tweets.getColumnIndex(Tweets.COL_CREATED_AT)))));
                // add picture if available
                if (tweets.getString(tweets.getColumnIndex(Tweets.COL_MEDIA_URIS)) != null) {
                    SDCardHelper sdCardHelper = new SDCardHelper();
                    String base64Photo = sdCardHelper.getImageAsBas64Jpeg(
                            tweets.getString(tweets.getColumnIndex(Tweets.COL_MEDIA_URIS)), null);
                    Log.d(TAG, base64Photo);
                    row.put(PHOTO, base64Photo);
                }

                disTweetsArray.put(row);
            }

            tweets.moveToNext();
        }
        tweets.close();

        if (disTweetsArray.length() > 0)
            disTweetsObject.put("content", disTweetsArray);
        else
            disTweetsObject = null;

    }
}