Search in sources :

Example 1 with ViewPropertyAnimatorUpdateListener

use of android.support.v4.view.ViewPropertyAnimatorUpdateListener in project Android-MaterialRefreshLayout by android-cjj.

the class MaterialRefreshLayout method createAnimatorTranslationY.

//    public void setProgressValue(int progressValue) {
//        this.progressValue = progressValue;
//        mMaterialHeaderView.setProgressValue(progressValue);
//    }
public void createAnimatorTranslationY(final View v, final float h, final FrameLayout fl) {
    ViewPropertyAnimatorCompat viewPropertyAnimatorCompat = ViewCompat.animate(v);
    viewPropertyAnimatorCompat.setDuration(250);
    viewPropertyAnimatorCompat.setInterpolator(new DecelerateInterpolator());
    viewPropertyAnimatorCompat.translationY(h);
    viewPropertyAnimatorCompat.start();
    viewPropertyAnimatorCompat.setUpdateListener(new ViewPropertyAnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(View view) {
            float height = ViewCompat.getTranslationY(v);
            fl.getLayoutParams().height = (int) height;
            fl.requestLayout();
        }
    });
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) ViewPropertyAnimatorUpdateListener(android.support.v4.view.ViewPropertyAnimatorUpdateListener) ViewPropertyAnimatorCompat(android.support.v4.view.ViewPropertyAnimatorCompat) AbsListView(android.widget.AbsListView) View(android.view.View)

Example 2 with ViewPropertyAnimatorUpdateListener

use of android.support.v4.view.ViewPropertyAnimatorUpdateListener in project floatingsearchview by arimorty.

the class FloatingSearchView method updateSuggestionsSectionHeight.

private void updateSuggestionsSectionHeight(List<? extends SearchSuggestion> newSearchSuggestions, boolean withAnim) {
    final int cardTopBottomShadowPadding = Util.dpToPx(CARD_VIEW_CORNERS_AND_TOP_BOTTOM_SHADOW_HEIGHT);
    final int cardRadiusSize = Util.dpToPx(CARD_VIEW_TOP_BOTTOM_SHADOW_HEIGHT);
    int visibleSuggestionHeight = calculateSuggestionItemsHeight(newSearchSuggestions, mSuggestionListContainer.getHeight());
    int diff = mSuggestionListContainer.getHeight() - visibleSuggestionHeight;
    int addedTranslationYForShadowOffsets = (diff <= cardTopBottomShadowPadding) ? -(cardTopBottomShadowPadding - diff) : diff < (mSuggestionListContainer.getHeight() - cardTopBottomShadowPadding) ? cardRadiusSize : 0;
    final float newTranslationY = -mSuggestionListContainer.getHeight() + visibleSuggestionHeight + addedTranslationYForShadowOffsets;
    final boolean animateAtEnd = newTranslationY >= mSuggestionListContainer.getTranslationY();
    //todo go over
    final float fullyInvisibleTranslationY = -mSuggestionListContainer.getHeight() + cardRadiusSize;
    ViewCompat.animate(mSuggestionListContainer).cancel();
    if (withAnim) {
        ViewCompat.animate(mSuggestionListContainer).setInterpolator(SUGGEST_ITEM_ADD_ANIM_INTERPOLATOR).setDuration(mSuggestionSectionAnimDuration).translationY(newTranslationY).setUpdateListener(new ViewPropertyAnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(View view) {
                if (mOnSuggestionsListHeightChanged != null) {
                    float newSuggestionsHeight = Math.abs(view.getTranslationY() - fullyInvisibleTranslationY);
                    mOnSuggestionsListHeightChanged.onSuggestionsListHeightChanged(newSuggestionsHeight);
                }
            }
        }).setListener(new ViewPropertyAnimatorListenerAdapter() {

            @Override
            public void onAnimationCancel(View view) {
                mSuggestionListContainer.setTranslationY(newTranslationY);
            }

            @Override
            public void onAnimationStart(View view) {
                if (!animateAtEnd) {
                    mSuggestionsList.smoothScrollToPosition(0);
                }
            }

            @Override
            public void onAnimationEnd(View view) {
                if (animateAtEnd) {
                    int lastPos = mSuggestionsList.getAdapter().getItemCount() - 1;
                    if (lastPos > -1) {
                        mSuggestionsList.smoothScrollToPosition(lastPos);
                    }
                }
            }
        }).start();
    } else {
        mSuggestionListContainer.setTranslationY(newTranslationY);
        if (mOnSuggestionsListHeightChanged != null) {
            float newSuggestionsHeight = Math.abs(mSuggestionListContainer.getTranslationY() - fullyInvisibleTranslationY);
            mOnSuggestionsListHeightChanged.onSuggestionsListHeightChanged(newSuggestionsHeight);
        }
    }
}
Also used : ViewPropertyAnimatorUpdateListener(android.support.v4.view.ViewPropertyAnimatorUpdateListener) ViewPropertyAnimatorListenerAdapter(android.support.v4.view.ViewPropertyAnimatorListenerAdapter) ImageView(android.widget.ImageView) MenuView(com.arlib.floatingsearchview.util.view.MenuView) View(android.view.View) CardView(android.support.v7.widget.CardView) SearchInputView(com.arlib.floatingsearchview.util.view.SearchInputView) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView)

Example 3 with ViewPropertyAnimatorUpdateListener

use of android.support.v4.view.ViewPropertyAnimatorUpdateListener in project NavigationTabBar by Devlight.

the class NavigationTabBarBehavior method ensureOrCancelAnimator.

// Manage animation for Android >= KITKAT
private void ensureOrCancelAnimator(final NavigationTabBar child, boolean withAnimation) {
    if (mTranslationAnimator == null) {
        mTranslationAnimator = ViewCompat.animate(child);
        mTranslationAnimator.setDuration(withAnimation ? ANIMATION_DURATION : 0);
        mTranslationAnimator.setUpdateListener(new ViewPropertyAnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(View view) {
                // Animate snack bar
                if (mSnackBarLayout != null && mSnackBarLayout.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
                    mTargetOffset = child.getBarHeight() - view.getTranslationY();
                    final ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) mSnackBarLayout.getLayoutParams();
                    p.setMargins(p.leftMargin, p.topMargin, p.rightMargin, (int) mTargetOffset);
                    mSnackBarLayout.requestLayout();
                }
                // Animate Floating Action Button
                if (mFloatingActionButton != null && mFloatingActionButton.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
                    final ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) mFloatingActionButton.getLayoutParams();
                    mFabTargetOffset = mFabDefaultBottomMargin - view.getTranslationY();
                    p.setMargins(p.leftMargin, p.topMargin, p.rightMargin, (int) mFabTargetOffset);
                    mFloatingActionButton.requestLayout();
                }
            }
        });
        mTranslationAnimator.setInterpolator(INTERPOLATOR);
    } else {
        mTranslationAnimator.setDuration(withAnimation ? ANIMATION_DURATION : 0);
        mTranslationAnimator.cancel();
    }
}
Also used : ViewPropertyAnimatorUpdateListener(android.support.v4.view.ViewPropertyAnimatorUpdateListener) ViewGroup(android.view.ViewGroup) View(android.view.View)

Example 4 with ViewPropertyAnimatorUpdateListener

use of android.support.v4.view.ViewPropertyAnimatorUpdateListener in project ahbottomnavigation by aurelhubert.

the class AHBottomNavigationBehavior method ensureOrCancelAnimator.

/**
	 * Manage animation for Android >= KITKAT
	 *
	 * @param child
	 */
private void ensureOrCancelAnimator(V child, boolean withAnimation) {
    if (translationAnimator == null) {
        translationAnimator = ViewCompat.animate(child);
        translationAnimator.setDuration(withAnimation ? ANIM_DURATION : 0);
        translationAnimator.setUpdateListener(new ViewPropertyAnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(View view) {
                if (navigationPositionListener != null) {
                    navigationPositionListener.onPositionChange((int) (view.getMeasuredHeight() - view.getTranslationY() + snackBarY));
                }
            }
        });
        translationAnimator.setInterpolator(INTERPOLATOR);
    } else {
        translationAnimator.setDuration(withAnimation ? ANIM_DURATION : 0);
        translationAnimator.cancel();
    }
}
Also used : ViewPropertyAnimatorUpdateListener(android.support.v4.view.ViewPropertyAnimatorUpdateListener) View(android.view.View)

Aggregations

ViewPropertyAnimatorUpdateListener (android.support.v4.view.ViewPropertyAnimatorUpdateListener)4 View (android.view.View)4 ViewPropertyAnimatorCompat (android.support.v4.view.ViewPropertyAnimatorCompat)1 ViewPropertyAnimatorListenerAdapter (android.support.v4.view.ViewPropertyAnimatorListenerAdapter)1 CardView (android.support.v7.widget.CardView)1 RecyclerView (android.support.v7.widget.RecyclerView)1 ViewGroup (android.view.ViewGroup)1 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)1 AbsListView (android.widget.AbsListView)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 MenuView (com.arlib.floatingsearchview.util.view.MenuView)1 SearchInputView (com.arlib.floatingsearchview.util.view.SearchInputView)1