Search in sources :

Example 1 with ImageInfo

use of com.facebook.imagepipeline.image.ImageInfo in project fresco by facebook.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // GIF
    final ViewGroup gifControls = (ViewGroup) findViewById(R.id.gif_controls);
    updateAnimationControls(gifControls, null);
    mAnimatedGifView = (SimpleDraweeView) findViewById(R.id.animated_gif);
    Uri animatedGifUri = Uri.parse("http://s3.amazonaws.com/giphygifs/media/4aBQ9oNjgEQ2k/giphy.gif");
    final TextView gifInfo = (TextView) findViewById(R.id.gif_info);
    DraweeController gifController = Fresco.newDraweeControllerBuilder().setUri(animatedGifUri).setControllerListener(new BaseControllerListener<ImageInfo>() {

        @Override
        public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable anim) {
            updateAnimationControls(gifControls, anim);
            gifInfo.setText(getAnimationInformation(anim));
        }
    }).build();
    mAnimatedGifView.setController(gifController);
    // Animated WebP
    final ViewGroup webpControls = (ViewGroup) findViewById(R.id.webp_controls);
    updateAnimationControls(webpControls, null);
    mAnimatedWebpView = (SimpleDraweeView) findViewById(R.id.animated_webp);
    final TextView webpInfo = (TextView) findViewById(R.id.webp_info);
    Uri animatedWebpUri = Uri.parse("http://www.gstatic.com/webp/animated/1.webp");
    DraweeController webpController = Fresco.newDraweeControllerBuilder().setUri(animatedWebpUri).setControllerListener(new BaseControllerListener<ImageInfo>() {

        @Override
        public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable anim) {
            updateAnimationControls(webpControls, anim);
            webpInfo.setText(getAnimationInformation(anim));
        }
    }).build();
    mAnimatedWebpView.setController(webpController);
}
Also used : BaseControllerListener(com.facebook.drawee.controller.BaseControllerListener) ViewGroup(android.view.ViewGroup) DraweeController(com.facebook.drawee.interfaces.DraweeController) Animatable(android.graphics.drawable.Animatable) TextView(android.widget.TextView) ImageInfo(com.facebook.imagepipeline.image.ImageInfo) Uri(android.net.Uri)

Example 2 with ImageInfo

use of com.facebook.imagepipeline.image.ImageInfo in project remusic by aa112901.

the class LoodView method initUI.

/**
 * 初始化UI
 *
 * @param context
 */
private void initUI(Context context) {
    LayoutInflater.from(context).inflate(R.layout.load_view, this, true);
    for (String imagesID : imageNet) {
        final SimpleDraweeView mAlbumArt = new SimpleDraweeView(context);
        ControllerListener controllerListener = new BaseControllerListener<ImageInfo>() {

            @Override
            public void onFinalImageSet(String id, @Nullable ImageInfo imageInfo, @Nullable Animatable anim) {
                if (imageInfo == null) {
                    return;
                }
                QualityInfo qualityInfo = imageInfo.getQualityInfo();
                FLog.d("Final image received! " + "Size %d x %d", "Quality level %d, good enough: %s, full quality: %s", imageInfo.getWidth(), imageInfo.getHeight(), qualityInfo.getQuality(), qualityInfo.isOfGoodEnoughQuality(), qualityInfo.isOfFullQuality());
            }

            @Override
            public void onIntermediateImageSet(String id, @Nullable ImageInfo imageInfo) {
            // FLog.d("Intermediate image received");
            }

            @Override
            public void onFailure(String id, Throwable throwable) {
                mAlbumArt.setImageURI(Uri.parse("res:/" + R.drawable.placeholder_disk_210));
            }
        };
        Uri uri = null;
        try {
            uri = Uri.parse(imagesID);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (uri != null) {
            ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri).build();
            DraweeController controller = Fresco.newDraweeControllerBuilder().setOldController(mAlbumArt.getController()).setImageRequest(request).setControllerListener(controllerListener).build();
            mAlbumArt.setController(controller);
        } else {
            mAlbumArt.setImageURI(Uri.parse("res:/" + R.drawable.placeholder_disk_210));
        }
        // view.setImageURI(Uri.parse(imagesID));
        // view.setImageResource(imagesID);
        // view.setImageResource(imagesID);
        mAlbumArt.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageViewList.add(mAlbumArt);
    }
    dotViewList.add(findViewById(R.id.v_dot1));
    dotViewList.add(findViewById(R.id.v_dot2));
    dotViewList.add(findViewById(R.id.v_dot3));
    dotViewList.add(findViewById(R.id.v_dot4));
    dotViewList.add(findViewById(R.id.v_dot5));
    dotViewList.add(findViewById(R.id.v_dot6));
    dotViewList.add(findViewById(R.id.v_dot7));
    viewPager = (ViewPager) findViewById(R.id.viewPager);
    viewPager.setFocusable(true);
    fPagerAdapter = new FPagerAdapter();
    viewPager.setAdapter(fPagerAdapter);
    viewPager.addOnPageChangeListener(new MyPageChangeListener());
}
Also used : SimpleDraweeView(com.facebook.drawee.view.SimpleDraweeView) DraweeController(com.facebook.drawee.interfaces.DraweeController) BaseControllerListener(com.facebook.drawee.controller.BaseControllerListener) ControllerListener(com.facebook.drawee.controller.ControllerListener) QualityInfo(com.facebook.imagepipeline.image.QualityInfo) Uri(android.net.Uri) BaseControllerListener(com.facebook.drawee.controller.BaseControllerListener) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) Animatable(android.graphics.drawable.Animatable) ImageInfo(com.facebook.imagepipeline.image.ImageInfo) Nullable(android.support.annotation.Nullable)

Example 3 with ImageInfo

use of com.facebook.imagepipeline.image.ImageInfo in project remusic by aa112901.

the class RoundFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_roundimage, container, false);
    ((ViewGroup) rootView).setAnimationCacheEnabled(false);
    if (getArguments() != null) {
        albumPath = getArguments().getString("album");
    }
    // CircleImageView  circleImageView = (CircleImageView) rootView.findViewById(R.id.circle);
    sdv = (SimpleDraweeView) rootView.findViewById(R.id.sdv);
    // 初始化圆角圆形参数对象
    RoundingParams rp = new RoundingParams();
    // 设置图像是否为圆形
    rp.setRoundAsCircle(true);
    // 设置圆角半径
    // rp.setCornersRadius(20);
    // 分别设置左上角、右上角、左下角、右下角的圆角半径
    // rp.setCornersRadii(20,25,30,35);
    // 分别设置(前2个)左上角、(3、4)右上角、(5、6)左下角、(7、8)右下角的圆角半径
    // rp.setCornersRadii(new float[]{20,25,30,35,40,45,50,55});
    // 设置边框颜色及其宽度
    rp.setBorder(Color.BLACK, 6);
    // 获取GenericDraweeHierarchy对象
    GenericDraweeHierarchy hierarchy = GenericDraweeHierarchyBuilder.newInstance(getResources()).setRoundingParams(rp).setFadeDuration(300).build();
    // 设置Hierarchy
    sdv.setHierarchy(hierarchy);
    // Log.e("music id",musicId + "");
    // String uri = MusicUtils.getAlbumdata(getContext().getApplicationContext(), musicId);
    // 
    // if (musicId != -1 && uri != null) {
    // //circleImageView.setImageBitmap(bitmap);
    // //circleImageView.setImageURI(Uri.parse(uri));
    // Uri ur = MusicUtils.getAlbumUri(getContext().getApplicationContext(), musicId);
    // sdv.setImageURI(ur);
    // } else {
    // 
    // // circleImageView.setImageResource(R.drawable.placeholder_disk_play_song);
    // Uri urr = Uri.parse("res:/" + R.drawable.placeholder_disk_play_song);
    // sdv.setImageURI(urr);
    // }
    ControllerListener controllerListener = new BaseControllerListener<ImageInfo>() {

        @Override
        public void onFinalImageSet(String id, @Nullable ImageInfo imageInfo, @Nullable Animatable anim) {
            if (imageInfo == null) {
                return;
            }
            QualityInfo qualityInfo = imageInfo.getQualityInfo();
            FLog.d("Final image received! " + "Size %d x %d", "Quality level %d, good enough: %s, full quality: %s", imageInfo.getWidth(), imageInfo.getHeight(), qualityInfo.getQuality(), qualityInfo.isOfGoodEnoughQuality(), qualityInfo.isOfFullQuality());
        }

        @Override
        public void onIntermediateImageSet(String id, @Nullable ImageInfo imageInfo) {
        // FLog.d("Intermediate image received");
        }

        @Override
        public void onFailure(String id, Throwable throwable) {
            sdv.setImageURI(Uri.parse("res:/" + R.drawable.placeholder_disk_play_song));
        }
    };
    if (albumPath == null) {
        sdv.setImageURI(Uri.parse("res:/" + R.drawable.placeholder_disk_play_song));
    } else {
        try {
            ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(albumPath)).build();
            DraweeController controller = Fresco.newDraweeControllerBuilder().setOldController(sdv.getController()).setImageRequest(request).setControllerListener(controllerListener).build();
            sdv.setController(controller);
        // sdv.setImageBitmap(BitmapFactory.decodeStream(HttpUtil.getFromCache(getActivity(),getAlbumPath())));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return rootView;
}
Also used : ViewGroup(android.view.ViewGroup) GenericDraweeHierarchy(com.facebook.drawee.generic.GenericDraweeHierarchy) DraweeController(com.facebook.drawee.interfaces.DraweeController) BaseControllerListener(com.facebook.drawee.controller.BaseControllerListener) ControllerListener(com.facebook.drawee.controller.ControllerListener) QualityInfo(com.facebook.imagepipeline.image.QualityInfo) SimpleDraweeView(com.facebook.drawee.view.SimpleDraweeView) View(android.view.View) BaseControllerListener(com.facebook.drawee.controller.BaseControllerListener) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) Animatable(android.graphics.drawable.Animatable) ImageInfo(com.facebook.imagepipeline.image.ImageInfo) RoundingParams(com.facebook.drawee.generic.RoundingParams) Nullable(android.support.annotation.Nullable)

Example 4 with ImageInfo

use of com.facebook.imagepipeline.image.ImageInfo in project fresco by facebook.

the class ImageFormatGifFragment method setAnimationUri.

private void setAnimationUri(Uri uri) {
    final PipelineDraweeControllerBuilder controllerBuilder = Fresco.newDraweeControllerBuilder().setAutoPlayAnimations(mAutoPlayEnabled).setOldController(mSimpleDraweeView.getController());
    final ImageDecodeOptionsBuilder optionsBuilder = ImageDecodeOptions.newBuilder().setMaxDimensionPx(4000);
    if (mGifDecoder != null) {
        optionsBuilder.setCustomImageDecoder(mGifDecoder);
    }
    controllerBuilder.setImageRequest(ImageRequestBuilder.newBuilderWithSource(uri).setImageDecodeOptions(optionsBuilder.build()).build());
    if (!mAutoPlayEnabled) {
        controllerBuilder.setControllerListener(new BaseControllerListener<ImageInfo>() {

            @Override
            public void onFinalImageSet(String id, @Nullable ImageInfo imageInfo, @Nullable final Animatable animatable) {
                if (animatable != null) {
                    mSimpleDraweeView.getHierarchy().setOverlayImage(getPlayOverlayDrawable());
                    mSimpleDraweeView.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            if (animatable.isRunning()) {
                                animatable.stop();
                                mSimpleDraweeView.getHierarchy().setOverlayImage(getPlayOverlayDrawable());
                            } else {
                                animatable.start();
                                mSimpleDraweeView.getHierarchy().setOverlayImage(null);
                            }
                        }
                    });
                }
            }
        });
    } else {
        mSimpleDraweeView.getHierarchy().setOverlayImage(null);
    }
    mSimpleDraweeView.setController(controllerBuilder.build());
}
Also used : Animatable(android.graphics.drawable.Animatable) ImageInfo(com.facebook.imagepipeline.image.ImageInfo) SimpleDraweeView(com.facebook.drawee.view.SimpleDraweeView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ImageDecodeOptionsBuilder(com.facebook.imagepipeline.common.ImageDecodeOptionsBuilder) PipelineDraweeControllerBuilder(com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder)

Example 5 with ImageInfo

use of com.facebook.imagepipeline.image.ImageInfo in project fresco by facebook.

the class ControllerListenerWrapperTest method testOnIntermediateImageSet.

@Test
public void testOnIntermediateImageSet() {
    final ImageInfo imageInfo = mock(ImageInfo.class);
    mControllerListenerWrapper.onIntermediateImageSet(ID, imageInfo);
    verify(mControllerListener).onIntermediateImageSet(eq(STRING_ID), eq(imageInfo));
    verifyNoMoreInteractions(mControllerListener);
}
Also used : ImageInfo(com.facebook.imagepipeline.image.ImageInfo) Test(org.junit.Test)

Aggregations

ImageInfo (com.facebook.imagepipeline.image.ImageInfo)13 Animatable (android.graphics.drawable.Animatable)11 BaseControllerListener (com.facebook.drawee.controller.BaseControllerListener)8 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)7 DraweeController (com.facebook.drawee.interfaces.DraweeController)5 QualityInfo (com.facebook.imagepipeline.image.QualityInfo)4 Uri (android.net.Uri)3 Nullable (android.support.annotation.Nullable)3 View (android.view.View)3 ControllerListener (com.facebook.drawee.controller.ControllerListener)3 SimpleDraweeView (com.facebook.drawee.view.SimpleDraweeView)3 Test (org.junit.Test)3 Point (android.graphics.Point)2 ViewGroup (android.view.ViewGroup)2 TextView (android.widget.TextView)2 PipelineDraweeControllerBuilder (com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder)2 ResizeOptions (com.facebook.imagepipeline.common.ResizeOptions)2 Drawable (android.graphics.drawable.Drawable)1 AdapterView (android.widget.AdapterView)1 GenericDraweeHierarchy (com.facebook.drawee.generic.GenericDraweeHierarchy)1