List of usage examples for android.database Cursor isClosed
boolean isClosed();
From source file:de.vanita5.twittnuker.activity.support.DraftsActivity.java
@Override public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) { switch (item.getItemId()) { case MENU_DELETE: { final DeleteDraftsConfirmDialogFragment f = new DeleteDraftsConfirmDialogFragment(); final Bundle args = new Bundle(); args.putLongArray(EXTRA_IDS, mListView.getCheckedItemIds()); f.setArguments(args);/*from w w w . j av a 2 s. com*/ f.show(getSupportFragmentManager(), "delete_drafts_confirm"); break; } case MENU_SEND: { final Cursor c = mAdapter.getCursor(); if (c == null || c.isClosed()) return false; final SparseBooleanArray checked = mListView.getCheckedItemPositions(); final List<DraftItem> list = new ArrayList<DraftItem>(); final DraftItem.CursorIndices indices = new DraftItem.CursorIndices(c); for (int i = 0, j = checked.size(); i < j; i++) { if (checked.valueAt(i) && c.moveToPosition(checked.keyAt(i))) { list.add(new DraftItem(c, indices)); } } if (sendDrafts(list)) { final Where where = Where.in(new Column(Drafts._ID), new RawItemArray(mListView.getCheckedItemIds())); mResolver.delete(Drafts.CONTENT_URI, where.getSQL(), null); } break; } default: { return false; } } mode.finish(); return true; }
From source file:fr.shywim.antoinedaniel.ui.fragment.VideoListFragment.java
@Override public void onLoaderReset(Loader<Cursor> loader) { Cursor oldCursor = ((CursorRecyclerAdapter) listView.getAdapter()).swapCursor(null); if (oldCursor != null && !oldCursor.isClosed()) oldCursor.close();/*ww w.j ava2 s. co m*/ ; }
From source file:tw.idv.palatis.danboorugallery.PostListActivity.java
@Override public Loader<Cursor> onCreateLoader(int id, Bundle bundle) { return new CustomTaskLoader<Cursor>(getApplicationContext()) { @Override//ww w . j av a 2 s.c om public Cursor runTaskInBackground(CancellationSignal signal) { return HostsTable.getAllHostsCursor(); } @Override public void cleanUp(Cursor oldCursor) { if (!oldCursor.isClosed()) oldCursor.close(); } }; }
From source file:org.getlantern.firetweet.activity.support.DraftsActivity.java
@Override public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) { switch (item.getItemId()) { case MENU_DELETE: { final DeleteDraftsConfirmDialogFragment f = new DeleteDraftsConfirmDialogFragment(); final Bundle args = new Bundle(); args.putLongArray(EXTRA_IDS, mListView.getCheckedItemIds()); f.setArguments(args);/*from w w w . j av a2 s. c o m*/ f.show(getSupportFragmentManager(), "delete_drafts_confirm"); break; } case MENU_SEND: { final Cursor c = mAdapter.getCursor(); if (c == null || c.isClosed()) return false; final SparseBooleanArray checked = mListView.getCheckedItemPositions(); final List<DraftItem> list = new ArrayList<>(); final DraftItem.CursorIndices indices = new DraftItem.CursorIndices(c); for (int i = 0, j = checked.size(); i < j; i++) { if (checked.valueAt(i) && c.moveToPosition(checked.keyAt(i))) { list.add(new DraftItem(c, indices)); } } if (sendDrafts(list)) { final Expression where = Expression.in(new Column(Drafts._ID), new RawItemArray(mListView.getCheckedItemIds())); mResolver.delete(Drafts.CONTENT_URI, where.getSQL(), null); } break; } default: { return false; } } mode.finish(); return true; }
From source file:com.digipom.manteresting.android.processor.json.NailsJsonProcessor.java
@Override public ArrayList<ContentProviderOperation> parse(JSONObject response, Meta meta) throws JSONException { final ArrayList<ContentProviderOperation> batch = Lists.newArrayList(); final TreeSet<Integer> nailIds = new TreeSet<Integer>(); final Cursor nails = resolver.query(ManterestingContract.Nails.CONTENT_URI, new String[] { Nails.NAIL_ID }, null, null, Nails.NAIL_ID + " DESC"); int greatestOfExisting = Integer.MIN_VALUE; if (nails != null && !nails.isClosed()) { try {//from w ww . j a v a 2 s . c om nails.moveToFirst(); final int idColumn = nails.getColumnIndex(Nails.NAIL_ID); while (!nails.isAfterLast()) { final int nailId = nails.getInt(idColumn); nailIds.add(nailId); greatestOfExisting = nailId > greatestOfExisting ? nailId : greatestOfExisting; nails.moveToNext(); } } finally { if (nails != null) { nails.close(); } } } final JSONArray objects = response.getJSONArray("objects"); int smallestOfNew = Integer.MAX_VALUE; for (int i = 0; i < objects.length(); i++) { final JSONObject nailObject = objects.getJSONObject(i); final boolean isPrivate = nailObject.getJSONObject("workbench").getBoolean("private"); if (!isPrivate) { final ContentProviderOperation.Builder builder = ContentProviderOperation .newInsert(Nails.CONTENT_URI); final int nailId = nailObject.getInt("id"); smallestOfNew = nailId < smallestOfNew ? nailId : smallestOfNew; builder.withValue(Nails.NAIL_ID, nailId); builder.withValue(Nails.NAIL_JSON, nailObject.toString()); batch.add(builder.build()); nailIds.add(nailId); } } // If more than LIMIT were fetched, and this was the initial fetch, then // we flush everything in the DB before adding the new nails (as // otherwise we would introduce a gap). if (meta.nextOffset == meta.nextLimit // For initial fetch && smallestOfNew > greatestOfExisting) { if (LoggerConfig.canLog(Log.DEBUG)) { Log.d(TAG, "Flushing all existing nails on initial fetch, so as to avoid a gap."); } resolver.delete(Nails.CONTENT_URI, null, null); } else { // If more than 500 nails, find the 500th biggest and delete those // after it. if (nailIds.size() > MAX_COUNT) { Iterator<Integer> it = nailIds.descendingIterator(); for (int i = 0; i < MAX_COUNT; i++) { it.next(); } final Integer toDelete = it.next(); if (LoggerConfig.canLog(Log.DEBUG)) { Log.d(TAG, "deleting from nails where NAIL_ID is less than or equal to " + toDelete); } SelectionBuilder selectionBuilder = new SelectionBuilder(); selectionBuilder.where(ManterestingContract.Nails.NAIL_ID + " <= ?", new String[] { String.valueOf(toDelete) }); resolver.delete(ManterestingContract.Nails.CONTENT_URI, selectionBuilder.getSelection(), selectionBuilder.getSelectionArgs()); } } return batch; }
From source file:de.questmaster.fatremote.fragments.SelectFATFragment.java
/** * Called in the closing process.//from w w w . j av a 2 s . c o m * * @see android.app.Activity#onStop() */ @Override public void onStop() { super.onStop(); Cursor cursor = mListAdapter.getCursor(); if (!cursor.isClosed()) { cursor.close(); } if (mDbHelper.isOpen()) { mDbHelper.close(); } }
From source file:de.questmaster.fatremote.fragments.SelectFATFragment.java
/** * Updates the FAT devices displayed in the ListView. Data is extracted from the database. *//*from ww w . j a va2 s . c om*/ private void updateListView() { // close old cursor Cursor oldCursor = mListAdapter.getCursor(); if (!oldCursor.isClosed()) { oldCursor.close(); } // Get all of the notes from the database and create the item list Cursor cursor = mDbHelper.fetchAllFatDevices(); mListAdapter.changeCursor(cursor); }
From source file:org.mariotaku.twidere.fragment.support.DraftsFragment.java
@Override public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) { switch (item.getItemId()) { case MENU_DELETE: { final DeleteDraftsConfirmDialogFragment f = new DeleteDraftsConfirmDialogFragment(); final Bundle args = new Bundle(); args.putLongArray(EXTRA_IDS, mListView.getCheckedItemIds()); f.setArguments(args);// ww w . j ava 2s . c om f.show(getChildFragmentManager(), "delete_drafts_confirm"); break; } case MENU_SEND: { final Cursor c = mAdapter.getCursor(); if (c == null || c.isClosed()) return false; final SparseBooleanArray checked = mListView.getCheckedItemPositions(); final List<DraftItem> list = new ArrayList<>(); final DraftItem.CursorIndices indices = new DraftItem.CursorIndices(c); for (int i = 0, j = checked.size(); i < j; i++) { if (checked.valueAt(i) && c.moveToPosition(checked.keyAt(i))) { list.add(new DraftItem(c, indices)); } } if (sendDrafts(list)) { final Expression where = Expression.in(new Column(Drafts._ID), new RawItemArray(mListView.getCheckedItemIds())); mResolver.delete(Drafts.CONTENT_URI, where.getSQL(), null); } break; } default: { return false; } } mode.finish(); return true; }
From source file:edu.mit.mobile.android.livingpostcards.CardViewFragment.java
public boolean checkAllCached() { final boolean allCached = true; if (mAdapter == null) { return false; }// w w w . j ava 2 s. c om final Cursor c = mAdapter.getCursor(); final int imgLocCol = c.getColumnIndexOrThrow(CardMedia.COL_LOCAL_URL); final int imgPubCol = c.getColumnIndexOrThrow(CardMedia.COL_MEDIA_URL); if (c == null || c.isClosed()) { return false; } for (c.moveToFirst(); c.isAfterLast(); c.moveToNext()) { String url = c.getString(imgLocCol); if (url == null) { url = c.getString(imgPubCol); } } return false; }
From source file:org.mariotaku.twidere.fragment.DraftsFragment.java
@Override public void onItemClick(final AdapterView<?> view, final View child, final int position, final long id) { final Cursor c = mAdapter.getCursor(); if (c == null || c.isClosed() || !c.moveToPosition(position)) return;/*w w w . j a va2s . c om*/ final Draft item = DraftCursorIndices.fromCursor(c); if (TextUtils.isEmpty(item.action_type)) { editDraft(item); return; } switch (item.action_type) { case "0": case "1": case Draft.Action.UPDATE_STATUS: case Draft.Action.REPLY: case Draft.Action.QUOTE: { editDraft(item); break; } } }