-
-
Notifications
You must be signed in to change notification settings - Fork 287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add animation support #420
Conversation
import android.graphics.drawable.Drawable; | ||
import android.text.style.DynamicDrawableSpan; | ||
import android.util.Log; | ||
|
||
import com.vanniktech.emoji.emoji.Emoji; | ||
|
||
final class EmojiSpan extends DynamicDrawableSpan { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of extending this span, we want a special Span
implementation for animations I think. Drawing the animation ourselfs on the Canvas
is hard.
final Bitmap strip = loadStrip(context); | ||
final Bitmap cut = Bitmap.createBitmap(strip, 1, y * SPRITE_SIZE_INC_BORDER + 1, SPRITE_SIZE, SPRITE_SIZE); | ||
BITMAP_CACHE.put(key, cut); | ||
return new BitmapDrawable(context.getResources(), cut); | ||
} | ||
|
||
@Override @NonNull public AnimationDrawable getAnimatedDrawable(final Context context) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could just reuse the getDrawable
method and decide there if we want an animated one. This way no change to the existing interface is necessary (the boolean would also not be necessary). Calling code could check if the returned Drawable
is an AnimatedDrawable
to decide what to do.
return animationDrawable; | ||
} | ||
|
||
private Bitmap[] loadAnimatedStrip(Bitmap bitmap) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think https://developer.android.com/reference/android/graphics/drawable/AnimatedVectorDrawable or some gif implementation is a more performant solution instead of loading each bitmap individually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rubengees I was thinking of using AnimatedImageDrawable: https://developer.android.com/reference/android/graphics/drawable/AnimatedImageDrawable
It allows for using GIF files directly using an ImageView. However, it requires API Version 28
which is fairly new, is this an option?
Sorry, can someone clarify to me what is this PR about and why do we need animation support? (Granted I do want to add stickers/etc support, but this can't interfere with the Emojis code) |
@mario Well, you kind of said it yourself, gif animation stickers are certainly of interest to be supported. Since I am using this project and I wanted to add gif support for stickers etc. I was thinking of implementing it in here directly. About the emojis code, I plan to make it in a way that the emojis code is not being touched and simply add to the current implementation a custom implementation for gif animations which can be added individually on a manual basis. |
How I envision this to be implemented is by extending the emoji core with minimal support for animated content (most likely by a custom Users would then implement their own category returning objects of the new |
Yes, the way @rubengees outlined sounds like a good way of implementation without touching the emojis core, so I was planning on performing only extensions of the core which do not interfere with the current implementation. @rubengees you suggested using a gif implementation, so I found this here: https://developer.android.com/reference/android/graphics/drawable/AnimatedImageDrawable |
Sorry for the delay @BennieBe - are you still interested in working on this? |
@mario I currently have a project where this might be useful so yes I am still willing to work on this |
@mario Can you please tell me if it is alright to use AnimatedImageDrawable? https://developer.android.com/reference/android/graphics/drawable/AnimatedImageDrawable |
@BennieBe I would use AnimatedImageDrawable for 28+ and https://github.com/koral--/android-gif-drawable for 17-27. This lib currently supports 15 and 16 as well, but I think it's safe to simply not have support for animations/gifs in case you're on such low API levels. |
Like @rubengees and you agreed earlier, please try to keep existing interface changes to minimum where possible. |
@mario this looks good to me thanks, I will try to keep interface changes to a minimum |
If we require a third party lib we should create a new module. |
@vanniktech This means that I can open up a new project and integrate into the existing project, correct? |
@BennieBe it's basically like we have: emoji-google, emoji-twitter, emoji-*. That's how you should do it. |
|
What's the progress here? |
I'm closing this issue due to inactivity. If you have any further input on the PR, don't hesitate to reopen this PR or post a new one. |
I have added methods to allow for either returning a bitmap or an animated bitmap if isAnimated boolean is true. I created a new Category with the Flag symbol and used one of the sprite sheets already existing in order to do the testing (in the app itself the chosen category is the last in the line of category icons, you can see two flags at the end, it is the last flag). I was planning to use the same method that the current long sprite sheets use to display all images, just that instead of showing all these bitmaps separately, I combine all bitmaps into one animation to be played when selected. You can find this in the loadAnimatedStrip method. In order to create an animation I use the existing loadStrip method to create a sequence of bitmaps using AnimationDrawable object. The animation played for me when I tried starting the method in loadAnimatedStrip directly, however, it does not animate when I try to start the animation in drawAnimation method. This is where I get stuck and I cannot find why it does not work. I would appreciate if someone can have a short look and give me some hints on what might be going wrong! ;)