Example usage for android.database Cursor moveToPrevious

List of usage examples for android.database Cursor moveToPrevious

Introduction

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

Prototype

boolean moveToPrevious();

Source Link

Document

Move the cursor to the previous row.

Usage

From source file:org.voidsink.anewjkuapp.fragment.ExamFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    mAdapter.clear();//from www  .ja  v  a  2s.  com

    if (data != null) {
        if (AppUtils.getAccount(getContext()) != null) {
            CourseMap map = new CourseMap(getContext());
            List<ExamListExam> mExams = new ArrayList<>();

            data.moveToFirst();
            data.moveToPrevious();
            while (data.moveToNext()) {
                try {
                    mExams.add(new ExamListExam(data, map));
                } catch (ParseException e) {
                    Analytics.sendException(getContext(), e, false);
                }
            }
            mAdapter.addAll(mExams);
        }
    }
    mAdapter.notifyDataSetChanged();

    finishProgress();
}

From source file:at.tm.android.fitacity.MainActivity.java

@Override
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
    List<Exercise> exercises = new ArrayList<>();

    // To start from the beginning every time
    cursor.moveToFirst();//from   w w  w  .  ja v  a2  s .  c o m
    cursor.moveToPrevious();

    while (cursor.moveToNext()) {
        int id = cursor.getInt(cursor.getColumnIndex(FitacityContract.ExerciseEntry.COLUMN_ID));
        String name = cursor.getString(cursor.getColumnIndex(FitacityContract.ExerciseEntry.COLUMN_NAME));
        String description = cursor
                .getString(cursor.getColumnIndex(FitacityContract.ExerciseEntry.COLUMN_DESCRIPTION));
        int category = cursor.getInt(cursor.getColumnIndex(FitacityContract.ExerciseEntry.COLUMN_CATEGORY));
        String equipment = cursor
                .getString(cursor.getColumnIndex(FitacityContract.ExerciseEntry.COLUMN_EQUIPMENT));
        float difficulty = cursor
                .getFloat(cursor.getColumnIndex(FitacityContract.ExerciseEntry.COLUMN_DIFFICULTY));
        String videoUrl = cursor
                .getString(cursor.getColumnIndex(FitacityContract.ExerciseEntry.COLUMN_VIDEO_URL));
        String imgUrl = cursor.getString(cursor.getColumnIndex(FitacityContract.ExerciseEntry.COLUMN_IMG_URL));

        // Get all exercises from the cursor and put them to the exercise list
        exercises.add(new Exercise(id, name, description, category, equipment, difficulty, videoUrl, imgUrl));
    }

    if (exercises.size() > 0) {
        mEmptyRecyclerView.setVisibility(View.INVISIBLE);
    } else {
        mEmptyRecyclerView.setVisibility(View.VISIBLE);
    }

    mExerciseRecyclerViewAdapter.updateExerciseData(exercises);
}

From source file:fr.mixit.android.ui.adapters.MyPlanningAdapter.java

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

    if (cursor != null) {
        final int oldPosition = cursor.getPosition();
        final long start = cursor.getLong(MixItContract.Sessions.PROJ_PLANNING.START);
        final String header = (String) DateUtils.formatPlanningHeader(start);

        long oldStart = 0;
        String oldHeader = null;/*from   w ww.j a  v a 2  s .c o m*/
        if (cursor.moveToPrevious()) {
            oldStart = cursor.getLong(MixItContract.Sessions.PROJ_PLANNING.START);
            oldHeader = (String) DateUtils.formatPlanningHeader(oldStart);
        }

        if (header.equalsIgnoreCase(oldHeader)) {
            holder.mHeader.setVisibility(View.GONE);
        } else {
            holder.mHeader.setVisibility(View.VISIBLE);
            holder.mHeader.setText(header);
        }

        cursor.moveToPosition(oldPosition);
    }

    holder.mTalk.setContentPlanning(cursor, mDisplayPastSessionsInGrey);
}

From source file:org.kontalk.ui.adapter.MessageListAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    if (!(view instanceof MessageListItem)) {
        Log.e(TAG, "unexpected bound view: " + view);
        return;/*  w  ww  . j  av a  2s  . c  o  m*/
    }

    MessageListItem headerView = (MessageListItem) view;
    CompositeMessage msg = CompositeMessage.fromCursor(context, cursor);

    long previousTimestamp = -1;
    int previousItemType = -1;
    String previousPeer = null;
    if (cursor.moveToPrevious()) {
        previousTimestamp = MessageUtils.getMessageTimestamp(cursor);
        previousPeer = MessageUtils.getMessagePeer(cursor);
        previousItemType = getItemViewType(cursor);
    }
    cursor.moveToNext();

    headerView.bind(context, msg, mHighlight, getItemViewType(cursor), previousItemType, previousTimestamp,
            previousPeer, mAudioPlayerControl);
}

From source file:org.zywx.wbpalmstar.plugin.uexcontacts.ContactActivity.java

private void readContactDetails(Cursor detailCursor) {
    if (detailCursor != null && detailCursor.moveToFirst()) {
        detailCursor.moveToPrevious();
        while (detailCursor.moveToNext()) {
            String lookupKey = detailCursor
                    .getString(detailCursor.getColumnIndex(ContactsContract.Data.LOOKUP_KEY));
            ContactVO contact = mContactsByLookupKey.get(lookupKey);

            if (contact != null) {
                readContactDetails(detailCursor, contact);
            }//from  w w w  . j a v a  2 s  .  c  o m
        }
    }
}

From source file:com.meiste.tempalarm.ui.CurrentTemp.java

/**
 * Move the Cursor returned by the query into the ListView adapter. This refreshes the existing
 * UI with the data in the Cursor./*w w w. ja  va2  s .  co  m*/
 */
@Override
public void onLoadFinished(final Loader<Cursor> loader, final Cursor cursor) {
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    mLightThreshold = prefs.getInt(AppConstants.PREF_THRES_LIGHT, 0);

    mGraph.removeAllSeries();
    final List<GraphView.GraphViewData> data = new ArrayList<>();
    cursor.moveToLast();
    while (cursor.moveToPrevious()) {
        data.add(new GraphView.GraphViewData(cursor.getLong(COLUMN_TIMESTAMP), cursor.getFloat(COLUMN_DEGF)));
    }
    final GraphViewSeries exampleSeries = new GraphViewSeries(
            data.toArray(new GraphView.GraphViewData[data.size()]));
    mGraph.addSeries(exampleSeries);

    mAdapter.changeCursor(cursor);
}

From source file:net.niyonkuru.koodroid.MainActivity.java

/**
 * Build the switcher url manually based on another subscriber's by replacing the last param.
 *//*from w  w w.ja  v a  2 s  .  co  m*/
private String buildSwitcherUrl(String subscriberId, Cursor data) {
    String url = null;

    if (data.moveToNext()) {
        url = data.getString(SubscribersQuery.SUBSCRIBER_SWITCHER);

        if (url != null) {
            // replace the last param with this subscriber
            url = url.substring(0, url.lastIndexOf('=') + 1) + subscriberId;
        }

        data.moveToPrevious();
    }

    return url;
}

From source file:com.digipom.manteresting.android.adapter.NailCursorAdapter.java

/**
 * BindView will also be called after newView. See {@link CursorAdapter}
 */// w w  w .  j  a  va 2  s.co m
@Override
public void bindView(View view, Context context, Cursor cursor) {
    try {
        // 84, or 0.825, comes from the margins/paddings around the
        // image. This will need to be changed if the margins/paddings are
        // changed or multi-column mode is used.
        final int approxImageWidthInPixels = (int) (context.getResources().getDisplayMetrics().widthPixels
                * 0.825f);

        // Request a load of the bitmaps on either side, to avoid
        // problems when scrolling up and down.
        final int cursorPosition = cursor.getPosition();

        if (cursorPosition > 0) {
            cursor.moveToPrevious();
            if (cursor.getString(nailObjectColumnIndex) != null) {
                cacheDataAndGet(context, cursor, approxImageWidthInPixels);
            }
            cursor.moveToNext();
        }

        if (cursorPosition < cursor.getCount() - 1) {
            cursor.moveToNext();
            if (cursor.getString(nailObjectColumnIndex) != null) {
                cacheDataAndGet(context, cursor, approxImageWidthInPixels);
            }
            cursor.moveToPrevious();
        }

        final ViewHolder viewHolder = (ViewHolder) view.getTag();

        final CachedData cachedDataForThisNailItem = cacheDataAndGet(context, cursor, approxImageWidthInPixels);

        viewHolder.nailDescription.setText(cachedDataForThisNailItem.nailDescription);
        viewHolder.nailUserAndCategory.setText(cachedDataForThisNailItem.styledUserAndCategory);

        if (failedDownloads.contains(cachedDataForThisNailItem.originalImageUriString)) {
            // This image has failed. The user will have to select to
            // retry this image. INVISIBLE and not GONE so that the view
            // doesn't jump in sizes for couldNotLoadImageIndicator.
            viewHolder.imageLoadingIndicator.setVisibility(View.INVISIBLE);
            viewHolder.couldNotLoadImageIndicator.setVisibility(View.VISIBLE);
            viewHolder.loadedImage.setVisibility(View.GONE);
        } else {
            // Should default to WRAP_CONTENT
            viewHolder.loadedImage.getLayoutParams().height = LayoutParams.WRAP_CONTENT;

            Bitmap bitmap = null;

            if (serviceConnector.getService() != null) {
                bitmap = serviceConnector.getService().getOrLoadLifoAsync(
                        cachedDataForThisNailItem.originalImageUriString, approxImageWidthInPixels,
                        bitmapCompleteReceiver);
            }

            if (bitmap == null) {
                viewHolder.imageLoadingIndicator.setVisibility(View.VISIBLE);
                viewHolder.couldNotLoadImageIndicator.setVisibility(View.INVISIBLE);
                viewHolder.loadedImage.setVisibility(View.GONE);
            } else {
                viewHolder.imageLoadingIndicator.setVisibility(View.GONE);
                viewHolder.couldNotLoadImageIndicator.setVisibility(View.GONE);
                viewHolder.loadedImage.setVisibility(View.VISIBLE);

                viewHolder.loadedImage.setImageBitmap(bitmap);
            }
        }
    } catch (JSONException e) {
        if (LoggerConfig.canLog(Log.ERROR)) {
            Log.e(TAG, "Could not load JSON object from database.", e);
        }
    } catch (Exception e) {
        if (LoggerConfig.canLog(Log.ERROR)) {
            Log.e(TAG, "Error binding view.", e);
        }
    }
}

From source file:com.onegravity.contactpicker.core.ContactPickerActivity.java

private void readContactDetails(Cursor cursor) {
    if (cursor != null && cursor.moveToFirst()) {
        cursor.moveToPrevious();
        while (cursor.moveToNext()) {
            String lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.LOOKUP_KEY));
            ContactImpl contact = mContactsByLookupKey.get(lookupKey);

            if (contact != null) {
                readContactDetails(cursor, contact);
            }//from w  w  w  . j av  a2 s.c  o  m
        }
    }

    sortAndPostCopy(mContacts);
    joinContactsAndGroups(mContacts);
}

From source file:com.onegravity.contactpicker.core.ContactPickerActivity.java

private void readGroups(Cursor cursor) {
    mGroups.clear();//from  w w w.ja v  a 2  s. c  o  m
    mGroupsById.clear();
    mVisibleGroups.clear();

    if (cursor.moveToFirst()) {
        cursor.moveToPrevious();
        while (cursor.moveToNext()) {
            GroupImpl group = GroupImpl.fromCursor(cursor);

            mGroups.add(group);
            mGroupsById.put(group.getId(), group);

            boolean isChecked = mSelectedGroupIds.contains(group.getId());
            group.setChecked(isChecked, true);

            group.addOnContactCheckedListener(mGroupListener);
        }
    }

    GroupsLoaded.post(mVisibleGroups);
    joinContactsAndGroups(mContacts);
}