Java 类com.facebook.imagepipeline.common.ResizeOptions 实例源码

项目:GitHub    文件:BitmapMemoryCacheKey.java   
public BitmapMemoryCacheKey(
    String sourceString,
    @Nullable ResizeOptions resizeOptions,
    RotationOptions rotationOptions,
    ImageDecodeOptions imageDecodeOptions,
    @Nullable CacheKey postprocessorCacheKey,
    @Nullable String postprocessorName,
    Object callerContext) {
  mSourceString = Preconditions.checkNotNull(sourceString);
  mResizeOptions = resizeOptions;
  mRotationOptions = rotationOptions;
  mImageDecodeOptions = imageDecodeOptions;
  mPostprocessorCacheKey = postprocessorCacheKey;
  mPostprocessorName = postprocessorName;
  mHash = HashCodeUtil.hashCode(
      sourceString.hashCode(),
      (resizeOptions != null) ? resizeOptions.hashCode() : 0,
      rotationOptions.hashCode(),
      mImageDecodeOptions,
      mPostprocessorCacheKey,
      postprocessorName);
  mCallerContext = callerContext;
  mCacheTime = RealtimeSinceBootClock.get().now();
}
项目:GitHub    文件:ResizeAndRotateProducer.java   
@VisibleForTesting static float determineResizeRatio(
    ResizeOptions resizeOptions,
    int width,
    int height) {

  if (resizeOptions == null) {
    return 1.0f;
  }

  final float widthRatio = ((float) resizeOptions.width) / width;
  final float heightRatio = ((float) resizeOptions.height) / height;
  float ratio = Math.max(widthRatio, heightRatio);

  if (width * ratio > resizeOptions.maxBitmapSize) {
    ratio = resizeOptions.maxBitmapSize / width;
  }
  if (height * ratio > resizeOptions.maxBitmapSize) {
    ratio = resizeOptions.maxBitmapSize / height;
  }
  return ratio;
}
项目:GitHub    文件:ImageRequestTest.java   
@Test
public void testCreatingRequestFromExistingRequest() {
  ImageRequest original = ImageRequestBuilder
      .newBuilderWithSource(Uri.parse("http://frescolib.org/image.jpg"))
          .setCacheChoice(ImageRequest.CacheChoice.SMALL)
      .setImageDecodeOptions(new ImageDecodeOptionsBuilder().build())
      .setLocalThumbnailPreviewsEnabled(true)
      .setLowestPermittedRequestLevel(ImageRequest.RequestLevel.DISK_CACHE)
      .setMediaVariations(MediaVariations.forMediaId("A113"))
      .setPostprocessor(new BasePostprocessor() {
        @Override
        public String getName() {
          return super.getName();
        }
      })
      .setProgressiveRenderingEnabled(true)
      .setRequestListener(new RequestLoggingListener())
      .setResizeOptions(new ResizeOptions(20, 20))
      .setRotationOptions(RotationOptions.forceRotation(RotationOptions.ROTATE_90))
      .setRequestPriority(Priority.HIGH)
      .build();

  ImageRequest copy = ImageRequestBuilder.fromRequest(original).build();

  assertThat(copy).isEqualTo(original);
}
项目:GitHub    文件:ThumbnailSizeCheckerTest.java   
private static void testWithImageNotBigEnoughForResizeOptions(
    int[] imageWidths,
    int[] imageHeights,
    int startRotation,
    int additionalRequestWidth,
    int additionalRequestHeight) {
  for (int rotation = startRotation; rotation < 360; rotation += 180) {
    for (int i = 0; i < TEST_COUNT; i++) {
      ResizeOptions resizeOptions = new ResizeOptions(
          REQUEST_WIDTHS[i] + additionalRequestWidth,
          REQUEST_HEIGHTS[i] + additionalRequestHeight);
      EncodedImage encodedImage = mockImage(imageWidths[i], imageHeights[i], rotation);
      assertFalse(ThumbnailSizeChecker.isImageBigEnough(encodedImage, resizeOptions));
    }
  }
}
项目:GitHub    文件:DecodeProducerTest.java   
@Test
public void testDecode_WhenSmartResizingEnabledAndLocalUri_ThenPerformDownsampling()
    throws Exception {
  int resizedWidth = 10;
  int resizedHeight = 10;
  when(mExperimentalResizingEnabledSupplier.get()).thenReturn(true);
  setupLocalUri(ResizeOptions.forDimensions(resizedWidth, resizedHeight));

  produceResults();
  JobScheduler.JobRunnable jobRunnable = getJobRunnable();

  jobRunnable.run(mEncodedImage, Consumer.IS_LAST);

  // The sample size was modified, which means Downsampling has been performed
  assertNotEquals(mEncodedImage.getSampleSize(), EncodedImage.DEFAULT_SAMPLE_SIZE);
}
项目:GitHub    文件:DecodeProducerTest.java   
@Test
public void testDecode_WhenSmartResizingEnabledAndNetworkUri_ThenPerformNoDownsampling()
    throws Exception {
  int resizedWidth = 10;
  int resizedHeight = 10;
  when(mExperimentalResizingEnabledSupplier.get()).thenReturn(true);
  setupNetworkUri(ResizeOptions.forDimensions(resizedWidth, resizedHeight));

  produceResults();
  JobScheduler.JobRunnable jobRunnable = getJobRunnable();

  jobRunnable.run(mEncodedImage, Consumer.IS_LAST);

  // The sample size was not modified, which means Downsampling has not been performed
  assertEquals(mEncodedImage.getSampleSize(), EncodedImage.DEFAULT_SAMPLE_SIZE);
}
项目:GitHub    文件:MediaVariationsFallbackProducerTest.java   
@Test
public void testSendsSmallestLargerFinalImageToConsumerWhenLargerVariantsFromIndexFound() {
  when(mImageRequest.getMediaVariations()).thenReturn(mMediaVariationsWithVariants);
  whenCacheContains(mDefaultBufferedDiskCache, CACHE_KEY_S, CACHE_KEY_M, CACHE_KEY_L);
  whenIndexDbContains(URI_M, SIZE_M, CacheChoice.DEFAULT);
  when(mImageRequest.getResizeOptions()).thenReturn(new ResizeOptions(SIZE_M - 10, SIZE_M - 10));

  mMediaVariationsFallbackProducer.produceResults(mConsumer, mProducerContext);

  verify(mConsumer).onNewResult(mImageM, Consumer.IS_LAST | Consumer.DO_NOT_CACHE_ENCODED);
  verify(mConsumer).onProgressUpdate(1L);
  verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME);
  verifySuccessSentToListener(
      FOUND,
      USED_AS_LAST,
      MediaVariations.SOURCE_IMAGE_REQUEST,
      VARIANTS_COUNT);
  verifyZeroInteractions(mInputProducer, mSmallImageBufferedDiskCache);
}
项目:GitHub    文件:MediaVariationsFallbackProducerTest.java   
@Test
public void testSendsLargestCachedNonFinalImageToConsumerAndStartsInputProducerIfNoCachedVariantFromRequestBigEnough() {
  when(mImageRequest.getMediaVariations()).thenReturn(mMediaVariationsWithVariants);
  whenCacheContains(mDefaultBufferedDiskCache, CACHE_KEY_S, CACHE_KEY_M, CACHE_KEY_L);
  when(mImageRequest.getResizeOptions()).thenReturn(new ResizeOptions(SIZE_L + 80, SIZE_L + 80));

  mMediaVariationsFallbackProducer.produceResults(mConsumer, mProducerContext);

  verify(mConsumer).onNewResult(mImageL, Consumer.DO_NOT_CACHE_ENCODED | Consumer.IS_PLACEHOLDER);
  verify(mConsumer, never()).onProgressUpdate(anyFloat());
  verifyInputProducerProduceResultsWithNewConsumer(false);
  verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME);
  verifySuccessSentToListener(
      FOUND,
      NOT_USED_AS_LAST,
      MediaVariations.SOURCE_IMAGE_REQUEST,
      VARIANTS_COUNT);
  verifyZeroInteractions(mSmallImageBufferedDiskCache);
}
项目:GitHub    文件:MediaVariationsFallbackProducerTest.java   
@Test
public void testSendsSmallestLargerFinalImageToConsumerWhenLargerVariantsFromRequestFound() {
  when(mImageRequest.getMediaVariations()).thenReturn(mMediaVariationsWithVariants);
  whenCacheContains(mDefaultBufferedDiskCache, CACHE_KEY_S, CACHE_KEY_M, CACHE_KEY_L);
  when(mImageRequest.getResizeOptions()).thenReturn(new ResizeOptions(SIZE_M - 10, SIZE_M - 10));

  mMediaVariationsFallbackProducer.produceResults(mConsumer, mProducerContext);

  verify(mConsumer).onNewResult(mImageM, Consumer.IS_LAST | Consumer.DO_NOT_CACHE_ENCODED);
  verify(mConsumer).onProgressUpdate(1L);
  verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME);
  verifySuccessSentToListener(
      FOUND,
      USED_AS_LAST,
      MediaVariations.SOURCE_IMAGE_REQUEST,
      VARIANTS_COUNT);
  verifyZeroInteractions(mInputProducer, mSmallImageBufferedDiskCache);
}
项目:GitHub    文件:MediaVariationsFallbackProducerTest.java   
@Test
public void testSendsNonFinalImageToConsumerAndStartsInputProducerIfRequestForcesRequestForSpecifiedUri() {
  MediaVariations mediaVariations = MediaVariations.newBuilderForMediaId(MEDIA_ID)
      .setForceRequestForSpecifiedUri(true)
      .build();
  when(mImageRequest.getMediaVariations()).thenReturn(mediaVariations);
  whenCacheContains(mDefaultBufferedDiskCache, CACHE_KEY_S, CACHE_KEY_M, CACHE_KEY_L);
  whenIndexDbContains(URI_M, SIZE_M, CacheChoice.DEFAULT);

  when(mImageRequest.getResizeOptions()).thenReturn(new ResizeOptions(SIZE_M - 10, SIZE_M - 10));

  mMediaVariationsFallbackProducer.produceResults(mConsumer, mProducerContext);

  verify(mConsumer).onNewResult(mImageM, Consumer.DO_NOT_CACHE_ENCODED | Consumer.IS_PLACEHOLDER);
  verify(mConsumer, never()).onProgressUpdate(anyFloat());
  verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME);
  verifySuccessSentToListener(FOUND, NOT_USED_AS_LAST, MediaVariations.SOURCE_INDEX_DB, 1);
  verifyInputProducerProduceResultsWithNewConsumer(false);
  verifyZeroInteractions(mSmallImageBufferedDiskCache);
}
项目:GitHub    文件:MediaVariationsFallbackProducerTest.java   
@Test
public void testUsesSmallCacheIfRequestedByImageRequest() {
  when(mImageRequest.getMediaVariations()).thenReturn(mMediaVariationsWithVariants);
  whenCacheContains(mSmallImageBufferedDiskCache, CACHE_KEY_S, CACHE_KEY_M, CACHE_KEY_L);
  when(mImageRequest.getResizeOptions()).thenReturn(new ResizeOptions(SIZE_S, SIZE_S));
  when(mImageRequest.getCacheChoice()).thenReturn(CacheChoice.SMALL);

  mMediaVariationsFallbackProducer.produceResults(mConsumer, mProducerContext);

  verify(mConsumer).onNewResult(mImageS, Consumer.IS_LAST | Consumer.DO_NOT_CACHE_ENCODED);
  verify(mConsumer).onProgressUpdate(1L);
  verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME);
  verifySuccessSentToListener(
      FOUND,
      USED_AS_LAST,
      MediaVariations.SOURCE_IMAGE_REQUEST,
      VARIANTS_COUNT);
  verifyZeroInteractions(mInputProducer, mDefaultBufferedDiskCache);
}
项目:GitHub    文件:ResizeAndRotateProducerTest.java   
@Test
public void testResizeRatio() {
  ResizeOptions resizeOptions = new ResizeOptions(512, 512);
  assertEquals(
      0.5f,
      ResizeAndRotateProducer.determineResizeRatio(resizeOptions, 1024, 1024),
      0.01);
  assertEquals(
      0.25f,
      ResizeAndRotateProducer.determineResizeRatio(resizeOptions, 2048, 4096),
      0.01);
  assertEquals(
      0.5f,
      ResizeAndRotateProducer.determineResizeRatio(resizeOptions, 4096, 512),
      0.01);
}
项目:GitHub    文件:FrescoHolder.java   
@Override
protected void onBind(String uriString) {
  Uri uri = Uri.parse(uriString);
  ImageRequestBuilder imageRequestBuilder =
      ImageRequestBuilder.newBuilderWithSource(uri);
  if (UriUtil.isNetworkUri(uri)) {
    imageRequestBuilder.setProgressiveRenderingEnabled(true);
  } else {
    imageRequestBuilder.setResizeOptions(new ResizeOptions(
        mImageView.getLayoutParams().width,
        mImageView.getLayoutParams().height));
  }
  DraweeController draweeController = Fresco.newDraweeControllerBuilder()
      .setImageRequest(imageRequestBuilder.build())
      .setOldController(mImageView.getController())
      .setControllerListener(mImageView.getListener())
      .setAutoPlayAnimations(true)
      .build();
  mImageView.setController(draweeController);
}
项目:GitHub    文件:MediaVariationsFragment.java   
private void loadThumb(
    SimpleDraweeView draweeView,
    Size size,
    ImageRequest.RequestLevel requestLevel) {
  ImageRequest request = ImageRequestBuilder.newBuilderWithSource(size.uri)
      .setMediaVariations(MediaVariations.newBuilderForMediaId(MEDIA_ID)
          .setForceRequestForSpecifiedUri(true)
          .build())
      .setLowestPermittedRequestLevel(requestLevel)
      .setResizeOptions(new ResizeOptions(draweeView.getWidth(), draweeView.getHeight()))
      .setCacheChoice(size.cacheChoice)
      .build();
  DraweeController controller = Fresco.newDraweeControllerBuilder()
      .setImageRequest(request)
      .setOldController(draweeView.getController())
      .build();
  draweeView.setController(controller);
}
项目:GitHub    文件:MediaVariationsFragment.java   
private void loadMainImage() {
  // Request a non-existent image to force fallback to the variations
  Uri uri = Uri.parse(String.format(URI_TEMPLATE, "full", "jpg"));
  ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri)
      .setMediaVariations(getMediaVariationsForMode(mMode))
      .setResizeOptions(new ResizeOptions(
          mMainImageDraweeView.getWidth(),
          mMainImageDraweeView.getHeight()))
      .build();

  Log.i(
      TAG,
      request.getMediaVariations() == null ? "null" : request.getMediaVariations().toString());

  setDraweeControllerForRequest(request);
}
项目:GitHub    文件:DraweeViewHolder.java   
/**
 * @param uri The Uri to show into the DraweeView for this Holder
 */
public void bind(Uri uri) {
  mDraweeView.initInstrumentation(uri.toString(), mPerfListener);
  ImageRequestBuilder imageRequestBuilder = ImageRequestBuilder
      .newBuilderWithSource(uri)
      .setResizeOptions(
          new ResizeOptions(
            mDraweeView.getLayoutParams().width,
            mDraweeView.getLayoutParams().height));
  PipelineUtil.addOptionalFeatures(imageRequestBuilder, mConfig);
  // Create the Builder
  PipelineDraweeControllerBuilder builder = Fresco.newDraweeControllerBuilder()
                                                    .setImageRequest(imageRequestBuilder.build());
  if (mConfig.reuseOldController) {
    builder.setOldController(mDraweeView.getController());
  }
  mDraweeView.setListener(builder);
  mDraweeView.setController(builder.build());
}
项目:CommentGallery    文件:CommentImageGrid.java   
private void layoutChildrenView() {
    int childrenCount = getChildCount();

    for (int i = 0; i < childrenCount; i++) {
        ViewGroup childImageLayout = (ViewGroup) getChildAt(i);
        SimpleDraweeView childImageView = (SimpleDraweeView) childImageLayout.getChildAt(0);
        if (mOnItemClickListener != null) {
            final int finalI = i;
            childImageLayout.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    mOnItemClickListener.OnItemClick(finalI);
                }
            });
        }
        ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(mImageUrls.get(i)))
                .setProgressiveRenderingEnabled(true)
                .setResizeOptions(new ResizeOptions(mItemWidth, mItemWidth))
                .build();
        DraweeController controller = Fresco.newDraweeControllerBuilder()
                .setImageRequest(request)
                .setOldController(childImageView.getController())
                .build();
        childImageView.setController(controller);

        int[] position = findPosition(i);
        int itemHeight = mItemWidth;
        int left = (int) (mItemWidth + mHorizontalSpace) * position[1];
        int top = (int) (itemHeight + mVerticalSpace) * position[0];
        int right = left + mItemWidth;
        int bottom = top + itemHeight;

        childImageLayout.layout(left, top, right, bottom);
    }
}
项目:CommentGallery    文件:CommentImageGrid.java   
private void refreshImageChild() {
    int childrenCount = getChildCount();
    if (childrenCount > 0) {
        for (int i = 0; i < childrenCount; i++) {
            ViewGroup childImageLayout = (ViewGroup) getChildAt(i);
            SimpleDraweeView childImageView = (SimpleDraweeView) childImageLayout.getChildAt(0);
            if (mOnItemClickListener != null) {
                final int finalI = i;
                childImageLayout.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mOnItemClickListener.OnItemClick(finalI);
                    }
                });
            }
            ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(mImageUrls.get(i)))
                    .setResizeOptions(new ResizeOptions(mItemWidth, mItemWidth))
                    .build();
            DraweeController controller = Fresco.newDraweeControllerBuilder()
                    .setImageRequest(request)
                    .setOldController(childImageView.getController())
                    .build();
            childImageView.setController(controller);
        }
    }
}
项目:Watermark    文件:FrescoImageLoader.java   
public static void setImageSmall(String url,
                                 SimpleDraweeView simpleDraweeView,
                                 int width,
                                 int height,
                                 SquareRelativeLayout relativeLayout, boolean playGif) {

    Uri uri = Uri.parse(url);
    ImageRequest request = ImageRequestBuilder
            .newBuilderWithSource(uri)
            .setRotationOptions(RotationOptions.autoRotate())
            .setResizeOptions(new ResizeOptions(width, height))
            .setLowestPermittedRequestLevel(ImageRequest.RequestLevel.FULL_FETCH)
            .build();
    DraweeController controller = Fresco.newDraweeControllerBuilder()
            .setTapToRetryEnabled(true)
            .setImageRequest(request)
            .setAutoPlayAnimations(playGif)
            .setOldController(simpleDraweeView.getController())
            .build();
    relativeLayout.setLayoutParams(new RelativeLayout.LayoutParams(width - 5, height));
    simpleDraweeView.setController(controller);
}
项目:fastDev    文件:FrescoUtils.java   
public static void load(Uri uri,SimpleDraweeView draweeView,BasePostprocessor processor,int width,int height,
                        BaseControllerListener listener){
    ImageRequest request =
            ImageRequestBuilder.newBuilderWithSource(uri)
                    .setPostprocessor(processor)
                    .setResizeOptions(new ResizeOptions(width,height))
                    //缩放,在解码前修改内存中的图片大小, 配合Downsampling可以处理所有图片,否则只能处理jpg,
                    // 开启Downsampling:在初始化时设置.setDownsampleEnabled(true)
                    .setProgressiveRenderingEnabled(true)//支持图片渐进式加载
                    .setAutoRotateEnabled(true) //如果图片是侧着,可以自动旋转
                    .build();

    PipelineDraweeController controller =
            (PipelineDraweeController) Fresco.newDraweeControllerBuilder()
                    .setImageRequest(request)
                    .setControllerListener(listener)
                    .setOldController(draweeView.getController())
                    .setAutoPlayAnimations(true) //自动播放gif动画
                    .build();

    draweeView.setController(controller);
}
项目:CanPhotos    文件:CanPhotoHelper.java   
/**
 * 设置图片
 *
 * @param image
 * @param url
 * @param width
 * @param heigth
 */
public void setDraweeImage(SimpleDraweeView image, String url, int width, int heigth) {


    if (width <= 0) {
        width = dp2Px(image.getContext(), 50);
    }
    if (heigth <= 0) {
        heigth = dp2Px(image.getContext(), 50);
    }

    ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url)).setLocalThumbnailPreviewsEnabled(true).setResizeOptions(new ResizeOptions(width, heigth)).build();
    DraweeController draweeController = Fresco.newDraweeControllerBuilder()
            .setImageRequest(imageRequest)
            .setAutoPlayAnimations(true)
            .build();
    image.setController(draweeController);

}
项目:FrescoCustomCacheKey    文件:FrescoImageLoader.java   
public static LJImageRequest getImageRequest(SimpleDraweeView view, String uri, String cacheKey, @Nullable ImageRequest.CacheChoice cacheChoice) {
    if (cacheChoice == null) {
        cacheChoice = ImageRequest.CacheChoice.DEFAULT;
    }

    LJImageRequestBuilder builder = LJImageRequestBuilder
            .newBuilderWithSource(Uri.parse(uri), cacheKey);
    ImageRequestBuilder requestBuilder = builder.getImageRequestBuilder();
    requestBuilder.setAutoRotateEnabled(true)//自动旋转图片方向
                  .setCacheChoice(cacheChoice)//图片类型,设置后可调整图片放入小图磁盘空间还是默认图片磁盘空间
                  .setLocalThumbnailPreviewsEnabled(true)//缩略图预览,影响图片显示速度(轻微)
                  .setLowestPermittedRequestLevel(ImageRequest.RequestLevel.FULL_FETCH)//请求经过缓存级别
                  .setProgressiveRenderingEnabled(true);//渐进加载,主要用于渐进式的JPEG图,影响图片显示速度(普通)

    ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
    if (layoutParams != null && layoutParams.width > 0 &&
            layoutParams.height > 0) {
        ResizeOptions resizeOptions = new ResizeOptions(layoutParams.width, layoutParams.height);
        requestBuilder.setResizeOptions(resizeOptions);//调整图片大小
    }

    return builder.build();
}
项目:android-base    文件:FrescoUtils.java   
/**
 * showThumb
 *
 * @param draweeView     draweeView
 * @param url            url
 * @param resizeWidthDp  resizeWidth
 * @param resizeHeightDp resizeHeight
 */
public static void showThumb(SimpleDraweeView draweeView, String url, int resizeWidthDp, int resizeHeightDp) {
    try {
        if (!isInit)
            return;
        if (url == null || "".equals(url))
            return;
        if (draweeView == null)
            return;
        initialize(draweeView.getContext());
        ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url))
                .setResizeOptions(new ResizeOptions(DimenUtils.dip2px(draweeView.getContext(), resizeWidthDp), DimenUtils.dip2px(draweeView.getContext(), resizeHeightDp)))
                .build();
        DraweeController controller = Fresco.newDraweeControllerBuilder()
                .setImageRequest(request)
                .setOldController(draweeView.getController())
                .setControllerListener(new BaseControllerListener<ImageInfo>())
                .build();
        draweeView.setController(controller);
    } catch (Exception e) {
    }
}
项目:videoPickPlayer    文件:VideoAdapter.java   
public void setFrescoImage(SimpleDraweeView frescoImage, String url , int w, int h){
        if (isNull(url)){
//            frescoImage.setImageURI(Uri.parse("" + R.drawable.fallload));
            frescoImage.setImageResource(R.drawable.fallload);
            return;
        }
//        int width = ScreenUtil.dip2px(w), height = ScreenUtil.dip2px(h);
        if (!url.startsWith("http")){
            url = "file://"+url;
        }
//        showErrorLog(url);
        Uri uri = Uri.parse(url);
//        frescoImage.setImageURI(uri);
        ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri)
                .setResizeOptions(new ResizeOptions(w, h))
                .build();
        PipelineDraweeController controller = (PipelineDraweeController) Fresco.newDraweeControllerBuilder()
                .setOldController(frescoImage.getController())
                .setImageRequest(request)
                .build();
        frescoImage.setController(controller);
    }
项目:android-upload-service    文件:Adapter.java   
public void bind(Item item){
  Uri uri = item.getUri();

  filename.setText(uri.toString());

  DraweeController controller = Fresco.newDraweeControllerBuilder()
      .setImageRequest(ImageRequestBuilder.newBuilderWithSource(uri).setResizeOptions(new ResizeOptions(width, height)).build())
      .setAutoPlayAnimations(true)
      .setOldController(image.getController())
      .setTapToRetryEnabled(true)
      .build();
  image.setController(controller);

  if(item.isCloud()){
    cloud.setImageResource(R.drawable.ic_cloud);
  }else{
    cloud.setImageResource(R.drawable.ic_cloud_off);
  }
}
项目:android-jungle-framework    文件:FrescoImageLoaderEngine.java   
private DraweeController createDraweeController(
        DraweeView draweeView, Uri uri, ControllerListener<ImageInfo> listener) {

    JungleSize size = ImageLoaderUtils.getAppropriateSize(draweeView);
    ImageRequest request = ImageRequestBuilder
            .newBuilderWithSource(uri)
            .setResizeOptions(new ResizeOptions(size.mWidth, size.mHeight))
            .setAutoRotateEnabled(true)
            .build();

    return Fresco.newDraweeControllerBuilder()
            .setUri(uri)
            .setImageRequest(request)
            .setControllerListener(listener)
            .setAutoPlayAnimations(true)
            .setOldController(draweeView.getController())
            .build();
}
项目:nono-android    文件:FrescoImageloadHelper.java   
public static void LoadImageFromURLAndCallBack(SimpleDraweeView destImageView , String URL,Context context,BaseBitmapDataSubscriber bbds)
{
    int w = destImageView.getWidth();
    int h  =destImageView.getHeight();
    if(w<1){
        w = destImageView.getLayoutParams().width;
    }
    if(h<1){
        h  =destImageView.getLayoutParams().height;
    }
    ImageRequest imageRequest =
            ImageRequestBuilder.newBuilderWithSource(Uri.parse(URL))
                    .setResizeOptions(new ResizeOptions(w,h))
                    .setProgressiveRenderingEnabled(true)
                    .build();
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, context);
    dataSource.subscribe(bbds, CallerThreadExecutor.getInstance());
    DraweeController draweeController = Fresco.newDraweeControllerBuilder()
            .setImageRequest(imageRequest)
            .setOldController(destImageView.getController())
            .setAutoPlayAnimations(true)
            .build();
    destImageView.setController(draweeController);
}
项目:nono-android    文件:FrescoImageloadHelper.java   
public static void LoadImageFromURIAndCallBack(SimpleDraweeView destImageView , Uri uri,Context context,BaseBitmapDataSubscriber bbds)
{
    int w = destImageView.getWidth();
    int h  =destImageView.getHeight();
    if(w<1){
        w = destImageView.getLayoutParams().width;
    }
    if(h<1){
        h  =destImageView.getLayoutParams().height;
    }
    ImageRequest imageRequest =
            ImageRequestBuilder.newBuilderWithSource(uri)
                    .setResizeOptions(new ResizeOptions(w,h))
                    .setProgressiveRenderingEnabled(true)
                    .build();
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, context);
    dataSource.subscribe(bbds, CallerThreadExecutor.getInstance());
    DraweeController draweeController = Fresco.newDraweeControllerBuilder()
            .setImageRequest(imageRequest)
            .setOldController(destImageView.getController())
            .setAutoPlayAnimations(true)
            .build();
    destImageView.setController(draweeController);
}
项目:SneezeReader    文件:ArticleAdapter.java   
private ResizeOptions getResizeOptions(ImageView imageView) {

        DisplayMetrics dm = Resources.getSystem().getDisplayMetrics();

        int maxWidth = dm.widthPixels;
        int maxHeight = dm.heightPixels;

        ViewGroup.LayoutParams lp = imageView.getLayoutParams();
        if (lp != null && lp.width > 0) {
            maxWidth = lp.width;
        } else {
            maxWidth = Math.min(maxWidth, Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN
                    ? imageView.getMaxWidth() : Integer.MAX_VALUE);
        }

        if (lp != null && lp.height > 0) {
            maxHeight = lp.height;
        } else {
            maxHeight = Math.min(maxHeight, Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN
                    ? imageView.getMaxHeight() : Integer.MAX_VALUE);
        }

        return new ResizeOptions(maxWidth, maxHeight);
    }
项目:actor-platform    文件:AvatarView.java   
public void bindRaw(String fileName) {
    if (bindedFile != null) {
        bindedFile.detach();
        bindedFile = null;
    }
    currentId = 0;

    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.fromFile(new File(fileName)))
            .setResizeOptions(new ResizeOptions(size, size))
            .setAutoRotateEnabled(true)
            .build();
    PipelineDraweeController controller = (PipelineDraweeController) Fresco.newDraweeControllerBuilder()
            .setOldController(getController())
            .setImageRequest(request)
            .build();
    setController(controller);
}
项目:TLint    文件:ImageAdapter.java   
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    Image image = images.get(position);
    holder.image = image;
    if (image == null) {
        return;
    }
    holder.ivCheck.setVisibility(View.VISIBLE);
    holder.ivCheck.setImageResource(selectedImages.contains(image) ? R.drawable.ap_gallery_checked
            : R.drawable.ap_gallery_normal);
    int width = 100, height = 100;
    ImageRequest request =
            ImageRequestBuilder.newBuilderWithSource(Uri.fromFile(new File(image.path)))
                    .setResizeOptions(new ResizeOptions(width, height))
                    .build();
    PipelineDraweeController controller =
            (PipelineDraweeController) Fresco.newDraweeControllerBuilder()
                    .setOldController(holder.ivPhoto.getController())
                    .setImageRequest(request)
                    .build();
    holder.ivPhoto.setController(controller);
}
项目:fresco    文件:BitmapMemoryCacheKey.java   
public BitmapMemoryCacheKey(
    String sourceString,
    @Nullable ResizeOptions resizeOptions,
    RotationOptions rotationOptions,
    ImageDecodeOptions imageDecodeOptions,
    @Nullable CacheKey postprocessorCacheKey,
    @Nullable String postprocessorName,
    Object callerContext) {
  mSourceString = Preconditions.checkNotNull(sourceString);
  mResizeOptions = resizeOptions;
  mRotationOptions = rotationOptions;
  mImageDecodeOptions = imageDecodeOptions;
  mPostprocessorCacheKey = postprocessorCacheKey;
  mPostprocessorName = postprocessorName;
  mHash = HashCodeUtil.hashCode(
      sourceString.hashCode(),
      (resizeOptions != null) ? resizeOptions.hashCode() : 0,
      rotationOptions.hashCode(),
      mImageDecodeOptions,
      mPostprocessorCacheKey,
      postprocessorName);
  mCallerContext = callerContext;
  mCacheTime = RealtimeSinceBootClock.get().now();
}
项目:fresco    文件:ResizeAndRotateProducer.java   
@VisibleForTesting static float determineResizeRatio(
    ResizeOptions resizeOptions,
    int width,
    int height) {

  if (resizeOptions == null) {
    return 1.0f;
  }

  final float widthRatio = ((float) resizeOptions.width) / width;
  final float heightRatio = ((float) resizeOptions.height) / height;
  float ratio = Math.max(widthRatio, heightRatio);

  if (width * ratio > resizeOptions.maxBitmapSize) {
    ratio = resizeOptions.maxBitmapSize / width;
  }
  if (height * ratio > resizeOptions.maxBitmapSize) {
    ratio = resizeOptions.maxBitmapSize / height;
  }
  return ratio;
}
项目:fresco    文件:ImageRequestTest.java   
@Test
public void testCreatingRequestFromExistingRequest() {
  ImageRequest original = ImageRequestBuilder
      .newBuilderWithSource(Uri.parse("http://frescolib.org/image.jpg"))
          .setCacheChoice(ImageRequest.CacheChoice.SMALL)
      .setImageDecodeOptions(new ImageDecodeOptionsBuilder().build())
      .setLocalThumbnailPreviewsEnabled(true)
      .setLowestPermittedRequestLevel(ImageRequest.RequestLevel.DISK_CACHE)
      .setMediaVariations(MediaVariations.forMediaId("A113"))
      .setPostprocessor(new BasePostprocessor() {
        @Override
        public String getName() {
          return super.getName();
        }
      })
      .setProgressiveRenderingEnabled(true)
      .setRequestListener(new RequestLoggingListener())
      .setResizeOptions(new ResizeOptions(20, 20))
      .setRotationOptions(RotationOptions.forceRotation(RotationOptions.ROTATE_90))
      .setRequestPriority(Priority.HIGH)
      .build();

  ImageRequest copy = ImageRequestBuilder.fromRequest(original).build();

  assertThat(copy).isEqualTo(original);
}
项目:fresco    文件:ThumbnailSizeCheckerTest.java   
private static void testWithImageNotBigEnoughForResizeOptions(
    int[] imageWidths,
    int[] imageHeights,
    int startRotation,
    int additionalRequestWidth,
    int additionalRequestHeight) {
  for (int rotation = startRotation; rotation < 360; rotation += 180) {
    for (int i = 0; i < TEST_COUNT; i++) {
      ResizeOptions resizeOptions = new ResizeOptions(
          REQUEST_WIDTHS[i] + additionalRequestWidth,
          REQUEST_HEIGHTS[i] + additionalRequestHeight);
      EncodedImage encodedImage = mockImage(imageWidths[i], imageHeights[i], rotation);
      assertFalse(ThumbnailSizeChecker.isImageBigEnough(encodedImage, resizeOptions));
    }
  }
}
项目:fresco    文件:DecodeProducerTest.java   
@Test
public void testDecode_WhenSmartResizingEnabledAndLocalUri_ThenPerformDownsampling()
    throws Exception {
  int resizedWidth = 10;
  int resizedHeight = 10;
  when(mExperimentalResizingEnabledSupplier.get()).thenReturn(true);
  setupLocalUri(ResizeOptions.forDimensions(resizedWidth, resizedHeight));

  produceResults();
  JobScheduler.JobRunnable jobRunnable = getJobRunnable();

  jobRunnable.run(mEncodedImage, Consumer.IS_LAST);

  // The sample size was modified, which means Downsampling has been performed
  assertNotEquals(mEncodedImage.getSampleSize(), EncodedImage.DEFAULT_SAMPLE_SIZE);
}
项目:fresco    文件:DecodeProducerTest.java   
@Test
public void testDecode_WhenSmartResizingEnabledAndNetworkUri_ThenPerformNoDownsampling()
    throws Exception {
  int resizedWidth = 10;
  int resizedHeight = 10;
  when(mExperimentalResizingEnabledSupplier.get()).thenReturn(true);
  setupNetworkUri(ResizeOptions.forDimensions(resizedWidth, resizedHeight));

  produceResults();
  JobScheduler.JobRunnable jobRunnable = getJobRunnable();

  jobRunnable.run(mEncodedImage, Consumer.IS_LAST);

  // The sample size was not modified, which means Downsampling has not been performed
  assertEquals(mEncodedImage.getSampleSize(), EncodedImage.DEFAULT_SAMPLE_SIZE);
}
项目:fresco    文件:MediaVariationsFallbackProducerTest.java   
@Test
public void testSendsSmallestLargerFinalImageToConsumerWhenLargerVariantsFromIndexFound() {
  when(mImageRequest.getMediaVariations()).thenReturn(mMediaVariationsWithVariants);
  whenCacheContains(mDefaultBufferedDiskCache, CACHE_KEY_S, CACHE_KEY_M, CACHE_KEY_L);
  whenIndexDbContains(URI_M, SIZE_M, CacheChoice.DEFAULT);
  when(mImageRequest.getResizeOptions()).thenReturn(new ResizeOptions(SIZE_M - 10, SIZE_M - 10));

  mMediaVariationsFallbackProducer.produceResults(mConsumer, mProducerContext);

  verify(mConsumer).onNewResult(mImageM, Consumer.IS_LAST | Consumer.DO_NOT_CACHE_ENCODED);
  verify(mConsumer).onProgressUpdate(1L);
  verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME);
  verifySuccessSentToListener(
      FOUND,
      USED_AS_LAST,
      MediaVariations.SOURCE_IMAGE_REQUEST,
      VARIANTS_COUNT);
  verifyZeroInteractions(mInputProducer, mSmallImageBufferedDiskCache);
}
项目:fresco    文件:MediaVariationsFallbackProducerTest.java   
@Test
public void testSendsLargestCachedNonFinalImageToConsumerAndStartsInputProducerIfNoCachedVariantFromRequestBigEnough() {
  when(mImageRequest.getMediaVariations()).thenReturn(mMediaVariationsWithVariants);
  whenCacheContains(mDefaultBufferedDiskCache, CACHE_KEY_S, CACHE_KEY_M, CACHE_KEY_L);
  when(mImageRequest.getResizeOptions()).thenReturn(new ResizeOptions(SIZE_L + 80, SIZE_L + 80));

  mMediaVariationsFallbackProducer.produceResults(mConsumer, mProducerContext);

  verify(mConsumer).onNewResult(mImageL, Consumer.DO_NOT_CACHE_ENCODED | Consumer.IS_PLACEHOLDER);
  verify(mConsumer, never()).onProgressUpdate(anyFloat());
  verifyInputProducerProduceResultsWithNewConsumer(false);
  verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME);
  verifySuccessSentToListener(
      FOUND,
      NOT_USED_AS_LAST,
      MediaVariations.SOURCE_IMAGE_REQUEST,
      VARIANTS_COUNT);
  verifyZeroInteractions(mSmallImageBufferedDiskCache);
}
项目:fresco    文件:MediaVariationsFallbackProducerTest.java   
@Test
public void testSendsSmallestLargerFinalImageToConsumerWhenLargerVariantsFromRequestFound() {
  when(mImageRequest.getMediaVariations()).thenReturn(mMediaVariationsWithVariants);
  whenCacheContains(mDefaultBufferedDiskCache, CACHE_KEY_S, CACHE_KEY_M, CACHE_KEY_L);
  when(mImageRequest.getResizeOptions()).thenReturn(new ResizeOptions(SIZE_M - 10, SIZE_M - 10));

  mMediaVariationsFallbackProducer.produceResults(mConsumer, mProducerContext);

  verify(mConsumer).onNewResult(mImageM, Consumer.IS_LAST | Consumer.DO_NOT_CACHE_ENCODED);
  verify(mConsumer).onProgressUpdate(1L);
  verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME);
  verifySuccessSentToListener(
      FOUND,
      USED_AS_LAST,
      MediaVariations.SOURCE_IMAGE_REQUEST,
      VARIANTS_COUNT);
  verifyZeroInteractions(mInputProducer, mSmallImageBufferedDiskCache);
}