Search in sources :

Example 51 with ImageRequest

use of com.facebook.imagepipeline.request.ImageRequest in project fresco by facebook.

the class ImagePipeline method submitPrefetchRequest.

private DataSource<Void> submitPrefetchRequest(Producer<Void> producerSequence, ImageRequest imageRequest, ImageRequest.RequestLevel lowestPermittedRequestLevelOnSubmit, Object callerContext, Priority priority) {
    final RequestListener requestListener = getRequestListenerForRequest(imageRequest);
    try {
        ImageRequest.RequestLevel lowestPermittedRequestLevel = ImageRequest.RequestLevel.getMax(imageRequest.getLowestPermittedRequestLevel(), lowestPermittedRequestLevelOnSubmit);
        SettableProducerContext settableProducerContext = new SettableProducerContext(imageRequest, generateUniqueFutureId(), requestListener, callerContext, lowestPermittedRequestLevel, /* isPrefetch */
        true, /* isIntermediateResultExpected */
        false, priority);
        return ProducerToDataSourceAdapter.create(producerSequence, settableProducerContext, requestListener);
    } catch (Exception exception) {
        return DataSources.immediateFailedDataSource(exception);
    }
}
Also used : ForwardingRequestListener(com.facebook.imagepipeline.listener.ForwardingRequestListener) RequestListener(com.facebook.imagepipeline.listener.RequestListener) SettableProducerContext(com.facebook.imagepipeline.producers.SettableProducerContext) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) CancellationException(java.util.concurrent.CancellationException)

Example 52 with ImageRequest

use of com.facebook.imagepipeline.request.ImageRequest in project fresco by facebook.

the class MediaVariationsFragment method loadMainImage.

private void loadMainImage() {
    // Request a non-existent image to force fallback to the variations
    Uri uri = Uri.parse(String.format(URI_TEMPLATE, "full"));
    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);
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) Uri(android.net.Uri)

Example 53 with ImageRequest

use of com.facebook.imagepipeline.request.ImageRequest in project fresco by facebook.

the class MediaVariationsFragment method loadThumb.

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())).build();
    DraweeController controller = Fresco.newDraweeControllerBuilder().setImageRequest(request).setOldController(draweeView.getController()).build();
    draweeView.setController(controller);
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) DraweeController(com.facebook.drawee.interfaces.DraweeController) ImageRequest(com.facebook.imagepipeline.request.ImageRequest)

Example 54 with ImageRequest

use of com.facebook.imagepipeline.request.ImageRequest in project fresco by facebook.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    findViewAndLoadUri(R.id.baseline_jpeg, "https://www.gstatic.com/webp/gallery/1.sm.jpg");
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse("http://pooyak.com/p/progjpeg/jpegload.cgi?o=1")).setProgressiveRenderingEnabled(true).build();
    DraweeController controller = Fresco.newDraweeControllerBuilder().setImageRequest(request).setRetainImageOnFailure(true).build();
    findViewAndSetController(R.id.progressive_jpeg, controller);
    findViewAndLoadUri(R.id.static_webp, "https://www.gstatic.com/webp/gallery/2.sm.webp");
    findViewAndLoadUri(R.id.alpha_webp, "http://frescolib.org/static/translucent.webp").getHierarchy().setBackgroundImage(new ColorDrawable(0xFF302013));
    findViewAndLoadAnimatedImageUri(R.id.animated_gif, "https://s3.amazonaws.com/giphygifs/media/4aBQ9oNjgEQ2k/giphy.gif");
    findViewAndLoadAnimatedImageUri(R.id.animated_webp, "https://www.gstatic.com/webp/animated/1.webp");
    findViewAndLoadAnimatedImageUri(R.id.one_loop_animated_webp, "https://dl.dropboxusercontent.com/u/6610969/webp_180_example.webp");
    String dataUri = "data:image/webp;base64," + "UklGRjgCAABXRUJQVlA4WAoAAAAQAAAAFwAAFwAAQUxQSC0AAAABJ6AgbQNm1+EkTnRExDkWahpJgRIk" + "oOCVgAKy/mVdSxvR/wyEHWJ49xCbCAcAVlA4IOQBAACQCgCdASoYABgAPlEkjkWjoiEUBAA4BQS2AE6Z" + "Qjgbyv8ZuWF3B3ANsBdoHoAeWj+s3wleTHcua7PMAYrNOLPHFqAbpKGWe8x3KqHen7YXTMnmq/c9GqBt" + "ZtuQ0AAA/r031iZbkliICmd/QSg0OjEWbX/nv8v+g4UDPpobcehywI6oypX8hbuzcQndgaVt0zW5DiZP" + "6Ueo/21IPqsuRm1WyZHL3bJIFStwH8BOWif7xVniUiHwD5HwW8AXIZiq2maDmyIvxn4a0fetR+flTrt/" + "5/Vq3BVTeorYBHMN7L09DE9xDW/2+dj45/mCe9vjNUGRpT5EJhV8jDz/ZxPixLvN9Tl5iPD/neh1RCl6" + "AOcx3JudnAseXqvm8dEtF+rA40Bg881EW88XwU1oXf/5RY/4ToF9NwcXPLC/AodLaAFPpiXt+C6cFDIj" + "+uqi12PWFO+p7jn1P+sjCpbP/OBdHIoez8Rp6nslBEiFG19LKqv6dkGzLKtvt9dRIpz2sef2JFUVB+v+" + "hvMMmQ4o6d8aMTGuv/4wZxogl/n/k3g83NO3bBnf7/TL8Baf97pQw43+FVR0hXfpvD0k51yE35e2jNF/" + "98Uv3fAfPXw0T8irZQR4r1/ktG5xrypg/aKDooBtoI5aQAAA";
    findViewAndLoadUri(R.id.data_webp, dataUri);
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) DraweeController(com.facebook.drawee.interfaces.DraweeController) ImageRequest(com.facebook.imagepipeline.request.ImageRequest)

Example 55 with ImageRequest

use of com.facebook.imagepipeline.request.ImageRequest in project actor-platform by actorapp.

the class DialogView method buildLayout.

@Override
public DialogLayout buildLayout(Dialog arg, int width, int height) {
    if (!isStylesLoaded) {
        isStylesLoaded = true;
        ActorStyle style = ActorSDK.sharedActor().style;
        Context context = getContext();
        titlePaint = createTextPaint(Fonts.medium(), 16, style.getDialogsTitleColor());
        titleSecurePaint = createTextPaint(Fonts.medium(), 16, style.getDialogsTitleSecureColor());
        datePaint = createTextPaint(Fonts.regular(), 14, style.getDialogsTimeColor());
        textPaint = createTextPaint(Fonts.regular(), 16, style.getDialogsTimeColor());
        textActivePaint = createTextPaint(Fonts.regular(), 16, style.getDialogsActiveTextColor());
        senderTextColor = style.getDialogsActiveTextColor();
        groupIcon = new TintDrawable(context.getResources().getDrawable(R.drawable.ic_group_black_18dp), style.getDialogsTitleColor());
        channelIcon = new TintDrawable(context.getResources().getDrawable(R.drawable.ic_megaphone_18dp_black), style.getDialogsTitleColor());
        botIcon = new TintDrawable(context.getResources().getDrawable(R.drawable.ic_robot_black_18dp), style.getDialogsTitleColor());
        secretIcon = new TintDrawable(context.getResources().getDrawable(R.drawable.ic_lock_black_18dp), style.getDialogsTitleSecureColor());
        counterTextPaint = createTextPaint(Fonts.medium(), 14, style.getDialogsCounterTextColor());
        counterTextPaint.setTextAlign(Paint.Align.CENTER);
        counterBgPaint = createFilledPaint(style.getDialogsCounterBackgroundColor());
        fillPaint = createFilledPaint(Color.BLACK);
        placeholderColors = ActorSDK.sharedActor().style.getDefaultAvatarPlaceholders();
        avatarBorder = new Paint();
        avatarBorder.setStyle(Paint.Style.STROKE);
        avatarBorder.setAntiAlias(true);
        avatarBorder.setColor(0x19000000);
        avatarBorder.setStrokeWidth(1);
        avatarTextColor = createTextPaint(Fonts.regular(), 20, Color.WHITE);
        avatarTextColor.setTextAlign(Paint.Align.CENTER);
        typingText = messenger().getFormatter().formatTyping();
        stateSent = new TintDrawable(context.getResources().getDrawable(R.drawable.msg_check_1), style.getDialogsStateSentColor());
        stateReceived = new TintDrawable(context.getResources().getDrawable(R.drawable.msg_check_2), style.getDialogsStateDeliveredColor());
        stateRead = new TintDrawable(context.getResources().getDrawable(R.drawable.msg_check_2), style.getDialogsStateReadColor());
    }
    DialogLayout res = new DialogLayout();
    res.setPlaceholderIndex(Math.abs(arg.getPeer().getPeerId()) % placeholderColors.length);
    res.setShortName(buildShortName(arg.getDialogTitle()));
    if (arg.getDialogAvatar() != null) {
        AvatarImage image = getAvatarImage(arg.getDialogAvatar());
        if (image != null) {
            String desc = messenger().findDownloadedDescriptor(image.getFileReference().getFileId());
            if (desc != null) {
                ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.fromFile(new File(desc))).setResizeOptions(new ResizeOptions(Screen.dp(52), Screen.dp(52))).setImageType(ImageRequest.ImageType.SMALL).build();
                res.setImageRequest(request);
            } else {
                InvalidationContext invalidationContext = getCurrentLayoutContext();
                messenger().bindRawFile(image.getFileReference(), true, new FileCallback() {

                    @Override
                    public void onNotDownloaded() {
                        if (invalidationContext.isCancelled()) {
                            messenger().unbindRawFile(image.getFileReference().getFileId(), false, this);
                        }
                    }

                    @Override
                    public void onDownloading(float progress) {
                        if (invalidationContext.isCancelled()) {
                            messenger().unbindRawFile(image.getFileReference().getFileId(), false, this);
                        }
                    }

                    @Override
                    public void onDownloaded(FileSystemReference reference) {
                        messenger().unbindRawFile(image.getFileReference().getFileId(), false, this);
                        invalidationContext.invalidate();
                    }
                });
            }
        }
    }
    // Top Row
    int maxTitleWidth = (width - Screen.dp(72)) - Screen.dp(8);
    if (arg.getDate() > 0) {
        String dateText = messenger().getFormatter().formatShortDate(arg.getDate());
        int dateWidth = (int) datePaint.measureText(dateText);
        res.setDate(dateText, dateWidth);
        maxTitleWidth -= dateWidth + Screen.dp(16);
    }
    if (arg.getPeer().getPeerType() == PeerType.GROUP) {
        if (arg.isChannel()) {
            res.setTitleIcon(channelIcon);
            res.setTitleIconTop(Screen.dp(33));
        } else {
            res.setTitleIcon(groupIcon);
            res.setTitleIconTop(Screen.dp(33));
        }
        maxTitleWidth -= Screen.dp(16 + /*icon width*/
        4);
    } else if (arg.getPeer().getPeerType() == PeerType.PRIVATE_ENCRYPTED) {
        res.setTitleIcon(secretIcon);
        res.setTitleIconTop(Screen.dp(31));
        maxTitleWidth -= Screen.dp(16 + /*icon width*/
        4);
    } else if (arg.getPeer().getPeerType() == PeerType.PRIVATE) {
        if (arg.isBot()) {
            res.setTitleIcon(botIcon);
            res.setTitleIconTop(Screen.dp(33));
            maxTitleWidth -= Screen.dp(16 + /*icon width*/
            4);
        }
    }
    if (arg.getSenderId() == messenger().myUid()) {
        if (arg.isRead()) {
            res.setState(stateRead);
        } else if (arg.isReceived()) {
            res.setState(stateReceived);
        } else {
            res.setState(stateSent);
        }
        maxTitleWidth -= Screen.dp(20);
    }
    res.setTitleLayout(singleLineText(arg.getDialogTitle(), arg.getPeer().getPeerType() == PeerType.PRIVATE_ENCRYPTED ? titleSecurePaint : titlePaint, maxTitleWidth));
    // Second Row
    int maxWidth = width - Screen.dp(72) - Screen.dp(8);
    if (arg.getUnreadCount() > 0) {
        String counterText = "" + arg.getUnreadCount();
        int counterWidth = (int) counterTextPaint.measureText(counterText) + Screen.sp(10);
        counterWidth = Math.max(counterWidth, Screen.dp(22));
        res.setCounter(counterText, counterWidth);
        maxWidth -= counterWidth + Screen.dp(8);
    }
    if (arg.getSenderId() > 0) {
        String contentText = messenger().getFormatter().formatContentText(arg.getSenderId(), arg.getMessageType(), arg.getText().replace("\n", " "), arg.getRelatedUid(), arg.isChannel());
        if (arg.getPeer().getPeerType() == PeerType.GROUP) {
            if (messenger().getFormatter().isLargeDialogMessage(arg.getMessageType())) {
                res.setTextLayout(singleLineText(handleEmoji(contentText), textActivePaint, maxWidth));
            } else {
                String senderName = messenger().getFormatter().formatPerformerName(arg.getSenderId()) + ": ";
                if (arg.getMessageType() == ContentType.TEXT) {
                    SpannableStringBuilder builder = new SpannableStringBuilder();
                    builder.append(senderName);
                    builder.setSpan(new ForegroundColorSpan(senderTextColor), 0, senderName.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
                    builder.append(contentText);
                    res.setTextLayout(singleLineText(builder, textPaint, maxWidth));
                } else {
                    CharSequence contentResult = handleEmoji(senderName, contentText);
                    res.setTextLayout(singleLineText(contentResult, textActivePaint, maxWidth));
                }
            }
        } else {
            if (arg.getMessageType() == ContentType.TEXT) {
                res.setTextLayout(singleLineText(handleEmoji(contentText), textPaint, maxWidth));
            } else {
                res.setTextLayout(singleLineText(handleEmoji(contentText), textActivePaint, maxWidth));
            }
        }
    }
    return res;
}
Also used : Context(android.content.Context) FileSystemReference(im.actor.runtime.files.FileSystemReference) ForegroundColorSpan(android.text.style.ForegroundColorSpan) TintDrawable(im.actor.sdk.view.TintDrawable) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) FileCallback(im.actor.core.viewmodel.FileCallback) ActorStyle(im.actor.sdk.ActorStyle) ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) AvatarImage(im.actor.core.entity.AvatarImage) File(java.io.File) SpannableStringBuilder(android.text.SpannableStringBuilder)

Aggregations

ImageRequest (com.facebook.imagepipeline.request.ImageRequest)100 ResizeOptions (com.facebook.imagepipeline.common.ResizeOptions)26 DraweeController (com.facebook.drawee.interfaces.DraweeController)25 CloseableReference (com.facebook.common.references.CloseableReference)24 Uri (android.net.Uri)18 ImagePipeline (com.facebook.imagepipeline.core.ImagePipeline)17 Test (org.junit.Test)14 Bitmap (android.graphics.Bitmap)13 CacheKey (com.facebook.cache.common.CacheKey)12 File (java.io.File)11 DataSource (com.facebook.datasource.DataSource)10 BaseBitmapDataSubscriber (com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber)9 CloseableImage (com.facebook.imagepipeline.image.CloseableImage)8 ImageRequestBuilder (com.facebook.imagepipeline.request.ImageRequestBuilder)8 Animatable (android.graphics.drawable.Animatable)7 PipelineDraweeController (com.facebook.drawee.backends.pipeline.PipelineDraweeController)7 BaseControllerListener (com.facebook.drawee.controller.BaseControllerListener)7 ImageOptions (com.facebook.fresco.vito.options.ImageOptions)7 ImageInfo (com.facebook.imagepipeline.image.ImageInfo)7 EncodedImage (com.facebook.imagepipeline.image.EncodedImage)6