@Override protected PipelineDraweeController obtainController() { DraweeController oldController = getOldController(); PipelineDraweeController controller; if (oldController instanceof PipelineDraweeController) { controller = (PipelineDraweeController) oldController; controller.initialize( obtainDataSourceSupplier(), generateUniqueControllerId(), getCacheKey(), getCallerContext(), mCustomDrawableFactories); } else { controller = mPipelineDraweeControllerFactory.newController( obtainDataSourceSupplier(), generateUniqueControllerId(), getCacheKey(), getCallerContext(), mCustomDrawableFactories); } return controller; }
@Override protected VolleyDraweeController obtainController() { DraweeController oldController = getOldController(); VolleyDraweeController controller; if (oldController instanceof VolleyDraweeController) { controller = (VolleyDraweeController) oldController; controller.initialize( obtainDataSourceSupplier(), generateUniqueControllerId(), getCallerContext()); } else { controller = mVolleyDraweeControllerFactory.newController( obtainDataSourceSupplier(), generateUniqueControllerId(), getCallerContext()); } return controller; }
/** * Sets a new controller. */ public void setController(@Nullable DraweeController draweeController) { boolean wasAttached = mIsControllerAttached; if (wasAttached) { detachController(); } // Clear the old controller if (isControllerValid()) { mEventTracker.recordEvent(Event.ON_CLEAR_OLD_CONTROLLER); mController.setHierarchy(null); } mController = draweeController; if (mController != null) { mEventTracker.recordEvent(Event.ON_SET_CONTROLLER); mController.setHierarchy(mHierarchy); } else { mEventTracker.recordEvent(Event.ON_CLEAR_CONTROLLER); } if (wasAttached) { attachController(); } }
/** * 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; }
public void setImageSpan( Context context, DraweeHierarchy draweeHierarchy, DraweeController draweeController, int index, final int drawableWidthPx, final int drawableHeightPx, boolean enableResizing, @BetterImageSpan.BetterImageSpanAlignment int verticalAlignment) { setImageSpan( context, draweeHierarchy, draweeController, index, index, drawableWidthPx, drawableHeightPx, enableResizing, verticalAlignment); }
public void setImageSpan( Context context, DraweeHierarchy draweeHierarchy, DraweeController draweeController, int startIndex, int endIndex, final int drawableWidthPx, final int drawableHeightPx, boolean enableResizing, @BetterImageSpan.BetterImageSpanAlignment int verticalAlignment) { DraweeHolder draweeHolder = DraweeHolder.create(draweeHierarchy, context); draweeHolder.setController(draweeController); setImageSpan( draweeHolder, startIndex, endIndex, drawableWidthPx, drawableHeightPx, enableResizing, verticalAlignment); }
@Override protected void onBind(String uriString) { Uri uri = Uri.parse(uriString); ImageRequestBuilder imageRequestBuilder = ImageRequestBuilder.newBuilderWithSource(uri); if (UriUtil.isNetworkUri(uri)) { imageRequestBuilder.setProgressiveRenderingEnabled(true); } else { imageRequestBuilder.setResizeOptions(new ResizeOptions( mImageView.getLayoutParams().width, mImageView.getLayoutParams().height)); } DraweeController draweeController = Fresco.newDraweeControllerBuilder() .setImageRequest(imageRequestBuilder.build()) .setOldController(mImageView.getController()) .setControllerListener(mImageView.getListener()) .setAutoPlayAnimations(true) .build(); mImageView.setController(draweeController); }
@Override protected void onDraw(Canvas canvas) { int saveCount = canvas.save(); canvas.concat(mZoomableController.getTransform()); try { super.onDraw(canvas); } catch (Exception e) { DraweeController controller = getController(); if (controller != null && controller instanceof AbstractDraweeController) { Object callerContext = ((AbstractDraweeController) controller).getCallerContext(); if (callerContext != null) { throw new RuntimeException( String.format("Exception in onDraw, callerContext=%s", callerContext.toString()), e); } } throw e; } canvas.restoreToCount(saveCount); }
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB) private void initAnimation(View view) { mSimpleDraweeView = (SimpleDraweeView) view.findViewById(R.id.drawee_view); mSimpleDraweeView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); DraweeController controller = Fresco.newDraweeControllerBuilder() .setOldController(mSimpleDraweeView.getController()) .setUri(URI_KEYFRAMES_ANIMATION) .setAutoPlayAnimations(true) .build(); mSimpleDraweeView.setController(controller); final SwitchCompat switchBackground = (SwitchCompat) view.findViewById(R.id.switch_background); switchBackground.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mSimpleDraweeView.getHierarchy().setBackgroundImage(isChecked ? new CheckerBoardDrawable(getResources()) : null); } }); }
private void loadThumb( SimpleDraweeView draweeView, Size size, ImageRequest.RequestLevel requestLevel) { ImageRequest request = ImageRequestBuilder.newBuilderWithSource(size.uri) .setMediaVariations(MediaVariations.newBuilderForMediaId(MEDIA_ID) .setForceRequestForSpecifiedUri(true) .build()) .setLowestPermittedRequestLevel(requestLevel) .setResizeOptions(new ResizeOptions(draweeView.getWidth(), draweeView.getHeight())) .setCacheChoice(size.cacheChoice) .build(); DraweeController controller = Fresco.newDraweeControllerBuilder() .setImageRequest(request) .setOldController(draweeView.getController()) .build(); draweeView.setController(controller); }
@Override public Object instantiateItem(ViewGroup container, int position) { FrameLayout page = (FrameLayout) container.getChildAt(position); if (page == null) { return null; } ZoomableDraweeView zoomableDraweeView = (ZoomableDraweeView) page.findViewById(R.id.zoomableView); zoomableDraweeView.setAllowTouchInterceptionWhileZoomed(mAllowSwipingWhileZoomed); // needed for double tap to zoom zoomableDraweeView.setIsLongpressEnabled(false); zoomableDraweeView.setTapListener(new DoubleTapGestureListener(zoomableDraweeView)); DraweeController controller = Fresco.newDraweeControllerBuilder() .setUri(SAMPLE_URIS[position % SAMPLE_URIS.length]) .setCallerContext("ZoomableApp-MyPagerAdapter") .build(); zoomableDraweeView.setController(controller); page.requestLayout(); return page; }
private void displayImage(SimpleDraweeView draweeView, String url) { GenericDraweeHierarchy hierarchy = draweeView.getHierarchy(); //设置占位图 if (hierarchy == null) { hierarchy = GenericDraweeHierarchyBuilder.newInstance(getResources()) .setPlaceholderImage(getResources().getDrawable(R.mipmap.ic_launcher) , ScalingUtils.ScaleType.CENTER).build(); draweeView.setHierarchy(hierarchy); } else { hierarchy.setPlaceholderImage(getResources().getDrawable(R.mipmap.ic_launcher) , ScalingUtils.ScaleType.CENTER); } //构建ImageRequestBuilder,传入请求Uri ImageRequestBuilder requestBuilder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url)); //构建Controller DraweeController controller = Fresco.newDraweeControllerBuilder() .setOldController(draweeView.getController()) .setImageRequest(requestBuilder.build()) .build(); //设置图片,Fresco设置显示图片都是通过Controller来实现 draweeView.setController(controller); }
@Override public Object instantiateItem(ViewGroup container, int position) { View view = LayoutInflater.from(mContext).inflate(R.layout.zoomable_view_pager_item, null); ZoomableDraweeView zoomableDraweeView = (ZoomableDraweeView) view.findViewById(R.id.zoomable_image); //允许缩放时切换 zoomableDraweeView.setAllowTouchInterceptionWhileZoomed(true); //长按 zoomableDraweeView.setIsLongpressEnabled(false); //双击击放大或缩小 zoomableDraweeView.setTapListener(new DoubleTapGestureListener(zoomableDraweeView)); DraweeController draweeController = Fresco.newDraweeControllerBuilder() .setUri(mPaths.get(position)) .build(); //加载图片 zoomableDraweeView.setController(draweeController); container.addView(view); view.requestLayout(); return view; }
private void layoutChildrenView() { int childrenCount = getChildCount(); for (int i = 0; i < childrenCount; i++) { ViewGroup childImageLayout = (ViewGroup) getChildAt(i); SimpleDraweeView childImageView = (SimpleDraweeView) childImageLayout.getChildAt(0); if (mOnItemClickListener != null) { final int finalI = i; childImageLayout.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mOnItemClickListener.OnItemClick(finalI); } }); } ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(mImageUrls.get(i))) .setProgressiveRenderingEnabled(true) .setResizeOptions(new ResizeOptions(mItemWidth, mItemWidth)) .build(); DraweeController controller = Fresco.newDraweeControllerBuilder() .setImageRequest(request) .setOldController(childImageView.getController()) .build(); childImageView.setController(controller); int[] position = findPosition(i); int itemHeight = mItemWidth; int left = (int) (mItemWidth + mHorizontalSpace) * position[1]; int top = (int) (itemHeight + mVerticalSpace) * position[0]; int right = left + mItemWidth; int bottom = top + itemHeight; childImageLayout.layout(left, top, right, bottom); } }
private void refreshImageChild() { int childrenCount = getChildCount(); if (childrenCount > 0) { for (int i = 0; i < childrenCount; i++) { ViewGroup childImageLayout = (ViewGroup) getChildAt(i); SimpleDraweeView childImageView = (SimpleDraweeView) childImageLayout.getChildAt(0); if (mOnItemClickListener != null) { final int finalI = i; childImageLayout.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mOnItemClickListener.OnItemClick(finalI); } }); } ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(mImageUrls.get(i))) .setResizeOptions(new ResizeOptions(mItemWidth, mItemWidth)) .build(); DraweeController controller = Fresco.newDraweeControllerBuilder() .setImageRequest(request) .setOldController(childImageView.getController()) .build(); childImageView.setController(controller); } } }
@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 setBlurFrescoController(SimpleDraweeView simpleDraweeView, String url, int iterations, int blurRadius) { try { Uri uri = Uri.parse(url); ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri) .setPostprocessor(new IterativeBoxBlurPostProcessor(iterations, blurRadius)) .build(); DraweeController controller = Fresco.newDraweeControllerBuilder() .setOldController(simpleDraweeView.getController()) .setImageRequest(request) .build(); simpleDraweeView.setController(controller); } catch (Exception e) { e.printStackTrace(); } }
private void setIconSource(ReadableMap source, IconControllerListener controllerListener, DraweeHolder holder) { String uri = source != null ? source.getString("uri") : null; if (uri == null) { controllerListener.setIconImageInfo(null); controllerListener.setDrawable(null); } else if (uri.startsWith("http://") || uri.startsWith("https://") || uri.startsWith("file://")) { controllerListener.setIconImageInfo(getIconImageInfo(source)); DraweeController controller = Fresco.newDraweeControllerBuilder() .setUri(Uri.parse(uri)) .setControllerListener(controllerListener) .setOldController(holder.getController()) .build(); holder.setController(controller); holder.getTopLevelDrawable().setVisible(true, true); } else { controllerListener.setDrawable(getDrawableByName(uri)); } }
public static void setImageSmall(String url, SimpleDraweeView simpleDraweeView, int width, int height, SquareRelativeLayout relativeLayout, boolean playGif) { Uri uri = Uri.parse(url); ImageRequest request = ImageRequestBuilder .newBuilderWithSource(uri) .setRotationOptions(RotationOptions.autoRotate()) .setResizeOptions(new ResizeOptions(width, height)) .setLowestPermittedRequestLevel(ImageRequest.RequestLevel.FULL_FETCH) .build(); DraweeController controller = Fresco.newDraweeControllerBuilder() .setTapToRetryEnabled(true) .setImageRequest(request) .setAutoPlayAnimations(playGif) .setOldController(simpleDraweeView.getController()) .build(); relativeLayout.setLayoutParams(new RelativeLayout.LayoutParams(width - 5, height)); simpleDraweeView.setController(controller); }
public static void loadHeadView(Context context, SimpleDraweeView simpleDraweeView, Uri httpUri) { //初始化圆角圆形参数对象 RoundingParams rp = new RoundingParams(); //设置图像是否为圆形 rp.setRoundAsCircle(true); final GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(context.getResources()) .setRoundingParams(rp) .build(); DraweeController controller = Fresco.newDraweeControllerBuilder() .setUri(httpUri) .setTapToRetryEnabled(true) .setOldController(simpleDraweeView.getController()) .build(); simpleDraweeView.setHierarchy(hierarchy); simpleDraweeView.setController(controller); }
/** * 指定控件 * * @param simpleDraweeView */ public void into(@NonNull SimpleDraweeView simpleDraweeView) { ImageRequestBuilder imageRequestBuilder = ImageRequestBuilder.newBuilderWithSource(uri); if (resizeOptions != null) { imageRequestBuilder.setResizeOptions(resizeOptions); } if (postprocessor != null) { imageRequestBuilder.setPostprocessor(postprocessor); } if (priority != null) { imageRequestBuilder.setRequestPriority(priority); } DraweeController controller = Fresco.newDraweeControllerBuilder() .setImageRequest(imageRequestBuilder.build()) .setOldController(simpleDraweeView.getController()) .build(); simpleDraweeView.setController(controller); }
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; }
/** * Sets an icon for a specific icon source. If the uri indicates an icon * to be somewhere remote (http/https) or on the local filesystem, it uses fresco to load it. * Otherwise it loads the Drawable from the Resources and directly returns it via a callback */ private void setIconSource(ReadableMap source, IconControllerListener controllerListener, DraweeHolder holder) { String uri = source != null ? source.getString(PROP_ICON_URI) : null; if (uri == null) { controllerListener.setIconImageInfo(null); controllerListener.setDrawable(null); } else if (uri.startsWith("http://") || uri.startsWith("https://") || uri.startsWith("file://")) { controllerListener.setIconImageInfo(getIconImageInfo(source)); DraweeController controller = Fresco.newDraweeControllerBuilder() .setUri(Uri.parse(uri)) .setControllerListener(controllerListener) .setOldController(holder.getController()) .build(); holder.setController(controller); holder.getTopLevelDrawable().setVisible(true, true); } else { controllerListener.setDrawable(getDrawableByName(uri)); } }
/** * Sets an icon for a specific icon source. If the uri indicates an icon * to be somewhere remote (http/https) or on the local filesystem, it uses fresco to load it. * Otherwise it loads the Drawable from the Resources and directly returns it via a callback */ private void setIconSource(ReadableMap source, IconControllerListener controllerListener, DraweeHolder holder) { String uri = source != null ? source.getString(PROP_ICON_URI) : null; if (uri == null) { controllerListener.setIconImageInfo(null); controllerListener.setDrawable(null); } else if (uri.startsWith("http://") || uri.startsWith("https://") || uri.startsWith("file://")) { controllerListener.setIconImageInfo(getIconImageInfo(source)); DraweeController controller = Fresco.newDraweeControllerBuilder() .setUri(Uri.parse(uri)) .setControllerListener(controllerListener) .setOldController(holder.getController()) .build(); holder.setController(controller); } else { controllerListener.setDrawable(getDrawableByName(uri)); } }
private void setupItemImage(SimpleDraweeView imageView, Uri imageUrl, boolean isVertical) { ImageRequest request = ImageRequestBuilder.newBuilderWithSource(imageUrl) .setProgressiveRenderingEnabled(true) .build(); DraweeController controller = Fresco.newDraweeControllerBuilder() .setImageRequest(request) .setOldController(imageView.getController()) .build(); imageView.setController(controller); // imageView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) context.getResources().getDimension(R.dimen.poster_grid2_height))); final RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) imageView.getLayoutParams(); // if (!isVertical) { lp.height = ViewGroup.LayoutParams.MATCH_PARENT; lp.width = (recyclerView.getMeasuredHeight()/3)*2/3; } else { lp.height = recyclerView.getMeasuredWidth()/2; lp.width = ViewGroup.LayoutParams.MATCH_PARENT; } imageView.setLayoutParams(lp); }
public void setImage(String uri) { if (uri == null) { iconBitmapDescriptor = null; update(); } else if (uri.startsWith("http://") || uri.startsWith("https://") || uri.startsWith("file://")) { ImageRequest imageRequest = ImageRequestBuilder .newBuilderWithSource(Uri.parse(uri)) .build(); ImagePipeline imagePipeline = Fresco.getImagePipeline(); dataSource = imagePipeline.fetchDecodedImage(imageRequest, this); DraweeController controller = Fresco.newDraweeControllerBuilder() .setImageRequest(imageRequest) .setControllerListener(mLogoControllerListener) .setOldController(logoHolder.getController()) .build(); logoHolder.setController(controller); } else { iconBitmapDescriptor = getBitmapDescriptorByName(uri); update(); } }
/** * 设置图片 * * @param image * @param url * @param width * @param heigth */ public void setDraweeImage(SimpleDraweeView image, String url, int width, int heigth) { if (width <= 0) { width = dp2Px(image.getContext(), 50); } if (heigth <= 0) { heigth = dp2Px(image.getContext(), 50); } ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url)).setLocalThumbnailPreviewsEnabled(true).setResizeOptions(new ResizeOptions(width, heigth)).build(); DraweeController draweeController = Fresco.newDraweeControllerBuilder() .setImageRequest(imageRequest) .setAutoPlayAnimations(true) .build(); image.setController(draweeController); }
/** * 图像选项类 * @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(); }
/** * 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; }
@BindingAdapter({"bind:normalUrl", "bind:teaserUrl"}) public static void loadImage(SimpleDraweeView view, String normal, String teaser) { ImageRequest imageRequest = ImageRequest.fromUri(normal); ImageRequest lowRequest = null; if (!TextUtils.isEmpty(teaser)) { lowRequest = ImageRequest.fromUri(teaser); } DraweeController draweeController = Fresco.newDraweeControllerBuilder() .setImageRequest(imageRequest) .setLowResImageRequest(lowRequest) .setOldController(view.getController()) .setAutoPlayAnimations(true) .build(); view.setController(draweeController); }
@Override protected void onPostExecute(String url) { if(mImage != null && !TextUtils.isEmpty(url)) { if(mImage.getTag() != null && mImage.getTag().equals(url)){ return; } DraweeController controller = Fresco.newDraweeControllerBuilder() .setImageRequest(ImageRequestBuilder.newBuilderWithSource(Uri.parse(url)) .build()) .setOldController(mImage.getController()) .build(); mImage.setController(controller); mImage.setTag(url); } }
@Override public View showThumbnail(BigImageView parent, Uri thumbnail, int scaleType) { SimpleDraweeView thumbnailView = (SimpleDraweeView) LayoutInflater.from(parent.getContext()) .inflate(R.layout.ui_fresco_thumbnail, parent, false); DraweeController controller = Fresco.newDraweeControllerBuilder() .setUri(thumbnail) .build(); switch (scaleType) { case BigImageView.INIT_SCALE_TYPE_CENTER_CROP: thumbnailView.getHierarchy() .setActualImageScaleType(ScalingUtils.ScaleType.CENTER_CROP); break; case BigImageView.INIT_SCALE_TYPE_CENTER_INSIDE: thumbnailView.getHierarchy() .setActualImageScaleType(ScalingUtils.ScaleType.CENTER_INSIDE); break; case BigImageView.INIT_SCALE_TYPE_START: thumbnailView.getHierarchy() .setActualImageScaleType(ScalingUtils.ScaleType.FIT_START); break; default: break; } thumbnailView.setController(controller); return thumbnailView; }