List of usage examples for android.database Cursor isAfterLast
boolean isAfterLast();
From source file:org.tomahawk.libtomahawk.database.DatabaseHelper.java
/** * @return an InfoRequestData object that contains all data that should be delivered to the API */// w ww . j a va2s. c om public List<InfoRequestData> getLoggedOps() { List<InfoRequestData> loggedOps = new ArrayList<InfoRequestData>(); String[] columns = new String[] { TomahawkSQLiteHelper.INFOSYSTEMOPLOG_COLUMN_ID, TomahawkSQLiteHelper.INFOSYSTEMOPLOG_COLUMN_TYPE, TomahawkSQLiteHelper.INFOSYSTEMOPLOG_COLUMN_HTTPTYPE, TomahawkSQLiteHelper.INFOSYSTEMOPLOG_COLUMN_JSONSTRING, TomahawkSQLiteHelper.INFOSYSTEMOPLOG_COLUMN_PARAMS }; Cursor opLogCursor = mDatabase.query(TomahawkSQLiteHelper.TABLE_INFOSYSTEMOPLOG, columns, null, null, null, null, TomahawkSQLiteHelper.INFOSYSTEMOPLOG_COLUMN_TIMESTAMP + " DESC"); opLogCursor.moveToFirst(); while (!opLogCursor.isAfterLast()) { String requestId = TomahawkMainActivity.getSessionUniqueStringId(); String paramJsonString = opLogCursor.getString(4); QueryParams params = null; if (paramJsonString != null) { try { params = InfoSystemUtils.getObjectMapper().readValue(paramJsonString, QueryParams.class); } catch (IOException e) { Log.e(TAG, "getLoggedOps: " + e.getClass() + ": " + e.getLocalizedMessage()); } } InfoRequestData infoRequestData = new InfoRequestData(requestId, opLogCursor.getInt(1), params, opLogCursor.getInt(0), opLogCursor.getInt(2), opLogCursor.getString(3)); loggedOps.add(infoRequestData); opLogCursor.moveToNext(); } opLogCursor.close(); return loggedOps; }
From source file:net.kourlas.voipms_sms.Database.java
/** * Gets all of the messages in the database. * * @return All of the messages in the database. *///from w ww.jav a2s .c o m public synchronized Message[] getMessages() { List<Message> messages = new ArrayList<>(); Cursor cursor = database.query(TABLE_MESSAGE, columns, null, 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(); Collections.sort(messages); Message[] messageArray = new Message[messages.size()]; return messages.toArray(messageArray); }
From source file:edu.pdx.cecs.orcycle.TripUploader.java
private JSONArray getTripResponsesJSON(long tripId) throws JSONException { // Create a JSON array to hold all of the answers JSONArray jsonAnswers = new JSONArray(); mDb.openReadOnly();//from w w w . j a va 2 s. c o m try { Cursor answers = mDb.fetchTripAnswers(tripId); int questionColumn = answers.getColumnIndex(DbAdapter.K_ANSWER_QUESTION_ID); int answerColumn = answers.getColumnIndex(DbAdapter.K_ANSWER_ANSWER_ID); int otherText = answers.getColumnIndex(DbAdapter.K_ANSWER_OTHER_TEXT); String text; // Cycle thru the database entries while (!answers.isAfterLast()) { // For each row, construct a JSON object JSONObject json = new JSONObject(); try { // Place values into the JSON object json.put(FID_QUESTION_ID, answers.getInt(questionColumn)); json.put(FID_ANSWER_ID, answers.getInt(answerColumn)); if (null != (text = answers.getString(otherText))) { text = text.trim(); if (!text.equals("")) { json.put(FID_ANSWER_OTHER_TEXT, text); } } // Place JSON objects into the JSON array jsonAnswers.put(json); } catch (Exception ex) { Log.e(MODULE_TAG, ex.getMessage()); } // Move to next row answers.moveToNext(); } answers.close(); } catch (Exception ex) { Log.e(MODULE_TAG, ex.getMessage()); } finally { mDb.close(); } return jsonAnswers; }
From source file:id.ridon.keude.UpdateService.java
/** * Looks in the database to see which apps we already know about. Only * returns ids of apps that are in the database if they are in the "apps" * array.//ww w . j a v a 2 s .co m */ private List<String> getKnownAppIdsFromProvider(List<App> apps) { final Uri uri = AppProvider.getContentUri(apps); String[] fields = new String[] { AppProvider.DataColumns.APP_ID }; Cursor cursor = getContentResolver().query(uri, fields, null, null, null); int knownIdCount = cursor != null ? cursor.getCount() : 0; List<String> knownIds = new ArrayList<String>(knownIdCount); if (cursor != null) { if (knownIdCount > 0) { cursor.moveToFirst(); while (!cursor.isAfterLast()) { knownIds.add(cursor.getString(0)); cursor.moveToNext(); } } cursor.close(); } return knownIds; }
From source file:com.netcompss.ffmpeg4android_client.BaseVideo.java
private String[] getVideoPath(String name) { // TODO Auto-generated method stub Log.e(Tag, "file name:" + name); Uri mUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; String[] cloumns = { MediaStore.Video.VideoColumns.DATA, MediaStore.Video.VideoColumns._ID, MediaStore.Video.VideoColumns.TITLE, MediaStore.Video.Thumbnails.DATA }; String selection = MediaStore.Video.Media.DATA + " Like '%" + name + "'"; Cursor videocursor = BaseVideo.this.cordova.getActivity().managedQuery(mUri, cloumns, selection, null, null);//from w w w. j a va 2 s . c om if (videocursor.getCount() > 0) { videocursor.moveToFirst(); while (!videocursor.isAfterLast()) { String path = videocursor.getString(0); String thumbpath = videocursor.getString(3); Log.e(Tag, "path:" + path + " thumb:" + thumbpath); String[] temp = path.split("/"); if (temp[temp.length - 1].equalsIgnoreCase(name)) { Bitmap thumb = ThumbnailUtils.createVideoThumbnail(path, MediaStore.Images.Thumbnails.MINI_KIND); FileOutputStream fos = null; String extr = Environment.getExternalStorageDirectory().toString(); File mFolder = new File(extr + "/MYAPPBUILDER2"); if (!mFolder.exists()) { mFolder.mkdir(); } else { mFolder.delete(); mFolder.mkdir(); } String s = "myappbuilder.png"; video_thumbpath = new File(mFolder.getAbsolutePath(), s); // returnPath = video_thumbpath.getAbsolutePath(); try { fos = new FileOutputStream(video_thumbpath); thumb.compress(Bitmap.CompressFormat.PNG, 100, fos); fos.flush(); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return new String[] { "success", path }; } videocursor.moveToNext(); } } else { return new String[] { "error", "Video not Founded..." }; } return new String[] { "error", "Video not Founded..." }; }
From source file:de.kraenksoft.c3tv.ui.PlaybackOverlayFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { if (cursor != null && cursor.moveToFirst()) { switch (loader.getId()) { case QUEUE_VIDEOS_LOADER: { mQueue.clear();// w w w. j a v a 2 s. c o m while (!cursor.isAfterLast()) { Video v = (Video) mVideoCursorMapper.convert(cursor); // Set the queue index to the selected video. if (v.id == mSelectedVideo.id) { mQueueIndex = mQueue.size(); } // Add the video to the queue. MediaSession.QueueItem item = getQueueItem(v); mQueue.add(item); cursor.moveToNext(); } mSession.setQueue(mQueue); mSession.setQueueTitle(getString(R.string.queue_name)); break; } case RECOMMENDED_VIDEOS_LOADER: { mVideoCursorAdapter.changeCursor(cursor); break; } default: { // Playing a specific video. Video video = (Video) mVideoCursorMapper.convert(cursor); Bundle extras = new Bundle(); extras.putBoolean(AUTO_PLAY, true); playVideo(video, extras); break; } } } }
From source file:org.tomahawk.libtomahawk.database.DatabaseHelper.java
/** * Checks if a query with the same track/artistName as the given query is included in the * lovedItems Playlist//from w w w .j a v a 2 s . co m * * @return whether or not the given query is loved */ public boolean isItemLoved(Query query) { String[] columns = new String[] { TomahawkSQLiteHelper.TRACKS_COLUMN_TRACKNAME, TomahawkSQLiteHelper.TRACKS_COLUMN_ARTISTNAME }; Cursor tracksCursor = mDatabase.query(TomahawkSQLiteHelper.TABLE_TRACKS, columns, TomahawkSQLiteHelper.TRACKS_COLUMN_PLAYLISTID + " = ?", new String[] { LOVEDITEMS_PLAYLIST_ID }, null, null, null); tracksCursor.moveToFirst(); while (!tracksCursor.isAfterLast()) { String trackName = tracksCursor.getString(0); String artistName = tracksCursor.getString(1); if (query.getName().equalsIgnoreCase(trackName) && query.getArtist().getName().equalsIgnoreCase(artistName)) { tracksCursor.close(); return true; } tracksCursor.moveToNext(); } tracksCursor.close(); return false; }
From source file:com.gdgdevfest.android.apps.devfestbcn.ui.MapFragment.java
private void onOverlayLoaderComplete(Cursor cursor) { if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst();/*from w ww. ja v a2 s.c om*/ while (!cursor.isAfterLast()) { final int floor = cursor.getInt(OverlayQuery.TILE_FLOOR); final String file = cursor.getString(OverlayQuery.TILE_FILE); File f = MapUtils.getTileFile(getActivity().getApplicationContext(), file); if (f != null) { addTileProvider(floor, f); } cursor.moveToNext(); } } mOverlaysLoaded = true; enableFloors(); }
From source file:com.spoiledmilk.ibikecph.util.DB.java
public ArrayList<SearchListItem> getSearchHistoryForString(String srchString) { ArrayList<SearchListItem> ret = new ArrayList<SearchListItem>(); SQLiteDatabase db = getReadableDatabase(); if (db == null) return null; String[] columns = { KEY_ID, KEY_NAME, KEY_ADDRESS, KEY_START_DATE, KEY_END_DATE, KEY_SOURCE, KEY_SUBSOURCE, KEY_LAT, KEY_LONG };//from w w w .ja v a2s. co m Cursor cursor = db.query(TABLE_SEARCH_HISTORY, columns, KEY_NAME + " LIKE ? OR " + KEY_ADDRESS + " LIKE ?", new String[] { "%" + srchString + "%", "%" + srchString + "%" }, null, null, null, null); if (cursor != null && cursor.moveToFirst()) { while (cursor != null && !cursor.isAfterLast()) { int colId = cursor.getColumnIndex(KEY_ID); int colName = cursor.getColumnIndex(KEY_NAME); int colAddress = cursor.getColumnIndex(KEY_ADDRESS); int colStartDate = cursor.getColumnIndex(KEY_START_DATE); int colEndDate = cursor.getColumnIndex(KEY_END_DATE); int colSource = cursor.getColumnIndex(KEY_SOURCE); int colSubSource = cursor.getColumnIndex(KEY_SUBSOURCE); int colLat = cursor.getColumnIndex(KEY_LAT); int colLong = cursor.getColumnIndex(KEY_LONG); HistoryData hd = new HistoryData(cursor.getInt(colId), cursor.getString(colName), cursor.getString(colAddress), cursor.getString(colStartDate), cursor.getString(colEndDate), cursor.getString(colSource), cursor.getString(colSubSource), cursor.getDouble(colLat), cursor.getDouble(colLong)); if (hd.getName() != null && !hd.getName().trim().equals("")) ret.add(hd); cursor.moveToNext(); } } if (cursor != null) cursor.close(); db.close(); return ret; }
From source file:org.openbmap.soapclient.GpxSerializer.java
/** * Iterates on track points and write them. * * @param trackName/* w ww .j a v a 2 s .c o m*/ * Name of the track (metadata). * @param bw * Writer to the target file. */ private void writeTrackpoints(final String trackName, final BufferedWriter bw) throws IOException { Log.i(TAG, "Writing trackpoints"); //@formatter:off Cursor c = mDbHelper.getReadableDatabase().rawQuery(TRACKPOINT_SQL_QUERY1, new String[] { String.valueOf(mSession), String.valueOf(0) }); //@formatter:on final int colLatitude = c.getColumnIndex(Schema.COL_LATITUDE); final int colLongitude = c.getColumnIndex(Schema.COL_LONGITUDE); final int colAltitude = c.getColumnIndex(Schema.COL_ALTITUDE); final int colTimestamp = c.getColumnIndex(Schema.COL_TIMESTAMP); bw.write("<trk>"); bw.write("<name>"); bw.write(trackName); bw.write("</name>"); bw.write("<trkseg>"); long outer = 0; while (!c.isAfterLast()) { c.moveToFirst(); while (!c.isAfterLast()) { StringBuffer out = new StringBuffer(32 * 1024); out.append("<trkpt lat=\""); out.append(String.valueOf(c.getDouble(colLatitude))); out.append("\" "); out.append("lon=\""); out.append(String.valueOf(c.getDouble(colLongitude))); out.append("\">"); out.append("<ele>"); out.append(String.valueOf(c.getDouble(colAltitude))); out.append("</ele>"); out.append("<time>"); // time stamp conversion to ISO 8601 out.append(getGpxDate(c.getLong(colTimestamp))); out.append("</time>"); out.append("</trkpt>"); bw.write(out.toString()); bw.flush(); c.moveToNext(); } // fetch next CURSOR_SIZE records outer += CURSOR_SIZE; c.close(); //@formatter:off c = mDbHelper.getReadableDatabase().rawQuery(TRACKPOINT_SQL_QUERY1, new String[] { String.valueOf(mSession), String.valueOf(outer) }); //@formatter:on } c.close(); bw.write("</trkseg>"); bw.write("</trk>"); bw.flush(); }