Skip to content

Commit

Permalink
Use custom emoji for avatars.
Browse files Browse the repository at this point in the history
  • Loading branch information
greyson-signal committed Jul 26, 2021
1 parent d0827eb commit 7e4396a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
Expand Up @@ -30,6 +30,7 @@ class TextAvatarDrawable(
textView.text = avatar.text
textView.gravity = Gravity.CENTER
textView.setTextColor(if (inverted) avatar.color.backgroundColor else avatar.color.foregroundColor)
textView.setForceCustomEmoji(true)

layout.addView(textView)

Expand Down
Expand Up @@ -33,10 +33,10 @@
public class EmojiTextView extends AppCompatTextView {

private final boolean scaleEmojis;
private final boolean forceCustom;

private static final char ELLIPSIS = '…';

private boolean forceCustom;
private CharSequence previousText;
private BufferType previousBufferType;
private float originalFontSize;
Expand Down Expand Up @@ -144,6 +144,13 @@ public void setOverflowText(@Nullable CharSequence overflowText) {
setText(previousText, BufferType.SPANNABLE);
}

public void setForceCustomEmoji(boolean forceCustom) {
if (this.forceCustom != forceCustom) {
this.forceCustom = forceCustom;
setText(previousText, BufferType.SPANNABLE);
}
}

private void ellipsizeAnyTextForMaxLength() {
if (maxLength > 0 && getText().length() > maxLength + 1) {
SpannableStringBuilder newContent = new SpannableStringBuilder();
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/avatar_picker_fragment.xml
Expand Up @@ -37,6 +37,7 @@
app:layout_constraintEnd_toEndOf="@id/avatar_picker_item_image"
app:layout_constraintStart_toStartOf="@id/avatar_picker_item_image"
app:layout_constraintTop_toTopOf="@id/avatar_picker_item_image"
app:emoji_forceCustom="true"
tools:ignore="SpUsage"
tools:text="AF" />

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/avatar_picker_item.xml
Expand Up @@ -22,7 +22,8 @@
android:layout_height="match_parent"
android:fontFamily="sans-serif-medium"
android:gravity="center"
tools:text="AF" />
tools:text="AF"
app:emoji_forceCustom="true"/>

<View
android:id="@+id/avatar_picker_item_fader"
Expand Down
Expand Up @@ -39,6 +39,7 @@
app:layout_constraintEnd_toEndOf="@id/avatar_picker_item_image"
app:layout_constraintStart_toStartOf="@id/avatar_picker_item_image"
app:layout_constraintTop_toTopOf="@id/avatar_picker_item_image"
app:emoji_forceCustom="true"
tools:ignore="SpUsage"
tools:text="AF" />
</androidx.constraintlayout.widget.ConstraintLayout>
Expand Down

0 comments on commit 7e4396a

Please sign in to comment.