I'm trying to load a large size JPG progressively. I saw this documentation using Fresco and that's exactly what I want: A blur lazy load effect. I took their code from repo sample which looks like this wrapping things up:
ImageFormatProgressiveJpegFragment.java
private void setImageUri(Uri uri) {
mDebugOutput.setText("");
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri)
.setProgressiveRenderingEnabled(mProgressiveRenderingEnabled)
.build();
DraweeController controller =
Fresco.newDraweeControllerBuilder()
.setImageRequest(request)
.setRetainImageOnFailure(true)
.setPerfDataListener(mImagePerfDataListener)
.setControllerListener(
new BaseControllerListener<ImageInfo>() {
@Override
public void onFinalImageSet(
String id,
@javax.annotation.Nullable ImageInfo imageInfo,
@javax.annotation.Nullable Animatable animatable) {
if (imageInfo != null) {
QualityInfo qualityInfo = imageInfo.getQualityInfo();
logScan(qualityInfo, true);
}
}
@Override
public void onIntermediateImageSet(
String id, @javax.annotation.Nullable ImageInfo imageInfo) {
if (imageInfo != null) {
QualityInfo qualityInfo = imageInfo.getQualityInfo();
logScan(qualityInfo, false);
}
}
@Override
public void onIntermediateImageFailed(String id, Throwable throwable) {
mDebugOutput.append(
String.format(
Locale.getDefault(),
"onIntermediateImageFailed, %s\n",
throwable.getMessage()));
}
})
.build();
mSimpleDraweeView.setController(controller);
}
private void logScan(QualityInfo qualityInfo, boolean isFinalImage) {
mDebugOutput.append(
String.format(
Locale.getDefault(),
"%s: %s, goodEnough=%b, fullQuality=%b, quality=%d\n\n",
mDateFormat.format(new Date(System.currentTimeMillis())),
isFinalImage ? "final" : "intermediate",
qualityInfo.isOfGoodEnoughQuality(),
qualityInfo.isOfFullQuality(),
qualityInfo.getQuality()));
}
The result is an output of image infos while loading it.
My code looks like the same, except for replacing logs partially:
MyFrescoActivity.java
private String IMAGE_URL = "https://eoimages.gsfc.nasa.gov/images/imagerecords/73000/73726/world.topo.bathy.200406.3x5400x2700.png";
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(IMAGE_URL))
.setProgressiveRenderingEnabled(true)
.build();
DraweeController controller =
Fresco.newDraweeControllerBuilder()
.setImageRequest(request)
.setRetainImageOnFailure(true)
.setPerfDataListener(this)
.setControllerListener(
new BaseControllerListener<ImageInfo>() {
@Override
public void onFinalImageSet(
String id,
@Nullable ImageInfo imageInfo,
@Nullable Animatable animatable) {
if (imageInfo != null) {
QualityInfo qualityInfo = imageInfo.getQualityInfo();
logScan(qualityInfo, true);
}
}
@Override
public void onIntermediateImageSet(
String id, @Nullable ImageInfo imageInfo) {
if (imageInfo != null) {
QualityInfo qualityInfo = imageInfo.getQualityInfo();
logScan(qualityInfo, false);
}
}
@Override
public void onIntermediateImageFailed(String id, Throwable throwable) {
Log.i("DraweeUpdate",
String.format(
Locale.getDefault(),
"onIntermediateImageFailed, %s\n",
throwable.getMessage()));
}
})
.build();
simpleDraweeView.setController(controller);
}
private void logScan(QualityInfo qualityInfo, boolean isFinalImage) {
Log.i("DraweeUpdate", String.format(
Locale.getDefault(),
"%s: %s, goodEnough=%b, fullQuality=%b, quality=%d\n\n",
"",
isFinalImage ? "final" : "intermediate",
qualityInfo.isOfGoodEnoughQuality(),
qualityInfo.isOfFullQuality(),
qualityInfo.getQuality()));
}
Still, I'm not getting responses on onIntermediateImageSet
. The only thing being called on this listener is onFinalImageSet
when the image is fully loaded. Anyone has an idea of what's going on?