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.currency.list.CurrencyListFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    // take cursor and move into position
    Cursor cursor = ((CurrencyListAdapter) getListAdapter()).getCursor();
    cursor.moveToPosition(info.position);
    // set currency name
    menu.setHeaderTitle(cursor.getString(cursor.getColumnIndex(Currency.CURRENCYNAME)));

    // compose context menu
    String[] menuItems = getResources().getStringArray(R.array.context_menu_currencies);
    for (int i = 0; i < menuItems.length; i++) {
        menu.add(Menu.NONE, i, i, menuItems[i]);
    }//from  w w w .ja v a 2 s. com
}

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

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);

    // On select go back to the calling activity (if there is one)
    if (getActivity().getCallingActivity() != null) {
        Cursor cursor = ((SimpleCursorAdapter) getListAdapter()).getCursor();
        if (cursor != null) {
            if (cursor.moveToPosition(position)) {
                setResultAndFinish();/*  w  w  w.  j a  v a  2  s. com*/
            }
        }
    } else {
        // No calling activity, this is the independent Payees view. Show context menu.
        getActivity().openContextMenu(v);
    }
}

From source file:org.chromium.chrome.browser.util.ChromeFileProvider.java

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    Uri fileUri = getFileUriWhenReady(uri);
    if (fileUri == null)
        return null;

    // Workaround for a bad assumption that particular MediaStore columns exist by certain third
    // party applications.
    // http://crbug.com/467423.
    Cursor source = super.query(fileUri, projection, selection, selectionArgs, sortOrder);

    String[] columnNames = source.getColumnNames();
    String[] newColumnNames = columnNamesWithData(columnNames);
    if (columnNames == newColumnNames)
        return source;

    MatrixCursor cursor = new MatrixCursor(newColumnNames, source.getCount());

    source.moveToPosition(-1);
    while (source.moveToNext()) {
        MatrixCursor.RowBuilder row = cursor.newRow();
        for (int i = 0; i < columnNames.length; i++) {
            switch (source.getType(i)) {
            case Cursor.FIELD_TYPE_INTEGER:
                row.add(source.getInt(i));
                break;
            case Cursor.FIELD_TYPE_FLOAT:
                row.add(source.getFloat(i));
                break;
            case Cursor.FIELD_TYPE_STRING:
                row.add(source.getString(i));
                break;
            case Cursor.FIELD_TYPE_BLOB:
                row.add(source.getBlob(i));
                break;
            case Cursor.FIELD_TYPE_NULL:
            default:
                row.add(null);//from  www  .j  ava  2 s .c  o  m
                break;
            }
        }
    }

    source.close();
    return cursor;
}

From source file:com.tingtingapps.securesms.contacts.ContactSelectionListAdapter.java

@Override
public View getHeaderView(int i, View convertView, ViewGroup viewGroup) {
    Cursor cursor = getCursor();

    HeaderViewHolder holder;//  ww  w. ja v a  2  s.co  m

    if (convertView == null) {
        holder = new HeaderViewHolder();
        convertView = li.inflate(R.layout.contact_selection_list_header, viewGroup, false);
        holder.text = (TextView) convertView.findViewById(R.id.text);
        convertView.setTag(holder);
    } else {
        holder = (HeaderViewHolder) convertView.getTag();
    }

    cursor.moveToPosition(i);

    int contactType = cursor.getInt(cursor.getColumnIndexOrThrow(ContactsDatabase.CONTACT_TYPE_COLUMN));

    if (contactType == ContactsDatabase.PUSH_TYPE)
        holder.text.setText(R.string.contact_selection_list__header_textsecure_users);
    else
        holder.text.setText(R.string.contact_selection_list__header_other);

    return convertView;
}

From source file:com.ant.sunshine.app.fragments.ForecastFragment.java

private void openPreferredLocationInMap() {
    // Using the URI scheme for showing a location found on a map.  This super-handy
    // intent can is detailed in the "Common Intents" page of Android's developer site:
    // http://developer.android.com/guide/components/intents-common.html#Maps
    if (null != mForecastAdapter) {
        Cursor c = mForecastAdapter.getCursor();
        if (null != c) {
            c.moveToPosition(0);
            String posLat = c.getString(ForecastConstants.COL_COORD_LAT);
            String posLong = c.getString(ForecastConstants.COL_COORD_LONG);
            Uri geoLocation = Uri.parse("geo:" + posLat + "," + posLong);

            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(geoLocation);

            if (intent.resolveActivity(getCurrentActivity().getPackageManager()) != null) {
                startActivity(intent);//from   ww  w  .  j ava 2s .co m
            } else {
                Log.d(LOG_TAG, "Couldn't call " + geoLocation.toString() + ", no receiving apps installed!");
            }
        }

    }
}

From source file:org.thoughtcrime.SMP.contacts.ContactSelectionListAdapter.java

@Override
public View getHeaderView(int i, View convertView, ViewGroup viewGroup) {
    Cursor cursor = getCursor();

    HeaderViewHolder holder;//  w ww . j  av a 2s  . c  o m

    if (convertView == null) {
        holder = new HeaderViewHolder();
        convertView = li.inflate(R.layout.push_contact_selection_list_header, viewGroup, false);
        holder.text = (TextView) convertView.findViewById(R.id.text);
        convertView.setTag(holder);
    } else {
        holder = (HeaderViewHolder) convertView.getTag();
    }

    cursor.moveToPosition(i);

    int type = cursor.getInt(cursor.getColumnIndexOrThrow(ContactsDatabase.TYPE_COLUMN));

    if (type == ContactsDatabase.PUSH_TYPE)
        holder.text.setText(R.string.contact_selection_list__header_textsecure_users);
    else
        holder.text.setText(R.string.contact_selection_list__header_other);

    return convertView;
}

From source file:ca.rmen.android.scrumchatter.chart.MeetingSpeakingTimeColumnChart.java

public static void populateMeeting(Context context, ColumnChartView chart, @NonNull Cursor cursor) {
    List<AxisValue> xAxisValues = new ArrayList<>();
    List<Column> columns = new ArrayList<>();

    MeetingMemberCursorWrapper cursorWrapper = new MeetingMemberCursorWrapper(cursor);
    int maxLabelLength = 0;
    while (cursorWrapper.moveToNext()) {
        List<SubcolumnValue> subcolumnValues = new ArrayList<>();
        Column column = new Column(subcolumnValues);

        Long memberId = cursorWrapper.getMemberId();
        String memberName = cursorWrapper.getMemberName();
        float durationInMinutes = (float) cursorWrapper.getDuration() / 60;
        String durationLabel = DateUtils.formatElapsedTime(cursorWrapper.getDuration());

        SubcolumnValue subcolumnValue = new SubcolumnValue();
        subcolumnValue.setValue(durationInMinutes);
        subcolumnValue.setLabel(durationLabel);
        int color = ChartUtils.getMemberColor(context, memberId);
        subcolumnValue.setColor(color);//from  w  w  w .  j a  v  a2s. c om
        subcolumnValues.add(subcolumnValue);

        column.setHasLabels(true);
        column.setValues(subcolumnValues);
        columns.add(column);

        AxisValue xAxisValue = new AxisValue(xAxisValues.size());
        xAxisValue.setLabel(memberName);
        xAxisValues.add(xAxisValue);
        if (memberName.length() > maxLabelLength)
            maxLabelLength = memberName.length();
    }

    cursor.moveToPosition(-1);

    Axis xAxis = new Axis(xAxisValues);
    xAxis.setAutoGenerated(false);
    //xAxis.setMaxLabelChars(maxLabelLength);
    xAxis.setTextColor(ResourcesCompat.getColor(context.getResources(), R.color.chart_text, null));
    xAxis.setHasTiltedLabels(true);

    ColumnChartData data = new ColumnChartData();
    data.setAxisXBottom(xAxis);
    data.setColumns(columns);
    chart.setInteractive(true);
    chart.setColumnChartData(data);
    chart.setZoomEnabled(true);
    chart.setZoomType(ZoomType.HORIZONTAL);
}

From source file:com.xbm.android.matisse.ui.MatisseActivity.java

@Override
public void onAlbumLoad(final Cursor cursor) {
    mAlbumsAdapter.swapCursor(cursor);/*from www  . j  a  v  a  2s.co m*/
    // select default album.
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {

        @Override
        public void run() {
            cursor.moveToPosition(mAlbumCollection.getCurrentSelection());
            mAlbumsSpinner.setSelection(MatisseActivity.this, mAlbumCollection.getCurrentSelection());
            Album album = Album.valueOf(cursor);
            if (album.isAll() && SelectionSpec.getInstance().capture) {
                album.addCaptureCount();
            }
            onAlbumSelected(album);
        }
    });
}

From source file:com.granita.tasks.utils.TasksListCursorAdapter.java

@Override
public Cursor swapCursor(Cursor c) {
    Cursor result = super.swapCursor(c);
    if (c != null) {
        mIdColumn = c.getColumnIndex(TaskContract.TaskListColumns._ID);
        mTaskColorColumn = c.getColumnIndex(TaskContract.TaskListColumns.LIST_COLOR);
        mTaskNameColumn = c.getColumnIndex(TaskContract.TaskListColumns.LIST_NAME);
        mAccountNameColumn = c.getColumnIndex(TaskContract.TaskListSyncColumns.ACCOUNT_NAME);

        c.moveToPosition(-1);
        mSelectedLists = new ArrayList<Long>(c.getCount());
        while (c.moveToNext()) {
            mSelectedLists.add(c.getLong(mIdColumn));
        }//from w w  w  . j  a va 2s.  com
    }
    return result;
}

From source file:org.gateshipone.odyssey.fragments.PlaylistTracksFragment.java

/**
 * Remove the selected track from the playlist in the mediastore.
 *
 * @param position the position of the selected track in the adapter
 *///  www. jav  a2  s .com
private void removeTrackFromPlaylist(int position) {
    Cursor trackCursor = PermissionHelper.query(getActivity(),
            MediaStore.Audio.Playlists.Members.getContentUri("external", mPlaylistID),
            MusicLibraryHelper.projectionPlaylistTracks, "", null, "");

    if (trackCursor != null) {
        if (trackCursor.moveToPosition(position)) {
            String where = MediaStore.Audio.Playlists.Members._ID + "=?";
            String[] whereVal = {
                    trackCursor.getString(trackCursor.getColumnIndex(MediaStore.Audio.Playlists.Members._ID)) };

            PermissionHelper.delete(getActivity(),
                    MediaStore.Audio.Playlists.Members.getContentUri("external", mPlaylistID), where, whereVal);

            // reload data
            getLoaderManager().restartLoader(0, getArguments(), this);
        }

        trackCursor.close();
    }
}