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

The following examples show how to use com.facebook.drawee.view.DraweeHolder#create() . 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: 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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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 13
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 14
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 15
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 16
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 17
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);
}
 
Example 18
Source File: ReactToolbar.java    From native-navigation with MIT License 3 votes vote down vote up
private 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);

    mActionsHolder.add(holder);

  }
 
Example 19
Source File: ReactToolbar.java    From react-native-GPay with MIT License 3 votes vote down vote up
private 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);

    mActionsHolder.add(holder);

  }