List of usage examples for android.database Cursor isAfterLast
boolean isAfterLast();
From source file:Main.java
/** * @param context The {@link Context} to use. * @param id The id of the album./*from w ww . java2s . c om*/ * @return The release date for an album. */ public static final String getReleaseDateForAlbum(final Context context, final long id) { if (id == -1) { return null; } Uri uri = ContentUris.withAppendedId(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, id); Cursor cursor = context.getContentResolver().query(uri, new String[] { AlbumColumns.FIRST_YEAR }, null, null, null); String releaseDate = null; if (cursor != null) { cursor.moveToFirst(); if (!cursor.isAfterLast()) { releaseDate = cursor.getString(0); } cursor.close(); cursor = null; } return releaseDate; }
From source file:Main.java
/** * @param context The {@link Context} to use. * @param id The id of the album.//from w w w .ja v a 2s .c om * @return The song count for an album. */ public static final String getSongCountForAlbum(final Context context, final long id) { if (id == -1) { return null; } Uri uri = ContentUris.withAppendedId(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, id); Cursor cursor = context.getContentResolver().query(uri, new String[] { AlbumColumns.NUMBER_OF_SONGS }, null, null, null); String songCount = null; if (cursor != null) { cursor.moveToFirst(); if (!cursor.isAfterLast()) { songCount = cursor.getString(0); } cursor.close(); cursor = null; } return songCount; }
From source file:Main.java
public static String getLatestImage(Activity context) { String latestImage = null;/*from w w w. j a v a 2 s .c o m*/ String[] items = { MediaStore.Images.Media._ID, MediaStore.Images.Media.DATA }; Cursor cursor = context.managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, items, null, null, MediaStore.Images.Media._ID + " desc"); if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst(); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { latestImage = cursor.getString(1); break; } } return latestImage; }
From source file:Main.java
public static LinkedList<Pair<Integer, String>> retrieveIntegerStringPairFromCursor(Cursor cursor, String integerColumnName, String stringColumnName) { LinkedList<Pair<Integer, String>> result = new LinkedList<Pair<Integer, String>>(); if (null == cursor || 0 == cursor.getCount()) { return result; }//from www . j a v a2 s . c o m try { for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { Integer integerVal = cursor.getInt(cursor.getColumnIndex(integerColumnName)); String stringVal = cursor.getString(cursor.getColumnIndexOrThrow(stringColumnName)); result.add(new Pair(integerVal, stringVal)); } } catch (Exception e) { //do nothing. } finally { cursor.close(); } return result; }
From source file:Main.java
public static String checkNull(Context context, int lastImageId, File fileCapture) { final String[] imageColumns = { Images.Media._ID, Images.Media.DATA }; final String imageOrderBy = Images.Media._ID + " DESC"; final String imageWhere = Images.Media._ID + ">?"; final String[] imageArguments = { Integer.toString(lastImageId) }; ContentResolver contentResolver = context.getContentResolver(); Cursor cursor = contentResolver.query(Images.Media.EXTERNAL_CONTENT_URI, imageColumns, imageWhere, imageArguments, imageOrderBy); if (cursor == null) return null; String newpath = null;/*from w ww . j av a 2 s . c o m*/ if (cursor.getCount() >= 2) { for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { int id = cursor.getInt(cursor.getColumnIndex(Images.Media._ID)); String data = cursor.getString(cursor.getColumnIndex(Images.Media.DATA)); if (data.equals(fileCapture.getPath())) { int rows = contentResolver.delete(Images.Media.EXTERNAL_CONTENT_URI, Images.Media._ID + "=?", new String[] { Long.toString(id) }); boolean ok = fileCapture.delete(); } else { newpath = data; } } } else { newpath = fileCapture.getPath(); Log.e("MediaUtils", "Not found duplicate."); } cursor.close(); return newpath; }
From source file:io.trigger.forge.android.modules.contprov.API.java
private static JSONArray extractNotesFromCursor(Cursor c) throws JSONException { JSONArray toRet = new JSONArray(); int[] cIndices = new int[] { c.getColumnIndex(MyContentDescriptor.Categories.Cols.key_2_catname), c.getColumnIndex(MyContentDescriptor.Categories.Cols.key_3_catstatus) }; for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {//Extract note from cursor JSONObject o = new JSONObject(); o.put("name", c.getString(cIndices[0])); o.put("status", c.getString(cIndices[1])); //c.getString(cIndices[SERVER_ID]), toRet.put(o);/*from www . jav a2 s . c o m*/ } return toRet; }
From source file:org.totschnig.myexpenses.provider.DbUtils.java
/** * @param c// w w w. j ava2s.c om * @return */ public static Map<String, String> getTableDetails(Cursor c) { HashMap<String, String> data = new HashMap<>(); if (c == null) { return data; } for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) { data.put(c.getString(0), c.getString(1)); } c.close(); return data; }
From source file:Main.java
/** * Returns the Id for an artist.//from w ww . j ava 2 s. c om * * @param context The {@link Context} to use. * @param name The name of the artist. * @return The ID for an artist. */ public static final long getIdForArtist(final Context context, final String name) { Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI, new String[] { BaseColumns._ID }, ArtistColumns.ARTIST + "=?", new String[] { name }, ArtistColumns.ARTIST); int id = -1; if (cursor != null) { cursor.moveToFirst(); if (!cursor.isAfterLast()) { id = cursor.getInt(0); } cursor.close(); cursor = null; } return id; }
From source file:Main.java
/** * Returns The ID for a playlist.// w w w. j a va2 s . co m * * @param context The {@link Context} to use. * @param name The name of the playlist. * @return The ID for a playlist. */ public static final long getIdForPlaylist(final Context context, final String name) { Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, new String[] { BaseColumns._ID }, PlaylistsColumns.NAME + "=?", new String[] { name }, PlaylistsColumns.NAME); int id = -1; if (cursor != null) { cursor.moveToFirst(); if (!cursor.isAfterLast()) { id = cursor.getInt(0); } cursor.close(); cursor = null; } return id; }
From source file:com.xfinity.ceylon_steel.controller.CustomerController.java
public static ArrayList<Customer> getCustomers(Context context) { ArrayList<Customer> customers = new ArrayList<Customer>(); SQLiteDatabaseHelper databaseInstance = SQLiteDatabaseHelper.getDatabaseInstance(context); SQLiteDatabase database = databaseInstance.getWritableDatabase(); Cursor customerCursor = database.rawQuery("select customerId, customerName from tbl_customer", null); int customerIdIndex = customerCursor.getColumnIndex("customerId"); int customerNameIndex = customerCursor.getColumnIndex("customerName"); for (customerCursor.moveToFirst(); !customerCursor.isAfterLast(); customerCursor.moveToNext()) { Customer customer = new Customer(customerCursor.getInt(customerIdIndex), customerCursor.getString(customerNameIndex)); customers.add(customer);//w w w . j ava 2s . c o m } customerCursor.close(); databaseInstance.close(); return customers; }