List of usage examples for android.database Cursor isClosed
boolean isClosed();
From source file:org.fitchfamily.android.wifi_backend.ui.data.CursorLoader.java
@Override public void deliverResult(Cursor cursor) { if (isReset()) { if (cursor != null) { cursor.close();/*from w w w . j a va2 s. co m*/ } } else { Cursor oldCursor = this.cursor; this.cursor = cursor; if (isStarted()) { super.deliverResult(cursor); } if (oldCursor != null && !oldCursor.isClosed()) { oldCursor.close(); } } }
From source file:com.github.monxalo.android.widget.SectionCursorAdapter.java
private void calculateSectionHeaders() { int i = 0;//from ww w .j a va2 s. co m String previous = ""; int count = 0; final Cursor c = getCursor(); mSectionsIndexer.clear(); if (c == null || c.isClosed()) { return; } c.moveToPosition(-1); while (c.moveToNext()) { final String group = getCustomGroup(c); if (!previous.equals(group)) { mSectionsIndexer.put(i + count, group); previous = group; if (LOGV) Log.v(TAG, "Group " + group + "at position: " + (i + count)); count++; } i++; } }
From source file:org.alfresco.mobile.android.application.fragments.site.search.SearchSitesFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { if (!data.isClosed()) { searchAdapter.changeCursor(data); }/* w ww .j a v a 2s. co m*/ // searchText.setAdapter(searchAdapter); }
From source file:hoahong.facebook.messenger.ui.android.BrowseImageActivity.java
public void setCursor(Cursor cursor) { if (cursorLoaded == false) { if (cursor != null && cursor.isClosed() == false) { this.cursor = cursor; this.cursorCount = cursor.getCount(); loadPhotos(0);/*from ww w. j a va 2 s.c o m*/ } } cursorLoaded = true; }
From source file:org.opendatakit.common.android.database.DataModelDatabaseHelper.java
/** * Accessor to retrieve the database tableId given a formId * * @param db//w w w . jav a 2 s .com * @param formId * -- either the integer _ID or the textual form_id * @return */ public static IdInstanceNameStruct getIds(SQLiteDatabase db, String formId) { boolean isNumericId = StringUtils.isNumeric(formId); Cursor c = null; try { c = db.query(FORMS_TABLE_NAME, new String[] { FormsColumns._ID, FormsColumns.FORM_ID, FormsColumns.TABLE_ID, FormsColumns.INSTANCE_NAME }, (isNumericId ? FormsColumns._ID : FormsColumns.FORM_ID) + "=?", new String[] { formId }, null, null, null); if (c.moveToFirst()) { int idxId = c.getColumnIndex(FormsColumns._ID); int idxFormId = c.getColumnIndex(FormsColumns.FORM_ID); int idxTableId = c.getColumnIndex(FormsColumns.TABLE_ID); int idxInstanceName = c.getColumnIndex(FormsColumns.INSTANCE_NAME); return new IdInstanceNameStruct(c.getInt(idxId), c.getString(idxFormId), c.getString(idxTableId), c.isNull(idxInstanceName) ? null : c.getString(idxInstanceName)); } } finally { if (c != null && !c.isClosed()) { c.close(); } } return null; }
From source file:se.chalmers.watchme.database.GenericCursorLoader.java
@Override public void deliverResult(Cursor cursor) { if (isReset()) { // An async query came in while the loader is stopped if (cursor != null) { cursor.close();/* ww w.j a va 2 s .co m*/ } return; } Cursor oldCursor = mCursor; mCursor = cursor; if (isStarted()) { super.deliverResult(cursor); } if (oldCursor != null && oldCursor != cursor && !oldCursor.isClosed()) { oldCursor.close(); } }
From source file:de.vanita5.twittnuker.activity.support.DraftsActivity.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;/*from w w w. j a v a 2 s.c o m*/ final DraftItem item = new DraftItem(c, new DraftItem.CursorIndices(c)); if (item.action_type == Drafts.ACTION_UPDATE_STATUS || item.action_type <= 0) { editDraft(item); } }
From source file:com.example.iotalk.ObjectCursorLoader.java
@Override public void deliverResult(ObjectCursor<T> cursor) { if (isReset()) { // An async query came in while the loader is stopped if (cursor != null) { cursor.close();//from w w w. j av a 2 s .c o m } return; } final Cursor oldCursor = mCursor; mCursor = cursor; if (isStarted()) { super.deliverResult(cursor); } if (oldCursor != null && oldCursor != cursor && !oldCursor.isClosed()) { oldCursor.close(); } }
From source file:br.com.cybereagle.androidlibrary.loader.ObjectCollectorLoader.java
@Override protected void deliverCarrierAndCloseOldCursor(LoadedObject<T> loadedObject) { if (collectOnUIThread) { cursorToObjectCollector.collect(loadedObject.getObject(), loadedObject.getCursor()); }// ww w.ja va 2 s. c o m Cursor oldCursor = this.loadedObject.getCursor(); this.loadedObject.setCursor(loadedObject.getCursor()); if (!loadedFirstTime) { loadedFirstTime = true; } if (oldCursor != null && oldCursor != this.loadedObject.getCursor() && !oldCursor.isClosed()) { oldCursor.close(); } }
From source file:saschpe.birthdays.service.CalendarSyncService.java
private static Cursor getContactsEvents(Context context, ContentResolver contentResolver) { // Account blacklist from our provider List<Account> accountBlacklist = AccountProviderHelper.getAccountList(context); List<String> addedEventsIdentifiers = new ArrayList<>(); /* 1. Get all raw contacts with their corresponding Account name and type (only raw * contacts get Account affiliation) */ Uri rawContactsUri = ContactsContract.RawContacts.CONTENT_URI; String[] rawContactsProjection = new String[] { ContactsContract.RawContacts._ID, ContactsContract.RawContacts.CONTACT_ID, ContactsContract.RawContacts.DISPLAY_NAME_PRIMARY, ContactsContract.RawContacts.ACCOUNT_NAME, ContactsContract.RawContacts.ACCOUNT_TYPE }; Cursor rawContacts = contentResolver.query(rawContactsUri, rawContactsProjection, null, null, null); /* 2. Go over all raw contacts and check if the Account is allowed. If account is allowed, * get display name and lookup key and all events for this contact. Build a new * MatrixCursor out of this data that can be used. */ String[] columns = new String[] { BaseColumns._ID, ContactsContract.Data.DISPLAY_NAME, ContactsContract.Data.LOOKUP_KEY, ContactsContract.CommonDataKinds.Event.START_DATE, ContactsContract.CommonDataKinds.Event.TYPE, ContactsContract.CommonDataKinds.Event.LABEL, }; MatrixCursor mc = new MatrixCursor(columns); int mcIndex = 0; try {//from ww w .j ava 2s. c om while (rawContacts != null && rawContacts.moveToNext()) { long rawId = rawContacts.getLong(rawContacts.getColumnIndex(ContactsContract.RawContacts._ID)); String accountType = rawContacts .getString(rawContacts.getColumnIndex(ContactsContract.RawContacts.ACCOUNT_TYPE)); String accountName = rawContacts .getString(rawContacts.getColumnIndex(ContactsContract.RawContacts.ACCOUNT_NAME)); // 2a. Check if Account is allowed (not in blacklist) boolean addEvent; if (TextUtils.isEmpty(accountType) || TextUtils.isEmpty(accountName)) { // Workaround: Simply add events without proper Account addEvent = true; } else { Account account = new Account(accountName, accountType); addEvent = !accountBlacklist.contains(account); } if (addEvent) { String displayName = null; String lookupKey = null; // 2b. Get display name and lookup key from normal contact table String[] displayProjection = new String[] { ContactsContract.Data.RAW_CONTACT_ID, ContactsContract.Data.DISPLAY_NAME, ContactsContract.Data.LOOKUP_KEY }; String displayWhere = ContactsContract.Data.RAW_CONTACT_ID + "= ?"; String[] displaySelectionArgs = new String[] { String.valueOf(rawId) }; Cursor displayCursor = contentResolver.query(ContactsContract.Data.CONTENT_URI, displayProjection, displayWhere, displaySelectionArgs, null); try { if (displayCursor != null && displayCursor.moveToNext()) { displayName = displayCursor .getString(displayCursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME)); lookupKey = displayCursor .getString(displayCursor.getColumnIndex(ContactsContract.Data.LOOKUP_KEY)); } } finally { if (displayCursor != null && !displayCursor.isClosed()) { displayCursor.close(); } } /* 2c. Get all events for this raw contact. We don't get this information for * the (merged) contact table, but from the raw contact. If we would query * this information from the contact table, we would also get events that * should have been filtered. */ Uri thisRawContactUri = ContentUris.withAppendedId(ContactsContract.RawContacts.CONTENT_URI, rawId); Uri entityUri = Uri.withAppendedPath(thisRawContactUri, ContactsContract.RawContacts.Entity.CONTENT_DIRECTORY); String[] eventsProjection = new String[] { ContactsContract.RawContacts._ID, ContactsContract.RawContacts.Entity.DATA_ID, ContactsContract.CommonDataKinds.Event.START_DATE, ContactsContract.CommonDataKinds.Event.TYPE, ContactsContract.CommonDataKinds.Event.LABEL }; String eventsWhere = ContactsContract.RawContacts.Entity.MIMETYPE + " = ? AND " + ContactsContract.RawContacts.Entity.DATA_ID + " IS NOT NULL"; String[] eventsSelectionArgs = new String[] { ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE }; Cursor eventsCursor = contentResolver.query(entityUri, eventsProjection, eventsWhere, eventsSelectionArgs, null); try { while (eventsCursor != null && eventsCursor.moveToNext()) { String startDate = eventsCursor.getString( eventsCursor.getColumnIndex(ContactsContract.CommonDataKinds.Event.START_DATE)); int type = eventsCursor.getInt( eventsCursor.getColumnIndex(ContactsContract.CommonDataKinds.Event.TYPE)); String label = eventsCursor.getString( eventsCursor.getColumnIndex(ContactsContract.CommonDataKinds.Event.LABEL)); /* 2d. Add this information to our MatrixCursor if not already added * previously. If two Event Reminder accounts have the same contact * with duplicated events, the event will already be in the HashSet * addedEventsIdentifiers. * * eventIdentifier does not include startDate, because the * String formats of startDate differ between accounts. */ //String eventIdentifier = lookupKey + type + label; String eventIdentifier = lookupKey + type; if (addedEventsIdentifiers.contains(eventIdentifier)) { Log.d(TAG, "Duplicate event was not added!"); } else { Log.d(TAG, "Event was added with identifier " + eventIdentifier); addedEventsIdentifiers.add(eventIdentifier); mc.newRow().add(mcIndex).add(displayName).add(lookupKey).add(startDate).add(type) .add(label); mcIndex++; } } } finally { if (eventsCursor != null && !eventsCursor.isClosed()) { eventsCursor.close(); } } } } } finally { if (rawContacts != null && !rawContacts.isClosed()) { rawContacts.close(); } } /*if (BuildConfig.DEBUG) { DatabaseUtils.dumpCursor(mc); }*/ return mc; }