/** * 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; }
public void maybeUpdateView() { if (!mIsDirty) { return; } boolean doResize = shouldResize(mUri); if (doResize && (getWidth() <= 0 || getHeight() <=0)) { // If need a resize and the size is not yet set, wait until the layout pass provides one return; } GenericDraweeHierarchy hierarchy = getHierarchy(); hierarchy.setActualImageScaleType(mScaleType); if (mLoadingImageDrawable != null) { hierarchy.setPlaceholderImage(mLoadingImageDrawable, ScalingUtils.ScaleType.CENTER); } boolean usePostprocessorScaling = mScaleType != ScalingUtils.ScaleType.CENTER_CROP && mScaleType != ScalingUtils.ScaleType.FOCUS_CROP; float hierarchyRadius = usePostprocessorScaling ? 0 : mBorderRadius; RoundingParams roundingParams = hierarchy.getRoundingParams(); roundingParams.setCornersRadius(hierarchyRadius); roundingParams.setBorder(mBorderColor, mBorderWidth); if (mOverlayColor != Color.TRANSPARENT) { roundingParams.setOverlayColor(mOverlayColor); } else { // make sure the default rounding method is used. roundingParams.setRoundingMethod(RoundingParams.RoundingMethod.BITMAP_ONLY); } hierarchy.setRoundingParams(roundingParams); hierarchy.setFadeDuration( mFadeDurationMs >= 0 ? mFadeDurationMs : mIsLocalImage ? 0 : REMOTE_IMAGE_FADE_DURATION_MS); Postprocessor postprocessor = usePostprocessorScaling ? mRoundedCornerPostprocessor : null; ResizeOptions resizeOptions = doResize ? new ResizeOptions(getWidth(), getHeight()) : null; ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(mUri) .setPostprocessor(postprocessor) .setResizeOptions(resizeOptions) .setAutoRotateEnabled(true) .setProgressiveRenderingEnabled(mProgressiveRenderingEnabled) .build(); // This builder is reused mDraweeControllerBuilder.reset(); mDraweeControllerBuilder .setAutoPlayAnimations(true) .setCallerContext(mCallerContext) .setOldController(getController()) .setImageRequest(imageRequest); if (mControllerListener != null && mControllerForTesting != null) { ForwardingControllerListener combinedListener = new ForwardingControllerListener(); combinedListener.addListener(mControllerListener); combinedListener.addListener(mControllerForTesting); mDraweeControllerBuilder.setControllerListener(combinedListener); } else if (mControllerForTesting != null) { mDraweeControllerBuilder.setControllerListener(mControllerForTesting); } else if (mControllerListener != null) { mDraweeControllerBuilder.setControllerListener(mControllerListener); } setController(mDraweeControllerBuilder.build()); mIsDirty = false; }
public void maybeUpdateView() { if (!mIsDirty) { return; } boolean doResize = shouldResize(mUri); if (doResize && (getWidth() <= 0 || getHeight() <=0)) { // If need a resize and the size is not yet set, wait until the layout pass provides one return; } GenericDraweeHierarchy hierarchy = getHierarchy(); hierarchy.setActualImageScaleType(mScaleType); if (mLoadingImageDrawable != null) { hierarchy.setPlaceholderImage(mLoadingImageDrawable, ScalingUtils.ScaleType.CENTER); } boolean usePostprocessorScaling = mScaleType != ScalingUtils.ScaleType.CENTER_CROP && mScaleType != ScalingUtils.ScaleType.FOCUS_CROP; RoundingParams roundingParams = hierarchy.getRoundingParams(); if (usePostprocessorScaling) { roundingParams.setCornersRadius(0); } else { cornerRadii(sComputedCornerRadii); roundingParams.setCornersRadii(sComputedCornerRadii[0], sComputedCornerRadii[1], sComputedCornerRadii[2], sComputedCornerRadii[3]); } roundingParams.setBorder(mBorderColor, mBorderWidth); if (mOverlayColor != Color.TRANSPARENT) { roundingParams.setOverlayColor(mOverlayColor); } else { // make sure the default rounding method is used. roundingParams.setRoundingMethod(RoundingParams.RoundingMethod.BITMAP_ONLY); } hierarchy.setRoundingParams(roundingParams); hierarchy.setFadeDuration( mFadeDurationMs >= 0 ? mFadeDurationMs : mIsLocalImage ? 0 : REMOTE_IMAGE_FADE_DURATION_MS); Postprocessor postprocessor = usePostprocessorScaling ? mRoundedCornerPostprocessor : null; ResizeOptions resizeOptions = doResize ? new ResizeOptions(getWidth(), getHeight()) : null; ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(mUri) .setPostprocessor(postprocessor) .setResizeOptions(resizeOptions) .setAutoRotateEnabled(true) .setProgressiveRenderingEnabled(mProgressiveRenderingEnabled) .build(); // This builder is reused mDraweeControllerBuilder.reset(); mDraweeControllerBuilder .setAutoPlayAnimations(true) .setCallerContext(mCallerContext) .setOldController(getController()) .setImageRequest(imageRequest); if (mControllerListener != null && mControllerForTesting != null) { ForwardingControllerListener combinedListener = new ForwardingControllerListener(); combinedListener.addListener(mControllerListener); combinedListener.addListener(mControllerForTesting); mDraweeControllerBuilder.setControllerListener(combinedListener); } else if (mControllerForTesting != null) { mDraweeControllerBuilder.setControllerListener(mControllerForTesting); } else if (mControllerListener != null) { mDraweeControllerBuilder.setControllerListener(mControllerListener); } setController(mDraweeControllerBuilder.build()); mIsDirty = false; }
public void maybeUpdateView() { if (!mIsDirty) { return; } boolean doResize = shouldResize(mUri); if (doResize && (getWidth() <= 0 || getHeight() <=0)) { // If need a resize and the size is not yet set, wait until the layout pass provides one return; } GenericDraweeHierarchy hierarchy = getHierarchy(); hierarchy.setActualImageScaleType(mScaleType); if (mLoadingImageDrawable != null) { // hierarchy.setPlaceholderImage(mLoadingImageDrawable, ScalingUtils.ScaleType.CENTER); } boolean usePostprocessorScaling = mScaleType != ScalingUtils.ScaleType.CENTER_CROP && mScaleType != ScalingUtils.ScaleType.FOCUS_CROP; float hierarchyRadius = usePostprocessorScaling ? 0 : mBorderRadius; RoundingParams roundingParams = hierarchy.getRoundingParams(); roundingParams.setCornersRadius(hierarchyRadius); roundingParams.setBorder(mBorderColor, mBorderWidth); hierarchy.setRoundingParams(roundingParams); hierarchy.setFadeDuration( mFadeDurationMs >= 0 ? mFadeDurationMs : mIsLocalImage ? 0 : REMOTE_IMAGE_FADE_DURATION_MS); Postprocessor postprocessor = usePostprocessorScaling ? mRoundedCornerPostprocessor : null; Postprocessor redMeshPostprocessor = new redMeshPostprocessor(); ResizeOptions resizeOptions = doResize ? new ResizeOptions(getWidth(), getHeight()) : null; ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(mUri) .setPostprocessor(redMeshPostprocessor) .setResizeOptions(resizeOptions) .setAutoRotateEnabled(true) .setProgressiveRenderingEnabled(mProgressiveRenderingEnabled) .build(); // This builder is reused mDraweeControllerBuilder.reset(); mDraweeControllerBuilder .setAutoPlayAnimations(true) .setCallerContext(mCallerContext) .setOldController(getController()) .setImageRequest(imageRequest); if (mControllerListener != null && mControllerForTesting != null) { ForwardingControllerListener combinedListener = new ForwardingControllerListener(); combinedListener.addListener(mControllerListener); combinedListener.addListener(mControllerForTesting); mDraweeControllerBuilder.setControllerListener(combinedListener); } else if (mControllerForTesting != null) { mDraweeControllerBuilder.setControllerListener(mControllerForTesting); } else if (mControllerListener != null) { mDraweeControllerBuilder.setControllerListener(mControllerListener); } setController(mDraweeControllerBuilder.build()); mIsDirty = false; }
public void maybeUpdateView() { if (!mIsDirty) { return; } boolean doResize = shouldResize(mUri); if (doResize && (getWidth() <= 0 || getHeight() <= 0)) { // If need a resize and the size is not yet set, wait until the layout pass provides one return; } GenericDraweeHierarchy hierarchy = getHierarchy(); hierarchy.setActualImageScaleType(mScaleType); if (mLoadingImageDrawable != null) { hierarchy.setPlaceholderImage(mLoadingImageDrawable, ScalingUtils.ScaleType.CENTER); } boolean usePostprocessorScaling = mScaleType != ScalingUtils.ScaleType.CENTER_CROP && mScaleType != ScalingUtils.ScaleType.FOCUS_CROP; float hierarchyRadius = usePostprocessorScaling ? 0 : mBorderRadius; RoundingParams roundingParams = hierarchy.getRoundingParams(); roundingParams.setCornersRadius(hierarchyRadius); roundingParams.setBorder(mBorderColor, mBorderWidth); if (mOverlayColor != Color.TRANSPARENT) { roundingParams.setOverlayColor(mOverlayColor); } else { // make sure the default rounding method is used. roundingParams.setRoundingMethod(RoundingParams.RoundingMethod.BITMAP_ONLY); } hierarchy.setRoundingParams(roundingParams); hierarchy.setFadeDuration( mFadeDurationMs >= 0 ? mFadeDurationMs : mIsLocalImage ? 0 : REMOTE_IMAGE_FADE_DURATION_MS); Postprocessor postprocessor = usePostprocessorScaling ? mRoundedCornerPostprocessor : null; ResizeOptions resizeOptions = doResize ? new ResizeOptions(getWidth(), getHeight()) : null; ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(mUri) .setPostprocessor(postprocessor) .setResizeOptions(resizeOptions) .setAutoRotateEnabled(true) .setProgressiveRenderingEnabled(mProgressiveRenderingEnabled) .build(); // This builder is reused mDraweeControllerBuilder.reset(); mDraweeControllerBuilder .setAutoPlayAnimations(true) .setCallerContext(mCallerContext) .setOldController(getController()) .setImageRequest(imageRequest); if (mControllerListener != null && mControllerForTesting != null) { ForwardingControllerListener combinedListener = new ForwardingControllerListener(); combinedListener.addListener(mControllerListener); combinedListener.addListener(mControllerForTesting); mDraweeControllerBuilder.setControllerListener(combinedListener); } else if (mControllerForTesting != null) { mDraweeControllerBuilder.setControllerListener(mControllerForTesting); } else if (mControllerListener != null) { mDraweeControllerBuilder.setControllerListener(mControllerListener); } setController(mDraweeControllerBuilder.build()); mIsDirty = false; }