Example usage for android.database Cursor moveToNext

List of usage examples for android.database Cursor moveToNext

Introduction

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

Prototype

boolean moveToNext();

Source Link

Document

Move the cursor to the next row.

Usage

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

@Override
protected Boolean doInBackground(Long... noteid) {
    // First, send the note user asked for:
    Boolean result = true;//from  w  ww  . j  av  a  2  s .c  o  m
    if (noteid.length != 0) {
        result = uploadOneNote(noteid[0]);
    }

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

    mDb.openReadOnly();
    Cursor cur = mDb.fetchUnsentNotes();
    if (cur != null && cur.getCount() > 0) {
        // pd.setMessage("Sent. You have previously unsent notes; submitting those now.");
        while (!cur.isAfterLast()) {
            unsentNotes.add(Long.valueOf(cur.getLong(0)));
            cur.moveToNext();
        }
        cur.close();
    }
    mDb.close();

    for (Long note : unsentNotes) {
        result &= uploadOneNote(note);
    }
    return result;
}

From source file:at.bitfire.ical4android.AndroidCalendar.java

protected AndroidEvent[] queryEvents(String where, String[] whereArgs) throws CalendarStorageException {
    where = (where == null ? "" : "(" + where + ") AND ") + Events.CALENDAR_ID + "=?";
    whereArgs = ArrayUtils.add(whereArgs, String.valueOf(id));

    @Cleanup
    Cursor cursor = null;/*www.  jav  a  2s.c om*/
    try {
        cursor = provider.query(syncAdapterURI(Events.CONTENT_URI), eventBaseInfoColumns(), where, whereArgs,
                null);
    } catch (RemoteException e) {
        throw new CalendarStorageException("Couldn't query calendar events", e);
    }

    List<AndroidEvent> events = new LinkedList<>();
    while (cursor != null && cursor.moveToNext()) {
        ContentValues baseInfo = new ContentValues(cursor.getColumnCount());
        DatabaseUtils.cursorRowToContentValues(cursor, baseInfo);
        events.add(eventFactory.newInstance(this, cursor.getLong(0), baseInfo));
    }
    return events.toArray(eventFactory.newArray(events.size()));
}

From source file:com.yuntongxun.ecdemo.storage.IMessageSqlManager.java

/**
 * ?//from   www . j  ava2  s  .  c o  m
 *
 * @return
 */
public static List<ECMessage> getDowndFailMsg() {
    String sql = "select * from " + DatabaseHelper.TABLES_NAME_IM_MESSAGE + " where msgType="
            + ECMessage.Type.IMAGE.ordinal() + " and box_type=2 and userData is null";
    Cursor cursor = null;

    List<ECMessage> al = null;
    try {
        cursor = getInstance().sqliteDB().rawQuery(sql, null);
        if (cursor != null && cursor.getCount() > 0) {
            al = new ArrayList<ECMessage>();
            while (cursor.moveToNext()) {

                ECMessage ecMessage = packageMessage(cursor);
                if (ecMessage == null) {
                    continue;
                }
                al.add(0, ecMessage);
            }
        }
    } catch (Exception e) {
        LogUtil.e(TAG + " " + e.toString());
        e.printStackTrace();
    } finally {
        if (cursor != null) {
            cursor.close();
            cursor = null;
        }
    }
    return al;
}

From source file:com.msrproduction.sunshine.app.FetchWeatherTask.java

/**
 * Helper method to handle insertion of a new location in the weather database.
 *
 * @param locationSetting The location string used to request updates from the server.
 * @param cityName A human-readable city name, e.g "Mountain View"
 * @param lat the latitude of the city//  w w w.  j  a  va 2 s .c  o  m
 * @param lon the longitude of the city
 * @return the row ID of the added location.
 */
long addLocation(String locationSetting, String cityName, double lat, double lon) {
    long locationId;

    Cursor locationCursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI,
            new String[] { WeatherContract.LocationEntry._ID },
            WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting },
            null);
    if (locationCursor.moveToNext()) {
        int locationIdIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID);
        locationId = locationCursor.getLong(locationIdIndex);
    } else {
        ContentValues locationValues = new ContentValues();

        locationValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName);
        locationValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting);
        locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat);
        locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon);

        Uri insertedUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI,
                locationValues);

        locationId = ContentUris.parseId(insertedUri);
    }
    locationCursor.close();
    return locationId;
}

From source file:org.mythtv.android.db.dvr.ProgramHelperV27.java

public List<Program> findAllPrograms(final Context context, final LocationProfile locationProfile, Uri uri,
        String table) {/*from w ww  . j a  v  a  2s.  c  o m*/
    Log.d(TAG, "findAllPrograms : enter");

    String programSelection = null;
    String[] programSelectionArgs = null;

    programSelection = appendLocationHostname(context, locationProfile, programSelection, table);

    List<Program> programs = new ArrayList<Program>();
    ;

    Cursor cursor = context.getContentResolver().query(uri, null, programSelection, programSelectionArgs, null);
    while (cursor.moveToNext()) {

        Program program = convertCursorToProgram(cursor, table);
        programs.add(program);

    }
    cursor.close();

    Log.d(TAG, "findAllPrograms : exit");
    return programs;
}

From source file:com.bellman.bible.service.db.bookmark.BookmarkDBAdapter.java

public List<BookmarkDto> getUnlabelledBookmarks() {
    String sql = "SELECT " + SQLHelper.getColumnsForQuery(BookmarkQuery.TABLE, BookmarkQuery.COLUMNS)
            + " FROM bookmark "
            + " WHERE NOT EXISTS (SELECT * FROM bookmark_label WHERE bookmark._id = bookmark_label.bookmark_id)";

    List<BookmarkDto> bookmarks = new ArrayList<BookmarkDto>();
    Cursor c = db.rawQuery(sql, null);
    try {/*ww w  .j  a v a  2 s.c  o  m*/
        if (c.moveToFirst()) {
            while (!c.isAfterLast()) {
                BookmarkDto bookmark = getBookmarkDto(c);
                bookmarks.add(bookmark);
                c.moveToNext();
            }
        }
    } finally {
        c.close();
    }

    return bookmarks;
}

From source file:com.miz.service.TraktTvShowsSyncService.java

private void loadTvShowLibrary() {
    // Get shows//from w w w .j  a v  a2s  . co m
    mShowDatabase = MizuuApplication.getTvDbAdapter();
    Cursor cursor = mShowDatabase.getAllShows();
    ColumnIndexCache cache = new ColumnIndexCache();

    try {
        while (cursor.moveToNext()) {
            mShowIds.add(cursor.getString(cache.getColumnIndex(cursor, DbAdapterTvShows.KEY_SHOW_ID)));

            // Full TV shows
            mShows.add(new TvShow(this,
                    cursor.getString(cache.getColumnIndex(cursor, DbAdapterTvShows.KEY_SHOW_ID)),
                    cursor.getString(cache.getColumnIndex(cursor, DbAdapterTvShows.KEY_SHOW_TITLE)),
                    cursor.getString(cache.getColumnIndex(cursor, DbAdapterTvShows.KEY_SHOW_PLOT)),
                    cursor.getString(cache.getColumnIndex(cursor, DbAdapterTvShows.KEY_SHOW_RATING)),
                    cursor.getString(cache.getColumnIndex(cursor, DbAdapterTvShows.KEY_SHOW_GENRES)),
                    cursor.getString(cache.getColumnIndex(cursor, DbAdapterTvShows.KEY_SHOW_ACTORS)),
                    cursor.getString(cache.getColumnIndex(cursor, DbAdapterTvShows.KEY_SHOW_CERTIFICATION)),
                    cursor.getString(cache.getColumnIndex(cursor, DbAdapterTvShows.KEY_SHOW_FIRST_AIRDATE)),
                    cursor.getString(cache.getColumnIndex(cursor, DbAdapterTvShows.KEY_SHOW_RUNTIME)), false,
                    cursor.getString(cache.getColumnIndex(cursor, DbAdapterTvShows.KEY_SHOW_FAVOURITE)),
                    MizuuApplication.getTvEpisodeDbAdapter().getLatestEpisodeAirdate(
                            cursor.getString(cache.getColumnIndex(cursor, DbAdapterTvShows.KEY_SHOW_ID)))));

            if (cursor.getString(cache.getColumnIndex(cursor, DbAdapterTvShows.KEY_SHOW_FAVOURITE)).equals("1"))
                mLocalFavorites
                        .add(cursor.getString(cache.getColumnIndex(cursor, DbAdapterTvShows.KEY_SHOW_ID)));
        }
    } catch (Exception e) {
    } finally {
        cursor.close();
        cache.clear();
    }

    mEpisodeDatabase = MizuuApplication.getTvEpisodeDbAdapter();
    int count = mShows.size();
    for (int i = 0; i < count; i++) {
        TraktTvShow collectionShow = new TraktTvShow(mShows.get(i).getId(), mShows.get(i).getTitle());
        TraktTvShow watchedShow = new TraktTvShow(mShows.get(i).getId(), mShows.get(i).getTitle());

        Cursor c = mEpisodeDatabase.getEpisodes(mShows.get(i).getId());
        try {
            while (c.moveToNext()) {
                collectionShow.addEpisode(
                        c.getString(cache.getColumnIndex(c, DbAdapterTvShowEpisodes.KEY_SEASON)),
                        c.getString(cache.getColumnIndex(c, DbAdapterTvShowEpisodes.KEY_EPISODE)));

                if (c.getString(cache.getColumnIndex(c, DbAdapterTvShowEpisodes.KEY_HAS_WATCHED)).equals("1")) {
                    watchedShow.addEpisode(
                            c.getString(cache.getColumnIndex(c, DbAdapterTvShowEpisodes.KEY_SEASON)),
                            c.getString(cache.getColumnIndex(c, DbAdapterTvShowEpisodes.KEY_EPISODE)));
                }
            }
        } catch (Exception ignored) {
        } finally {
            c.close();
        }

        if (collectionShow.getSeasons().size() > 0)
            mLocalCollection.add(collectionShow);

        if (watchedShow.getSeasons().size() > 0)
            mLocalWatched.add(watchedShow);
    }
}

From source file:com.looseboxes.idisc.common.util.ContactEmailsExtractor.java

public JSONObject getNameEmailDetails(Context context) {

    JSONObject emailsMap = new JSONObject();

    Set<String> emailsSet = new HashSet<String>();

    ContentResolver contentResolver = context.getContentResolver();

    String[] PROJECTION = new String[] { ContactsContract.RawContacts._ID,
            ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.Contacts.PHOTO_ID,
            ContactsContract.CommonDataKinds.Email.DATA, ContactsContract.CommonDataKinds.Photo.CONTACT_ID };

    String order = "CASE WHEN " + ContactsContract.Contacts.DISPLAY_NAME + " NOT LIKE '%@%' THEN 1 ELSE 2 END, "
            + ContactsContract.Contacts.DISPLAY_NAME + ", " + ContactsContract.CommonDataKinds.Email.DATA
            + " COLLATE NOCASE";

    String filter = ContactsContract.CommonDataKinds.Email.DATA + " NOT LIKE ''";

    Cursor cur = contentResolver.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, PROJECTION, filter,
            null, order);// ww  w .ja va2  s .co m

    if (cur.moveToFirst()) {

        do {

            // names comes in hand sometimes
            String name = cur.getString(1);
            String email = cur.getString(3);

            // keep unique only
            if (emailsSet.add(email.toLowerCase())) {
                emailsMap.put(email, name);
            }
        } while (cur.moveToNext());
    }

    cur.close();

    return emailsMap;
}

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

public static List<Pergunta> readAll() {
    Cursor cursor = null;
    try {// ww  w . j a v  a  2 s . co m
        List<Pergunta> all = 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 nomeIndex = 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(nomeIndex);
                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);

                all.add(ask);

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

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

From source file:com.bellman.bible.service.db.bookmark.BookmarkDBAdapter.java

public List<BookmarkDto> getBookmarksWithLabel(LabelDto label) {
    String sql = "SELECT " + SQLHelper.getColumnsForQuery(BookmarkQuery.TABLE, BookmarkQuery.COLUMNS)
            + " FROM bookmark " + "JOIN bookmark_label ON (bookmark._id = bookmark_label.bookmark_id) "
            + "JOIN label ON (bookmark_label.label_id = label._id) " + "WHERE label._id = ? ";

    List<BookmarkDto> allBookmarks = new ArrayList<BookmarkDto>();
    String[] args = new String[] { label.getId().toString() };
    Cursor c = db.rawQuery(sql, args);
    try {//from  w ww  . j  ava2s .  c  o  m
        if (c.moveToFirst()) {
            while (!c.isAfterLast()) {
                BookmarkDto bookmark = getBookmarkDto(c);
                allBookmarks.add(bookmark);
                c.moveToNext();
            }
        }
    } finally {
        c.close();
    }

    return allBookmarks;
}