Java Code Examples for com.facebook.drawee.view.DraweeHolder#setController()

The following examples show how to use com.facebook.drawee.view.DraweeHolder#setController() . 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: ReactToolbar.java    From react-native-GPay with MIT License 6 votes vote down vote up
/**
 * 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));
  }

}
 
Example 2
Source File: ReactToolbar.java    From native-navigation with MIT License 6 votes vote down vote up
/**
 * 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));
  }

}
 
Example 3
Source File: ReactBottomNavigation.java    From native-navigation with MIT License 6 votes vote down vote up
/**
 * 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));
  }
}
 
Example 4
Source File: DraweeSpanStringBuilder.java    From fresco with MIT License 6 votes vote down vote up
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);
}
 
Example 5
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());


    }
 
Example 6
Source File: FrescoImageLoader.java    From GalleryFinal with Apache License 2.0 4 votes vote down vote up
@Override
public void displayImage(Activity activity, String path, final GFImageView imageView, final Drawable defaultDrawable, int width, int height) {
    Resources resources = context.getResources();
    GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(resources)
            .setFadeDuration(300)
            .setPlaceholderImage(defaultDrawable)
            .setFailureImage(defaultDrawable)
            .setProgressBarImage(new ProgressBarDrawable())
            .build();

    final DraweeHolder<GenericDraweeHierarchy> draweeHolder = DraweeHolder.create(hierarchy, context);
    imageView.setOnImageViewListener(new GFImageView.OnImageViewListener() {
        @Override
        public void onDetach() {
            draweeHolder.onDetach();
        }

        @Override
        public void onAttach() {
            draweeHolder.onAttach();
        }

        @Override
        public boolean verifyDrawable(Drawable dr) {
            if (dr == draweeHolder.getHierarchy().getTopLevelDrawable()) {
                return true;
            }
            return false;
        }

        @Override
        public void onDraw(Canvas canvas) {
            Drawable drawable = draweeHolder.getHierarchy().getTopLevelDrawable();
            if (drawable == null) {
                imageView.setImageDrawable(defaultDrawable);
            } else {
                imageView.setImageDrawable(drawable);
            }
        }
    });
    Uri uri = new Uri.Builder()
            .scheme(UriUtil.LOCAL_FILE_SCHEME)
            .path(path)
            .build();
    ImageRequest imageRequest = ImageRequestBuilder
            .newBuilderWithSource(uri)
            .setResizeOptions(new ResizeOptions(width, height))//图片目标大小
            .build();
    DraweeController controller = Fresco.newDraweeControllerBuilder()
            .setOldController(draweeHolder.getController())
            .setImageRequest(imageRequest)
            .build();
    draweeHolder.setController(controller);
}