@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { SimpleDraweeView simpleDraweeView = (SimpleDraweeView) view.findViewById(R.id.drawee_view); ImageDecodeOptions imageDecodeOptionsWithCustomDecoder = new ImageDecodeOptionsBuilder() .setCustomImageDecoder(CUSTOM_COLOR_DECODER) .build(); AbstractDraweeController controller = Fresco.newDraweeControllerBuilder() .setImageRequest( ImageRequestBuilder.newBuilderWithResourceId(R.raw.custom_color1) .setImageDecodeOptions(imageDecodeOptionsWithCustomDecoder) .build()) .build(); simpleDraweeView.setController(controller); }
/** * Stubs addControllerListener * @param controller * @return forwarding listener */ public static ControllerListener stubControllerListener( final DraweeController controller) { final ForwardingControllerListener forwardingListener = new ForwardingControllerListener(); if (!(controller instanceof AbstractDraweeController)) { return null; } AbstractDraweeController abstractController = (AbstractDraweeController) controller; doAnswer( new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { forwardingListener.addListener((ControllerListener) invocation.getArguments()[0]); return null; } }).when(abstractController).addControllerListener(any(ControllerListener.class)); return forwardingListener; }
@Override protected void onDraw(Canvas canvas) { int saveCount = canvas.save(); canvas.concat(mZoomableController.getTransform()); try { super.onDraw(canvas); } catch (Exception e) { DraweeController controller = getController(); if (controller != null && controller instanceof AbstractDraweeController) { Object callerContext = ((AbstractDraweeController) controller).getCallerContext(); if (callerContext != null) { throw new RuntimeException( String.format("Exception in onDraw, callerContext=%s", callerContext.toString()), e); } } throw e; } canvas.restoreToCount(saveCount); }
public void displayImage(String imageUri, ImageView imageView, ImageLoadingListener listener) { if (TextUtils.isEmpty(imageUri)) return; if (imageView instanceof GenericDraweeView) { if (listener != null) { PipelineDraweeControllerBuilder builder = Fresco.newDraweeControllerBuilder(); ImageLoaderListener listener1 = new ImageLoaderListener(); listener1.setData(listener, imageUri, imageView); ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(imageUri)).build(); AbstractDraweeController controller = builder.setOldController(((GenericDraweeView) imageView).getController()).setControllerListener(listener1).setImageRequest(request).build(); ((GenericDraweeView) imageView).setController(controller); return; } } imageView.setImageURI(Uri.parse(imageUri)); }
/** * Creates a mock DraweeController with some methods stubbed. * @return mock DraweeController */ public static DraweeController mockController() { DraweeController controller = mock(AbstractDraweeController.class); stubGetAndSetHierarchy(controller); stubGetAndSetContentDescription(controller); return controller; }
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 void prepareFrontground(String frontWebpName) { if (!TextUtils.isEmpty(frontWebpName)) { File backWebp = new File("/sdcard/sololive/effect/ship3", frontWebpName); ImageRequest localImageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.fromFile(backWebp)).build(); AbstractDraweeController localAbstractDraweeController = Fresco.newDraweeControllerBuilder().setOldController(mFrontAnimView.getController()).setImageRequest(localImageRequest).setAutoPlayAnimations(true).build(); mFrontAnimView.setController(localAbstractDraweeController); } }
public static boolean prepareBg(SimpleDraweeView bgImage, String bgFileName) { if (!TextUtils.isEmpty(bgFileName)) { File bgFile = new File("/sdcard/sololive/effect/ship3", bgFileName); Log.e(TAG, "bgFile=" + bgFile.getAbsolutePath()); if (bgFile.exists()) { if (FileUtils.isWebpFile(bgFileName)) { Log.e(TAG, "isWebp File"); ImageRequest localImageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.fromFile(bgFile)).build(); Log.e(TAG, "simpledrawee=" + bgImage.hashCode()); ControllerListener controllerListener = new BaseControllerListener<ImageInfo>() { @Override public void onFinalImageSet( String id, @Nullable ImageInfo imageInfo, @Nullable Animatable anim) { Log.e(TAG, "onFinalImageSet"); if (anim != null) { // app-specific logic to enable animation starting anim.start(); } } }; AbstractDraweeController localAbstractDraweeController = Fresco .newDraweeControllerBuilder() .setOldController(bgImage.getController()) .setControllerListener(controllerListener) .setImageRequest(localImageRequest) .build(); bgImage.setController(localAbstractDraweeController); return true; } else { Uri uri = Uri.fromFile(bgFile); bgImage.setImageURI(uri); } } } return false; }
public static void loadWithSize(ShapedDraweeView draweeView, Uri uri, int width, int height) { ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri) .setResizeOptions(new ResizeOptions(width, height)) .setProgressiveRenderingEnabled(true) .setAutoRotateEnabled(true) .build(); AbstractDraweeController controller = Fresco.newDraweeControllerBuilder() .setImageRequest(request) .setAutoPlayAnimations(true) .build(); draweeView.setController(controller); }
@Override protected void onResume() { super.onResume(); final AbstractDraweeController controller = Fresco.newDraweeControllerBuilder() .setUri(Uri.parse("https://assets-cdn.github.com/images/modules/open_graph/github-octocat.png")) .setOldController(imageView.getController()) .build(); imageView.setController(controller); }
private void removeControllerListener(DraweeController controller) { if (controller instanceof AbstractDraweeController) { ((AbstractDraweeController) controller) .removeControllerListener(mControllerListener); } }
private void addControllerListener(DraweeController controller) { if (controller instanceof AbstractDraweeController) { ((AbstractDraweeController) controller) .addControllerListener(mControllerListener); } }
public void setImageUri(String uri, ResizeOptions options) { final ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(uri)) .setResizeOptions(options) .setAutoRotateEnabled(true) .build(); final ImagePipeline imagePipeline = Fresco.getImagePipeline(); final DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, this); final AbstractDraweeController controller = Fresco.newDraweeControllerBuilder() .setOldController(mDraweeHolder.getController()) .setImageRequest(imageRequest) .setControllerListener(new BaseControllerListener<ImageInfo>() { @Override public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) { super.onFinalImageSet(id, imageInfo, animatable); CloseableReference<CloseableImage> imageCloseableReference = null; try { imageCloseableReference = dataSource.getResult(); if (imageCloseableReference != null) { final CloseableImage image = imageCloseableReference.get(); if (image != null && image instanceof CloseableStaticBitmap) { CloseableStaticBitmap closeableStaticBitmap = (CloseableStaticBitmap) image; final Bitmap bitmap = closeableStaticBitmap.getUnderlyingBitmap(); if (bitmap != null) { setImageBitmap(bitmap); // 如果是长图,让其宽度放大至与屏幕等宽 setScaleType(ScaleType.CENTER_CROP); } } } } finally { dataSource.close(); CloseableReference.closeSafely(imageCloseableReference); } } }) .build(); mDraweeHolder.setController(controller); setImageDrawable(mDraweeHolder.getTopLevelDrawable()); }
public void setImageUri(String uri) { final ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(uri)).setResizeOptions(null).setAutoRotateEnabled(true).build(); final ImagePipeline imagePipeline = Fresco.getImagePipeline(); final DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, this); final AbstractDraweeController controller = Fresco.newDraweeControllerBuilder() .setOldController(mDraweeHolder.getController()) .setAutoPlayAnimations(true) .setImageRequest(imageRequest) .setControllerListener(new BaseControllerListener<ImageInfo>() { @Override public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) { super.onFinalImageSet(id, imageInfo, animatable); // set flag if this is an animated image if (animatable != null) { isAnimation = true; } CloseableReference<CloseableImage> imageCloseableReference = null; try { imageCloseableReference = dataSource.getResult(); if (imageCloseableReference != null) { final CloseableImage image = imageCloseableReference.get(); if (image != null && image instanceof CloseableStaticBitmap) { CloseableStaticBitmap closeableStaticBitmap = (CloseableStaticBitmap) image; final Bitmap bitmap = closeableStaticBitmap.getUnderlyingBitmap(); if (bitmap != null) { setImageBitmap(bitmap); } } } } finally { dataSource.close(); CloseableReference.closeSafely(imageCloseableReference); } } }) .build(); mDraweeHolder.setController(controller); setImageDrawable(mDraweeHolder.getTopLevelDrawable()); }
private void prepareBackground(String backWebpName) { if (!TextUtils.isEmpty("kiss3")) { File backWebp = new File("/sdcard/sololive/effect/kiss3", "kiss.webp"); ImageRequest localImageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.fromFile(backWebp)).build(); ControllerListener controllerListener = new BaseControllerListener<ImageInfo>() { @Override public void onFinalImageSet( String id, @Nullable ImageInfo imageInfo, @Nullable Animatable anim) { Log.e(TAG, "onFinalImageSet"); if (anim != null) { // app-specific logic to enable animation starting anim.start(); } } }; AbstractDraweeController localAbstractDraweeController = Fresco .newDraweeControllerBuilder() .setOldController(mBackAnimView.getController()) .setImageRequest(localImageRequest) .setControllerListener(controllerListener) // .setAutoPlayAnimations(true) .build(); mBackAnimView.setController(localAbstractDraweeController); postDelayed(new Runnable() { @Override public void run() { Animatable animation = mBackAnimView.getController().getAnimatable(); if (animation != null) { // 开始播放 animation.start(); // 一段时间之后,根据业务逻辑,停止播放 // animation.stop(); } } },12000); } }