Java Code Examples for android.database.Cursor#isLast()
The following examples show how to use
android.database.Cursor#isLast() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: operatorsDao.java From RxJavaApp with Apache License 2.0 | 6 votes |
public operators loadDeep(Long key) { assertSinglePk(); if (key == null) { return null; } StringBuilder builder = new StringBuilder(getSelectDeep()); builder.append("WHERE "); SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns()); String sql = builder.toString(); String[] keyArray = new String[] { key.toString() }; Cursor cursor = db.rawQuery(sql, keyArray); try { boolean available = cursor.moveToFirst(); if (!available) { return null; } else if (!cursor.isLast()) { throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount()); } return loadCurrentDeep(cursor, true); } finally { cursor.close(); } }
Example 2
Source File: StudentImageCollectionEventDao.java From ml-authentication with Apache License 2.0 | 6 votes |
public StudentImageCollectionEvent loadDeep(Long key) { assertSinglePk(); if (key == null) { return null; } StringBuilder builder = new StringBuilder(getSelectDeep()); builder.append("WHERE "); SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns()); String sql = builder.toString(); String[] keyArray = new String[] { key.toString() }; Cursor cursor = db.rawQuery(sql, keyArray); try { boolean available = cursor.moveToFirst(); if (!available) { return null; } else if (!cursor.isLast()) { throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount()); } return loadCurrentDeep(cursor, true); } finally { cursor.close(); } }
Example 3
Source File: StudentImageDao.java From ml-authentication with Apache License 2.0 | 6 votes |
public StudentImage loadDeep(Long key) { assertSinglePk(); if (key == null) { return null; } StringBuilder builder = new StringBuilder(getSelectDeep()); builder.append("WHERE "); SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns()); String sql = builder.toString(); String[] keyArray = new String[] { key.toString() }; Cursor cursor = db.rawQuery(sql, keyArray); try { boolean available = cursor.moveToFirst(); if (!available) { return null; } else if (!cursor.isLast()) { throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount()); } return loadCurrentDeep(cursor, true); } finally { cursor.close(); } }
Example 4
Source File: StudentImageCollectionEventDao.java From ml-authentication with Apache License 2.0 | 6 votes |
public StudentImageCollectionEvent loadDeep(Long key) { assertSinglePk(); if (key == null) { return null; } StringBuilder builder = new StringBuilder(getSelectDeep()); builder.append("WHERE "); SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns()); String sql = builder.toString(); String[] keyArray = new String[] { key.toString() }; Cursor cursor = db.rawQuery(sql, keyArray); try { boolean available = cursor.moveToFirst(); if (!available) { return null; } else if (!cursor.isLast()) { throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount()); } return loadCurrentDeep(cursor, true); } finally { cursor.close(); } }
Example 5
Source File: StoryBookDao.java From ml-authentication with Apache License 2.0 | 6 votes |
public StoryBook loadDeep(Long key) { assertSinglePk(); if (key == null) { return null; } StringBuilder builder = new StringBuilder(getSelectDeep()); builder.append("WHERE "); SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns()); String sql = builder.toString(); String[] keyArray = new String[] { key.toString() }; Cursor cursor = db.rawQuery(sql, keyArray); try { boolean available = cursor.moveToFirst(); if (!available) { return null; } else if (!cursor.isLast()) { throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount()); } return loadCurrentDeep(cursor, true); } finally { cursor.close(); } }
Example 6
Source File: StudentImageDao.java From ml-authentication with Apache License 2.0 | 6 votes |
public StudentImage loadDeep(Long key) { assertSinglePk(); if (key == null) { return null; } StringBuilder builder = new StringBuilder(getSelectDeep()); builder.append("WHERE "); SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns()); String sql = builder.toString(); String[] keyArray = new String[] { key.toString() }; Cursor cursor = db.rawQuery(sql, keyArray); try { boolean available = cursor.moveToFirst(); if (!available) { return null; } else if (!cursor.isLast()) { throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount()); } return loadCurrentDeep(cursor, true); } finally { cursor.close(); } }
Example 7
Source File: CollectEntityDao.java From MeiZiNews with MIT License | 6 votes |
public CollectEntity loadDeep(Long key) { assertSinglePk(); if (key == null) { return null; } StringBuilder builder = new StringBuilder(getSelectDeep()); builder.append("WHERE "); SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns()); String sql = builder.toString(); String[] keyArray = new String[] { key.toString() }; Cursor cursor = db.rawQuery(sql, keyArray); try { boolean available = cursor.moveToFirst(); if (!available) { return null; } else if (!cursor.isLast()) { throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount()); } return loadCurrentDeep(cursor, true); } finally { cursor.close(); } }
Example 8
Source File: ImageTask.java From boxing with Apache License 2.0 | 6 votes |
private void queryThumbnails(ContentResolver cr, String[] projection) { Cursor cur = null; try { cur = Images.Thumbnails.queryMiniThumbnails(cr, Images.Thumbnails.EXTERNAL_CONTENT_URI, Images.Thumbnails.MINI_KIND, projection); if (cur != null && cur.moveToFirst()) { do { String imageId = cur.getString(cur.getColumnIndex(Images.Thumbnails.IMAGE_ID)); String imagePath = cur.getString(cur.getColumnIndex(Images.Thumbnails.DATA)); mThumbnailMap.put(imageId, imagePath); } while (cur.moveToNext() && !cur.isLast()); } } finally { if (cur != null) { cur.close(); } } }
Example 9
Source File: ContactDao.java From AndroidDatabaseLibraryComparison with MIT License | 6 votes |
public Contact loadDeep(Long key) { assertSinglePk(); if (key == null) { return null; } StringBuilder builder = new StringBuilder(getSelectDeep()); builder.append("WHERE "); SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns()); String sql = builder.toString(); String[] keyArray = new String[] { key.toString() }; Cursor cursor = db.rawQuery(sql, keyArray); try { boolean available = cursor.moveToFirst(); if (!available) { return null; } else if (!cursor.isLast()) { throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount()); } return loadCurrentDeep(cursor, true); } finally { cursor.close(); } }
Example 10
Source File: UserDao.java From BrainPhaser with GNU General Public License v3.0 | 6 votes |
public User loadDeep(Long key) { assertSinglePk(); if (key == null) { return null; } StringBuilder builder = new StringBuilder(getSelectDeep()); builder.append("WHERE "); SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns()); String sql = builder.toString(); String[] keyArray = new String[] { key.toString() }; Cursor cursor = db.rawQuery(sql, keyArray); try { boolean available = cursor.moveToFirst(); if (!available) { return null; } else if (!cursor.isLast()) { throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount()); } return loadCurrentDeep(cursor, true); } finally { cursor.close(); } }
Example 11
Source File: StoryBookDao.java From ml-authentication with Apache License 2.0 | 6 votes |
public StoryBook loadDeep(Long key) { assertSinglePk(); if (key == null) { return null; } StringBuilder builder = new StringBuilder(getSelectDeep()); builder.append("WHERE "); SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns()); String sql = builder.toString(); String[] keyArray = new String[] { key.toString() }; Cursor cursor = db.rawQuery(sql, keyArray); try { boolean available = cursor.moveToFirst(); if (!available) { return null; } else if (!cursor.isLast()) { throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount()); } return loadCurrentDeep(cursor, true); } finally { cursor.close(); } }
Example 12
Source File: ContentProviderLocationDAO.java From background-geolocation-android with Apache License 2.0 | 5 votes |
@Override public BackgroundLocation getFirstUnpostedLocation() { SqlSelectStatement subsql = new SqlSelectStatement(); subsql.column(new SqlExpression(String.format("MIN(%s)", LocationEntry._ID)), LocationEntry._ID); subsql.from(LocationEntry.TABLE_NAME); subsql.where(LocationEntry.COLUMN_NAME_STATUS, SqlExpression.SqlOperatorEqualTo, BackgroundLocation.POST_PENDING); subsql.orderBy(LocationEntry.COLUMN_NAME_TIME); String substmt = subsql.statement(); substmt = com.marianhello.utils.TextUtils.removeLastChar(substmt, ";"); BackgroundLocation location = null; Cursor cursor = null; try { cursor = mResolver.query( mContentUri, null, LocationEntry._ID + " = (" + substmt + ")", null, null ); while (cursor.moveToNext()) { location = BackgroundLocation.fromCursor(cursor); if (!cursor.isLast()) { throw new RuntimeException("Expected single location"); } } } finally { if (cursor != null) { cursor.close(); } } return location; }
Example 13
Source File: ImageTask.java From boxing with Apache License 2.0 | 5 votes |
private void addItem(final int allCount, final List<ImageMedia> result, Cursor cursor, @NonNull final IMediaTaskCallback<ImageMedia> callback) { if (cursor != null && cursor.moveToFirst()) { do { String picPath = cursor.getString(cursor.getColumnIndex(Images.Media.DATA)); if (callback.needFilter(picPath)) { BoxingLog.d("path:" + picPath + " has been filter"); } else { String id = cursor.getString(cursor.getColumnIndex(Images.Media._ID)); String size = cursor.getString(cursor.getColumnIndex(Images.Media.SIZE)); String mimeType = cursor.getString(cursor.getColumnIndex(Images.Media.MIME_TYPE)); int width = 0; int height = 0; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { width = cursor.getInt(cursor.getColumnIndex(Images.Media.WIDTH)); height = cursor.getInt(cursor.getColumnIndex(Images.Media.HEIGHT)); } ImageMedia imageItem = new ImageMedia.Builder(id, picPath).setThumbnailPath(mThumbnailMap.get(id)) .setSize(size).setMimeType(mimeType).setHeight(height).setWidth(width).build(); if (!result.contains(imageItem)) { result.add(imageItem); } } } while (!cursor.isLast() && cursor.moveToNext()); postMedias(result, allCount, callback); } else { postMedias(result, 0, callback); } clear(); }
Example 14
Source File: VideoTask.java From boxing with Apache License 2.0 | 5 votes |
private void loadVideos(ContentResolver cr, int page, @NonNull final IMediaTaskCallback<VideoMedia> callback) { final List<VideoMedia> videoMedias = new ArrayList<>(); final Cursor cursor = cr.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, MEDIA_COL, null, null, MediaStore.Images.Media.DATE_MODIFIED + " desc" + " LIMIT " + page * IMediaTask.PAGE_LIMIT + " , " + IMediaTask.PAGE_LIMIT); try { int count = 0; if (cursor != null && cursor.moveToFirst()) { count = cursor.getCount(); do { String data = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.DATA)); String id = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media._ID)); String title = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.TITLE)); String type = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.MIME_TYPE)); String size = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.SIZE)); String date = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.DATE_TAKEN)); String duration = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.DURATION)); VideoMedia video = new VideoMedia.Builder(id, data).setTitle(title).setDuration(duration) .setSize(size).setDataTaken(date).setMimeType(type).build(); videoMedias.add(video); } while (!cursor.isLast() && cursor.moveToNext()); postMedias(callback, videoMedias, count); } else { postMedias(callback, videoMedias, 0); } } finally { if (cursor != null) { cursor.close(); } } }
Example 15
Source File: CallLogAdapter.java From CSipSimple with GNU General Public License v3.0 | 5 votes |
/** Returns true if this is the last item of a section. */ private boolean isLastOfSection(Cursor c) { if (c.isLast()) { return true; } return false; }
Example 16
Source File: SQLiteLocationDAO.java From background-geolocation-android with Apache License 2.0 | 5 votes |
public BackgroundLocation getNextUnpostedLocation(long fromId) { SqlSelectStatement subsql = new SqlSelectStatement(); subsql.column(new SqlExpression(String.format("MIN(%s)", LocationEntry._ID)), LocationEntry._ID); subsql.from(LocationEntry.TABLE_NAME); subsql.where(LocationEntry.COLUMN_NAME_STATUS, SqlExpression.SqlOperatorEqualTo, BackgroundLocation.POST_PENDING); subsql.where(LocationEntry._ID, SqlExpression.SqlOperatorNotEqualTo, fromId); subsql.orderBy(LocationEntry.COLUMN_NAME_TIME); SqlSelectStatement sql = new SqlSelectStatement(); sql.columns(queryColumns()); sql.from(LocationEntry.TABLE_NAME); sql.where(LocationEntry._ID, SqlExpression.SqlOperatorEqualTo, subsql); BackgroundLocation location = null; Cursor cursor = null; try { cursor = db.rawQuery(sql.statement(), new String[]{}); while (cursor.moveToNext()) { location = hydrate(cursor); if (!cursor.isLast()) { throw new RuntimeException("Expected single location"); } } } finally { if (cursor != null) { cursor.close(); } } return location; }
Example 17
Source File: AbstractDao.java From MiBandDecompiled with Apache License 2.0 | 5 votes |
protected Object loadUnique(Cursor cursor) { if (!cursor.moveToFirst()) { return null; } if (!cursor.isLast()) { throw new DaoException((new StringBuilder()).append("Expected unique result, but count was ").append(cursor.getCount()).toString()); } else { return loadCurrent(cursor, 0, true); } }
Example 18
Source File: ContentProviderLocationDAO.java From background-geolocation-android with Apache License 2.0 | 5 votes |
@Override public BackgroundLocation getNextUnpostedLocation(long fromId) { SqlSelectStatement subsql = new SqlSelectStatement(); subsql.column(new SqlExpression(String.format("MIN(%s)", LocationEntry._ID)), LocationEntry._ID); subsql.from(LocationEntry.TABLE_NAME); subsql.where(LocationEntry.COLUMN_NAME_STATUS, SqlExpression.SqlOperatorEqualTo, BackgroundLocation.POST_PENDING); subsql.where(LocationEntry._ID, SqlExpression.SqlOperatorNotEqualTo, fromId); subsql.orderBy(LocationEntry.COLUMN_NAME_TIME); String substmt = subsql.statement(); substmt = com.marianhello.utils.TextUtils.removeLastChar(substmt, ";"); BackgroundLocation location = null; Cursor cursor = null; try { cursor = mResolver.query( mContentUri, null, LocationEntry._ID + " = (" + substmt + ")", null, null ); while (cursor.moveToNext()) { location = BackgroundLocation.fromCursor(cursor); if (!cursor.isLast()) { throw new RuntimeException("Expected single location"); } } } finally { if (cursor != null) { cursor.close(); } } return location; }
Example 19
Source File: ContentProviderLocationDAO.java From background-geolocation-android with Apache License 2.0 | 5 votes |
@Override public BackgroundLocation getLocationById(long id) { BackgroundLocation location = null; Cursor cursor = null; try { cursor = mResolver.query( LocationContentProvider.buildUriWithId(mAuthority, id), null, null, null, null ); while (cursor.moveToNext()) { location = BackgroundLocation.fromCursor(cursor); if (!cursor.isLast()) { throw new RuntimeException("Location " + id + " is not unique"); } } } finally { if (cursor != null) { cursor.close(); } } return location; }
Example 20
Source File: GoogleCalendarService.java From Speculum-Android with MIT License | 4 votes |
@SuppressWarnings("all") public Observable<String> getCalendarEvents() { String details, title; Cursor cursor; ContentResolver contentResolver = application.getContentResolver(); final String[] colsToQuery = new String[]{ CalendarContract.EventsEntity.TITLE, CalendarContract.EventsEntity.DTSTART, CalendarContract.EventsEntity.DTEND, CalendarContract.EventsEntity.EVENT_LOCATION}; Calendar now = Calendar.getInstance(); SimpleDateFormat startFormat = new SimpleDateFormat(Constants.SIMPLEDATEFORMAT_DDMMYY, Locale.getDefault()); String dateString = startFormat.format(now.getTime()); long start = now.getTimeInMillis(); SimpleDateFormat endFormat = new SimpleDateFormat(Constants.SIMPLEDATEFORMAT_HHMMSSDDMMYY, Locale.getDefault()); Calendar endOfDay = Calendar.getInstance(); Date endOfDayDate; try { endOfDayDate = endFormat.parse(Constants.END_OF_DAY_TIME + dateString); endOfDay.setTime(endOfDayDate); } catch (ParseException e) { Log.e(GoogleCalendarService.class.getSimpleName(), e.toString()); throw new RuntimeException(String.format("ParseException occured: %s", e.getLocalizedMessage())); } cursor = contentResolver.query(CalendarContract.Events.CONTENT_URI, colsToQuery, Constants.CALENDAR_QUERY_FIRST + start + Constants.CALENDAR_QUERY_SECOND + endOfDay.getTimeInMillis() + Constants.CALENDAR_QUERY_THIRD, null, Constants.CALENDAR_QUERY_FOURTH); if (cursor != null) { if (cursor.getCount() > 0) { StringBuilder stringBuilder = new StringBuilder(); while (cursor.moveToNext()) { title = cursor.getString(0); Calendar startTime = Calendar.getInstance(); startTime.setTimeInMillis(cursor.getLong(1)); Calendar endTime = Calendar.getInstance(); endTime.setTimeInMillis(cursor.getLong(2)); DateFormat formatter = SimpleDateFormat.getTimeInstance(DateFormat.SHORT); details = formatter.format(startTime.getTime()) + " - " + formatter.format(endTime.getTime()); if (!TextUtils.isEmpty(cursor.getString(3))) { details += " " + application.getString(R.string.at) + " " + cursor.getString(3); } stringBuilder.append(title + ", " + details); if (!cursor.isLast()) { stringBuilder.append(" | "); } } cursor.close(); return Observable.just(stringBuilder.toString()); } else { cursor.close(); return Observable.just(application.getString(R.string.no_events_today)); } } else { throw new RuntimeException(application.getString(R.string.no_events_error)); } }