List of usage examples for android.database Cursor getInt
int getInt(int columnIndex);
From source file:Main.java
public static ArrayList<ContentValues> getArea(SQLiteDatabase db, int dqx_dqxx01) { ArrayList<ContentValues> list = new ArrayList<ContentValues>(); ContentValues values = null;//from w ww .j a va 2 s . co m Cursor cursor = db.query(TABLE_NAME, new String[] { "DQXX01", "DQXX02", "DQXX05" }, "DQX_DQXX01=?", new String[] { "" + dqx_dqxx01 }, null, null, "DQXX01 ASC"); if (cursor != null) { while (cursor.moveToNext()) { values = new ContentValues(); values.put("area_id", cursor.getInt(0)); values.put("area", cursor.getString(1)); values.put("full_area", cursor.getString(2)); list.add(values); } } if (cursor != null && !cursor.isClosed()) { cursor.close(); } return list; }
From source file:Main.java
public static int getOrientation(Context context, Uri uri) { Cursor cursor = null; try {//from w w w .j a va 2 s. c o m cursor = context.getContentResolver().query(uri, new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null); if (cursor == null) { return 0; } if (cursor.moveToNext()) { int ori = cursor.getInt(0); return ori; } else { return -1; } } catch (SQLiteException e) { return 0; } finally { if (cursor != null) { cursor.close(); } } }
From source file:Main.java
private static String dumpRow(Cursor c) { String result = "VALUES("; for (int pos = 0; pos < c.getColumnCount(); pos++) { switch (c.getType(pos)) { case Cursor.FIELD_TYPE_NULL: result += "null"; break; case Cursor.FIELD_TYPE_INTEGER: result += Integer.toString(c.getInt(pos)); break; case Cursor.FIELD_TYPE_FLOAT: result += Float.toString(c.getFloat(pos)); break; case Cursor.FIELD_TYPE_STRING: result += DatabaseUtils.sqlEscapeString(c.getString(pos)); break; case Cursor.FIELD_TYPE_BLOB: result += "X'"; for (byte b : c.getBlob(pos)) { result += String.format("%02X", b); }//from ww w . j a v a 2 s . c o m result += "'"; break; default: return "Invalid field type " + c.getType(pos) + " at position " + pos; } if (pos < c.getColumnCount() - 1) { result += ", "; } } return result + ")"; }
From source file:cn.edu.wyu.documentviewer.model.DocumentInfo.java
/** * Missing or null values are returned as 0. *//*from w w w .j a v a 2 s . c o m*/ public static int getCursorInt(Cursor cursor, String columnName) { final int index = cursor.getColumnIndex(columnName); return (index != -1) ? cursor.getInt(index) : 0; }
From source file:Main.java
/** * Return file size from Uri/* w w w . j a v a 2s. com*/ * * @param uri file URI * @return return file size */ public static long getFileSizeFromUri(Context context, Uri uri) { long size = 0; if (uri.getScheme().toString().compareTo("content") == 0) { Cursor cursor = null; try { cursor = context.getApplicationContext().getContentResolver().query(uri, null, null, null, null); if (cursor != null && cursor.moveToFirst()) { final int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.SIZE); size = cursor.getInt(column_index); } } finally { if (cursor != null) { cursor.close(); } } } else if (uri.getScheme().toString().compareTo("file") == 0) { final File file = new File(uri.getPath()); size = file.length(); } return size; }
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);// ww w . jav a 2 s.c om 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
public static Map<String, Integer> getCity(SQLiteDatabase db, String tableName, int dqx_dqxx01, boolean municipalities) { Map<String, Integer> cityMap = new LinkedHashMap<String, Integer>(); Cursor cursor = db.query(tableName, new String[] { "DQXX02", "DQXX01" }, "DQX_DQXX01=?", new String[] { "" + dqx_dqxx01 }, null, null, "DQXX01 ASC"); if (cursor != null) { if (municipalities) { cursor.moveToNext();/*from www . ja va 2 s. co m*/ } while (cursor.moveToNext()) { cityMap.put(cursor.getString(0), cursor.getInt(1)); } } if (cursor != null && !cursor.isClosed()) { cursor.close(); } return cityMap; }
From source file:com.google.android.apps.santatracker.data.DestinationDbHelper.java
/** * Helper method that converts the cursor to a destination object. *//*from w ww .j a va2 s. com*/ static Destination getCursorDestination(Cursor mCursor) { Destination d = new Destination(); d.id = mCursor.getInt(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_ID)); d.identifier = mCursor.getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_IDENTIFIER)); d.city = mCursor.getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_CITY)); d.region = mCursor.getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_REGION)); d.country = mCursor.getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_COUNTRY)); d.arrival = mCursor.getLong(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_ARRIVAL)); d.departure = mCursor.getLong(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_DEPARTURE)); double lat = mCursor.getDouble(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_LAT)); double lng = mCursor.getDouble(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_LNG)); d.position = new LatLng(lat, lng); d.presentsDelivered = mCursor .getLong(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_PRESENTSDELIVERED)); d.presentsDeliveredAtDestination = mCursor .getLong(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_PRESENTS_DESTINATION)); d.timezone = mCursor.getLong(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_TIMEZONE)); d.altitude = mCursor.getLong(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_ALTITUDE)); d.photoString = mCursor.getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_PHOTOS)); d.weatherString = mCursor.getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_WEATHER)); d.streetViewString = mCursor .getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_STREETVIEW)); d.gmmStreetViewString = mCursor .getString(mCursor.getColumnIndex(SantaDestinationContract.COLUMN_NAME_GMMSTREETVIEW)); // Process the panoramio string if possible d.photos = processPhoto(d.photoString); d.weather = processWeather(d.weatherString); d.streetView = processStreetView(d.streetViewString); d.gmmStreetView = processStreetView(d.gmmStreetViewString); return d; }
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// www . j a v a2 s . c om */ 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:com.goliathonline.android.kegbot.io.RemoteKegHandler.java
private static ContentValues queryKegDetails(Uri uri, ContentResolver resolver) { final ContentValues values = new ContentValues(); final Cursor cursor = resolver.query(uri, KegsQuery.PROJECTION, null, null, null); try {/*from w ww . j av a 2 s . co m*/ if (cursor.moveToFirst()) { values.put(SyncColumns.UPDATED, cursor.getLong(KegsQuery.UPDATED)); values.put(Kegs.KEG_STARRED, cursor.getInt(KegsQuery.STARRED)); } else { values.put(SyncColumns.UPDATED, KegbotContract.UPDATED_NEVER); } } finally { cursor.close(); } return values; }