List of usage examples for android.database Cursor isAfterLast
boolean isAfterLast();
From source file:net.potterpcs.recipebook.RecipeData.java
public String[] getRecipeDirectionStrings(long rid) { // NOTE: the returned array is in database sequential order Cursor c = getRecipeDirections(rid); String[] dirs = new String[c.getCount()]; c.moveToFirst();/*from w ww .ja v a 2 s. c o m*/ while (!c.isAfterLast()) { dirs[c.getPosition()] = c.getString(c.getColumnIndex(DT_STEP)); c.moveToNext(); } c.close(); return dirs; }
From source file:net.potterpcs.recipebook.RecipeData.java
private String[] getRecipeDirectionPhotoStrings(long rid) { // NOTE: the returned array is in database sequential order Cursor c = getRecipeDirections(rid); String[] dirs = new String[c.getCount()]; c.moveToFirst();/*from ww w. ja va2s. c o m*/ while (!c.isAfterLast()) { dirs[c.getPosition()] = c.getString(c.getColumnIndex(DT_PHOTO)); c.moveToNext(); } c.close(); return dirs; }
From source file:com.example.android.uamp.model.ExternalStorageSource.java
@Override public Iterator<MediaMetadataCompat> iterator() { ArrayList<MediaMetadataCompat> tracks = new ArrayList<>(); Cursor cursor; Uri euri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; // String[] projection = {MediaStore.Audio.Media._ID, // MediaStore.Audio.Media.DISPLAY_NAME, // MediaStore.Audio.Media.DATA, MediaStore.Audio.Media.TITLE}; String selection = MediaStore.Audio.Media.IS_MUSIC + "!=" + 0; cursor = mContentResolver.query(euri, null, selection, null, MediaStore.Audio.Media.TITLE + " ASC"); // retrieve the indices of the columns where the ID, title, etc. of the song are int artistColumn = cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST); int titleColumn = cursor.getColumnIndex(MediaStore.Audio.Media.TITLE); int albumColumn = cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM); int durationColumn = cursor.getColumnIndex(MediaStore.Audio.Media.DURATION); int idColumn = cursor.getColumnIndex(MediaStore.Audio.Media._ID); int dataColumn = cursor.getColumnIndex(MediaStore.Audio.Media.DATA); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { tracks.add(new MediaMetadataCompat.Builder() .putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, cursor.getString(idColumn)) .putString(MusicProviderSource.CUSTOM_METADATA_TRACK_SOURCE, cursor.getString(dataColumn)) .putString(MediaMetadataCompat.METADATA_KEY_ALBUM, cursor.getString(albumColumn)) .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, cursor.getString(artistColumn)) .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, cursor.getLong(durationColumn)) .putString(MediaMetadataCompat.METADATA_KEY_GENRE, "Pop") .putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI, "") .putString(MediaMetadataCompat.METADATA_KEY_TITLE, cursor.getString(titleColumn)) .putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, 2) .putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, 2).build()); }//w ww. j a v a 2 s.com return tracks.iterator(); }
From source file:edu.pdx.cecs.orcycle.TripUploader.java
@SuppressLint("SimpleDateFormat") private JSONArray getPausesJSON(long tripId) throws JSONException { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); mDb.openReadOnly();/* ww w . j a va 2 s. co m*/ Cursor pausesCursor = mDb.fetchPauses(tripId); // Build the map between JSON fieldname and phone db fieldname: Map<String, Integer> fieldMap = new HashMap<String, Integer>(); fieldMap.put(PAUSE_START, pausesCursor.getColumnIndex(DbAdapter.K_PAUSE_START_TIME)); fieldMap.put(PAUSE_END, pausesCursor.getColumnIndex(DbAdapter.K_PAUSE_END_TIME)); // Build JSON objects for each coordinate: JSONArray jsonPauses = new JSONArray(); while (!pausesCursor.isAfterLast()) { JSONObject json = new JSONObject(); try { json.put(PAUSE_START, df.format(pausesCursor.getDouble(fieldMap.get(PAUSE_START)))); json.put(PAUSE_END, df.format(pausesCursor.getDouble(fieldMap.get(PAUSE_END)))); jsonPauses.put(json); } catch (Exception ex) { Log.e(MODULE_TAG, ex.getMessage()); } pausesCursor.moveToNext(); } pausesCursor.close(); mDb.close(); return jsonPauses; }
From source file:cn.loveapple.client.android.shiba.database.impl.BookMarkDaoImpl.java
/** * {@inheritDoc}// ww w . ja v a 2s. c o m */ public List<BookMarkEntity> getUrlHistory(String url, String title, int limit) { Cursor cursor = null; List<BookMarkEntity> result = null; StringBuilder condition = new StringBuilder(); List<String> params = new ArrayList<String>(); if (StringUtils.isNotEmpty(url)) { condition.append(COLUMN_URL); condition.append(" LIKE '?%' "); params.add(url); } if (StringUtils.isNotEmpty(title)) { if (StringUtils.isNotEmpty(url)) { condition.append(" AND "); } condition.append(COLUMN_TITLE); condition.append(" LIKE '?%' "); params.add(title); } try { writableDb = getWritableDb(); cursor = writableDb.query(TABLE_NAME, null, condition.toString() + " ORDER BY " + COLUMN_TIMESTAMP + " DESC", params.toArray(new String[] {}), null, null, null); result = new ArrayList<BookMarkEntity>(); cursor.moveToFirst(); while (!cursor.isAfterLast()) { result.add(getUrlHistoryEntity(cursor)); cursor.moveToNext(); } } finally { if (cursor != null) { cursor.close(); } } return result; }
From source file:nerd.tuxmobil.fahrplan.congress.FahrplanMisc.java
/** * Load all Lectures from the DB on the day specified * * @param context The Android Context//from w w w.j a v a 2s .c o m * @param day The day to load lectures for (0..), or -1 for all days * @return ArrayList of Lecture objects */ public static LectureList loadLecturesForDayIndex(Context context, int day) { MyApp.LogDebug(LOG_TAG, "load lectures of day " + day); SQLiteDatabase lecturedb = null; LecturesDBOpenHelper lecturesDB = new LecturesDBOpenHelper(context); lecturedb = lecturesDB.getReadableDatabase(); HighlightDBOpenHelper highlightDB = new HighlightDBOpenHelper(context); SQLiteDatabase highlightdb = highlightDB.getReadableDatabase(); LectureList lectures = new LectureList(); Cursor cursor, hCursor; boolean allDays; if (day == ALL_DAYS) { allDays = true; } else { allDays = false; } try { cursor = lecturedb.query(LecturesTable.NAME, LecturesDBOpenHelper.allcolumns, allDays ? null : (LecturesTable.Columns.DAY + "=?"), allDays ? null : (new String[] { String.format("%d", day) }), null, null, LecturesTable.Columns.DATE_UTC); } catch (SQLiteException e) { e.printStackTrace(); lecturedb.close(); highlightdb.close(); lecturesDB.close(); return null; } try { hCursor = highlightdb.query(HighlightsTable.NAME, HighlightDBOpenHelper.allcolumns, null, null, null, null, null); } catch (SQLiteException e) { e.printStackTrace(); lecturedb.close(); highlightdb.close(); lecturesDB.close(); return null; } MyApp.LogDebug(LOG_TAG, "Got " + cursor.getCount() + " rows."); MyApp.LogDebug(LOG_TAG, "Got " + hCursor.getCount() + " highlight rows."); if (cursor.getCount() == 0) { cursor.close(); lecturedb.close(); highlightdb.close(); lecturesDB.close(); return null; } cursor.moveToFirst(); while (!cursor.isAfterLast()) { Lecture lecture = new Lecture(cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.EVENT_ID))); lecture.title = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.TITLE)); lecture.subtitle = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.SUBTITLE)); lecture.day = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.DAY)); lecture.room = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.ROOM)); lecture.startTime = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.START)); lecture.duration = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.DURATION)); lecture.speakers = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.SPEAKERS)); lecture.track = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.TRACK)); lecture.type = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.TYPE)); lecture.lang = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.LANG)); lecture.abstractt = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.ABSTRACT)); lecture.description = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.DESCR)); lecture.relStartTime = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.REL_START)); lecture.date = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.DATE)); lecture.links = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.LINKS)); lecture.dateUTC = cursor.getLong(cursor.getColumnIndex(LecturesTable.Columns.DATE_UTC)); lecture.room_index = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.ROOM_IDX)); lecture.recordingLicense = cursor.getString(cursor.getColumnIndex(LecturesTable.Columns.REC_LICENSE)); lecture.recordingOptOut = cursor.getInt( cursor.getColumnIndex(LecturesTable.Columns.REC_OPTOUT)) == LecturesTable.Values.REC_OPTOUT_OFF ? Lecture.RECORDING_OPTOUT_OFF : Lecture.RECORDING_OPTOUT_ON; lecture.changedTitle = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_TITLE)) != 0; lecture.changedSubtitle = cursor .getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_SUBTITLE)) != 0; lecture.changedRoom = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_ROOM)) != 0; lecture.changedDay = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_DAY)) != 0; lecture.changedSpeakers = cursor .getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_SPEAKERS)) != 0; lecture.changedRecordingOptOut = cursor .getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_RECORDING_OPTOUT)) != 0; lecture.changedLanguage = cursor .getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_LANGUAGE)) != 0; lecture.changedTrack = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_TRACK)) != 0; lecture.changedIsNew = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_IS_NEW)) != 0; lecture.changedTime = cursor.getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_TIME)) != 0; lecture.changedDuration = cursor .getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_DURATION)) != 0; lecture.changedIsCanceled = cursor .getInt(cursor.getColumnIndex(LecturesTable.Columns.CHANGED_IS_CANCELED)) != 0; lectures.add(lecture); cursor.moveToNext(); } cursor.close(); hCursor.moveToFirst(); while (!hCursor.isAfterLast()) { String lecture_id = hCursor.getString(hCursor.getColumnIndex(HighlightsTable.Columns.EVENT_ID)); int highlightState = hCursor.getInt(hCursor.getColumnIndex(HighlightsTable.Columns.HIGHLIGHT)); MyApp.LogDebug(LOG_TAG, "lecture " + lecture_id + " is hightlighted:" + highlightState); for (Lecture lecture : lectures) { if (lecture.lecture_id.equals(lecture_id)) { lecture.highlight = (highlightState == HighlightsTable.Values.HIGHLIGHT_STATE_ON ? true : false); } } hCursor.moveToNext(); } hCursor.close(); highlightdb.close(); lecturedb.close(); lecturesDB.close(); return lectures; }
From source file:net.kourlas.voipms_sms.Database.java
/** * Gets all of the messages associated with the specified contact phone number, except for deleted messages. * * @param contact The contact phone number. * @return All of the messages associated with the specified contact phone number, except for deleted messages. *///from w ww. ja v a 2 s . c o m public synchronized Conversation getConversation(String did, String contact) { List<Message> messages = new ArrayList<>(); Cursor cursor = database.query(TABLE_MESSAGE, columns, COLUMN_CONTACT + "=" + contact + " AND " + COLUMN_DID + "=" + did + " AND " + COLUMN_DELETED + "=" + "0", null, null, null, null); cursor.moveToFirst(); while (!cursor.isAfterLast()) { Message message = new Message(cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_DATABASE_ID)), cursor.isNull(cursor.getColumnIndexOrThrow(COLUMN_VOIP_ID)) ? null : cursor.getLong(cursor.getColumnIndex(COLUMN_VOIP_ID)), cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_DATE)), cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_TYPE)), cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_DID)), cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_CONTACT)), cursor.getString(cursor.getColumnIndexOrThrow(COLUMN_MESSAGE)), cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_UNREAD)), cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_DELETED)), cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_DELIVERED)), cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_DELIVERY_IN_PROGRESS))); messages.add(message); cursor.moveToNext(); } cursor.close(); Message[] messageArray = new Message[messages.size()]; messages.toArray(messageArray); return new Conversation(messageArray); }
From source file:com.conferenceengineer.android.iosched.ui.ScheduleFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { if (!isAdded()) { return;/*from w ww . j a va2 s . c o m*/ } Context context = getActivity(); long currentTime = UIUtils.getCurrentTime(getActivity()); int firstNowPosition = ListView.INVALID_POSITION; String displayTimeZone = PrefUtils.getDisplayTimeZone(context).getID(); List<SimpleSectionedListAdapter.Section> sections = new ArrayList<SimpleSectionedListAdapter.Section>(); cursor.moveToFirst(); long previousBlockStart = -1; long blockStart, blockEnd; while (!cursor.isAfterLast()) { blockStart = cursor.getLong(BlocksQuery.BLOCK_START); blockEnd = cursor.getLong(BlocksQuery.BLOCK_END); if (!UIUtils.isSameDayDisplay(previousBlockStart, blockStart, context)) { mBuffer.setLength(0); sections.add( new SimpleSectionedListAdapter.Section(cursor.getPosition(), DateUtils .formatDateRange(context, mFormatter, blockStart, blockStart, DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY, displayTimeZone) .toString())); } if (mScrollToNow && firstNowPosition == ListView.INVALID_POSITION // if we're currently in this block, or we're not in a block // and this block is in the future, then this is the scroll position && ((blockStart < currentTime && currentTime < blockEnd) || blockStart > currentTime)) { firstNowPosition = cursor.getPosition(); } previousBlockStart = blockStart; cursor.moveToNext(); } mScheduleAdapter.swapCursor(cursor); SimpleSectionedListAdapter.Section[] dummy = new SimpleSectionedListAdapter.Section[sections.size()]; mAdapter.setSections(sections.toArray(dummy)); if (mScrollToNow && firstNowPosition != ListView.INVALID_POSITION) { firstNowPosition = mAdapter.positionToSectionedPosition(firstNowPosition); getListView().setSelectionFromTop(firstNowPosition, getResources().getDimensionPixelSize(R.dimen.list_scroll_top_offset)); mScrollToNow = false; } }
From source file:org.tomahawk.libtomahawk.database.DatabaseHelper.java
/** * @return every stored {@link org.tomahawk.libtomahawk.collection.Playlist} in the database *//*w w w . j a v a2 s .c o m*/ public ArrayList<Playlist> getPlaylists() { ArrayList<Playlist> playListList = new ArrayList<Playlist>(); String[] columns = new String[] { TomahawkSQLiteHelper.PLAYLISTS_COLUMN_ID }; Cursor playlistsCursor = mDatabase.query( TomahawkSQLiteHelper.TABLE_PLAYLISTS, columns, TomahawkSQLiteHelper.PLAYLISTS_COLUMN_ID + " != ? AND " + TomahawkSQLiteHelper.PLAYLISTS_COLUMN_ID + " != ?", new String[] { CACHED_PLAYLIST_ID, LOVEDITEMS_PLAYLIST_ID }, null, null, null); playlistsCursor.moveToFirst(); while (!playlistsCursor.isAfterLast()) { Playlist playlist = getEmptyPlaylist(playlistsCursor.getString(0)); if (playlist != null) { playListList.add(playlist); } playlistsCursor.moveToNext(); } playlistsCursor.close(); return playListList; }
From source file:com.heneryh.aquanotes.service.SyncService.java
@Override protected void onHandleIntent(Intent intent) { Log.d(TAG, "onHandleIntent(intent=" + intent.toString() + ")"); /**/*from w w w. ja v a2 s .c o m*/ * Using the intent, we can tell why we are running this service */ Cursor cursor = null; // This came from the timer expiring or from the gui, either way, push all controllers onto the queue. if (ACTION_UPDATE_ALL.equals(intent.getAction()) || Intent.ACTION_SYNC.equals(intent.getAction())) { try { Uri controllersQueryUri = Controllers.buildQueryControllersUri(); cursor = dbResolverSyncSrvc.query(controllersQueryUri, ControllersQuery.PROJECTION, null, null, null); if (cursor != null && cursor.moveToFirst()) { while (!cursor.isAfterLast()) { Integer controllerId = cursor.getInt(ControllersQuery._ID); requestUpdate(controllerId); cursor.moveToNext(); } } } catch (SQLException e) { Log.e(TAG, "getting controller list", e); // need a little more here! } finally { if (cursor != null) { cursor.close(); } } } else if (ACTION_UPDATE_SINGLE.equals(intent.getAction())) { // This came from the a widget update, id is in the queue } /** * Only start processing thread if not already running, if the thread was running it would * grab the queue items */ synchronized (sLock) { if (!sThreadRunning) { sThreadRunning = true; new SyncThread().execute(); } } }