-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
468 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
166 changes: 166 additions & 0 deletions
166
revealator/src/main/java/com/jaouan/revealator/RevealBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
package com.jaouan.revealator; | ||
|
||
import android.support.annotation.NonNull; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Revealator "reveal" builder. | ||
*/ | ||
public class RevealBuilder { | ||
|
||
private View mViewToReveal; | ||
|
||
private View mFromView; | ||
|
||
private int mTranslateDuration = 250; | ||
|
||
private int mRevealDuration = 250; | ||
|
||
private boolean mChildsAnimation = false; | ||
|
||
private long mChildAnimationDuration = 500; | ||
|
||
private int mDelayBetweenChildAnimation = 50; | ||
|
||
private boolean mCurvedTranslation = false; | ||
|
||
private Runnable mEndAction; | ||
|
||
/** | ||
* Reveal builder's contructor. | ||
* | ||
* @param viewToReveal View to reveal. | ||
*/ | ||
RevealBuilder(@NonNull final View viewToReveal) { | ||
this.mViewToReveal = viewToReveal; | ||
} | ||
|
||
/** | ||
* Defines reveal duration. | ||
* | ||
* @param revealDuration Reveal duration. | ||
* @return Builder. | ||
*/ | ||
public RevealBuilder withRevealDuration(final int revealDuration) { | ||
this.mRevealDuration = revealDuration; | ||
return this; | ||
} | ||
|
||
/** | ||
* Defines translate duration. | ||
* | ||
* @param translateDuration Translate duration. | ||
* @return Builder. | ||
*/ | ||
public RevealBuilder withTranslateDuration(final int translateDuration) { | ||
this.mTranslateDuration = translateDuration; | ||
return this; | ||
} | ||
|
||
/** | ||
* Defines that childs should be animated after reveal. | ||
* | ||
* @return Builder. | ||
*/ | ||
public RevealBuilder withChildsAnimation() { | ||
this.mChildsAnimation = mViewToReveal instanceof ViewGroup; | ||
return this; | ||
} | ||
|
||
/** | ||
* Defines that translation must be curved. | ||
* | ||
* @return Builder. | ||
*/ | ||
public RevealBuilder withCurvedTranslation() { | ||
this.mCurvedTranslation = true; | ||
return this; | ||
} | ||
|
||
/** | ||
* Defines by child animation duration. | ||
* | ||
* @param childAnimationDuration Child animation duration. | ||
* @return Builder. | ||
*/ | ||
public RevealBuilder withChildAnimationDuration(final int childAnimationDuration) { | ||
this.mChildAnimationDuration = childAnimationDuration; | ||
return this; | ||
} | ||
|
||
/** | ||
* Defines delay between child animation. | ||
* | ||
* @param delayBetweenChildAnimation Delay between child animation. | ||
* @return Builder. | ||
*/ | ||
public RevealBuilder withDelayBetweenChildAnimation(final int delayBetweenChildAnimation) { | ||
this.mDelayBetweenChildAnimation = delayBetweenChildAnimation; | ||
return this; | ||
} | ||
|
||
/** | ||
* Defines the view to translate to the view to reveal. | ||
* | ||
* @param fromView View to translate to the view to reveal. | ||
* @return Builder. | ||
*/ | ||
public RevealBuilder from(@NonNull final View fromView) { | ||
this.mFromView = fromView; | ||
return this; | ||
} | ||
|
||
/** | ||
* Defines end action callback. | ||
* | ||
* @param endAction End action callback. | ||
* @return Builder. | ||
*/ | ||
public RevealBuilder withEndAction(@NonNull final Runnable endAction) { | ||
this.mEndAction = endAction; | ||
return this; | ||
} | ||
|
||
/** | ||
* Let's animate ! | ||
*/ | ||
public void start() { | ||
// - Make view to reveal invisible. | ||
mViewToReveal.setVisibility(View.INVISIBLE); | ||
|
||
// - If from view exists, translate and hide the "from view" and delay reveal animation. | ||
int revealStartDelay = 0; | ||
if (this.mFromView != null) { | ||
RevealatorHelper.translateAndHideView(this.mFromView, this.mViewToReveal, this.mTranslateDuration, this.mCurvedTranslation); | ||
revealStartDelay = (int) (this.mTranslateDuration * 0.9f); | ||
} | ||
|
||
// - Find and hide all childs if necessary. | ||
final List<View> ordoredChildsViews = new ArrayList<>(); | ||
if (this.mChildsAnimation) { | ||
RevealatorHelper.findAllVisibleChilds((ViewGroup) this.mViewToReveal, ordoredChildsViews); | ||
for (final View childView : ordoredChildsViews) { | ||
childView.setVisibility(View.INVISIBLE); | ||
} | ||
} | ||
|
||
// - Reveal the view ! | ||
RevealatorHelper.revealView(mViewToReveal, revealStartDelay, this.mRevealDuration, new Runnable() { | ||
@Override | ||
public void run() { | ||
// - Show childs view if necessary. | ||
RevealatorHelper.orderedShowViews(ordoredChildsViews, mChildAnimationDuration, mDelayBetweenChildAnimation); | ||
|
||
// - Fire end action if necessary. | ||
if (mEndAction != null) { | ||
mEndAction.run(); | ||
} | ||
} | ||
} | ||
); | ||
} | ||
} |
Oops, something went wrong.