3

I've noticed that animateOpen(), animateClose() and animateToggle() are doing the same function, meaning that any one of them can replace the others.
The only difference that I noticed was that the speed of the animation varies from one method to the other as follows:

  1. animateOpen(), the animation while opening is faster than the animation while closing.
  2. animateClose(), the animation while closing is faster than the animation while opening.
  3. animateToggle(), both speeds are equal.

So, my question is:
Am I missing something? or do I just have to check isOpened() before using any of them?

I'm asking this question because my problem raised when I wrote animateClose() somewhere, thinking that if the sliding drawer is already closed then no action will be taken, but I found out that it behaves exactly the same as animateToggle().

Adinia
  • 3,722
  • 5
  • 40
  • 58
a fair player
  • 11,530
  • 9
  • 46
  • 48

2 Answers2

1

animateOpen, animateclose and animateToggle public methods will make the slide open,close or toggle with animaiton respectively. The methods have to be compared with open, close which will open and close the slider without animation. The speed of animation should not change in default implementation.

Alessandro Minoccheri
  • 35,521
  • 22
  • 122
  • 171
1

Confirmed, on two different devices.

  • animateClose() called on a drawer that is already closed will sometimes animate the drawer to opened.
  • animateOpen() called on a drawer that is already opened will always (?) animate the drawer to closed.

The immediate functions (close and open) seem to work as you would expect.

Given this, I would suggest subclassing the SlidingDrawer and overriding the 5 methods that open or close the drawer. Using a few member variable booleans, you should be able to determine the real state of the drawer and call (or not call) the appropriate superclass method, updating your state accordingly.

(It might also be necessary to implement the OnDrawerXxxListeners to keep your state correct; my drawer is only opened and closed programmatically, not using the "handle", so I didn't test that.)

Edit to add: The nice thing about doing this is that you can add an isOpening() and isClosing() based on your subclass's state plus the existing isMoving() method.

benkc
  • 3,292
  • 1
  • 28
  • 37