JoanZapata / android-iconify

Android integration of multiple icon providers such as FontAwesome, Entypo, Typicons,...
http://joanzapata.com/android-iconify
Other
3.93k stars 526 forks source link

Spin an IconDrawable #107

Closed JoanZapata closed 9 years ago

JoanZapata commented 9 years ago

See #56:

@guilhermesgb Is it possible to make an IconDrawable spin (programatically)?

@joanzapata Spin only works in IconTextView, IconButton and IconToggleButton for now. I guess it wouldn't be very complicated to make a SpinningIconDrawable, but I'm concerned about memory leaks: I'm not sure a Drawable can know when it's not displayed anymore, so the refresh-loop wouldn't know when to stop. Could be based on the context, but that's not accurate. I'll see what I can do.

guilhermesgb commented 9 years ago

I still think this would be useful (as in convenient) but definitely something that we can live by without.

+1

ch-muhammad-adil commented 9 years ago

I am using IconTextView

< com.joanzapata.iconify.widget.IconTextView ... android:text="{fa-cog spin}" .../>

spin isn't working . :(

JoanZapata commented 9 years ago

@ch-muhammad-adil It has nothing to do with IconDrawable. Please open a separate issue and specify which version of Iconify you're using.

JoanZapata commented 9 years ago

This won't be fixed, as discussed in #56, a drawable can be used in many ways and spinning requires to regularly invalidate the drawable until the target view is detached. Detecting the fact that the view is detached is difficult and any mistake would create a memory leak.

Workarounds Consider using an IconTextView. If used on ImageView, use an animation to rotate the ImageView. If used elsewhere or rendered directly, progressively rotate the Canvas before drawing the Drawable would achieve the spinning effect.

ch-muhammad-adil commented 9 years ago

ok thank you . I will manage it.

Regards, Muhammad Adil

On Tue, Sep 1, 2015 at 1:00 PM, Joan Zapata notifications@github.com wrote:

Closed #107 https://github.com/JoanZapata/android-iconify/issues/107.

— Reply to this email directly or view it on GitHub https://github.com/JoanZapata/android-iconify/issues/107#event-397499662 .

1zaman commented 8 years ago

@JoanZapata: Drawable animations don't leak anything, because they depends on the draw() callback instead of using a global scheduler (just like view animations). If a view is detached then it's no longer being drawn, and thus it's animation cycle is automatically stopped (including drawables).

For an example of drawable rotate animation, you can check out the hidden AnimatedRotateDrawable implementation from the framework. EDIT: Looking at the source, it seems like AnimatedRotateDrawable does leak the view and run the animation indefinitely. However, it looks like AnimatedVectorDrawable implements this properly.

Note that the same thing could be done with CustomTypefaceSpan as well, but it would need to be understood that the text holds a reference to the view. Alternatively, you could use the built-in OnAttachStateChangeListener instead of the custom HasOnViewAttachListener to allow animation on the standard platform widgets if the minimum API level is >= Honeycomb MR 1.

1zaman commented 8 years ago

I added support for spin animation in IconDrawable in #134.