List of usage examples for android.database Cursor getInt
int getInt(int columnIndex);
From source file:fr.mixit.android.io.JsonHandlerApplyMembers.java
private static boolean isSharedLinkUpdated(Uri uri, String itemId, JSONObject sharedLink, ContentResolver resolver) throws JSONException { final String[] selectionArgs = { itemId }; final Cursor cursor = resolver.query(uri, MixItContract.SharedLinks.PROJ.PROJECTION, MixItContract.SharedLinks.MEMBER_ID + " = ?", selectionArgs, null); try {//from w w w . java2 s . c om if (!cursor.moveToFirst()) { return false; } final int curOrderNum = cursor.getInt(MixItContract.SharedLinks.PROJ.ORDER_NUM); final String curName = cursor.getString(MixItContract.SharedLinks.PROJ.NAME) .toLowerCase(Locale.getDefault()).trim(); final String curUrl = cursor.getString(MixItContract.SharedLinks.PROJ.URL) .toLowerCase(Locale.getDefault()).trim(); final int newOrderNum = sharedLink.has(TAG_ORDER_NUM) ? sharedLink.getInt(TAG_ORDER_NUM) : curOrderNum; final String newName = sharedLink.has(TAG_NAME) ? sharedLink.getString(TAG_NAME).toLowerCase(Locale.getDefault()).trim() : curName; final String newUrl = sharedLink.has(TAG_URL) ? sharedLink.getString(TAG_URL).toLowerCase(Locale.getDefault()).trim() : curUrl; return !curName.equals(newName) || // !curUrl.equals(newUrl) || // curOrderNum != newOrderNum; } finally { if (cursor != null) { cursor.close(); } } }
From source file:ro.weednet.contactssync.platform.ContactManager.java
public static int getStreamItemLimit(Context context) { Cursor c = context.getContentResolver().query(StreamItems.CONTENT_LIMIT_URI, new String[] { StreamItems.MAX_ITEMS }, null, null, null); try {/*from ww w.j a va2 s .c om*/ c.moveToFirst(); return c.getInt(0); } catch (Exception e) { } finally { if (c != null) { c.close(); } } return 1; }
From source file:ro.weednet.contactssync.platform.ContactManager.java
public static int getPhotoPickSize(Context context) { Cursor c = context.getContentResolver().query(DisplayPhoto.CONTENT_MAX_DIMENSIONS_URI, new String[] { DisplayPhoto.DISPLAY_MAX_DIM }, null, null, null); try {// w w w . ja v a 2s . c om c.moveToFirst(); return c.getInt(0); } catch (Exception e) { } finally { if (c != null) { c.close(); } } return ContactsSync.getInstance().getPictureSize(); }
From source file:curso.android.DAO.RespostaDAO.java
public static Resposta getPerguntaById(Resposta p) { Cursor cursor = null; try {// w w w .j av a2 s .c om cursor = Const.db.rawQuery("SELECT * FROM resposta WHERE asw_id = " + p.getAsw_id(), null); if (cursor.getCount() > 0) { int idIndex = cursor.getColumnIndex("asw_id"); int askIndex = cursor.getColumnIndex("ask_id"); int userIndex = cursor.getColumnIndex("user_id"); int respostaIndex = cursor.getColumnIndex("asw_resposta"); int nameIndex = cursor.getColumnIndex("user_name"); cursor.moveToFirst(); do { Long id = Long.valueOf(cursor.getInt(idIndex)); Long ask = Long.valueOf(cursor.getString(askIndex)); Long user = Long.valueOf(cursor.getString(userIndex)); String resposta = cursor.getString(respostaIndex); String user_name = cursor.getString(nameIndex); Resposta answer = new Resposta(); answer.setAsw_id(id); answer.setAsk_id(ask); answer.setUser_id(user); answer.setAsw_resposta(resposta); answer.setUser_name(user_name); return answer; } while (!cursor.isAfterLast()); } return null; } finally { if (cursor != null) { cursor.close(); } } }
From source file:com.hichinaschool.flashcards.libanki.Stats.java
public static double[][] getSmallDueStats(Collection col) { ArrayList<int[]> dues = new ArrayList<int[]>(); Cursor cur = null; try {/* w ww. jav a2s .c om*/ cur = col.getDb().getDatabase().rawQuery("SELECT (due - " + col.getSched().getToday() + ") AS day, " // day + "count(), " // all cards + "sum(CASE WHEN ivl >= 21 THEN 1 ELSE 0 END) " // mature cards + "FROM cards WHERE did IN " + col.getSched()._deckLimit() + " AND queue IN (2,3) AND day <= 7 GROUP BY day ORDER BY day", null); while (cur.moveToNext()) { dues.add(new int[] { cur.getInt(0), cur.getInt(1), cur.getInt(2) }); } } finally { if (cur != null && !cur.isClosed()) { cur.close(); } } // small adjustment for a proper chartbuilding with achartengine if (dues.size() == 0 || dues.get(0)[0] > 0) { dues.add(0, new int[] { 0, 0, 0 }); } if (dues.get(dues.size() - 1)[0] < 7) { dues.add(new int[] { 7, 0, 0 }); } double[][] serieslist = new double[3][dues.size()]; for (int i = 0; i < dues.size(); i++) { int[] data = dues.get(i); serieslist[0][i] = data[0]; serieslist[1][i] = data[1]; serieslist[2][i] = data[2]; } return serieslist; }
From source file:me.myatminsoe.myansms.Message.java
/** * Get a {@link Message} from cache or {@link Cursor}. * * @param context {@link Context}/*w w w . ja va2 s . c om*/ * @param cursor {@link Cursor} * @return {@link Message} */ public static Message getMessage(final Context context, final Cursor cursor) { synchronized (CACHE) { String body = cursor.getString(INDEX_BODY); int id = cursor.getInt(INDEX_ID); if (body == null) { // MMS id *= -1; } Message ret = CACHE.get(id); if (ret == null) { ret = new Message(context, cursor); CACHE.put(id, ret); while (CACHE.size() > CAHCESIZE) { Integer i = CACHE.keySet().iterator().next(); Message cc = CACHE.remove(i); if (cc == null) { break; } } } else { ret.update(cursor); } return ret; } }
From source file:curso.android.DAO.RespostaDAO.java
public static List<Resposta> readAll() { Cursor cursor = null; try {//from w w w .j a v a 2 s . c o m List<Resposta> all = new ArrayList<Resposta>(); cursor = Const.db.rawQuery("SELECT * FROM resposta", null); if (cursor.getCount() > 0) { int idIndex = cursor.getColumnIndex("asw_id"); int askIndex = cursor.getColumnIndex("ask_id"); int userIndex = cursor.getColumnIndex("user_id"); int respostaIndex = cursor.getColumnIndex("asw_resposta"); int nameIndex = cursor.getColumnIndex("user_name"); cursor.moveToFirst(); do { Long id = Long.valueOf(cursor.getInt(idIndex)); Long ask = Long.valueOf(cursor.getString(askIndex)); Long user = Long.valueOf(cursor.getString(userIndex)); String pergunta = cursor.getString(respostaIndex); String user_name = cursor.getString(nameIndex); Resposta asw = new Resposta(); asw.setAsw_id(id); asw.setAsk_id(ask); asw.setUser_id(user); asw.setAsw_resposta(pergunta); asw.setUser_name(user_name); all.add(asw); cursor.moveToNext(); } while (!cursor.isAfterLast()); } return all; } finally { if (cursor != null) { cursor.close(); } } }
From source file:com.example.android.ennis.barrett.popularmovies.asynchronous.TMDbSyncUtil.java
/** * Removes all data from themovies, thevideos, and thereviews tables. Does not remove data * flagged favorite but the columns istoprated, and ispopular will be set to false, "0". * @param context/*from www.j a v a 2 s. c o m*/ */ public static void deletePopularAndTopRated(Context context) { ContentResolver contentResolver = context.getContentResolver(); ContentValues removePopAndTop = new ContentValues(2); removePopAndTop.put(TMDbContract.Movies.IS_POPULAR, "0"); removePopAndTop.put(TMDbContract.Movies.IS_TOP_RATED, "0"); contentResolver.update(TMDbContract.Movies.URI, removePopAndTop, TMDbContract.Movies.IS_FAVORITE + " = ?", new String[] { "1" }); contentResolver.delete(TMDbContract.Movies.URI, TMDbContract.Movies.IS_POPULAR + " = ? OR " + TMDbContract.Movies.IS_TOP_RATED + " = ?", new String[] { "1", "1" }); Cursor favoriteMovieIds = getFavoriteIds(context); int numberOfIds = favoriteMovieIds.getCount(); String[] movieIds = new String[numberOfIds]; String whereClauseVideos = ""; String whereClauseReviews = ""; for (int i = 0; i < numberOfIds; i++) { favoriteMovieIds.moveToNext(); movieIds[i] = Integer.toString( favoriteMovieIds.getInt(favoriteMovieIds.getColumnIndex(TMDbContract.Movies.MOVIE_ID))); if (i == numberOfIds - 1) { whereClauseVideos += TMDbContract.Videos.MOVIE_IDS + " != ? "; whereClauseReviews += TMDbContract.Videos.MOVIE_IDS + " != ? "; } else { whereClauseVideos += TMDbContract.Videos.MOVIE_IDS + " != ? OR "; whereClauseReviews += TMDbContract.Reviews.MOVIE_IDS + " != ? OR "; } } contentResolver.delete(TMDbContract.Videos.URI, whereClauseVideos, movieIds); contentResolver.delete(TMDbContract.Reviews.URI, whereClauseReviews, movieIds); }
From source file:edu.stanford.mobisocial.dungbeetle.model.DbObject.java
/** * @param v the view to bind/*from w w w . j a v a2 s. c om*/ * @param context standard activity context * @param c the cursor source for the object in the db object table. * Must include _id in the projection. * * @param allowInteractions controls whether the bound view is * allowed to intercept touch events and do its own processing. */ public static void bindView(View v, final Context context, Cursor cursor, boolean allowInteractions) { TextView nameText = (TextView) v.findViewById(R.id.name_text); ViewGroup frame = (ViewGroup) v.findViewById(R.id.object_content); frame.removeAllViews(); // make sure we have all the columns we need Long objId = cursor.getLong(cursor.getColumnIndexOrThrow(DbObj.COL_ID)); String[] projection = null; String selection = DbObj.COL_ID + " = ?"; String[] selectionArgs = new String[] { Long.toString(objId) }; String sortOrder = null; Cursor c = context.getContentResolver().query(DbObj.OBJ_URI, projection, selection, selectionArgs, sortOrder); if (!c.moveToFirst()) { Log.w(TAG, "could not find obj " + objId); c.close(); return; } DbObj obj = App.instance().getMusubi().objForCursor(c); if (obj == null) { nameText.setText("Failed to access database."); Log.e("DbObject", "cursor was null for bindView of DbObject"); return; } DbUser sender = obj.getSender(); Long timestamp = c.getLong(c.getColumnIndexOrThrow(DbObj.COL_TIMESTAMP)); Long hash = obj.getHash(); short deleted = c.getShort(c.getColumnIndexOrThrow(DELETED)); String feedName = obj.getFeedName(); String type = obj.getType(); Date date = new Date(timestamp); c.close(); c = null; if (sender == null) { nameText.setText("Message from unknown contact."); return; } nameText.setText(sender.getName()); final ImageView icon = (ImageView) v.findViewById(R.id.icon); if (sViewProfileAction == null) { sViewProfileAction = new OnClickViewProfile((Activity) context); } icon.setTag(sender.getLocalId()); if (allowInteractions) { icon.setOnClickListener(sViewProfileAction); v.setTag(objId); } icon.setImageBitmap(sender.getPicture()); if (deleted == 1) { v.setBackgroundColor(sDeletedColor); } else { v.setBackgroundColor(Color.TRANSPARENT); } TextView timeText = (TextView) v.findViewById(R.id.time_text); timeText.setText(RelativeDate.getRelativeDate(date)); frame.setTag(objId); // TODO: error prone! This is database id frame.setTag(R.id.object_entry, cursor.getPosition()); // this is cursor id FeedRenderer renderer = DbObjects.getFeedRenderer(type); if (renderer != null) { renderer.render(context, frame, obj, allowInteractions); } if (!allowInteractions) { v.findViewById(R.id.obj_attachments_icon).setVisibility(View.GONE); v.findViewById(R.id.obj_attachments).setVisibility(View.GONE); } else { if (!MusubiBaseActivity.isDeveloperModeEnabled(context)) { v.findViewById(R.id.obj_attachments_icon).setVisibility(View.GONE); v.findViewById(R.id.obj_attachments).setVisibility(View.GONE); } else { ImageView attachmentCountButton = (ImageView) v.findViewById(R.id.obj_attachments_icon); TextView attachmentCountText = (TextView) v.findViewById(R.id.obj_attachments); attachmentCountButton.setVisibility(View.VISIBLE); if (hash == 0) { attachmentCountButton.setVisibility(View.GONE); } else { //int color = DbObject.colorFor(hash); boolean selfPost = false; DBHelper helper = new DBHelper(context); try { Cursor attachments = obj.getSubfeed().query("type=?", new String[] { LikeObj.TYPE }); try { attachmentCountText.setText("+" + attachments.getCount()); if (attachments.moveToFirst()) { while (!attachments.isAfterLast()) { if (attachments.getInt(attachments.getColumnIndex(CONTACT_ID)) == -666) { selfPost = true; break; } attachments.moveToNext(); } } } finally { attachments.close(); } } finally { helper.close(); } if (selfPost) { attachmentCountButton.setImageResource(R.drawable.ic_menu_love_red); } else { attachmentCountButton.setImageResource(R.drawable.ic_menu_love); } attachmentCountText.setTag(R.id.object_entry, hash); attachmentCountText.setTag(R.id.feed_label, Feed.uriForName(feedName)); attachmentCountText.setOnClickListener(LikeListener.getInstance(context)); } } } }
From source file:curso.android.DAO.RespostaDAO.java
public static List<Resposta> getRespostaPergunta(Pergunta p) { Cursor cursor = null; try {/* w ww.j ava2 s. c om*/ List<Resposta> questions = new ArrayList<Resposta>(); cursor = Const.db.rawQuery("SELECT * FROM resposta WHERE ask_id = " + p.getAsk_id(), null); if (cursor.getCount() > 0) { int idIndex = cursor.getColumnIndex("asw_id"); int askIndex = cursor.getColumnIndex("ask_id"); int userIndex = cursor.getColumnIndex("user_id"); int respostaIndex = cursor.getColumnIndex("asw_resposta"); int nameIndex = cursor.getColumnIndex("user_name"); cursor.moveToFirst(); do { Long id = Long.valueOf(cursor.getInt(idIndex)); Long ask = Long.valueOf(cursor.getString(askIndex)); Long user = Long.valueOf(cursor.getInt(userIndex)); String resposta = cursor.getString(respostaIndex); String user_name = cursor.getString(nameIndex); Resposta answer = new Resposta(); answer.setAsw_id(id); answer.setAsk_id(ask); answer.setUser_id(user); answer.setAsw_resposta(resposta); answer.setUser_name(user_name); questions.add(answer); cursor.moveToNext(); } while (!cursor.isAfterLast()); } return questions; } finally { if (cursor != null) { cursor.close(); } } }