List of usage examples for android.database Cursor getInt
int getInt(int columnIndex);
From source file:Main.java
public static boolean isCityExist(Context context, String city) { File file = new File(context.getFilesDir(), DATABASE_NAME); SQLiteDatabase db = context.openOrCreateDatabase(file.getAbsolutePath(), Context.MODE_PRIVATE, null); Cursor cursor = db.rawQuery("select count(1) from " + TABLE_NAME + " where DQXX02=?", new String[] { city }); cursor.moveToNext();// w ww .j a v a 2 s.c o m return cursor.getInt(0) > 0; }
From source file:Main.java
public static java.util.List<String> getLabelsFromInt(Cursor c) { c.moveToFirst();// w ww. ja v a 2 s .c o m ArrayList<String> res = new ArrayList<>(); for (int i = 0; i < c.getCount(); i++) { res.add(i, String.valueOf(c.getInt(0))); c.moveToNext(); } return res; }
From source file:Main.java
public static int getContactIdFromPhoneNumber(final Context context, final String number) { final Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number)); final String[] projection = { PhoneLookup._ID }; final Cursor c = context.getContentResolver().query(uri, projection, null, null, null); if (c.getCount() > 0) { c.moveToFirst();//from ww w. java2s . c o m return c.getInt(0); } else { return -1; } }
From source file:Main.java
/** * Calculates the amount of rotation needed for the image to look upright. * /*from www.j av a2s . co m*/ * @param context * the application's context * @param uri * the Uri pointing to the file * @return the needed rotation as a <code>float</code> */ private static float rotationForImage(Context context, Uri uri) { if ("content".equals(uri.getScheme())) { String[] projection = { Images.ImageColumns.ORIENTATION }; Cursor c = context.getContentResolver().query(uri, projection, null, null, null); if (c.moveToFirst()) { return c.getInt(0); } } else if ("file".equals(uri.getScheme())) { try { ExifInterface exif = new ExifInterface(uri.getPath()); int rotation = (int) exifOrientationToDegrees( exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL)); return rotation; } catch (IOException e) { Log.e(TAG, "Error checking exif", e); } } return 0f; }
From source file:Main.java
public static String getNewThreadID(Context context) { int new_id = 0; final String[] projection = new String[] { "_id" }; Uri uri = Uri.parse("content://mms-sms/conversations?simple=true"); Cursor query = context.getContentResolver().query(uri, projection, null, null, "date DESC"); if (query != null) { while (query.moveToNext()) { int tmp = query.getInt(query.getColumnIndexOrThrow("_id")) + 1; if (tmp > new_id) { new_id = tmp; }/* ww w .java 2 s . c o m*/ } query.close(); } return "" + new_id; }
From source file:Main.java
public static int getRotationFromUri(Context context, Uri imageUri) { String[] orientationColumn = { MediaStore.Images.Media.ORIENTATION }; Cursor cur = context.getContentResolver().query(imageUri, orientationColumn, null, null, null); int orientation = -1; if (cur != null && cur.moveToFirst()) { orientation = cur.getInt(cur.getColumnIndex(orientationColumn[0])); }// w w w. j a v a2 s .c om return orientation; }
From source file:de.stadtrallye.rallyesoft.util.converters.CursorConverters.java
public static ChatEntry getChatEntry(Cursor cursor, ChatCursorIds c) { return new ChatEntry(cursor.getInt(c.id), cursor.getString(c.message), cursor.getLong(c.timestamp), cursor.getInt(c.groupID), cursor.getString(c.groupName), cursor.getInt(c.userID), cursor.getString(c.userName), cursor.getString(c.pictureHash)); }
From source file:Main.java
private static Object getCursorValue(Cursor cursor, Field field, String columnName) { Class<?> fieldType = field.getType(); if (fieldType.equals(int.class) || field.equals(Integer.class)) { return cursor.getInt(cursor.getColumnIndex(columnName)); } else if (fieldType.equals(String.class)) { return cursor.getString(cursor.getColumnIndex(columnName)); } else if (fieldType.equals(long.class) || field.equals(Long.class)) { return cursor.getLong(cursor.getColumnIndex(columnName)); } else if (fieldType.equals(float.class) || field.equals(Float.class)) { return cursor.getFloat(cursor.getColumnIndex(columnName)); } else if (fieldType.equals(double.class) || field.equals(Double.class)) { return cursor.getDouble(cursor.getColumnIndex(columnName)); } else if (fieldType.equals(long.class) || field.equals(Long.class)) { return cursor.getLong(cursor.getColumnIndex(columnName)); } else if (fieldType.equals(Date.class)) { long time = cursor.getLong(cursor.getColumnIndex(columnName)); Date date = new Date(time); return date; }/*ww w .j a va 2 s . com*/ return cursor.getString(cursor.getColumnIndex(columnName)); }
From source file:Main.java
public static Uri getUriFromPath(Context context, String path) { String fileName = "file:///sdcard/DCIM/Camera/2013_07_07_12345.jpg"; Uri fileUri = Uri.parse(fileName);/*from ww w.ja v a 2 s .co m*/ String filePath = fileUri.getPath(); Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, "_data = '" + filePath + "'", null, null); cursor.moveToNext(); int id = cursor.getInt(cursor.getColumnIndex("_id")); Uri uri = ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id); return uri; }
From source file:Main.java
public static int getApnPortInt(Context context) { Cursor c = context.getContentResolver().query(PREFERRED_APN_URI, null, null, null, null); c.moveToFirst();/* ww w .jav a 2 s. c o m*/ if (c.isAfterLast()) { c.close(); return -1; } int result = c.getInt(c.getColumnIndex(APN_PROP_PORT)); return result; }