Skip to content

Commit

Permalink
Updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ajalt committed Apr 24, 2015
1 parent 34b9821 commit 726f7e9
Showing 1 changed file with 37 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,25 @@ public interface AnimationSeriesListener {
private Map<String, AnimationSection> mSectionsById;

/**
* Create a new instance and automatically set animations as the background of the given view.
*
* @param view If not null, animations will be set as the background of this view.
*/
public MultiStateAnimation(View view) {
mSectionsById = new HashMap<String, AnimationSection>();
mView = view;
}

/**
* Create an instance without giving a view to hold the animations.
* <p/>
* Note that due to a limitation in AnimationDrawable, you must set
* created animations as the image or background of a View in an
* onAnimationStarting listener, otherwise the animation will not
* advance.
*
* @see com.getkeepsafe.android.multistateanimation.MultiStateAnimation.AnimationSeriesListener#onAnimationStarting()
*/
public MultiStateAnimation() {
this(null);
}
Expand All @@ -228,6 +240,7 @@ private static String[] jsonArrayToArray(JSONArray jsonArray) throws JSONExcepti

/**
* Creates a new MultiStateAnimation object from a json string.
* <p/>
* The document must have the following structure:
* <pre>
* {
Expand Down Expand Up @@ -264,15 +277,19 @@ private static String[] jsonArrayToArray(JSONArray jsonArray) throws JSONExcepti
* }
* </pre>
* The key for each entry is the ID of the state.
* If "oneshot" is false, the animation will play in a loop instead of stopping at the last
* frame.
* "frame_duration" is the number of milliseconds that each frame in the "frame" list will play.
* It defaults to 33 if not given.
* "frames" is a list of string resource ID names that must correspond to a drawable resource.
* "transitions_from" is optional, and is a set of animations that play when transitioning to
* <dl>
* <dt>"oneshot"</dt>
* <dd>If false, the animation will play in a loop instead of stopping at the last
* frame.</dd>
* <dt>"frame_duration"</dt><dd>The number of milliseconds that each frame in the "frame"
* list will play. It defaults to 33 (30fps) if not given.</dd>
* <dt>"frames"</dt><dd>A list of string resource ID names that must correspond to a
* drawable resource.</dd>
* <dt>"transitions_from"</dt><dd>Optional, and is a set of animations that play when transitioning to
* the current state from another given state. A transition will play when the ID of the
* current state matches the transition's key and the state is transitioning to the state
* in which the transition is defined.
* in which the transition is defined.</dd>
* </dl>
*
* @param context The application Context.
* @param view If not null, animations will be set as the background of this view.
Expand Down Expand Up @@ -378,7 +395,8 @@ public int currentSectionDuration() {
}

/**
* Returns the currently playing animation, or null if no animation has ever played.
* Returns the currently playing animation. If no animation has played since this object was
* created or since a call to {@link #clearAnimation()}, null is returned.
*/
public AnimationDrawable getCurrentDrawable() {
return mCurrentDrawable;
Expand All @@ -392,8 +410,8 @@ public String getCurrentSectionId() {
}

/**
* If the currently playing animation is a transition, return the ID if the
* section that this is transitioning from. Otherwise return null.
* If the currently playing animation is a transition, return the ID of the
* section that is being transitioned from. Otherwise return null.
*/
public String getTransitioningFromId() {
return mTransitioningFromId;
Expand Down Expand Up @@ -425,8 +443,10 @@ private void playDrawable(NotifyingAnimationDrawable drawable) {

/**
* Queues a section to start as soon as the current animation finishes.
* If no animation is playing, the queued animation will be started immediately
* if it is not the current animation.
* If no animation is playing, the queued animation will be started immediately.
* Queueing a transition to the currently playing section has no effect.
*
* @param id The name of the section that will be queued.
*/
public void queueTransition(String id) {
if (id.equals(getCurrentSectionId())) return;
Expand All @@ -442,8 +462,11 @@ public void queueTransition(String id) {

/**
* Starts a specific section without waiting for the current animation to finish.
* If the last registered animation is currently playing, or no animations have been
* registered, no action is taken.
* If there is a defined transition from the current section to the new one, the
* transition will be played, followed immediately by the regular section animation.
* Transitioning to the currently playing section will restart the animation.
*
* @param id The name of the section that will be played.
*/
public void transitionNow(String id) {
AnimationSection newSection = mSectionsById.get(id);
Expand Down

0 comments on commit 726f7e9

Please sign in to comment.