List of usage examples for android.database Cursor isClosed
boolean isClosed();
From source file:com.android.mail.photo.MailPhotoViewController.java
private List<Attachment> getAllAttachments() { final Cursor cursor = getCursor(); if (cursor == null || cursor.isClosed() || !cursor.moveToFirst()) { return null; }/*from ww w.j a v a2s . com*/ List<Attachment> list = Lists.newArrayList(); do { list.add(new Attachment(cursor)); } while (cursor.moveToNext()); return list; }
From source file:org.mariotaku.twidere.fragment.DraftsFragment.java
@Override public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) { switch (item.getItemId()) { case R.id.delete: { final DeleteDraftsConfirmDialogFragment f = new DeleteDraftsConfirmDialogFragment(); final Bundle args = new Bundle(); args.putLongArray(EXTRA_IDS, mListView.getCheckedItemIds()); f.setArguments(args);//from w ww .j ava 2s . co m f.show(getChildFragmentManager(), "delete_drafts_confirm"); break; } case R.id.send: { final Cursor c = mAdapter.getCursor(); if (c == null || c.isClosed()) return false; final SparseBooleanArray checked = mListView.getCheckedItemPositions(); final List<Draft> list = new ArrayList<>(); final DraftCursorIndices indices = new DraftCursorIndices(c); for (int i = 0, j = checked.size(); i < j; i++) { if (checked.valueAt(i) && c.moveToPosition(checked.keyAt(i))) { list.add(indices.newObject(c)); } } 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:org.getlantern.firetweet.fragment.CustomTabsFragment.java
private void saveTabPositions() { final ArrayList<Integer> positions = mAdapter.getCursorPositions(); final Cursor c = mAdapter.getCursor(); if (positions != null && c != null && !c.isClosed()) { final int idIdx = c.getColumnIndex(Tabs._ID); for (int i = 0, j = positions.size(); i < j; i++) { c.moveToPosition(positions.get(i)); final long id = c.getLong(idIdx); final ContentValues values = new ContentValues(); values.put(Tabs.POSITION, i); final String where = Expression.equals(Tabs._ID, id).getSQL(); mResolver.update(Tabs.CONTENT_URI, values, where, null); }// w ww. j av a 2s. co m } SettingsActivity.setShouldNotifyChange(getActivity()); }
From source file:com.android.calendar.selectcalendars.SelectSyncedCalendarsMultiAccountAdapter.java
public void closeChildrenCursors() { synchronized (mChildrenCursors) { for (String key : mChildrenCursors.keySet()) { Cursor cursor = mChildrenCursors.get(key); if (!cursor.isClosed()) { cursor.close();//ww w . java 2 s . c o m } } mChildrenCursors.clear(); mClosedCursorsFlag = true; } }
From source file:com.android.contacts.list.MultiSelectContactsListFragment.java
private SearchState createSearchState(int selectedPosition) { final MultiSelectEntryContactListAdapter adapter = getAdapter(); if (adapter == null) { return null; }//from w w w . j av a 2 s . c o m final SearchState searchState = new SearchState(); searchState.queryLength = adapter.getQueryString() == null ? 0 : adapter.getQueryString().length(); searchState.numPartitions = adapter.getPartitionCount(); // Set the number of results displayed to the user. Note that the adapter.getCount(), // value does not always match the number of results actually displayed to the user, // which is why we calculate it manually. final List<Integer> numResultsInEachPartition = new ArrayList<>(); for (int i = 0; i < adapter.getPartitionCount(); i++) { final Cursor cursor = adapter.getCursor(i); if (cursor == null || cursor.isClosed()) { // Something went wrong, abort. numResultsInEachPartition.clear(); break; } numResultsInEachPartition.add(cursor.getCount()); } if (!numResultsInEachPartition.isEmpty()) { int numResults = 0; for (int i = 0; i < numResultsInEachPartition.size(); i++) { numResults += numResultsInEachPartition.get(i); } searchState.numResults = numResults; } // If a selection was made, set additional search state if (selectedPosition >= 0) { searchState.selectedPartition = adapter.getPartitionForPosition(selectedPosition); searchState.selectedIndexInPartition = adapter.getOffsetInPartition(selectedPosition); final Cursor cursor = adapter.getCursor(searchState.selectedPartition); searchState.numResultsInSelectedPartition = cursor == null || cursor.isClosed() ? -1 : cursor.getCount(); // Calculate the index across all partitions if (!numResultsInEachPartition.isEmpty()) { int selectedIndex = 0; for (int i = 0; i < searchState.selectedPartition; i++) { selectedIndex += numResultsInEachPartition.get(i); } selectedIndex += searchState.selectedIndexInPartition; searchState.selectedIndex = selectedIndex; } } return searchState; }
From source file:net.niyonkuru.koodroid.ui.DataDetailFragment.java
private XYMultipleSeriesDataset getBarDataset(Cursor cursor, int x, int maxX) { XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset(); XYSeries series = new XYSeries(null); Calendar cal = Calendar.getInstance(); CalendarUtils.trimTimestamp(cal);// w w w. ja v a 2s.c om if (cursor.isClosed() || !cursor.moveToFirst()) return null; while (x <= maxX) { double count = 0; if (!cursor.isAfterLast()) { /* cursor has data */ Date rowDate = new Date(cal.getTimeInMillis()); Date currDate = Date.valueOf(cursor.getString(UsagesQuery.DATE)); if (rowDate.equals(currDate)) { count = cursor.getDouble(UsagesQuery.COUNT); cursor.moveToNext(); } } cal.add(Calendar.DAY_OF_YEAR, -1); series.add(x++, count); } dataset.addSeries(series); return dataset; }
From source file:de.k3b.android.androFotoFinder.imagedetail.ImagePagerAdapterFromCursor.java
/** debug support for logging current cursor content */ private String debugCursor(Cursor cursor, int maxRows, String delim, String... colmnNames) { StringBuilder result = new StringBuilder(); if ((cursor != null) && (!cursor.isClosed())) { int oldPosition = cursor.getPosition(); int last = Math.min(maxRows - 1, cursor.getCount() - 1); for (int position = 0; position <= last; position++) { result.append("#").append(position); cursor.moveToPosition(position); for (String col : colmnNames) { result.append(";").append(cursor.getString(cursor.getColumnIndex(col))); }/*w ww. j ava 2 s. c o m*/ result.append(delim); } } return result.toString(); }
From source file:com.android.contacts.common.list.PhoneNumberPickerFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { super.onLoadFinished(loader, data); // disable scroll bar if there is no data setVisibleScrollbarEnabled(data != null && !data.isClosed() && data.getCount() > 0); }
From source file:eu.inmite.apps.smsjizdenka.adapter.TicketsAdapter.java
public void showSms(int position) { //SL.get(AnalyticsService.class).trackEvent("show-sms", "my-tickets"); Cursor cursor = getCursor(); if (cursor.isClosed()) { return;//w w w .ja v a2 s.c om } cursor.moveToPosition(position); String text = cursor.getString(iText); long cityId = cursor.getLong(iCityId); ShowSmsDialogFragment.newInstance(text, cityId).show(mFragment.getFragmentManager(), ShowSmsDialogFragment.TAG); }
From source file:eu.inmite.apps.smsjizdenka.adapter.TicketsAdapter.java
private void deleteTicket(int position) { //SL.get(AnalyticsService.class).trackEvent("delete", "my-tickets"); Cursor cursor = getCursor(); if (cursor.isClosed()) { return;/*from w w w . jav a 2 s. co m*/ } cursor.moveToPosition(position); long id; try { id = cursor.getLong(iId); } catch (CursorIndexOutOfBoundsException e) { return; } c.getContentResolver().delete(ContentUris.withAppendedId(Tickets.CONTENT_URI, id), null, null); getCursor().requery(); }