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:de.stadtrallye.rallyesoft.util.converters.CursorConverters.java

public static Task getTask(int pos, Cursor cursor, TaskCursorIds c) {
    cursor.moveToPosition(pos);

    return getTask(cursor, c);
}

From source file:de.stadtrallye.rallyesoft.util.converters.CursorConverters.java

/**
 * Move a Cursor to a id//from   www. j av a 2s. c om
 * This assumes that the cursor is sorted by id
 * @return true if the element could be found.
  */
public static boolean moveCursorToId(Cursor cursor, int column, int id) {
    int left = 0;
    int right = cursor.getCount() - 1;

    while (left <= right) {
        int middle = (left + right) / 2;

        cursor.moveToPosition(middle);
        int val = cursor.getInt(column);
        if (val == id)
            return true;
        if (val > id)
            right = middle - 1;
        else
            left = middle + 1;
    }

    return false;
}

From source file:Main.java

public static ArrayList<HashMap<String, String>> cursorToHashMap(Cursor cursor) {

    if (cursor != null) {
        int cursorCount = cursor.getCount();
        int columnCount;
        ArrayList<HashMap<String, String>> cursorData = new ArrayList<HashMap<String, String>>();
        HashMap<String, String> rowHashMap;
        for (int i = 0; i < cursorCount; i++) {
            cursor.moveToPosition(i);
            rowHashMap = new HashMap<String, String>();
            columnCount = cursor.getColumnCount();
            for (int j = 0; j < columnCount; j++) {
                rowHashMap.put(cursor.getColumnName(j), cursor.getString(j));
            }//from   w ww.  j a  va2s.c om
            cursorData.add(rowHashMap);
        }
        cursor.close();

        return cursorData;
    } else {
        return null;
    }
}

From source file:com.android.calendar.event.EventLocationAdapter.java

/**
 * Post-process the query results to return the first MAX_LOCATION_SUGGESTIONS
 * unique locations in alphabetical order.
 * <p/>/*from w  ww . j a v  a 2  s.c  o  m*/
 * TODO: Refactor to share code with the recent titles auto-complete.
 */
private static List<Result> processLocationsQueryResults(Cursor cursor) {
    TreeSet<String> locations = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
    cursor.moveToPosition(-1);

    // Remove dupes.
    while ((locations.size() < MAX_LOCATION_SUGGESTIONS) && cursor.moveToNext()) {
        String location = cursor.getString(EVENT_INDEX_LOCATION).trim();
        locations.add(location);
    }

    // Copy the sorted results.
    List<Result> results = new ArrayList<Result>();
    for (String location : locations) {
        results.add(new Result(null, location, R.drawable.ic_history_holo_light, null));
    }
    return results;
}

From source file:com.android.ex.chips.RecipientAlternatesAdapter.java

/**
 * @return a new cursor based on the given cursor with all duplicate destinations removed.
 *         It's only intended to use for the alternate list, so...
 *         - This method ignores all other fields and dedupe solely on the destination. Normally,
 *         if a cursor contains multiple contacts and they have the same destination, we'd still want
 *         to show both./* ww w.  j a va  2s  . c o m*/
 *         - This method creates a MatrixCursor, so all data will be kept in memory. We wouldn't want
 *         to do this if the original cursor is large, but it's okay here because the alternate list
 *         won't be that big.
 */
// Visible for testing
/* package */static Cursor removeDuplicateDestinations(Cursor original) {
    final MatrixCursor result = new MatrixCursor(original.getColumnNames(), original.getCount());
    final HashSet<String> destinationsSeen = new HashSet<String>();

    original.moveToPosition(-1);
    while (original.moveToNext()) {
        final String destination = original.getString(Query.DESTINATION);
        if (destinationsSeen.contains(destination)) {
            continue;
        }
        destinationsSeen.add(destination);

        Object[] cursorObjects;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            cursorObjects = new Object[] { original.getString(Query.NAME),
                    original.getString(Query.DESTINATION), original.getInt(Query.DESTINATION_TYPE),
                    original.getString(Query.DESTINATION_LABEL), original.getLong(Query.CONTACT_ID),
                    original.getLong(Query.DATA_ID), original.getString(Query.PHOTO_THUMBNAIL_URI),
                    original.getInt(Query.DISPLAY_NAME_SOURCE) };
        } else {
            cursorObjects = new Object[] { original.getString(Query.NAME),
                    original.getString(Query.DESTINATION), original.getInt(Query.DESTINATION_TYPE),
                    original.getString(Query.DESTINATION_LABEL), original.getLong(Query.CONTACT_ID),
                    original.getLong(Query.DATA_ID), original.getString(Query.PHOTO_ID) };
        }
        result.addRow(cursorObjects);
    }

    return result;
}

From source file:net.ccghe.emocha.model.DBAdapter.java

public static ArrayList<String> getFilePaths() {
    Cursor c = sDB.query(TABLE_DOWNLOADS, new String[] { "path" }, null, null, null, null, null);
    ArrayList<String> result = new ArrayList<String>();

    int numRows = c.getCount();
    for (int i = 0; i < numRows; i++) {
        c.moveToPosition(i);
        result.add(c.getString(DL_COL_PATH));
    }// ww  w  .  j av a  2  s .c  om
    c.close();
    return result;
}

From source file:net.ccghe.emocha.model.DBAdapter.java

public static ArrayList<String> getFilesFiltered(String filter) {
    ArrayList<String> result = new ArrayList<String>();
    Cursor c = sDB.query(TABLE_DOWNLOADS, new String[] { "path" }, filter, null, null, null, null);
    int numRows = c.getCount();
    Log.i(Constants.LOG_TAG, filter + " : " + numRows);
    for (int i = 0; i < numRows; i++) {
        c.moveToPosition(i);
        result.add(c.getString(DL_COL_PATH));
        Log.i(Constants.LOG_TAG, i + " : " + c.getString(DL_COL_PATH));
    }/*w ww  .java  2s .c  om*/
    c.close();
    return result;
}

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

public static void populateMeetingDurationChart(Context context, LineChartView chart, @NonNull Cursor cursor) {
    List<PointValue> points = new ArrayList<>();
    List<AxisValue> xAxisValues = new ArrayList<>();

    MeetingCursorWrapper cursorWrapper = new MeetingCursorWrapper(cursor);
    while (cursorWrapper.moveToNext()) {
        Meeting meeting = Meeting.read(context, cursorWrapper);
        points.add(getMeetingDurationPointValue(meeting));
        xAxisValues.add(getMeetingDurationXAxisValue(context, meeting));
    }/*from w w  w.  jav a 2  s .c  o m*/
    cursor.moveToPosition(-1);

    int lineColor = ResourcesCompat.getColor(context.getResources(), R.color.scrum_chatter_primary_color, null);
    Line line = new Line(points);
    line.setColor(lineColor);
    List<Line> lines = new ArrayList<>();
    lines.add(line);

    LineChartData lineChartData = new LineChartData();
    lineChartData.setLines(lines);
    setupChart(context, chart, xAxisValues, context.getString(R.string.chart_duration), lines);
}

From source file:com.chess.genesis.data.GameDataDB.java

public static Bundle rowToBundle(final Cursor cursor, final int index, final boolean closeCursor) {
    final Bundle bundle = new Bundle();
    final String[] column = cursor.getColumnNames();

    cursor.moveToPosition(index);
    for (int i = 0, len = cursor.getColumnCount(); i < len; i++)
        bundle.putString(column[i], cursor.getString(i));
    if (closeCursor)
        cursor.close();//from w ww  . ja v  a 2s.  c  om
    return bundle;
}

From source file:edu.stanford.mobisocial.dungbeetle.ImageGalleryActivity.java

private static int binarySearch(Cursor c, long id, int colId) {
    long test;//ww  w  . j a  va  2 s. c  o  m
    int first = 0;
    int max = c.getCount();
    while (first < max) {
        int mid = (first + max) / 2;
        c.moveToPosition(mid);
        test = c.getLong(colId);
        if (id > test) {
            max = mid;
        } else if (id < test) {
            first = mid + 1;
        } else {
            return mid;
        }
    }
    return 0;
}