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:com.enadein.carlogbook.adapter.CarAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    CarHolder setsHolder = (CarHolder) view.getTag();

    int idIdx = cursor.getColumnIndex(ProviderDescriptor.Car.Cols._ID);
    int nameIdx = cursor.getColumnIndex(ProviderDescriptor.Car.Cols.NAME);
    int activeFlagIdx = cursor.getColumnIndex(ProviderDescriptor.Car.Cols.ACTIVE_FLAG);

    String name = cursor.getString(nameIdx);
    int id = cursor.getInt(idIdx);
    boolean active = cursor.getInt(activeFlagIdx) > 0;

    setsHolder.activeView.setVisibility(active ? View.VISIBLE : View.INVISIBLE);

    setsHolder.nameView.setText(name);//ww  w  .  jav a  2s .  c  o m
    setsHolder.id = id;

    int pos = cursor.getPosition();
    CommonUtils.runAnimation(mlastPos, pos, view, UnitFacade.animSize);
    mlastPos = pos;
}

From source file:xyz.jc.zeus.moviesguide.MainActivity.java

@Override
public Loader<String[][]> onCreateLoader(int id, Bundle args) {
    return new AsyncTaskLoader<String[][]>(this) {
        String[][] moviesInfo = null;

        @Override//  ww w. j av a2 s .  c  o  m
        protected void onStartLoading() {
            if (moviesInfo != null) {
                deliverResult(moviesInfo);
            } else {
                mLoadingIndicator.setVisibility(View.VISIBLE);
                forceLoad();
            }
        }

        @Override
        public String[][] loadInBackground() {
            String category = sortBy;
            URL[] movieDbRequestUrl = NetworkUtils.buildUrl(category);
            List<String[]> tempMovieInfo = new ArrayList<>();
            try {
                if (!sortBy.equals(getString(R.string.pref_sort_favourite))) {
                    //Iterating through the array of URL received from NetworkUtils.buildUrl()
                    for (URL aMovieDbRequestUrl : movieDbRequestUrl) {
                        String jsonMovieDbResponse = NetworkUtils.getResponseFromHttpUrl(aMovieDbRequestUrl);
                        String[][] tmpMInfo = MovieDBJsonUtils.getMoviesInfoStringsFromJson(MainActivity.this,
                                jsonMovieDbResponse);
                        if (tmpMInfo != null) {
                            Collections.addAll(tempMovieInfo, tmpMInfo);
                        }
                    }
                } else {
                    ContentResolver resolver = getContentResolver();
                    Cursor cursor = resolver.query(MovieProvider.Movies.CONTENT_URI, null, null, null, null);
                    if (cursor != null && cursor.getCount() > 0) {
                        String[][] tmpMInfo = new String[cursor.getCount()][6];
                        cursor.moveToFirst();
                        while (!cursor.isAfterLast()) {
                            tmpMInfo[cursor.getPosition()][0] = cursor
                                    .getString(cursor.getColumnIndex(MovieColumns.ID));
                            tmpMInfo[cursor.getPosition()][1] = cursor
                                    .getString(cursor.getColumnIndex(MovieColumns.ORIGINAL_TITLE));
                            tmpMInfo[cursor.getPosition()][2] = cursor
                                    .getString(cursor.getColumnIndex(MovieColumns.POSTER_PATH));
                            tmpMInfo[cursor.getPosition()][3] = cursor
                                    .getString(cursor.getColumnIndex(MovieColumns.MOVIES_OVERVIEW));
                            tmpMInfo[cursor.getPosition()][4] = cursor
                                    .getString(cursor.getColumnIndex(MovieColumns.RELEASE_DATE));
                            tmpMInfo[cursor.getPosition()][5] = cursor
                                    .getString(cursor.getColumnIndex(MovieColumns.USER_RATING));
                            cursor.moveToNext();
                        }
                        cursor.close();
                        Collections.addAll(tempMovieInfo, tmpMInfo);
                    }
                }
                moviesInfo = new String[tempMovieInfo.size()][];
                moviesInfo = tempMovieInfo.toArray(moviesInfo);
                return moviesInfo;
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }

        public void deliverResult(String[][] data) {
            moviesInfo = data;
            super.deliverResult(data);
        }
    };
}

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

@Override
public void bindView(View view, Context context, Cursor cursor) {
    // get cursor wrapper
    JournalRecordCursorWrapper cursorWrapper = (JournalRecordCursorWrapper) cursor;
    // get journal item
    JournalRecord record = cursorWrapper.getJournalRecord();
    // get view holder from the row
    ViewHolder viewHolder = (ViewHolder) view.getTag();

    // get previous record time
    long previousRecordTime = cursorWrapper.getTime(cursor.getPosition() - 1);
    // define date format of showing record
    calendar.setTimeInMillis(previousRecordTime);
    int lastRecordDay = calendar.get(Calendar.DAY_OF_YEAR);
    int lastRecordYear = calendar.get(Calendar.YEAR);
    calendar.setTimeInMillis(record.time);
    int currentRecordDay = calendar.get(Calendar.DAY_OF_YEAR);
    int currentRecordYear = calendar.get(Calendar.YEAR);
    DateFormat df = null;/*from w  ww . j a  va2s .  co  m*/
    // if date of the previous record isn't the same as the current one - show date
    if (lastRecordDay != currentRecordDay || lastRecordYear != currentRecordYear) {
        // if current year - do not show it
        if (currentRecordYear == currentYear) {
            df = yearLessDateFormat;
        } else {
            df = dateFormat;
        }
    }

    // update the view holder with the new record
    viewHolder.setModel(record, df);
}

From source file:com.opensource.bitmapfun.ui.ImageGridFragment.java

@SuppressWarnings("unused")
private String[] getImages() {
    ContentResolver cr = getActivity().getContentResolver();
    Cursor cursor = MediaStore.Images.Media.query(cr, MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            new String[] { MediaStore.MediaColumns.DATA, });
    if (cursor != null) {
        String[] datas = new String[cursor.getCount()];
        if (cursor.moveToFirst()) {
            int index = cursor.getColumnIndex(MediaStore.MediaColumns.DATA);
            do {//  w  ww .  j a  v  a 2s  .  c o m
                datas[cursor.getPosition()] = cursor.getString(index);
            } while (cursor.moveToNext());
        }
        cursor.close();
        return datas;
    }
    return new String[0];
}

From source file:pl.epodreczniki.service.MetadataService.java

private void requestCovers() {
    Cursor c = getContentResolver().query(BooksProvider.BOOKS_URI, BooksTable.COLUMNS,
            BooksTable.C_COVER_STATUS + "=?", new String[] { CoverStatus.REMOTE.getStringVal() }, null);
    List<Book> booksWithoutCovers = new ArrayList<Book>();
    if (c != null) {
        while (c.moveToNext()) {
            booksWithoutCovers.add(Util.getBookBuilderFromCursor(c, c.getPosition()).build());
        }/*from  ww w.ja  va 2 s  .co m*/
        c.close();
    }
    for (Book b : booksWithoutCovers) {
        requestCoverDownload(b);
    }
}

From source file:de.elanev.studip.android.app.frontend.contacts.ContactsGroupsFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    if (getActivity() == null) {
        return;/*from w ww. j av a 2s .c  o m*/
    }

    List<SectionedCursorAdapter.Section> sections = new ArrayList<SectionedCursorAdapter.Section>();
    cursor.moveToFirst();
    String prevGroup = null;
    String currGroup = null;

    while (!cursor.isAfterLast()) {
        currGroup = cursor.getString(cursor.getColumnIndex(ContactsContract.Columns.ContactGroups.GROUP_NAME));
        if (!TextUtils.equals(currGroup, prevGroup)) {
            sections.add(new SectionedCursorAdapter.Section(cursor.getPosition(), currGroup));
        }

        prevGroup = currGroup;

        cursor.moveToNext();
    }

    mUserAdapter.setSections(sections);
    mUserAdapter.swapCursor(cursor);

    setLoadingViewVisible(false);
}

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

public int getPositionForId(long id) {
    if (id == TicketsFragment.NONE) {
        return NO_SELECTION;
    }//from ww w. j  a v  a 2  s . com
    Cursor cursor = getCursor();
    if (cursor.isClosed()) {
        return NO_SELECTION;
    }
    while (cursor.moveToNext()) {
        long ticketId = cursor.getLong(iId);
        if (ticketId == id) {
            return cursor.getPosition();
        }
    }
    return NO_SELECTION;
}

From source file:com.amsterdam.marktbureau.makkelijkemarkt.adapters.DagvergunningenAdapter.java

/**
 * Bind the cursor data to the view elements
 * @param view listitem view containing the elements
 * @param context the context/*  w  w w  .  ja  va  2  s . c om*/
 * @param cursor a cursor containing the dagvergunning data
 */
@Override
public void bindView(View view, Context context, Cursor cursor) {
    boolean multipleDagvergunningen = false;

    // get erkenningsnummer for checking multiple dagvergunningen for the same koopman
    String erkenningsnummer = cursor.getString(
            cursor.getColumnIndex(MakkelijkeMarktProvider.Dagvergunning.COL_ERKENNINGSNUMMER_INVOER_WAARDE));

    // get current position, check for multiple dagvergunningen, and restore position again
    int position = cursor.getPosition();
    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
        if (cursor
                .getString(cursor.getColumnIndex(
                        MakkelijkeMarktProvider.Dagvergunning.COL_ERKENNINGSNUMMER_INVOER_WAARDE))
                .equals(erkenningsnummer) && cursor.getPosition() != position) {
            multipleDagvergunningen = true;
            break;
        }
        cursor.moveToNext();
    }
    cursor.moveToPosition(position);

    // get the viewholder layout containing the view items
    ViewHolder viewHolder = (ViewHolder) view.getTag();

    // koopman foto
    Glide.with(context.getApplicationContext())
            .load(cursor.getString(cursor.getColumnIndex(MakkelijkeMarktProvider.Koopman.COL_FOTO_URL)))
            .error(R.drawable.no_koopman_image).into(viewHolder.koopmanFoto);

    // alert !
    String koopmanStatus = cursor.getString(cursor.getColumnIndex("koopman_status"));
    if (multipleDagvergunningen
            || koopmanStatus.equals(context.getString(R.string.koopman_status_verwijderd))) {
        viewHolder.koopmanStatusText.setVisibility(View.VISIBLE);
    } else {
        viewHolder.koopmanStatusText.setVisibility(View.GONE);
    }

    // koopman naam
    String koopmanVoorletters = cursor
            .getString(cursor.getColumnIndex(MakkelijkeMarktProvider.Koopman.COL_VOORLETTERS));
    String koopmanAchternaam = cursor
            .getString(cursor.getColumnIndex(MakkelijkeMarktProvider.Koopman.COL_ACHTERNAAM));
    viewHolder.koopmanVoorlettersAchternaamText.setText(koopmanVoorletters + " " + koopmanAchternaam);

    // vervanger aanwezig
    String vervangerErkenningsnummer = cursor.getString(
            cursor.getColumnIndex(MakkelijkeMarktProvider.Dagvergunning.COL_VERVANGER_ERKENNINGSNUMMER));
    if (vervangerErkenningsnummer != null) {
        viewHolder.vervangerAanwezigText.setVisibility(View.VISIBLE);
    } else {
        viewHolder.vervangerAanwezigText.setVisibility(View.GONE);
    }

    // registratietijd
    String registratieDatumtijd = cursor
            .getString(cursor.getColumnIndex(MakkelijkeMarktProvider.Dagvergunning.COL_REGISTRATIE_DATUMTIJD));
    try {
        Date registratieDate = new SimpleDateFormat(context.getString(R.string.date_format_datumtijd),
                Locale.getDefault()).parse(registratieDatumtijd);
        SimpleDateFormat sdf = new SimpleDateFormat(context.getString(R.string.date_format_tijd));
        String registratieTijd = sdf.format(registratieDate);
        viewHolder.dagvergunningRegistratieDatumtijdText.setText(registratieTijd);
    } catch (java.text.ParseException e) {
        viewHolder.dagvergunningRegistratieDatumtijdText.setText("");
    }

    // erkennings nummer
    viewHolder.erkenningsnummerText
            .setText(context.getString(R.string.label_erkenningsnummer) + ": " + erkenningsnummer);

    // sollicitatie nummer
    String sollicitatieNummer = cursor
            .getString(cursor.getColumnIndex(MakkelijkeMarktProvider.Sollicitatie.COL_SOLLICITATIE_NUMMER));
    if (sollicitatieNummer != null && !sollicitatieNummer.equals("")) {
        viewHolder.sollicitatieSollicitatieNummerText.setVisibility(View.VISIBLE);
        viewHolder.sollicitatieSollicitatieNummerText
                .setText(context.getString(R.string.label_sollicitatienummer) + ": " + sollicitatieNummer);
    } else {
        // we need to clear the textview contents because listview items are recycled and may
        // therefor contain data from other dagvergunning
        viewHolder.sollicitatieSollicitatieNummerText.setVisibility(View.GONE);
        viewHolder.sollicitatieSollicitatieNummerText.setText("");
    }

    // sollicitatie status
    String sollicitatieStatus = cursor
            .getString(cursor.getColumnIndex(MakkelijkeMarktProvider.Dagvergunning.COL_STATUS_SOLLICITATIE));
    if (sollicitatieStatus != null && !sollicitatieStatus.equals("?") && !sollicitatieStatus.equals("")) {
        viewHolder.sollicitatieStatusText.setVisibility(View.VISIBLE);
        viewHolder.sollicitatieStatusText.setText(sollicitatieStatus);
        viewHolder.sollicitatieStatusText.setBackgroundColor(ContextCompat.getColor(context,
                Utility.getSollicitatieStatusColor(context, sollicitatieStatus)));
    } else {
        viewHolder.sollicitatieStatusText.setVisibility(View.GONE);
        viewHolder.sollicitatieStatusText.setText("");
    }

    // notitie
    String notitie = cursor.getString(cursor.getColumnIndex(MakkelijkeMarktProvider.Dagvergunning.COL_NOTITIE));
    if (notitie != null && !notitie.equals("")) {
        viewHolder.notitieText.setText(context.getString(R.string.label_notitie) + ": " + notitie);
        Utility.collapseView(viewHolder.notitieText, false);
    } else {
        Utility.collapseView(viewHolder.notitieText, true);
    }

    // totale lengte
    String totaleLengte = cursor
            .getString(cursor.getColumnIndex(MakkelijkeMarktProvider.Dagvergunning.COL_TOTALE_LENGTE));
    viewHolder.dagvergunningTotaleLengteText
            .setText(totaleLengte + " " + context.getString(R.string.length_meter));

    // account naam
    String accountNaam = cursor.getString(cursor.getColumnIndex(MakkelijkeMarktProvider.Account.COL_NAAM));
    viewHolder.accountNaamText.setText(accountNaam);
}

From source file:monakhv.android.samlib.AuthorListFragment.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() != -1) {

        launchBrowser(AuthorController.Cursor2Author(getActivity().getApplicationContext(), c));
        return true;
    }/*w  w w .j  av  a 2s.  co m*/
    return false;
}

From source file:monakhv.android.samlib.AuthorListFragment.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() != -1) {
        MarkRead marker = new MarkRead(getActivity().getApplicationContext());
        marker.execute(AuthorController.Cursor2Author(getActivity().getApplicationContext(), c).getId());
        return true;
    }// www .  j  ava 2  s .c om
    return false;

}