List of usage examples for android.database Cursor isAfterLast
boolean isAfterLast();
From source file:com.example.android.movies.MainActivity.java
public void getFavoriteMoviesFromDB() { // Get all movie objects from the database and save in a cursor Cursor cursor = getAllMovies(); ArrayList<Movie> favoriteMovies = new ArrayList<Movie>(); cursor.moveToFirst();/*from w w w.j a v a2 s. c om*/ while (!cursor.isAfterLast()) { favoriteMovies .add(new Movie(cursor.getInt(cursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_MOVIE_ID)), cursor.getString(cursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_TITLE)), cursor.getString( cursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_POSTER_PATH_URL)), cursor.getString(cursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_ORIGINAL_TITLE)), cursor.getString(cursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_SYNOPSIS)), cursor.getString(cursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_USER_RATING)), cursor.getString(cursor.getColumnIndex(MovieContract.MovieEntry.COLUMN_RELEASE_DATE)))); //add the item cursor.moveToNext(); } // Link the adapter to the RecyclerView mMovieAdapter.setMoviesData(favoriteMovies); }
From source file:com.bellman.bible.service.db.bookmark.BookmarkDBAdapter.java
public List<LabelDto> getAllLabels() { List<LabelDto> allLabels = new ArrayList<LabelDto>(); Cursor c = db.query(LabelQuery.TABLE, LabelQuery.COLUMNS, null, null, null, null, LabelColumn.NAME); try {/*from w w w . ja v a 2s . com*/ if (c.moveToFirst()) { while (!c.isAfterLast()) { LabelDto bookmark = getLabelDto(c); allLabels.add(bookmark); c.moveToNext(); } } } finally { c.close(); } return allLabels; }
From source file:gov.wa.wsdot.android.wsdot.service.TravelTimesSyncService.java
/** * Check the travel times table for any starred entries. If we find some, save them * to a list so we can re-star those after we flush the database. *///from www.j a 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(TravelTimes.CONTENT_URI, new String[] { TravelTimes.TRAVEL_TIMES_ID }, TravelTimes.TRAVEL_TIMES_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:com.chalmers.feedlr.service.DataService.java
public void updateFeedFacebookItems(final Feed feed) { final long time = System.currentTimeMillis(); final List<User> facebookUsersInFeed = new ArrayList<User>(); final List<FacebookItem> facebookItemsForUsers = new ArrayList<FacebookItem>(); Cursor c = db.getUsers(feed, "facebook"); c.moveToFirst();//from w w w . java 2 s . c o m while (!c.isAfterLast()) { facebookUsersInFeed.add(new User(c.getString(c.getColumnIndex(DatabaseHelper.USER_COLUMN_USERID)), c.getString(c.getColumnIndex(DatabaseHelper.USER_COLUMN_USERNAME)))); c.moveToNext(); } facebook.getFeedsForUsers(facebookUsersInFeed, new com.facebook.android.AsyncFacebookRunner.RequestListener() { private int responses = 0; @Override public void onComplete(String response, Object state) { try { if (response != null) { facebookItemsForUsers.addAll(new FacebookJSONParser().parseFeed(response)); } } catch (Exception e) { Log.e(getClass().getName(), e.getMessage()); } responses++; if (responses == facebookUsersInFeed.size()) { onAllComplete(); } } private void onAllComplete() { db.addListOfItems(facebookItemsForUsers); // Broadcast update to activity Intent intent = new Intent(); intent.setAction(FeedActivity.FEED_UPDATED); Bundle b = new Bundle(); b.putString("feedTitle", feed.getTitle()); intent.putExtras(b); lbm.sendBroadcast(intent); Log.i(TwitterJSONParser.class.getName(), "Time in millis for complete update of feed \"" + feed.getTitle() + "\" facebook items request: " + (System.currentTimeMillis() - time)); } @Override public void onFacebookError(FacebookError e, final Object state) { Log.e("Parse", "Facebook Error:" + e.getMessage()); } @Override public void onFileNotFoundException(FileNotFoundException e, final Object state) { Log.e("Parse", "Resource not found:" + e.getMessage()); } @Override public void onIOException(IOException e, final Object state) { Log.e("Parse", "Network Error:" + e.getMessage()); } @Override public void onMalformedURLException(MalformedURLException e, final Object state) { Log.e("Parse", "Invalid URL:" + e.getMessage()); } }); }
From source file:de.uni_koblenz_landau.apow.db.SyncDBHelper.java
/** * Finds the last modified date of a table. * @param table Table//from www . j av a 2 s .c om * @return Last modified date */ public String lastUpdate(String table) { String query; String lastupdate = ""; if (table.equals(Constants.TABLES.OBS.getName())) { query = "SELECT MAX(IFNULL(date_created, 0)) FROM obs;"; } else { query = "SELECT MAX(MAX(IFNULL(date_changed, 0)), MAX(IFNULL(date_created, 0))) FROM " + table; } Cursor cursor = mDatabase.rawQuery(query, new String[] {}); cursor.moveToFirst(); if (!cursor.isAfterLast()) { lastupdate = cursor.getString(0); } cursor.close(); return lastupdate; }
From source file:org.mariotaku.twidere.util.DataStoreUtils.java
@NonNull public static UserKey[] getFilteredUserIds(Context context) { if (context == null) return new UserKey[0]; final ContentResolver resolver = context.getContentResolver(); final String[] projection = { Filters.Users.USER_KEY }; final Cursor cur = resolver.query(Filters.Users.CONTENT_URI, projection, null, null, null); if (cur == null) return new UserKey[0]; try {// w w w. ja va2 s. c o m final UserKey[] ids = new UserKey[cur.getCount()]; cur.moveToFirst(); int i = 0; while (!cur.isAfterLast()) { ids[i] = UserKey.valueOf(cur.getString(0)); cur.moveToNext(); i++; } cur.close(); return ids; } finally { cur.close(); } }
From source file:de.uni_koblenz_landau.apow.db.SyncDBHelper.java
/** * Is row modified?// w ww . ja va 2 s .c om * @param table Table * @param uuid UUID * @return -1 if new, 0 if not modified, 1 if modified */ private int isDirty(String table, String uuid) { int dirty = -1; String query = "SELECT dirty FROM " + table + " WHERE uuid = ?;"; Cursor cursor = mDatabase.rawQuery(query, new String[] { uuid }); cursor.moveToFirst(); if (!cursor.isAfterLast()) { dirty = cursor.getInt(0); } cursor.close(); return dirty; }
From source file:de.uni_koblenz_landau.apow.db.SyncDBHelper.java
/** * Gets ID of a person by UUID.// w ww. ja v a2s. co m * @param uuid UUID * @return Person ID */ private int getPersonIDByUUID(String uuid) { int result = -1; String query = "SELECT pe.person_id FROM person pe WHERE pe.uuid = ?"; Cursor cursor = mDatabase.rawQuery(query, new String[] { uuid }); cursor.moveToFirst(); if (!cursor.isAfterLast()) { result = cursor.getInt(0); } cursor.close(); return result; }
From source file:de.uni_koblenz_landau.apow.db.SyncDBHelper.java
/** * Gets ID of an encounter by UUID.//from w w w . ja va2s .c o m * @param uuid UUID * @return Encounter ID */ private int getEncounterIDByUUID(String uuid) { int result = -1; String query = "SELECT en.encounter_id FROM encounter en WHERE en.uuid = ?"; Cursor cursor = mDatabase.rawQuery(query, new String[] { uuid }); cursor.moveToFirst(); if (!cursor.isAfterLast()) { result = cursor.getInt(0); } cursor.close(); return result; }
From source file:de.uni_koblenz_landau.apow.db.SyncDBHelper.java
/** * Gets ID of an observation by UUID.// ww w .j a v a 2 s . co m * @param uuid UUID * @return Observation ID */ private int getObsIDByUUID(String uuid) { int result = -1; String query = "SELECT o.obs_id FROM obs o WHERE o.uuid = ?"; Cursor cursor = mDatabase.rawQuery(query, new String[] { uuid }); cursor.moveToFirst(); if (!cursor.isAfterLast()) { result = cursor.getInt(0); } cursor.close(); return result; }