Search in sources :

Example 6 with ColorizerView

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

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