JoanZapata / android-iconify

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

Support for spinning icons? #56

Closed rampatra closed 10 years ago

rampatra commented 10 years ago

I was wondering how do i use spinning icons.

I tried with {fa-spinner fa-spin} and {fa-spinner} {fa-spin} but none of them worked.

So, am I going wrong somewhere or iconify doesn't support spinning icons?

bryancallahan commented 10 years ago

I don't believe it is supported just yet. I agree it would be great for feature parity. :)

rampatra commented 10 years ago

Cool! Will wait for it :+1:

mikepenz commented 10 years ago

I don't think this can be done with the current implementation.

If someone got an idea how to implement such behavior please submit a pull-request.

guilhermesgb commented 9 years ago

So it seems it eventually got implemented (as per the README.md). So I was wondering: Is it possible to make an IconDrawable spin (programatically)?

JoanZapata commented 9 years ago

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.

I'm opening a new issue for this.

guilhermesgb commented 9 years ago

That's great, man. And thanks for the response!

I don't really know the inner workings of rendering drawables, but maybe there's another approach that could work. If there's a way to force a drawable to be rendered continuously while it is within viewport bounds, maybe you could keep state on it's current rotation and on every draw step, increase it just a bit before rendering it. Then I'd try evolving from there (so that the rotation is smooth / not dependent on the "clock"/draw steps / happening at a stable pace).

JoanZapata commented 9 years ago

That's actually how {fa-cog spin} works inside an IconTextView. It's continuously invalidated and redrawn, and stops when the IconTextView is detached from the window.

But I don't think there's a way to know when a Drawable is not anymore displayed on the screen, so there's no way no know when to stop continuously rendering it. If it's attached to an ImageView then it depends on this ImageView, but a Drawable can be used (and reused) in many other ways.

What is your usecase? ImageView?

guilhermesgb commented 9 years ago

I understand… thanks. Yeah, it's tricky if it depends heavily on where the Drawable's used. I'm using it alongside/attached to an EditText, as its drawableEnd drawable. On Aug 20, 2015 12:46 PM, "Joan Zapata" notifications@github.com wrote:

That's actually how {fa-cog spin} works inside a IconTextView. It's continuously invalidated and redrawn, and stops when the IconTextView is detached from the window.

But I don't think there's a way to know when a Drawable is not anymore displayed on the screen, so there's no way no know when to stop continuously rendering it. If it's attached to an ImageView then it depends on this ImageView, but a Drawable can be used (and reused) in many other ways.

What is your usecase? ImageView?

— Reply to this email directly or view it on GitHub https://github.com/JoanZapata/android-iconify/issues/56#issuecomment-133056620 .

JoanZapata commented 9 years ago

Can't you just use IconEditText and put {fa-something spin} at the end of the text?

guilhermesgb commented 9 years ago

Yeah, that's the other approach I considered taking but was too lazy to go ahead and build it myself last night, as I think I'd have to perform a major copy-and-pasting of the EditText's source and have this new class extend IconTextView, and I really hate copy-and-pasting. I couldn't think of a better approach for building it but maybe later I could sit down and start learning from IconTextView and make a new class that simply extends EditText and then does the same things that IconTextView does.

(And I actually don't need a spinning IconDrawable - I'm just experimenting with this library to see how powerful it just for curiosity's sake right now, I plan on using it in future projects. Thanks for this, it's really convenient!)

EDIT: Oops, just noticed it's rather easy to implement IconEditText by extending EditText. Almost just a matter of overriding setText.

@Override
public void setText(CharSequence text, BufferType type) {
    super.setText(Iconify.compute(getContext(), text, this), type);
}

I'm sorry for being so lazy and actually not reading through IconTextView's source until now. :( I was thinking that maybe it could be a good PR in the future but... not really haha

JoanZapata commented 9 years ago

Oh my bad, I just realized you were talking about an EditText and not a TextView! There's actually a convenient lib based on Iconify which does just that! https://github.com/DayS/EnhancedEditText/

guilhermesgb commented 9 years ago

That's cool, and thanks for referring me to that library! In the meanwhile I attempted building IconEditText. That approach I mentioned above works great (spinning doesn't work maybe EditText doesn't allow the invalidation approach) unless you want to apply icons to hint's as well (my case). Unfortunatelly setHint is final and thus cannot be overriden.

I need that because I want to use EditText in conjunction with TextInputLayout. Apparently it's not supported by EnhancedEditText as well, at least from what I could tell by quickly skimming through the source. So that's potentially a cool PR I could try sending them, thanks! :)

ghost commented 8 years ago

@JoanZapata can I change spinning speed?