List of usage examples for android.database Cursor isAfterLast
boolean isAfterLast();
From source file:br.com.viniciuscr.notification2android.mediaPlayer.MusicUtils.java
/** * Fills out the given submenu with items for "new playlist" and * any existing playlists. When the user selects an item, the * application will receive PLAYLIST_SELECTED with the Uri of * the selected playlist, NEW_PLAYLIST if a new playlist * should be created, and QUEUE if the "current playlist" was * selected.// w ww . j av a2 s . c o m * * @param context The context to use for creating the menu items * @param sub The submenu to add the items to. */ public static void makePlaylistMenu(Context context, SubMenu sub) { String[] cols = new String[] { MediaStore.Audio.Playlists._ID, MediaStore.Audio.Playlists.NAME }; ContentResolver resolver = context.getContentResolver(); if (resolver == null) { System.out.println("resolver = null"); } else { String whereclause = MediaStore.Audio.Playlists.NAME + " != ''"; Cursor cur = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, cols, whereclause, null, MediaStore.Audio.Playlists.NAME); sub.clear(); sub.add(1, Defs.QUEUE, 0, R.string.queue); sub.add(1, Defs.NEW_PLAYLIST, 0, R.string.new_playlist); if (cur != null && cur.getCount() > 0) { //sub.addSeparator(1, 0); cur.moveToFirst(); while (!cur.isAfterLast()) { Intent intent = new Intent(); intent.putExtra("playlist", cur.getLong(0)); // if (cur.getInt(0) == mLastPlaylistSelected) { // sub.add(0, MusicBaseActivity.PLAYLIST_SELECTED, cur.getString(1)).setIntent(intent); // } else { sub.add(1, Defs.PLAYLIST_SELECTED, 0, cur.getString(1)).setIntent(intent); // } cur.moveToNext(); } } if (cur != null) { cur.close(); } } }
From source file:com.andrew.apollo.utils.MusicUtils.java
public static String getFirstStringResult(Cursor cursor, boolean closeCursor) { String result = null;/* w ww . j a va2s . com*/ if (cursor != null) { cursor.moveToFirst(); if (!cursor.isAfterLast()) { result = cursor.getString(0); } if (closeCursor) { cursor.close(); } } return result; }
From source file:org.yammp.dialog.PlaylistDialog.java
private int idForplaylist(String name) { Cursor cursor = mUtils.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, new String[] { MediaStore.Audio.Playlists._ID }, MediaStore.Audio.Playlists.NAME + "=?", new String[] { name }, MediaStore.Audio.Playlists.NAME); int id = -1;/*from ww w. jav a 2s .c o m*/ if (cursor != null) { cursor.moveToFirst(); if (!cursor.isAfterLast()) { id = cursor.getInt(0); } cursor.close(); } return id; }
From source file:curso.android.DAO.RespostaDAO.java
public static List<Resposta> getRespostaPergunta(Pergunta p) { Cursor cursor = null; try {//from w w w . jav a 2s .c o m List<Resposta> questions = new ArrayList<Resposta>(); cursor = Const.db.rawQuery("SELECT * FROM resposta WHERE ask_id = " + p.getAsk_id(), null); if (cursor.getCount() > 0) { int idIndex = cursor.getColumnIndex("asw_id"); int askIndex = cursor.getColumnIndex("ask_id"); int userIndex = cursor.getColumnIndex("user_id"); int respostaIndex = cursor.getColumnIndex("asw_resposta"); int nameIndex = cursor.getColumnIndex("user_name"); cursor.moveToFirst(); do { Long id = Long.valueOf(cursor.getInt(idIndex)); Long ask = Long.valueOf(cursor.getString(askIndex)); Long user = Long.valueOf(cursor.getInt(userIndex)); String resposta = cursor.getString(respostaIndex); String user_name = cursor.getString(nameIndex); Resposta answer = new Resposta(); answer.setAsw_id(id); answer.setAsk_id(ask); answer.setUser_id(user); answer.setAsw_resposta(resposta); answer.setUser_name(user_name); questions.add(answer); cursor.moveToNext(); } while (!cursor.isAfterLast()); } return questions; } finally { if (cursor != null) { cursor.close(); } } }
From source file:com.geozen.smarttrail.ui.tablet.AreasDropdownFragment.java
/** {@inheritDoc} */ public void onQueryComplete(int token, Object cookie, Cursor cursor) { if (getActivity() == null || cursor == null) { return;//from w w w. j a va 2 s . c o m } mCursor = cursor; getActivity().startManagingCursor(mCursor); // If there was a last-opened track, load it. Otherwise load the first // track. cursor.moveToFirst(); String lastAreaID = UIUtils.getLastUsedAreaId(getActivity()); if (lastAreaID != null) { while (!cursor.isAfterLast()) { if (lastAreaID.equals(cursor.getString(AreasAdapter.AreasQuery.AREA_ID))) { break; } cursor.moveToNext(); } if (cursor.isAfterLast()) { loadArea(null, mAutoloadTarget); } else { loadArea(cursor, mAutoloadTarget); } } else { loadArea(null, mAutoloadTarget); } mAdapter.changeCursor(mCursor); }
From source file:edu.gatech.ppl.cycleatlanta.TripUploader.java
@Override protected Boolean doInBackground(Long... tripid) { // First, send the trip user asked for: Boolean result = true;//from ww w. j a va 2 s . co m if (tripid.length != 0) { result = uploadOneTrip(tripid[0]); } // Then, automatically try and send previously-completed trips // that were not sent successfully. Vector<Long> unsentTrips = new Vector<Long>(); mDb.openReadOnly(); Cursor cur = mDb.fetchUnsentTrips(); if (cur != null && cur.getCount() > 0) { // pd.setMessage("Sent. You have previously unsent trips; submitting those now."); while (!cur.isAfterLast()) { unsentTrips.add(Long.valueOf(cur.getLong(0))); cur.moveToNext(); } cur.close(); } mDb.close(); for (Long trip : unsentTrips) { result &= uploadOneTrip(trip); } return result; }
From source file:cn.loveapple.client.android.database.impl.TemperatureDaoImpl.java
/** * {@inheritDoc}/*from w ww .java 2s .c o m*/ */ @Override public List<TemperatureEntity> findByTerm(String start, String end) { List<TemperatureEntity> result = null; Cursor cursor = null; try { writableDb = getWritableDb(); cursor = writableDb.query(TABLE_NAME, null, "?<=" + COLUMN_DATE + " AND ?>=" + COLUMN_DATE + " ORDER BY " + COLUMN_DATE, new String[] { start, end }, null, null, null); result = new ArrayList<TemperatureEntity>(); cursor.moveToFirst(); while (!cursor.isAfterLast()) { result.add(getTemperatureEntity(cursor)); cursor.moveToNext(); } } finally { if (cursor != null) { cursor.close(); } } return result; }
From source file:com.aptoide.amethyst.ui.ScheduledDownloadsActivity.java
@Override public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor c) { scheduledDownloadsMap.clear();/*from w w w . j a va 2 s. c o m*/ if (c.getCount() == 0) { findViewById(android.R.id.empty).setVisibility(View.VISIBLE); } else { findViewById(android.R.id.empty).setVisibility(View.GONE); } for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) { ScheduledDownload scheduledDownload = new ScheduledDownload(c.getLong(c.getColumnIndex("_id")), true); scheduledDownload.setPackage_name(c.getString(c.getColumnIndex("package_name"))); scheduledDownload.setMd5(c.getString(c.getColumnIndex("md5"))); scheduledDownload.setName(c.getString(c.getColumnIndex("name"))); scheduledDownload.setVersion_name(c.getString(c.getColumnIndex("version_name"))); scheduledDownload.setRepo_name(c.getString(c.getColumnIndex("repo_name"))); scheduledDownload.setIcon(c.getString(c.getColumnIndex("icon"))); scheduledDownloadsMap.put(c.getLong(c.getColumnIndex("_id")), scheduledDownload); } adapter.swapCursor(c); }
From source file:net.niyonkuru.koodroid.ui.DataDetailFragment.java
private XYMultipleSeriesDataset getBarDataset(Cursor cursor, int x, int maxX) { XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset(); XYSeries series = new XYSeries(null); Calendar cal = Calendar.getInstance(); CalendarUtils.trimTimestamp(cal);// ww w. java 2s. com if (cursor.isClosed() || !cursor.moveToFirst()) return null; while (x <= maxX) { double count = 0; if (!cursor.isAfterLast()) { /* cursor has data */ Date rowDate = new Date(cal.getTimeInMillis()); Date currDate = Date.valueOf(cursor.getString(UsagesQuery.DATE)); if (rowDate.equals(currDate)) { count = cursor.getDouble(UsagesQuery.COUNT); cursor.moveToNext(); } } cal.add(Calendar.DAY_OF_YEAR, -1); series.add(x++, count); } dataset.addSeries(series); return dataset; }
From source file:org.apache.cordova.backgroundDownload.BackgroundDownload.java
private long findActiveDownload(String uri) { DownloadManager mgr = (DownloadManager) cordova.getActivity().getSystemService(Context.DOWNLOAD_SERVICE); long downloadId = DOWNLOAD_ID_UNDEFINED; DownloadManager.Query query = new DownloadManager.Query(); query.setFilterByStatus(DownloadManager.STATUS_PAUSED | DownloadManager.STATUS_PENDING | DownloadManager.STATUS_RUNNING | DownloadManager.STATUS_SUCCESSFUL); Cursor cur = mgr.query(query); int idxId = cur.getColumnIndex(DownloadManager.COLUMN_ID); int idxUri = cur.getColumnIndex(DownloadManager.COLUMN_URI); for (cur.moveToFirst(); !cur.isAfterLast(); cur.moveToNext()) { if (uri.equals(cur.getString(idxUri))) { downloadId = cur.getLong(idxId); break; }/*from ww w . j a v a2 s.co m*/ } cur.close(); return downloadId; }