List of usage examples for android.database Cursor moveToNext
boolean moveToNext();
From source file:com.google.samples.apps.topeka.persistence.TopekaDatabaseHelper.java
/** * Creates objects for quizzes according to a category id. * * @param categoryId The category to create quizzes for. * @param database The database containing the quizzes. * @return The found quizzes or an empty list if none were available. *//*from w w w.j a v a2 s .c o m*/ private static List<Quiz> getQuizzes(final String categoryId, SQLiteDatabase database) { final List<Quiz> quizzes = new ArrayList<>(); final Cursor cursor = database.query(QuizTable.NAME, QuizTable.PROJECTION, QuizTable.FK_CATEGORY + " LIKE ?", new String[] { categoryId }, null, null, null); cursor.moveToFirst(); do { quizzes.add(createQuizDueToType(cursor)); } while (cursor.moveToNext()); cursor.close(); return quizzes; }
From source file:com.csipsimple.utils.SipProfileJson.java
public static JSONObject serializeSipProfile(SipProfile profile, DBAdapter db) { JSONObject jsonProfile = serializeBaseSipProfile(profile); JSONArray jsonFilters = new JSONArray(); Cursor c = db.getFiltersForAccount(profile.id); int numRows = c.getCount(); c.moveToFirst();/*from www .jav a2 s. c o m*/ for (int i = 0; i < numRows; ++i) { Filter f = new Filter(); f.createFromDb(c); try { jsonFilters.put(i, serializeBaseFilter(f)); } catch (JSONException e) { Log.e(THIS_FILE, "Impossible to add fitler", e); e.printStackTrace(); } c.moveToNext(); } c.close(); try { jsonProfile.put(FILTER_KEY, jsonFilters); } catch (JSONException e) { Log.e(THIS_FILE, "Impossible to add fitlers", e); } return jsonProfile; }
From source file:Main.java
public static boolean haveCalendars(Activity ctx) { boolean exists = false; String[] projection = new String[] { "_id", "name" }; Uri calendars = Uri.parse("content://calendar/calendars"); // Calendar uri changes for 2.2 Uri calendars_2_2 = Uri.parse("content://com.android.calendar/calendars"); Cursor managedCursor = ctx.managedQuery(calendars, projection, null, null, null); if (managedCursor == null || managedCursor.getCount() == 0) managedCursor = ctx.managedQuery(calendars_2_2, projection, null, null, null); if (managedCursor != null && managedCursor.moveToFirst()) { String calName;/*from ww w. j a v a 2s . c o m*/ String calId; int nameColumn = managedCursor.getColumnIndex("name"); int idColumn = managedCursor.getColumnIndex("_id"); do { calName = managedCursor.getString(nameColumn); calId = managedCursor.getString(idColumn); exists = true; } while (managedCursor.moveToNext()); managedCursor.close(); } return exists; }
From source file:edu.stanford.mobisocial.dungbeetle.DungBeetleContentProvider.java
static void notifyDependencies(DBHelper helper, ContentResolver resolver, String feedName) { Uri feedUri = Feed.uriForName(feedName); if (DBG)//from ww w . java2 s . co m Log.d(TAG, "notifying dependencies of " + feedUri); resolver.notifyChange(feedUri, null); resolver.notifyChange(Feed.uriForName(Feed.FEED_NAME_GLOBAL), null); if (feedName.contains(":")) { feedName = feedName.split(":")[0]; resolver.notifyChange(Feed.uriForName(feedName), null); } Cursor c = helper.getFeedDependencies(feedName); try { while (c.moveToNext()) { Uri uri = Feed.uriForName(c.getString(0)); resolver.notifyChange(uri, null); } } finally { c.close(); } }
From source file:com.csipsimple.backup.SipProfileJson.java
public static JSONObject serializeSipProfile(Context context, SipProfile profile) { JSONObject jsonProfile = serializeBaseSipProfile(profile); JSONArray jsonFilters = new JSONArray(); Cursor c = Filter.getFiltersCursorForAccount(context, profile.id); int numRows = c.getCount(); c.moveToFirst();//w w w . ja v a 2s . co m for (int i = 0; i < numRows; ++i) { Filter f = new Filter(c); try { jsonFilters.put(i, serializeBaseFilter(f)); } catch (JSONException e) { Log.e(THIS_FILE, "Impossible to add fitler", e); } c.moveToNext(); } c.close(); try { jsonProfile.put(FILTER_KEY, jsonFilters); } catch (JSONException e) { Log.e(THIS_FILE, "Impossible to add fitlers", e); } return jsonProfile; }
From source file:ro.weednet.contactssync.platform.ContactManager.java
public static List<RawContact> getLocalContacts(Context context, Uri uri) { Log.i(TAG, "*** Looking for local contacts"); List<RawContact> localContacts = new ArrayList<RawContact>(); final ContentResolver resolver = context.getContentResolver(); final Cursor c = resolver.query(uri, new String[] { Contacts._ID, RawContacts.SOURCE_ID }, null, null, null);//w ww .ja v a 2 s . c om try { while (c.moveToNext()) { final long rawContactId = c.getLong(0); final String serverContactId = c.getString(1); RawContact rawContact = RawContact.create(rawContactId, serverContactId); localContacts.add(rawContact); } } finally { if (c != null) { c.close(); } } Log.i(TAG, "*** ... found " + localContacts.size()); return localContacts; }
From source file:edu.mit.mobile.android.locast.data.TaggableItem.java
/** * @param cr//from w w w .ja va2 s. c o m * @param item * @param prefix * @return a list of all the tags attached to a given item */ public static Set<String> getTags(ContentResolver cr, Uri item, String prefix) { final Cursor tags = cr.query(Uri.withAppendedPath(item, Tag.PATH), Tag.DEFAULT_PROJECTION, null, null, null); final Set<String> tagSet = new HashSet<String>(tags.getCount()); final int tagColumn = tags.getColumnIndex(Tag._NAME); final Predicate<String> predicate = getPrefixPredicate(prefix); for (tags.moveToFirst(); !tags.isAfterLast(); tags.moveToNext()) { final String tag = tags.getString(tagColumn); if (predicate.apply(tag)) { final int separatorIndex = tag.indexOf(PREFIX_SEPARATOR); if (separatorIndex == -1) { tagSet.add(tag); } else { tagSet.add(tag.substring(separatorIndex + 1)); } } } tags.close(); return tagSet; }
From source file:com.example.android.ennis.barrett.popularmovies.asynchronous.TMDbSyncUtil.java
/** * Removes all data from themovies, thevideos, and thereviews tables. Does not remove data * flagged favorite but the columns istoprated, and ispopular will be set to false, "0". * @param context// www . j av a 2s. co m */ public static void deletePopularAndTopRated(Context context) { ContentResolver contentResolver = context.getContentResolver(); ContentValues removePopAndTop = new ContentValues(2); removePopAndTop.put(TMDbContract.Movies.IS_POPULAR, "0"); removePopAndTop.put(TMDbContract.Movies.IS_TOP_RATED, "0"); contentResolver.update(TMDbContract.Movies.URI, removePopAndTop, TMDbContract.Movies.IS_FAVORITE + " = ?", new String[] { "1" }); contentResolver.delete(TMDbContract.Movies.URI, TMDbContract.Movies.IS_POPULAR + " = ? OR " + TMDbContract.Movies.IS_TOP_RATED + " = ?", new String[] { "1", "1" }); Cursor favoriteMovieIds = getFavoriteIds(context); int numberOfIds = favoriteMovieIds.getCount(); String[] movieIds = new String[numberOfIds]; String whereClauseVideos = ""; String whereClauseReviews = ""; for (int i = 0; i < numberOfIds; i++) { favoriteMovieIds.moveToNext(); movieIds[i] = Integer.toString( favoriteMovieIds.getInt(favoriteMovieIds.getColumnIndex(TMDbContract.Movies.MOVIE_ID))); if (i == numberOfIds - 1) { whereClauseVideos += TMDbContract.Videos.MOVIE_IDS + " != ? "; whereClauseReviews += TMDbContract.Videos.MOVIE_IDS + " != ? "; } else { whereClauseVideos += TMDbContract.Videos.MOVIE_IDS + " != ? OR "; whereClauseReviews += TMDbContract.Reviews.MOVIE_IDS + " != ? OR "; } } contentResolver.delete(TMDbContract.Videos.URI, whereClauseVideos, movieIds); contentResolver.delete(TMDbContract.Reviews.URI, whereClauseReviews, movieIds); }
From source file:org.thoughtcrime.securesms.mms.MmsCommunication.java
protected static MmsConnectionParameters getMmsConnectionParameters(Context context) throws MmsException { Cursor cursor = DatabaseFactory.getMmsDatabase(context).getCarrierMmsInformation(); try {//from www . j a v a 2s . c o m if (cursor == null || !cursor.moveToFirst()) throw new MmsException("No carrier MMS information available."); do { String mmsc = cursor.getString(cursor.getColumnIndexOrThrow("mmsc")); String proxy = cursor.getString(cursor.getColumnIndexOrThrow("mmsproxy")); String port = cursor.getString(cursor.getColumnIndexOrThrow("mmsport")); if (mmsc != null && !mmsc.equals("")) return new MmsConnectionParameters(mmsc, proxy, port); } while (cursor.moveToNext()); throw new MmsException("No carrier MMS information available."); } finally { if (cursor != null) cursor.close(); } }
From source file:com.hichinaschool.flashcards.libanki.Stats.java
public static double[][] getSmallDueStats(Collection col) { ArrayList<int[]> dues = new ArrayList<int[]>(); Cursor cur = null; try {//from w ww . ja va2 s. c o m cur = col.getDb().getDatabase().rawQuery("SELECT (due - " + col.getSched().getToday() + ") AS day, " // day + "count(), " // all cards + "sum(CASE WHEN ivl >= 21 THEN 1 ELSE 0 END) " // mature cards + "FROM cards WHERE did IN " + col.getSched()._deckLimit() + " AND queue IN (2,3) AND day <= 7 GROUP BY day ORDER BY day", null); while (cur.moveToNext()) { dues.add(new int[] { cur.getInt(0), cur.getInt(1), cur.getInt(2) }); } } finally { if (cur != null && !cur.isClosed()) { cur.close(); } } // small adjustment for a proper chartbuilding with achartengine if (dues.size() == 0 || dues.get(0)[0] > 0) { dues.add(0, new int[] { 0, 0, 0 }); } if (dues.get(dues.size() - 1)[0] < 7) { dues.add(new int[] { 7, 0, 0 }); } double[][] serieslist = new double[3][dues.size()]; for (int i = 0; i < dues.size(); i++) { int[] data = dues.get(i); serieslist[0][i] = data[0]; serieslist[1][i] = data[1]; serieslist[2][i] = data[2]; } return serieslist; }