List of usage examples for android.database Cursor isClosed
boolean isClosed();
From source file:org.ohmage.db.DbHelper.java
/** * Swaps newCursor into the given adapter and closes the old cursor if one exists * @param adapter the adapter into which to swap the new cursor * @param newCursor the cursor to swap into the adapter *//*from w w w . j a v a2 s .c o m*/ public static void swapCursorSafe(CursorAdapter adapter, Cursor newCursor) { Cursor oldCursor = adapter.swapCursor(newCursor); if (oldCursor != null && !oldCursor.isClosed()) oldCursor.close(); }
From source file:de.ub0r.android.smsdroid.SmsReceiver.java
/** * Get unread SMS./*w w w . j a v a2 s.c om*/ * * @param cr {@link ContentResolver} to query * @param text text of the last assumed unread message * @return [thread id (-1 if there are more), number of unread messages (-1 if text does not * match newest message)] */ private static int[] getUnreadSMS(final ContentResolver cr, final String text) { Log.d(TAG, "getUnreadSMS(cr, ", text, ")"); Cursor cursor = cr.query(URI_SMS, Message.PROJECTION, Message.SELECTION_READ_UNREAD, Message.SELECTION_UNREAD, SORT); //Cursor cursor = cr.query(URI_SMS, null, null, null, null); if (cursor == null || cursor.isClosed() || cursor.getCount() == 0 || !cursor.moveToFirst()) { if (text != null) { // try again! if (cursor != null && !cursor.isClosed()) { cursor.close(); } return new int[] { -1, -1 }; } else { if (cursor != null && !cursor.isClosed()) { cursor.close(); } return new int[] { 0, 0 }; } } final String t = cursor.getString(Message.INDEX_BODY); if (text != null && (t == null || !t.startsWith(text))) { if (!cursor.isClosed()) { cursor.close(); } return new int[] { -1, -1 }; // try again! } final long d = cursor.getLong(Message.INDEX_DATE); if (d > lastUnreadDate) { lastUnreadDate = d; lastUnreadBody = t; } int tid = cursor.getInt(Message.INDEX_THREADID); while (cursor.moveToNext() && tid > -1) { // check if following messages are from the same thread if (tid != cursor.getInt(Message.INDEX_THREADID)) { tid = -1; } } final int count = cursor.getCount(); if (!cursor.isClosed()) { cursor.close(); } return new int[] { tid, count }; }
From source file:org.opensilk.video.data.VideosProviderClient.java
static void closeCursor(Cursor c) { if (c != null && !c.isClosed()) { try {/*w w w.jav a 2 s. c om*/ c.close(); } catch (Exception e) { Timber.w(e, "closeCursor()"); } } }
From source file:com.hichinaschool.flashcards.libanki.Stats.java
public static double[][] getSmallDueStats(Collection col) { ArrayList<int[]> dues = new ArrayList<int[]>(); Cursor cur = null; try {/*from w ww .j av a2s.c o m*/ cur = col.getDb().getDatabase().rawQuery("SELECT (due - " + col.getSched().getToday() + ") AS day, " // day + "count(), " // all cards + "sum(CASE WHEN ivl >= 21 THEN 1 ELSE 0 END) " // mature cards + "FROM cards WHERE did IN " + col.getSched()._deckLimit() + " AND queue IN (2,3) AND day <= 7 GROUP BY day ORDER BY day", null); while (cur.moveToNext()) { dues.add(new int[] { cur.getInt(0), cur.getInt(1), cur.getInt(2) }); } } finally { if (cur != null && !cur.isClosed()) { cur.close(); } } // small adjustment for a proper chartbuilding with achartengine if (dues.size() == 0 || dues.get(0)[0] > 0) { dues.add(0, new int[] { 0, 0, 0 }); } if (dues.get(dues.size() - 1)[0] < 7) { dues.add(new int[] { 7, 0, 0 }); } double[][] serieslist = new double[3][dues.size()]; for (int i = 0; i < dues.size(); i++) { int[] data = dues.get(i); serieslist[0][i] = data[0]; serieslist[1][i] = data[1]; serieslist[2][i] = data[2]; } return serieslist; }
From source file:org.mariotaku.twidere.adapter.TrendsAdapter.java
@Override public String getItem(int position) { final Cursor c = getCursor(); if (c != null && !c.isClosed() && c.moveToPosition(position)) return c.getString(mNameIdx); return null;// w w w .ja v a 2 s . co m }
From source file:org.alfresco.mobile.android.application.providers.search.HistorySearchInlineCursorAdapter.java
@Override protected void updateIcon(TwoLinesViewHolder vh, Cursor cursor) { if (cursor.isClosed()) { return;//from www .j a v a 2 s .co m } vh.icon.setImageResource(R.drawable.ic_clock); vh.choose.setImageResource(R.drawable.ic_item_up); vh.choose.setVisibility(View.VISIBLE); vh.choose.setTag(cursor.getLong(HistorySearchSchema.COLUMN_ID_ID)); if (frRef.get() != null && frRef.get() instanceof SearchSitesFragment) { vh.choose.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { HistorySearch history = HistorySearchManager.retrieveHistorySearch(context, (Long) v.getTag()); ((SearchSitesFragment) frRef.get()).setSearchValue(history.getQuery()); } }); } }
From source file:eu.monniot.memoArcher.loaders.SimpleCursorLoader.java
@Override public void onCanceled(Cursor cursor) { if (cursor != null && !cursor.isClosed()) cursor.close(); }
From source file:de.vanita5.twittnuker.adapter.SourceAutoCompleteAdapter.java
public boolean isCursorClosed() { final Cursor cursor = getCursor(); return cursor == null || cursor.isClosed(); }
From source file:br.com.estudio89.rv_tools.SimpleCursorLoader.java
@Override public void onCanceled(Cursor cursor) { if (cursor != null && !cursor.isClosed()) { cursor.close(); } }
From source file:com.aizak.drawnote.model.loader.SimpleCursorLoader.java
@Override public void onCanceled(Cursor cursor) { if ((cursor != null) && !cursor.isClosed()) { cursor.close(); } }