Search in sources :

Example 1 with ColorizerView

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

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

the class ChatWallpaperFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    viewModel = ViewModelProviders.of(requireActivity()).get(ChatWallpaperViewModel.class);
    AvatarImageView portrait = view.findViewById(R.id.chat_wallpaper_preview_top_bar_portrait);
    Toolbar toolbar = view.findViewById(R.id.toolbar);
    ImageView chatWallpaperPreview = view.findViewById(R.id.chat_wallpaper_preview_background);
    View setWallpaper = view.findViewById(R.id.chat_wallpaper_set_wallpaper);
    SwitchCompat dimInNightMode = view.findViewById(R.id.chat_wallpaper_dark_theme_dims_wallpaper);
    View chatWallpaperDim = view.findViewById(R.id.chat_wallpaper_dim);
    TextView setChatColor = view.findViewById(R.id.chat_wallpaper_set_chat_color);
    TextView resetChatColors = view.findViewById(R.id.chat_wallpaper_reset_chat_colors);
    ImageView sentBubble = view.findViewById(R.id.chat_wallpaper_preview_bubble_2);
    ColorizerView colorizerView = view.findViewById(R.id.colorizer);
    TextView resetAllWallpaper = view.findViewById(R.id.chat_wallpaper_reset_all_wallpapers);
    AppCompatImageView recvBubble = view.findViewById(R.id.chat_wallpaper_preview_bubble_1);
    toolbar.setTitle(R.string.preferences__chat_color_and_wallpaper);
    toolbar.setNavigationOnClickListener(nav -> {
        if (!Navigation.findNavController(nav).popBackStack()) {
            requireActivity().finish();
        }
    });
    forceAspectRatioToScreenByAdjustingHeight(chatWallpaperPreview);
    viewModel.getWallpaperPreviewPortrait().observe(getViewLifecycleOwner(), wallpaperPreviewPortrait -> wallpaperPreviewPortrait.applyToAvatarImageView(portrait));
    viewModel.getCurrentWallpaper().observe(getViewLifecycleOwner(), wallpaper -> {
        if (wallpaper.isPresent()) {
            wallpaper.get().loadInto(chatWallpaperPreview);
            ImageViewCompat.setImageTintList(recvBubble, ColorStateList.valueOf(ContextCompat.getColor(requireContext(), R.color.conversation_item_wallpaper_bubble_color)));
        } else {
            chatWallpaperPreview.setImageDrawable(null);
            ImageViewCompat.setImageTintList(recvBubble, ColorStateList.valueOf(ContextCompat.getColor(requireContext(), R.color.signal_background_secondary)));
        }
    });
    viewModel.getDimInDarkTheme().observe(getViewLifecycleOwner(), shouldDimInNightMode -> {
        if (shouldDimInNightMode != dimInNightMode.isChecked()) {
            isSettingDimFromViewModel = true;
            dimInNightMode.setChecked(shouldDimInNightMode);
            isSettingDimFromViewModel = false;
        }
        chatWallpaperDim.setAlpha(ChatWallpaper.FIXED_DIM_LEVEL_FOR_DARK_THEME);
        chatWallpaperDim.setVisibility(shouldDimInNightMode && ThemeUtil.isDarkTheme(requireContext()) ? View.VISIBLE : View.GONE);
    });
    viewModel.getEnableWallpaperControls().observe(getViewLifecycleOwner(), enableWallpaperControls -> {
        dimInNightMode.setEnabled(enableWallpaperControls);
        dimInNightMode.setAlpha(enableWallpaperControls ? 1 : 0.5f);
    });
    chatWallpaperPreview.setOnClickListener(unused -> setWallpaper.performClick());
    setWallpaper.setOnClickListener(unused -> SafeNavigation.safeNavigate(Navigation.findNavController(view), R.id.action_chatWallpaperFragment_to_chatWallpaperSelectionFragment));
    setChatColor.setOnClickListener(unused -> SafeNavigation.safeNavigate(Navigation.findNavController(view), ChatWallpaperFragmentDirections.actionChatWallpaperFragmentToChatColorSelectionFragment(viewModel.getRecipientId())));
    if (viewModel.isGlobal()) {
        resetAllWallpaper.setOnClickListener(unused -> {
            new MaterialAlertDialogBuilder(requireContext()).setTitle(R.string.ChatWallpaperFragment__reset_wallpaper).setMessage(R.string.ChatWallpaperFragment__would_you_like_to_override_all_wallpapers).setPositiveButton(R.string.ChatWallpaperFragment__reset_default_wallpaper, (dialog, which) -> {
                viewModel.setWallpaper(null);
                viewModel.setDimInDarkTheme(true);
                viewModel.saveWallpaperSelection();
                dialog.dismiss();
            }).setNegativeButton(R.string.ChatWallpaperFragment__reset_all_wallpapers, (dialog, which) -> {
                viewModel.setWallpaper(null);
                viewModel.setDimInDarkTheme(true);
                viewModel.resetAllWallpaper();
                dialog.dismiss();
            }).setNeutralButton(android.R.string.cancel, (dialog, which) -> {
                dialog.dismiss();
            }).show();
        });
        resetChatColors.setOnClickListener(unused -> {
            new MaterialAlertDialogBuilder(requireContext()).setTitle(R.string.ChatWallpaperFragment__reset_chat_colors).setMessage(R.string.ChatWallpaperFragment__would_you_like_to_override_all_chat_colors).setPositiveButton(R.string.ChatWallpaperFragment__reset_default_colors, (dialog, which) -> {
                viewModel.clearChatColor();
                dialog.dismiss();
            }).setNegativeButton(R.string.ChatWallpaperFragment__reset_all_colors, (dialog, which) -> {
                viewModel.resetAllChatColors();
                dialog.dismiss();
            }).setNeutralButton(android.R.string.cancel, (dialog, which) -> {
                dialog.dismiss();
            }).show();
        });
    } else {
        resetAllWallpaper.setText(R.string.ChatWallpaperFragment__reset_wallpaper);
        resetChatColors.setText(R.string.ChatWallpaperFragment__reset_chat_color);
        resetAllWallpaper.setOnClickListener(unused -> {
            new MaterialAlertDialogBuilder(requireContext()).setMessage(R.string.ChatWallpaperFragment__reset_wallpaper_question).setPositiveButton(R.string.ChatWallpaperFragment__reset, (dialog, which) -> {
                viewModel.setWallpaper(null);
                viewModel.setDimInDarkTheme(true);
                viewModel.saveWallpaperSelection();
                viewModel.refreshChatColors();
            }).setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.dismiss()).show();
        });
        resetChatColors.setOnClickListener(unused -> {
            new MaterialAlertDialogBuilder(requireContext()).setMessage(R.string.ChatWallpaperFragment__reset_chat_color_question).setPositiveButton(R.string.ChatWallpaperFragment__reset, (dialog, which) -> viewModel.clearChatColor()).setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.dismiss()).show();
        });
    }
    dimInNightMode.setOnCheckedChangeListener((buttonView, isChecked) -> {
        if (!isSettingDimFromViewModel) {
            viewModel.setDimInDarkTheme(isChecked);
        }
    });
    viewModel.getCurrentChatColors().observe(getViewLifecycleOwner(), chatColors -> {
        sentBubble.getDrawable().setColorFilter(chatColors.getChatBubbleColorFilter());
        colorizerView.setBackground(chatColors.getChatBubbleMask());
        Projection projection = Projection.relativeToViewWithCommonRoot(sentBubble, colorizerView, new Projection.Corners(ViewUtil.dpToPx(10)));
        colorizerView.setProjections(Collections.singletonList(projection));
        Drawable colorCircle = chatColors.asCircle();
        colorCircle.setBounds(0, 0, ViewUtil.dpToPx(16), ViewUtil.dpToPx(16));
        TextViewCompat.setCompoundDrawablesRelative(setChatColor, null, null, colorCircle, null);
    });
    sentBubble.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> viewModel.refreshChatColors());
}
Also used : TextViewCompat(androidx.core.widget.TextViewCompat) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) ImageView(android.widget.ImageView) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) Drawable(android.graphics.drawable.Drawable) R(org.thoughtcrime.securesms.R) DisplayMetricsUtil(org.thoughtcrime.securesms.util.DisplayMetricsUtil) ColorStateList(android.content.res.ColorStateList) SafeNavigation(org.thoughtcrime.securesms.util.navigation.SafeNavigation) ColorizerView(org.thoughtcrime.securesms.conversation.colors.ColorizerView) Fragment(androidx.fragment.app.Fragment) View(android.view.View) ViewModelProviders(androidx.lifecycle.ViewModelProviders) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView) ContextCompat(androidx.core.content.ContextCompat) SwitchCompat(androidx.appcompat.widget.SwitchCompat) LayoutInflater(android.view.LayoutInflater) ImageViewCompat(androidx.core.widget.ImageViewCompat) DisplayMetrics(android.util.DisplayMetrics) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) ThemeUtil(org.thoughtcrime.securesms.util.ThemeUtil) Toolbar(androidx.appcompat.widget.Toolbar) Navigation(androidx.navigation.Navigation) Projection(org.thoughtcrime.securesms.util.Projection) Collections(java.util.Collections) Drawable(android.graphics.drawable.Drawable) Projection(org.thoughtcrime.securesms.util.Projection) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) ImageView(android.widget.ImageView) ColorizerView(org.thoughtcrime.securesms.conversation.colors.ColorizerView) View(android.view.View) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView) TextView(android.widget.TextView) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) TextView(android.widget.TextView) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) ImageView(android.widget.ImageView) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView) ColorizerView(org.thoughtcrime.securesms.conversation.colors.ColorizerView) Toolbar(androidx.appcompat.widget.Toolbar) SwitchCompat(androidx.appcompat.widget.SwitchCompat)

Example 3 with ColorizerView

use of org.thoughtcrime.securesms.conversation.colors.ColorizerView 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)

Example 4 with ColorizerView

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

the class ChatWallpaperFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    viewModel = ViewModelProviders.of(requireActivity()).get(ChatWallpaperViewModel.class);
    AvatarImageView portrait = view.findViewById(R.id.chat_wallpaper_preview_top_bar_portrait);
    Toolbar toolbar = view.findViewById(R.id.toolbar);
    ImageView chatWallpaperPreview = view.findViewById(R.id.chat_wallpaper_preview_background);
    View setWallpaper = view.findViewById(R.id.chat_wallpaper_set_wallpaper);
    SwitchCompat dimInNightMode = view.findViewById(R.id.chat_wallpaper_dark_theme_dims_wallpaper);
    View chatWallpaperDim = view.findViewById(R.id.chat_wallpaper_dim);
    TextView setChatColor = view.findViewById(R.id.chat_wallpaper_set_chat_color);
    TextView resetChatColors = view.findViewById(R.id.chat_wallpaper_reset_chat_colors);
    ImageView sentBubble = view.findViewById(R.id.chat_wallpaper_preview_bubble_2);
    ColorizerView colorizerView = view.findViewById(R.id.colorizer);
    TextView resetAllWallpaper = view.findViewById(R.id.chat_wallpaper_reset_all_wallpapers);
    AppCompatImageView recvBubble = view.findViewById(R.id.chat_wallpaper_preview_bubble_1);
    toolbar.setTitle(R.string.preferences__chat_color_and_wallpaper);
    toolbar.setNavigationOnClickListener(nav -> {
        if (!Navigation.findNavController(nav).popBackStack()) {
            requireActivity().finish();
        }
    });
    forceAspectRatioToScreenByAdjustingHeight(chatWallpaperPreview);
    viewModel.getWallpaperPreviewPortrait().observe(getViewLifecycleOwner(), wallpaperPreviewPortrait -> wallpaperPreviewPortrait.applyToAvatarImageView(portrait));
    viewModel.getCurrentWallpaper().observe(getViewLifecycleOwner(), wallpaper -> {
        if (wallpaper.isPresent()) {
            wallpaper.get().loadInto(chatWallpaperPreview);
            ImageViewCompat.setImageTintList(recvBubble, ColorStateList.valueOf(ContextCompat.getColor(requireContext(), R.color.conversation_item_wallpaper_bubble_color)));
        } else {
            chatWallpaperPreview.setImageDrawable(null);
            ImageViewCompat.setImageTintList(recvBubble, ColorStateList.valueOf(ContextCompat.getColor(requireContext(), R.color.signal_background_secondary)));
        }
    });
    viewModel.getDimInDarkTheme().observe(getViewLifecycleOwner(), shouldDimInNightMode -> {
        if (shouldDimInNightMode != dimInNightMode.isChecked()) {
            isSettingDimFromViewModel = true;
            dimInNightMode.setChecked(shouldDimInNightMode);
            isSettingDimFromViewModel = false;
        }
        chatWallpaperDim.setAlpha(ChatWallpaper.FIXED_DIM_LEVEL_FOR_DARK_THEME);
        chatWallpaperDim.setVisibility(shouldDimInNightMode && ThemeUtil.isDarkTheme(requireContext()) ? View.VISIBLE : View.GONE);
    });
    viewModel.getEnableWallpaperControls().observe(getViewLifecycleOwner(), enableWallpaperControls -> {
        dimInNightMode.setEnabled(enableWallpaperControls);
        dimInNightMode.setAlpha(enableWallpaperControls ? 1 : 0.5f);
    });
    chatWallpaperPreview.setOnClickListener(unused -> setWallpaper.performClick());
    setWallpaper.setOnClickListener(unused -> SafeNavigation.safeNavigate(Navigation.findNavController(view), R.id.action_chatWallpaperFragment_to_chatWallpaperSelectionFragment));
    setChatColor.setOnClickListener(unused -> SafeNavigation.safeNavigate(Navigation.findNavController(view), ChatWallpaperFragmentDirections.actionChatWallpaperFragmentToChatColorSelectionFragment(viewModel.getRecipientId())));
    if (viewModel.isGlobal()) {
        resetAllWallpaper.setOnClickListener(unused -> {
            new MaterialAlertDialogBuilder(requireContext()).setTitle(R.string.ChatWallpaperFragment__reset_wallpaper).setMessage(R.string.ChatWallpaperFragment__would_you_like_to_override_all_wallpapers).setPositiveButton(R.string.ChatWallpaperFragment__reset_default_wallpaper, (dialog, which) -> {
                viewModel.setWallpaper(null);
                viewModel.setDimInDarkTheme(true);
                viewModel.saveWallpaperSelection();
                dialog.dismiss();
            }).setNegativeButton(R.string.ChatWallpaperFragment__reset_all_wallpapers, (dialog, which) -> {
                viewModel.setWallpaper(null);
                viewModel.setDimInDarkTheme(true);
                viewModel.resetAllWallpaper();
                dialog.dismiss();
            }).setNeutralButton(android.R.string.cancel, (dialog, which) -> {
                dialog.dismiss();
            }).show();
        });
        resetChatColors.setOnClickListener(unused -> {
            new MaterialAlertDialogBuilder(requireContext()).setTitle(R.string.ChatWallpaperFragment__reset_chat_colors).setMessage(R.string.ChatWallpaperFragment__would_you_like_to_override_all_chat_colors).setPositiveButton(R.string.ChatWallpaperFragment__reset_default_colors, (dialog, which) -> {
                viewModel.clearChatColor();
                dialog.dismiss();
            }).setNegativeButton(R.string.ChatWallpaperFragment__reset_all_colors, (dialog, which) -> {
                viewModel.resetAllChatColors();
                dialog.dismiss();
            }).setNeutralButton(android.R.string.cancel, (dialog, which) -> {
                dialog.dismiss();
            }).show();
        });
    } else {
        resetAllWallpaper.setText(R.string.ChatWallpaperFragment__reset_wallpaper);
        resetChatColors.setText(R.string.ChatWallpaperFragment__reset_chat_color);
        resetAllWallpaper.setOnClickListener(unused -> {
            new MaterialAlertDialogBuilder(requireContext()).setMessage(R.string.ChatWallpaperFragment__reset_wallpaper_question).setPositiveButton(R.string.ChatWallpaperFragment__reset, (dialog, which) -> {
                viewModel.setWallpaper(null);
                viewModel.setDimInDarkTheme(true);
                viewModel.saveWallpaperSelection();
                viewModel.refreshChatColors();
            }).setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.dismiss()).show();
        });
        resetChatColors.setOnClickListener(unused -> {
            new MaterialAlertDialogBuilder(requireContext()).setMessage(R.string.ChatWallpaperFragment__reset_chat_color_question).setPositiveButton(R.string.ChatWallpaperFragment__reset, (dialog, which) -> viewModel.clearChatColor()).setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.dismiss()).show();
        });
    }
    dimInNightMode.setOnCheckedChangeListener((buttonView, isChecked) -> {
        if (!isSettingDimFromViewModel) {
            viewModel.setDimInDarkTheme(isChecked);
        }
    });
    viewModel.getCurrentChatColors().observe(getViewLifecycleOwner(), chatColors -> {
        sentBubble.getDrawable().setColorFilter(chatColors.getChatBubbleColorFilter());
        colorizerView.setBackground(chatColors.getChatBubbleMask());
        Projection projection = Projection.relativeToViewWithCommonRoot(sentBubble, colorizerView, new Projection.Corners(ViewUtil.dpToPx(10)));
        colorizerView.setProjections(Collections.singletonList(projection));
        Drawable colorCircle = chatColors.asCircle();
        colorCircle.setBounds(0, 0, ViewUtil.dpToPx(16), ViewUtil.dpToPx(16));
        TextViewCompat.setCompoundDrawablesRelative(setChatColor, null, null, colorCircle, null);
    });
    sentBubble.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> viewModel.refreshChatColors());
}
Also used : TextViewCompat(androidx.core.widget.TextViewCompat) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) ImageView(android.widget.ImageView) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) Drawable(android.graphics.drawable.Drawable) R(org.thoughtcrime.securesms.R) DisplayMetricsUtil(org.thoughtcrime.securesms.util.DisplayMetricsUtil) ColorStateList(android.content.res.ColorStateList) SafeNavigation(org.thoughtcrime.securesms.util.navigation.SafeNavigation) ColorizerView(org.thoughtcrime.securesms.conversation.colors.ColorizerView) Fragment(androidx.fragment.app.Fragment) View(android.view.View) ViewModelProviders(androidx.lifecycle.ViewModelProviders) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView) ContextCompat(androidx.core.content.ContextCompat) SwitchCompat(androidx.appcompat.widget.SwitchCompat) LayoutInflater(android.view.LayoutInflater) ImageViewCompat(androidx.core.widget.ImageViewCompat) DisplayMetrics(android.util.DisplayMetrics) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) ThemeUtil(org.thoughtcrime.securesms.util.ThemeUtil) Toolbar(androidx.appcompat.widget.Toolbar) Navigation(androidx.navigation.Navigation) Projection(org.thoughtcrime.securesms.util.Projection) Collections(java.util.Collections) Drawable(android.graphics.drawable.Drawable) Projection(org.thoughtcrime.securesms.util.Projection) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) ImageView(android.widget.ImageView) ColorizerView(org.thoughtcrime.securesms.conversation.colors.ColorizerView) View(android.view.View) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView) TextView(android.widget.TextView) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) TextView(android.widget.TextView) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) ImageView(android.widget.ImageView) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView) ColorizerView(org.thoughtcrime.securesms.conversation.colors.ColorizerView) Toolbar(androidx.appcompat.widget.Toolbar) SwitchCompat(androidx.appcompat.widget.SwitchCompat)

Example 5 with ColorizerView

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

the class WallpaperCropActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    dynamicTheme.onCreate(this);
    setContentView(R.layout.chat_wallpaper_crop_activity);
    RecipientId recipientId = getIntent().getParcelableExtra(EXTRA_RECIPIENT_ID);
    Uri inputImage = Objects.requireNonNull(getIntent().getParcelableExtra(EXTRA_IMAGE_URI));
    Log.i(TAG, "Cropping wallpaper for " + (recipientId == null ? "default wallpaper" : recipientId));
    WallpaperCropViewModel.Factory factory = new WallpaperCropViewModel.Factory(recipientId);
    viewModel = ViewModelProviders.of(this, factory).get(WallpaperCropViewModel.class);
    imageEditor = findViewById(R.id.image_editor);
    View sentBubble = findViewById(R.id.preview_bubble_2);
    TextView bubble2Text = findViewById(R.id.chat_wallpaper_bubble2_text);
    View setWallPaper = findViewById(R.id.preview_set_wallpaper);
    SwitchCompat blur = findViewById(R.id.preview_blur);
    ColorizerView colorizerView = findViewById(R.id.colorizer);
    setupImageEditor(inputImage);
    setWallPaper.setOnClickListener(v -> setWallpaper());
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar supportActionBar = Objects.requireNonNull(getSupportActionBar());
    supportActionBar.setHomeAsUpIndicator(ContextCompat.getDrawable(this, R.drawable.ic_arrow_left_24));
    supportActionBar.setDisplayHomeAsUpEnabled(true);
    blur.setOnCheckedChangeListener((v, checked) -> viewModel.setBlur(checked));
    viewModel.getBlur().observe(this, blurred -> {
        setBlurred(blurred);
        if (blurred != blur.isChecked()) {
            blur.setChecked(blurred);
        }
    });
    viewModel.getRecipient().observe(this, r -> {
        if (r.getId().isUnknown()) {
            bubble2Text.setText(R.string.WallpaperCropActivity__set_wallpaper_for_all_chats);
        } else {
            bubble2Text.setText(getString(R.string.WallpaperCropActivity__set_wallpaper_for_s, r.getDisplayName(this)));
            sentBubble.getBackground().setColorFilter(r.getChatColors().getChatBubbleColorFilter());
            colorizerView.setBackground(r.getChatColors().getChatBubbleMask());
        }
    });
    sentBubble.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
        colorizerView.setProjections(Collections.singletonList(Projection.relativeToViewWithCommonRoot(sentBubble, colorizerView, new Projection.Corners(ViewUtil.dpToPx(18)))));
    });
}
Also used : RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Projection(org.thoughtcrime.securesms.util.Projection) Uri(android.net.Uri) ColorizerView(org.thoughtcrime.securesms.conversation.colors.ColorizerView) View(android.view.View) ImageEditorView(org.signal.imageeditor.core.ImageEditorView) TextView(android.widget.TextView) TextView(android.widget.TextView) ColorizerView(org.thoughtcrime.securesms.conversation.colors.ColorizerView) ActionBar(androidx.appcompat.app.ActionBar) SwitchCompat(androidx.appcompat.widget.SwitchCompat) Toolbar(androidx.appcompat.widget.Toolbar)

Aggregations

View (android.view.View)6 TextView (android.widget.TextView)6 Toolbar (androidx.appcompat.widget.Toolbar)6 ColorizerView (org.thoughtcrime.securesms.conversation.colors.ColorizerView)6 Projection (org.thoughtcrime.securesms.util.Projection)6 Drawable (android.graphics.drawable.Drawable)4 Bundle (android.os.Bundle)4 NonNull (androidx.annotation.NonNull)4 SwitchCompat (androidx.appcompat.widget.SwitchCompat)4 Collections (java.util.Collections)4 R (org.thoughtcrime.securesms.R)4 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)4 ViewUtil (org.thoughtcrime.securesms.util.ViewUtil)4 Context (android.content.Context)2 Intent (android.content.Intent)2 ColorStateList (android.content.res.ColorStateList)2 Uri (android.net.Uri)2 DisplayMetrics (android.util.DisplayMetrics)2 LayoutInflater (android.view.LayoutInflater)2 ViewGroup (android.view.ViewGroup)2