List of usage examples for android.database Cursor getString
String getString(int columnIndex);
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:curso.android.DAO.PerguntaDAO.java
public static List<Pergunta> readAll() { Cursor cursor = null; try {/*from w w w. j a va 2s . co 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:com.rp.justcast.video.VideoProvider.java
public static List<MediaInfo> buildMedia() throws JSONException { if (null != mediaList) { return mediaList; }/* ww w . j a v a 2 s . c o m*/ String[] columns = { MediaStore.Video.Media._ID, MediaStore.Video.Media.DATA, MediaStore.Video.Media.TITLE, MediaStore.Video.Media.DURATION }; String orderBy = MediaStore.Images.Media.DATE_TAKEN + " desc"; Cursor videoCursor = null; try { videoCursor = JustCast.getmAppContext().getContentResolver() .query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, columns, null, null, orderBy); videoCursor.moveToFirst(); long fileId = videoCursor.getLong(videoCursor.getColumnIndex(MediaStore.Video.Media._ID)); Log.w(TAG, "Building Media"); Log.w(TAG, "Video Count" + videoCursor.getCount()); int count = videoCursor.getCount(); Log.d(TAG, "Count of images" + count); mediaList = new ArrayList<MediaInfo>(); for (int i = 0; i < count; i++) { videoCursor.moveToPosition(i); int dataColumnIndex = videoCursor.getColumnIndex(MediaStore.Video.Media.DATA); int titleIndex = videoCursor.getColumnIndex(MediaStore.Video.Media.TITLE); Log.w(TAG, "Video added" + videoCursor.getString(dataColumnIndex)); String path = videoCursor.getString(dataColumnIndex); String title = videoCursor.getString(titleIndex); MediaMetadata movieMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE); movieMetadata.putString("VIDEO_PATH", path); movieMetadata.putString(MediaMetadata.KEY_SUBTITLE, title); movieMetadata.putString(MediaMetadata.KEY_TITLE, title); movieMetadata.putString(MediaMetadata.KEY_STUDIO, title); path = JustCast.addJustCastServerParam(path); MediaInfo mediaInfo = new MediaInfo.Builder(path).setStreamType(MediaInfo.STREAM_TYPE_BUFFERED) .setContentType(getMediaType()).setMetadata(movieMetadata).build(); mediaList.add(mediaInfo); } } finally { videoCursor.close(); } return mediaList; }
From source file:curso.android.DAO.PerguntaDAO.java
public static List<Pergunta> getPerguntasUsuario() { Cursor cursor = null; try {//from ww w .j a v a2 s .co 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
/** * Calculates directory content size, recursively if necessary. * //from ww w. j a v a 2 s . c o m * @param resourcePath * the directory resource path to calculate size of * @param recursive * the flag indicating recursive calculation * @return the resorucePath defined directory size */ public static long getDirectorySize(final String resourcePath, final boolean recursive) { final String[] projection = new String[] { Nodes.NODE_RESOURCE_PATH, Nodes.NODE_KIND, Nodes.NODE_SIZE }; final String selection = Nodes.NODE_PARENT_PATH + "=?"; final String[] selectionArgs = new String[] { resourcePath }; final Cursor c = sResolver.query(Nodes.CONTENT_URI, projection, selection, selectionArgs, null); U1NodeKind kind; long size = 0L; try { if (c.moveToFirst()) { do { kind = U1NodeKind .valueOf(c.getString(c.getColumnIndex(Nodes.NODE_KIND)).toUpperCase(Locale.US)); if (U1NodeKind.FILE == kind) { size += c.getLong(c.getColumnIndex(Nodes.NODE_SIZE)); } else if (U1NodeKind.DIRECTORY == kind && recursive) { final String subDirResourcePath = c.getString(c.getColumnIndex(Nodes.NODE_RESOURCE_PATH)); size += getDirectorySize(subDirResourcePath, true); } } while (c.moveToNext()); } } finally { c.close(); } return size; }
From source file:busradar.madison.StopDialog.java
static RouteURL[] get_time_urls(int stopid) { Cursor c = G.db.rawQuery("SELECT url, route " + "FROM routestops " + "WHERE stopid = ? " + "ORDER BY route", new String[] { stopid + "" }); RouteURL[] list = new RouteURL[c.getCount()]; //ArrayList<RouteURL> list = new ArrayLst<RouteURL>(); //int last = -1; int i = 0;/*from www . j a va 2s. c o m*/ while (c.moveToNext()) { RouteURL r = new RouteURL(); r.url = c.getString(0); r.route = c.getInt(1); list[i++] = r; } c.close(); return list; }
From source file:com.futurologeek.smartcrossing.crop.CropImageActivity.java
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { Cursor cursor = null; final String column = "_data"; final String[] projection = { column }; try {/*from ww w . ja v a 2s . co m*/ cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); if (cursor != null && cursor.moveToFirst()) { final int index = cursor.getColumnIndexOrThrow(column); return cursor.getString(index); } } finally { if (cursor != null) cursor.close(); } return null; }
From source file:com.orm.androrm.field.CharField.java
@Override public void set(Cursor c, String fieldName) { set(c.getString(c.getColumnIndexOrThrow(fieldName))); }
From source file:de.luhmer.owncloudnewsreader.reader.GoogleReaderApi.GoogleReaderMethods.java
public static void MarkItemAsRead(Boolean isRead, Cursor cursor, DatabaseConnection dbConn, Context context, OnAsyncTaskCompletedListener asyncTaskCompletedPerformTagRead) { List<NameValuePair> nameValuePairs = getStarredReadNameValuePairs(dbConn, cursor); if (isRead)/*from w ww.ja v a 2s .c o m*/ nameValuePairs.add(new BasicNameValuePair("a", GoogleReaderConstants._STATE_READ)); else nameValuePairs.add(new BasicNameValuePair("r", GoogleReaderConstants._STATE_READ)); ExecuteTagsReadStarred(nameValuePairs, context, asyncTaskCompletedPerformTagRead); Log.d("CHECKBOX", "STATUS CHANGED: " + isRead); dbConn.updateIsReadOfItem(cursor.getString(0), isRead); }
From source file:com.hichinaschool.flashcards.libanki.Finder.java
public static int findReplace(Collection col, List<Long> nids, String src, String dst, boolean isRegex, String field, boolean fold) { Map<Long, Integer> mmap = new HashMap<Long, Integer>(); if (field != null) { try {//from w w w.j a v a 2 s . c om for (JSONObject m : col.getModels().all()) { JSONArray flds = m.getJSONArray("flds"); for (int fi = 0; fi < flds.length(); ++fi) { JSONObject f = flds.getJSONObject(fi); if (f.getString("name").equals(field)) { mmap.put(m.getLong("id"), f.getInt("ord")); } } } } catch (JSONException e) { throw new RuntimeException(e); } if (mmap.isEmpty()) { return 0; } } // find and gather replacements if (!isRegex) { src = Pattern.quote(src); } if (fold) { src = "(?i)" + src; } Pattern regex = Pattern.compile(src); ArrayList<Object[]> d = new ArrayList<Object[]>(); String sql = "select id, mid, flds from notes where id in " + Utils.ids2str(nids.toArray(new Long[] {})); nids = new ArrayList<Long>(); Cursor cur = null; try { cur = col.getDb().getDatabase().rawQuery(sql, null); while (cur.moveToNext()) { String flds = cur.getString(2); String origFlds = flds; // does it match? String[] sflds = Utils.splitFields(flds); if (field != null) { long mid = cur.getLong(1); if (!mmap.containsKey(mid)) { continue; } int ord = mmap.get(mid); sflds[ord] = regex.matcher(sflds[ord]).replaceAll(dst); } else { for (int i = 0; i < sflds.length; ++i) { sflds[i] = regex.matcher(sflds[i]).replaceAll(dst); } } flds = Utils.joinFields(sflds); if (!flds.equals(origFlds)) { long nid = cur.getLong(0); nids.add(nid); d.add(new Object[] { flds, Utils.intNow(), col.usn(), nid }); } } } finally { if (cur != null) { cur.close(); } } if (d.isEmpty()) { return 0; } // replace col.getDb().executeMany("update notes set flds=?,mod=?,usn=? where id=?", d); long[] pnids = Utils.toPrimitive(nids); col.updateFieldCache(pnids); col.genCards(pnids); return d.size(); }