Search in sources :

Example 11 with DraweeController

use of com.facebook.drawee.interfaces.DraweeController 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 12 with DraweeController

use of com.facebook.drawee.interfaces.DraweeController in project fresco by facebook.

the class SimpleDraweeView method setImageURI.

/**
 * Displays an image given by the uri.
 *
 * @param uri uri of the image
 * @param callerContext caller context
 */
public void setImageURI(Uri uri, @Nullable Object callerContext) {
    DraweeController controller = mControllerBuilder.setCallerContext(callerContext).setUri(uri).setOldController(getController()).build();
    setController(controller);
}
Also used : DraweeController(com.facebook.drawee.interfaces.DraweeController)

Example 13 with DraweeController

use of com.facebook.drawee.interfaces.DraweeController in project fresco by facebook.

the class DraweeHolderTest method testNewControllerKeepsHierarchy.

@Test
public void testNewControllerKeepsHierarchy() {
    mDraweeHolder.setController(mController);
    assertSame(mDraweeHierarchy, mDraweeHolder.getHierarchy());
    DraweeController another = DraweeMocks.mockController();
    mDraweeHolder.setController(another);
    assertSame(mDraweeHierarchy, mDraweeHolder.getHierarchy());
    assertSame(another, mDraweeHolder.getController());
    assertNull(mController.getHierarchy());
    assertSame(mDraweeHierarchy, another.getHierarchy());
}
Also used : DraweeController(com.facebook.drawee.interfaces.DraweeController) Test(org.junit.Test)

Example 14 with DraweeController

use of com.facebook.drawee.interfaces.DraweeController in project fresco by facebook.

the class DraweeViewTest method testNewControllerKeepsHierarchy.

@Test
public void testNewControllerKeepsHierarchy() {
    mDraweeView.setHierarchy(mDraweeHierarchy);
    mDraweeView.setController(mController);
    DraweeController controller2 = DraweeMocks.mockController();
    mDraweeView.setController(controller2);
    assertSame(controller2, mDraweeView.getController());
    assertSame(mTopLevelDrawable, mDraweeView.getDrawable());
    verify(mController).setHierarchy(null);
    verify(controller2).setHierarchy(mDraweeHierarchy);
}
Also used : DraweeController(com.facebook.drawee.interfaces.DraweeController) Test(org.junit.Test)

Example 15 with DraweeController

use of com.facebook.drawee.interfaces.DraweeController in project fresco by facebook.

the class DraweeSpanSimpleTextFragment method updateText.

private void updateText() {
    // The # will be replaced with the image.
    String text = getString(R.string.drawee_span_simple_text);
    int imagePosition = text.indexOf('#');
    DraweeSpanStringBuilder draweeSpanStringBuilder = new DraweeSpanStringBuilder(text);
    DraweeHierarchy draweeHierarchy = GenericDraweeHierarchyBuilder.newInstance(getResources()).setPlaceholderImage(new ColorDrawable(Color.RED)).setActualImageScaleType(mScaleType).build();
    DraweeController controller = Fresco.newDraweeControllerBuilder().setUri(mInlineImageUri).build();
    draweeSpanStringBuilder.setImageSpan(getContext(), /* Context */
    draweeHierarchy, /* hierarchy to be used */
    controller, /* controller to be used to update the hierarchy */
    imagePosition, /* image index within the text */
    200, /* image width */
    200, /* image height */
    false, /* auto resize */
    DraweeSpan.ALIGN_CENTER);
    /* alignment */
    int imagePosition2 = text.indexOf('@');
    DraweeHierarchy draweeAnimatedHierarchy = GenericDraweeHierarchyBuilder.newInstance(getResources()).setPlaceholderImage(new ColorDrawable(Color.RED)).setActualImageScaleType(mScaleType).build();
    DraweeController animatedController = Fresco.newDraweeControllerBuilder().setUri(mInlineAnimatedImageUri).setAutoPlayAnimations(true).build();
    draweeSpanStringBuilder.setImageSpan(getContext(), /* Context */
    draweeAnimatedHierarchy, /* hierarchy to be used */
    animatedController, /* controller to be used to update the hierarchy */
    imagePosition2, /* image index within the text */
    200, /* image width */
    200, /* image height */
    false, /* auto resize */
    DraweeSpan.ALIGN_CENTER);
    /* alignment */
    mDraweeSpanTextView.setDraweeSpanStringBuilder(draweeSpanStringBuilder);
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) DraweeController(com.facebook.drawee.interfaces.DraweeController) DraweeSpanStringBuilder(com.facebook.drawee.span.DraweeSpanStringBuilder) DraweeHierarchy(com.facebook.drawee.interfaces.DraweeHierarchy)

Aggregations

DraweeController (com.facebook.drawee.interfaces.DraweeController)53 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)25 ResizeOptions (com.facebook.imagepipeline.common.ResizeOptions)10 Uri (android.net.Uri)8 SimpleDraweeView (com.facebook.drawee.view.SimpleDraweeView)8 Animatable (android.graphics.drawable.Animatable)7 BaseControllerListener (com.facebook.drawee.controller.BaseControllerListener)6 GenericDraweeHierarchy (com.facebook.drawee.generic.GenericDraweeHierarchy)5 ImageInfo (com.facebook.imagepipeline.image.ImageInfo)5 ControllerListener (com.facebook.drawee.controller.ControllerListener)4 QualityInfo (com.facebook.imagepipeline.image.QualityInfo)4 Drawable (android.graphics.drawable.Drawable)3 Nullable (android.support.annotation.Nullable)3 Canvas (android.graphics.Canvas)2 ColorDrawable (android.graphics.drawable.ColorDrawable)2 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 AbstractDraweeController (com.facebook.drawee.controller.AbstractDraweeController)2 ProgressBarDrawable (com.facebook.drawee.drawable.ProgressBarDrawable)2 GenericDraweeHierarchyBuilder (com.facebook.drawee.generic.GenericDraweeHierarchyBuilder)2