Search in sources :

Example 6 with SimpleAnimatorListener

use of com.hippo.yorozuya.SimpleAnimatorListener in project EhViewer by seven332.

the class FabLayout method setSecondaryFabAnimation.

private void setSecondaryFabAnimation(final View child, final boolean expanded, boolean delay) {
    float startTranslationY;
    float endTranslationY;
    float startAlpha;
    float endAlpha;
    Interpolator interpolator;
    if (expanded) {
        startTranslationY = mMainFabCenterY - (child.getTop() + (child.getHeight() / 2));
        endTranslationY = 0f;
        startAlpha = 0f;
        endAlpha = 1f;
        interpolator = AnimationUtils.FAST_SLOW_INTERPOLATOR;
    } else {
        startTranslationY = 0f;
        endTranslationY = mMainFabCenterY - (child.getTop() + (child.getHeight() / 2));
        startAlpha = 1f;
        endAlpha = 0f;
        interpolator = AnimationUtils.SLOW_FAST_INTERPOLATOR;
    }
    child.setAlpha(startAlpha);
    child.setTranslationY(startTranslationY);
    child.animate().alpha(endAlpha).translationY(endTranslationY).setStartDelay(delay ? ANIMATE_TIME : 0L).setDuration(ANIMATE_TIME).setInterpolator(interpolator).setListener(new SimpleAnimatorListener() {

        @Override
        public void onAnimationStart(Animator animation) {
            if (expanded) {
                child.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            if (!expanded) {
                child.setVisibility(View.INVISIBLE);
            }
        }
    }).start();
}
Also used : Animator(android.animation.Animator) Interpolator(android.view.animation.Interpolator) SimpleAnimatorListener(com.hippo.yorozuya.SimpleAnimatorListener)

Example 7 with SimpleAnimatorListener

use of com.hippo.yorozuya.SimpleAnimatorListener in project EhViewer by seven332.

the class SearchBarMover method returnSearchBarPosition.

@SuppressWarnings("SimplifiableIfStatement")
public void returnSearchBarPosition(boolean animation) {
    if (mSearchBar.getHeight() == 0) {
        // Layout not called
        return;
    }
    boolean show;
    if (mHelper.forceShowSearchBar()) {
        show = true;
    } else {
        RecyclerView recyclerView = mHelper.getValidRecyclerView();
        if (recyclerView == null) {
            return;
        }
        if (!recyclerView.isShown()) {
            show = true;
        } else if (recyclerView.computeVerticalScrollOffset() < mSearchBar.getBottom()) {
            show = true;
        } else {
            show = (int) ViewUtils.getY2(mSearchBar) > (mSearchBar.getHeight()) / 2;
        }
    }
    int offset;
    if (show) {
        offset = -(int) mSearchBar.getTranslationY();
    } else {
        offset = -(int) ViewUtils.getY2(mSearchBar);
    }
    if (offset == 0) {
        // No need to scroll
        return;
    }
    if (animation) {
        if (mSearchBarMoveAnimator != null) {
            if (mShow == show) {
                // The same target, no need to do animation
                return;
            } else {
                // Cancel it
                mSearchBarMoveAnimator.cancel();
                mSearchBarMoveAnimator = null;
            }
        }
        mShow = show;
        final ValueAnimator va = ValueAnimator.ofInt(0, offset);
        va.setDuration(ANIMATE_TIME);
        va.addListener(new SimpleAnimatorListener() {

            @Override
            public void onAnimationEnd(Animator animation) {
                mSearchBarMoveAnimator = null;
            }
        });
        va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            int lastValue;

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                int value = (Integer) animation.getAnimatedValue();
                int offsetStep = value - lastValue;
                lastValue = value;
                ViewUtils.translationYBy(mSearchBar, offsetStep);
            }
        });
        mSearchBarMoveAnimator = va;
        va.start();
    } else {
        if (mSearchBarMoveAnimator != null) {
            mSearchBarMoveAnimator.cancel();
        }
        ViewUtils.translationYBy(mSearchBar, offset);
    }
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) RecyclerView(androidx.recyclerview.widget.RecyclerView) SimpleAnimatorListener(com.hippo.yorozuya.SimpleAnimatorListener) ValueAnimator(android.animation.ValueAnimator)

Example 8 with SimpleAnimatorListener

use of com.hippo.yorozuya.SimpleAnimatorListener in project EhViewer by seven332.

the class SearchBarMover method showSearchBar.

public void showSearchBar(boolean animation) {
    if (mSearchBar.getHeight() == 0) {
        // Layout not called
        return;
    }
    final int offset = -(int) mSearchBar.getTranslationY();
    if (offset == 0) {
        // No need to scroll
        return;
    }
    if (animation) {
        if (mSearchBarMoveAnimator != null) {
            if (mShow) {
                // The same target, no need to do animation
                return;
            } else {
                // Cancel it
                mSearchBarMoveAnimator.cancel();
                mSearchBarMoveAnimator = null;
            }
        }
        mShow = true;
        final ValueAnimator va = ValueAnimator.ofInt(0, offset);
        va.setDuration(ANIMATE_TIME);
        va.addListener(new SimpleAnimatorListener() {

            @Override
            public void onAnimationEnd(Animator animation) {
                mSearchBarMoveAnimator = null;
            }
        });
        va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            int lastValue;

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                int value = (Integer) animation.getAnimatedValue();
                int offsetStep = value - lastValue;
                lastValue = value;
                ViewUtils.translationYBy(mSearchBar, offsetStep);
            }
        });
        mSearchBarMoveAnimator = va;
        va.start();
    } else {
        if (mSearchBarMoveAnimator != null) {
            mSearchBarMoveAnimator.cancel();
        }
        ViewUtils.translationYBy(mSearchBar, offset);
    }
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) SimpleAnimatorListener(com.hippo.yorozuya.SimpleAnimatorListener) ValueAnimator(android.animation.ValueAnimator)

Example 9 with SimpleAnimatorListener

use of com.hippo.yorozuya.SimpleAnimatorListener in project EhViewer by seven332.

the class SearchBar method showImeAndSuggestionsList.

public void showImeAndSuggestionsList(boolean animation) {
    // Show ime
    InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(mEditText, 0);
    // update suggestion for show suggestions list
    updateSuggestions();
    // Show suggestions list
    if (animation) {
        ObjectAnimator oa = ObjectAnimator.ofFloat(this, "progress", 1f);
        oa.setDuration(ANIMATE_TIME);
        oa.setInterpolator(AnimationUtils.FAST_SLOW_INTERPOLATOR);
        oa.addListener(new SimpleAnimatorListener() {

            @Override
            public void onAnimationStart(Animator animation) {
                mListContainer.setVisibility(View.VISIBLE);
                mInAnimation = true;
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                mInAnimation = false;
            }
        });
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            oa.setAutoCancel(true);
        }
        oa.start();
    } else {
        mListContainer.setVisibility(View.VISIBLE);
        setProgress(1f);
    }
}
Also used : Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ObjectAnimator(android.animation.ObjectAnimator) InputMethodManager(android.view.inputmethod.InputMethodManager) SimpleAnimatorListener(com.hippo.yorozuya.SimpleAnimatorListener)

Aggregations

Animator (android.animation.Animator)9 SimpleAnimatorListener (com.hippo.yorozuya.SimpleAnimatorListener)9 ObjectAnimator (android.animation.ObjectAnimator)3 ValueAnimator (android.animation.ValueAnimator)2 SuppressLint (android.annotation.SuppressLint)2 Interpolator (android.view.animation.Interpolator)2 InputMethodManager (android.view.inputmethod.InputMethodManager)2 DefaultItemAnimator (androidx.recyclerview.widget.DefaultItemAnimator)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 EasyRecyclerView (com.hippo.easyrecyclerview.EasyRecyclerView)1 LinkifyTextView (com.hippo.widget.LinkifyTextView)1 ObservedTextView (com.hippo.widget.ObservedTextView)1