List of usage examples for android.database Cursor getInt
int getInt(int columnIndex);
From source file:free.yhc.netmbuddy.share.Json.java
static JSONObject videoToJson(long vid) { final int COLI_VIDEOID = 0; final int COLI_TITLE = 1; final int COLI_AUTHOR = 2; final int COLI_VOLUME = 3; final int COLI_PLAYTIME = 4; final int COLI_BOOKMARKS = 5; Cursor c = DB.get().queryVideo(vid, new ColVideo[] { ColVideo.VIDEOID, ColVideo.TITLE, ColVideo.AUTHOR, ColVideo.VOLUME, ColVideo.PLAYTIME, ColVideo.BOOKMARKS }); if (!c.moveToFirst()) { c.close();//from w w w .jav a 2s . c om return null; } JSONObject jo = new JSONObject(); try { jo.put(FYTID, c.getString(COLI_VIDEOID)); jo.put(FTITLE, c.getString(COLI_TITLE)); // NOTE // Below field - author - is newly added at Database version 2 // So, we cannot sure that DB includes valid field value for them. if (Utils.isValidValue(c.getString(COLI_AUTHOR))) jo.put(FAUTHOR, c.getString(COLI_AUTHOR)); jo.put(FPLAYTIME, c.getInt(COLI_PLAYTIME)); jo.put(FBOOKMARKS, c.getString(COLI_BOOKMARKS)); int vol = c.getInt(COLI_VOLUME); if (Policy.DEFAULT_VIDEO_VOLUME != vol) jo.put(FVOLUME, vol); } catch (JSONException e) { jo = null; } c.close(); return jo; }
From source file:com.ubuntuone.android.files.provider.MetaUtilities.java
public static boolean isCached(String resourcePath) { String[] projection = new String[] { Nodes.NODE_IS_CACHED }; String selection = Nodes.NODE_RESOURCE_PATH + "=?"; String[] selectionArgs = new String[] { resourcePath }; Cursor c = sResolver.query(Nodes.CONTENT_URI, projection, selection, selectionArgs, null); if (c != null) { try {//from ww w. ja v a 2s . co m if (c.moveToFirst()) { return c.getInt(c.getColumnIndex(Nodes.NODE_IS_CACHED)) != 0; } } finally { c.close(); } } return false; }
From source file:com.ubuntuone.android.files.provider.MetaUtilities.java
public static Set<Integer> getRootNodeIds() { Set<Integer> ids = new TreeSet<Integer>(); final String[] projection = new String[] { Nodes._ID }; final String selection = Nodes.NODE_PARENT_PATH + " IS NULL"; final Cursor c = sResolver.query(Nodes.CONTENT_URI, projection, selection, null, null); try {/*from w w w. java 2 s . co m*/ if (c.moveToFirst()) { int id; do { id = c.getInt(c.getColumnIndex(Nodes._ID)); ids.add(id); } while (c.moveToNext()); } } finally { c.close(); } return ids; }
From source file:curso.android.DAO.PerguntaDAO.java
public static List<Pergunta> readAll() { Cursor cursor = null; try {/*from w w w .j a v a 2 s . c o m*/ List<Pergunta> all = new ArrayList<Pergunta>(); cursor = Const.db.rawQuery("SELECT * FROM pergunta WHERE user_id <> " + Const.config.idUser, null); if (cursor.getCount() > 0) { int idIndex = cursor.getColumnIndex("ask_id"); int userIndex = cursor.getColumnIndex("user_id"); int perguntaIndex = cursor.getColumnIndex("ask_pergunta"); int nomeIndex = cursor.getColumnIndex("user_name"); int statusIndex = cursor.getColumnIndex("status"); cursor.moveToFirst(); do { Long id = Long.valueOf(cursor.getInt(idIndex)); Long user = Long.valueOf(cursor.getString(userIndex)); String pergunta = cursor.getString(perguntaIndex); String user_name = cursor.getString(nomeIndex); String status = cursor.getString(statusIndex); Pergunta ask = new Pergunta(); ask.setAsk_id(id); ask.setUser_id(user); ask.setAsk_pergunta(pergunta); ask.setUser_name(user_name); ask.setStatus(Integer.valueOf(status) == 1); all.add(ask); cursor.moveToNext(); } while (!cursor.isAfterLast()); } return all; } finally { if (cursor != null) { cursor.close(); } } }
From source file:de.stadtrallye.rallyesoft.util.converters.CursorConverters.java
public static Task getTask(Cursor cursor, TaskCursorIds c) { LatLng coords;// ww w .j a v a 2 s .co m coords = (cursor.isNull(c.latitude) || cursor.isNull(c.longitude)) ? null : new LatLng(cursor.getDouble(c.latitude), cursor.getDouble(c.longitude)); try { List<AdditionalResource> res = null; String addRes = cursor.getString(c.additionalResources); if (addRes != null) { try { res = Serialization.getJsonInstance().readValue(addRes, new TypeReference<List<AdditionalResource>>() { }); } catch (JsonProcessingException e) { Log.e("CursorConverters", "Could not read additional resources: " + addRes, e); } } return new Task(cursor.getInt(c.id), getBoolean(cursor, c.locationSpecific), coords, cursor.getDouble(c.radius), cursor.getString(c.name), cursor.getString(c.description), getBoolean(cursor, c.multiple), cursor.getInt(c.submitType), cursor.getString(c.points), res); } catch (IOException e) { Log.e("Task Cursor Converter", "Json deserialization failed", e); return null; } }
From source file:curso.android.DAO.PerguntaDAO.java
public static List<Pergunta> getPerguntasUsuario() { Cursor cursor = null; try {/* w w w . j a v a2 s . c o m*/ List<Pergunta> questions = new ArrayList<Pergunta>(); cursor = Const.db.rawQuery("SELECT * FROM pergunta WHERE user_id =" + Const.config.idUser, null); if (cursor.getCount() > 0) { int idIndex = cursor.getColumnIndex("ask_id"); int userIndex = cursor.getColumnIndex("user_id"); int perguntaIndex = cursor.getColumnIndex("ask_pergunta"); int nameIndex = cursor.getColumnIndex("user_name"); int statusIndex = cursor.getColumnIndex("status"); cursor.moveToFirst(); do { Long id = Long.valueOf(cursor.getInt(idIndex)); Long user = Long.valueOf(cursor.getString(userIndex)); String pergunta = cursor.getString(perguntaIndex); String user_name = cursor.getString(nameIndex); String status = cursor.getString(statusIndex); Pergunta ask = new Pergunta(); ask.setAsk_id(id); ask.setUser_id(user); ask.setAsk_pergunta(pergunta); ask.setUser_name(user_name); ask.setStatus(Integer.valueOf(status) == 1); questions.add(ask); cursor.moveToNext(); } while (!cursor.isAfterLast()); } return questions; } finally { if (cursor != null) { cursor.close(); } } }
From source file:com.ubuntuone.android.files.provider.MetaUtilities.java
public static Set<Integer> getChildrenIds(String resourcePath) { Set<Integer> ids = new TreeSet<Integer>(); final String[] projection = new String[] { Nodes._ID, Nodes.NODE_RESOURCE_STATE }; final String selection = Nodes.NODE_PARENT_PATH + "=?"; //+ " AND " + Nodes.NODE_RESOURCE_STATE + " IS NULL"; // FIXME final String[] selectionArgs = new String[] { resourcePath }; final Cursor c = sResolver.query(Nodes.CONTENT_URI, projection, selection, selectionArgs, null); try {/*from ww w . jav a2 s . com*/ if (c.moveToFirst()) { int id; do { id = c.getInt(c.getColumnIndex(Nodes._ID)); // We check the state, above SQL is failing to filter out // nodes which are in non-null state. No idea why. String s = c.getString(c.getColumnIndex(Nodes.NODE_RESOURCE_STATE)); if (s == null) { ids.add(id); } else { Log.d("MetaUtilities", "child state != null, ignoring"); } } while (c.moveToNext()); } } finally { c.close(); } return ids; }
From source file:at.bitfire.davdroid.mirakel.resource.LocalCalendar.java
public static LocalCalendar[] findAll(Account account, ContentProviderClient providerClient, Context ctx) throws RemoteException { @Cleanup Cursor cursor = providerClient.query(calendarsURI(account), new String[] { Calendars._ID, Calendars.NAME }, Calendars.DELETED + "=0 AND " + Calendars.SYNC_EVENTS + "=1", null, null); LinkedList<LocalCalendar> calendars = new LinkedList<LocalCalendar>(); while (cursor != null && cursor.moveToNext()) calendars.add(new LocalCalendar(account, providerClient, cursor.getInt(0), cursor.getString(1), ctx)); return calendars.toArray(new LocalCalendar[0]); }
From source file:Main.java
/** * Try to get the exif orientation of the passed image uri * //from w w w. java2 s . c o m * @param context * @param uri * @return */ public static int getExifOrientation(Context context, Uri uri) { final String scheme = uri.getScheme(); ContentProviderClient provider = null; if (scheme == null || ContentResolver.SCHEME_FILE.equals(scheme)) { return getExifOrientation(uri.getPath()); } else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) { try { provider = context.getContentResolver().acquireContentProviderClient(uri); } catch (SecurityException e) { return 0; } if (provider != null) { Cursor result; try { result = provider.query(uri, new String[] { Images.ImageColumns.ORIENTATION, Images.ImageColumns.DATA }, null, null, null); } catch (Exception e) { e.printStackTrace(); return 0; } if (result == null) { return 0; } int orientationColumnIndex = result.getColumnIndex(Images.ImageColumns.ORIENTATION); int dataColumnIndex = result.getColumnIndex(Images.ImageColumns.DATA); try { if (result.getCount() > 0) { result.moveToFirst(); int rotation = 0; if (orientationColumnIndex > -1) { rotation = result.getInt(orientationColumnIndex); } if (dataColumnIndex > -1) { String path = result.getString(dataColumnIndex); rotation |= getExifOrientation(path); } return rotation; } } finally { result.close(); } } } return 0; }
From source file:com.android.providers.downloads.DownloadInfo.java
/** * Query and return status of requested download. */// www . j av a 2 s. c o m public static int queryDownloadStatus(ContentResolver resolver, long id) { final Cursor cursor = resolver.query( ContentUris.withAppendedId(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI, id), new String[] { Downloads.Impl.COLUMN_STATUS }, null, null, null); try { if (cursor.moveToFirst()) { return cursor.getInt(0); } else { // TODO: increase strictness of value returned for unknown // downloads; this is safe default for now. return Downloads.Impl.STATUS_PENDING; } } finally { cursor.close(); } }