use of android.os.CancellationSignal in project fresco by facebook.
the class LocalThumbnailBitmapProducer method produceResults.
@Override
public void produceResults(final Consumer<CloseableReference<CloseableImage>> consumer, final ProducerContext context) {
final ProducerListener2 listener = context.getProducerListener();
final ImageRequest imageRequest = context.getImageRequest();
context.putOriginExtra("local", "thumbnail_bitmap");
final CancellationSignal cancellationSignal = new CancellationSignal();
final StatefulProducerRunnable<CloseableReference<CloseableImage>> cancellableProducerRunnable = new StatefulProducerRunnable<CloseableReference<CloseableImage>>(consumer, listener, context, PRODUCER_NAME) {
@Override
protected void onSuccess(@Nullable CloseableReference<CloseableImage> result) {
super.onSuccess(result);
listener.onUltimateProducerReached(context, PRODUCER_NAME, result != null);
context.putOriginExtra("local");
}
@Override
protected void onFailure(Exception e) {
super.onFailure(e);
listener.onUltimateProducerReached(context, PRODUCER_NAME, false);
context.putOriginExtra("local");
}
@Override
@Nullable
protected CloseableReference<CloseableImage> getResult() throws IOException {
final Bitmap thumbnailBitmap = mContentResolver.loadThumbnail(imageRequest.getSourceUri(), new Size(imageRequest.getPreferredWidth(), imageRequest.getPreferredHeight()), cancellationSignal);
if (thumbnailBitmap == null) {
return null;
}
CloseableStaticBitmap closeableStaticBitmap = new CloseableStaticBitmap(thumbnailBitmap, SimpleBitmapReleaser.getInstance(), ImmutableQualityInfo.FULL_QUALITY, 0);
context.setExtra(ProducerContext.ExtraKeys.IMAGE_FORMAT, "thumbnail");
closeableStaticBitmap.setImageExtras(context.getExtras());
return CloseableReference.<CloseableImage>of(closeableStaticBitmap);
}
@Override
protected void onCancellation() {
super.onCancellation();
cancellationSignal.cancel();
}
@Override
protected Map<String, String> getExtraMapOnSuccess(@Nullable final CloseableReference<CloseableImage> result) {
return ImmutableMap.of(CREATED_THUMBNAIL, String.valueOf(result != null));
}
@Override
protected void disposeResult(CloseableReference<CloseableImage> result) {
CloseableReference.closeSafely(result);
}
};
context.addCallbacks(new BaseProducerContextCallbacks() {
@Override
public void onCancellationRequested() {
cancellableProducerRunnable.cancel();
}
});
mExecutor.execute(cancellableProducerRunnable);
}
use of android.os.CancellationSignal in project robolectric by robolectric.
the class SQLiteDatabaseTest method testRawQueryWithFactoryAndCancellationSignal.
@Test
public void testRawQueryWithFactoryAndCancellationSignal() {
CancellationSignal signal = new CancellationSignal();
Cursor cursor = database.rawQueryWithFactory(null, "select * from" + " table_name", null, null, signal);
assertThat(cursor).isNotNull();
assertThat(cursor.getColumnCount()).isEqualTo(5);
assertThat(cursor.isClosed()).isFalse();
signal.cancel();
try {
cursor.moveToNext();
fail("did not get cancellation signal");
} catch (OperationCanceledException e) {
// expected
}
cursor.close();
}
use of android.os.CancellationSignal in project robolectric by robolectric.
the class ShadowLocationManagerTest method testGetCurrentLocation_Cancel.
@Test
@Config(minSdk = R)
public void testGetCurrentLocation_Cancel() {
Location loc = createLocation(MY_PROVIDER);
TestLocationConsumer consumer = new TestLocationConsumer();
shadowLocationManager.setProviderEnabled(MY_PROVIDER, true);
CancellationSignal cs = new CancellationSignal();
locationManager.getCurrentLocation(MY_PROVIDER, cs, Runnable::run, consumer);
cs.cancel();
shadowLocationManager.simulateLocation(loc);
assertThat(consumer.locations).isEmpty();
}
use of android.os.CancellationSignal in project robolectric by robolectric.
the class ShadowContentResolverTest method whenCursorHasBeenSet_queryWithCancellationSignal_shouldReturnTheCursor.
@Test
public void whenCursorHasBeenSet_queryWithCancellationSignal_shouldReturnTheCursor() {
assertThat(shadowContentResolver.query(null, null, null, null, null, new CancellationSignal())).isNull();
BaseCursor cursor = new BaseCursor();
shadowContentResolver.setCursor(cursor);
assertThat((BaseCursor) shadowContentResolver.query(null, null, null, null, null, new CancellationSignal())).isSameInstanceAs(cursor);
}
use of android.os.CancellationSignal in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class FingerprintAuthenticateSidecar method startAuthentication.
public void startAuthentication(int userId) {
mCancellationSignal = new CancellationSignal();
mFingerprintManager.authenticate(null, mCancellationSignal, 0, /* flags */
mAuthenticationCallback, null, userId);
}
Aggregations