Example usage for android.database Cursor isClosed

List of usage examples for android.database Cursor isClosed

Introduction

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

Prototype

boolean isClosed();

Source Link

Document

return true if the cursor is closed

Usage

From source file:eu.inmite.apps.smsjizdenka.adapter.TicketsAdapter.java

public int getPositionForId(long id) {
    if (id == TicketsFragment.NONE) {
        return NO_SELECTION;
    }//  w  ww. j a v  a 2  s  .  co m
    Cursor cursor = getCursor();
    if (cursor.isClosed()) {
        return NO_SELECTION;
    }
    while (cursor.moveToNext()) {
        long ticketId = cursor.getLong(iId);
        if (ticketId == id) {
            return cursor.getPosition();
        }
    }
    return NO_SELECTION;
}

From source file:eu.inmite.apps.smsjizdenka.adapter.TicketsAdapter.java

/**
 * Tries to delete ticket either from swipe-to-dismiss or button.
 *
 * @return Pair of ticket id and previous status or null if it wasn't deleted.
 *///w ww. j  a  v a  2s .  c om
public Pair<Long, Integer> archiveTicket(int position) {
    Cursor cursor = getCursor();
    if (cursor.isClosed()) {
        return null;
    }
    cursor.moveToPosition(position);
    long id;
    try {
        id = cursor.getLong(iId);
    } catch (CursorIndexOutOfBoundsException e) {
        return null;
    }
    final Time validTo = FormatUtil.timeFrom3339(cursor.getString(iValidTo));
    int status = getValidityStatus(cursor.getInt(iStatus), validTo);
    if (status == Tickets.STATUS_EXPIRED) {
        ContentValues values = new ContentValues();
        values.put(TicketProvider.Tickets.STATUS, TicketProvider.Tickets.STATUS_DELETED);
        c.getContentResolver().update(ContentUris.withAppendedId(TicketProvider.Tickets.CONTENT_URI, id),
                values, null, null);
        // I had to call this deprecated method, because it needs to run synchronously. In asynchronous case, previous tickets blinks during swipe to dismiss.
        //noinspection deprecation
        getCursor().requery();
        return new Pair<Long, Integer>(id, status);
    } else {
        return null;
    }
}

From source file:com.digipom.manteresting.android.fragment.NailFragment.java

private int calculateInitialOffsetForNextFetch() {
    int offsetToReturn = -1;

    if (listView != null) {
        try {/* w w  w.java2 s . com*/
            final int listViewCount = listView.getCount();

            if (listViewCount > 2) {
                // Get the first and last nail IDs, and subtract the 2
                // to get the initial offset.
                final Cursor firstCursor = (Cursor) listView.getItemAtPosition(1);

                if (firstCursor != null && !firstCursor.isClosed()) {
                    final int columnIndex = firstCursor.getColumnIndex(Nails.NAIL_ID);
                    final int firstNailId = Integer.parseInt(firstCursor.getString(columnIndex));

                    final Cursor lastCursor = (Cursor) listView.getItemAtPosition(listViewCount - 2);
                    if (lastCursor != null && !lastCursor.isClosed()) {
                        final int lastNailId = Integer.parseInt(firstCursor.getString(columnIndex));

                        offsetForNextPage = firstNailId - lastNailId;
                        return firstNailId - lastNailId;
                    }
                }
            }
        } catch (Exception e) {
            if (LoggerConfig.canLog(Log.ERROR)) {
                Log.e(TAG, "getOffsetForNextFetch()", e);
            }
        }
    }

    return offsetToReturn;
}

From source file:net.news.inrss.fragment.EntriesListFragment.java

/**
 * Schedules all entries which are not mobilized yet, for download.
 * Then invokes download by calling FetcherService.
 *///from   w w w. j av  a2 s  . c  o m
private void downloadUnmobilitedEntries() {
    Cursor cursor = mEntriesCursorAdapter.getCursor();
    if (cursor != null && !cursor.isClosed()) {
        int mobilizedPos = cursor.getColumnIndex(EntryColumns.MOBILIZED_HTML);
        long[] entries = new long[cursor.getCount()];
        int i = 0;
        if (cursor.moveToFirst()) {
            do {
                if (cursor.isNull(mobilizedPos)) {
                    entries[i++] = cursor.getLong(0);
                    //not mobilized, yet
                    //                        entries[i++] = (Long.valueOf(cursor.getPosition()));
                }
            } while (cursor.moveToNext());
        }
        if (i > 0) {
            entries = Arrays.copyOf(entries, i);
            FetcherService.addEntriesToMobilize(entries);
            getActivity().startService(new Intent(getActivity(), FetcherService.class)
                    .setAction(FetcherService.ACTION_MOBILIZE_FEEDS));
        }
    }
}

From source file:com.digipom.manteresting.android.fragment.NailFragment.java

private boolean handleMenuItemSelected(int listItemPosition, int itemId) {
    listItemPosition -= listView.getHeaderViewsCount();

    if (listItemPosition >= 0 && listItemPosition < nailAdapter.getCount()) {
        switch (itemId) {
        case R.id.share:
            try {
                final Cursor cursor = (Cursor) nailAdapter.getItem(listItemPosition);

                if (cursor != null && !cursor.isClosed()) {
                    final int nailId = cursor.getInt(cursor.getColumnIndex(Nails.NAIL_ID));
                    final JSONObject nailJson = new JSONObject(
                            cursor.getString(cursor.getColumnIndex(Nails.NAIL_JSON)));

                    final Uri uri = MANTERESTING_SERVER.buildUpon().appendPath("nail")
                            .appendPath(String.valueOf(nailId)).build();
                    String description = nailJson.getString("description");

                    if (description.length() > 100) {
                        description = description.substring(0, 97) + '';
                    }/*from  www . j  av  a2  s . c  o m*/

                    final String user = nailJson.getJSONObject("user").getString("username");
                    final String category = nailJson.getJSONObject("workbench").getJSONObject("category")
                            .getString("title");

                    final Intent shareIntent = new Intent(Intent.ACTION_SEND);
                    shareIntent.setType("text/plain");
                    shareIntent.putExtra(Intent.EXTRA_TEXT, description + ' ' + uri.toString());
                    shareIntent.putExtra(Intent.EXTRA_SUBJECT,
                            String.format(getResources().getString(R.string.shareSubject), user, category));
                    try {
                        startActivity(Intent.createChooser(shareIntent, getText(R.string.share)));
                    } catch (ActivityNotFoundException e) {
                        new AlertDialog.Builder(getActivity()).setMessage(R.string.noShareApp).show();
                    }
                }
            } catch (Exception e) {
                if (LoggerConfig.canLog(Log.WARN)) {
                    Log.w(TAG, "Could not share nail at position " + listItemPosition + " with id " + itemId);
                }
            }

            return true;
        default:
            return false;
        }
    } else {
        return false;
    }
}

From source file:com.finchuk.clock2.data.SQLiteCursorLoader.java

@Override
public void deliverResult(C cursor) {
    if (isReset()) {
        // An async query came in while the loader is stopped
        if (cursor != null) {
            cursor.close();//from w  w w  . j  ava2s .  c o m
        }
        return;
    }
    Cursor oldCursor = mCursor;
    mCursor = cursor;

    if (isStarted()) {
        super.deliverResult(cursor);
    }

    // Close the old cursor because it is no longer needed.
    // Because an existing cursor may be cached and redelivered, it is important
    // to make sure that the old cursor and the new cursor are not the
    // same before the old cursor is closed.
    if (oldCursor != null && oldCursor != cursor && !oldCursor.isClosed()) {
        oldCursor.close();
    }
}

From source file:com.tune.news.fragment.EntriesListFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_share_starred: {
        if (mEntriesCursorAdapter != null) {
            String starredList = "";
            Cursor cursor = mEntriesCursorAdapter.getCursor();
            if (cursor != null && !cursor.isClosed()) {
                int titlePos = cursor.getColumnIndex(EntryColumns.TITLE);
                int linkPos = cursor.getColumnIndex(EntryColumns.LINK);
                if (cursor.moveToFirst()) {
                    do {
                        starredList += cursor.getString(titlePos) + "\n" + cursor.getString(linkPos) + "\n\n";
                    } while (cursor.moveToNext());
                }/*w ww  . j  a  v a2  s  .  c  o m*/
                startActivity(
                        Intent.createChooser(
                                new Intent(Intent.ACTION_SEND)
                                        .putExtra(Intent.EXTRA_SUBJECT,
                                                getString(R.string.share_favorites_title))
                                        .putExtra(Intent.EXTRA_TEXT, starredList)
                                        .setType(Constants.MIMETYPE_TEXT_PLAIN),
                                getString(R.string.menu_share)));
            }
        }
        return true;
    }
    case R.id.menu_refresh: {
        startRefresh();
        return true;
    }
    case R.id.menu_all_read: {
        if (mEntriesCursorAdapter != null) {
            mEntriesCursorAdapter.markAllAsRead(mListDisplayDate);

            // If we are on "all items" uri, we can remove the notification here
            if (mUri != null && EntryColumns.CONTENT_URI.equals(mUri) && Constants.NOTIF_MGR != null) {
                Constants.NOTIF_MGR.cancel(0);
            }
        }
        return true;
    }
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.andrew.apollo.ui.activities.SearchActivity.java

/**
 * {@inheritDoc}//from   w w  w .j a  v a 2 s  . co  m
 */
@Override
public void onLoadFinished(final Loader<Cursor> loader, final Cursor data) {
    if (data == null || data.isClosed() || data.getCount() <= 0) {
        // Set the empty text
        final TextView empty = (TextView) findViewById(R.id.empty);
        empty.setText(getString(R.string.empty_search));
        mGridView.setEmptyView(empty);
        return;
    }
    // Swap the new cursor in. (The framework will take care of closing the
    // old cursor once we return.)
    mAdapter.swapCursor(data);
}

From source file:net.etuldan.sparss.fragment.EntriesListFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_share_starred: {
        if (mEntriesCursorAdapter != null) {
            String starredList = "";
            Cursor cursor = mEntriesCursorAdapter.getCursor();
            if (cursor != null && !cursor.isClosed()) {
                int titlePos = cursor.getColumnIndex(EntryColumns.TITLE);
                int linkPos = cursor.getColumnIndex(EntryColumns.LINK);
                if (cursor.moveToFirst()) {
                    do {
                        starredList += cursor.getString(titlePos) + "\n" + cursor.getString(linkPos) + "\n\n";
                    } while (cursor.moveToNext());
                }/*  w w w .j  av  a  2s. c  o  m*/
                startActivity(
                        Intent.createChooser(
                                new Intent(Intent.ACTION_SEND)
                                        .putExtra(Intent.EXTRA_SUBJECT,
                                                getString(R.string.share_favorites_title))
                                        .putExtra(Intent.EXTRA_TEXT, starredList)
                                        .setType(Constants.MIMETYPE_TEXT_PLAIN),
                                getString(R.string.menu_share)));
            }
        }
        return true;
    }
    case R.id.menu_refresh: {
        startRefresh();
        return true;
    }
    case R.id.menu_all_read: {
        if (mEntriesCursorAdapter != null) {
            mEntriesCursorAdapter.markAllAsRead(mListDisplayDate);

            // If we are on "all items" uri, we can remove the notification here
            if (mUri != null && EntryColumns.CONTENT_URI.equals(mUri) && Constants.NOTIF_MGR != null) {
                Constants.NOTIF_MGR.cancel(0);
            }
        }
        return true;
    }
    case R.id.menu_show_new_entries: {
        if (mNewEntriesNumber == 0) {
            Toast.makeText(mListView.getContext(), R.string.no_new_entries, Toast.LENGTH_LONG).show();
        }
        menu.findItem(R.id.menu_show_new_entries).getIcon().setColorFilter(null);
        mNewEntriesNumber = 0;
        mListDisplayDate = new Date().getTime();

        refreshUI();
        if (mUri != null) {
            restartLoaders();
        }
    }
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.viktorrudometkin.burramys.fragment.EntriesListFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_share_starred: {
        if (mEntriesCursorAdapter != null) {
            String starredList = "";
            Cursor cursor = mEntriesCursorAdapter.getCursor();
            if (cursor != null && !cursor.isClosed()) {
                int titlePos = cursor.getColumnIndex(EntryColumns.TITLE);
                int linkPos = cursor.getColumnIndex(EntryColumns.LINK);
                if (cursor.moveToFirst()) {
                    do {
                        starredList += cursor.getString(titlePos) + "\n" + cursor.getString(linkPos) + "\n\n";
                    } while (cursor.moveToNext());
                }//ww  w .  j  a va 2  s  .  c o  m
                startActivity(
                        Intent.createChooser(
                                new Intent(Intent.ACTION_SEND)
                                        .putExtra(Intent.EXTRA_SUBJECT,
                                                getString(R.string.share_favorites_title))
                                        .putExtra(Intent.EXTRA_TEXT, starredList)
                                        .setType(Constants.MIMETYPE_TEXT_PLAIN),
                                getString(R.string.menu_share)));
            }
        }
        return true;
    }
    case R.id.menu_refresh: {
        startRefresh();
        return true;
    }
    }
    return super.onOptionsItemSelected(item);
}