List of usage examples for android.database Cursor getCount
int getCount();
From source file:Main.java
private static int getImageRotationAngle(Uri imageUri, ContentResolver contentResolver) throws IOException { int angle = 0; Cursor cursor = contentResolver.query(imageUri, new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null);/*from w ww.j a va 2s.co m*/ if (cursor != null) { if (cursor.getCount() == 1) { cursor.moveToFirst(); angle = cursor.getInt(0); } cursor.close(); } else { ExifInterface exif = new ExifInterface(imageUri.getPath()); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_270: angle = 270; break; case ExifInterface.ORIENTATION_ROTATE_180: angle = 180; break; case ExifInterface.ORIENTATION_ROTATE_90: angle = 90; break; default: break; } } return angle; }
From source file:Main.java
/** * Looks up a contacts display name by contact id - if not found, the * address (phone number) will be formatted and returned instead. */// w ww . ja v a 2s. c om public static String getPersonName(Context context, String id, String address) { // Check for id, if null return the formatting phone number as the name if (id == null || "".equals(id.trim())) { if (address != null && !"".equals(address.trim())) { return PhoneNumberUtils.formatNumber(address); } else { return null; } } Cursor cursor = context.getContentResolver().query(Uri.withAppendedPath(Contacts.CONTENT_URI, id), new String[] { Contacts.DISPLAY_NAME }, null, null, null); if (cursor != null) { try { if (cursor.getCount() > 0) { cursor.moveToFirst(); String name = cursor.getString(0); return name; } } finally { cursor.close(); } } if (address != null) { return PhoneNumberUtils.formatNumber(address); } return null; }
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;/* w w w . j av a2 s . c om*/ 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:Main.java
public static byte[] getPersonPhoto(Context context, String id) { if (id == null) return null; byte photo[] = null; Cursor cursor = context.getContentResolver().query(Uri.withAppendedPath(Contacts.Photos.CONTENT_URI, id), new String[] { PhotosColumns.DATA }, null, null, null); if (cursor != null) { try {/*from w w w . j av a 2 s . c om*/ if (cursor.getCount() > 0) { cursor.moveToFirst(); photo = cursor.getBlob(0); if (photo != null) { return photo; // Log.v("Found photo for person: " + id); // bitmap = BitmapFactory.decodeStream(new // ByteArrayInputStream(photo)); } } } finally { cursor.close(); } } return photo; }
From source file:com.bourke.kitchentimer.utils.Utils.java
public static boolean exportCSV(Context context, Cursor cursor) { if (cursor.getCount() == 0) return true; // An array to hold the rows that will be written to the CSV file. final int rowLenght = FoodMetaData.COLUMNS.length - 1; String[] row = new String[rowLenght]; System.arraycopy(FoodMetaData.COLUMNS, 1, row, 0, rowLenght); CSVWriter writer = null;/*from ww w . j a v a 2s. c o m*/ boolean success = false; try { writer = new CSVWriter(new FileWriter(Constants.CSV_FILE)); // Write descriptive headers. writer.writeNext(row); int nameIndex = cursor.getColumnIndex(FoodMetaData.NAME); int hoursIndex = cursor.getColumnIndex(FoodMetaData.HOURS); int minutesIndex = cursor.getColumnIndex(FoodMetaData.MINUTES); int secondsIndex = cursor.getColumnIndex(FoodMetaData.SECONDS); if (cursor.requery()) { while (cursor.moveToNext()) { row[0] = cursor.getString(nameIndex); row[1] = cursor.getInt(hoursIndex) + ""; row[2] = cursor.getInt(minutesIndex) + ""; row[3] = cursor.getInt(secondsIndex) + ""; // NOTE: writeNext() handles nulls in row[] gracefully. writer.writeNext(row); } } success = true; } catch (Exception ex) { Log.e("Utils", "exportCSV", ex); } finally { try { if (null != writer) writer.close(); } catch (IOException ex) { } } return success; }
From source file:Main.java
public static int getMessageTypeByThreadAndBody(Context context, long threadId, String body) { int type = 1; final String[] projection = new String[] { " sms.type " + " from sms " + " where sms.thread_id = " + threadId + " and sms.body = '" + body + "' --" }; // Create cursor /*/* w w w . j a v a 2 s . c om*/ * Cursor cursor = context.getContentResolver().query( SMS_CONTENT_URI, * projection, null, null, null); */ Cursor cursor = context.getContentResolver().query(SMS_CONTENT_URI, new String[] { "type" }, "sms.thread_id = ? and sms.body = ?", new String[] { String.valueOf(threadId), body }, null); if (cursor != null) { try { if (cursor.getCount() > 0) { while (cursor.moveToNext()) { type = cursor.getInt(cursor.getColumnIndexOrThrow("type")); return type; } } } catch (Exception e) { e.printStackTrace(); } finally { cursor.close(); } } return type; }
From source file:net.sf.sprockets.database.Cursors.java
/** * Get all int values in the first column. * * @param close true to close the cursor or false to leave it open * @since 2.5.0//from w ww . j ava 2s . co m */ public static int[] allInts(Cursor cursor, boolean close) { int[] i = EMPTY_INT_ARRAY; if (cursor.moveToFirst()) { i = new int[cursor.getCount()]; do { i[cursor.getPosition()] = cursor.getInt(0); } while (cursor.moveToNext()); } close(cursor, close); return i; }
From source file:Main.java
private static int getOrientation(Context context, Uri photoUri) { /* it's on the external media. */ Cursor cursor = context.getContentResolver().query(photoUri, new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null); if (cursor.getCount() != 1) { return -1; }/*from w w w .j a va2s . c o m*/ cursor.moveToFirst(); return cursor.getInt(0); }
From source file:net.sf.sprockets.database.Cursors.java
/** * Get all long values in the first column. * * @param close true to close the cursor or false to leave it open *///from w ww. ja va 2 s .c o m public static long[] allLongs(Cursor cursor, boolean close) { long[] l = EMPTY_LONG_ARRAY; if (cursor.moveToFirst()) { l = new long[cursor.getCount()]; do { l[cursor.getPosition()] = cursor.getLong(0); } while (cursor.moveToNext()); } close(cursor, close); return l; }
From source file:net.sf.sprockets.database.Cursors.java
/** * Get all String values in the first column. * * @param close true to close the cursor or false to leave it open *//*from w w w.j a v a 2 s. com*/ public static String[] allStrings(Cursor cursor, boolean close) { String[] s = EMPTY_STRING_ARRAY; if (cursor.moveToFirst()) { s = new String[cursor.getCount()]; do { s[cursor.getPosition()] = cursor.getString(0); } while (cursor.moveToNext()); } close(cursor, close); return s; }