Search in sources :

Example 46 with Cursor

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

the class QueryToOneOperator method call.

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

        @Override
        public void onNext(SqlBrite.Query query) {
            try {
                boolean emit = false;
                T item = null;
                Cursor cursor = query.run();
                if (cursor != null) {
                    try {
                        if (cursor.moveToNext()) {
                            item = mapper.call(cursor);
                            emit = true;
                            if (cursor.moveToNext()) {
                                throw new IllegalStateException("Cursor returned more than 1 row");
                            }
                        }
                    } finally {
                        cursor.close();
                    }
                }
                if (!subscriber.isUnsubscribed()) {
                    if (emit) {
                        subscriber.onNext(item);
                    } else if (emitDefault) {
                        subscriber.onNext(defaultValue);
                    } else {
                        // Account upstream for the lack of downstream emission.
                        request(1L);
                    }
                }
            } 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) OnErrorThrowable(rx.exceptions.OnErrorThrowable) Cursor(android.database.Cursor)

Example 47 with Cursor

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

the class SqlUtils method createQuery.

@WorkerThread
public static Cursor createQuery(Context context, Query query) {
    long time = System.currentTimeMillis();
    Cursor cursor = context.getContentResolver().query(query.uri, query.projection, query.selection, query.args, query.sort);
    if (ENABLE_LOGGING && BuildConfig.DEBUG) {
        Log.d(TAG, String.format("Query took %sms. %s", (System.currentTimeMillis() - time), query));
    }
    ThreadUtils.ensureNotOnMainThread();
    return cursor;
}
Also used : Cursor(android.database.Cursor) WorkerThread(android.support.annotation.WorkerThread)

Example 48 with Cursor

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

the class SqlUtils method createSingleQuery.

public static <T> T createSingleQuery(Context context, Func1<Cursor, T> mapper, T defaultValue, Query query) {
    T item = defaultValue;
    Cursor cursor = createQuery(context, query);
    if (cursor != null) {
        try {
            if (cursor.moveToFirst()) {
                item = mapper.call(cursor);
                if (cursor.moveToNext()) {
                    Log.e(TAG, "Cursor returned more than 1 row. Query: " + query);
                }
            }
        } finally {
            cursor.close();
        }
    }
    return item;
}
Also used : Cursor(android.database.Cursor)

Example 49 with Cursor

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

the class CustomArtworkContentProvider method query.

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    // Using SQLiteQueryBuilder instead of query() method
    SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
    // Check if the caller has requested a column which does not exists
    checkColumns(projection);
    // Set the table
    queryBuilder.setTables(CustomArtworkTable.TABLE_ARTIST_ART);
    int uriType = sURIMatcher.match(uri);
    switch(uriType) {
        case CUSTOM_ARTWORK:
            break;
        default:
            throw new IllegalArgumentException("Unknown URI: " + uri);
    }
    SQLiteDatabase db = database.getWritableDatabase();
    Cursor cursor = queryBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder);
    // Make sure that potential listeners are getting notified
    cursor.setNotificationUri(getContext().getContentResolver(), uri);
    return cursor;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor) SQLiteQueryBuilder(android.database.sqlite.SQLiteQueryBuilder)

Example 50 with Cursor

use of android.database.Cursor in project glitch-hq-android by tinyspeck.

the class BitmapUtil method ImageUri2Path.

public static String ImageUri2Path(Activity act, Uri uri) {
    if (uri == null)
        return null;
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor actualimagecursor = act.managedQuery(uri, proj, null, null, null);
    int actual_image_column_index = actualimagecursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    actualimagecursor.moveToFirst();
    return actualimagecursor.getString(actual_image_column_index);
}
Also used : Cursor(android.database.Cursor) Paint(android.graphics.Paint)

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