Skip to content

Commit

Permalink
Added curved translation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaouan committed Aug 2, 2016
1 parent a79f9f8 commit 6ef004c
Show file tree
Hide file tree
Showing 9 changed files with 468 additions and 278 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Android Revealator
An helper to circle reveal/unreveal a view easily, with translations and childs animations.
The libraries is Android 15+ compatible.

![demo](art/demo1.gif) ![demo](art/demo2.gif)
![demo](art/demo1.gif) ![demo](art/demo2.gif) ![demo](art/demo3.gif)

Installation
--------
Expand All @@ -17,7 +17,7 @@ repositories {
```

```java
compile 'com.github.jaouan:revealator:1.0.0'
compile 'com.github.jaouan:revealator:1.1.0'
```

Usage
Expand Down Expand Up @@ -52,6 +52,7 @@ Just put the view you want to animate in a `io.codetail.widget.RevealFrameLayout
```java
Revealator.reveal( theAwesomeViewYouWantToReveal )
.from( theInitiatorViewYouWantToTranslate )
.withCurvedTranslation()
.withChildsAnimation()
//.withDelayBetweenChildAnimation(...)
//.withChildAnimationDuration(...)
Expand All @@ -65,6 +66,7 @@ Revealator.reveal( theAwesomeViewYouWantToReveal )
```java
Revealator.unreveal( theAwesomeViewYouWantToUnreveal )
.to( theInitiatorViewYouWantToTranslateBack )
.withCurvedTranslation()
//.withUnrevealDuration(...)
//.withTranslateDuration(...)
//.withEndAction(...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ protected void onCreate(Bundle savedInstanceState) {
public void onClick(View view) {
Revealator.reveal(theAwesomeView)
.from(fab)
.withCurvedTranslation()
.withChildsAnimation()
//.withDelayBetweenChildAnimation(...)
//.withChildAnimationDuration(...)
Expand All @@ -47,8 +48,9 @@ public void onClick(View view) {
public void onClick(View view) {
Revealator.unreveal(theAwesomeView)
.to(fab)
//.withUnrevealDuration(...)
//.withTranslateDuration(...)
.withCurvedTranslation()
// .withUnrevealDuration(...)
// .withTranslateDuration(...)
.withEndAction(new Runnable() {
@Override
public void run() {
Expand Down
Binary file added art/demo3.gif
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 revealator/src/main/java/com/jaouan/revealator/RevealBuilder.java
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();
}
}
}
);
}
}
Loading

0 comments on commit 6ef004c

Please sign in to comment.