use of org.thoughtcrime.securesms.components.emoji.EmojiTextView in project Signal-Android by WhisperSystems.
the class LongMessageFragment method initViewModel.
private void initViewModel(long messageId, boolean isMms) {
viewModel = new ViewModelProvider(this, new LongMessageViewModel.Factory(requireActivity().getApplication(), new LongMessageRepository(), messageId, isMms)).get(LongMessageViewModel.class);
viewModel.getMessage().observe(this, message -> {
if (message == null)
return;
if (!message.isPresent()) {
Toast.makeText(requireContext(), R.string.LongMessageActivity_unable_to_find_message, Toast.LENGTH_SHORT).show();
dismissAllowingStateLoss();
return;
}
if (message.get().getMessageRecord().isOutgoing()) {
toolbar.setTitle(getString(R.string.LongMessageActivity_your_message));
} else {
Recipient recipient = message.get().getMessageRecord().getRecipient();
String name = recipient.getDisplayName(requireContext());
toolbar.setTitle(getString(R.string.LongMessageActivity_message_from_s, name));
}
ViewGroup bubble;
if (message.get().getMessageRecord().isOutgoing()) {
bubble = sentBubble.get();
colorizerView.setVisibility(View.VISIBLE);
colorizerView.setBackground(message.get().getMessageRecord().getRecipient().getChatColors().getChatBubbleMask());
bubble.getBackground().setColorFilter(message.get().getMessageRecord().getRecipient().getChatColors().getChatBubbleColorFilter());
bubble.addOnLayoutChangeListener(bubbleLayoutListener);
bubbleLayoutListener.onLayoutChange(bubble, 0, 0, 0, 0, 0, 0, 0, 0);
} else {
bubble = receivedBubble.get();
bubble.getBackground().setColorFilter(ContextCompat.getColor(requireContext(), R.color.signal_background_secondary), PorterDuff.Mode.MULTIPLY);
}
EmojiTextView text = bubble.findViewById(R.id.longmessage_text);
ConversationItemFooter footer = bubble.findViewById(R.id.longmessage_footer);
CharSequence trimmedBody = getTrimmedBody(message.get().getFullBody(requireContext()));
SpannableString styledBody = linkifyMessageBody(new SpannableString(trimmedBody));
bubble.setVisibility(View.VISIBLE);
text.setText(styledBody);
text.setMovementMethod(LinkMovementMethod.getInstance());
text.setTextSize(TypedValue.COMPLEX_UNIT_SP, SignalStore.settings().getMessageFontSize());
if (!message.get().getMessageRecord().isOutgoing()) {
text.setMentionBackgroundTint(ContextCompat.getColor(requireContext(), ThemeUtil.isDarkTheme(requireActivity()) ? R.color.core_grey_60 : R.color.core_grey_20));
} else {
text.setMentionBackgroundTint(ContextCompat.getColor(requireContext(), R.color.transparent_black_40));
}
footer.setMessageRecord(message.get().getMessageRecord(), Locale.getDefault());
});
}
use of org.thoughtcrime.securesms.components.emoji.EmojiTextView 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));
}
use of org.thoughtcrime.securesms.components.emoji.EmojiTextView in project Signal-Android by WhisperSystems.
the class GroupDescriptionUtil method setText.
/**
* Set a group description.
*
* @param description full description
* @param emojiTextView Text view to update with description
* @param linkify flag indicating if web urls should be linkified
* @param moreClick Callback for when truncating and need to show more via another means. Required to enable truncating.
*/
public static void setText(@NonNull Context context, @NonNull EmojiTextView emojiTextView, @NonNull String description, boolean linkify, @Nullable Runnable moreClick) {
boolean shouldEllipsize = moreClick != null;
String scrubbedDescription = shouldEllipsize ? description.replaceAll("\\n", " ") : description;
SpannableString descriptionSpannable = new SpannableString(scrubbedDescription);
if (linkify) {
int linkPattern = Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES | Linkify.PHONE_NUMBERS;
boolean hasLinks = LinkifyCompat.addLinks(descriptionSpannable, linkPattern);
if (hasLinks) {
Stream.of(descriptionSpannable.getSpans(0, descriptionSpannable.length(), URLSpan.class)).filterNot(url -> LinkPreviewUtil.isLegalUrl(url.getURL())).forEach(descriptionSpannable::removeSpan);
URLSpan[] urlSpans = descriptionSpannable.getSpans(0, descriptionSpannable.length(), URLSpan.class);
for (URLSpan urlSpan : urlSpans) {
int start = descriptionSpannable.getSpanStart(urlSpan);
int end = descriptionSpannable.getSpanEnd(urlSpan);
URLSpan span = new LongClickCopySpan(urlSpan.getURL());
descriptionSpannable.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
}
if (shouldEllipsize) {
ClickableSpan style = new ClickableSpan() {
@Override
public void onClick(@NonNull View widget) {
moreClick.run();
}
@Override
public void updateDrawState(@NonNull TextPaint ds) {
ds.setTypeface(Typeface.DEFAULT_BOLD);
}
};
emojiTextView.setEllipsize(TextUtils.TruncateAt.END);
emojiTextView.setMaxLines(2);
SpannableString overflowText = new SpannableString(context.getString(R.string.ManageGroupActivity_more));
overflowText.setSpan(style, 0, overflowText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
emojiTextView.setOverflowText(overflowText);
}
emojiTextView.setText(descriptionSpannable);
}
use of org.thoughtcrime.securesms.components.emoji.EmojiTextView in project Signal-Android by signalapp.
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));
}
use of org.thoughtcrime.securesms.components.emoji.EmojiTextView in project Signal-Android by signalapp.
the class GroupDescriptionUtil method setText.
/**
* Set a group description.
*
* @param description full description
* @param emojiTextView Text view to update with description
* @param linkify flag indicating if web urls should be linkified
* @param moreClick Callback for when truncating and need to show more via another means. Required to enable truncating.
*/
public static void setText(@NonNull Context context, @NonNull EmojiTextView emojiTextView, @NonNull String description, boolean linkify, @Nullable Runnable moreClick) {
boolean shouldEllipsize = moreClick != null;
String scrubbedDescription = shouldEllipsize ? description.replaceAll("\\n", " ") : description;
SpannableString descriptionSpannable = new SpannableString(scrubbedDescription);
if (linkify) {
int linkPattern = Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES | Linkify.PHONE_NUMBERS;
boolean hasLinks = LinkifyCompat.addLinks(descriptionSpannable, linkPattern);
if (hasLinks) {
Stream.of(descriptionSpannable.getSpans(0, descriptionSpannable.length(), URLSpan.class)).filterNot(url -> LinkPreviewUtil.isLegalUrl(url.getURL())).forEach(descriptionSpannable::removeSpan);
URLSpan[] urlSpans = descriptionSpannable.getSpans(0, descriptionSpannable.length(), URLSpan.class);
for (URLSpan urlSpan : urlSpans) {
int start = descriptionSpannable.getSpanStart(urlSpan);
int end = descriptionSpannable.getSpanEnd(urlSpan);
URLSpan span = new LongClickCopySpan(urlSpan.getURL());
descriptionSpannable.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
}
if (shouldEllipsize) {
ClickableSpan style = new ClickableSpan() {
@Override
public void onClick(@NonNull View widget) {
moreClick.run();
}
@Override
public void updateDrawState(@NonNull TextPaint ds) {
ds.setTypeface(Typeface.DEFAULT_BOLD);
}
};
emojiTextView.setEllipsize(TextUtils.TruncateAt.END);
emojiTextView.setMaxLines(2);
SpannableString overflowText = new SpannableString(context.getString(R.string.ManageGroupActivity_more));
overflowText.setSpan(style, 0, overflowText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
emojiTextView.setOverflowText(overflowText);
}
emojiTextView.setText(descriptionSpannable);
}
Aggregations