Skip to content

Commit

Permalink
Merge pull request #3 from lgvalle/reveal-animation
Browse files Browse the repository at this point in the history
Add reveal animation for API > 21
  • Loading branch information
MiguelCatalan committed Oct 25, 2015
2 parents 16da0fe + 5918a9b commit 781ceb4
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -495,25 +495,8 @@ public void showSearch(boolean animate) {
mSearchSrcTextView.requestFocus();

if (animate) {
AnimationUtil.fadeInView(mSearchLayout, AnimationUtil.ANIMATION_DURATION_MEDIUM, new AnimationUtil.AnimationListener() {
@Override
public boolean onAnimationStart(View view) {
return false;
}

@Override
public boolean onAnimationEnd(View view) {
if (mSearchViewListener != null) {
mSearchViewListener.onSearchViewShown();
}
return false;
}
setVisibleWithAnimation();

@Override
public boolean onAnimationCancel(View view) {
return false;
}
});
} else {
mSearchLayout.setVisibility(VISIBLE);
if (mSearchViewListener != null) {
Expand All @@ -523,6 +506,36 @@ public boolean onAnimationCancel(View view) {
mIsSearchOpen = true;
}

private void setVisibleWithAnimation() {
AnimationUtil.AnimationListener animationListener = new AnimationUtil.AnimationListener() {
@Override
public boolean onAnimationStart(View view) {
return false;
}

@Override
public boolean onAnimationEnd(View view) {
if (mSearchViewListener != null) {
mSearchViewListener.onSearchViewShown();
}
return false;
}

@Override
public boolean onAnimationCancel(View view) {
return false;
}
};

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mSearchLayout.setVisibility(View.VISIBLE);
AnimationUtil.reveal(mSearchTopBar, AnimationUtil.ANIMATION_DURATION_MEDIUM, animationListener);

} else {
AnimationUtil.fadeInView(mSearchLayout, AnimationUtil.ANIMATION_DURATION_MEDIUM, animationListener);
}
}

/**
* Close search view.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package com.miguelcatalan.materialsearchview.utils;

import android.animation.Animator;
import android.annotation.TargetApi;
import android.os.Build;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPropertyAnimatorListener;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.animation.DecelerateInterpolator;

/**
* @author Miguel Catalan Bañuls
Expand Down Expand Up @@ -75,6 +80,42 @@ public void onAnimationCancel(View view) {
ViewCompat.animate(view).alpha(1f).setDuration(duration).setListener(vpListener);
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void reveal(final View view, int animationDuration, final AnimationListener listener) {
View viewRoot = view;
int cx = (viewRoot.getRight());
int cy = (viewRoot.getTop() + viewRoot.getBottom()) / 2;
int finalRadius = Math.max(viewRoot.getWidth(), viewRoot.getHeight());

Animator anim = ViewAnimationUtils.createCircularReveal(viewRoot, cx, cy, 0, finalRadius);
viewRoot.setVisibility(View.VISIBLE);

anim.setDuration(animationDuration);
anim.setInterpolator(new DecelerateInterpolator());
anim.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
listener.onAnimationStart(view);
}

@Override
public void onAnimationEnd(Animator animation) {
listener.onAnimationEnd(view);
}

@Override
public void onAnimationCancel(Animator animation) {
listener.onAnimationCancel(view);
}

@Override
public void onAnimationRepeat(Animator animation) {

}
});
anim.start();
}

public static void fadeOutView(View view) {
fadeOutView(view, ANIMATION_DURATION_SHORT);
}
Expand Down

0 comments on commit 781ceb4

Please sign in to comment.