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.money.manager.ex.investment.watchlist.WatchlistItemsFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;

    // ignore the header row if the headers are shown.
    if (hasHeaderRow() && info.position == 0)
        return;/*  ww w.  j  ava 2 s .c  o m*/

    Cursor cursor = ((StocksCursorAdapter) getListAdapter()).getCursor();

    int cursorPosition = hasHeaderRow() ? info.position - 1 : info.position;
    cursor.moveToPosition(cursorPosition);

    menu.setHeaderTitle(cursor.getString(cursor.getColumnIndex(StockFields.SYMBOL)));

    MenuHelper menuHelper = new MenuHelper(getActivity(), menu);
    menuHelper.addToContextMenu(ContextMenuIds.DownloadPrice);
    menuHelper.addToContextMenu(ContextMenuIds.EditPrice);
    menuHelper.addToContextMenu(ContextMenuIds.DELETE);
}

From source file:com.nicolls.ablum.fragment.ImageFragment.java

private void setAdapter(Cursor imagecursor) {
    //      Toast.makeText(getActivity(),pathList.size()+"###",Toast.LENGTH_SHORT).show();

    if (imagecursor.getCount() > 0) {

        mGalleryModelList = new ArrayList<MediaModel>();

        for (int i = 0; i < imagecursor.getCount(); i++) {
            imagecursor.moveToPosition(i);
            int dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.DATA);
            MediaModel galleryModel = new MediaModel(imagecursor.getString(dataColumnIndex).toString(), false);
            for (String path : pathList) {
                if (TextUtils.equals(path, galleryModel.url)) {
                    galleryModel.status = true;
                    mSelectedItems.add(galleryModel.url.toString());
                    break;
                }/*  ww w.  j a va2s.  c  o m*/
            }

            mGalleryModelList.add(galleryModel);
        }

        mImageAdapter = new GridViewAdapter(getActivity(), 0, mGalleryModelList, false);
        mImageGridView.setAdapter(mImageAdapter);
    } else {
        Toast.makeText(getActivity(), getActivity().getString(R.string.no_media_file_available),
                Toast.LENGTH_SHORT).show();
    }

    mImageGridView.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter();
            MediaModel galleryModel = (MediaModel) adapter.getItem(position);
            File file = new File(galleryModel.url);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.fromFile(file), "image/*");
            startActivity(intent);
            return true;
        }
    });

    mImageGridView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // update the mStatus of each category in the adapter
            GridViewAdapter adapter = (GridViewAdapter) parent.getAdapter();
            MediaModel galleryModel = (MediaModel) adapter.getItem(position);

            if (!galleryModel.status) {
                long size = MediaChooserConstants.ChekcMediaFileSize(new File(galleryModel.url.toString()),
                        false);
                if (size != 0) {
                    Toast.makeText(getActivity(),
                            getActivity().getResources().getString(R.string.file_size_exeeded) + "  "
                                    + MediaChooserConstants.SELECTED_IMAGE_SIZE_IN_MB + " "
                                    + getActivity().getResources().getString(R.string.mb),
                            Toast.LENGTH_SHORT).show();
                    return;
                }

                if ((MediaChooserConstants.MAX_MEDIA_LIMIT == MediaChooserConstants.SELECTED_MEDIA_COUNT)) {
                    if (MediaChooserConstants.SELECTED_MEDIA_COUNT < 2) {
                        Toast.makeText(getActivity(),
                                getActivity().getResources().getString(R.string.max_limit_file) + "  "
                                        + MediaChooserConstants.SELECTED_MEDIA_COUNT + " "
                                        + getActivity().getResources().getString(R.string.file),
                                Toast.LENGTH_SHORT).show();
                        return;
                    } else {
                        Toast.makeText(getActivity(),
                                getActivity().getResources().getString(R.string.max_limit_file) + "  "
                                        + MediaChooserConstants.SELECTED_MEDIA_COUNT + " "
                                        + getActivity().getResources().getString(R.string.files),
                                Toast.LENGTH_SHORT).show();
                        return;
                    }

                }
            }

            // inverse the status
            galleryModel.status = !galleryModel.status;

            adapter.notifyDataSetChanged();

            if (galleryModel.status) {
                mSelectedItems.add(galleryModel.url.toString());
                MediaChooserConstants.SELECTED_MEDIA_COUNT++;

            } else {
                mSelectedItems.remove(galleryModel.url.toString().trim());
                MediaChooserConstants.SELECTED_MEDIA_COUNT--;
            }

            if (mCallback != null) {
                mCallback.onImageSelected(mSelectedItems.size());
                Intent intent = new Intent();
                intent.putStringArrayListExtra("list", mSelectedItems);
                getActivity().setResult(Activity.RESULT_OK, intent);
            }

        }
    });
}

From source file:org.sufficientlysecure.keychain.ui.adapter.ViewKeyUserIdsAdapter.java

@Override
public Cursor swapCursor(Cursor newCursor) {
    initIndex(newCursor);//ww w .  j a v  a 2  s.  co m
    if (mCheckStates != null) {
        mCheckStates.clear();
        if (newCursor != null) {
            int count = newCursor.getCount();
            mCheckStates.ensureCapacity(count);
            // initialize to true (use case knowledge: we usually want to sign all uids)
            for (int i = 0; i < count; i++) {
                newCursor.moveToPosition(i);
                int verified = newCursor.getInt(mVerifiedId);
                mCheckStates.add(verified != Certs.VERIFIED_SECRET);
            }
        }
    }

    return super.swapCursor(newCursor);
}

From source file:tw.idv.palatis.danboorugallery.PostDetailActivity.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    if (mPosition != -1) {
        // tries to find the position in the new cursor
        Cursor oldCursor = mPagerAdapter.getCursor(mPosition);
        if (oldCursor != null) {
            int post_id = oldCursor.getInt(PostsTable.INDEX_POST_POST_ID);
            cursor.moveToPosition(-1);
            while (cursor.moveToNext())
                if (cursor.getInt(PostsTable.INDEX_POST_POST_ID) == post_id) {
                    mPosition = cursor.getPosition();
                    break;
                }/*from  w  w  w. j av a  2 s . c o  m*/
        }
    }

    mPagerAdapter.swapCursor(cursor);
    mViewPager.setCurrentItem(mPosition, false);
    cursor.moveToPosition(mPosition);
    Host host = SiteSession.getHostById(cursor.getInt(PostsTable.INDEX_POST_HOST_ID));
    Post post = Post.fromCursor(host, cursor, null);
    mInfoText.setText(post.describeContent(PostDetailActivity.this));
}

From source file:org.getlantern.firetweet.fragment.CustomTabsFragment.java

private void saveTabPositions() {
    final ArrayList<Integer> positions = mAdapter.getCursorPositions();
    final Cursor c = mAdapter.getCursor();
    if (positions != null && c != null && !c.isClosed()) {
        final int idIdx = c.getColumnIndex(Tabs._ID);
        for (int i = 0, j = positions.size(); i < j; i++) {
            c.moveToPosition(positions.get(i));
            final long id = c.getLong(idIdx);
            final ContentValues values = new ContentValues();
            values.put(Tabs.POSITION, i);
            final String where = Expression.equals(Tabs._ID, id).getSQL();
            mResolver.update(Tabs.CONTENT_URI, values, where, null);
        }//from w w  w.  j  a va  2s .com
    }
    SettingsActivity.setShouldNotifyChange(getActivity());
}

From source file:eu.inmite.apps.smsjizdenka.adapter.TicketsAdapter.java

@Override
public long getItemId(int position) {
    Cursor cursor = getCursor();
    if (cursor == null) {
        return -1;
    }// ww  w  .ja  va2 s .co m
    try {
        boolean success = cursor.moveToPosition(position);
        if (!success) {
            return -1;
        }
    } catch (IllegalStateException e) {
        return -1;
    }
    return cursor.getLong(iId);
}

From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.FavouriteStopsFragment.java

/**
 * {@inheritDoc}/*from  w w w  .  j  av a2 s. co  m*/
 */
@Override
public void onClick(final View v) {
    final int position = getListView().getPositionForView(v);
    if (position != AdapterView.INVALID_POSITION) {
        final Cursor c = ca.getCursor();
        if (c != null && c.moveToPosition(position)) {
            callbacks.onShowConfirmFavouriteDeletion(c.getString(0));
        }
    }
}

From source file:com.kaliturin.blacklist.adapters.ContactsCursorAdapter.java

public List<Contact> extractCheckedContacts() {
    List<Contact> list = new LinkedList<>();
    Cursor cursor = getCursor();
    if (cursor != null) {
        int position = cursor.getPosition();
        cursor.moveToFirst();//  www  .  j  av  a2 s  .c o m
        do {
            Contact contact = ((ContactSource) cursor).getContact();
            if (checkedItems.contains((int) contact.id)) {
                list.add(contact);
            }
        } while (cursor.moveToNext());
        cursor.moveToPosition(position);
    }
    return list;
}

From source file:mobisocial.musubi.ImageGalleryActivity.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    if (mAdapter == null) {
        int init = binarySearch(cursor, mInitialObjId, 0);
        cursor.moveToPosition(-1);
        mAdapter = new ImageGalleryAdapter(this, cursor, init);
        mGallery.setAdapter(mAdapter);//from ww  w.  ja v a  2 s.c  o  m
        mGallery.setSelection((mInitialSelection == -1) ? mAdapter.getInitialSelection() : mInitialSelection);
    } else {
        mAdapter.changeCursor(cursor);
    }
}

From source file:com.cuddlesoft.nori.SearchActivity.java

/**
 * Set up the action bar SearchView and its event handlers.
 *
 * @param menu Menu after being inflated in {@link #onCreateOptionsMenu(android.view.Menu)}.
 *//*  ww w  .j  a  v  a 2 s  .  c o  m*/
private void setUpSearchView(Menu menu) {
    // Extract SearchView from the MenuItem object.
    searchMenuItem = menu.findItem(R.id.action_search);
    searchMenuItem.setVisible(searchClientSettings != null);
    searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);

    // Set Searchable XML configuration.
    SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    // Set SearchView attributes.
    searchView.setFocusable(false);
    searchView.setQueryRefinementEnabled(true);

    // Set SearchView event listeners.
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            if (searchClientSettings != null) {
                // Prepare a intent to send to a new instance of this activity.
                Intent intent = new Intent(SearchActivity.this, SearchActivity.class);
                intent.setAction(Intent.ACTION_SEARCH);
                intent.putExtra(BUNDLE_ID_SEARCH_CLIENT_SETTINGS, searchClientSettings);
                intent.putExtra(BUNDLE_ID_SEARCH_QUERY, query);

                // Collapse the ActionView. This makes navigating through previous results using the back key less painful.
                MenuItemCompat.collapseActionView(searchMenuItem);

                // Start a new activity with the created Intent.
                startActivity(intent);
            }

            // Returns true to override the default behaviour and stop another search Intent from being sent.
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            // Returns false to perform the default action.
            return false;
        }
    });
    searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() {
        @Override
        public boolean onSuggestionSelect(int position) {
            return onSuggestionClick(position);
        }

        @Override
        public boolean onSuggestionClick(int position) {
            if (searchClientSettings != null) {
                // Get the SearchView's suggestion adapter.
                CursorAdapter adapter = searchView.getSuggestionsAdapter();
                // Get the suggestion at given position.
                Cursor c = adapter.getCursor();
                c.moveToPosition(position);

                // Create and send a search intent.
                Intent intent = new Intent(SearchActivity.this, SearchActivity.class);
                intent.setAction(Intent.ACTION_SEARCH);
                intent.putExtra(BUNDLE_ID_SEARCH_CLIENT_SETTINGS, searchClientSettings);
                intent.putExtra(BUNDLE_ID_SEARCH_QUERY,
                        c.getString(c.getColumnIndex(SearchSuggestionDatabase.COLUMN_NAME)));
                startActivity(intent);

                // Release native resources.
                c.close();
            }

            // Return true to override default behaviour and prevent another intent from being sent.
            return true;
        }
    });

    if (savedInstanceState != null) {
        // Restore state from saved instance state bundle (after screen rotation, app restored from background, etc.)
        if (savedInstanceState.containsKey(BUNDLE_ID_SEARCH_QUERY)) {
            // Restore search query from saved instance state.
            searchView.setQuery(savedInstanceState.getCharSequence(BUNDLE_ID_SEARCH_QUERY), false);
        }
        // Restore iconified/expanded search view state from saved instance state.
        if (savedInstanceState.getBoolean(BUNDLE_ID_SEARCH_VIEW_IS_EXPANDED, false)) {
            MenuItemCompat.expandActionView(searchMenuItem);
            // Restore focus state.
            if (!savedInstanceState.getBoolean(BUNDLE_ID_SEARCH_VIEW_IS_FOCUSED, false)) {
                searchView.clearFocus();
            }
        }
    } else if (getIntent() != null && getIntent().getAction().equals(Intent.ACTION_SEARCH)) {
        // Set SearchView query string to match the one sent in the SearchIntent.
        searchView.setQuery(getIntent().getStringExtra(BUNDLE_ID_SEARCH_QUERY), false);
    }
}