Java Code Examples for android.database.Cursor.isLast()

The following are Jave code examples for showing how to use isLast() of the android.database.Cursor class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: chat-sdk-android-push-firebase   File: BThreadDao.java   Source Code and License Vote up 6 votes
public BThread 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
Project: NeiHanDuanZiTV   File: AlbumTask.java   Source Code and License Vote up 6 votes
private void buildAlbumInfo(ContentResolver cr) {
    String[] distinctBucketColumns = new String[]{Media.BUCKET_ID, Media.BUCKET_DISPLAY_NAME};
    Cursor bucketCursor = null;
    try {
        bucketCursor = cr.query(Media.EXTERNAL_CONTENT_URI, distinctBucketColumns, "0==0)" + " GROUP BY(" + Media.BUCKET_ID, null,
                Media.DATE_MODIFIED + " desc");
        if (bucketCursor != null && bucketCursor.moveToFirst()) {
            do {
                String buckId = bucketCursor.getString(bucketCursor.getColumnIndex(Media.BUCKET_ID));
                String name = bucketCursor.getString(bucketCursor.getColumnIndex(Media.BUCKET_DISPLAY_NAME));
                AlbumEntity album = buildAlbumInfo(name, buckId);
                if (!TextUtils.isEmpty(buckId)) {
                    buildAlbumCover(cr, buckId, album);
                }
            } while (bucketCursor.moveToNext() && !bucketCursor.isLast());
        }
    } finally {
        if (bucketCursor != null) {
            bucketCursor.close();
        }
    }
}
 
Example 3
Project: chat-sdk-android-push-firebase   File: UserThreadLinkDao.java   Source Code and License Vote up 6 votes
public UserThreadLink 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
Project: GitHub   File: AlbumTask.java   Source Code and License Vote up 6 votes
private void buildAlbumInfo(ContentResolver cr) {
    String[] distinctBucketColumns = new String[]{Media.BUCKET_ID, Media.BUCKET_DISPLAY_NAME};
    Cursor bucketCursor = null;
    try {
        bucketCursor = cr.query(Media.EXTERNAL_CONTENT_URI, distinctBucketColumns, "0==0)" + " GROUP BY(" + Media.BUCKET_ID, null,
                Media.DATE_MODIFIED + " desc");
        if (bucketCursor != null && bucketCursor.moveToFirst()) {
            do {
                String buckId = bucketCursor.getString(bucketCursor.getColumnIndex(Media.BUCKET_ID));
                String name = bucketCursor.getString(bucketCursor.getColumnIndex(Media.BUCKET_DISPLAY_NAME));
                AlbumEntity album = buildAlbumInfo(name, buckId);
                if (!TextUtils.isEmpty(buckId)) {
                    buildAlbumCover(cr, buckId, album);
                }
            } while (bucketCursor.moveToNext() && !bucketCursor.isLast());
        }
    } finally {
        if (bucketCursor != null) {
            bucketCursor.close();
        }
    }
}
 
Example 5
Project: Shopping_List   File: UsedProductDao.java   Source Code and License Vote up 6 votes
public UsedProduct 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
Project: GitHub   File: AbstractDao.java   Source Code and License Vote up 6 votes
/** Resets all locally changed properties of the entity by reloading the values from the database. */
public void refresh(T entity) {
    assertSinglePk();
    K key = getKeyVerified(entity);
    String sql = statements.getSelectByKey();
    String[] keyArray = new String[]{key.toString()};
    Cursor cursor = db.rawQuery(sql, keyArray);
    try {
        boolean available = cursor.moveToFirst();
        if (!available) {
            throw new DaoException("Entity does not exist in the database anymore: " + entity.getClass()
                    + " with key " + key);
        } else if (!cursor.isLast()) {
            throw new DaoException("Expected unique result, but count was " + cursor.getCount());
        }
        readEntity(cursor, entity, 0);
        attachEntity(key, entity, true);
    } finally {
        cursor.close();
    }
}
 
Example 7
Project: GitHub   File: CountQuery.java   Source Code and License Vote up 6 votes
/** Returns the count (number of results matching the query). Uses SELECT COUNT (*) sematics. */
public long count() {
    checkThread();
    Cursor cursor = dao.getDatabase().rawQuery(sql, parameters);
    try {
        if (!cursor.moveToNext()) {
            throw new DaoException("No result for count");
        } else if (!cursor.isLast()) {
            throw new DaoException("Unexpected row count: " + cursor.getCount());
        } else if (cursor.getColumnCount() != 1) {
            throw new DaoException("Unexpected column count: " + cursor.getColumnCount());
        }
        return cursor.getLong(0);
    } finally {
        cursor.close();
    }
}
 
Example 8
Project: GitHub   File: TreeEntityDao.java   Source Code and License Vote up 6 votes
public TreeEntity 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 9
Project: GitHub   File: RelationEntityDao.java   Source Code and License Vote up 6 votes
public RelationEntity 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
Project: chat-sdk-android-push-firebase   File: BMessageDao.java   Source Code and License Vote up 6 votes
public BMessage 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
Project: chat-sdk-android-push-firebase   File: BLinkedAccountDao.java   Source Code and License Vote up 6 votes
public BLinkedAccount 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
Project: AndroidBackendlessChat   File: BMessageDao.java   Source Code and License Vote up 6 votes
public BMessage 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 13
Project: AndroidBackendlessChat   File: BThreadDao.java   Source Code and License Vote up 6 votes
public BThread 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 14
Project: AndroidBackendlessChat   File: BLinkedAccountDao.java   Source Code and License Vote up 6 votes
public BLinkedAccount 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 15
Project: AndroidBackendlessChat   File: ContactLinkDao.java   Source Code and License Vote up 6 votes
public ContactLink 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 16
Project: AndroidBackendlessChat   File: UserThreadLinkDao.java   Source Code and License Vote up 6 votes
public UserThreadLink 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 17
Project: AndroidBackendlessChat   File: FollowerLinkDao.java   Source Code and License Vote up 6 votes
public FollowerLink 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 18
Project: NeiHanDuanZiTV   File: ImageTask.java   Source Code and License Vote up 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 19
Project: boxing   File: VideoTask.java   Source Code and License Vote up 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 20
Project: CryptoVoice   File: Main.java   Source Code and License Vote up 5 votes
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // check whether the result is ok
    if (resultCode == RESULT_OK) {
        // Check for the request code, we might be usign multiple startActivityForReslut
        switch (requestCode) {
            case RESULT_PICK_CONTACT:
                Uri uri = data.getData();
                Cursor cursor = getContentResolver().query(uri, null, null, null, null);
                cursor.moveToFirst();
                String number = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                number = number.replace("-", "");
                number = number.replace(" ", "");
                while(number.length() != 6 && !cursor.isLast()){
                    cursor.moveToNext();
                    number = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                    number = number.replace("-", "");
                    number = number.replace(" ", "");
                }
                if (number.length() != 6){
                    Toast.makeText(this, "No valid RTVOICE number was found for selected contact", Toast.LENGTH_LONG).show();
                    break;
                }
                final EditText numberTextView = (EditText) findViewById(R.id.editText);
                numberTextView.setText(number);
                break;
        }
    } else {
        Log.e("MainActivity", "Failed to pick contact");
    }
}