Search in sources :

Example 6 with ProfileContactPhoto

use of org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto in project Signal-Android by WhisperSystems.

the class InsightsRepository method getUserAvatar.

@Override
public void getUserAvatar(@NonNull Consumer<InsightsUserAvatar> avatarConsumer) {
    SimpleTask.run(() -> {
        Recipient self = Recipient.self().resolve();
        String name = Optional.fromNullable(self.getDisplayName(context)).or("");
        return new InsightsUserAvatar(new ProfileContactPhoto(self, self.getProfileAvatar()), self.getAvatarColor(), new GeneratedContactPhoto(name, R.drawable.ic_profile_outline_40));
    }, avatarConsumer::accept);
}
Also used : ProfileContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto) Recipient(org.thoughtcrime.securesms.recipients.Recipient) GeneratedContactPhoto(org.thoughtcrime.securesms.contacts.avatars.GeneratedContactPhoto)

Example 7 with ProfileContactPhoto

use of org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto in project Signal-Android by WhisperSystems.

the class AvatarUtil method loadBlurredIconIntoImageView.

public static void loadBlurredIconIntoImageView(@NonNull Recipient recipient, @NonNull AppCompatImageView target) {
    Context context = target.getContext();
    ContactPhoto photo;
    if (recipient.isSelf()) {
        photo = new ProfileContactPhoto(Recipient.self(), Recipient.self().getProfileAvatar());
    } else if (recipient.getContactPhoto() == null) {
        target.setImageDrawable(null);
        target.setBackgroundColor(ContextCompat.getColor(target.getContext(), R.color.black));
        return;
    } else {
        photo = recipient.getContactPhoto();
    }
    GlideApp.with(target).load(photo).transform(new BlurTransformation(context, 0.25f, BlurTransformation.MAX_RADIUS)).into(new CustomViewTarget<View, Drawable>(target) {

        @Override
        public void onLoadFailed(@Nullable Drawable errorDrawable) {
            target.setImageDrawable(null);
            target.setBackgroundColor(ContextCompat.getColor(target.getContext(), R.color.black));
        }

        @Override
        public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
            target.setImageDrawable(resource);
        }

        @Override
        protected void onResourceCleared(@Nullable Drawable placeholder) {
            target.setImageDrawable(placeholder);
        }
    });
}
Also used : Context(android.content.Context) ProfileContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto) Drawable(android.graphics.drawable.Drawable) GeneratedContactPhoto(org.thoughtcrime.securesms.contacts.avatars.GeneratedContactPhoto) ContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ContactPhoto) ProfileContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) ImageView(android.widget.ImageView) View(android.view.View)

Example 8 with ProfileContactPhoto

use of org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto in project Signal-Android by WhisperSystems.

the class AvatarUtil method request.

private static <T> GlideRequest<T> request(@NonNull GlideRequest<T> glideRequest, @NonNull Context context, @NonNull Recipient recipient, boolean loadSelf, int targetSize) {
    final ContactPhoto photo;
    if (Recipient.self().equals(recipient) && loadSelf) {
        photo = new ProfileContactPhoto(recipient, recipient.getProfileAvatar());
    } else {
        photo = recipient.getContactPhoto();
    }
    final GlideRequest<T> request = glideRequest.load(photo).error(getFallback(context, recipient, targetSize)).diskCacheStrategy(DiskCacheStrategy.ALL);
    if (recipient.shouldBlurAvatar()) {
        return request.transform(new BlurTransformation(context, 0.25f, BlurTransformation.MAX_RADIUS));
    } else {
        return request;
    }
}
Also used : ProfileContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto) GeneratedContactPhoto(org.thoughtcrime.securesms.contacts.avatars.GeneratedContactPhoto) ContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ContactPhoto) ProfileContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto)

Example 9 with ProfileContactPhoto

use of org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto 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 10 with ProfileContactPhoto

use of org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto in project Signal-Android by WhisperSystems.

the class AvatarPreviewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState, boolean ready) {
    super.onCreate(savedInstanceState, ready);
    setTheme(R.style.TextSecure_MediaPreview);
    setContentView(R.layout.contact_photo_preview_activity);
    if (Build.VERSION.SDK_INT >= 21) {
        postponeEnterTransition();
        TransitionInflater inflater = TransitionInflater.from(this);
        getWindow().setSharedElementEnterTransition(inflater.inflateTransition(R.transition.full_screen_avatar_image_enter_transition_set));
        getWindow().setSharedElementReturnTransition(inflater.inflateTransition(R.transition.full_screen_avatar_image_return_transition_set));
    }
    Toolbar toolbar = findViewById(R.id.toolbar);
    EmojiTextView title = findViewById(R.id.title);
    ImageView avatar = findViewById(R.id.avatar);
    setSupportActionBar(toolbar);
    requireSupportActionBar().setDisplayHomeAsUpEnabled(true);
    requireSupportActionBar().setDisplayShowTitleEnabled(false);
    Context context = getApplicationContext();
    RecipientId recipientId = RecipientId.from(getIntent().getStringExtra(RECIPIENT_ID_EXTRA));
    Recipient.live(recipientId).observe(this, recipient -> {
        ContactPhoto contactPhoto = recipient.isSelf() ? new ProfileContactPhoto(recipient, recipient.getProfileAvatar()) : recipient.getContactPhoto();
        FallbackContactPhoto fallbackPhoto = recipient.isSelf() ? new ResourceContactPhoto(R.drawable.ic_profile_outline_40, R.drawable.ic_profile_outline_20, R.drawable.ic_person_large) : recipient.getFallbackContactPhoto();
        Resources resources = this.getResources();
        GlideApp.with(this).asBitmap().load(contactPhoto).fallback(fallbackPhoto.asCallCard(this)).error(fallbackPhoto.asCallCard(this)).diskCacheStrategy(DiskCacheStrategy.ALL).addListener(new RequestListener<Bitmap>() {

            @Override
            public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
                Log.w(TAG, "Unable to load avatar, or avatar removed, closing");
                finish();
                return false;
            }

            @Override
            public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
                return false;
            }
        }).into(new CustomTarget<Bitmap>() {

            @Override
            public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                avatar.setImageDrawable(RoundedBitmapDrawableFactory.create(resources, resource));
                if (Build.VERSION.SDK_INT >= 21) {
                    startPostponedEnterTransition();
                }
            }

            @Override
            public void onLoadCleared(@Nullable Drawable placeholder) {
            }
        });
        title.setText(recipient.getDisplayName(context));
    });
    FullscreenHelper fullscreenHelper = new FullscreenHelper(this);
    findViewById(android.R.id.content).setOnClickListener(v -> fullscreenHelper.toggleUiVisibility());
    fullscreenHelper.configureToolbarSpacer(findViewById(R.id.toolbar_cutout_spacer));
    fullscreenHelper.showAndHideWithSystemUI(getWindow(), findViewById(R.id.toolbar_layout));
}
Also used : Context(android.content.Context) ProfileContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) RequestListener(com.bumptech.glide.request.RequestListener) Drawable(android.graphics.drawable.Drawable) TransitionInflater(android.transition.TransitionInflater) ContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ContactPhoto) ProfileContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto) FallbackContactPhoto(org.thoughtcrime.securesms.contacts.avatars.FallbackContactPhoto) ResourceContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ResourceContactPhoto) DataSource(com.bumptech.glide.load.DataSource) FallbackContactPhoto(org.thoughtcrime.securesms.contacts.avatars.FallbackContactPhoto) CustomTarget(com.bumptech.glide.request.target.CustomTarget) Target(com.bumptech.glide.request.target.Target) Bitmap(android.graphics.Bitmap) ResourceContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ResourceContactPhoto) EmojiTextView(org.thoughtcrime.securesms.components.emoji.EmojiTextView) ImageView(android.widget.ImageView) Resources(android.content.res.Resources) GlideException(com.bumptech.glide.load.engine.GlideException) Nullable(androidx.annotation.Nullable) FullscreenHelper(org.thoughtcrime.securesms.util.FullscreenHelper) Toolbar(androidx.appcompat.widget.Toolbar)

Aggregations

ProfileContactPhoto (org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto)15 ContactPhoto (org.thoughtcrime.securesms.contacts.avatars.ContactPhoto)8 Drawable (android.graphics.drawable.Drawable)6 GeneratedContactPhoto (org.thoughtcrime.securesms.contacts.avatars.GeneratedContactPhoto)6 ResourceContactPhoto (org.thoughtcrime.securesms.contacts.avatars.ResourceContactPhoto)5 Context (android.content.Context)4 ImageView (android.widget.ImageView)4 FallbackContactPhoto (org.thoughtcrime.securesms.contacts.avatars.FallbackContactPhoto)4 ChatColors (org.thoughtcrime.securesms.conversation.colors.ChatColors)4 BlurTransformation (org.thoughtcrime.securesms.util.BlurTransformation)4 Resources (android.content.res.Resources)2 Bitmap (android.graphics.Bitmap)2 TransitionInflater (android.transition.TransitionInflater)2 View (android.view.View)2 Nullable (androidx.annotation.Nullable)2 AppCompatImageView (androidx.appcompat.widget.AppCompatImageView)2 Toolbar (androidx.appcompat.widget.Toolbar)2 DataSource (com.bumptech.glide.load.DataSource)2 MultiTransformation (com.bumptech.glide.load.MultiTransformation)2 Transformation (com.bumptech.glide.load.Transformation)2