/** * Stubs addControllerListener * @param controller * @return forwarding listener */ public static ControllerListener stubControllerListener( final DraweeController controller) { final ForwardingControllerListener forwardingListener = new ForwardingControllerListener(); if (!(controller instanceof AbstractDraweeController)) { return null; } AbstractDraweeController abstractController = (AbstractDraweeController) controller; doAnswer( new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { forwardingListener.addListener((ControllerListener) invocation.getArguments()[0]); return null; } }).when(abstractController).addControllerListener(any(ControllerListener.class)); return forwardingListener; }
DraweeRequestHelper( ImageRequest imageRequest, @Nullable ImageRequest cachedImageRequest, ControllerListener listener) { AbstractDraweeControllerBuilder controllerBuilder = sControllerBuilder .setImageRequest(imageRequest) .setCallerContext(RCTImageView.getCallerContext()) .setControllerListener(listener); if (cachedImageRequest != null) { controllerBuilder.setLowResImageRequest(cachedImageRequest); } DraweeController controller = controllerBuilder.build(); controller.setHierarchy(sHierarchyBuilder.build()); mDraweeController = controller; }
/** * 图像选项类 * @param uri 图片路径 * @param oldController DraweeView.getoldcontroller * @param controllerListener 监听 * @return */ public static DraweeController getImageViewController(String uri, DraweeController oldController, ControllerListener<ImageInfo> controllerListener) { PipelineDraweeControllerBuilder builder = Fresco.newDraweeControllerBuilder(); if (!TextUtils.isEmpty(uri)) { // Logger.d("StringUtils.utf8Encode(uri)"+StringUtils.utf8Encode(uri)); builder.setUri(Uri.parse(uri)); } if (oldController != null) { builder.setOldController(oldController); } if (controllerListener != null) { builder.setControllerListener(controllerListener); } return builder.build(); }
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; }
private DraweeController createDraweeController( DraweeView draweeView, Uri uri, ControllerListener<ImageInfo> listener) { JungleSize size = ImageLoaderUtils.getAppropriateSize(draweeView); ImageRequest request = ImageRequestBuilder .newBuilderWithSource(uri) .setResizeOptions(new ResizeOptions(size.mWidth, size.mHeight)) .setAutoRotateEnabled(true) .build(); return Fresco.newDraweeControllerBuilder() .setUri(uri) .setImageRequest(request) .setControllerListener(listener) .setAutoPlayAnimations(true) .setOldController(draweeView.getController()) .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 PipelineDraweeControllerBuilderSupplier( Context context, ImagePipelineFactory imagePipelineFactory, Set<ControllerListener> boundControllerListeners, @Nullable DraweeConfig draweeConfig) { mContext = context; mImagePipeline = imagePipelineFactory.getImagePipeline(); if (draweeConfig != null && draweeConfig.getPipelineDraweeControllerFactory() != null) { mPipelineDraweeControllerFactory = draweeConfig.getPipelineDraweeControllerFactory(); } else { mPipelineDraweeControllerFactory = new PipelineDraweeControllerFactory(); } mPipelineDraweeControllerFactory.init( context.getResources(), DeferredReleaser.getInstance(), imagePipelineFactory.getAnimatedDrawableFactory(context), UiThreadImmediateExecutorService.getInstance(), mImagePipeline.getBitmapMemoryCache(), draweeConfig != null ? draweeConfig.getCustomDrawableFactories() : null, draweeConfig != null ? draweeConfig.getDebugOverlayEnabledSupplier() : null); mBoundControllerListeners = boundControllerListeners; }
public PipelineDraweeControllerBuilder( Context context, PipelineDraweeControllerFactory pipelineDraweeControllerFactory, ImagePipeline imagePipeline, Set<ControllerListener> boundControllerListeners) { super(context, boundControllerListeners); mImagePipeline = imagePipeline; mPipelineDraweeControllerFactory = pipelineDraweeControllerFactory; }
public VolleyDraweeControllerBuilderSupplier( Context context, ImageLoader imageLoader, Set<ControllerListener> boundControllerListeners) { mContext = context; mImageLoader = imageLoader; mVolleyDraweeControllerFactory = new VolleyDraweeControllerFactory( context.getResources(), DeferredReleaser.getInstance(), UiThreadImmediateExecutorService.getInstance()); mBoundControllerListeners = boundControllerListeners; }
public VolleyDraweeControllerBuilder( Context context, ImageLoader imageLoader, VolleyDraweeControllerFactory volleyDraweeControllerFactory, Set<ControllerListener> boundControllerListeners) { super(context, boundControllerListeners); mImageLoader = imageLoader; mVolleyDraweeControllerFactory = volleyDraweeControllerFactory; }
/** * 自定义控件调用该方法显示 * @param draweeView * @param uri * @param resizeOptions * @param defaultDrawable * @param scaleType */ public void disPlay(DraweeView draweeView, Uri uri, String lowResUri, ResizeOptions resizeOptions, Drawable defaultDrawable, ScalingUtils.ScaleType scaleType, ControllerListener controllerListener) { // System.out.println(draweeView.hasHierarchy()); if (!draweeView.hasHierarchy()) { setDefaultHierarchy(draweeView,defaultDrawable,scaleType); } ImageRequestBuilder imageRequestBuilder = ImageRequestBuilder.newBuilderWithSource(uri); if (UriUtil.isNetworkUri(uri)) { imageRequestBuilder.setProgressiveRenderingEnabled(true); } else { imageRequestBuilder.setLocalThumbnailPreviewsEnabled(true); imageRequestBuilder.setProgressiveRenderingEnabled(false); if ( resizeOptions != null ) { imageRequestBuilder.setResizeOptions(resizeOptions); } } // imageRequestBuilder.setAutoRotateEnabled(true); // imageRequestBuilder.setLowestPermittedRequestLevel(ImageRequest.RequestLevel.FULL_FETCH); DraweeController draweeController = Fresco.newDraweeControllerBuilder() .setImageRequest(imageRequestBuilder.build()) .setOldController(draweeView.getController()) .setLowResImageRequest(ImageRequest.fromUri(lowResUri)) .setControllerListener(controllerListener) .build(); draweeView.setController(draweeController); }
public void setController(@NonNull SimpleDraweeView draweeView, @Nullable String uri,@Nullable ControllerListener<ImageInfo> controllerListener){ DraweeController draweeController = initControllerBuilder() .setOldController(draweeView.getController()) .setUri(uri) .setControllerListener(controllerListener) .build(); draweeView.setController(draweeController); }
public void setImageRequest(@NonNull SimpleDraweeView draweeView, @Nullable ImageRequest imageRequest, @Nullable ControllerListener<ImageInfo> controllerListener){ DraweeController draweeController = initControllerBuilder() .setOldController(draweeView.getController()) .setImageRequest(imageRequest) .setControllerListener(controllerListener) .build(); draweeView.setController(draweeController); }
/** * 获取DraweeController * * @param imageRequest 设置单个图片请求~~~不可与setFirstAvailableImageRequests共用,配合setLowResImageRequest为高分辨率的图 * @param lowResImageRequest 先下载显示低分辨率的图 * @param firstAvailableImageRequests 本地图片复用,可加入ImageRequest数组 * @param controllerListener 监听图片下载完毕等 * @param tapToRetryEnabled 点击重新加载图 */ public static PipelineDraweeControllerBuilder getDraweeController(SimpleDraweeView view, @Nullable ImageRequest imageRequest, ImageRequest lowResImageRequest, @Nullable ImageRequest[] firstAvailableImageRequests, @Nullable ControllerListener<ImageInfo> controllerListener, boolean tapToRetryEnabled) { PipelineDraweeControllerBuilder builder = Fresco .newDraweeControllerBuilder(); //自动播放图片动画 builder.setAutoPlayAnimations(true); //点击重新加载图 builder.setTapToRetryEnabled(tapToRetryEnabled); if (firstAvailableImageRequests != null && firstAvailableImageRequests.length > 0) { //本地图片复用,可加入ImageRequest数组 builder.setFirstAvailableImageRequests(firstAvailableImageRequests); } else if (imageRequest != null) { //设置单个图片请求~~~不可与setFirstAvailableImageRequests共用,配合setLowResImageRequest为高分辨率的图 builder.setImageRequest(imageRequest); if (lowResImageRequest != null) { //先下载显示低分辨率的图 builder.setLowResImageRequest(lowResImageRequest); } } if (controllerListener != null) { //监听图片下载完毕等 builder.setControllerListener(controllerListener); } //DraweeController复用 builder.setOldController(view.getController()); return builder; }
public static void loadImageFromUrl(Context context, ImageView imageView, String url, String cookie, String referer, boolean noCache, ControllerListener controllerListener) { if (TextUtils.isEmpty(url)) { imageView.setImageURI(null); return; } Uri uri = Uri.parse(url); JsonObject header = new JsonObject(); header.addProperty("Cookie", cookie); header.addProperty("Referer", referer); if (url != null && url.startsWith("http")) { if (HProxy.isEnabled() && HProxy.isAllowPicture()) { HProxy proxy = new HProxy(url); header.addProperty(proxy.getHeaderKey(), proxy.getHeaderValue()); } MyOkHttpNetworkFetcher.headers.put(uri, getGson().toJson(header)); } if (imageView instanceof SimpleDraweeView) { SimpleDraweeView draweeView = ((SimpleDraweeView) imageView); ImageRequestBuilder requestBuilder = ImageRequestBuilder.newBuilderWithSource(uri) .setResizeOptions(new ResizeOptions(1080, 1920)); if (noCache) requestBuilder.disableDiskCache(); ImageRequest request = requestBuilder.build(); DraweeController controller = Fresco.newDraweeControllerBuilder() .setCallerContext(context) .setTapToRetryEnabled(true) .setAutoPlayAnimations(true) .setOldController(draweeView.getController()) .setControllerListener(controllerListener) .setImageRequest(request) .build(); draweeView.setController(controller); } }
public static RetainingDataSourceSupplier loadImageFromUrlRetainingImage(Context context, ImageView imageView, String url, String cookie, String referer, boolean noCache, ControllerListener controllerListener) { if (TextUtils.isEmpty(url)) { imageView.setImageURI(null); return null; } Uri uri = Uri.parse(url); JsonObject header = new JsonObject(); header.addProperty("Cookie", cookie); header.addProperty("Referer", referer); if (url != null && url.startsWith("http")) { if (HProxy.isEnabled() && HProxy.isAllowPicture()) { HProxy proxy = new HProxy(url); header.addProperty(proxy.getHeaderKey(), proxy.getHeaderValue()); } MyOkHttpNetworkFetcher.headers.put(uri, getGson().toJson(header)); } if (imageView instanceof SimpleDraweeView) { SimpleDraweeView draweeView = ((SimpleDraweeView) imageView); RetainingDataSourceSupplier<CloseableReference<CloseableImage>> retainingSupplier = new RetainingDataSourceSupplier<>(); PipelineDraweeControllerBuilder draweeControllerBuilder = Fresco.newDraweeControllerBuilder(); draweeControllerBuilder.setDataSourceSupplier(retainingSupplier); DraweeController controller = draweeControllerBuilder .setCallerContext(context) .setTapToRetryEnabled(true) .setAutoPlayAnimations(true) .setOldController(draweeView.getController()) .setControllerListener(controllerListener) .build(); draweeView.setController(controller); ImageRequestBuilder requestBuilder = ImageRequestBuilder.newBuilderWithSource(uri) .setResizeOptions(new ResizeOptions(1080, 1920)); if (noCache) requestBuilder.disableDiskCache(); ImageRequest request = requestBuilder.build(); retainingSupplier.setSupplier(Fresco.getImagePipeline().getDataSourceSupplier(request, null, ImageRequest.RequestLevel.FULL_FETCH)); return retainingSupplier; } return null; }
public static void loadThumbFromUrl(Context context, ImageView imageView, int resizeWidthDp, int resizeHeightDp, String url, String cookie, String referer, ControllerListener controllerListener) { if (TextUtils.isEmpty(url)) { imageView.setImageURI(null); return; } Uri uri = Uri.parse(url); JsonObject header = new JsonObject(); header.addProperty("Cookie", cookie); header.addProperty("Referer", referer); if (url != null && url.startsWith("http")) { if (HProxy.isEnabled() && HProxy.isAllowPicture()) { HProxy proxy = new HProxy(url); header.addProperty(proxy.getHeaderKey(), proxy.getHeaderValue()); MyOkHttpNetworkFetcher.headers.put(uri, getGson().toJson(header)); } MyOkHttpNetworkFetcher.headers.put(uri, getGson().toJson(header)); } if (imageView instanceof SimpleDraweeView) { ImageDecodeOptions imageDecodeOptions = new ImageDecodeOptionsBuilder() .setForceStaticImage(true) .setDecodePreviewFrame(true) .build(); ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri) .setResizeOptions(new ResizeOptions(DensityUtil.dp2px(context, resizeWidthDp), DensityUtil.dp2px(context, resizeHeightDp))) .setImageDecodeOptions(imageDecodeOptions) .setLocalThumbnailPreviewsEnabled(true) .build(); DraweeController controller = Fresco.newDraweeControllerBuilder() .setCallerContext(context) .setTapToRetryEnabled(true) .setAutoPlayAnimations(false) .setOldController(((SimpleDraweeView) imageView).getController()) .setControllerListener(controllerListener) .setImageRequest(request) .build(); ((SimpleDraweeView) imageView).setController(controller); } }
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; }
public ControllerListener<Object> getListener() { return mListener; }
public void disPlay(DraweeView draweeView, String imgUrl, String lowResUri, ControllerListener controllerListener) { disPlay(draweeView,getUriFromStr(imgUrl),lowResUri,null,null,null,controllerListener); }
@Override public ControllerListener getControllerListener() { return this.mControllerListener; }
@Override public void setControllerListener(ControllerListener controllerListener) { this.mControllerListener = controllerListener; }
public void setControllerListener(ControllerListener controllerListener) { mControllerForTesting = controllerListener; mIsDirty = true; maybeUpdateView(); }
public DraweeImageLoader(ControllerListener<ImageInfo> mListener, int defaultResId ) { this.mListener = mListener; this.mDefaultResId = defaultResId; }
public void setImageRequest(@NonNull SimpleDraweeView draweeView, @Nullable String uri, @Nullable ControllerListener<ImageInfo> controllerListener){ ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(uri)) .build(); setImageRequest(draweeView,imageRequest,controllerListener); }