private void init() { mInstrumentation = new Instrumentation(this); mListener = new BaseControllerListener<Object>() { @Override public void onSubmit(String id, Object callerContext) { mInstrumentation.onStart(); } @Override public void onFinalImageSet( String id, @Nullable Object imageInfo, @Nullable Animatable animatable) { mInstrumentation.onSuccess(); } @Override public void onFailure(String id, Throwable throwable) { mInstrumentation.onFailure(); } @Override public void onRelease(String id) { mInstrumentation.onCancellation(); } }; }
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash); ButterKnife.bind(this); Uri uri = Uri.parse("asset:///splash.webp"); mSplashPresenter = new SplashPresenterImpl(this); DraweeController controller = Fresco.newDraweeControllerBuilder() .setUri(uri) .setAutoPlayAnimations(true) .setControllerListener(new BaseControllerListener<ImageInfo>(){ @Override public void onFinalImageSet(String id, @Nullable ImageInfo imageInfo, @Nullable Animatable animatable) { super.onFinalImageSet(id, imageInfo, animatable); mSplashPresenter.startCountDown(1); } }) .build(); splashDraweee.setController(controller); }
public static void loadImage(final PhotoDraweeView mPhotoDraweeView, Uri uri) { PipelineDraweeControllerBuilder controller = Fresco.newDraweeControllerBuilder(); controller.setUri(uri); controller.setAutoPlayAnimations(true); controller.setOldController(mPhotoDraweeView.getController()); controller.setControllerListener(new BaseControllerListener<ImageInfo>() { @Override public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) { super.onFinalImageSet(id, imageInfo, animatable); if (imageInfo == null || mPhotoDraweeView == null) { return; } mPhotoDraweeView.update(imageInfo.getWidth(), imageInfo.getHeight()); } }); mPhotoDraweeView.setController(controller.build()); }
public void loadImage(String url,String lowurl, int placeHolderResId, int errorResId,ScalingUtils.ScaleType scaleType){ final boolean isHttp = url.startsWith("http"); Uri uri = isHttp ? Uri.parse(url) : Uri.fromFile(new File(url)); PipelineDraweeControllerBuilder controller = Fresco.newDraweeControllerBuilder() .setImageRequest(ImageRequest.fromUri(uri)); if(lowurl!=null && lowurl.startsWith("http")) { controller .setLowResImageRequest(ImageRequest.fromUri(lowurl)); } getHierarchy().setActualImageScaleType(scaleType); // controller.setUri(URI); getHierarchy().setPlaceholderImage(getResources().getDrawable( placeHolderResId ),scaleType); getHierarchy().setFailureImage(getResources().getDrawable(errorResId),scaleType); controller.setOldController(this.getController()) .setControllerListener(new BaseControllerListener<ImageInfo>() { @Override public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) { if (imageInfo == null) { return; } PhotoDraweeView.this.update(imageInfo.getWidth(), imageInfo.getHeight()); } }); this.setController(controller.build()); }
public static void load(Uri uri,SimpleDraweeView draweeView,BasePostprocessor processor,int width,int height, BaseControllerListener listener){ ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri) .setPostprocessor(processor) .setResizeOptions(new ResizeOptions(width,height)) //缩放,在解码前修改内存中的图片大小, 配合Downsampling可以处理所有图片,否则只能处理jpg, // 开启Downsampling:在初始化时设置.setDownsampleEnabled(true) .setProgressiveRenderingEnabled(true)//支持图片渐进式加载 .setAutoRotateEnabled(true) //如果图片是侧着,可以自动旋转 .build(); PipelineDraweeController controller = (PipelineDraweeController) Fresco.newDraweeControllerBuilder() .setImageRequest(request) .setControllerListener(listener) .setOldController(draweeView.getController()) .setAutoPlayAnimations(true) //自动播放gif动画 .build(); draweeView.setController(controller); }
/** * showThumb * * @param draweeView draweeView * @param url url * @param resizeWidthDp resizeWidth * @param resizeHeightDp resizeHeight */ public static void showThumb(SimpleDraweeView draweeView, String url, int resizeWidthDp, int resizeHeightDp) { try { if (!isInit) return; if (url == null || "".equals(url)) return; if (draweeView == null) return; initialize(draweeView.getContext()); ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url)) .setResizeOptions(new ResizeOptions(DimenUtils.dip2px(draweeView.getContext(), resizeWidthDp), DimenUtils.dip2px(draweeView.getContext(), resizeHeightDp))) .build(); DraweeController controller = Fresco.newDraweeControllerBuilder() .setImageRequest(request) .setOldController(draweeView.getController()) .setControllerListener(new BaseControllerListener<ImageInfo>()) .build(); draweeView.setController(controller); } catch (Exception e) { } }
public static DraweeController showResGif(int resourceId, SimpleDraweeView simpleDraweeView) { ControllerListener controllerListener = new BaseControllerListener<ImageInfo>() { @Override public void onFinalImageSet( String id, @Nullable ImageInfo imageInfo, @Nullable Animatable anim) { if (anim != null) { anim.start(); } } }; Uri uri = Uri.parse("res://com.blinnnk.gaia/" + resourceId); DraweeController draweeController = Fresco.newDraweeControllerBuilder() .setUri(uri) .setControllerListener(controllerListener) .build(); simpleDraweeView.setController(draweeController); return draweeController; }
@Override public void initLoad() { super.initLoad(); if (!TextUtils.isEmpty(mImageUrl)) { PipelineDraweeControllerBuilder controller = Fresco.newDraweeControllerBuilder(); controller.setUri(mImageUrl); controller.setOldController(mPhotoIv.getController()); controller.setControllerListener(new BaseControllerListener<ImageInfo>() { @Override public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) { super.onFinalImageSet(id, imageInfo, animatable); if (imageInfo == null || mPhotoIv == null) { return; } mPhotoIv.update(imageInfo.getWidth(), imageInfo.getHeight()); } }); mPhotoIv.setController(controller.build()); } }
private void loadByFresco(String url) { Uri uri = Uri.parse(url); ControllerListener listener = new BaseControllerListener<ImageInfo>() { @Override public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) { super.onFinalImageSet(id, imageInfo, animatable); Log.d(TAG, "Fresco----->onFinalImageSet: " + LogTime.getElapsedMillis(startTimeFresco) + "ms"); textFresco.setText(getString(R.string.text_load_time, "Fresco", String.format("%.6f", LogTime.getElapsedMillis(startTimeFresco)))); } }; DraweeController controller = Fresco.newDraweeControllerBuilder() .setControllerListener(listener) .setUri(uri) .build(); imgFresco.setController(controller); }
public static void display(final PhotoDraweeView draweeView, Uri uri) { PipelineDraweeControllerBuilder controller = Fresco.newDraweeControllerBuilder(); controller.setUri(uri); controller.setOldController(draweeView.getController()); controller.setControllerListener(new BaseControllerListener<ImageInfo>() { @Override public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) { super.onFinalImageSet(id, imageInfo, animatable); if (imageInfo == null || draweeView == null) { return; } draweeView.update(imageInfo.getWidth(), imageInfo.getHeight()); } }); draweeView.setController(controller.build()); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String imageUrl = getIntent().getStringExtra(IMAGE_URL); if (!TextUtils.isEmpty(imageUrl)) { PipelineDraweeControllerBuilder builder = Fresco.newDraweeControllerBuilder(); builder.setUri(Uri.parse(imageUrl)); builder.setOldController(photoView.getController()); builder.setControllerListener(new BaseControllerListener<ImageInfo>() { @Override public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) { super.onFinalImageSet(id, imageInfo, animatable); if (imageInfo == null || photoView == null) { return; } photoView.update(imageInfo.getWidth(), imageInfo.getHeight()); } }); photoView.setController(builder.build()); } }
@Override public void onBindItemViewHolder(final ViewHolder holder, final int position) { MediaEntity entity = getItem(position); holder.mImageViewCover.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onItemClickListener.onItemClick(getItem(position)); } }); holder.mTextViewLikesCount.setTextImageStart(18, R.mipmap.ic_thumb_up_gray_18dp, " " + entity.getLikes_count()); holder.mTextViewRecommendCaption.setText(entity.getCaption()); String url = entity.getCover_pic().replace("!thumb320", ""); DraweeController controller = Fresco.newDraweeControllerBuilder() .setControllerListener(new BaseControllerListener<ImageInfo>() { @Override public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) { float aspectRatio = (float)imageInfo.getWidth() / (float)imageInfo.getHeight(); holder.mImageViewCover.setAspectRatio(aspectRatio); } }) .setUri(Uri.parse(url)) .build(); holder.mImageViewCover.setController(controller); AppUtils.loadSmallUserAvata(getItem(position).getUser(), holder.mImageViewAvatar); }
private void init() { mInstrumentation = new Instrumentation(this); if (mConfig.instrumentationEnabled) { mListener = new BaseControllerListener<Object>() { @Override public void onSubmit(String id, Object callerContext) { mInstrumentation.onStart(); } @Override public void onFinalImageSet( String id, @Nullable Object imageInfo, @Nullable Animatable animatable) { mInstrumentation.onSuccess(); } @Override public void onFailure(String id, Throwable throwable) { mInstrumentation.onFailure(); } @Override public void onRelease(String id) { mInstrumentation.onCancellation(); } }; } DraweeUtil.setBgColor(this, mConfig); }
@Override protected void init() { super.init(); transparentStatusBar(); ButterKnife.bind(this); url = getIntent().getStringExtra("url"); PipelineDraweeControllerBuilder controller = Fresco.newDraweeControllerBuilder(); controller.setUri(Uri.parse(url)); controller.setAutoPlayAnimations(true); controller.setOldController(photoDraweeView.getController()); controller.setControllerListener(new BaseControllerListener<ImageInfo>() { @Override public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) { super.onFinalImageSet(id, imageInfo, animatable); if (imageInfo == null || photoDraweeView == null) { return; } photoDraweeView.update(imageInfo.getWidth(), imageInfo.getHeight()); normalScale = photoDraweeView.getScale(); } }); photoDraweeView.setController(controller.build()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){ String name = getIntent().getStringExtra("transition_name"); photoDraweeView.setTransitionName(name); getWindow().setSharedElementEnterTransition(DraweeTransition.createTransitionSet( ScalingUtils.ScaleType.CENTER_CROP, ScalingUtils.ScaleType.FIT_CENTER)); getWindow().setSharedElementReturnTransition(DraweeTransition.createTransitionSet( ScalingUtils.ScaleType.FIT_CENTER, ScalingUtils.ScaleType.CENTER_CROP)); } }
public static void loadFileFromSdcard(final Context context, final SimpleDraweeView draweeView, Uri loackUri, final int reqWidth, final int reqHeight) { ImageRequest request = ImageRequestBuilder.newBuilderWithSource(loackUri) .setRotationOptions(RotationOptions.autoRotate()) .setLocalThumbnailPreviewsEnabled(true) .setResizeOptions(new ResizeOptions(dip2px(context, 140), dip2px(context, 220))) .build(); DraweeController controller = Fresco.newDraweeControllerBuilder() .setImageRequest(request) .setOldController(draweeView.getController()) .setTapToRetryEnabled(true) .setControllerListener(new BaseControllerListener<ImageInfo>() { @Override public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable anim) { if (imageInfo == null) { return; } ViewGroup.LayoutParams layoutParams = draweeView.getLayoutParams(); int width = reqWidth; int height = reqHeight; int imgWidth = dip2px(context, 140); int imgHight = dip2px(context, 220); int bitScalew = getRatioSize(width, height, imgHight, imgWidth); layoutParams.height = height / bitScalew; layoutParams.width = width / bitScalew; draweeView.requestLayout(); } }) .setAutoPlayAnimations(true) .build(); draweeView.setController(controller); }
public void setShouldNotifyLoadEvents(boolean shouldNotify) { if (!shouldNotify) { mControllerListener = null; } else { final EventDispatcher mEventDispatcher = ((ReactContext) getContext()). getNativeModule(UIManagerModule.class).getEventDispatcher(); mControllerListener = new BaseControllerListener<ImageInfo>() { @Override public void onSubmit(String id, Object callerContext) { mEventDispatcher.dispatchEvent( new ImageLoadEvent(getId(), ImageLoadEvent.ON_LOAD_START)); } @Override public void onFinalImageSet( String id, @Nullable final ImageInfo imageInfo, @Nullable Animatable animatable) { if (imageInfo != null) { mEventDispatcher.dispatchEvent( new ImageLoadEvent(getId(), ImageLoadEvent.ON_LOAD, mImageSource.getSource(), imageInfo.getWidth(), imageInfo.getHeight())); mEventDispatcher.dispatchEvent( new ImageLoadEvent(getId(), ImageLoadEvent.ON_LOAD_END)); } } @Override public void onFailure(String id, Throwable throwable) { mEventDispatcher.dispatchEvent( new ImageLoadEvent(getId(), ImageLoadEvent.ON_ERROR)); mEventDispatcher.dispatchEvent( new ImageLoadEvent(getId(), ImageLoadEvent.ON_LOAD_END)); } }; } mIsDirty = true; }
/*** * load net work image. * @param url the main url of image, from net * @param lowUrl the low url, from net or local image file name, can be null. * @param placeHolder the place holder. 0 with no place holder * @param errorResId error res id , 0 with no error res. * @param width the width you want * @param height the height you want * @param scaleType scale type * @param l BaseControllerListener,can be null */ public void loadImage(String url, String lowUrl,int placeHolder, int errorResId, ScalingUtils.ScaleType scaleType, int width , int height , final BaseControllerListener<ImageInfo> l){ ImageRequest request = ImageRequestBuilder .newBuilderWithSource(Uri.parse(url)) //.setLowestPermittedRequestLevel(ImageRequest.RequestLevel.FULL_FETCH) .setResizeOptions(new ResizeOptions(width, height)) .build(); getHierarchy().setActualImageScaleType(scaleType); if(placeHolder!=0) { getHierarchy().setPlaceholderImage(getResources().getDrawable( placeHolder ),scaleType); } if(errorResId!=0){ getHierarchy().setFailureImage(getResources().getDrawable( errorResId ),scaleType); } PipelineDraweeControllerBuilder controller = Fresco.newDraweeControllerBuilder() .setControllerListener(l) .setImageRequest(request) .setOldController(getController()); if(lowUrl!=null){ Uri lowUri = lowUrl.startsWith("http") ? Uri.parse(lowUrl) : Uri.fromFile(new File(lowUrl)); controller.setLowResImageRequest(ImageRequestBuilder.newBuilderWithSource(lowUri) .setResizeOptions(new ResizeOptions(width, height)) .build() ); } setController(controller.build()); }
private void loadImageURI(Uri uri, @Nullable Object callerContext, int width, int height) { // 对URL做格式转换、尺寸限制等处理 uri = Uri.parse(ImageUtils.format(uri.toString(), DisplayInfo.getWidthPixels())); ImageRequestBuilder imageRequestBuilder = ImageRequestBuilder.newBuilderWithSource(uri); imageRequestBuilder.setProgressiveRenderingEnabled(true); imageRequestBuilder.setRotationOptions(RotationOptions.autoRotateAtRenderTime()); if (width > 0 && height > 0) { imageRequestBuilder.setResizeOptions(new ResizeOptions(width, height)); } PipelineDraweeControllerBuilder controller = Fresco.newDraweeControllerBuilder() .setCallerContext(callerContext) .setImageRequest(imageRequestBuilder.build()) .setOldController(getController()) .setAutoPlayAnimations(true) // 自动播放动态图 .setTapToRetryEnabled(true) // 在加载失败时,可以点击重新加载 .setControllerListener(new BaseControllerListener<ImageInfo>() { @Override public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) { super.onFinalImageSet(id, imageInfo, animatable); onUpdateImage(imageInfo); } }); if (AppUtils.isMainThread()) { setController(controller.build()); } else { Observable.just(0) .observeOn(AndroidSchedulers.mainThread()) .subscribe(it -> setController(controller.build())); } }
/** * 加载远程图片 * * @param url * @param imageSize */ private void displayImage(Uri url, ResizeOptions imageSize, final ImageView imageView, final DraweeHolder<GenericDraweeHierarchy> draweeHolder) { ImageRequest imageRequest = ImageRequestBuilder .newBuilderWithSource(url) .setResizeOptions(imageSize)//图片目标大小 .build(); ImagePipeline imagePipeline = Fresco.getImagePipeline(); final DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, this); DraweeController controller = Fresco.newDraweeControllerBuilder() .setOldController(draweeHolder.getController()) .setImageRequest(imageRequest) .setControllerListener(new BaseControllerListener<ImageInfo>() { @Override public void onFinalImageSet(String s, ImageInfo imageInfo, Animatable animatable) { CloseableReference<CloseableImage> imageReference = null; try { imageReference = dataSource.getResult(); if (imageReference != null) { CloseableImage image = imageReference.get(); if (image != null && image instanceof CloseableStaticBitmap) { CloseableStaticBitmap closeableStaticBitmap = (CloseableStaticBitmap) image; Bitmap bitmap = closeableStaticBitmap.getUnderlyingBitmap(); if (bitmap != null && imageView != null) { imageView.setImageBitmap(bitmap); } } } } finally { dataSource.close(); CloseableReference.closeSafely(imageReference); } } }) .setTapToRetryEnabled(true) .build(); draweeHolder.setController(controller); }
public void setImageUri(String url) { ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url)).build(); ImagePipeline imagePipeline = Fresco.getImagePipeline(); final DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, this); DraweeController controller = Fresco.newDraweeControllerBuilder() .setOldController(mDraweeHolder.getController()) .setImageRequest(imageRequest) .setControllerListener(new BaseControllerListener<ImageInfo>() { @Override public void onFinalImageSet(String s, @Nullable ImageInfo imageInfo, @Nullable Animatable animatable) { try { imageReference = dataSource.getResult(); if (imageReference != null) { CloseableImage image = imageReference.get(); // do something with the image if (image != null && image instanceof CloseableStaticBitmap) { CloseableStaticBitmap closeableStaticBitmap = (CloseableStaticBitmap) image; Bitmap bitmap = closeableStaticBitmap.getUnderlyingBitmap(); if (bitmap != null) { setImageBitmap(bitmap); } } } } finally { dataSource.close(); CloseableReference.closeSafely(imageReference); } } }) .setTapToRetryEnabled(true) .build(); mDraweeHolder.setController(controller); }
public void setImageUri(String uri, int width, int height) { ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(uri)) .setAutoRotateEnabled(true) .setResizeOptions(new ResizeOptions(width, height)) .build(); ImagePipeline imagePipeline = Fresco.getImagePipeline(); final DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, this); DraweeController controller = Fresco.newDraweeControllerBuilder() .setOldController(mDraweeHolder.getController()) .setImageRequest(imageRequest) .setControllerListener(new BaseControllerListener<ImageInfo>() { @Override public void onFinalImageSet(String s, @Nullable ImageInfo imageInfo, @Nullable Animatable animatable) { try { imageReference = dataSource.getResult(); if (imageReference != null) { CloseableImage image = imageReference.get(); if (image != null && image instanceof CloseableStaticBitmap) { CloseableStaticBitmap closeableStaticBitmap = (CloseableStaticBitmap) image; Bitmap bitmap = closeableStaticBitmap.getUnderlyingBitmap(); if (bitmap != null) { setImageBitmap(bitmap); } } } } finally { dataSource.close(); CloseableReference.closeSafely(imageReference); } } }) .setTapToRetryEnabled(true) .build(); mDraweeHolder.setController(controller); }
public static void showThumb(Uri uri, SimpleDraweeView draweeView){ ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri) .setAutoRotateEnabled(true) .setResizeOptions(new ResizeOptions(200, 200)) .build(); DraweeController controller = Fresco.newDraweeControllerBuilder() .setImageRequest(request) .setAutoPlayAnimations(true) .setOldController(draweeView.getController()) .setControllerListener(new BaseControllerListener<ImageInfo>()) .build(); draweeView.setController(controller); }
@Override public Object instantiateItem(ViewGroup viewGroup, int position) { final PhotoDraweeView photoDraweeView = new PhotoDraweeView(viewGroup.getContext()); PipelineDraweeControllerBuilder controller = Fresco.newDraweeControllerBuilder(); controller.setUri(Uri.parse("res:///" + mDrawables[position])); if(position == 1){ String uri1 = "http://git.oschina.net/biezhihua/MyResource/raw/master/25-173250_974.gif "; String uri2 = "http://img5.duitang.com/uploads/item/201511/04/20151104214718_FfnST.jpeg"; controller.setUri(Uri.parse(uri1)); } controller.setOldController(photoDraweeView.getController()); controller.setControllerListener(new BaseControllerListener<ImageInfo>() { @Override public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) { super.onFinalImageSet(id, imageInfo, animatable); if (imageInfo == null) { return; } photoDraweeView.update(imageInfo.getWidth(), imageInfo.getHeight()); if(animatable != null){ animatable.start(); } } }); photoDraweeView.setController(controller.build()); try { viewGroup.addView(photoDraweeView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); } catch (Exception e) { e.printStackTrace(); } return photoDraweeView; }
@Override public Object instantiateItem(ViewGroup viewGroup, int position) { IImageInfo bean = images.get(position); final PhotoDraweeView photoDraweeView = new PhotoDraweeView(viewGroup.getContext()); PipelineDraweeControllerBuilder controller = Fresco.newDraweeControllerBuilder(); controller.setUri(Uri.parse(bean.getUri())); controller.setOldController(photoDraweeView.getController()); controller.setControllerListener(new BaseControllerListener<ImageInfo>() { @Override public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) { super.onFinalImageSet(id, imageInfo, animatable); if (imageInfo == null) { return; } photoDraweeView.update(imageInfo.getWidth(), imageInfo.getHeight()); if(animatable != null){ animatable.start(); } } }); photoDraweeView.setController(controller.build()); try { viewGroup.addView(photoDraweeView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); } catch (Exception e) { e.printStackTrace(); } return photoDraweeView; }
public static boolean prepareBg(SimpleDraweeView bgImage, String bgFileName) { if (!TextUtils.isEmpty(bgFileName)) { File bgFile = new File("/sdcard/sololive/effect/ship3", bgFileName); Log.e(TAG, "bgFile=" + bgFile.getAbsolutePath()); if (bgFile.exists()) { if (FileUtils.isWebpFile(bgFileName)) { Log.e(TAG, "isWebp File"); ImageRequest localImageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.fromFile(bgFile)).build(); Log.e(TAG, "simpledrawee=" + bgImage.hashCode()); ControllerListener controllerListener = new BaseControllerListener<ImageInfo>() { @Override public void onFinalImageSet( String id, @Nullable ImageInfo imageInfo, @Nullable Animatable anim) { Log.e(TAG, "onFinalImageSet"); if (anim != null) { // app-specific logic to enable animation starting anim.start(); } } }; AbstractDraweeController localAbstractDraweeController = Fresco .newDraweeControllerBuilder() .setOldController(bgImage.getController()) .setControllerListener(controllerListener) .setImageRequest(localImageRequest) .build(); bgImage.setController(localAbstractDraweeController); return true; } else { Uri uri = Uri.fromFile(bgFile); bgImage.setImageURI(uri); } } } return false; }
private ControllerListener<? super ImageInfo> getControllerListener() { ControllerListener controllerListener = new BaseControllerListener<ImageInfo>(){ @Override public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) { imageLoaded = true; } }; return controllerListener; }
private void handleCaptcha(boolean isReload) { if (captchaResult == null) { return; } if (!isReload) { ViewAnimations.crossFade(primaryView, captchaContainer); } captchaImage.setController(Fresco.newDraweeControllerBuilder() .setUri(captchaResult.getCaptchaUrl(wiki)) .setAutoPlayAnimations(true) .setControllerListener(new BaseControllerListener<ImageInfo>() { @Override public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) { ((AppCompatActivity)activity).getSupportActionBar().setTitle(R.string.title_captcha); if (progressDialog.isShowing()) { progressDialog.hide(); } // for our Dark theme, show a "negative image" of the captcha! final int maxColorVal = 255; if (WikipediaApp.getInstance().getCurrentTheme().isDark()) { float[] colorMatrixNegative = { -1.0f, 0, 0, 0, maxColorVal, //red 0, -1.0f, 0, 0, maxColorVal, //green 0, 0, -1.0f, 0, maxColorVal, //blue 0, 0, 0, 1.0f, 0 //alpha }; captchaImage.getDrawable().setColorFilter(new ColorMatrixColorFilter(colorMatrixNegative)); } else { captchaImage.getDrawable().clearColorFilter(); } // In case there was a captcha attempt before captchaText.setText(""); } }) .build()); }
public void setShouldNotifyLoadEvents(boolean shouldNotify) { if (!shouldNotify) { mControllerListener = null; } else { final EventDispatcher mEventDispatcher = ((ReactContext) getContext()). getNativeModule(UIManagerModule.class).getEventDispatcher(); mControllerListener = new BaseControllerListener<ImageInfo>() { @Override public void onSubmit(String id, Object callerContext) { mEventDispatcher.dispatchEvent( new ImageLoadEvent(getId(), SystemClock.nanoTime(), ImageLoadEvent.ON_LOAD_START) ); } @Override public void onFinalImageSet( String id, @Nullable final ImageInfo imageInfo, @Nullable Animatable animatable) { if (imageInfo != null) { mEventDispatcher.dispatchEvent( new ImageLoadEvent(getId(), SystemClock.nanoTime(), ImageLoadEvent.ON_LOAD_END) ); mEventDispatcher.dispatchEvent( new ImageLoadEvent(getId(), SystemClock.nanoTime(), ImageLoadEvent.ON_LOAD) ); } } @Override public void onFailure(String id, Throwable throwable) { mEventDispatcher.dispatchEvent( new ImageLoadEvent(getId(), SystemClock.nanoTime(), ImageLoadEvent.ON_LOAD_END) ); } }; } mIsDirty = true; }
/** * @see #loadImage(String, String, int, int, ScalingUtils.ScaleType, int, int, BaseControllerListener) */ public void loadImage(String url, int placeHolder, int errorResId, ScalingUtils.ScaleType scaleType, final BaseControllerListener<ImageInfo> l){ loadImage(url,null, placeHolder, errorResId, scaleType,getWidth() , getHeight(),l); }
/** * @see #loadImage(String, String, int, int, ScalingUtils.ScaleType, int, int, BaseControllerListener) */ public void loadImage(String url, String lowUrl,int placeHolder, int errorResId, ScalingUtils.ScaleType scaleType, final BaseControllerListener<ImageInfo> l){ loadImage(url, lowUrl, placeHolder, errorResId, scaleType,getWidth() , getHeight(), l); }