List of usage examples for android.database Cursor getInt
int getInt(int columnIndex);
From source file:net.peterkuterna.android.apps.devoxxsched.io.RemoteSessionsHandler.java
private static int isStarred(Uri uri, ContentResolver resolver) { final Cursor cursor = resolver.query(uri, SessionsQuery.PROJECTION, null, null, null); int starred = 0; try {//from w w w . j av a 2 s . c o m if (cursor.moveToFirst()) { starred = cursor.getInt(SessionsQuery.STARRED); } } finally { cursor.close(); } return starred; }
From source file:Main.java
public static Map<Integer, List> getAreaByPid(int id, File file) { String sql = "select area,areaid from area where cityid= " + id; SQLiteDatabase db = null;// w w w . j a va 2s . c om Cursor c = null; List<String> areaList = null; List areaIdList = null; Map<Integer, List> areaData = new HashMap<Integer, List>(); try { db = SQLiteDatabase.openOrCreateDatabase(file, null); c = db.rawQuery(sql, null); areaList = new ArrayList<String>(); areaIdList = new ArrayList<String>(); while (c.moveToNext()) { Map areaMap = new HashMap(); areaMap.put(c.getString(0), c.getInt(1)); areaList.add(c.getString(0)); areaIdList.add(areaMap); } areaData.put(0, areaList); areaData.put(1, areaIdList); } catch (Exception e) { Log.d("WineStock", "getAreaByPid:" + e.getMessage()); } finally { if (c != null) { c.close(); } if (db != null) { db.close(); } } return areaData; }
From source file:com.example.igorklimov.popularmoviesdemo.helpers.Utility.java
public static int getId(Context context) { Uri uri = getContentUri(context);//from w ww . j a v a2 s . c o m Cursor cursor = context.getContentResolver().query(uri, null, null, null, null); int id = 0; if (cursor != null && cursor.moveToFirst()) { id = cursor.getInt(0); cursor.close(); } return id; }
From source file:Main.java
public static String logCursor(String prefix, Cursor cr) { StringBuilder sb = new StringBuilder().append(prefix + ": "); for (int i = 0; i < cr.getColumnCount(); i++) { sb.append(cr.getColumnName(i)).append("="); switch (cr.getType(i)) { case Cursor.FIELD_TYPE_NULL: sb.append("NULL"); break; case Cursor.FIELD_TYPE_STRING: sb.append("\"").append(cr.getString(i)).append("\""); break; case Cursor.FIELD_TYPE_INTEGER: sb.append(cr.getInt(i)); break; case Cursor.FIELD_TYPE_FLOAT: sb.append(cr.getFloat(i));/*ww w . jav a 2 s. co m*/ break; case Cursor.FIELD_TYPE_BLOB: sb.append("BIN(").append(cr.getBlob(i).length).append("b)"); break; } sb.append(" "); } return sb.toString(); }
From source file:mobisocial.noteshere.util.UriImage.java
public static float rotationForImage(Context context, Uri uri) { if (uri.getScheme().equals("content")) { String[] projection = { Images.ImageColumns.ORIENTATION }; Cursor c = context.getContentResolver().query(uri, projection, null, null, null); try {//from ww w .ja v a 2s. c o m if (c.moveToFirst()) { return c.getInt(0); } } finally { c.close(); } } else if (uri.getScheme().equals("file")) { 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:za.co.neilson.alarm.database.Database.java
public static Alarm getAlarm(int id) { // TODO Auto-generated method stub String[] columns = new String[] { COLUMN_ALARM_ID, COLUMN_ALARM_ACTIVE, COLUMN_ALARM_TIME, COLUMN_ALARM_DAYS, COLUMN_ALARM_DIFFICULTY, COLUMN_ALARM_TONE, COLUMN_ALARM_VIBRATE, COLUMN_ALARM_NAME };/*w w w. j a v a 2s.c om*/ Cursor c = getDatabase().query(ALARM_TABLE, columns, COLUMN_ALARM_ID + "=" + id, null, null, null, null); Alarm alarm = null; if (c.moveToFirst()) { alarm = new Alarm(); alarm.setId(c.getInt(1)); alarm.setAlarmActive(c.getInt(2) == 1); alarm.setAlarmTime(c.getString(3)); byte[] repeatDaysBytes = c.getBlob(4); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(repeatDaysBytes); try { ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream); Alarm.Day[] repeatDays; Object object = objectInputStream.readObject(); if (object instanceof Alarm.Day[]) { repeatDays = (Alarm.Day[]) object; alarm.setDays(repeatDays); } } catch (StreamCorruptedException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } alarm.setDifficulty(Difficulty.values()[c.getInt(5)]); alarm.setAlarmTonePath(c.getString(6)); alarm.setVibrate(c.getInt(7) == 1); alarm.setAlarmName(c.getString(8)); } c.close(); return alarm; }
From source file:com.energysystem.videoexplorerTV.video.VideoProvider.java
public static HashMap<String, List<Video>> buildMedia(String url, Cursor data) throws JSONException { mMovieList = new HashMap<String, List<Video>>(); mMovieList.clear();/*from ww w . j av a 2 s. c om*/ Log.e("Abrimos", "Videos"); List<Video> categoryList = new ArrayList<Video>(); List<Video> categoryList2 = new ArrayList<Video>(); while (data.moveToNext()) { int videoID = data.getInt(data.getColumnIndex(MediaStore.Video.Media._ID)); int title = data.getColumnIndexOrThrow(MediaStore.Video.Media.TITLE); int category = data.getColumnIndexOrThrow(MediaStore.Video.Media.CATEGORY); int durationID = data.getColumnIndexOrThrow(MediaStore.Video.Media.DURATION); int data_string = data.getColumnIndexOrThrow(MediaStore.Video.Media.DATA); //int videoUrl = data.getColumnIndexOrThrow(MediaStore.Video.Media.EXTERNAL_CONTENT_URI.toString()); // int bgImageUrl = data.getColumnIndexOrThrow(MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI.toString()); int duration = Integer.parseInt(data.getString(durationID)); String categoria = new File(data.getString(data_string)).getParent(); Log.e("Ruta:", categoria); if (categoria.equals("/storage/emulated/0/Movies")) { categoryList.add(buildMovieInfo(categoria, data.getString(title), "Descripcion", String.format("%d min, %d sec", TimeUnit.MILLISECONDS.toMinutes(duration), TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration))), ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoID).toString(), ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoID).toString(), ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoID) .toString())); mMovieList.put("Almacenamiento Interno", categoryList); } else { categoryList2.add(buildMovieInfo(categoria, data.getString(title), "Descripcion", String.format("%d min, %d sec", TimeUnit.MILLISECONDS.toMinutes(duration), TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration))), ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoID).toString(), ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoID).toString(), ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, videoID) .toString())); mMovieList.put("USB", categoryList2); } } /*JSONObject jsonObj = new VideoProvider().parseUrl(url); JSONArray categories = jsonObj.getJSONArray(TAG_GOOGLE_VIDEOS); if (null != categories) { Log.d(TAG, "category #: " + categories.length()); String title; String videoUrl; String bgImageUrl; String cardImageUrl; String studio; for (int i = 0; i < categories.length(); i++) { JSONObject category = categories.getJSONObject(i); String category_name = category.getString(TAG_CATEGORY); JSONArray videos = category.getJSONArray(TAG_MEDIA); Log.d(TAG, "category: " + i + " Name:" + category_name + " video length: " + videos.length()); List<Video> categoryList = new ArrayList<Video>(); if (null != videos) { for (int j = 0; j < videos.length(); j++) { JSONObject video = videos.getJSONObject(j); String description = video.getString(TAG_DESCRIPTION); JSONArray videoUrls = video.getJSONArray(TAG_SOURCES); if (null == videoUrls || videoUrls.length() == 0) { continue; } title = video.getString(TAG_TITLE); videoUrl = getVideoPrefix(category_name, videoUrls.getString(0)); bgImageUrl = getThumbPrefix(category_name, title, video.getString(TAG_BACKGROUND)); cardImageUrl = getThumbPrefix(category_name, title, video.getString(TAG_CARD_THUMB)); studio = video.getString(TAG_STUDIO); categoryList.add(buildMovieInfo(category_name, title, description, studio, videoUrl, cardImageUrl, bgImageUrl)); } mMovieList.put(category_name, categoryList); } } }*/ Log.e("VideoProvider", "Tamano mMovie: " + mMovieList.size()); return mMovieList; }
From source file:org.opendatakit.common.android.utilities.ODKCursorUtils.java
/** * Return the data stored in the cursor at the given index and given position * (ie the given row which the cursor is currently on) as null OR whatever * data type it is./* w w w . j a v a 2 s . co m*/ * <p> * This does not actually convert data types from one type to the other. * Instead, it safely preserves null values and returns boxed data values. If * you specify ArrayList or HashMap, it JSON deserializes the value into one * of those. * * @param c * @param clazz * @param i * @return */ @SuppressWarnings("unchecked") public static final <T> T getIndexAsType(Cursor c, Class<T> clazz, int i) { // If you add additional return types here be sure to modify the javadoc. try { if (i == -1) return null; if (c.isNull(i)) { return null; } if (clazz == Long.class) { Long l = c.getLong(i); return (T) l; } else if (clazz == Integer.class) { Integer l = c.getInt(i); return (T) l; } else if (clazz == Double.class) { Double d = c.getDouble(i); return (T) d; } else if (clazz == String.class) { String str = c.getString(i); return (T) str; } else if (clazz == Boolean.class) { // stored as integers Integer l = c.getInt(i); return (T) Boolean.valueOf(l != 0); } else if (clazz == ArrayList.class) { // json deserialization of an array String str = c.getString(i); return (T) ODKFileUtils.mapper.readValue(str, ArrayList.class); } else if (clazz == HashMap.class) { // json deserialization of an object String str = c.getString(i); return (T) ODKFileUtils.mapper.readValue(str, HashMap.class); } else { throw new IllegalStateException("Unexpected data type in SQLite table"); } } catch (ClassCastException e) { e.printStackTrace(); throw new IllegalStateException( "Unexpected data type conversion failure " + e.toString() + " in SQLite table "); } catch (JsonParseException e) { e.printStackTrace(); throw new IllegalStateException( "Unexpected data type conversion failure " + e.toString() + " on SQLite table"); } catch (JsonMappingException e) { e.printStackTrace(); throw new IllegalStateException( "Unexpected data type conversion failure " + e.toString() + " on SQLite table"); } catch (IOException e) { e.printStackTrace(); throw new IllegalStateException( "Unexpected data type conversion failure " + e.toString() + " on SQLite table"); } }
From source file:com.android.dialer.calllog.ContactInfoHelper.java
/** * Returns the contact information stored in an entry of the call log. * * @param c A cursor pointing to an entry in the call log. *//*from www.j a va 2s .co m*/ public static ContactInfo getContactInfo(Cursor c) { ContactInfo info = new ContactInfo(); info.lookupUri = UriUtils.parseUriOrNull(c.getString(CallLogQuery.CACHED_LOOKUP_URI)); info.name = c.getString(CallLogQuery.CACHED_NAME); info.type = c.getInt(CallLogQuery.CACHED_NUMBER_TYPE); info.label = c.getString(CallLogQuery.CACHED_NUMBER_LABEL); String matchedNumber = c.getString(CallLogQuery.CACHED_MATCHED_NUMBER); info.number = matchedNumber == null ? c.getString(CallLogQuery.NUMBER) : matchedNumber; info.normalizedNumber = c.getString(CallLogQuery.CACHED_NORMALIZED_NUMBER); info.photoId = c.getLong(CallLogQuery.CACHED_PHOTO_ID); info.photoUri = UriUtils .nullForNonContactsUri(UriUtils.parseUriOrNull(c.getString(CallLogQuery.CACHED_PHOTO_URI))); info.formattedNumber = c.getString(CallLogQuery.CACHED_FORMATTED_NUMBER); return info; }
From source file:org.zoumbox.mh_dla_notifier.sp.PublicScriptsProxy.java
protected static int computeRequestCount(Context context, ScriptCategory category, String trollId) { MhDlaSQLHelper helper = new MhDlaSQLHelper(context); SQLiteDatabase database = helper.getReadableDatabase(); Calendar instance = Calendar.getInstance(); instance.add(Calendar.HOUR_OF_DAY, -24); Date sinceDate = instance.getTime(); Cursor cursor = database.rawQuery(SQL_COUNT, new String[] { trollId, category.name(), "" + sinceDate.getTime() }); int result = 0; if (cursor.getCount() > 0) { cursor.moveToFirst();/*www . j a v a 2 s . c o m*/ result = cursor.getInt(0); } cursor.close(); database.close(); String format = "Quota for category %s and troll=%s since '%s' is: %d"; String message = String.format(format, category, trollId, sinceDate, result); Log.d(TAG, message); return result; }