From 1d3e53a00175fc639cd2323effa40a50f2fb8c0f Mon Sep 17 00:00:00 2001 From: tom79 Date: Thu, 25 Jul 2019 17:20:04 +0200 Subject: [PATCH] Gif --- app/build.gradle | 1 - .../android/client/Entities/Status.java | 53 ++++++------------- 2 files changed, 16 insertions(+), 38 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 37a9ead8b..37e6f83e6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -121,7 +121,6 @@ dependencies { implementation "ch.acra:acra-notification:$acraVersion" implementation 'com.github.stom79:Android-WYSIWYG-Editor:3.2.1' implementation 'com.github.duanhong169:colorpicker:1.1.6' - implementation 'com.linecorp:apng:1.6.0' implementation 'com.github.pengfeizhou.android.animation:awebp:0.2.16' implementation 'com.github.pengfeizhou.android.animation:apng:0.2.16' diff --git a/app/src/main/java/app/fedilab/android/client/Entities/Status.java b/app/src/main/java/app/fedilab/android/client/Entities/Status.java index 91478f004..53143ada5 100644 --- a/app/src/main/java/app/fedilab/android/client/Entities/Status.java +++ b/app/src/main/java/app/fedilab/android/client/Entities/Status.java @@ -52,11 +52,11 @@ import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.target.SimpleTarget; import com.bumptech.glide.request.target.Target; import com.bumptech.glide.request.transition.Transition; -import com.linecorp.apng.ApngDrawable; -import com.linecorp.apng.decoder.ApngException; +import com.github.pengfeizhou.animation.apng.APNGDrawable; +import com.github.pengfeizhou.animation.loader.AssetStreamLoader; +import com.github.pengfeizhou.animation.loader.StreamLoader; import java.io.File; -import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; @@ -1089,13 +1089,14 @@ public class Status implements Parcelable{ final int[] i = {0}; for (final Emojis emoji : emojis) { Glide.with(context) - .asFile() + .asDrawable() .load(emoji.getUrl()) - .listener(new RequestListener() { + .listener(new RequestListener() { @Override - public boolean onResourceReady(File resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { + public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { return false; } + @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { i[0]++; @@ -1105,45 +1106,20 @@ public class Status implements Parcelable{ return false; } }) - .into(new SimpleTarget() { + .into(new SimpleTarget() { @Override - public void onResourceReady(@NonNull File resource, @Nullable Transition transition) { - - ApngDrawable emojo = null; - Drawable emojoD = null; - - if( ApngDrawable.Companion.isApng(resource)){ - try { - emojo = ApngDrawable.Companion.decode(resource,(int) Helper.convertDpToPixel(20, context),(int) Helper.convertDpToPixel(20, context)); - Log.v(Helper.TAG,"frame count " + emojo.getFrameCount()); - emojo.setLoopCount(ApngDrawable.LOOP_FOREVER); - emojo.start(); - - } catch (ApngException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - }else{ - emojoD = Drawable.createFromPath(resource.getAbsolutePath()); - assert emojoD != null; - emojoD.setBounds(0, 0, (int) Helper.convertDpToPixel(20, context), (int) Helper.convertDpToPixel(20, context)); - } - Log.v(Helper.TAG,"-> " + ApngDrawable.Companion.isApng(resource)); + public void onResourceReady(@NonNull Drawable resource, @Nullable Transition transition) { 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) { - - ImageSpan imageSpan = new ImageSpan(emojo!=null?emojo:emojoD); + resource.setBounds(0,0,(int) Helper.convertDpToPixel(20, context),(int) Helper.convertDpToPixel(20, context)); + ImageSpan imageSpan = new ImageSpan(resource, ImageSpan.ALIGN_BASELINE); contentSpan.setSpan( imageSpan, startPosition, endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); - if (emojo != null) { - emojo.start(); - } } } } @@ -1152,7 +1128,8 @@ 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) { - ImageSpan imageSpan = new ImageSpan(emojo!=null?emojo:emojoD, ImageSpan.ALIGN_BASELINE); + resource.setBounds(0,0,(int) Helper.convertDpToPixel(20, context),(int) Helper.convertDpToPixel(20, context)); + ImageSpan imageSpan = new ImageSpan(resource, ImageSpan.ALIGN_BASELINE); displayNameSpan.setSpan( imageSpan, startPosition, endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); @@ -1165,7 +1142,8 @@ 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) { - ImageSpan imageSpan = new ImageSpan(emojo!=null?emojo:emojoD, ImageSpan.ALIGN_BASELINE); + resource.setBounds(0,0,(int) Helper.convertDpToPixel(20, context),(int) Helper.convertDpToPixel(20, context)); + ImageSpan imageSpan = new ImageSpan(resource, ImageSpan.ALIGN_BASELINE); contentSpanCW.setSpan( imageSpan, startPosition, endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); @@ -1181,6 +1159,7 @@ public class Status implements Parcelable{ } } + }); }