Example usage for android.database Cursor moveToPosition

List of usage examples for android.database Cursor moveToPosition

Introduction

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

Prototype

boolean moveToPosition(int position);

Source Link

Document

Move the cursor to an absolute position.

Usage

From source file:com.monxalo.android.widget.SectionCursorAdapter.java

private void calculateSectionHeaders() {
    int i = 0;/*w  ww. ja  v  a 2  s.co m*/

    String previous = "";
    int count = 0;

    final Cursor c = getCursor();

    sectionsIndexer.clear();

    if (c == null) {
        return;
    }

    c.moveToPosition(-1);

    while (c.moveToNext()) {
        final String group = getCustomGroup(c.getString(mGroupColumn));

        if (!previous.equals(group)) {
            sectionsIndexer.put(i + count, group);
            previous = group;

            if (LOGV)
                Log.v(TAG, "Group " + group + "at position: " + (i + count));

            count++;
        }

        i++;
    }
}

From source file:com.jaspersoft.android.jaspermobile.activities.profile.fragment.ServersFragment.java

@Override
public void onPositiveButtonClicked(int position) {
    Cursor cursor = mAdapter.getCursor();
    cursor.moveToPosition(position);
    long id = cursor.getLong(cursor.getColumnIndex(ServerProfilesTable._ID));
    if (mServerProfileId == id) {
        Toast.makeText(getActivity(), "Can`t delete active profile", Toast.LENGTH_SHORT).show();
        return;/*from   ww w . j  a v a 2s.  c  om*/
    }
    Uri uri = Uri.withAppendedPath(JasperMobileDbProvider.SERVER_PROFILES_CONTENT_URI, String.valueOf(id));
    int deleteCount = getActivity().getContentResolver().delete(uri, null, null);
    if (deleteCount > 0) {
        Toast.makeText(getActivity(), R.string.spm_profile_deleted_toast, Toast.LENGTH_SHORT).show();
    }
    mAdapter.finishActionMode();
}

From source file:com.android.ex.chips.RecipientAlternatesAdapter.java

public RecipientEntry getRecipientEntry(int position) {
    Cursor c = getCursor();
    c.moveToPosition(position);

    String photoThumbnailUri;//ww w  .  j  a  v  a2 s.  co  m
    int displayNameSource;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        photoThumbnailUri = c.getString(Queries.Query.PHOTO_THUMBNAIL_URI);
        displayNameSource = c.getInt(Queries.Query.DISPLAY_NAME_SOURCE);
    } else {
        long photoId = c.getLong(Queries.Query.PHOTO_ID);
        Uri photoUri = ContentUris.withAppendedId(ContactsContract.Data.CONTENT_URI, photoId);
        photoThumbnailUri = photoUri.toString();
        displayNameSource = Query.DEFAULT_DISPLAY_NAME_SOURCE;
    }

    return RecipientEntry.constructTopLevelEntry(c.getString(Queries.Query.NAME), displayNameSource,
            c.getString(Queries.Query.DESTINATION), c.getInt(Queries.Query.DESTINATION_TYPE),
            c.getString(Queries.Query.DESTINATION_LABEL), c.getLong(Queries.Query.CONTACT_ID),
            c.getLong(Queries.Query.DATA_ID), photoThumbnailUri);
}

From source file:com.android.ex.chips.RecipientAlternatesAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    Cursor cursor = getCursor();
    cursor.moveToPosition(position);
    if (convertView == null) {
        convertView = newView();//from  w  w w.  jav  a2s.com
    }
    if (cursor.getLong(Queries.Query.DATA_ID) == mCurrentId) {
        mCheckedItemPosition = position;
        if (mCheckedItemChangedListener != null) {
            mCheckedItemChangedListener.onCheckedItemChanged(mCheckedItemPosition);
        }
    }
    bindView(convertView, convertView.getContext(), cursor);
    return convertView;
}

From source file:br.com.casadalagoa.vorf.BoatFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // The ArrayAdapter will take data from a source and
    // use it to populate the ListView it's attached to.
    mBoatAdapter = new BoatAdapter(getActivity(), null, 0);

    View rootView = inflater.inflate(R.layout.fragment_main, container, false);
    View descView = inflater.inflate(R.layout.list_item_description, container, false);
    // Get a reference to the ListView, and attach this adapter to it.
    mListView = (ListView) rootView.findViewById(R.id.listview_boats);
    mListView.addHeaderView(descView);/*w w  w. j av  a  2 s  . c  o  m*/
    mListView.setAdapter(mBoatAdapter);
    mBoatAdapter.setUseTodayLayout(false);
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            Context mContext = getActivity().getBaseContext();
            if (position == 0) {
                String show = Utility.getNextEventShow(mContext) ? "false" : "true";
                switch (Utility.getNextEventIdx(mContext)) {
                case 0:
                    Utility.setNextEventShow(mContext, show);
                    Utility.setNextEventTimeInUse(mContext, Utility.getNextEventTime(mContext));
                    Utility.setNextEventTitleInUse(mContext, Utility.getNextEventTitle(mContext));
                    break;
                case 1:
                    Utility.setNextEventTimeInUse(mContext, Utility.getNextUpdateLong(mContext));
                    Utility.setNextEventTitleInUse(mContext, "NxtUpdate");
                    break;
                case 2:
                    Utility.setNextEventShow(mContext, show);
                    break;
                }
                Log.v("SetCrono: ",
                        show + " " + Utility.getNextEventTimeInUse(mContext)
                                + Utility.getNextEventTitleInUse(mContext)
                                + String.valueOf(Utility.getNextEventIdx(mContext)));
                Utility.setNextEventTimeIdx(mContext);
            } else {
                Cursor cursor = mBoatAdapter.getCursor();
                if (cursor != null && cursor.moveToPosition(position - 1)) {
                    ((Callback) getActivity()).onItemSelected(cursor.getString(COL_BOAT_ID));
                    Utility.setPreferredBoat(mContext, cursor.getString(COL_BOAT_CODE));
                }
            }
            updateBoat();
            mPosition = position;
        }
    });

    // If there's instance state, mine it for useful information.
    // The end-goal here is that the user never knows that turning their device sideways
    // does crazy lifecycle related things.  It should feel like some stuff stretched out,
    // or magically appeared to take advantage of room, but data or place in the app was never
    // actually *lost*.
    if (savedInstanceState != null && savedInstanceState.containsKey(SELECTED_KEY)) {
        // The listview probably hasn't even been populated yet.  Actually perform the
        // swapout in onLoadFinished.
        mPosition = savedInstanceState.getInt(SELECTED_KEY);
    }

    //mBoatAdapter.setUseTodayLayout(mUseTodayLayout);

    return rootView;
}

From source file:net.daverix.urlforward.FiltersFragment.java

private List<FilterRowViewModel> mapListFilters(Cursor cursor) {
    if (cursor == null)
        throw new IllegalArgumentException("cursor is null");

    List<FilterRowViewModel> items = new ArrayList<FilterRowViewModel>(cursor.getCount());

    for (int i = 0; cursor.moveToPosition(i); i++) {
        items.add(/*from   w  ww. j  ava2  s  . c  o  m*/
                new FilterRowViewModel(mListener, cursor.getString(1), cursor.getString(2), cursor.getLong(0)));
    }

    return items;
}

From source file:com.armtimes.drawer.CommonFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    // Get current selected item.
    Cursor cursor = ((FragmentAdapter) l.getAdapter()).getCursor();
    cursor.moveToPosition(position);
    // Create new intent to send to News Reader Activity.
    Intent intent = new Intent(getActivity(), SingleArticlePreviewActivity.class);
    intent.putExtra(SingleArticlePreviewActivity.EXTRA_CATEGORY_TITLE_ID, mCategoryTitleId);
    intent.putExtra(SingleArticlePreviewActivity.EXTRA_TITLE,
            cursor.getString(cursor.getColumnIndexOrThrow(NewsContract.COL_NAME_NEWS_TITLE)));
    intent.putExtra(SingleArticlePreviewActivity.EXTRA_DESCRIPTION,
            cursor.getString(cursor.getColumnIndexOrThrow(NewsContract.COL_NAME_NEWS_DESC_LONG)));
    intent.putExtra(SingleArticlePreviewActivity.EXTRA_URL,
            cursor.getString(cursor.getColumnIndexOrThrow(NewsContract.COL_NAME_NEWS_URL)));
    intent.putExtra(SingleArticlePreviewActivity.EXTRA_IMAGE_PATH,
            cursor.getString(cursor.getColumnIndexOrThrow(NewsContract.COL_NAME_NEWS_MAIN_IMAGE_PATH)));
    intent.putExtra(SingleArticlePreviewActivity.EXTRA_IMAGE_LINK,
            cursor.getString(cursor.getColumnIndexOrThrow(NewsContract.COL_NAME_NEWS_IMAGE_URL)));
    intent.putExtra(SingleArticlePreviewActivity.EXTRA_SHORT_DESC,
            cursor.getString(cursor.getColumnIndexOrThrow(NewsContract.COL_NAME_NEWS_DESC_SHORT)));
    intent.putExtra(SingleArticlePreviewActivity.EXTRA_CATEGORY, mCategory);

    // Start News Reader Activity.
    startActivityForResult(intent, 0);//from   w w w  .  j a  v a 2  s  .  c om
}

From source file:com.google.android.apps.gutenberg.TimelineFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    switch (loader.getId()) {
    case LOADER_ATTENDEES:
        mAdapter.removeAttendees();/*from   w  ww  .  ja va  2 s  .  c o  m*/
        cursor.moveToPosition(-1);
        while (cursor.moveToNext()) {
            mAdapter.add(new Checkin(cursor));
        }
        mAdapter.notifyDataSetChanged();
        break;
    case LOADER_EVENT:
        if (cursor.moveToFirst()) {
            mRecyclerView.setVisibility(View.VISIBLE);
            mEmptyView.setVisibility(View.GONE);
            mAdapter.removeExplanations();
            mAdapter.add(new Explanation(cursor));
            mAdapter.notifyDataSetChanged();
        } else {
            mRecyclerView.setVisibility(View.GONE);
            mEmptyView.setVisibility(View.VISIBLE);
        }
        break;
    }
}

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

@Override
public Post getPostFromCursor(Host host, Cursor post_cursor, Cursor tags_cursor) {
    String[] tags;/*from  w ww.j  a  v  a2  s.  com*/
    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 ShimmiePost(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:com.cw.litenote.operation.delete.DeleteFolders.java

/**
 * Do delete folders/*from   w w  w  . j a  v a 2  s.  com*/
 */
void doDeleteFolders() {
    DB_drawer dbDrawer = new DB_drawer(act);

    // drawer DB check
    boolean doDB_check = true;
    if (doDB_check) {
        dbDrawer.open();
        for (int i = 0; i < list_selFolder.count; i++) {
            int folderTableId = dbDrawer.getFolderTableId(i, false);
            System.out.println("DeleteFolders / folderTableId = " + folderTableId);

            int folderId = (int) dbDrawer.getFolderId(i, false);
            System.out.println("DeleteFolders / folderId = " + folderId);
        }
        dbDrawer.close();
    }

    dbDrawer.open();
    for (int i = 0; i < list_selFolder.count; i++) {
        if (list_selFolder.mCheckedArr.get(i)) {
            // get folder table id
            int folderTableId = dbDrawer.getFolderTableId(i, false);

            // 1) delete related page tables
            DB_folder dbFolder = new DB_folder(act, folderTableId);
            int pgsCnt = dbFolder.getPagesCount(true);
            for (int j = 0; j < pgsCnt; j++) {
                int pageTableId = dbFolder.getPageTableId(j, true);
                dbFolder.dropPageTable(folderTableId, pageTableId);
            }

            // 2) delete folder table
            dbDrawer.dropFolderTable(folderTableId, false);

            // 3) delete folder Id
            int folderId = (int) dbDrawer.getFolderId(i, false);
            dbDrawer.deleteFolderId(folderId, false);

            // change focus
            FolderUi.setFocus_folderPos(0);
        }
    }
    dbDrawer.close();

    // check if only one folder left
    int foldersCnt = dbDrawer.getFoldersCount(true);

    // set focus folder table Id
    dbDrawer.open();
    if (foldersCnt > 0) {
        int newFirstFolderTblId = 0;
        int i = 0;
        Cursor folderCursor = dbDrawer.getFolderCursor();
        while (i < foldersCnt) {
            folderCursor.moveToPosition(i);
            if (folderCursor.isFirst())
                newFirstFolderTblId = dbDrawer.getFolderTableId(i, false);
            i++;
        }
        Pref.setPref_focusView_folder_tableId(act, newFirstFolderTblId);
    } else if (foldersCnt == 0)
        Pref.setPref_focusView_folder_tableId(act, 1);
    dbDrawer.close();

    // set scroll X
    //        int scrollX = 0; //over the last scroll X
    //        Pref.setPref_focusView_scrollX_byFolderTableId(act, scrollX );

    if (BackgroundAudioService.mMediaPlayer != null) {
        Audio_manager.stopAudioPlayer();
        Audio_manager.mAudioPos = 0;
        Audio_manager.setPlayerState(Audio_manager.PLAYER_AT_STOP);
    }

    list_selFolder = new List_selectFolder(act, rootView, mListView);
}