use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.
the class JobScheduler method updateJob.
/**
* Updates the job.
*
* <p>This just updates the job, but it doesn't schedule it. In order to be executed, the job has
* to be scheduled after being set. In case there was a previous job scheduled that has not yet
* started, this new job will be executed instead.
*
* @return whether the job was successfully updated.
*/
public boolean updateJob(@Nullable EncodedImage encodedImage, @Consumer.Status int status) {
if (!shouldProcess(encodedImage, status)) {
return false;
}
EncodedImage oldEncodedImage;
synchronized (this) {
oldEncodedImage = mEncodedImage;
this.mEncodedImage = EncodedImage.cloneOrNull(encodedImage);
this.mStatus = status;
}
EncodedImage.closeSafely(oldEncodedImage);
return true;
}
use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.
the class JobScheduler method clearJob.
/**
* Clears the currently set job.
*
* <p>In case the currently set job has been scheduled but not started yet, the job won't be
* executed.
*/
public void clearJob() {
EncodedImage oldEncodedImage;
synchronized (this) {
oldEncodedImage = mEncodedImage;
mEncodedImage = null;
mStatus = 0;
}
EncodedImage.closeSafely(oldEncodedImage);
}
use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.
the class JobScheduler method doJob.
private void doJob() {
long now = SystemClock.uptimeMillis();
EncodedImage input;
int status;
synchronized (this) {
input = mEncodedImage;
status = mStatus;
mEncodedImage = null;
this.mStatus = 0;
mJobState = JobState.RUNNING;
mJobStartTime = now;
}
try {
// we need to do a check in case the job got cleared in the meantime
if (shouldProcess(input, status)) {
mJobRunnable.run(input, status);
}
} finally {
EncodedImage.closeSafely(input);
onJobFinished();
}
}
use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.
the class LocalContentUriFetchProducer method getEncodedImage.
@Override
protected EncodedImage getEncodedImage(ImageRequest imageRequest) throws IOException {
Uri uri = imageRequest.getSourceUri();
if (UriUtil.isLocalContactUri(uri)) {
final InputStream inputStream;
if (uri.toString().endsWith("/photo")) {
inputStream = mContentResolver.openInputStream(uri);
} else if (uri.toString().endsWith("/display_photo")) {
try {
AssetFileDescriptor fd = mContentResolver.openAssetFileDescriptor(uri, "r");
Preconditions.checkNotNull(fd);
inputStream = fd.createInputStream();
} catch (IOException e) {
throw new IOException("Contact photo does not exist: " + uri);
}
} else {
inputStream = ContactsContract.Contacts.openContactPhotoInputStream(mContentResolver, uri);
if (inputStream == null) {
throw new IOException("Contact photo does not exist: " + uri);
}
}
Preconditions.checkNotNull(inputStream);
// If a Contact URI is provided, use the special helper to open that contact's photo.
return getEncodedImage(inputStream, EncodedImage.UNKNOWN_STREAM_SIZE);
}
if (UriUtil.isLocalCameraUri(uri)) {
EncodedImage cameraImage = this.getCameraImage(uri);
if (cameraImage != null) {
return cameraImage;
}
}
return getEncodedImage(Preconditions.checkNotNull(mContentResolver.openInputStream(uri)), EncodedImage.UNKNOWN_STREAM_SIZE);
}
use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.
the class LocalExifThumbnailProducer method produceResults.
@Override
public void produceResults(final Consumer<EncodedImage> consumer, final ProducerContext producerContext) {
final ProducerListener2 listener = producerContext.getProducerListener();
final ImageRequest imageRequest = producerContext.getImageRequest();
producerContext.putOriginExtra("local", "exif");
final StatefulProducerRunnable cancellableProducerRunnable = new StatefulProducerRunnable<EncodedImage>(consumer, listener, producerContext, PRODUCER_NAME) {
@Override
@Nullable
protected EncodedImage getResult() throws Exception {
final Uri sourceUri = imageRequest.getSourceUri();
final ExifInterface exifInterface = getExifInterface(sourceUri);
if (exifInterface == null || !exifInterface.hasThumbnail()) {
return null;
}
byte[] bytes = Preconditions.checkNotNull(exifInterface.getThumbnail());
PooledByteBuffer pooledByteBuffer = mPooledByteBufferFactory.newByteBuffer(bytes);
return buildEncodedImage(pooledByteBuffer, exifInterface);
}
@Override
protected void disposeResult(@Nullable EncodedImage result) {
EncodedImage.closeSafely(result);
}
@Override
protected Map<String, String> getExtraMapOnSuccess(@Nullable final EncodedImage result) {
return ImmutableMap.of(CREATED_THUMBNAIL, Boolean.toString(result != null));
}
};
producerContext.addCallbacks(new BaseProducerContextCallbacks() {
@Override
public void onCancellationRequested() {
cancellableProducerRunnable.cancel();
}
});
mExecutor.execute(cancellableProducerRunnable);
}
Aggregations