List of usage examples for android.database Cursor moveToNext
boolean moveToNext();
From source file:com.wildplot.android.ankistats.Intervals.java
public boolean calculateIntervals(int type) { mType = type;//from w w w . j a v a 2 s . c om double all = 0, avg = 0, max_ = 0; mType = type; mBackwards = true; mTitle = R.string.stats_review_intervals; mAxisTitles = new int[] { type, R.string.stats_cards, R.string.stats_percentage }; mValueLabels = new int[] { R.string.stats_cards_intervals }; mColors = new int[] { R.color.stats_interval }; int num = 0; String lim = ""; int chunk = 0; switch (type) { case Utils.TYPE_MONTH: num = 31; chunk = 1; lim = " and grp <= 30"; break; case Utils.TYPE_YEAR: num = 52; chunk = 7; lim = " and grp <= 52"; break; case Utils.TYPE_LIFE: num = -1; chunk = 30; lim = ""; break; } ArrayList<double[]> list = new ArrayList<double[]>(); Cursor cur = null; try { cur = mAnkiDb.getDatabase() .rawQuery("select ivl / " + chunk + " as grp, count() from cards " + "where did in " + _limitWholeOnly() + " and queue = 2 " + lim + " " + "group by grp " + "order by grp", null); while (cur.moveToNext()) { list.add(new double[] { cur.getDouble(0), cur.getDouble(1) }); } if (cur != null && !cur.isClosed()) { cur.close(); } cur = mAnkiDb.getDatabase().rawQuery("select count(), avg(ivl), max(ivl) from cards where did in " + _limitWholeOnly() + " and queue = 2", null); cur.moveToFirst(); all = cur.getDouble(0); avg = cur.getDouble(1); max_ = cur.getDouble(2); } finally { if (cur != null && !cur.isClosed()) { cur.close(); } } // small adjustment for a proper chartbuilding with achartengine if (list.size() == 0 || list.get(0)[0] > 0) { list.add(0, new double[] { 0, 0, 0 }); } if (num == -1 && list.size() < 2) { num = 31; } if (type != Utils.TYPE_LIFE && list.get(list.size() - 1)[0] < num) { list.add(new double[] { num, 0 }); } else if (type == Utils.TYPE_LIFE && list.size() < 2) { list.add(new double[] { Math.max(12, list.get(list.size() - 1)[0] + 1), 0 }); } mSeriesList = new double[2][list.size()]; for (int i = 0; i < list.size(); i++) { double[] data = list.get(i); mSeriesList[0][i] = data[0]; // grp mSeriesList[1][i] = data[1]; // cnt if (mSeriesList[1][i] > mMaxCards) mMaxCards = (int) Math.round(data[1]); } mCumulative = Utils.createCumulative(mSeriesList); for (int i = 0; i < list.size(); i++) { mCumulative[1][i] /= all / 100; } mMaxElements = list.size() - 1; mAverage = Utils.fmtTimeSpan((int) Math.round(avg * 86400)); mLongest = Utils.fmtTimeSpan((int) Math.round(max_ * 86400)); return list.size() > 0; }
From source file:edu.pdx.cecs.orcycle.NoteUploader.java
@Override protected Boolean doInBackground(Long... noteIds) { // First, send the note user asked for: Boolean result = true;//from w ww . j a va 2 s . c om if (noteIds.length != 0) { result = uploadOneNote(noteIds[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:com.google.zxing.client.android.history.HistoryManager.java
/** * <p>/* w ww . j ava2s . c o m*/ * Builds a text representation of the scanning history. Each scan is * encoded on one line, terminated by a line break (\r\n). The values in * each line are comma-separated, and double-quoted. Double-quotes within * values are escaped with a sequence of two double-quotes. The fields * output are: * </p> * * <ul> * <li>Raw text</li> * <li>Display text</li> * <li>Format (e.g. QR_CODE)</li> * <li>Timestamp</li> * <li>Formatted version of timestamp</li> * </ul> */ CharSequence buildHistory() { SQLiteOpenHelper helper = new DBHelper(activity); SQLiteDatabase db = null; Cursor cursor = null; try { db = helper.getWritableDatabase(); cursor = db.query(DBHelper.TABLE_NAME, COLUMNS, null, null, null, null, DBHelper.TIMESTAMP_COL + " DESC"); StringBuilder historyText = new StringBuilder(1000); while (cursor.moveToNext()) { historyText.append('"').append(massageHistoryField(cursor.getString(0))).append("\","); historyText.append('"').append(massageHistoryField(cursor.getString(1))).append("\","); historyText.append('"').append(massageHistoryField(cursor.getString(2))).append("\","); historyText.append('"').append(massageHistoryField(cursor.getString(3))).append("\","); // Add timestamp again, formatted long timestamp = cursor.getLong(3); historyText.append('"') .append(massageHistoryField(EXPORT_DATE_TIME_FORMAT.format(new Date(timestamp)))) .append("\","); // Above we're preserving the old ordering of columns which had // formatted data in position 5 historyText.append('"').append(massageHistoryField(cursor.getString(4))).append("\"\r\n"); } return historyText; } finally { close(cursor, db); } }
From source file:heartware.com.heartware_master.DBAdapter.java
public HashMap<String, String> getProfileById(String id) { HashMap<String, String> profileMap = new HashMap<String, String>(); SQLiteDatabase database = this.getReadableDatabase(); String selectQuery = "SELECT * FROM " + PROFILES_TABLE + " WHERE " + PROFILE_ID + "='" + id + "'"; Cursor cursor = database.rawQuery(selectQuery, null); if (cursor.moveToFirst()) { do {/*w w w . j a va 2 s . co m*/ profileMap.put(PROFILE_ID, cursor.getString(0)); profileMap.put(USERNAME, cursor.getString(1)); profileMap.put(PASSWORD, cursor.getString(2)); profileMap.put(DIFFICULTY, cursor.getString(3)); profileMap.put(DISABILITY, cursor.getString(4)); } while (cursor.moveToNext()); } return profileMap; }
From source file:com.murrayc.galaxyzoo.app.syncadapter.SyncAdapter.java
/** * Remove old classified subjects if we have too many. * * @return Return true if we know for sure that no further removal is currently necessary. *///from ww w. j av a2 s . c o m private boolean removeOldSubjects() { final int count = getUploadedCount(); final int max = getKeepCount(); if (count > max) { Log.info("removeOldSubjects(): start"); //Get the oldest done (and uploaded) items: final ContentResolver resolver = getContentResolver(); final String[] projection = { Item.Columns._ID }; //ISO-8601 dates can be alphabetically sorted to get date-time order: final String orderBy = Item.Columns.DATETIME_DONE + " ASC"; final int countToRemove = count - max; //TODO: Use this: final String limit = Integer.toString(countToRemove); //TODO: Is this locale-independent? final Cursor c = resolver.query(Item.ITEMS_URI, projection, WHERE_CLAUSE_UPLOADED, new String[] {}, orderBy); //Remove them one by one: int removed = 0; while (c.moveToNext()) { final String itemId = c.getString(0); if (!TextUtils.isEmpty(itemId)) { removeItem(itemId); //Only remove enough: removed++; if (removed == countToRemove) { break; } } } c.close(); Log.info("removeOldSubjects(): end"); return false; } else { return true; //Tell the caller that no action was necessary. } }
From source file:heartware.com.heartware_master.DBAdapter.java
public HashMap<String, String> getProfileByUserAndToken(String user, String token) { HashMap<String, String> profileMap = new HashMap<String, String>(); SQLiteDatabase database = this.getReadableDatabase(); String selectQuery = "SELECT * FROM " + PROFILES_TABLE + " WHERE " + USERNAME + "='" + user + "'" + " AND " + PASSWORD + "='" + token + "'"; Cursor cursor = database.rawQuery(selectQuery, null); if (cursor.moveToFirst()) { do {/*from w w w . j a v a 2 s. c om*/ profileMap.put(PROFILE_ID, cursor.getString(0)); profileMap.put(USERNAME, cursor.getString(1)); profileMap.put(PASSWORD, cursor.getString(2)); profileMap.put(DIFFICULTY, cursor.getString(3)); profileMap.put(DISABILITY, cursor.getString(4)); } while (cursor.moveToNext()); } return profileMap; }
From source file:gov.nasa.arc.geocam.geocam.CameraActivity.java
private int getMediaStoreNumEntries() { Cursor cur = managedQuery(GeoCamMobile.MEDIA_URI, null, null, null, null); cur.moveToFirst();/* w ww .ja va2s. c o m*/ Log.d(GeoCamMobile.DEBUG_ID, "Retrieving list of photos"); int count = 0; while (cur.moveToNext()) { count++; } Log.d(GeoCamMobile.DEBUG_ID, "Found " + count + " photos"); return count; }
From source file:com.akop.bach.parser.PsnParser.java
@Override public void deleteAccount(BasicAccount account) { ContentResolver cr = mContext.getContentResolver(); long accountId = account.getId(); // Clear games & achievements StringBuffer buffer = new StringBuffer(); Cursor c = cr.query(Games.CONTENT_URI, new String[] { Games._ID }, Games.ACCOUNT_ID + "=" + accountId, null, null);// ww w . java 2 s. co m try { if (c != null) { while (c.moveToNext()) { if (buffer.length() > 0) buffer.append(","); buffer.append(c.getLong(0)); } } } finally { if (c != null) c.close(); } // Clear trophies cr.delete(Trophies.CONTENT_URI, Trophies.GAME_ID + " IN (" + buffer.toString() + ")", null); // Clear rest of data cr.delete(Games.CONTENT_URI, Games.ACCOUNT_ID + "=" + accountId, null); cr.delete(Profiles.CONTENT_URI, Profiles.ACCOUNT_ID + "=" + accountId, null); cr.delete(Friends.CONTENT_URI, Friends.ACCOUNT_ID + "=" + accountId, null); // Send notifications cr.notifyChange(Profiles.CONTENT_URI, null); cr.notifyChange(Trophies.CONTENT_URI, null); cr.notifyChange(Games.CONTENT_URI, null); cr.notifyChange(Friends.CONTENT_URI, null); // Delete authenticated session deleteSession(account); }
From source file:com.example.jumpnote.android.SyncAdapter.java
public List<ModelJava.Note> getLocallyChangedNotes(ContentProviderClient provider, Account account, Date sinceDate) throws RemoteException { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Getting local notes changed since " + Long.toString(sinceDate.getTime())); }/*from w w w. ja v a 2s . com*/ Cursor notesCursor = provider.query(JumpNoteContract.buildNoteListUri(account.name), PROJECTION, JumpNoteContract.Notes.MODIFIED_DATE + " > ?", new String[] { Long.toString(sinceDate.getTime()) }, null); List<ModelJava.Note> locallyChangedNotes = new ArrayList<ModelJava.Note>(); while (notesCursor.moveToNext()) { ContentValues values = new ContentValues(); DatabaseUtils.cursorRowToContentValues(notesCursor, values); ModelJava.Note changedNote = new ModelJava.Note(values); locallyChangedNotes.add(changedNote); } notesCursor.close(); return locallyChangedNotes; }
From source file:org.noorganization.instalistsynch.controller.synch.impl.RecipeSynch.java
@Override public void indexLocal(int _groupId, Date _lastIndexTime) { String lastIndexTime = ISO8601Utils.format(_lastIndexTime, false, TimeZone.getTimeZone("GMT+0000"));//.concat("+0000"); boolean isLocal = false; GroupAuth groupAuth = mGroupAuthDbController.getLocalGroup(); if (groupAuth != null) { isLocal = groupAuth.getGroupId() == _groupId; }/* ww w.j a va 2s . c o m*/ Cursor logCursor = mClientLogDbController.getLogsSince(lastIndexTime, mModelType); if (logCursor.getCount() == 0) { logCursor.close(); return; } try { while (logCursor.moveToNext()) { // fetch the action type int actionId = logCursor.getInt(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION)); eActionType actionType = eActionType.getTypeById(actionId); List<ModelMapping> modelMappingList = mRecipeMappingController.get( ModelMapping.COLUMN.GROUP_ID + " = ? AND " + ModelMapping.COLUMN.CLIENT_SIDE_UUID + " LIKE ?", new String[] { String.valueOf(_groupId), logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ITEM_UUID)) }); ModelMapping modelMapping = modelMappingList.size() == 0 ? null : modelMappingList.get(0); switch (actionType) { case INSERT: // skip insertion because this should be decided by the user if the non local groups should have access to the category // and also skip if a mapping for this case already exists! if (!isLocal || modelMapping != null) { continue; } String clientUuid = logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ITEM_UUID)); Date clientDate = ISO8601Utils.parse( logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE)), new ParsePosition(0)); modelMapping = new ModelMapping(null, groupAuth.getGroupId(), null, clientUuid, new Date(Constants.INITIAL_DATE), clientDate, false); mRecipeMappingController.insert(modelMapping); break; case UPDATE: if (modelMapping == null) { Log.i(TAG, "indexLocal: the model is null but shouldn't be"); continue; } String timeString = logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE)); clientDate = ISO8601Utils.parse(timeString, new ParsePosition(0)); modelMapping.setLastClientChange(clientDate); mRecipeMappingController.update(modelMapping); break; case DELETE: if (modelMapping == null) { Log.i(TAG, "indexLocal: the model is null but shouldn't be"); continue; } modelMapping.setDeleted(true); timeString = logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE)); clientDate = ISO8601Utils.parse(timeString, new ParsePosition(0)); modelMapping.setLastClientChange(clientDate); mRecipeMappingController.update(modelMapping); break; default: } } } catch (Exception e) { logCursor.close(); } }