Example usage for android.database Cursor getPosition

List of usage examples for android.database Cursor getPosition

Introduction

In this page you can find the example usage for android.database Cursor getPosition.

Prototype

int getPosition();

Source Link

Document

Returns the current position of the cursor in the row set.

Usage

From source file:ca.rmen.android.poetassistant.main.dictionaries.search.Search.java

private String[] getSearchHistory() {
    Cursor cursor = mContext.getContentResolver().query(SuggestionsProvider.CONTENT_URI, null, null, null,
            null);/*from   w ww. j  av a 2  s .co m*/
    if (cursor != null) {
        try {
            String[] result = new String[cursor.getCount()];
            int columnIndex = cursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_1);
            while (cursor.moveToNext()) {
                result[cursor.getPosition()] = cursor.getString(columnIndex);
            }
            return result;
        } finally {
            cursor.close();
        }
    }
    return new String[0];
}

From source file:tw.idv.palatis.danboorugallery.siteapi.DanbooruAPI.java

@Override
public Post getPostFromCursor(Host host, Cursor post_cursor, Cursor tags_cursor) {
    String[] tags;//ww  w.j  a  va2s .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 DanbooruPost(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:info.guardianproject.otr.app.im.app.AddContactActivity.java

private int searchInitListPos(Cursor c, String listName) {
    if (TextUtils.isEmpty(listName)) {
        return 0;
    }//from   w  ww. j av a2  s  . co m
    c.moveToPosition(-1);
    while (c.moveToNext()) {
        if (listName.equals(c.getString(CONTACT_LIST_NAME_COLUMN))) {
            return c.getPosition();
        }
    }
    return 0;
}

From source file:com.kyakujin.android.tagnotepad.ui.TagDialogListFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    switch (loader.getId()) {
    case TagsQuery.LOADER_ID:
        mTagListAdapter.swapCursor(data);
        //setCheck();
        mManager.restartLoader(MappingQuery.LOADER_ID, null, this);
        break;//w w  w . j  a  v  a 2s. c om

    case MappingQuery.LOADER_ID:
        // ????????????ON??
        if (data.getCount() != 0) {
            Cursor tCur;
            for (int i = 0; i < mTagListView.getCount(); i++) {
                tCur = (Cursor) mTagListView.getItemAtPosition(i);
                data.moveToFirst();
                do {
                    if (tCur.getInt(TagsQuery.TAGS_ID) == data.getInt(MappingQuery.TAGID)) {
                        mTagListView.setItemChecked(tCur.getPosition(), true);
                    }
                } while (data.moveToNext());
            }
        }
        break;
    default:
        break;
    }
}

From source file:com.android.email.provider.EmailMessageCursor.java

public EmailMessageCursor(final Context c, final Cursor cursor, final String htmlColumn,
        final String textColumn) {
    super(cursor);
    mHtmlColumnIndex = cursor.getColumnIndex(htmlColumn);
    mTextColumnIndex = cursor.getColumnIndex(textColumn);
    final int cursorSize = cursor.getCount();
    mHtmlParts = new SparseArray<String>(cursorSize);
    mTextParts = new SparseArray<String>(cursorSize);

    final ContentResolver cr = c.getContentResolver();

    while (cursor.moveToNext()) {
        final int position = cursor.getPosition();
        final long messageId = cursor.getLong(cursor.getColumnIndex(BaseColumns._ID));
        try {/*  w w w.  j a v a2  s.c o  m*/
            if (mHtmlColumnIndex != -1) {
                final Uri htmlUri = Body.getBodyHtmlUriForMessageWithId(messageId);
                final InputStream in = cr.openInputStream(htmlUri);
                final String underlyingHtmlString;
                try {
                    underlyingHtmlString = IOUtils.toString(in);
                } finally {
                    in.close();
                }
                final String sanitizedHtml = HtmlSanitizer.sanitizeHtml(underlyingHtmlString);
                mHtmlParts.put(position, sanitizedHtml);
            }
        } catch (final IOException e) {
            LogUtils.v(LogUtils.TAG, e, "Did not find html body for message %d", messageId);
        }
        try {
            if (mTextColumnIndex != -1) {
                final Uri textUri = Body.getBodyTextUriForMessageWithId(messageId);
                final InputStream in = cr.openInputStream(textUri);
                final String underlyingTextString;
                try {
                    underlyingTextString = IOUtils.toString(in);
                } finally {
                    in.close();
                }
                mTextParts.put(position, underlyingTextString);
            }
        } catch (final IOException e) {
            LogUtils.v(LogUtils.TAG, e, "Did not find text body for message %d", messageId);
        }
    }
    cursor.moveToPosition(-1);
}

From source file:com.aboveware.sms.ui.MessageListAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    if (view instanceof MessageListItem) {
        String type = cursor.getString(ConversationsDatabase.messageTypeIndex);
        long msgId = cursor.getLong(ConversationsDatabase.messageIdIndex);

        MessageItem msgItem = getCachedMessageItem(type, msgId, cursor);
        if (msgItem != null) {
            MessageListItem mli = (MessageListItem) view;
            int position = cursor.getPosition();
            mli.bind(msgItem, mIsGroupConversation, position);
            mli.setMsgListItemHandler(mMsgListItemHandler);
        }/*from w w  w . j  av a2 s .  co  m*/
    }
}

From source file:com.dwdesign.tweetings.adapter.CursorStatusesAdapter.java

@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
    final int position = cursor.getPosition();
    StatusViewHolder holder = (StatusViewHolder) view.getTag();

    // Clear images in prder to prevent images in recycled view shown.
    holder.profile_image.setImageDrawable(null);
    holder.image_preview.setImageDrawable(null);

    final boolean is_gap = cursor.getShort(mIndices.is_gap) == 1;

    final boolean show_gap = is_gap && !mGapDisallowed;

    holder.setShowAsGap(show_gap);/* w  ww  .j  a  va  2 s . c  o  m*/

    final long account_id = cursor.getLong(mIndices.account_id);

    holder.setAccountColorEnabled(mShowAccountColor);

    if (mShowAccountColor) {
        holder.setAccountColor(getAccountColor(mContext, account_id));
    }

    if (!show_gap) {

        final String retweeted_by = mDisplayName ? cursor.getString(mIndices.retweeted_by_name)
                : cursor.getString(mIndices.retweeted_by_screen_name);
        final String text = cursor.getString(mIndices.text);
        final String screen_name = cursor.getString(mIndices.screen_name);
        final String display_name = mDisplayName ? cursor.getString(mIndices.name) : 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 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 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 = !isNullOrEmpty(cursor.getString(mIndices.location));
        final boolean is_retweet = !isNullOrEmpty(retweeted_by) && cursor.getShort(mIndices.is_retweet) == 1;
        final boolean is_reply = !isNullOrEmpty(in_reply_to_screen_name)
                && cursor.getLong(mIndices.in_reply_to_status_id) > 0;

        if (mMultiSelectEnabled) {
            holder.setSelected(mSelectedStatusIds.contains(status_id));
        } else {
            holder.setSelected(false);
        }

        if (!mFastProcessingEnabled) {
            boolean is_mine = false;
            if (account_id > 0 && screen_name != null && mContext != null
                    && getAccountUsername(mContext, account_id) != null
                    && getAccountUsername(mContext, account_id).equals(screen_name)) {
                is_mine = true;
            }
            holder.setUserColor(getUserColor(mContext, user_id));
            if (text != null) {
                holder.setHighlightColor(
                        getStatusBackground(
                                mMentionsHighlightDisabled ? false
                                        : text.toLowerCase().contains(
                                                '@' + getAccountUsername(mContext, account_id).toLowerCase()),
                                is_favorite, is_retweet, is_mine));
            }
        } else {
            holder.setUserColor(Color.TRANSPARENT);
            holder.setHighlightColor(Color.TRANSPARENT);
        }

        final PreviewImage preview = getPreviewImage(text, mInlineImagePreviewDisplayOption);
        //final PreviewImage preview = !mFastProcessingEnabled || mDisplayImagePreview ? getPreviewImage(text,
        //mDisplayImagePreview) : null;
        final boolean has_media = preview != null ? preview.has_image : false;

        holder.setTextSize(mTextSize);

        if (mShowLinks) {
            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(unescape(text));
        }
        holder.text.setMovementMethod(null);

        /*if (mShowLinks) {
           holder.text.setText(TwidereLinkify.twitterifyText(account_id, mContext, text));
           holder.text.setMovementMethod(LinkMovementMethod.getInstance());
           holder.text.setLinksClickable(false);
           holder.text.setTag(position);
           holder.text.setOnClickListener(this);
           holder.text.setOnLongClickListener(this);
        }
        else {
           holder.text.setText(unescape(text));
        }*/

        //holder.name.setCompoundDrawablesWithIntrinsicBounds(getUserTypeIconRes(is_verified, is_protected), 0, 0, 0);
        if (mDisplayNameBoth) {
            holder.name.setText(name);
            if (holder.name2 != null) {
                holder.name2.setText("@" + screen_name);
            }
        } else {
            holder.name.setText(display_name);
        }
        if (holder.name2 != null) {
            holder.name2.setVisibility(mDisplayNameBoth ? View.VISIBLE : View.GONE);
        }

        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) {
            holder.reply_retweet_status.setText(retweet_count > 1
                    ? mContext.getString(R.string.retweeted_by_with_count, retweeted_by, retweet_count - 1)
                    : mContext.getString(R.string.retweeted_by, retweeted_by));
            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);
        }
        holder.profile_image.setVisibility(mDisplayProfileImage ? View.VISIBLE : View.GONE);
        if (mDisplayProfileImage) {
            final String profile_image_url_string = cursor.getString(mIndices.profile_image_url);
            if (mDisplayHiResProfileImage) {
                mLazyImageLoader.displayProfileImage(holder.profile_image,
                        getBiggerTwitterProfileImage(profile_image_url_string));
            } else {
                mLazyImageLoader.displayProfileImage(holder.profile_image, profile_image_url_string);
            }
            holder.profile_image.setTag(position);
        }
        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
                    || mInlineImagePreviewDisplayOption == INLINE_IMAGE_PREVIEW_DISPLAY_OPTION_CODE_LARGE_HIGH) {
                lp.width = LayoutParams.MATCH_PARENT;
                lp.leftMargin = 0;
                holder.image_preview_frame.setLayoutParams(lp);
            } else if (mInlineImagePreviewDisplayOption == INLINE_IMAGE_PREVIEW_DISPLAY_OPTION_CODE_SMALL) {
                final Resources res = mContext.getResources();
                lp.width = res.getDimensionPixelSize(R.dimen.image_preview_width);
                lp.leftMargin = (int) (mDensity * 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 {
                mLazyImageLoader.displayPreviewImage(holder.image_preview, preview.matched_url);
            }
            holder.image_preview_frame.setTag(position);
        }
    }

    super.bindView(view, context, cursor);
}

From source file:com.enadein.carlogbook.core.DataLoader.java

protected int getPosition(Cursor c, long id) {
    if (c == null || c.getCount() == 0) {
        return 0;
    }//from   ww  w  . j  ava2 s  .  co  m

    int position = 0;
    while (c.moveToNext()) {
        long currentId = c.getLong(0);
        if (currentId == id) {
            position = c.getPosition();
            break;
        }
    }
    return position;
}

From source file:eu.iescities.pilot.rovereto.roveretoexplorer.custom.data.DTHelper.java

public static List<String> getAllPOITitles() {

    Cursor cursor = null;
    try {//from   ww  w .ja va2 s . c  o m
        cursor = getInstance().storage.rawQuery("select title from pois", null);
        if (cursor != null) {
            List<String> result = new ArrayList<String>();
            cursor.moveToFirst();
            int i = 0;
            while (cursor.getPosition() < cursor.getCount()) {
                String v = cursor.getString(0);
                if (v != null && v.trim().length() > 0) {
                    result.add(v.trim());
                }
                cursor.moveToNext();
                i++;
            }
            return result;
        }
    } catch (Exception e) {
        Log.e(DTHelper.class.getName(), "" + e.getMessage());
    } finally {
        try {
            getInstance().storage.cleanCursor(cursor);
        } catch (DataException e) {
        }
    }
    return Collections.emptyList();
}