Search in sources :

Example 1 with ChatColors

use of org.thoughtcrime.securesms.conversation.colors.ChatColors in project Signal-Android by WhisperSystems.

the class ChatWallpaperPreviewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState, boolean ready) {
    dynamicTheme.onCreate(this);
    setContentView(R.layout.chat_wallpaper_preview_activity);
    adapter = new ChatWallpaperPreviewAdapter();
    colorizerView = findViewById(R.id.colorizer);
    bubble2 = findViewById(R.id.preview_bubble_2);
    viewPager = findViewById(R.id.preview_pager);
    View submit = findViewById(R.id.preview_set_wallpaper);
    ChatWallpaperRepository repository = new ChatWallpaperRepository();
    ChatWallpaper selected = getIntent().getParcelableExtra(EXTRA_CHAT_WALLPAPER);
    boolean dim = getIntent().getBooleanExtra(EXTRA_DIM_IN_DARK_MODE, false);
    Toolbar toolbar = findViewById(R.id.toolbar);
    TextView bubble2Text = findViewById(R.id.preview_bubble_2_text);
    toolbar.setNavigationOnClickListener(unused -> {
        finish();
    });
    viewPager.setAdapter(adapter);
    adapter.submitList(Collections.singletonList(new ChatWallpaperSelectionMappingModel(selected)));
    repository.getAllWallpaper(wallpapers -> adapter.submitList(Stream.of(wallpapers).map(wallpaper -> ChatWallpaperFactory.updateWithDimming(wallpaper, dim ? ChatWallpaper.FIXED_DIM_LEVEL_FOR_DARK_THEME : 0f)).<MappingModel<?>>map(ChatWallpaperSelectionMappingModel::new).toList()));
    submit.setOnClickListener(unused -> {
        ChatWallpaperSelectionMappingModel model = (ChatWallpaperSelectionMappingModel) adapter.getCurrentList().get(viewPager.getCurrentItem());
        setResult(RESULT_OK, new Intent().putExtra(EXTRA_CHAT_WALLPAPER, model.getWallpaper()));
        finish();
    });
    RecipientId recipientId = getIntent().getParcelableExtra(EXTRA_RECIPIENT_ID);
    final ChatColors chatColors;
    if (recipientId != null && Recipient.live(recipientId).get().hasOwnChatColors()) {
        Recipient recipient = Recipient.live(recipientId).get();
        bubble2Text.setText(getString(R.string.ChatWallpaperPreviewActivity__set_wallpaper_for_s, recipient.getDisplayName(this)));
        chatColors = recipient.getChatColors();
        bubble2.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
            updateChatColors(chatColors);
        });
    } else if (SignalStore.chatColorsValues().hasChatColors()) {
        chatColors = Objects.requireNonNull(SignalStore.chatColorsValues().getChatColors());
        bubble2.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
            updateChatColors(chatColors);
        });
    } else {
        onPageChanged = new OnPageChanged();
        viewPager.registerOnPageChangeCallback(onPageChanged);
        bubble2.addOnLayoutChangeListener(new UpdateChatColorsOnNextLayoutChange(selected.getAutoChatColors()));
    }
    new FullscreenHelper(this).showSystemUI();
    WindowUtil.setLightStatusBarFromTheme(this);
    WindowUtil.setLightNavigationBarFromTheme(this);
}
Also used : SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) Context(android.content.Context) Bundle(android.os.Bundle) Stream(com.annimon.stream.Stream) NonNull(androidx.annotation.NonNull) Intent(android.content.Intent) ViewPager2(androidx.viewpager2.widget.ViewPager2) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) ChatColors(org.thoughtcrime.securesms.conversation.colors.ChatColors) Drawable(android.graphics.drawable.Drawable) R(org.thoughtcrime.securesms.R) DynamicTheme(org.thoughtcrime.securesms.util.DynamicTheme) ColorizerView(org.thoughtcrime.securesms.conversation.colors.ColorizerView) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) View(android.view.View) Recipient(org.thoughtcrime.securesms.recipients.Recipient) FullscreenHelper(org.thoughtcrime.securesms.util.FullscreenHelper) MappingModel(org.thoughtcrime.securesms.util.adapter.mapping.MappingModel) WindowUtil(org.thoughtcrime.securesms.util.WindowUtil) Objects(java.util.Objects) TextView(android.widget.TextView) PassphraseRequiredActivity(org.thoughtcrime.securesms.PassphraseRequiredActivity) DynamicNoActionBarTheme(org.thoughtcrime.securesms.util.DynamicNoActionBarTheme) Toolbar(androidx.appcompat.widget.Toolbar) Projection(org.thoughtcrime.securesms.util.Projection) Collections(java.util.Collections) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) ChatColors(org.thoughtcrime.securesms.conversation.colors.ChatColors) Intent(android.content.Intent) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ColorizerView(org.thoughtcrime.securesms.conversation.colors.ColorizerView) View(android.view.View) TextView(android.widget.TextView) TextView(android.widget.TextView) FullscreenHelper(org.thoughtcrime.securesms.util.FullscreenHelper) Toolbar(androidx.appcompat.widget.Toolbar)

Example 2 with ChatColors

use of org.thoughtcrime.securesms.conversation.colors.ChatColors in project Signal-Android by WhisperSystems.

the class CallParticipantView method setPipAvatar.

private void setPipAvatar(@NonNull Recipient recipient) {
    ContactPhoto contactPhoto = recipient.isSelf() ? new ProfileContactPhoto(Recipient.self(), Recipient.self().getProfileAvatar()) : recipient.getContactPhoto();
    FallbackContactPhoto fallbackPhoto = recipient.getFallbackContactPhoto(FALLBACK_PHOTO_PROVIDER);
    GlideApp.with(this).load(contactPhoto).fallback(fallbackPhoto.asCallCard(getContext())).error(fallbackPhoto.asCallCard(getContext())).diskCacheStrategy(DiskCacheStrategy.ALL).into(pipAvatar);
    pipAvatar.setScaleType(contactPhoto == null ? ImageView.ScaleType.CENTER_INSIDE : ImageView.ScaleType.CENTER_CROP);
    ChatColors chatColors = recipient.getChatColors();
    pipAvatar.setBackground(chatColors.getChatBubbleMask());
}
Also used : ProfileContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto) FallbackContactPhoto(org.thoughtcrime.securesms.contacts.avatars.FallbackContactPhoto) ChatColors(org.thoughtcrime.securesms.conversation.colors.ChatColors) 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)

Example 3 with ChatColors

use of org.thoughtcrime.securesms.conversation.colors.ChatColors 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 4 with ChatColors

use of org.thoughtcrime.securesms.conversation.colors.ChatColors 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 5 with ChatColors

use of org.thoughtcrime.securesms.conversation.colors.ChatColors in project Signal-Android by signalapp.

the class ChatWallpaperPreviewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState, boolean ready) {
    dynamicTheme.onCreate(this);
    setContentView(R.layout.chat_wallpaper_preview_activity);
    adapter = new ChatWallpaperPreviewAdapter();
    colorizerView = findViewById(R.id.colorizer);
    bubble2 = findViewById(R.id.preview_bubble_2);
    viewPager = findViewById(R.id.preview_pager);
    View submit = findViewById(R.id.preview_set_wallpaper);
    ChatWallpaperRepository repository = new ChatWallpaperRepository();
    ChatWallpaper selected = getIntent().getParcelableExtra(EXTRA_CHAT_WALLPAPER);
    boolean dim = getIntent().getBooleanExtra(EXTRA_DIM_IN_DARK_MODE, false);
    Toolbar toolbar = findViewById(R.id.toolbar);
    TextView bubble2Text = findViewById(R.id.preview_bubble_2_text);
    toolbar.setNavigationOnClickListener(unused -> {
        finish();
    });
    viewPager.setAdapter(adapter);
    adapter.submitList(Collections.singletonList(new ChatWallpaperSelectionMappingModel(selected)));
    repository.getAllWallpaper(wallpapers -> adapter.submitList(Stream.of(wallpapers).map(wallpaper -> ChatWallpaperFactory.updateWithDimming(wallpaper, dim ? ChatWallpaper.FIXED_DIM_LEVEL_FOR_DARK_THEME : 0f)).<MappingModel<?>>map(ChatWallpaperSelectionMappingModel::new).toList()));
    submit.setOnClickListener(unused -> {
        ChatWallpaperSelectionMappingModel model = (ChatWallpaperSelectionMappingModel) adapter.getCurrentList().get(viewPager.getCurrentItem());
        setResult(RESULT_OK, new Intent().putExtra(EXTRA_CHAT_WALLPAPER, model.getWallpaper()));
        finish();
    });
    RecipientId recipientId = getIntent().getParcelableExtra(EXTRA_RECIPIENT_ID);
    final ChatColors chatColors;
    if (recipientId != null && Recipient.live(recipientId).get().hasOwnChatColors()) {
        Recipient recipient = Recipient.live(recipientId).get();
        bubble2Text.setText(getString(R.string.ChatWallpaperPreviewActivity__set_wallpaper_for_s, recipient.getDisplayName(this)));
        chatColors = recipient.getChatColors();
        bubble2.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
            updateChatColors(chatColors);
        });
    } else if (SignalStore.chatColorsValues().hasChatColors()) {
        chatColors = Objects.requireNonNull(SignalStore.chatColorsValues().getChatColors());
        bubble2.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
            updateChatColors(chatColors);
        });
    } else {
        onPageChanged = new OnPageChanged();
        viewPager.registerOnPageChangeCallback(onPageChanged);
        bubble2.addOnLayoutChangeListener(new UpdateChatColorsOnNextLayoutChange(selected.getAutoChatColors()));
    }
    new FullscreenHelper(this).showSystemUI();
    WindowUtil.setLightStatusBarFromTheme(this);
    WindowUtil.setLightNavigationBarFromTheme(this);
}
Also used : SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) Context(android.content.Context) Bundle(android.os.Bundle) Stream(com.annimon.stream.Stream) NonNull(androidx.annotation.NonNull) Intent(android.content.Intent) ViewPager2(androidx.viewpager2.widget.ViewPager2) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) ChatColors(org.thoughtcrime.securesms.conversation.colors.ChatColors) Drawable(android.graphics.drawable.Drawable) R(org.thoughtcrime.securesms.R) DynamicTheme(org.thoughtcrime.securesms.util.DynamicTheme) ColorizerView(org.thoughtcrime.securesms.conversation.colors.ColorizerView) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) View(android.view.View) Recipient(org.thoughtcrime.securesms.recipients.Recipient) FullscreenHelper(org.thoughtcrime.securesms.util.FullscreenHelper) MappingModel(org.thoughtcrime.securesms.util.adapter.mapping.MappingModel) WindowUtil(org.thoughtcrime.securesms.util.WindowUtil) Objects(java.util.Objects) TextView(android.widget.TextView) PassphraseRequiredActivity(org.thoughtcrime.securesms.PassphraseRequiredActivity) DynamicNoActionBarTheme(org.thoughtcrime.securesms.util.DynamicNoActionBarTheme) Toolbar(androidx.appcompat.widget.Toolbar) Projection(org.thoughtcrime.securesms.util.Projection) Collections(java.util.Collections) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) ChatColors(org.thoughtcrime.securesms.conversation.colors.ChatColors) Intent(android.content.Intent) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ColorizerView(org.thoughtcrime.securesms.conversation.colors.ColorizerView) View(android.view.View) TextView(android.widget.TextView) TextView(android.widget.TextView) FullscreenHelper(org.thoughtcrime.securesms.util.FullscreenHelper) Toolbar(androidx.appcompat.widget.Toolbar)

Aggregations

ChatColors (org.thoughtcrime.securesms.conversation.colors.ChatColors)6 Drawable (android.graphics.drawable.Drawable)4 ProfileContactPhoto (org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto)4 Context (android.content.Context)2 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 View (android.view.View)2 TextView (android.widget.TextView)2 NonNull (androidx.annotation.NonNull)2 Toolbar (androidx.appcompat.widget.Toolbar)2 ViewPager2 (androidx.viewpager2.widget.ViewPager2)2 Stream (com.annimon.stream.Stream)2 MultiTransformation (com.bumptech.glide.load.MultiTransformation)2 Transformation (com.bumptech.glide.load.Transformation)2 CircleCrop (com.bumptech.glide.load.resource.bitmap.CircleCrop)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 Objects (java.util.Objects)2 PassphraseRequiredActivity (org.thoughtcrime.securesms.PassphraseRequiredActivity)2 R (org.thoughtcrime.securesms.R)2