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);
}
};
}
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;
}
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;
}
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;
}
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);
}
Aggregations