Search in sources :

Example 41 with Cursor

use of android.database.Cursor in project Talon-for-Twitter by klinker24.

the class MentionsDataSource method getLastIds.

public synchronized long[] getLastIds(int account) {
    long[] ids = new long[] { 0, 0 };
    Cursor cursor;
    try {
        cursor = getCursor(account);
    } catch (Exception e) {
        return ids;
    }
    try {
        if (cursor.moveToLast()) {
            ids[0] = cursor.getLong(cursor.getColumnIndex(MentionsSQLiteHelper.COLUMN_TWEET_ID));
        }
        if (cursor.moveToPrevious()) {
            ids[1] = cursor.getLong(cursor.getColumnIndex(MentionsSQLiteHelper.COLUMN_TWEET_ID));
        }
    } catch (Exception e) {
    }
    cursor.close();
    return ids;
}
Also used : Cursor(android.database.Cursor) SQLException(android.database.SQLException) SQLiteDatabaseLockedException(android.database.sqlite.SQLiteDatabaseLockedException)

Example 42 with Cursor

use of android.database.Cursor in project Talon-for-Twitter by klinker24.

the class MentionsDataSource method getUnreadCount.

public synchronized int getUnreadCount(int account) {
    Cursor cursor = getUnreadCursor(account);
    int count = cursor.getCount();
    cursor.close();
    return count;
}
Also used : Cursor(android.database.Cursor)

Example 43 with Cursor

use of android.database.Cursor in project cordova-android-chromeview by thedracle.

the class CameraLauncher method checkForDuplicateImage.

/**
     * Used to find out if we are in a situation where the Camera Intent adds to images
     * to the content store. If we are using a FILE_URI and the number of images in the DB
     * increases by 2 we have a duplicate, when using a DATA_URL the number is 1.
     *
     * @param type FILE_URI or DATA_URL
     */
private void checkForDuplicateImage(int type) {
    int diff = 1;
    Uri contentStore = whichContentStore();
    Cursor cursor = queryImgDB(contentStore);
    int currentNumOfImages = cursor.getCount();
    if (type == FILE_URI && this.saveToPhotoAlbum) {
        diff = 2;
    }
    // delete the duplicate file if the difference is 2 for file URI or 1 for Data URL
    if ((currentNumOfImages - numPics) == diff) {
        cursor.moveToLast();
        int id = Integer.valueOf(cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media._ID)));
        if (diff == 2) {
            id--;
        }
        Uri uri = Uri.parse(contentStore + "/" + id);
        this.cordova.getActivity().getContentResolver().delete(uri, null, null);
    }
}
Also used : Cursor(android.database.Cursor) Uri(android.net.Uri)

Example 44 with Cursor

use of android.database.Cursor in project cordova-android-chromeview by thedracle.

the class Capture method checkForDuplicateImage.

/**
     * Used to find out if we are in a situation where the Camera Intent adds to images
     * to the content store.
     */
private void checkForDuplicateImage() {
    Uri contentStore = whichContentStore();
    Cursor cursor = queryImgDB(contentStore);
    int currentNumOfImages = cursor.getCount();
    // delete the duplicate file if the difference is 2
    if ((currentNumOfImages - numPics) == 2) {
        cursor.moveToLast();
        int id = Integer.valueOf(cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media._ID))) - 1;
        Uri uri = Uri.parse(contentStore + "/" + id);
        this.cordova.getActivity().getContentResolver().delete(uri, null, null);
    }
}
Also used : Cursor(android.database.Cursor) Uri(android.net.Uri)

Example 45 with Cursor

use of android.database.Cursor in project Shuttle by timusus.

the class QueryToListOperator method call.

@Override
public Subscriber<? super SqlBrite.Query> call(final Subscriber<? super List<T>> subscriber) {
    return new Subscriber<SqlBrite.Query>(subscriber) {

        @Override
        public void onNext(SqlBrite.Query query) {
            try {
                Cursor cursor = query.run();
                if (cursor == null) {
                    return;
                }
                List<T> items = new ArrayList<>(cursor.getCount());
                try {
                    for (int i = 1; cursor.moveToNext() && !subscriber.isUnsubscribed(); i++) {
                        T item = mapper.call(cursor);
                        if (item == null) {
                            throw new NullPointerException("Mapper returned null for row " + i);
                        }
                        items.add(item);
                    }
                } finally {
                    cursor.close();
                }
                if (!subscriber.isUnsubscribed()) {
                    subscriber.onNext(items);
                }
            } catch (Throwable e) {
                Exceptions.throwIfFatal(e);
                onError(OnErrorThrowable.addValueAsLastCause(e, query.toString()));
            }
        }

        @Override
        public void onCompleted() {
            subscriber.onCompleted();
        }

        @Override
        public void onError(Throwable e) {
            subscriber.onError(e);
        }
    };
}
Also used : Subscriber(rx.Subscriber) SqlBrite(com.squareup.sqlbrite.SqlBrite) ArrayList(java.util.ArrayList) OnErrorThrowable(rx.exceptions.OnErrorThrowable) Cursor(android.database.Cursor)

Aggregations

Cursor (android.database.Cursor)4002 ArrayList (java.util.ArrayList)547 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)527 Uri (android.net.Uri)467 ContentValues (android.content.ContentValues)334 ContentResolver (android.content.ContentResolver)193 Test (org.junit.Test)183 RemoteException (android.os.RemoteException)182 File (java.io.File)170 IOException (java.io.IOException)159 MatrixCursor (android.database.MatrixCursor)154 Intent (android.content.Intent)140 SQLException (android.database.SQLException)126 MediumTest (android.test.suitebuilder.annotation.MediumTest)116 HashMap (java.util.HashMap)108 SQLiteException (android.database.sqlite.SQLiteException)94 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)93 SQLiteCursor (android.database.sqlite.SQLiteCursor)88 Query (android.app.DownloadManager.Query)76 MergeCursor (android.database.MergeCursor)75