com.facebook.drawee.view.DraweeHolder Java Examples

The following examples show how to use com.facebook.drawee.view.DraweeHolder. 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: ShapedDraweeView.java    From AndroidPlayground with MIT License 6 votes vote down vote up
private void setup(Context context, AttributeSet attrs, int defStyle) {
    if (getScaleType() == ScaleType.FIT_CENTER) {
        setScaleType(ScaleType.CENTER_CROP);
    }

    Drawable placeholder = null;
    if (attrs != null) {
        TypedArray typedArray =
                context.obtainStyledAttributes(attrs, R.styleable.ShapedDrawee, defStyle, 0);
        shape = typedArray.getDrawable(R.styleable.ShapedDrawee_maskShape);
        placeholder = typedArray.getDrawable(R.styleable.ShapedDrawee_placeholder);
        typedArray.recycle();
    }
    if (shape == null) {
        throw new IllegalArgumentException("maskShape must be specified in layout!");
    }

    GenericDraweeHierarchy hierarchy =
            new GenericDraweeHierarchyBuilder(getResources()).setPlaceholderImage(placeholder)
                    .setPlaceholderImageScaleType(ScalingUtils.ScaleType.CENTER_CROP)
                    .setActualImageScaleType(ScalingUtils.ScaleType.CENTER_CROP)
                    .build();
    mDraweeHolder = DraweeHolder.create(hierarchy, getContext());
}
 
Example #2
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 #3
Source File: FrescoBasedReactTextInlineImageSpan.java    From react-native-GPay with MIT License 6 votes vote down vote up
public FrescoBasedReactTextInlineImageSpan(
    Resources resources,
    int height,
    int width,
    int tintColor,
    @Nullable Uri uri,
    ReadableMap headers,
    AbstractDraweeControllerBuilder draweeControllerBuilder,
    @Nullable Object callerContext) {
  mDraweeHolder = new DraweeHolder(
      GenericDraweeHierarchyBuilder.newInstance(resources)
          .build()
  );
  mDraweeControllerBuilder = draweeControllerBuilder;
  mCallerContext = callerContext;
  mTintColor = tintColor;
  mUri = (uri != null) ? uri : Uri.EMPTY;
  mHeaders = headers;
  mWidth = (int)(PixelUtil.toPixelFromDIP(width));
  mHeight = (int)(PixelUtil.toPixelFromDIP(height));

}
 
Example #4
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 #5
Source File: DraweeSpanStringBuilder.java    From fresco with MIT License 6 votes vote down vote up
public void setImageSpan(
    DraweeHolder draweeHolder,
    int index,
    final int drawableWidthPx,
    final int drawableHeightPx,
    boolean enableResizing,
    @BetterImageSpan.BetterImageSpanAlignment int verticalAlignment) {
  setImageSpan(
      draweeHolder,
      index,
      index,
      drawableWidthPx,
      drawableHeightPx,
      enableResizing,
      verticalAlignment);
}
 
Example #6
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 #7
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 #8
Source File: DraweeSpanStringBuilder.java    From fresco with MIT License 5 votes vote down vote up
public void setImageSpan(
    DraweeHolder draweeHolder,
    int startIndex,
    int endIndex,
    final int drawableWidthPx,
    final int drawableHeightPx,
    boolean enableResizing,
    @BetterImageSpan.BetterImageSpanAlignment int verticalAlignment) {
  if (endIndex >= length()) {
    // Unfortunately, some callers use this wrong. The original implementation also swallows
    // an exception if this happens (e.g. if you tap on a video that has a minutiae as well.
    // Example: Text = "ABC", insert image at position 18.
    return;
  }
  Drawable topLevelDrawable = draweeHolder.getTopLevelDrawable();
  if (topLevelDrawable != null) {
    if (topLevelDrawable.getBounds().isEmpty()) {
      topLevelDrawable.setBounds(0, 0, drawableWidthPx, drawableHeightPx);
    }
    topLevelDrawable.setCallback(mDrawableCallback);
  }
  DraweeSpan draweeSpan = new DraweeSpan(draweeHolder, verticalAlignment);
  final DraweeController controller = draweeHolder.getController();
  if (controller instanceof AbstractDraweeController) {
    ((AbstractDraweeController) controller)
        .addControllerListener(
            new DrawableChangedListener(draweeSpan, enableResizing, drawableHeightPx));
  }
  mDraweeSpans.add(draweeSpan);
  setSpan(draweeSpan, startIndex, endIndex + 1, SPAN_EXCLUSIVE_EXCLUSIVE);
}
 
Example #9
Source File: DrawableController.java    From WindowImageView with MIT License 5 votes vote down vote up
private void initDraweeHolder() {
    if (mDraweeHolder == null) {
        GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(mContext.getResources())
                .build();
        mDraweeHolder = DraweeHolder.create(hierarchy, mContext);
    }
}
 
Example #10
Source File: DialogView.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
protected void initStyles() {
        GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(getResources())
                .setFadeDuration(0)
                .setRoundingParams(new RoundingParams()
                        .setRoundAsCircle(true))
                .build();
        draweeHolder = DraweeHolder.create(hierarchy, getContext());
        draweeHolder.getTopLevelDrawable().setCallback(this);

        setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Screen.dp(72)));
        setDividerPaddingLeft(Screen.dp(72));

//        setLayerType(LAYER_TYPE_HARDWARE, null);
    }
 
Example #11
Source File: ReactToolbar.java    From native-navigation with MIT License 5 votes vote down vote up
public ReactToolbar(Context context, AttributeSet attributeSet) {
  super(context, attributeSet);
  mLogoHolder = DraweeHolder.create(createDraweeHierarchy(), context);
  mNavIconHolder = DraweeHolder.create(createDraweeHierarchy(), context);
  mOverflowIconHolder = DraweeHolder.create(createDraweeHierarchy(), context);
  init(context);
}
 
Example #12
Source File: ReactToolbar.java    From native-navigation with MIT License 5 votes vote down vote up
public ReactToolbar(Context context) {
  super(context);
  mLogoHolder = DraweeHolder.create(createDraweeHierarchy(), context);
  mNavIconHolder = DraweeHolder.create(createDraweeHierarchy(), context);
  mOverflowIconHolder = DraweeHolder.create(createDraweeHierarchy(), context);
  init(context);
}
 
Example #13
Source File: NetImagePieceView.java    From Fishing with GNU General Public License v3.0 5 votes vote down vote up
@Override
    protected void initView() {
        super.initView();
        GenericDraweeHierarchyBuilder builder =
                new GenericDraweeHierarchyBuilder(getResources());
        GenericDraweeHierarchy hierarchy = builder
//                .setProgressBarImage(getContext().getResources().getDrawable(R.drawable.default_loading))
//                .setFailureImage(getContext().getResources().getDrawable(R.drawable.job_error))
                .build();
        mDraweeHolder = DraweeHolder.create(hierarchy, getContext());
        setWillNotDraw(false);
    }
 
Example #14
Source File: ReactToolbar.java    From react-native-GPay with MIT License 5 votes vote down vote up
public ReactToolbar(Context context) {
  super(context);

  mLogoHolder = DraweeHolder.create(createDraweeHierarchy(), context);
  mNavIconHolder = DraweeHolder.create(createDraweeHierarchy(), context);
  mOverflowIconHolder = DraweeHolder.create(createDraweeHierarchy(), context);

  mLogoControllerListener = new IconControllerListener(mLogoHolder) {
    @Override
    protected void setDrawable(Drawable d) {
      setLogo(d);
    }
  };

  mNavIconControllerListener = new IconControllerListener(mNavIconHolder) {
    @Override
    protected void setDrawable(Drawable d) {
      setNavigationIcon(d);
    }
  };

  mOverflowIconControllerListener = new IconControllerListener(mOverflowIconHolder) {
    @Override
    protected void setDrawable(Drawable d) {
      setOverflowIcon(d);
    }
  };

}
 
Example #15
Source File: ShapedDraweeView.java    From ShapedDraweeView with MIT License 5 votes vote down vote up
private void setup(Context context, AttributeSet attrs, int defStyle) {
    if (getScaleType() == ScaleType.FIT_CENTER) {
        setScaleType(ScaleType.CENTER_CROP);
    }

    Drawable placeholder = null;
    if (attrs != null) {
        TypedArray typedArray =
                context.obtainStyledAttributes(attrs, R.styleable.ShapedDrawee, defStyle, 0);
        int shapeId = typedArray.getResourceId(R.styleable.ShapedDrawee_maskShape, -1);
        // AppCompatResources is added in 24.2.0, for those don't use up to date support
        // library, we could not use this class :(
        // shape = AppCompatResources.getDrawable(getContext(), shapeId);
        setImageResource(shapeId);
        shape = getDrawable();
        if (shape == null) {
            throw new IllegalArgumentException("maskShape must be specified in layout!");
        }
        placeholder = typedArray.getDrawable(R.styleable.ShapedDrawee_placeholder);
        typedArray.recycle();
    }

    GenericDraweeHierarchy hierarchy =
            new GenericDraweeHierarchyBuilder(getResources()).setPlaceholderImage(placeholder)
                    .setPlaceholderImageScaleType(ScalingUtils.ScaleType.CENTER_CROP)
                    .setActualImageScaleType(ScalingUtils.ScaleType.CENTER_CROP)
                    .build();
    mDraweeHolder = DraweeHolder.create(hierarchy, getContext());
}
 
Example #16
Source File: DraweeSpanStringBuilderTest.java    From fresco with MIT License 5 votes vote down vote up
private static void addDraweeSpan(
    DraweeSpanStringBuilder draweeSpanStringBuilder,
    DraweeHolder draweeHolder,
    int index,
    int spanLength) {
  draweeSpanStringBuilder.setImageSpan(
      draweeHolder, /* draweeHolder */
      index, /* startIndex */
      index + spanLength, /* endIndex */
      DRAWABLE_WIDTH, /* drawableWidthPx */
      DRAWABLE_HEIGHT, /* drawableHeightPx */
      false, /* enableResizing */
      BetterImageSpan.ALIGN_CENTER); /* verticalAlignment */
}
 
Example #17
Source File: OverlayMarker.java    From react-native-baidu-map with MIT License 5 votes vote down vote up
protected void init() {
    GenericDraweeHierarchy genericDraweeHierarchy = new GenericDraweeHierarchyBuilder(getResources())
            .setActualImageScaleType(ScalingUtils.ScaleType.FIT_CENTER)
            .setFadeDuration(0)
            .build();
    imageHolder = DraweeHolder.create(genericDraweeHierarchy, getContext());
    imageHolder.onAttach();
}
 
Example #18
Source File: AMapMarker.java    From react-native-amap with MIT License 5 votes vote down vote up
public AMapMarker(Context context) {
    super(context);
    this.context = context;
    LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
    this.view = inflater.inflate(R.layout.layout_bubble, null);
    logoHolder = DraweeHolder.create(createDraweeHierarchy(), context);
    logoHolder.onAttach();
}
 
Example #19
Source File: ReactBottomNavigation.java    From native-navigation with MIT License 5 votes vote down vote up
public void setMenuItemIcon(final MenuItem item, ReadableMap iconSource) {
  DraweeHolder<GenericDraweeHierarchy> holder =
      DraweeHolder.create(createDraweeHierarchy(), getContext());
  ActionIconControllerListener controllerListener = new ActionIconControllerListener(item, holder);
  controllerListener.setIconImageInfo(getIconImageInfo(iconSource));

  setIconSource(iconSource, controllerListener, holder);

  mItemIconHolders.add(holder);
}
 
Example #20
Source File: DraweeSpan.java    From fresco with MIT License 4 votes vote down vote up
public DraweeSpan(
    DraweeHolder draweeHolder, @BetterImageSpan.BetterImageSpanAlignment int verticalAlignment) {
  super(draweeHolder.getTopLevelDrawable(), verticalAlignment);
  mDraweeHolder = draweeHolder;
}
 
Example #21
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);
}
 
Example #22
Source File: ReactBottomNavigation.java    From native-navigation with MIT License 4 votes vote down vote up
ActionIconControllerListener(MenuItem item, DraweeHolder holder) {
  super(holder);
  mItem = item;
}
 
Example #23
Source File: ReactBottomNavigation.java    From native-navigation with MIT License 4 votes vote down vote up
public ReactBottomNavigation(Context context) {
  super(context);
  mBackgroundHolder = DraweeHolder.create(createDraweeHierarchy(), context);
  init(context);
}
 
Example #24
Source File: ReactBottomNavigation.java    From native-navigation with MIT License 4 votes vote down vote up
public ReactBottomNavigation(Context context, AttributeSet attributeSet) {
  super(context, attributeSet);
  mBackgroundHolder = DraweeHolder.create(createDraweeHierarchy(), context);
  init(context);
}
 
Example #25
Source File: ReactBottomNavigation.java    From native-navigation with MIT License 4 votes vote down vote up
public IconControllerListener(DraweeHolder holder) {
  mHolder = holder;
}
 
Example #26
Source File: ReactToolbar.java    From native-navigation with MIT License 4 votes vote down vote up
ActionIconControllerListener(MenuItem item, DraweeHolder holder) {
  super(holder);
  mItem = item;
}
 
Example #27
Source File: ReactToolbar.java    From native-navigation with MIT License 4 votes vote down vote up
public IconControllerListener(DraweeHolder holder) {
  mHolder = holder;
}
 
Example #28
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 #29
Source File: ViewStatesListener.java    From ImageLoader with Apache License 2.0 4 votes vote down vote up
public ViewStatesListener(DraweeHolder holder){
    this.holder=holder;
}
 
Example #30
Source File: DraweeDrawable.java    From litho with Apache License 2.0 4 votes vote down vote up
public DraweeDrawable(Context context, DH draweeHierarchy) {
  super(null);

  setCurrent(mNoOpDrawable);
  mDraweeHolder = DraweeHolder.create(draweeHierarchy, context);
}