Java Code Examples for com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder#setOldController()

The following examples show how to use com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder#setOldController() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FrescoImageLoader.java    From FimiX8-RE with MIT License 6 votes vote down vote up
public static void display(SimpleDraweeView view, String uri, int width, int height, ControllerListener listener) {
    if (uri != null) {
        PipelineDraweeControllerBuilder controller = Fresco.newDraweeControllerBuilder();
        controller.setOldController(view.getController());
        controller.setAutoPlayAnimations(true);
        ImageRequestBuilder imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(uri)).setCacheChoice(CacheChoice.SMALL).setLocalThumbnailPreviewsEnabled(true);
        imageRequest.setProgressiveRenderingEnabled(true);
        Log.d("Good", uri);
        if (width > 0 && height > 0) {
            imageRequest.setResizeOptions(new ResizeOptions(width, height));
        }
        controller.setImageRequest(imageRequest.build());
        controller.setControllerListener(listener);
        view.setController(controller.build());
    }
}
 
Example 2
Source File: ImageViewerAdapter.java    From photo-viewer with Apache License 2.0 6 votes vote down vote up
private void setController(String url, ReadableMap headers) {
			PipelineDraweeControllerBuilder controllerBuilder = Fresco.newDraweeControllerBuilder();
//			controllerBuilder.setUri(url);
			controllerBuilder.setOldController(drawee.getController());
			controllerBuilder.setControllerListener(getDraweeControllerListener(drawee));
			controllerBuilder.setAutoPlayAnimations(true);
			if (imageRequestBuilder != null) {
				imageRequestBuilder.setSource(Uri.parse(url));
				controllerBuilder.setImageRequest(imageRequestBuilder.build());
			}
//			support load local image just like React Native do

			ImageSource imageSource = new ImageSource(getContext(), url);
			ImageRequestBuilder imageRequestBuilder1 = ImageRequestBuilder.newBuilderWithSource(imageSource.getUri());
//			support headers
			ImageRequest imageRequest = ReactNetworkImageRequest.fromBuilderWithHeaders(imageRequestBuilder1, headers);

			controllerBuilder.setImageRequest(imageRequest);


			drawee.setController(controllerBuilder.build());
		}
 
Example 3
Source File: PhotoShowActivity.java    From Elephant with Apache License 2.0 6 votes vote down vote up
@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());
    }
}
 
Example 4
Source File: GalleryActivity.java    From phphub-android with Apache License 2.0 6 votes vote down vote up
@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());
    }
}
 
Example 5
Source File: ViewPagerActivity.java    From PhotoDraweeView with Apache License 2.0 6 votes vote down vote up
@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]));
    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());
        }
    });
    photoDraweeView.setController(controller.build());

    try {
        viewGroup.addView(photoDraweeView, ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);
    } catch (Exception e) {
        e.printStackTrace();
    }

    return photoDraweeView;
}
 
Example 6
Source File: DraweeViewHolder.java    From fresco with MIT License 6 votes vote down vote up
/** @param uri The Uri to show into the DraweeView for this Holder */
public void bind(Uri uri) {
  mDraweeView.initInstrumentation(uri.toString(), mPerfListener);
  ImageRequestBuilder imageRequestBuilder =
      ImageRequestBuilder.newBuilderWithSource(uri)
          .setResizeOptions(
              new ResizeOptions(
                  mDraweeView.getLayoutParams().width, mDraweeView.getLayoutParams().height));
  PipelineUtil.addOptionalFeatures(imageRequestBuilder, mConfig);
  // Create the Builder
  PipelineDraweeControllerBuilder builder =
      Fresco.newDraweeControllerBuilder().setImageRequest(imageRequestBuilder.build());
  if (mConfig.reuseOldController) {
    builder.setOldController(mDraweeView.getController());
  }
  mDraweeView.setListener(builder);
  mDraweeView.setController(builder.build());
}
 
Example 7
Source File: FrescoUtils.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public static void displayPhoto(SimpleDraweeView mSimpleDraweeView, String path, int width, int height) {
    if (!TextUtils.isEmpty(path)) {
        PipelineDraweeControllerBuilder mPipelineDraweeControllerBuilder = Fresco.newDraweeControllerBuilder();
        ImageRequestBuilder mImageRequestBuilder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(path));
        mImageRequestBuilder.setResizeOptions(new ResizeOptions(width, height));
        mPipelineDraweeControllerBuilder.setOldController(mSimpleDraweeView.getController());
        mPipelineDraweeControllerBuilder.setImageRequest(mImageRequestBuilder.build());
        mSimpleDraweeView.setController(mPipelineDraweeControllerBuilder.build());
    }
}
 
Example 8
Source File: FrescoUtils.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public static void displayPhoto(SimpleDraweeView mSimpleDraweeView, String path, int width, int height, ControllerListener mControllerListener) {
    if (!TextUtils.isEmpty(path)) {
        PipelineDraweeControllerBuilder mPipelineDraweeControllerBuilder = Fresco.newDraweeControllerBuilder();
        ImageRequestBuilder mImageRequestBuilder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(path));
        mImageRequestBuilder.setResizeOptions(new ResizeOptions(width, height));
        mPipelineDraweeControllerBuilder.setOldController(mSimpleDraweeView.getController());
        mPipelineDraweeControllerBuilder.setImageRequest(mImageRequestBuilder.build());
        mPipelineDraweeControllerBuilder.setControllerListener(mControllerListener);
        mSimpleDraweeView.setController(mPipelineDraweeControllerBuilder.build());
    }
}
 
Example 9
Source File: FrescoImageLoader.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public static void display(SimpleDraweeView view, String lowUri, String uri, ControllerListener listener) {
    if (uri != null) {
        ImageRequestBuilder imageRequest;
        int w = view.getLayoutParams().width;
        int h = view.getLayoutParams().height;
        PipelineDraweeControllerBuilder controller = Fresco.newDraweeControllerBuilder();
        if (!lowUri.startsWith("file:///")) {
            lowUri = "file://" + lowUri;
        }
        if (lowUri != null && lowUri.length() > 0) {
            controller.setLowResImageRequest(ImageRequest.fromUri(lowUri));
        }
        controller.setOldController(view.getController());
        controller.setAutoPlayAnimations(true);
        if (uri.endsWith(".MP4")) {
            imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(lowUri));
        } else {
            imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(uri));
        }
        if (w > 0 && h > 0) {
            imageRequest.setResizeOptions(new ResizeOptions(w, h));
        }
        controller.setImageRequest(imageRequest.build());
        controller.setControllerListener(listener);
        view.setController(controller.build());
    }
}
 
Example 10
Source File: FrescoLoader.java    From ImageLoader with Apache License 2.0 5 votes vote down vote up
private void requestForSimpleDraweeView(SimpleDraweeView target, SingleConfig config) {

        // 数据-model
        ImageRequest request = buildRequest(config);

        //view
        setDraweeHierarchyForDraweeView(config);

        //controller
        PipelineDraweeControllerBuilder controller = buildPipelineDraweeController(config,request);
        controller.setOldController(target.getController());

        target.setController(controller.build());
    }
 
Example 11
Source File: FrescoUtils.java    From SprintNBA with Apache License 2.0 5 votes vote down vote up
public static PipelineDraweeControllerBuilder getPreController(String url, final PhotoDraweeView draweeView) {
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url))
            .setProgressiveRenderingEnabled(true)
            .build();

    PipelineDraweeControllerBuilder controller = Fresco.newDraweeControllerBuilder();
    controller.setImageRequest(request);
    controller.setOldController(draweeView.getController());
    controller.setAutoPlayAnimations(true);
    return controller;
}
 
Example 12
Source File: ImageFragment.java    From TLint with Apache License 2.0 5 votes vote down vote up
@Override
public void initData() {
    showContent(true);
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url))
            .setProgressiveRenderingEnabled(true)
            .build();

    GenericDraweeHierarchy hierarchy =
            new GenericDraweeHierarchyBuilder(getResources()).setProgressBarImage(
                    new ImageLoadProgressBar(new ImageLoadProgressBar.OnLevelChangeListener() {
                        @Override
                        public void onChange(int level) {
                            if (level > 100 && progress.getVisibility() == View.VISIBLE) {
                                progress.setVisibility(View.GONE);
                            }
                        }
                    }, ResourceUtil.getThemeColor(getActivity()))).build();
    hierarchy.setActualImageScaleType(ScalingUtils.ScaleType.FIT_CENTER);

    PipelineDraweeControllerBuilder controller = Fresco.newDraweeControllerBuilder();
    controller.setControllerListener(listener);
    controller.setImageRequest(request);
    controller.setOldController(image.getController());
    controller.setAutoPlayAnimations(true);
    image.setHierarchy(hierarchy);
    image.setController(controller.build());
}
 
Example 13
Source File: DraweeViewListAdapter.java    From fresco with MIT License 5 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
  InstrumentedDraweeView draweeView;
  if (convertView == null) {
    final Context context = parent.getContext();
    GenericDraweeHierarchy gdh = DraweeUtil.createDraweeHierarchy(context, mConfig);
    draweeView = new InstrumentedDraweeView(context, gdh, mConfig);
    SizeUtil.setConfiguredSize(parent, draweeView, mConfig);
    draweeView.setPadding(mPaddingPx, mPaddingPx, mPaddingPx, mPaddingPx);
  } else {
    draweeView = (InstrumentedDraweeView) convertView;
  }
  final Uri uri = getItem(position);
  draweeView.initInstrumentation(uri.toString(), mPerfListener);
  ImageRequestBuilder imageRequestBuilder =
      ImageRequestBuilder.newBuilderWithSource(uri)
          .setResizeOptions(
              new ResizeOptions(
                  draweeView.getLayoutParams().width, draweeView.getLayoutParams().height));
  PipelineUtil.addOptionalFeatures(imageRequestBuilder, mConfig);
  // Create the Builder
  PipelineDraweeControllerBuilder builder =
      Fresco.newDraweeControllerBuilder().setImageRequest(imageRequestBuilder.build());
  if (mConfig.reuseOldController) {
    builder.setOldController(draweeView.getController());
  }
  if (mConfig.instrumentationEnabled) {
    draweeView.setListener(builder);
  }
  draweeView.setController(builder.build());
  return draweeView;
}
 
Example 14
Source File: FrescoLoader.java    From ImageLoader with Apache License 2.0 4 votes vote down vote up
private void requestForImageView(ImageView imageView,final SingleConfig config) {

           /* config.setBitmapListener(new SingleConfig.BitmapListener() {
                @Override
                public void onSuccess(Bitmap bitmap) {
                    imageView.setImageBitmap(bitmap);
                }

                @Override
                public void onFail(Throwable e) {
                    if(config.getErrorResId() >0){
                        imageView.setImageResource(config.getErrorResId());
                    }
                }
            });
            requestBitmap(config);
            return;*/
           checkWrapContentOrMatchParent(config);


        //GenericDraweeHierarchy hierarchy=null;
        GenericDraweeHierarchy hierarchy = GenericDraweeHierarchyBuilder.newInstance(imageView.getContext().getResources()).build();
        setupHierarchy(hierarchy,config);

        // 数据-model
        ImageRequest request = buildRequest(config);

        //设置controller

        DraweeHolder draweeHolder= (DraweeHolder) imageView.getTag(R.id.fresco_drawee);


        PipelineDraweeControllerBuilder controllerBuilder = buildPipelineDraweeController(config,request);


        if (draweeHolder == null) {
            draweeHolder=DraweeHolder.create(hierarchy,imageView.getContext());
        }else {
             controllerBuilder.setOldController(draweeHolder.getController());
            draweeHolder.setHierarchy(hierarchy);
        }

        draweeHolder.setController(controllerBuilder.build());


        //imageview的特殊处理
        ViewStatesListener mStatesListener=new ViewStatesListener(draweeHolder);

        imageView.addOnAttachStateChangeListener(mStatesListener);

        // 判断是否ImageView已经 attachToWindow
        if (ViewCompat.isAttachedToWindow(imageView)) {
            draweeHolder.onAttach();
        }

        //设置scaletype
        //setImageViewScaleType(imageView,config);


//        if (ViewC.isAttachedToWindow()) {
//            draweeHolder.onAttach();
//        }
        // 保证每一个ImageView中只存在一个draweeHolder
        imageView.setTag(R.id.fresco_drawee,draweeHolder);
        // 拿到数据
        imageView.setImageDrawable(draweeHolder.getTopLevelDrawable());


    }