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:org.mariotaku.twidere.adapter.ParcelableStatusesAdapter.java

@Override
public UserKey getAccountKey(int adapterPosition) {
    int dataPosition = adapterPosition - getStatusStartIndex();
    if (dataPosition < 0 || dataPosition >= getRawStatusCount())
        return null;
    if (mData instanceof ObjectCursor) {
        final Cursor cursor = ((ObjectCursor) mData).getCursor();
        if (!cursor.moveToPosition(dataPosition))
            return null;
        final ParcelableStatusCursorIndices indices = (ParcelableStatusCursorIndices) ((ObjectCursor) mData)
                .getIndices();/*w w  w  .j av a2 s . c  o m*/
        return UserKey.valueOf(cursor.getString(indices.account_key));
    }
    return mData.get(dataPosition).account_key;
}

From source file:org.mariotaku.twidere.adapter.ParcelableStatusesAdapter.java

@Nullable
@Override/*from  w  w  w .java2 s.  c  o m*/
public String getStatusId(int adapterPosition) {
    int dataPosition = adapterPosition - getStatusStartIndex();
    if (dataPosition < 0 || dataPosition >= getRawStatusCount())
        return null;
    if (mData instanceof ObjectCursor) {
        final Cursor cursor = ((ObjectCursor) mData).getCursor();
        if (!cursor.moveToPosition(dataPosition))
            return null;
        final ParcelableStatusCursorIndices indices = (ParcelableStatusCursorIndices) ((ObjectCursor) mData)
                .getIndices();
        return cursor.getString(indices.id);
    }
    return mData.get(dataPosition).id;
}

From source file:org.mariotaku.twidere.adapter.ParcelableStatusesAdapter.java

@Override
public long getItemId(int adapterPosition) {
    int dataPosition = adapterPosition - getStatusStartIndex();
    if (dataPosition < 0 || dataPosition >= getStatusCount())
        return adapterPosition;
    if (mData instanceof ObjectCursor) {
        final Cursor cursor = ((ObjectCursor) mData).getCursor();
        if (!cursor.moveToPosition(dataPosition))
            return -1;
        final ParcelableStatusCursorIndices indices = (ParcelableStatusCursorIndices) ((ObjectCursor) mData)
                .getIndices();//  www  .  j  a  v a 2  s  .  co  m
        final UserKey accountKey = UserKey.valueOf(cursor.getString(indices.account_key));
        final String id = cursor.getString(indices.id);
        return ParcelableStatus.calculateHashCode(accountKey, id);
    }
    return mData.get(dataPosition).hashCode();
}

From source file:org.mariotaku.twidere.adapter.ParcelableStatusesAdapter.java

@Override
public boolean isGapItem(int position) {
    int dataPosition = position - getStatusStartIndex();
    final int statusCount = getStatusCount();
    if (dataPosition < 0 || dataPosition >= statusCount)
        return false;
    // Don't show gap if it's last item
    if (dataPosition == statusCount - 1)
        return false;
    if (mData instanceof ObjectCursor) {
        final Cursor cursor = ((ObjectCursor) mData).getCursor();
        if (!cursor.moveToPosition(dataPosition))
            return false;
        final ParcelableStatusCursorIndices indices = (ParcelableStatusCursorIndices) ((ObjectCursor) mData)
                .getIndices();/*from www.java 2s  .com*/
        return cursor.getShort(indices.is_gap) == 1;
    }
    return mData.get(dataPosition).is_gap;
}

From source file:com.ultramegasoft.flavordex2.fragment.ViewFlavorsFragment.java

@Override
public void onLoadFinished(@NonNull Loader<Cursor> loader, Cursor data) {
    if (data == null) {
        return;//from  w ww . java  2s  .c o  m
    }
    data.moveToPosition(-1);
    final ArrayList<RadarHolder> flavorValues = new ArrayList<>();

    String name;
    int value;
    switch (loader.getId()) {
    case LOADER_FLAVOR:
        while (data.moveToNext()) {
            name = data.getString(data.getColumnIndex(Tables.EntriesFlavors.FLAVOR));
            value = data.getInt(data.getColumnIndex(Tables.EntriesFlavors.VALUE));
            flavorValues.add(new RadarHolder(name, value));
        }
        if (flavorValues.isEmpty()) {
            getLoaderManager().initLoader(LOADER_DEFAULT_FLAVOR, null, this);
            break;
        }
        mData = flavorValues;
        if (mRadarView.getVisibility() != View.VISIBLE) {
            mRadarView.startAnimation(AnimationUtils.loadAnimation(getContext(), android.R.anim.fade_in));
        }
        if (!mEditMode) {
            mRadarView.setData(flavorValues);
        }
        break;
    case LOADER_DEFAULT_FLAVOR:
    case LOADER_RESET_FLAVOR:
        while (data.moveToNext()) {
            name = data.getString(data.getColumnIndex(Tables.Flavors.NAME));
            flavorValues.add(new RadarHolder(name, 0));
        }

        mRadarView.setData(flavorValues);
        if (loader.getId() == LOADER_RESET_FLAVOR) {
            if (!mEditMode) {
                setEditMode(true, true);
            } else {
                mRadarView.turnTo(0);
            }
        }
        break;
    }
    mRadarView.setVisibility(View.VISIBLE);
}

From source file:org.mariotaku.twidere.adapter.ParcelableStatusesAdapter.java

@Override
public long getStatusPositionKey(int adapterPosition) {
    int dataPosition = adapterPosition - getStatusStartIndex();
    if (dataPosition < 0 || dataPosition >= getRawStatusCount())
        return -1;
    if (mData instanceof ObjectCursor) {
        final Cursor cursor = ((ObjectCursor) mData).getCursor();
        if (!cursor.moveToPosition(dataPosition))
            return -1;
        final ParcelableStatusCursorIndices indices = (ParcelableStatusCursorIndices) ((ObjectCursor) mData)
                .getIndices();/*from w w w  .j  a  v  a2s  .c  om*/
        final long positionKey = cursor.getLong(indices.position_key);
        if (positionKey > 0)
            return positionKey;
        return cursor.getLong(indices.timestamp);
    }
    final ParcelableStatus status = mData.get(dataPosition);
    final long positionKey = status.position_key;
    if (positionKey > 0)
        return positionKey;
    return status.timestamp;
}

From source file:com.android.mail.photo.MailPhotoViewController.java

/**
 * Save all of the attachments in the cursor.
 */// www .  j  a  v a  2 s  . c om
private void saveAllAttachments() {
    Cursor cursor = getCursorAtProperPosition();

    if (cursor == null) {
        return;
    }

    int i = -1;
    while (cursor.moveToPosition(++i)) {
        saveAttachment(new Attachment(cursor));
    }
}

From source file:com.dabay6.android.apps.carlog.adapters.FuelHistoryCursorAdapter.java

/**
 * @param context The {@link Context} used to retrieve string resources.
 * @param history The current {@link FuelHistoryDTO} record.
 * @param cursor  All history records./*from   w  w w. jav a2 s .c o  m*/
 */
private Pair<Float, String> calculateMilesPerGallon(final Context context, final FuelHistoryDTO history,
        final Cursor cursor) {
    final Pair<Long, String> returnValue;
    final int count = cursor.getCount() - 1;
    final int currentPosition = cursor.getPosition();
    final int next = cursor.getPosition() + 1;
    final float mileage;
    final float mpg;

    if (next <= count) {
        final FuelHistoryDTO previous;

        cursor.moveToPosition(next);

        previous = FuelHistoryDTO.newInstance(cursor);
        mileage = history.getOdometerReading() - previous.getOdometerReading();

        mpg = mileage / history.getFuelAmount();

        cursor.moveToPosition(currentPosition);
    } else {
        mpg = history.getOdometerReading() / history.getFuelAmount();
    }

    return new Pair<Float, String>(mpg, String.format(context.getString(R.string.miles_per_gallon), mpg));
}

From source file:com.money.manager.ex.fragment.PayeeListFragment.java

@Override
public boolean onContextItemSelected(android.view.MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = null;
    if (item.getMenuInfo() instanceof AdapterView.AdapterContextMenuInfo) {
        info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    } else {/*from   w ww. j  a va  2s.co  m*/
        return false;
    }
    //        if (item.getMenuInfo() instanceof ExpandableListView.ExpandableListContextMenuInfo) {
    //            info = item.getMenuInfo();
    //        }

    Cursor cursor = ((SimpleCursorAdapter) getListAdapter()).getCursor();
    cursor.moveToPosition(info.position);

    // Read values from cursor.
    Payee payee = new Payee();
    payee.loadFromCursor(cursor);

    ContextMenuIds menuId = ContextMenuIds.get(item.getItemId());
    if (menuId == null)
        return false;

    switch (menuId) {
    case EDIT:
        showDialogEditPayeeName(SQLTypeTransaction.UPDATE, payee.getId(), payee.getName());
        break;

    case DELETE:
        PayeeService service = new PayeeService(getActivity());
        if (!service.isPayeeUsed(payee.getId())) {
            showDialogDeletePayee(payee.getId());
        } else {
            new AlertDialogWrapper(getActivity()).setTitle(R.string.attention)
                    .setIcon(new UIHelper(getActivity()).getIcon(GoogleMaterial.Icon.gmd_warning))
                    .setMessage(R.string.payee_can_not_deleted).setPositiveButton(android.R.string.ok)
                    .onPositive(new MaterialDialog.SingleButtonCallback() {
                        @Override
                        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                            dialog.dismiss();
                        }
                    }).create().show();
        }
        break;

    case VIEW_TRANSACTIONS:
        SearchParameters parameters = new SearchParameters();
        parameters.payeeId = payee.getId();
        parameters.payeeName = payee.getName();

        Intent intent = IntentFactory.getSearchIntent(getActivity(), parameters);
        startActivity(intent);
    }
    return false;
}

From source file:com.rowland.hashtrace.ui.fragments.subfragment.TweetListFragment.java

@Override
public void onListItemClick(ListView lv, View view, int position, long rowID) {
    super.onListItemClick(lv, view, position, rowID);
    // Do the onItemClick action
    Cursor cursor = mTweetListAdapter.getCursor();
    if (cursor != null && cursor.moveToPosition(position)) {
        //((onTweetItemSelectedCallback) getActivity()).onTweetItemSelected((cursor.getInt(COL_ID)));
        ((onTweetItemSelectedCallback) getActivity()).onTweetItemSelected((int) rowID);
        //mPullToRefreshListView.getRefreshableView().setItemChecked(position, true);;
    }/*from   w  w w . j ava2  s  . c  o m*/
    mPosition = position;
    Log.d("ROWSELECT", "" + rowID);
}