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); }
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); }
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 FrescoBasedReactTextInlineImageSpan( Resources resources, int height, int width, @Nullable Uri uri, ReadableMap headers, AbstractDraweeControllerBuilder draweeControllerBuilder, @Nullable Object callerContext) { mDraweeHolder = new DraweeHolder( GenericDraweeHierarchyBuilder.newInstance(resources) .build() ); mDraweeControllerBuilder = draweeControllerBuilder; mCallerContext = callerContext; mHeight = height; mWidth = width; mUri = (uri != null) ? uri : Uri.EMPTY; mHeaders = headers; }
/** * 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)); } }
public FrescoBasedReactTextInlineImageSpan( Resources resources, int height, int width, @Nullable Uri uri, AbstractDraweeControllerBuilder draweeControllerBuilder, @Nullable Object callerContext) { mDraweeHolder = new DraweeHolder( GenericDraweeHierarchyBuilder.newInstance(resources) .build() ); mDraweeControllerBuilder = draweeControllerBuilder; mCallerContext = callerContext; mHeight = height; mWidth = width; mUri = (uri != null) ? uri : Uri.EMPTY; }
/** * 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)); } }
protected void init() { if (null == mAttacher || null == mAttacher.getImageView()) { mAttacher = new PhotoViewAttacher(this); } if (null != mPendingScaleType) { setScaleType(mPendingScaleType); mPendingScaleType = null; } if (mDraweeHolder == null) { GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(getResources()) .setFadeDuration(500) .setProgressBarImage(new CustomProgressbarDrawable(this)) .build(); mDraweeHolder = DraweeHolder.create(hierarchy, getContext()); } }
protected void init() { if (null == mAttacher || null == mAttacher.getImageView()) { mAttacher = new PhotoViewAttacher(this); } if (null != mPendingScaleType) { setScaleType(mPendingScaleType); mPendingScaleType = null; } if (mDraweeHolder == null) { GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(getResources()) .setFadeDuration(300) .setProgressBarImage(new CustomProgressbarDrawable(this)) .build(); mDraweeHolder = DraweeHolder.create(hierarchy, getContext()); } }
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()); }
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); }
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 */ }
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); }
private void init(Context ctx, Drawable defaultDrawable) { if (draweeHolder == null) { Resources resources = ctx.getResources(); GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(resources) .setPlaceholderImage(defaultDrawable) .setFailureImage(defaultDrawable) .build(); draweeHolder = DraweeHolder.create(hierarchy, ctx); } }
private void initDraweeHolder() { if (mDraweeHolder == null) { GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(mContext.getResources()) .build(); mDraweeHolder = DraweeHolder.create(hierarchy, mContext); } }
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); } }; }
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); }
public ReactToolbar(Context context) { super(context); mLogoHolder = DraweeHolder.create(createDraweeHierarchy(), context); mNavIconHolder = DraweeHolder.create(createDraweeHierarchy(), context); mOverflowIconHolder = DraweeHolder.create(createDraweeHierarchy(), context); init(context); }
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); }
@Override public void displayImage(Activity activity, String path, GFImageView imageView, 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; } }); Uri uri = new Uri.Builder() .scheme(UriUtil.LOCAL_FILE_SCHEME) .path(path) .build(); displayImage(uri, new ResizeOptions(width, height), imageView, draweeHolder); }
/** * 加载远程图片 * * @param url * @param imageSize */ private void displayImage(Uri url, ResizeOptions imageSize, final ImageView imageView, final DraweeHolder<GenericDraweeHierarchy> draweeHolder) { ImageRequest imageRequest = ImageRequestBuilder .newBuilderWithSource(url) .setResizeOptions(imageSize)//图片目标大小 .build(); ImagePipeline imagePipeline = Fresco.getImagePipeline(); final DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, this); DraweeController controller = Fresco.newDraweeControllerBuilder() .setOldController(draweeHolder.getController()) .setImageRequest(imageRequest) .setControllerListener(new BaseControllerListener<ImageInfo>() { @Override public void onFinalImageSet(String s, ImageInfo imageInfo, Animatable animatable) { CloseableReference<CloseableImage> imageReference = null; try { imageReference = dataSource.getResult(); if (imageReference != null) { CloseableImage image = imageReference.get(); if (image != null && image instanceof CloseableStaticBitmap) { CloseableStaticBitmap closeableStaticBitmap = (CloseableStaticBitmap) image; Bitmap bitmap = closeableStaticBitmap.getUnderlyingBitmap(); if (bitmap != null && imageView != null) { imageView.setImageBitmap(bitmap); } } } } finally { dataSource.close(); CloseableReference.closeSafely(imageReference); } } }) .setTapToRetryEnabled(true) .build(); draweeHolder.setController(controller); }
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(); }
private void selfInit() { if (mDraweeHolder == null) { final GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(getResources()) .build(); mDraweeHolder = DraweeHolder.create(hierarchy, getContext()); } }