本教程內(nèi)容來(lái)源于:http://fresco-cn.org
采用 知識(shí)共享 署名 4.0 國(guó)際 許可協(xié)議 進(jìn)行許可
你也許想在圖片下載完成或者下載失敗之后,做一些其他事情。
圖片是后臺(tái)線程異步加載的,我們可以使用一個(gè)ControllerListener實(shí)現(xiàn)事件的監(jiān)聽(tīng)。
_在監(jiān)聽(tīng)事件回調(diào)時(shí),無(wú)法修改圖片,如果需要修改圖片,可使用 后處理器(Postprocessor)
ControllerListener controllerListener = new BaseControllerListener() {
@Override
public void onFinalImageSet(
String id,
@Nullable ImageInfo imageInfo,
@Nullable Animatable anim) {
if (imageInfo == null) {
return;
}
QualityInfo qualityInfo = imageInfo.getQualityInfo();
FLog.d("Final image received! " +
"Size %d x %d",
"Quality level %d, good enough: %s, full quality: %s",
imageInfo.getWidth(),
imageInfo.getHeight(),
qualityInfo.getQuality(),
qualityInfo.isOfGoodEnoughQuality(),
qualityInfo.isOfFullQuality());
}
@Override
public void onIntermediateImageSet(String id, @Nullable ImageInfo imageInfo) {
FLog.d("Intermediate image received");
}
@Override
public void onFailure(String id, Throwable throwable) {
FLog.e(getClass(), throwable, "Error loading %s", id)
}
};
Uri uri;
DraweeController controller = Fresco.newControllerBuilder()
.setControllerListener(controllerListener)
.setUri(uri);
// other setters
.build();
mSimpleDraweeView.setController(controller);
對(duì)所有的圖片加載,onFinalImageSet 或者 onFailure 都會(huì)被觸發(fā)。前者在成功時(shí),后者在失敗時(shí)。
如果允許呈現(xiàn)漸進(jìn)式JPEG,同時(shí)圖片也是漸進(jìn)式圖片,onIntermediateImageSet會(huì)在每個(gè)掃描被解碼后回調(diào)。具體圖片的那個(gè)掃描會(huì)被解碼,參見(jiàn)漸進(jìn)式JPEG圖