List of usage examples for android.database Cursor getPosition
int getPosition();
From source file:com.akhbulatov.wordkeeper.ui.fragment.CategoryListFragment.java
private void deleteCategory() { // First, deletes all words that are in the deleted category Cursor cursor = mWordDbAdapter.getRecordsByCategory(getName()); WordAdapter wordAdapter = new WordAdapter(cursor); while (!cursor.isAfterLast()) { long id = wordAdapter.getItemId(cursor.getPosition()); mWordDbAdapter.delete(new Word(id)); cursor.moveToNext();/* ww w . j a va 2 s . c o m*/ } mCategoryDbAdapter.delete(new Category(mSelectedItemId)); getLoaderManager().restartLoader(LOADER_ID, null, this); }
From source file:de.k3b.android.androFotoFinder.imagedetail.ImagePagerAdapterFromCursor.java
/** debug support for logging current cursor content */ private String debugCursor(Cursor cursor, int maxRows, String delim, String... colmnNames) { StringBuilder result = new StringBuilder(); if ((cursor != null) && (!cursor.isClosed())) { int oldPosition = cursor.getPosition(); int last = Math.min(maxRows - 1, cursor.getCount() - 1); for (int position = 0; position <= last; position++) { result.append("#").append(position); cursor.moveToPosition(position); for (String col : colmnNames) { result.append(";").append(cursor.getString(cursor.getColumnIndex(col))); }/*from w w w.j av a2s .com*/ result.append(delim); } } return result.toString(); }
From source file:monakhv.android.samlib.BookListFragment.java
public boolean singleClick(MotionEvent e) { int position = getListView().pointToPosition((int) e.getX(), (int) e.getY()); Cursor c = (Cursor) adapter.getItem(position); if (c.getPosition() < 0) { //Log.d(DEBUG_TAG, "get cursor at position: "+c.getPosition()+ " Exiting."); return false; }/* w ww . j a v a 2 s. co m*/ long book_id = c.getLong(c.getColumnIndex(SQLController.COL_ID)); Book book = sql.getBookController().getById(book_id); loadBook(book); return true; }
From source file:monakhv.android.samlib.BookListFragment.java
public boolean swipeLeft(MotionEvent e) { int position = getListView().pointToPosition((int) e.getX(), (int) e.getY()); Cursor c = (Cursor) adapter.getItem(position); if (c.getPosition() < 0) { Log.d(DEBUG_TAG, "get cursor at position: " + c.getPosition() + " Exiting."); return false; }/* w w w . ja va2 s . c o m*/ long book_id = c.getLong(c.getColumnIndex(SQLController.COL_ID)); Book book = sql.getBookController().getById(book_id); launchBrowser(book); return true; }
From source file:tw.idv.palatis.danboorugallery.siteapi.GelbooruAPI.java
@Override public Post getPostFromCursor(Host host, Cursor post_cursor, Cursor tags_cursor) { String[] tags;/*from w w w . j av a 2 s. co m*/ if (tags_cursor != null) { tags_cursor.moveToPosition(-1); tags = new String[tags_cursor.getCount()]; while (tags_cursor.moveToNext()) tags[tags_cursor.getPosition()] = tags_cursor.getString(PostTagsView.INDEX_KEY_POST_TAG_TAG_NAME); } else tags = new String[0]; return new GelbooruPost(host, post_cursor.getInt(PostsTable.INDEX_POST_POST_ID), post_cursor.getInt(PostsTable.INDEX_POST_IMAGE_WIDTH), post_cursor.getInt(PostsTable.INDEX_POST_IMAGE_HEIGHT), new Date(post_cursor.getLong(PostsTable.INDEX_POST_CREATED_AT)), new Date(post_cursor.getLong(PostsTable.INDEX_POST_UPDATED_AT)), post_cursor.getInt(PostsTable.INDEX_POST_FILE_SIZE), post_cursor.getString(PostsTable.INDEX_POST_FILE_URL), post_cursor.getString(PostsTable.INDEX_POST_LARGE_FILE_URL), post_cursor.getString(PostsTable.INDEX_POST_PREVIEW_FILE_URL), tags, post_cursor.getString(PostsTable.INDEX_POST_RATING), post_cursor.getString(PostsTable.INDEX_POST_EXTRA_INFO)); }
From source file:tw.idv.palatis.danboorugallery.siteapi.MoebooruAPI.java
@Override public Post getPostFromCursor(Host host, Cursor post_cursor, Cursor tags_cursor) { String[] tags;//from w w w . j av a2s . c om if (tags_cursor != null) { tags_cursor.moveToPosition(-1); tags = new String[tags_cursor.getCount()]; while (tags_cursor.moveToNext()) tags[tags_cursor.getPosition()] = tags_cursor.getString(PostTagsView.INDEX_KEY_POST_TAG_TAG_NAME); } else tags = new String[0]; return new MoebooruPost(host, post_cursor.getInt(PostsTable.INDEX_POST_POST_ID), post_cursor.getInt(PostsTable.INDEX_POST_IMAGE_WIDTH), post_cursor.getInt(PostsTable.INDEX_POST_IMAGE_HEIGHT), new Date(post_cursor.getLong(PostsTable.INDEX_POST_CREATED_AT)), new Date(post_cursor.getLong(PostsTable.INDEX_POST_UPDATED_AT)), post_cursor.getInt(PostsTable.INDEX_POST_FILE_SIZE), post_cursor.getString(PostsTable.INDEX_POST_FILE_URL), post_cursor.getString(PostsTable.INDEX_POST_LARGE_FILE_URL), post_cursor.getString(PostsTable.INDEX_POST_PREVIEW_FILE_URL), tags, post_cursor.getString(PostsTable.INDEX_POST_RATING), post_cursor.getString(PostsTable.INDEX_POST_EXTRA_INFO)); }
From source file:monakhv.android.samlib.BookListFragment.java
public boolean swipeRight(MotionEvent e) { int position = getListView().pointToPosition((int) e.getX(), (int) e.getY()); Cursor c = (Cursor) adapter.getItem(position); if (c.getPosition() < 0) { //Log.d(DEBUG_TAG, "get cursor at position: "+c.getPosition()+ " Exiting."); return false; }//w w w . jav a 2 s .co m long book_id = c.getLong(c.getColumnIndex(SQLController.COL_ID)); Book book = sql.getBookController().getById(book_id); settings.log("MARK_READ", "BookListFragment: call markRead for book: " + book_id + " - " + book.getUri()); sql.getBookController().markRead(book); Author a = sql.getByBook(book); sql.testMarkRead(a); return true; }
From source file:tw.idv.palatis.danboorugallery.siteapi.DanbooruLegacyAPI.java
@Override public Post getPostFromCursor(Host host, Cursor post_cursor, Cursor tags_cursor) { String[] tags;//from w w w .j a v a 2 s . c o m if (tags_cursor != null) { tags_cursor.moveToPosition(-1); tags = new String[tags_cursor.getCount()]; while (tags_cursor.moveToNext()) tags[tags_cursor.getPosition()] = tags_cursor.getString(PostTagsView.INDEX_KEY_POST_TAG_TAG_NAME); } else tags = new String[0]; return new DanbooruLegacyPost(host, post_cursor.getInt(PostsTable.INDEX_POST_POST_ID), post_cursor.getInt(PostsTable.INDEX_POST_IMAGE_WIDTH), post_cursor.getInt(PostsTable.INDEX_POST_IMAGE_HEIGHT), new Date(post_cursor.getLong(PostsTable.INDEX_POST_CREATED_AT)), new Date(post_cursor.getLong(PostsTable.INDEX_POST_UPDATED_AT)), post_cursor.getInt(PostsTable.INDEX_POST_FILE_SIZE), post_cursor.getString(PostsTable.INDEX_POST_FILE_URL), post_cursor.getString(PostsTable.INDEX_POST_LARGE_FILE_URL), post_cursor.getString(PostsTable.INDEX_POST_PREVIEW_FILE_URL), tags, post_cursor.getString(PostsTable.INDEX_POST_RATING), post_cursor.getString(PostsTable.INDEX_POST_EXTRA_INFO)); }
From source file:org.mariotaku.twidere.adapter.CursorStatusesAdapter.java
@Override public void bindView(final View view, final Context context, final Cursor cursor) { final int position = cursor.getPosition(); final StatusViewHolder holder = (StatusViewHolder) view.getTag(); final boolean is_gap = cursor.getShort(mIndices.is_gap) == 1; final boolean show_gap = is_gap && !mGapDisallowed && position != getCount() - 1; holder.setShowAsGap(show_gap);// ww w .j a v a 2 s .com if (!show_gap) { final long account_id = cursor.getLong(mIndices.account_id); final long user_id = cursor.getLong(mIndices.user_id); final long status_id = cursor.getLong(mIndices.status_id); final long status_timestamp = cursor.getLong(mIndices.status_timestamp); final long retweet_count = cursor.getLong(mIndices.retweet_count); final String retweeted_by_name = cursor.getString(mIndices.retweeted_by_name); final String retweeted_by_screen_name = cursor.getString(mIndices.retweeted_by_screen_name); final String text = cursor.getString(mIndices.text_html); final String screen_name = cursor.getString(mIndices.screen_name); final String name = cursor.getString(mIndices.name); final String in_reply_to_screen_name = cursor.getString(mIndices.in_reply_to_screen_name); final String account_screen_name = getAccountScreenName(mContext, account_id); final boolean is_favorite = cursor.getShort(mIndices.is_favorite) == 1; final boolean is_protected = cursor.getShort(mIndices.is_protected) == 1; final boolean is_verified = cursor.getShort(mIndices.is_verified) == 1; final boolean has_location = !TextUtils.isEmpty(cursor.getString(mIndices.location)); final boolean is_retweet = !TextUtils.isEmpty(retweeted_by_name) && cursor.getShort(mIndices.is_retweet) == 1; final boolean is_reply = !TextUtils.isEmpty(in_reply_to_screen_name) && cursor.getLong(mIndices.in_reply_to_status_id) > 0; final boolean is_mention = text.toLowerCase().contains('@' + account_screen_name.toLowerCase()); final boolean is_my_status = account_id == user_id; if (mMultiSelectEnabled) { holder.setSelected(mSelectedStatusIds.contains(status_id)); } else { holder.setSelected(false); } holder.setUserColor(getUserColor(mContext, user_id)); if (text != null) { holder.setHighlightColor(getStatusBackground(mMentionsHighlightDisabled ? false : is_mention, is_favorite, is_retweet)); } holder.setAccountColorEnabled(mShowAccountColor); if (mShowAccountColor) { holder.setAccountColor(getAccountColor(mContext, account_id)); } final PreviewImage preview = getPreviewImage(text, mInlineImagePreviewDisplayOption); final boolean has_media = preview != null ? preview.has_image : false; holder.setTextSize(mTextSize); holder.setIsMyStatus(is_my_status && !mIndicateMyStatusDisabled); if (mLinkHighlightingEnabled) { holder.text.setText(Html.fromHtml(text)); final TwidereLinkify linkify = new TwidereLinkify(holder.text); linkify.setOnLinkClickListener(new OnLinkClickHandler(context, account_id)); linkify.addAllLinks(); } else { holder.text.setText(toPlainText(text)); } holder.text.setMovementMethod(null); holder.name.setCompoundDrawablesWithIntrinsicBounds(0, 0, getUserTypeIconRes(is_verified, is_protected), 0); switch (mNameDisplayOption) { case NAME_DISPLAY_OPTION_CODE_NAME: { holder.name.setText(name); holder.screen_name.setText(null); holder.screen_name.setVisibility(View.GONE); break; } case NAME_DISPLAY_OPTION_CODE_SCREEN_NAME: { holder.name.setText("@" + screen_name); holder.screen_name.setText(null); holder.screen_name.setVisibility(View.GONE); break; } default: { holder.name.setText(name); holder.screen_name.setText("@" + screen_name); holder.screen_name.setVisibility(View.VISIBLE); break; } } if (mShowAbsoluteTime) { holder.time.setText(formatSameDayTime(context, status_timestamp)); } else { holder.time.setText(getRelativeTimeSpanString(status_timestamp)); } holder.time.setCompoundDrawablesWithIntrinsicBounds(0, 0, getStatusTypeIconRes(is_favorite, has_location, has_media), 0); holder.reply_retweet_status.setVisibility(is_retweet || is_reply ? View.VISIBLE : View.GONE); if (is_retweet) { if (mNameDisplayOption == NAME_DISPLAY_OPTION_CODE_SCREEN_NAME) { holder.reply_retweet_status.setText(retweet_count > 1 ? mContext.getString(R.string.retweeted_by_with_count, retweeted_by_screen_name, retweet_count - 1) : mContext.getString(R.string.retweeted_by, retweeted_by_screen_name)); } else { holder.reply_retweet_status.setText(retweet_count > 1 ? mContext.getString(R.string.retweeted_by_with_count, retweeted_by_name, retweet_count - 1) : mContext.getString(R.string.retweeted_by, retweeted_by_name)); } holder.reply_retweet_status.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_indicator_retweet, 0, 0, 0); } else if (is_reply) { holder.reply_retweet_status .setText(mContext.getString(R.string.in_reply_to, in_reply_to_screen_name)); holder.reply_retweet_status.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_indicator_reply, 0, 0, 0); } if (mDisplayProfileImage) { final String profile_image_url = cursor.getString(mIndices.profile_image_url); mProfileImageLoader.displayImage(holder.my_profile_image, profile_image_url); mProfileImageLoader.displayImage(holder.profile_image, profile_image_url); holder.profile_image.setTag(position); holder.my_profile_image.setTag(position); } else { holder.profile_image.setVisibility(View.GONE); holder.my_profile_image.setVisibility(View.GONE); } final boolean has_preview = mInlineImagePreviewDisplayOption != INLINE_IMAGE_PREVIEW_DISPLAY_OPTION_CODE_NONE && has_media && preview.matched_url != null; holder.image_preview_frame.setVisibility(has_preview ? View.VISIBLE : View.GONE); if (has_preview) { final MarginLayoutParams lp = (MarginLayoutParams) holder.image_preview_frame.getLayoutParams(); if (mInlineImagePreviewDisplayOption == INLINE_IMAGE_PREVIEW_DISPLAY_OPTION_CODE_LARGE) { lp.width = LayoutParams.MATCH_PARENT; lp.leftMargin = 0; holder.image_preview_frame.setLayoutParams(lp); } else if (mInlineImagePreviewDisplayOption == INLINE_IMAGE_PREVIEW_DISPLAY_OPTION_CODE_SMALL) { lp.width = mResources.getDimensionPixelSize(R.dimen.image_preview_width); lp.leftMargin = (int) (mResources.getDisplayMetrics().density * 16); holder.image_preview_frame.setLayoutParams(lp); } final boolean is_possibly_sensitive = cursor.getInt(mIndices.is_possibly_sensitive) == 1; if (is_possibly_sensitive && !mDisplaySensitiveContents) { holder.image_preview.setImageResource(R.drawable.image_preview_nsfw); } else { mPreviewImageLoader.displayImage(holder.image_preview, preview.matched_url); } holder.image_preview_frame.setTag(position); } } super.bindView(view, context, cursor); }
From source file:com.alley.android.ppi.app.OverviewFragment.java
private void paintHousesOnMap(Cursor cursor) { int count = 0; if (cursor != null) { Log.i(LOG_TAG, "Cursor had " + cursor.getCount() + " entries, current position" + cursor.getPosition()); if (mMap == null) { // Log.e(LOG_TAG, "Camera was null - "); return; }//from ww w .ja v a 2 s. c o m mMap.clear(); int cursorCount = cursor.getCount(); Log.i(LOG_TAG, "After movetoFirst Cursor had " + cursor.getCount() + " entries, current position" + cursor.getPosition()); LatLng house = null; ArrayList<MarkerOptions> markers = new ArrayList<MarkerOptions>(); while (count < cursorCount) { // this sucks but moveToFirst loses first entry so cant use cursor.moveToNext cursor.moveToPosition(count); float lat = cursor.getFloat(COL_COORD_LAT); float lon = cursor.getFloat(COL_COORD_LONG); if (lat != 0 && lon != 0) { house = new LatLng(lat, lon); if (latitude == 0 && longitude == 0 && zoom == 0 && lat != 0 && lon != 0) { if (house != null) { Log.i(LOG_TAG, " moving to house " + house.toString()); latitude = lat; longitude = lon; zoom = 15; CameraUpdate center = CameraUpdateFactory.newLatLngZoom(house, zoom); mMap.moveCamera(center); } } MarkerOptions marker = new MarkerOptions().position(house) .title(cursor.getString(OverviewFragment.COL_PRICE)) .snippet(cursor.getString(OverviewFragment.COL_SEARCH_STRING_USED) + "/" + cursor.getString(OverviewFragment.COL_DESCRIPTION)) .icon(getBitmap(cursor.getString(OverviewFragment.COLUMN_NUM_BEDS), cursor.getString(OverviewFragment.COL_APARTMENT_HOUSE))); mMap.addMarker(marker); markers.add(marker); Log.i(LOG_TAG, count + " " + cursor.getString(OverviewFragment.COL_PRICE) + " " + house.toString()); } else { Log.i(LOG_TAG, count + " lat " + lat + " long " + lon); } count++; } zoomToViewableObjects(markers); } }