List of usage examples for android.database Cursor isAfterLast
boolean isAfterLast();
From source file:edu.mit.mobile.android.demomode.Preferences.java
private String toConfigString() { final String password = mPrefs.getString(KEY_PASSWORD, null); final ArrayList<BasicNameValuePair> nvp = new ArrayList<BasicNameValuePair>(); int ver;/*from w w w. j a v a 2 s . c o m*/ try { ver = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode; } catch (final NameNotFoundException e) { // this should never happen ver = 0; e.printStackTrace(); } nvp.add(new BasicNameValuePair(CFG_K_VER, String.valueOf(ver))); nvp.add(new BasicNameValuePair(CFG_K_SECRETKEY, password)); final Cursor c = getContentResolver().query(LauncherItem.CONTENT_URI, null, null, null, null); try { final int pkgCol = c.getColumnIndex(LauncherItem.PACKAGE_NAME); final int actCol = c.getColumnIndex(LauncherItem.ACTIVITY_NAME); for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) { nvp.add(new BasicNameValuePair(CFG_K_APPS, c.getString(pkgCol) + CFG_PKG_SEP + c.getString(actCol))); } return "data:" + CFG_MIME_TYPE + "," + URLEncodedUtils.format(nvp, "utf-8"); } finally { c.close(); } }
From source file:br.com.viniciuscr.notification2android.mediaPlayer.MusicUtils.java
public static void deleteTracks(Context context, long[] list) { String[] cols = new String[] { MediaStore.Audio.Media._ID, MediaStore.Audio.Media.DATA, MediaStore.Audio.Media.ALBUM_ID }; StringBuilder where = new StringBuilder(); where.append(MediaStore.Audio.Media._ID + " IN ("); for (int i = 0; i < list.length; i++) { where.append(list[i]);/* w w w . j a v a 2 s . co m*/ if (i < list.length - 1) { where.append(","); } } where.append(")"); Cursor c = query(context, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, cols, where.toString(), null, null); if (c != null) { // step 1: remove selected tracks from the current playlist, as well // as from the album art cache c.moveToFirst(); while (!c.isAfterLast()) { // remove from current playlist long id = c.getLong(0); sService.removeTrack(id); // remove from album art cache long artIndex = c.getLong(2); synchronized (sArtCache) { sArtCache.remove(artIndex); } c.moveToNext(); } // step 2: remove selected tracks from the database context.getContentResolver().delete(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, where.toString(), null); // step 3: remove files from card c.moveToFirst(); while (!c.isAfterLast()) { String name = c.getString(1); File f = new File(name); try { // File.delete can throw a security exception if (!f.delete()) { // I'm not sure if we'd ever get here (deletion would // have to fail, but no exception thrown) Log.e("MusicUtils", "Failed to delete file " + name); } c.moveToNext(); } catch (SecurityException ex) { c.moveToNext(); } } c.close(); } String message = context.getResources().getQuantityString(R.plurals.NNNtracksdeleted, list.length, Integer.valueOf(list.length)); Toast.makeText(context, message, Toast.LENGTH_SHORT).show(); // We deleted a number of tracks, which could affect any number of things // in the media content domain, so update everything. context.getContentResolver().notifyChange(Uri.parse("content://media"), null); }
From source file:org.mariotaku.twidere.activity.AccountSelectorActivity.java
@Override public void onLoadFinished(final Loader<Cursor> loader, final Cursor cursor) { mAdapter.swapCursor(cursor);// w w w.j a v a2 s . c o m final SparseBooleanArray checked = new SparseBooleanArray(); cursor.moveToFirst(); if (mSelectedIds.size() == 0) { if (mAllowSelectNone) return; while (!cursor.isAfterLast()) { final boolean is_activated = cursor .getInt(cursor.getColumnIndexOrThrow(Accounts.IS_ACTIVATED)) == 1; final long user_id = cursor.getLong(cursor.getColumnIndexOrThrow(Accounts.ACCOUNT_ID)); if (is_activated) { mSelectedIds.add(user_id); } mAdapter.setItemChecked(cursor.getPosition(), is_activated); cursor.moveToNext(); } } else { while (!cursor.isAfterLast()) { final long user_id = cursor.getLong(cursor.getColumnIndexOrThrow(Accounts.ACCOUNT_ID)); if (mSelectedIds.contains(user_id)) { checked.put(cursor.getPosition(), true); mAdapter.setItemChecked(cursor.getPosition(), true); } cursor.moveToNext(); } } }
From source file:com.conferenceengineer.android.iosched.ui.tablet.TracksDropdownFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { if (getActivity() == null || cursor == null) { return;// w w w.j a va2s. c om } boolean trackLoaded = false; if (mTrackId != null) { cursor.moveToFirst(); while (!cursor.isAfterLast()) { if (mTrackId.equals(cursor.getString(TracksAdapter.TracksQuery.TRACK_ID))) { loadTrack(cursor, false); trackLoaded = true; break; } cursor.moveToNext(); } } if (!trackLoaded) { loadTrack(null, false); } mAdapter.setHasAllItem(true); mAdapter.changeCursor(cursor); }
From source file:com.clevertrail.mobile.Database_SavedTrails.java
public String getJSONString() { String[] columns = new String[] { "json" }; Cursor cursor = sqLiteDatabase.query(MYDATABASE_TABLE, columns, null, null, null, null, null); cursor.moveToFirst();/*from ww w . ja v a 2 s .c o m*/ int index_JSON = cursor.getColumnIndex("json"); //we will create a simple return value of the format: //"[trail1JSON, trail2JSON, ...]" String sReturn = "["; while (!cursor.isAfterLast()) { String sTrailJSON = cursor.getString(index_JSON); sReturn = sReturn.concat(sTrailJSON); cursor.moveToNext(); if (!cursor.isAfterLast()) { if (sTrailJSON.compareTo("") != 0) sReturn = sReturn.concat(","); } else { break; } } sReturn = sReturn.concat("]"); return sReturn; }
From source file:org.kiwix.kiwixmobile.ZimFileSelectActivity.java
private RescanDataAdapter buildArrayAdapter(Cursor cursor) { ArrayList<DataModel> files = new ArrayList<>(); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { if (new File(cursor.getString(2)).exists()) { files.add(new DataModel(cursor.getString(1), cursor.getString(2))); }/*from w ww . ja v a 2s . com*/ } files = new FileWriter(ZimFileSelectActivity.this, files).getDataModelList(); for (int i = 0; i < files.size(); i++) { if (!new File(files.get(i).getPath()).exists()) { Log.e(TAG_KIWIX, "File removed: " + files.get(i).getTitle()); files.remove(i); } } files = new FileSearch().sortDataModel(files); mFiles = files; return new RescanDataAdapter(ZimFileSelectActivity.this, 0, mFiles); }
From source file:edu.mit.mobile.android.livingpostcards.CardViewFragment.java
public boolean checkAllCached() { final boolean allCached = true; if (mAdapter == null) { return false; }//from www . j a v a 2 s . c om final Cursor c = mAdapter.getCursor(); final int imgLocCol = c.getColumnIndexOrThrow(CardMedia.COL_LOCAL_URL); final int imgPubCol = c.getColumnIndexOrThrow(CardMedia.COL_MEDIA_URL); if (c == null || c.isClosed()) { return false; } for (c.moveToFirst(); c.isAfterLast(); c.moveToNext()) { String url = c.getString(imgLocCol); if (url == null) { url = c.getString(imgPubCol); } } return false; }
From source file:com.bellman.bible.service.db.bookmark.BookmarkDBAdapter.java
public List<BookmarkDto> getAllBookmarks() { List<BookmarkDto> allBookmarks = new ArrayList<BookmarkDto>(); Cursor c = db.query(BookmarkQuery.TABLE, BookmarkQuery.COLUMNS, null, null, null, null, null); try {//ww w .j a v a 2s. co m if (c.moveToFirst()) { while (!c.isAfterLast()) { BookmarkDto bookmark = getBookmarkDto(c); allBookmarks.add(bookmark); c.moveToNext(); } } } finally { c.close(); } return allBookmarks; }
From source file:gov.wa.wsdot.android.wsdot.service.BorderWaitSyncService.java
/** * Check the travel border wait table for any starred entries. If we find some, save them * to a list so we can re-star those after we flush the database. *//* ww w . j a v a 2s . c o m*/ private List<Integer> getStarred() { ContentResolver resolver = getContentResolver(); Cursor cursor = null; List<Integer> starred = new ArrayList<Integer>(); try { cursor = resolver.query(BorderWait.CONTENT_URI, new String[] { BorderWait.BORDER_WAIT_ID }, BorderWait.BORDER_WAIT_IS_STARRED + "=?", new String[] { "1" }, null); if (cursor != null && cursor.moveToFirst()) { while (!cursor.isAfterLast()) { starred.add(cursor.getInt(0)); cursor.moveToNext(); } } } finally { if (cursor != null) { cursor.close(); } } return starred; }
From source file:curso.android.DAO.RespostaDAO.java
public static Resposta getPerguntaById(Resposta p) { Cursor cursor = null; try {/*from www . j a v a 2 s . c o m*/ cursor = Const.db.rawQuery("SELECT * FROM resposta WHERE asw_id = " + p.getAsw_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.getString(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); return answer; } while (!cursor.isAfterLast()); } return null; } finally { if (cursor != null) { cursor.close(); } } }