animate emoji
This commit is contained in:
parent
92b3a6d3cb
commit
3c31939498
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
|
@ -77,6 +77,7 @@ import app.fedilab.android.activities.ShowAccountActivity;
|
|||
import app.fedilab.android.asynctasks.RetrieveFeedsAsyncTask;
|
||||
import app.fedilab.android.asynctasks.UpdateAccountInfoAsyncTask;
|
||||
import app.fedilab.android.helper.CrossActions;
|
||||
import app.fedilab.android.helper.EmojiDrawableSpan;
|
||||
import app.fedilab.android.helper.Helper;
|
||||
import app.fedilab.android.interfaces.OnRetrieveEmojiInterface;
|
||||
import app.fedilab.android.interfaces.OnRetrieveImageInterface;
|
||||
|
@ -1089,11 +1090,11 @@ public class Status implements Parcelable{
|
|||
final int[] i = {0};
|
||||
for (final Emojis emoji : emojis) {
|
||||
Glide.with(context)
|
||||
// .asDrawable()
|
||||
.asFile()
|
||||
.load(emoji.getUrl())
|
||||
.listener(new RequestListener<Drawable>() {
|
||||
.listener(new RequestListener<File>() {
|
||||
@Override
|
||||
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
|
||||
public boolean onResourceReady(File resource, Object model, Target<File> target, DataSource dataSource, boolean isFirstResource) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1106,17 +1107,19 @@ public class Status implements Parcelable{
|
|||
return false;
|
||||
}
|
||||
})
|
||||
.into(new SimpleTarget<Drawable>() {
|
||||
.into(new SimpleTarget<File>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
||||
public void onResourceReady(@NonNull File resource, @Nullable Transition<? super File> transition) {
|
||||
AssetStreamLoader assetLoader = new AssetStreamLoader(context, "test.png");
|
||||
APNGDrawable apngDrawable = APNGDrawable.fromFile(resource.getPath());
|
||||
final String targetedEmoji = ":" + emoji.getShortcode() + ":";
|
||||
if (contentSpan != null && contentSpan.toString().contains(targetedEmoji)) {
|
||||
//emojis can be used several times so we have to loop
|
||||
for (int startPosition = -1; (startPosition = contentSpan.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) {
|
||||
final int endPosition = startPosition + targetedEmoji.length();
|
||||
if( endPosition <= contentSpan.toString().length() && endPosition >= startPosition) {
|
||||
resource.setBounds(0,0,(int) Helper.convertDpToPixel(20, context),(int) Helper.convertDpToPixel(20, context));
|
||||
ImageSpan imageSpan = new ImageSpan(resource, ImageSpan.ALIGN_BASELINE);
|
||||
//resource.setBounds(0,0,(int) Helper.convertDpToPixel(20, context),(int) Helper.convertDpToPixel(20, context));
|
||||
EmojiDrawableSpan imageSpan = new EmojiDrawableSpan(context,apngDrawable);
|
||||
contentSpan.setSpan(
|
||||
imageSpan, startPosition,
|
||||
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
|
@ -1128,8 +1131,7 @@ public class Status implements Parcelable{
|
|||
for (int startPosition = -1; (startPosition = displayNameSpan.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) {
|
||||
final int endPosition = startPosition + targetedEmoji.length();
|
||||
if(endPosition <= displayNameSpan.toString().length() && endPosition >= startPosition) {
|
||||
resource.setBounds(0,0,(int) Helper.convertDpToPixel(20, context),(int) Helper.convertDpToPixel(20, context));
|
||||
ImageSpan imageSpan = new ImageSpan(resource, ImageSpan.ALIGN_BASELINE);
|
||||
EmojiDrawableSpan imageSpan = new EmojiDrawableSpan(context,apngDrawable);
|
||||
displayNameSpan.setSpan(
|
||||
imageSpan, startPosition,
|
||||
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
|
@ -1142,8 +1144,7 @@ public class Status implements Parcelable{
|
|||
for (int startPosition = -1; (startPosition = contentSpanCW.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) {
|
||||
final int endPosition = startPosition + targetedEmoji.length();
|
||||
if( endPosition <= contentSpanCW.toString().length() && endPosition >= startPosition) {
|
||||
resource.setBounds(0,0,(int) Helper.convertDpToPixel(20, context),(int) Helper.convertDpToPixel(20, context));
|
||||
ImageSpan imageSpan = new ImageSpan(resource, ImageSpan.ALIGN_BASELINE);
|
||||
EmojiDrawableSpan imageSpan = new EmojiDrawableSpan(context,apngDrawable);
|
||||
contentSpanCW.setSpan(
|
||||
imageSpan, startPosition,
|
||||
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
|
@ -1160,6 +1161,8 @@ public class Status implements Parcelable{
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package app.fedilab.android.helper;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.style.DynamicDrawableSpan;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.DrawableRes;
|
||||
import com.github.pengfeizhou.animation.apng.APNGDrawable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EmojiDrawableSpan extends DynamicDrawableSpan {
|
||||
|
||||
|
||||
private APNGDrawable mDrawable;
|
||||
private int size;
|
||||
public EmojiDrawableSpan(Context context, APNGDrawable apngDrawable) {
|
||||
mDrawable = apngDrawable;
|
||||
size = (int) Helper.convertDpToPixel(20, context);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Drawable getDrawable() {
|
||||
return mDrawable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(@NotNull Canvas canvas, CharSequence text,
|
||||
int start, int end, float x,
|
||||
int top, int y, int bottom, @NotNull Paint paint) {
|
||||
Drawable b = mDrawable;
|
||||
canvas.save();
|
||||
int transY = bottom - b.getBounds().bottom;
|
||||
canvas.translate(x, transY);
|
||||
|
||||
mDrawable.setBounds(0, 0, size, size);
|
||||
b.draw(canvas);
|
||||
canvas.restore();
|
||||
mDrawable.start();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue