Example usage for android.database Cursor isAfterLast

List of usage examples for android.database Cursor isAfterLast

Introduction

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

Prototype

boolean isAfterLast();

Source Link

Document

Returns whether the cursor is pointing to the position after the last row.

Usage

From source file:net.abcdroid.devfest12.ui.MyScheduleFragment.java

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

    long currentTime = UIUtils.getCurrentTime(getActivity());
    int firstNowPosition = ListView.INVALID_POSITION;

    List<SimpleSectionedListAdapter.Section> sections = new ArrayList<SimpleSectionedListAdapter.Section>();
    cursor.moveToFirst();
    long previousBlockStart = -1;
    long blockStart, blockEnd;
    while (!cursor.isAfterLast()) {
        blockStart = cursor.getLong(BlocksQuery.BLOCK_START);
        blockEnd = cursor.getLong(BlocksQuery.BLOCK_END);
        if (!UIUtils.isSameDay(previousBlockStart, blockStart)) {
            sections.add(new SimpleSectionedListAdapter.Section(cursor.getPosition(),
                    DateUtils.formatDateTime(getActivity(), blockStart, DateUtils.FORMAT_ABBREV_MONTH
                            | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY)));
        }
        if (mScrollToNow && firstNowPosition == ListView.INVALID_POSITION
        // if we're currently in this block, or we're not in a block
        // and this
        // block is in the future, then this is the scroll position
                && ((blockStart < currentTime && currentTime < blockEnd) || blockStart > currentTime)) {
            firstNowPosition = cursor.getPosition();
        }
        previousBlockStart = blockStart;
        cursor.moveToNext();
    }

    mScheduleAdapter.changeCursor(cursor);

    SimpleSectionedListAdapter.Section[] dummy = new SimpleSectionedListAdapter.Section[sections.size()];
    mAdapter.setSections(sections.toArray(dummy));

    if (mScrollToNow && firstNowPosition != ListView.INVALID_POSITION) {
        firstNowPosition = mAdapter.positionToSectionedPosition(firstNowPosition);
        getListView().setSelectionFromTop(firstNowPosition,
                getResources().getDimensionPixelSize(R.dimen.list_scroll_top_offset));
        mScrollToNow = false;
    }
}

From source file:com.example.app_2.activities.ImageGridActivity.java

private void setActionBar() {
    mActionBar = getActionBar();//from  w  w  w.  j a v a 2 s  .c  om
    mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    if (mEditMode) {
        mActionBar.setBackgroundDrawable(new ColorDrawable(0xff0084b3));
        mActionBar.setDisplayShowTitleEnabled(false);
        mActionBar.setDisplayShowTitleEnabled(true);
    } else {
        mActionBar.setBackgroundDrawable(new ColorDrawable(0xff4d055e));
        mActionBar.setDisplayShowTitleEnabled(false);
        mActionBar.setDisplayShowTitleEnabled(true);
        Uri uri = Uri.parse(UserContract.CONTENT_URI + "/" + logged_user_id);
        Cursor c = getContentResolver().query(uri, new String[] { UserContract.Columns.IMG_FILENAME }, null,
                null, null);
        c.moveToFirst();
        if (!c.isAfterLast()) {
            String path = Storage.getPathToScaledBitmap(c.getString(0), 50);
            Bitmap user_icon = ScalingUtilities.decodeFile(path, 50, 50, ScalingLogic.FIT);
            mActionBar.setIcon(new BitmapDrawable(getResources(), user_icon));
        }
        c.close();
    }

    navSpinner = new ArrayList<SpinnerNavItem>();
    navSpinner.add(new SpinnerNavItem("Alfabetycznie", R.drawable.sort_ascend));
    navSpinner.add(new SpinnerNavItem("Ostatnio zmodyfikowane", R.drawable.clock));
    navSpinner.add(new SpinnerNavItem("Najczciej uywane", R.drawable.favourites));

    title_nav_adapter = new TitleNavigationAdapter(getApplicationContext(), navSpinner);
    mActionBar.setListNavigationCallbacks(title_nav_adapter, this);
}

From source file:com.google.android.apps.iosched.ui.MyScheduleFragment.java

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

    long currentTime = UIUtils.getCurrentTime(getActivity());
    int firstNowPosition = ListView.INVALID_POSITION;

    List<SimpleSectionedListAdapter.Section> sections = new ArrayList<SimpleSectionedListAdapter.Section>();
    cursor.moveToFirst();
    long previousBlockStart = -1;
    long blockStart, blockEnd;
    while (!cursor.isAfterLast()) {
        blockStart = cursor.getLong(BlocksQuery.BLOCK_START);
        blockEnd = cursor.getLong(BlocksQuery.BLOCK_END);
        if (!UIUtils.isSameDay(previousBlockStart, blockStart)) {
            sections.add(new SimpleSectionedListAdapter.Section(cursor.getPosition(),
                    DateUtils.formatDateTime(getActivity(), blockStart, DateUtils.FORMAT_ABBREV_MONTH
                            | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY)));
        }
        if (mScrollToNow && firstNowPosition == ListView.INVALID_POSITION
        // if we're currently in this block, or we're not in a block
        // and this
        // block is in the future, then this is the scroll position
                && ((blockStart < currentTime && currentTime < blockEnd) || blockStart > currentTime)) {
            firstNowPosition = cursor.getPosition();
        }
        previousBlockStart = blockStart;
        cursor.moveToNext();
    }

    mScheduleAdapter.changeCursor(cursor);

    SimpleSectionedListAdapter.Section[] dummy = new SimpleSectionedListAdapter.Section[sections.size()];
    mAdapter.setSections(sections.toArray(dummy));

    if (mScrollToNow && firstNowPosition != ListView.INVALID_POSITION) {
        firstNowPosition = mAdapter.positionToSectionedPosition(firstNowPosition);
        getListView().setSelectionFromTop(firstNowPosition,
                getResources().getDimensionPixelSize(R.dimen.list_scroll_top_offset));
        mScrollToNow = false;
    }
}

From source file:com.samknows.measurement.storage.DBHelper.java

public List<Integer> getTestBatchesByPassiveMetric(String selection) {
    synchronized (sync) {
        open();// w ww . j  a  va 2s  .c o m
        List<Integer> ret = new ArrayList<Integer>();
        String[] columns = { SKSQLiteHelper.PM_COLUMN_BATCH_ID };
        Cursor cursor = database.query(SKSQLiteHelper.TABLE_PASSIVEMETRIC, columns, selection, null,
                SKSQLiteHelper.PM_COLUMN_BATCH_ID, null, null);
        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
            ret.add(cursor.getInt(0));
            cursor.moveToNext();
        }
        cursor.close();
        close();
        return ret;
    }
}

From source file:liqui.droid.activity.Base.java

public String queryString(Uri uri, String column, String selection, String[] selectionArgs, String orderBy) {
    Cursor c = getContentResolver().query(uri, null, selection, selectionArgs, orderBy);

    c.moveToFirst();/* w  w w.  j a va 2  s  . c  o  m*/

    String str = null;

    if (!c.isAfterLast()) {
        str = c.getString(c.getColumnIndex(column));
    }

    c.close();

    return str;
}

From source file:org.openbmap.soapclient.GpxExporter.java

/**
 * Iterates on way points and write them.
 * @param bw Writer to the target file.//from www.  j ava2 s . c om
 * @param c Cursor to way points.
 * @throws IOException
 */
private void writeCells(final BufferedWriter bw) throws IOException {
    Log.i(TAG, "Writing cell waypoints");
    Cursor c = mDbHelper.getReadableDatabase().rawQuery(CELL_POINTS_SQL_QUERY,
            new String[] { String.valueOf(mSession), String.valueOf(0) });

    final int colLatitude = c.getColumnIndex(Schema.COL_LATITUDE);
    final int colLongitude = c.getColumnIndex(Schema.COL_LONGITUDE);
    final int colAltitude = c.getColumnIndex(Schema.COL_ALTITUDE);
    final int colTimestamp = c.getColumnIndex(Schema.COL_TIMESTAMP);
    final int colName = c.getColumnIndex("name");

    long outer = 0;
    while (!c.isAfterLast()) {
        c.moveToFirst();
        //StringBuffer out = new StringBuffer();
        while (!c.isAfterLast()) {
            bw.write("\t<wpt lat=\"");
            bw.write(String.valueOf(c.getDouble(colLatitude)));
            bw.write("\" ");
            bw.write("lon=\"");
            bw.write(String.valueOf(c.getDouble(colLongitude)));
            bw.write("\">\n");
            bw.write("\t\t<ele>");
            bw.write(String.valueOf(c.getDouble(colAltitude)));
            bw.write("</ele>\n");
            bw.write("\t\t<time>");
            // time stamp conversion to ISO 8601
            bw.write(getGpxDate(c.getLong(colTimestamp)));
            bw.write("</time>\n");
            bw.write("\t\t<name>");
            bw.write(StringEscapeUtils.escapeXml(c.getString(colName)));
            bw.write("</name>\n");
            bw.write("\t</wpt>\n");

            c.moveToNext();
        }

        //bw.write(out.toString());
        //out = null;
        // fetch next CURSOR_SIZE records
        outer += CURSOR_SIZE;
        c.close();
        c = mDbHelper.getReadableDatabase().rawQuery(CELL_POINTS_SQL_QUERY,
                new String[] { String.valueOf(mSession), String.valueOf(outer) });
    }
    c.close();
    System.gc();
}

From source file:org.openbmap.soapclient.GpxSerializer.java

/**
 * Iterates on track points and write them.
 *
 * @param bw/*ww  w. j av a2 s. c o m*/
 *         Writer to the target file.
 */
private void writeWaypoints(final BufferedWriter bw) throws IOException {
    Log.i(TAG, "Writing trackpoints");

    //@formatter:off
    Cursor c = mDbHelper.getReadableDatabase().rawQuery(WAYPOINT_SQL_QUERY,
            new String[] { String.valueOf(mSession), String.valueOf(0) });
    //@formatter:on

    final int colLatitude = c.getColumnIndex(Schema.COL_LATITUDE);
    final int colLongitude = c.getColumnIndex(Schema.COL_LONGITUDE);
    final int colAltitude = c.getColumnIndex(Schema.COL_ALTITUDE);
    final int colTimestamp = c.getColumnIndex(Schema.COL_TIMESTAMP);

    long outer = 0;
    while (!c.isAfterLast()) {
        c.moveToFirst();
        while (!c.isAfterLast()) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("<wpt lat=\"");
            stringBuilder.append(String.valueOf(c.getDouble(colLatitude)));
            stringBuilder.append("\" ");
            stringBuilder.append("lon=\"");
            stringBuilder.append(String.valueOf(c.getDouble(colLongitude)));
            stringBuilder.append("\">");
            stringBuilder.append("<ele>");
            stringBuilder.append(String.valueOf(c.getDouble(colAltitude)));
            stringBuilder.append("</ele>");
            stringBuilder.append("<time>");
            // time stamp conversion to ISO 8601
            stringBuilder.append(getGpxDate(c.getLong(colTimestamp)));
            stringBuilder.append("</time>");
            stringBuilder.append("</wpt>");

            bw.write(stringBuilder.toString());
            bw.flush(); //in case of exception we don't lose data
            c.moveToNext();
        }

        // fetch next CURSOR_SIZE records
        outer += CURSOR_SIZE;
        c.close();

        //@formatter:off
        c = mDbHelper.getReadableDatabase().rawQuery(WAYPOINT_SQL_QUERY,
                new String[] { String.valueOf(mSession), String.valueOf(outer) });
        //@formatter:on
    }

    c.close();
}

From source file:com.aengbee.android.leanback.ui.PlaybackOverlayFragment_WebView.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    if (cursor != null && cursor.moveToFirst()) {
        switch (loader.getId()) {
        case QUEUE_VIDEOS_LOADER: {
            mQueue.clear();//  ww w .  j  ava2s .c  om
            while (!cursor.isAfterLast()) {
                Video v = (Video) mVideoCursorMapper.convert(cursor);

                // Set the queue index to the selected video.
                if (v.id == mSelectedVideo.id) {
                    mQueueIndex = mQueue.size();
                }

                // Add the video to the queue.
                MediaSessionCompat.QueueItem item = getQueueItem(v);
                mQueue.add(item);

                cursor.moveToNext();
            }

            mSession.setQueue(mQueue);
            mSession.setQueueTitle(getString(R.string.queue_name));
            break;
        }
        case RECOMMENDED_VIDEOS_LOADER: {
            mVideoCursorAdapter.changeCursor(cursor);
            break;
        }
        default: {
            // Playing a specific video.
            Video video = (Video) mVideoCursorMapper.convert(cursor);
            playVideo(video, mAutoPlayExtras);
            break;
        }
        }
    }
}

From source file:org.mozilla.gecko.sync.repositories.android.AndroidBrowserBookmarksRepositorySession.java

private String getParentName(String parentGUID) throws ParentNotFoundException, NullCursorException {
    if (parentGUID == null) {
        return "";
    }//from  ww w.  j  a  v a2 s.c o m
    if (SPECIAL_GUIDS_MAP.containsKey(parentGUID)) {
        return SPECIAL_GUIDS_MAP.get(parentGUID);
    }

    // Get parent name from database.
    String parentName = "";
    Cursor name = dataAccessor.fetch(new String[] { parentGUID });
    try {
        name.moveToFirst();
        if (!name.isAfterLast()) {
            parentName = RepoUtils.getStringFromCursor(name, BrowserContract.Bookmarks.TITLE);
        } else {
            Logger.error(LOG_TAG,
                    "Couldn't find record with guid '" + parentGUID + "' when looking for parent name.");
            throw new ParentNotFoundException(null);
        }
    } finally {
        name.close();
    }
    return parentName;
}

From source file:com.samknows.measurement.storage.DBHelper.java

private List<JSONObject> getPassiveMetrics(long test_batch_id) {
    synchronized (sync) {
        List<JSONObject> ret = new ArrayList<JSONObject>();
        open();/*  w ww. j  a  v a2s .c o  m*/
        String selection = SKSQLiteHelper.PM_COLUMN_BATCH_ID + " = " + test_batch_id;
        Cursor cursor = database.query(SKSQLiteHelper.TABLE_PASSIVEMETRIC,
                SKSQLiteHelper.TABLE_PASSIVEMETRIC_ALLCOLUMNS, selection, null, null, null, null, null);
        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
            ret.add(cursorPassiveMetricToJSONObject(cursor));
            cursor.moveToNext();
        }
        cursor.close();
        close();
        return ret;
    }
}