List of usage examples for android.database Cursor isAfterLast
boolean isAfterLast();
From source file:edu.mit.mobile.android.locast.data.TaggableItem.java
/** * @param cr//from w w w.java 2s. com * @param item * @param prefix * @return a list of all the tags attached to a given item */ public static Set<String> getTags(ContentResolver cr, Uri item, String prefix) { final Cursor tags = cr.query(Uri.withAppendedPath(item, Tag.PATH), Tag.DEFAULT_PROJECTION, null, null, null); final Set<String> tagSet = new HashSet<String>(tags.getCount()); final int tagColumn = tags.getColumnIndex(Tag._NAME); final Predicate<String> predicate = getPrefixPredicate(prefix); for (tags.moveToFirst(); !tags.isAfterLast(); tags.moveToNext()) { final String tag = tags.getString(tagColumn); if (predicate.apply(tag)) { final int separatorIndex = tag.indexOf(PREFIX_SEPARATOR); if (separatorIndex == -1) { tagSet.add(tag); } else { tagSet.add(tag.substring(separatorIndex + 1)); } } } tags.close(); return tagSet; }
From source file:org.thoughtcrime.SMP.notifications.MessageNotifier.java
private static void updateNotification(Context context, MasterSecret masterSecret, boolean signal, int reminderCount) { Cursor telcoCursor = null; Cursor pushCursor = null;/*from ww w . j a v a2s . c om*/ try { telcoCursor = DatabaseFactory.getMmsSmsDatabase(context).getUnread(); pushCursor = DatabaseFactory.getPushDatabase(context).getPending(); if ((telcoCursor == null || telcoCursor.isAfterLast()) && (pushCursor == null || pushCursor.isAfterLast())) { ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)) .cancel(NOTIFICATION_ID); updateBadge(context, 0); clearReminder(context); return; } NotificationState notificationState = constructNotificationState(context, masterSecret, telcoCursor); appendPushNotificationState(context, masterSecret, notificationState, pushCursor); if (notificationState.hasMultipleThreads()) { sendMultipleThreadNotification(context, masterSecret, notificationState, signal); } else { sendSingleThreadNotification(context, masterSecret, notificationState, signal); } updateBadge(context, notificationState.getMessageCount()); scheduleReminder(context, masterSecret, reminderCount); } finally { if (telcoCursor != null) telcoCursor.close(); if (pushCursor != null) pushCursor.close(); } }
From source file:com.tonyodev.fetch.Utils.java
static List<RequestInfo> cursorToRequestInfoList(Cursor cursor, boolean closeCursor, boolean loggingEnabled) { List<RequestInfo> requests = new ArrayList<>(); try {// w w w . j a v a2 s . co m if (cursor == null || cursor.isClosed() || cursor.getCount() < 1) { return requests; } cursor.moveToFirst(); while (!cursor.isAfterLast()) { requests.add(createRequestInfo(cursor, loggingEnabled)); cursor.moveToNext(); } if (closeCursor) { cursor.close(); } } catch (Exception e) { if (loggingEnabled) { e.printStackTrace(); } } return requests; }
From source file:com.tonyodev.fetch.Utils.java
static ArrayList<Bundle> cursorToQueryResultList(Cursor cursor, boolean closeCursor, boolean loggingEnabled) { ArrayList<Bundle> requests = new ArrayList<>(); try {/* w ww.j a v a2 s. c om*/ if (cursor == null || cursor.isClosed()) { return requests; } cursor.moveToFirst(); while (!cursor.isAfterLast()) { long id = cursor.getLong(DatabaseHelper.INDEX_COLUMN_ID); int status = cursor.getInt(DatabaseHelper.INDEX_COLUMN_STATUS); String url = cursor.getString(DatabaseHelper.INDEX_COLUMN_URL); String filePath = cursor.getString(DatabaseHelper.INDEX_COLUMN_FILEPATH); int error = cursor.getInt(DatabaseHelper.INDEX_COLUMN_ERROR); long fileSize = cursor.getLong(DatabaseHelper.INDEX_COLUMN_FILE_SIZE); int priority = cursor.getInt(DatabaseHelper.INDEX_COLUMN_PRIORITY); long downloadedBytes = cursor.getLong(DatabaseHelper.INDEX_COLUMN_DOWNLOADED_BYTES); String headers = cursor.getString(DatabaseHelper.INDEX_COLUMN_HEADERS); ArrayList<Bundle> headersList = headersToBundleList(headers, loggingEnabled); int progress = getProgress(downloadedBytes, fileSize); Bundle bundle = new Bundle(); bundle.putLong(FetchService.EXTRA_ID, id); bundle.putInt(FetchService.EXTRA_STATUS, status); bundle.putString(FetchService.EXTRA_URL, url); bundle.putString(FetchService.EXTRA_FILE_PATH, filePath); bundle.putInt(FetchService.EXTRA_ERROR, error); bundle.putLong(FetchService.EXTRA_DOWNLOADED_BYTES, downloadedBytes); bundle.putLong(FetchService.EXTRA_FILE_SIZE, fileSize); bundle.putInt(FetchService.EXTRA_PROGRESS, progress); bundle.putInt(FetchService.EXTRA_PRIORITY, priority); bundle.putParcelableArrayList(FetchService.EXTRA_HEADERS, headersList); requests.add(bundle); cursor.moveToNext(); } if (closeCursor) { cursor.close(); } } catch (Exception e) { if (loggingEnabled) { e.printStackTrace(); } } return requests; }
From source file:fr.eoit.activity.loader.InvestItemsLoader.java
private static SparseItemBeanArray getInvestItems(Context context, long itemId) { SparseItemBeanArray items = new SparseItemBeanArray(); final Cursor cursor = context.getContentResolver().query( ContentUris.withAppendedId(Item.CONTENT_ID_URI_INVEST, itemId), new String[] { Item._ID, Item.COLUMN_NAME_NAME, Item.COLUMN_NAME_CHOSEN_PRICE_ID, Blueprint.COLUMN_NAME_PRODUCE_ITEM_ID, Prices.COLUMN_NAME_OWN_PRICE, Prices.COLUMN_NAME_BUY_PRICE, Prices.COLUMN_NAME_SELL_PRICE, Prices.COLUMN_NAME_PRODUCE_PRICE }, null, null, null);//from w ww .j av a 2 s. com try { if (DbUtil.hasAtLeastOneRow(cursor)) { while (!cursor.isAfterLast()) { long producedItemId = cursor .getInt(cursor.getColumnIndexOrThrow(Blueprint.COLUMN_NAME_PRODUCE_ITEM_ID)); ItemBeanWithMaterials item = new ItemBeanWithMaterials(); item.id = cursor.getInt(cursor.getColumnIndexOrThrow(Item._ID)); item.name = cursor.getString(cursor.getColumnIndexOrThrow(Item.COLUMN_NAME_NAME)); item.price = PricesUtils.getPriceOrNaN(cursor); item.quantity = 1; item.chosenPriceId = cursor .getShort(cursor.getColumnIndexOrThrow(Item.COLUMN_NAME_CHOSEN_PRICE_ID)); item.volume = Double.NaN; items.append(item); items.putAll(getInvestItems(context, producedItemId)); cursor.moveToNext(); } } } finally { cursor.close(); } return items; }
From source file:edu.stanford.mobisocial.dungbeetle.model.DbObject.java
/** * @param v the view to bind//from www.j a v a2s.co m * @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:org.getlantern.firetweet.util.CustomTabUtils.java
public static List<SupportTabSpec> getHomeTabs(final Context context) { if (context == null) return Collections.emptyList(); final ContentResolver resolver = context.getContentResolver(); final Cursor cur = resolver.query(Tabs.CONTENT_URI, Tabs.COLUMNS, null, null, Tabs.DEFAULT_SORT_ORDER); if (cur == null) return Collections.emptyList(); final ArrayList<SupportTabSpec> tabs = new ArrayList<>(); cur.moveToFirst();//from w ww .ja va 2 s.c o m final int idxName = cur.getColumnIndex(Tabs.NAME), idxIcon = cur.getColumnIndex(Tabs.ICON), idxType = cur.getColumnIndex(Tabs.TYPE), idxArguments = cur.getColumnIndex(Tabs.ARGUMENTS), idxExtras = cur.getColumnIndex(Tabs.EXTRAS), idxPosition = cur.getColumnIndex(Tabs.POSITION); while (!cur.isAfterLast()) { final String type = cur.getString(idxType); final int position = cur.getInt(idxPosition); final String iconType = cur.getString(idxIcon); final String name = cur.getString(idxName); final Bundle args = ParseUtils.jsonToBundle(cur.getString(idxArguments)); final String tag = getTagByType(type); args.putInt(EXTRA_TAB_POSITION, position); args.putBundle(EXTRA_EXTRAS, ParseUtils.jsonToBundle(cur.getString(idxExtras))); final CustomTabConfiguration conf = getTabConfiguration(type); final Class<? extends Fragment> cls = conf != null ? conf.getFragmentClass() : InvalidTabFragment.class; tabs.add(new SupportTabSpec(name != null ? name : getTabTypeName(context, type), getTabIconObject(iconType), type, cls, args, position, tag)); cur.moveToNext(); } cur.close(); Collections.sort(tabs); return tabs; }
From source file:de.vanita5.twittnuker.util.CustomTabUtils.java
public static List<SupportTabSpec> getHomeTabs(final Context context) { if (context == null) return Collections.emptyList(); final ContentResolver resolver = context.getContentResolver(); final Cursor cur = resolver.query(Tabs.CONTENT_URI, Tabs.COLUMNS, null, null, Tabs.DEFAULT_SORT_ORDER); if (cur == null) return Collections.emptyList(); final ArrayList<SupportTabSpec> tabs = new ArrayList<SupportTabSpec>(); cur.moveToFirst();/*from www . ja va2 s . co m*/ final int idxName = cur.getColumnIndex(Tabs.NAME), idxIcon = cur.getColumnIndex(Tabs.ICON), idxType = cur.getColumnIndex(Tabs.TYPE), idxArguments = cur.getColumnIndex(Tabs.ARGUMENTS), idxExtras = cur.getColumnIndex(Tabs.EXTRAS), idxPosition = cur.getColumnIndex(Tabs.POSITION); while (!cur.isAfterLast()) { final String type = cur.getString(idxType); final int position = cur.getInt(idxPosition); final String iconType = cur.getString(idxIcon); final String name = cur.getString(idxName); final Bundle args = ParseUtils.jsonToBundle(cur.getString(idxArguments)); args.putInt(EXTRA_TAB_POSITION, position); args.putBundle(EXTRA_EXTRAS, ParseUtils.jsonToBundle(cur.getString(idxExtras))); final CustomTabConfiguration conf = getTabConfiguration(type); final Class<? extends Fragment> cls = conf != null ? conf.getFragmentClass() : InvalidTabFragment.class; tabs.add(new SupportTabSpec(name != null ? name : getTabTypeName(context, type), getTabIconObject(iconType), type, cls, args, position)); cur.moveToNext(); } cur.close(); Collections.sort(tabs); return tabs; }
From source file:de.azapps.mirakel.model.list.ListMirakel.java
@NonNull public static List<ListMirakel> all(final boolean withSpecial) { final List<ListMirakel> lists = new ArrayList<>(); if (withSpecial) { lists.addAll(SpecialList.allSpecial()); }/*from w w w .j av a 2 s . co m*/ String[] cols = new String[allColumns.length + 1]; for (int i = 0; i < allColumns.length; i++) { cols[i] = "n." + allColumns[i]; } cols[allColumns.length] = "COUNT(*)-1 AS level"; final Cursor cursor = query( MirakelInternalContentProvider.LISTS_SORT_URI, cols, "n." + LFT + " BETWEEN p." + LFT + " AND p." + RGT + " " + " AND NOT n." + DatabaseHelper.SYNC_STATE_FIELD + "=" + SYNC_STATE.DELETE, null, "n." + LFT); cursor.moveToFirst(); while (!cursor.isAfterLast()) { lists.add(new ListMirakel(cursor)); cursor.moveToNext(); } cursor.close(); return lists; }
From source file:Main.java
/** * Retourner la liste des calendriers//from w w w . j ava 2 s.co m * * @return Liste des calendriers */ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public static Map<Integer, String> getCalendars(ContentResolver contentResolver) { Map<Integer, String> calendars = new HashMap<Integer, String>(); String[] projection; Uri calendarUri; Cursor cursor; String accessLevelCol; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { calendarUri = CalendarContract.Calendars.CONTENT_URI; projection = new String[] { CalendarContract.Calendars._ID, CalendarContract.Calendars.CALENDAR_DISPLAY_NAME }; accessLevelCol = CalendarContract.Calendars.CALENDAR_ACCESS_LEVEL; } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) { calendarUri = Uri.parse("content://com.android.calendar/calendars"); projection = new String[] { "_id", "displayname" }; accessLevelCol = "ACCESS_LEVEL"; } else { calendarUri = Uri.parse("content://calendar/calendars"); projection = new String[] { "_id", "displayname" }; accessLevelCol = "ACCESS_LEVEL"; } cursor = contentResolver.query(calendarUri, projection, accessLevelCol + "=700", null, null); if (cursor != null && cursor.moveToFirst()) { while (cursor.isAfterLast() == false) { calendars.put(cursor.getInt(0), cursor.getString(1)); cursor.moveToNext(); } cursor.close(); } return calendars; }