Some tries
This commit is contained in:
parent
0bdee201e7
commit
3b15c34e18
|
@ -4,10 +4,10 @@ import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.drawable.Animatable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
import android.text.style.ReplacementSpan;
|
import android.text.style.ReplacementSpan;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
@ -18,6 +18,7 @@ import com.bumptech.glide.Glide;
|
||||||
import com.bumptech.glide.request.target.CustomTarget;
|
import com.bumptech.glide.request.target.CustomTarget;
|
||||||
import com.bumptech.glide.request.target.Target;
|
import com.bumptech.glide.request.target.Target;
|
||||||
import com.bumptech.glide.request.transition.Transition;
|
import com.bumptech.glide.request.transition.Transition;
|
||||||
|
import com.github.penfeizhou.animation.apng.APNGDrawable;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -62,7 +63,6 @@ public class CustomEmoji extends ReplacementSpan {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSize(@NonNull Paint paint, CharSequence charSequence, int i, int i1, @Nullable Paint.FontMetricsInt fontMetricsInt) {
|
public int getSize(@NonNull Paint paint, CharSequence charSequence, int i, int i1, @Nullable Paint.FontMetricsInt fontMetricsInt) {
|
||||||
Log.v(Helper.TAG, "fontMetricsInt: " + fontMetricsInt);
|
|
||||||
if (fontMetricsInt != null) {
|
if (fontMetricsInt != null) {
|
||||||
Paint.FontMetrics fontMetrics = paint.getFontMetrics();
|
Paint.FontMetrics fontMetrics = paint.getFontMetrics();
|
||||||
fontMetricsInt.top = (int) fontMetrics.top;
|
fontMetricsInt.top = (int) fontMetrics.top;
|
||||||
|
@ -75,18 +75,15 @@ public class CustomEmoji extends ReplacementSpan {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(@NonNull Canvas canvas, CharSequence charSequence, int start, int end, float x, int top, int y, int bottom, @NonNull Paint paint) {
|
public void draw(@NonNull Canvas canvas, CharSequence charSequence, int start, int end, float x, int top, int y, int bottom, @NonNull Paint paint) {
|
||||||
|
|
||||||
if (imageDrawable != null) {
|
if (imageDrawable != null) {
|
||||||
canvas.save();
|
canvas.save();
|
||||||
int emojiSize = (int) (paint.getTextSize() * scale);
|
int emojiSize = (int) (paint.getTextSize() * scale);
|
||||||
Drawable drawable = imageDrawable;
|
Drawable drawable = imageDrawable;
|
||||||
drawable.setBounds(0, 0, emojiSize, emojiSize);
|
drawable.setBounds(0, 0, emojiSize, emojiSize);
|
||||||
int transY = bottom - drawable.getBounds().bottom;
|
int transY = bottom - drawable.getBounds().bottom;
|
||||||
Log.v(Helper.TAG, "transY: " + transY);
|
|
||||||
transY -= paint.getFontMetrics().descent / 2;
|
transY -= paint.getFontMetrics().descent / 2;
|
||||||
Log.v(Helper.TAG, "transY: " + transY);
|
|
||||||
canvas.translate(x, (float) transY);
|
canvas.translate(x, (float) transY);
|
||||||
Log.v(Helper.TAG, "x: " + x);
|
|
||||||
drawable.draw(canvas);
|
drawable.draw(canvas);
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
}
|
}
|
||||||
|
@ -96,7 +93,7 @@ public class CustomEmoji extends ReplacementSpan {
|
||||||
return new CustomTarget<Drawable>() {
|
return new CustomTarget<Drawable>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
||||||
if (animate) {
|
if (animate && resource instanceof Animatable) {
|
||||||
Drawable.Callback callback = resource.getCallback();
|
Drawable.Callback callback = resource.getCallback();
|
||||||
resource.setCallback(new Drawable.Callback() {
|
resource.setCallback(new Drawable.Callback() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -115,10 +112,10 @@ public class CustomEmoji extends ReplacementSpan {
|
||||||
callback.unscheduleDrawable(drawable, runnable);
|
callback.unscheduleDrawable(drawable, runnable);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
((APNGDrawable) resource).start();
|
||||||
|
imageDrawable = resource;
|
||||||
|
view.invalidate();
|
||||||
}
|
}
|
||||||
Log.v(Helper.TAG, "imageDrawable2: " + imageDrawable);
|
|
||||||
imageDrawable = resource;
|
|
||||||
view.invalidate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue