Search in sources :

Example 1 with BlurTransformation

use of org.thoughtcrime.securesms.util.BlurTransformation in project Signal-Android by signalapp.

the class AvatarImageView method setAvatar.

private void setAvatar(@NonNull GlideRequests requestManager, @Nullable Recipient recipient, @NonNull AvatarOptions avatarOptions) {
    if (recipient != null) {
        RecipientContactPhoto photo = (recipient.isSelf() && avatarOptions.useSelfProfileAvatar) ? new RecipientContactPhoto(recipient, new ProfileContactPhoto(Recipient.self(), Recipient.self().getProfileAvatar())) : new RecipientContactPhoto(recipient);
        boolean shouldBlur = recipient.shouldBlurAvatar();
        ChatColors chatColors = recipient.getChatColors();
        if (!photo.equals(recipientContactPhoto) || shouldBlur != blurred || !Objects.equals(chatColors, this.chatColors)) {
            requestManager.clear(this);
            this.chatColors = chatColors;
            recipientContactPhoto = photo;
            Drawable fallbackContactPhotoDrawable = size == SIZE_SMALL ? photo.recipient.getSmallFallbackContactPhotoDrawable(getContext(), inverted, fallbackPhotoProvider, ViewUtil.getWidth(this)) : photo.recipient.getFallbackContactPhotoDrawable(getContext(), inverted, fallbackPhotoProvider, ViewUtil.getWidth(this));
            if (fixedSizeTarget != null) {
                requestManager.clear(fixedSizeTarget);
            }
            if (photo.contactPhoto != null) {
                List<Transformation<Bitmap>> transforms = new ArrayList<>();
                if (shouldBlur) {
                    transforms.add(new BlurTransformation(ApplicationDependencies.getApplication(), 0.25f, BlurTransformation.MAX_RADIUS));
                }
                transforms.add(new CircleCrop());
                blurred = shouldBlur;
                GlideRequest<Drawable> request = requestManager.load(photo.contactPhoto).dontAnimate().fallback(fallbackContactPhotoDrawable).error(fallbackContactPhotoDrawable).diskCacheStrategy(DiskCacheStrategy.ALL).downsample(DownsampleStrategy.CENTER_INSIDE).transform(new MultiTransformation<>(transforms));
                if (avatarOptions.fixedSize > 0) {
                    fixedSizeTarget = new FixedSizeTarget(avatarOptions.fixedSize);
                    request.into(fixedSizeTarget);
                } else {
                    request.into(this);
                }
            } else {
                setImageDrawable(fallbackContactPhotoDrawable);
            }
        }
        setAvatarClickHandler(recipient, avatarOptions.quickContactEnabled);
    } else {
        recipientContactPhoto = null;
        requestManager.clear(this);
        if (fallbackPhotoProvider != null) {
            setImageDrawable(fallbackPhotoProvider.getPhotoForRecipientWithoutName().asDrawable(getContext(), AvatarColor.UNKNOWN, inverted));
        } else {
            setImageDrawable(unknownRecipientDrawable);
        }
        disableQuickContact();
    }
}
Also used : ProfileContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto) BlurTransformation(org.thoughtcrime.securesms.util.BlurTransformation) MultiTransformation(com.bumptech.glide.load.MultiTransformation) BlurTransformation(org.thoughtcrime.securesms.util.BlurTransformation) Transformation(com.bumptech.glide.load.Transformation) ChatColors(org.thoughtcrime.securesms.conversation.colors.ChatColors) Drawable(android.graphics.drawable.Drawable) ArrayList(java.util.ArrayList) CircleCrop(com.bumptech.glide.load.resource.bitmap.CircleCrop)

Example 2 with BlurTransformation

use of org.thoughtcrime.securesms.util.BlurTransformation in project Signal-Android by WhisperSystems.

the class AvatarImageView method setAvatar.

private void setAvatar(@NonNull GlideRequests requestManager, @Nullable Recipient recipient, @NonNull AvatarOptions avatarOptions) {
    if (recipient != null) {
        RecipientContactPhoto photo = (recipient.isSelf() && avatarOptions.useSelfProfileAvatar) ? new RecipientContactPhoto(recipient, new ProfileContactPhoto(Recipient.self(), Recipient.self().getProfileAvatar())) : new RecipientContactPhoto(recipient);
        boolean shouldBlur = recipient.shouldBlurAvatar();
        ChatColors chatColors = recipient.getChatColors();
        if (!photo.equals(recipientContactPhoto) || shouldBlur != blurred || !Objects.equals(chatColors, this.chatColors)) {
            requestManager.clear(this);
            this.chatColors = chatColors;
            recipientContactPhoto = photo;
            Drawable fallbackContactPhotoDrawable = size == SIZE_SMALL ? photo.recipient.getSmallFallbackContactPhotoDrawable(getContext(), inverted, fallbackPhotoProvider, ViewUtil.getWidth(this)) : photo.recipient.getFallbackContactPhotoDrawable(getContext(), inverted, fallbackPhotoProvider, ViewUtil.getWidth(this));
            if (fixedSizeTarget != null) {
                requestManager.clear(fixedSizeTarget);
            }
            if (photo.contactPhoto != null) {
                List<Transformation<Bitmap>> transforms = new ArrayList<>();
                if (shouldBlur) {
                    transforms.add(new BlurTransformation(ApplicationDependencies.getApplication(), 0.25f, BlurTransformation.MAX_RADIUS));
                }
                transforms.add(new CircleCrop());
                blurred = shouldBlur;
                GlideRequest<Drawable> request = requestManager.load(photo.contactPhoto).dontAnimate().fallback(fallbackContactPhotoDrawable).error(fallbackContactPhotoDrawable).diskCacheStrategy(DiskCacheStrategy.ALL).downsample(DownsampleStrategy.CENTER_INSIDE).transform(new MultiTransformation<>(transforms));
                if (avatarOptions.fixedSize > 0) {
                    fixedSizeTarget = new FixedSizeTarget(avatarOptions.fixedSize);
                    request.into(fixedSizeTarget);
                } else {
                    request.into(this);
                }
            } else {
                setImageDrawable(fallbackContactPhotoDrawable);
            }
        }
        setAvatarClickHandler(recipient, avatarOptions.quickContactEnabled);
    } else {
        recipientContactPhoto = null;
        requestManager.clear(this);
        if (fallbackPhotoProvider != null) {
            setImageDrawable(fallbackPhotoProvider.getPhotoForRecipientWithoutName().asDrawable(getContext(), AvatarColor.UNKNOWN, inverted));
        } else {
            setImageDrawable(unknownRecipientDrawable);
        }
        disableQuickContact();
    }
}
Also used : ProfileContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto) BlurTransformation(org.thoughtcrime.securesms.util.BlurTransformation) MultiTransformation(com.bumptech.glide.load.MultiTransformation) BlurTransformation(org.thoughtcrime.securesms.util.BlurTransformation) Transformation(com.bumptech.glide.load.Transformation) ChatColors(org.thoughtcrime.securesms.conversation.colors.ChatColors) Drawable(android.graphics.drawable.Drawable) ArrayList(java.util.ArrayList) CircleCrop(com.bumptech.glide.load.resource.bitmap.CircleCrop)

Example 3 with BlurTransformation

use of org.thoughtcrime.securesms.util.BlurTransformation in project Signal-Android by WhisperSystems.

the class WebRtcCallView method updateLocalCallParticipant.

public void updateLocalCallParticipant(@NonNull WebRtcLocalRenderState state, @NonNull CallParticipant localCallParticipant, @NonNull CallParticipant focusedParticipant, boolean displaySmallSelfPipInLandscape) {
    largeLocalRender.setMirror(localCallParticipant.getCameraDirection() == CameraState.Direction.FRONT);
    smallLocalRender.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL);
    largeLocalRender.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL);
    localCallParticipant.getVideoSink().getLockableEglBase().performWithValidEglBase(eglBase -> {
        largeLocalRender.init(eglBase);
    });
    videoToggle.setChecked(localCallParticipant.isVideoEnabled(), false);
    smallLocalRender.setRenderInPip(true);
    if (state == WebRtcLocalRenderState.EXPANDED) {
        expandPip(localCallParticipant, focusedParticipant);
        return;
    } else if ((state == WebRtcLocalRenderState.SMALL_RECTANGLE || state == WebRtcLocalRenderState.GONE) && pictureInPictureExpansionHelper.isExpandedOrExpanding()) {
        shrinkPip(localCallParticipant);
        return;
    } else {
        smallLocalRender.setCallParticipant(localCallParticipant);
        smallLocalRender.setMirror(localCallParticipant.getCameraDirection() == CameraState.Direction.FRONT);
    }
    switch(state) {
        case GONE:
            largeLocalRender.attachBroadcastVideoSink(null);
            largeLocalRenderFrame.setVisibility(View.GONE);
            smallLocalRenderFrame.setVisibility(View.GONE);
            break;
        case SMALL_RECTANGLE:
            smallLocalRenderFrame.setVisibility(View.VISIBLE);
            animatePipToLargeRectangle(displaySmallSelfPipInLandscape);
            largeLocalRender.attachBroadcastVideoSink(null);
            largeLocalRenderFrame.setVisibility(View.GONE);
            break;
        case SMALLER_RECTANGLE:
            smallLocalRenderFrame.setVisibility(View.VISIBLE);
            animatePipToSmallRectangle();
            largeLocalRender.attachBroadcastVideoSink(null);
            largeLocalRenderFrame.setVisibility(View.GONE);
            break;
        case LARGE:
            largeLocalRender.attachBroadcastVideoSink(localCallParticipant.getVideoSink());
            largeLocalRenderFrame.setVisibility(View.VISIBLE);
            largeLocalRenderNoVideo.setVisibility(View.GONE);
            largeLocalRenderNoVideoAvatar.setVisibility(View.GONE);
            smallLocalRenderFrame.setVisibility(View.GONE);
            break;
        case LARGE_NO_VIDEO:
            largeLocalRender.attachBroadcastVideoSink(null);
            largeLocalRenderFrame.setVisibility(View.VISIBLE);
            largeLocalRenderNoVideo.setVisibility(View.VISIBLE);
            largeLocalRenderNoVideoAvatar.setVisibility(View.VISIBLE);
            GlideApp.with(getContext().getApplicationContext()).load(new ProfileContactPhoto(localCallParticipant.getRecipient(), localCallParticipant.getRecipient().getProfileAvatar())).transform(new CenterCrop(), new BlurTransformation(getContext(), 0.25f, BlurTransformation.MAX_RADIUS)).diskCacheStrategy(DiskCacheStrategy.ALL).into(largeLocalRenderNoVideoAvatar);
            smallLocalRenderFrame.setVisibility(View.GONE);
            break;
    }
}
Also used : ProfileContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto) BlurTransformation(org.thoughtcrime.securesms.util.BlurTransformation) CenterCrop(com.bumptech.glide.load.resource.bitmap.CenterCrop)

Example 4 with BlurTransformation

use of org.thoughtcrime.securesms.util.BlurTransformation in project Signal-Android by signalapp.

the class WebRtcCallView method updateLocalCallParticipant.

public void updateLocalCallParticipant(@NonNull WebRtcLocalRenderState state, @NonNull CallParticipant localCallParticipant, @NonNull CallParticipant focusedParticipant, boolean displaySmallSelfPipInLandscape) {
    largeLocalRender.setMirror(localCallParticipant.getCameraDirection() == CameraState.Direction.FRONT);
    smallLocalRender.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL);
    largeLocalRender.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL);
    localCallParticipant.getVideoSink().getLockableEglBase().performWithValidEglBase(eglBase -> {
        largeLocalRender.init(eglBase);
    });
    videoToggle.setChecked(localCallParticipant.isVideoEnabled(), false);
    smallLocalRender.setRenderInPip(true);
    if (state == WebRtcLocalRenderState.EXPANDED) {
        expandPip(localCallParticipant, focusedParticipant);
        return;
    } else if ((state == WebRtcLocalRenderState.SMALL_RECTANGLE || state == WebRtcLocalRenderState.GONE) && pictureInPictureExpansionHelper.isExpandedOrExpanding()) {
        shrinkPip(localCallParticipant);
        return;
    } else {
        smallLocalRender.setCallParticipant(localCallParticipant);
        smallLocalRender.setMirror(localCallParticipant.getCameraDirection() == CameraState.Direction.FRONT);
    }
    switch(state) {
        case GONE:
            largeLocalRender.attachBroadcastVideoSink(null);
            largeLocalRenderFrame.setVisibility(View.GONE);
            smallLocalRenderFrame.setVisibility(View.GONE);
            break;
        case SMALL_RECTANGLE:
            smallLocalRenderFrame.setVisibility(View.VISIBLE);
            animatePipToLargeRectangle(displaySmallSelfPipInLandscape);
            largeLocalRender.attachBroadcastVideoSink(null);
            largeLocalRenderFrame.setVisibility(View.GONE);
            break;
        case SMALLER_RECTANGLE:
            smallLocalRenderFrame.setVisibility(View.VISIBLE);
            animatePipToSmallRectangle();
            largeLocalRender.attachBroadcastVideoSink(null);
            largeLocalRenderFrame.setVisibility(View.GONE);
            break;
        case LARGE:
            largeLocalRender.attachBroadcastVideoSink(localCallParticipant.getVideoSink());
            largeLocalRenderFrame.setVisibility(View.VISIBLE);
            largeLocalRenderNoVideo.setVisibility(View.GONE);
            largeLocalRenderNoVideoAvatar.setVisibility(View.GONE);
            smallLocalRenderFrame.setVisibility(View.GONE);
            break;
        case LARGE_NO_VIDEO:
            largeLocalRender.attachBroadcastVideoSink(null);
            largeLocalRenderFrame.setVisibility(View.VISIBLE);
            largeLocalRenderNoVideo.setVisibility(View.VISIBLE);
            largeLocalRenderNoVideoAvatar.setVisibility(View.VISIBLE);
            GlideApp.with(getContext().getApplicationContext()).load(new ProfileContactPhoto(localCallParticipant.getRecipient(), localCallParticipant.getRecipient().getProfileAvatar())).transform(new CenterCrop(), new BlurTransformation(getContext(), 0.25f, BlurTransformation.MAX_RADIUS)).diskCacheStrategy(DiskCacheStrategy.ALL).into(largeLocalRenderNoVideoAvatar);
            smallLocalRenderFrame.setVisibility(View.GONE);
            break;
    }
}
Also used : ProfileContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto) BlurTransformation(org.thoughtcrime.securesms.util.BlurTransformation) CenterCrop(com.bumptech.glide.load.resource.bitmap.CenterCrop)

Aggregations

ProfileContactPhoto (org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto)4 BlurTransformation (org.thoughtcrime.securesms.util.BlurTransformation)4 Drawable (android.graphics.drawable.Drawable)2 MultiTransformation (com.bumptech.glide.load.MultiTransformation)2 Transformation (com.bumptech.glide.load.Transformation)2 CenterCrop (com.bumptech.glide.load.resource.bitmap.CenterCrop)2 CircleCrop (com.bumptech.glide.load.resource.bitmap.CircleCrop)2 ArrayList (java.util.ArrayList)2 ChatColors (org.thoughtcrime.securesms.conversation.colors.ChatColors)2