diff --git a/library/src/main/java/com/miguelcatalan/materialsearchview/MaterialSearchView.java b/library/src/main/java/com/miguelcatalan/materialsearchview/MaterialSearchView.java index f7fdc6e..e8aa0a9 100644 --- a/library/src/main/java/com/miguelcatalan/materialsearchview/MaterialSearchView.java +++ b/library/src/main/java/com/miguelcatalan/materialsearchview/MaterialSearchView.java @@ -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) { @@ -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. */ diff --git a/library/src/main/java/com/miguelcatalan/materialsearchview/utils/AnimationUtil.java b/library/src/main/java/com/miguelcatalan/materialsearchview/utils/AnimationUtil.java index d07f0ad..16e8807 100644 --- a/library/src/main/java/com/miguelcatalan/materialsearchview/utils/AnimationUtil.java +++ b/library/src/main/java/com/miguelcatalan/materialsearchview/utils/AnimationUtil.java @@ -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 @@ -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); }