Example usage for android.animation ValueAnimator addListener

List of usage examples for android.animation ValueAnimator addListener

Introduction

In this page you can find the example usage for android.animation ValueAnimator addListener.

Prototype

public void addListener(AnimatorListener listener) 

Source Link

Document

Adds a listener to the set of listeners that are sent events through the life of an animation, such as start, repeat, and end.

Usage

From source file:com.arksh.summer.ui.zone.widget.ExpandableTextView.java

/**
 * /*from  w  w w.  j  ava2  s .c om*/
 * @param view
 */
@Override
public void onClick(View view) {
    if (mTvExpandCollapse.getVisibility() != View.VISIBLE) {
        return;
    }
    mCollapsed = !mCollapsed;
    ///?
    if (showExpandCollapseDrawable) {
        mTvExpandCollapse.setCompoundDrawablesWithIntrinsicBounds(null, null,
                mCollapsed ? mExpandDrawable : mCollapseDrawable, null);
    }
    mTvExpandCollapse.setText(
            mCollapsed ? getResources().getString(R.string.expand) : getResources().getString(R.string.shink));
    //???
    if (mCollapsedStatus != null) {
        mCollapsedStatus.put(mPosition, mCollapsed);
    }
    // /
    mAnimating = true;
    ValueAnimator valueAnimator;
    if (mCollapsed) {
        //            mTvContent.setMaxLines(mMaxCollapsedLines);
        valueAnimator = new ValueAnimator().ofInt(getHeight(), mCollapsedHeight);
    } else {
        valueAnimator = new ValueAnimator().ofInt(getHeight(),
                getHeight() + mTextHeightWithMaxLines - mTvContent.getHeight());
    }
    valueAnimator.addUpdateListener(valueAnimator1 -> {
        int animatedValue = (int) valueAnimator1.getAnimatedValue();
        mTvContent.setMaxHeight(animatedValue - mMarginBetweenTxtAndBottom);
        getLayoutParams().height = animatedValue;
        requestLayout();
    });
    valueAnimator.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animator) {

        }

        @Override
        public void onAnimationEnd(Animator animator) {
            // ??????
            /// clear the animation flag
            mAnimating = false;
            // notify the listener
            if (mListener != null) {
                mListener.onExpandStateChanged(mTvContent, !mCollapsed);
            }
        }

        @Override
        public void onAnimationCancel(Animator animator) {

        }

        @Override
        public void onAnimationRepeat(Animator animator) {

        }
    });
    valueAnimator.setDuration(mAnimationDuration);
    valueAnimator.start();
}

From source file:io.github.sin3hz.wifispinnerview.WifiSpinnerDrawable.java

private void setupAnimators() {
    AnimatorSet set = new AnimatorSet();
    for (int i = 0; i < mSpinnerCount; i++) {
        final int index = i;
        final ValueAnimator sweepAnimator = ValueAnimator.ofFloat(0, MAX_SWEEP_ANGLE);
        sweepAnimator.setInterpolator(SWEEP_ANIMATOR_INTERPOLATOR);
        sweepAnimator.setDuration(mSweepAnimatorDuration);
        sweepAnimator.setRepeatMode(ValueAnimator.RESTART);
        sweepAnimator.setRepeatCount(ValueAnimator.INFINITE);
        sweepAnimator.setStartDelay(index * SWEEP_ANIMATOR_DELAY);
        sweepAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            @Override//from  w  w w .  j  a v  a  2  s .c o  m
            public void onAnimationUpdate(ValueAnimator animation) {
                mSpinners[index].sweepAngle = (float) animation.getAnimatedValue();
                mSpinners[index].updatePath();
                invalidateSelf();
            }
        });
        sweepAnimator.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationRepeat(Animator animation) {
                mSpinners[index].sweepAngleOffset = (mSpinners[index].sweepAngleOffset + MAX_SWEEP_ANGLE) % 360;
                mSpinners[index].updatePath();
            }
        });
        set.playTogether(sweepAnimator);
    }
    mSweepAnimator = set;

    mAngleAnimator = ValueAnimator.ofFloat(0, 360);
    mAngleAnimator.setInterpolator(ANGLE_ANIMATOR_INTERPOLATOR);
    mAngleAnimator.setRepeatCount(ValueAnimator.INFINITE);
    mAngleAnimator.setRepeatMode(ValueAnimator.RESTART);
    mAngleAnimator.setDuration(ANGLE_ANIMATOR_DURATION);
    mAngleAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mGlobalAngle = (float) animation.getAnimatedValue();
            updatePath();
            invalidateSelf();
        }
    });
}

From source file:ch.gianulli.flashcards.ui.Flashcard.java

private void expandButtonBar() {
    mButtonBarShowing = true;//w ww . java  2  s .  co  m

    mButtonBar.setVisibility(View.VISIBLE);
    mButtonBar.setAlpha(0.0f);

    final int startingHeight = mCardView.getHeight();

    final ViewTreeObserver observer = mCardView.getViewTreeObserver();
    observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            // We don't want to continue getting called for every listview drawing.
            if (observer.isAlive()) {
                observer.removeOnPreDrawListener(this);
            }

            final int endingHeight = mCardView.getHeight();
            final int distance = endingHeight - startingHeight;

            mCardView.getLayoutParams().height = startingHeight;

            mCardView.requestLayout();

            ValueAnimator heightAnimator = ValueAnimator.ofFloat(0f, 1f).setDuration(300);

            heightAnimator.setInterpolator(new DecelerateInterpolator());
            heightAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animator) {
                    Float value = (Float) animator.getAnimatedValue();
                    mCardView.getLayoutParams().height = (int) (value * distance + startingHeight);
                    mCardView.requestLayout();
                }
            });
            heightAnimator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    mCardView.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
                }
            });

            mButtonBar.setLayerType(View.LAYER_TYPE_HARDWARE, null);
            ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(mButtonBar, "alpha", 0.0f, 1.0f);
            alphaAnimator.setInterpolator(new DecelerateInterpolator());
            alphaAnimator.setDuration(300);
            alphaAnimator.setStartDelay(100);

            AnimatorSet set = new AnimatorSet();
            set.playTogether(heightAnimator, alphaAnimator);
            set.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    mButtonBar.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
                }
            });

            set.start();

            return false;
        }
    });
}

From source file:com.test.xujixiao.xjx.widget.view.swipe_listview.SwipeListViewTouchListener.java

/**
 * Perform dismiss action//  w  w  w.ja v  a2s. c  om
 *
 * @param dismissView     View
 * @param dismissPosition Position of list
 */
protected void performDismiss(final View dismissView, final int dismissPosition, boolean doPendingDismiss) {
    final ViewGroup.LayoutParams lp = dismissView.getLayoutParams();
    final int originalHeight = dismissView.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(animationTime);

    if (doPendingDismiss) {
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                --dismissAnimationRefCount;
                if (dismissAnimationRefCount == 0) {
                    removePendingDismisses(originalHeight);
                }
            }
        });
    }

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            dismissView.setLayoutParams(lp);
        }
    });

    pendingDismisses.add(new PendingDismissData(dismissPosition, dismissView));
    animator.start();
}

From source file:bottombar.BottomBarTab.java

void updateWidth(float endWidth, boolean animated) {
    if (!animated) {
        getLayoutParams().width = (int) endWidth;

        if (!isActive && badge != null) {
            badge.adjustPositionAndSize(this);
            badge.show();//from w  w w  . j a  v  a2  s.  c om
        }
        return;
    }

    float start = getWidth();

    ValueAnimator animator = ValueAnimator.ofFloat(start, endWidth);
    animator.setDuration(150);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animator) {
            ViewGroup.LayoutParams params = getLayoutParams();
            if (params == null)
                return;

            params.width = Math.round((float) animator.getAnimatedValue());
            setLayoutParams(params);
        }
    });
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (!isActive && badge != null) {
                badge.adjustPositionAndSize(BottomBarTab.this);
                badge.show();
            }
        }
    });
    animator.start();
}

From source file:com.jinzht.pro.swipelistview.SwipeListViewTouchListener.java

/**
 * Perform dismiss action/*w w  w .j  a va 2s . c  om*/
 *
 * @param dismissView     View
 * @param dismissPosition Position of list
 */
protected void performDismiss(final View dismissView, final int dismissPosition, boolean doPendingDismiss) {
    enableDisableViewGroup((ViewGroup) dismissView, false);
    final ViewGroup.LayoutParams lp = dismissView.getLayoutParams();
    final int originalHeight = dismissView.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(animationTime);

    if (doPendingDismiss) {
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                --dismissAnimationRefCount;
                if (dismissAnimationRefCount == 0) {
                    removePendingDismisses(originalHeight);
                }
            }
        });
    }

    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            enableDisableViewGroup((ViewGroup) dismissView, true);
        }
    });

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            dismissView.setLayoutParams(lp);
        }
    });

    pendingDismisses.add(new PendingDismissData(dismissPosition, dismissView));
    animator.start();
}

From source file:com.androidinspain.deskclock.DeskClock.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.desk_clock);
    mSnackbarAnchor = findViewById(R.id.content);

    // Configure the toolbar.
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from   ww  w.  java  2s .  c om

    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayShowTitleEnabled(false);
    }

    // Configure the menu item controllers add behavior to the toolbar.
    mOptionsMenuManager.addMenuItemController(new NightModeMenuItemController(this),
            new SettingsMenuItemController(this));
    mOptionsMenuManager
            .addMenuItemController(MenuItemControllerFactory.getInstance().buildMenuItemControllers(this));

    // Inflate the menu during creation to avoid a double layout pass. Otherwise, the menu
    // inflation occurs *after* the initial draw and a second layout pass adds in the menu.
    onCreateOptionsMenu(toolbar.getMenu());

    // Create the tabs that make up the user interface.
    mTabLayout = (TabLayout) findViewById(R.id.tabs);
    final int tabCount = UiDataModel.getUiDataModel().getTabCount();
    final boolean showTabLabel = getResources().getBoolean(R.bool.showTabLabel);
    final boolean showTabHorizontally = getResources().getBoolean(R.bool.showTabHorizontally);
    for (int i = 0; i < tabCount; i++) {
        final UiDataModel.Tab tabModel = UiDataModel.getUiDataModel().getTab(i);
        final @StringRes int labelResId = tabModel.getLabelResId();

        final TabLayout.Tab tab = mTabLayout.newTab().setTag(tabModel).setIcon(tabModel.getIconResId())
                .setContentDescription(labelResId);

        if (showTabLabel) {
            tab.setText(labelResId);
            tab.setCustomView(R.layout.tab_item);

            @SuppressWarnings("ConstantConditions")
            final TextView text = (TextView) tab.getCustomView().findViewById(android.R.id.text1);
            text.setTextColor(mTabLayout.getTabTextColors());

            // Bind the icon to the TextView.
            final Drawable icon = tab.getIcon();
            if (showTabHorizontally) {
                // Remove the icon so it doesn't affect the minimum TabLayout height.
                tab.setIcon(null);
                text.setCompoundDrawablesRelativeWithIntrinsicBounds(icon, null, null, null);
            } else {
                text.setCompoundDrawablesRelativeWithIntrinsicBounds(null, icon, null, null);
            }
        }

        mTabLayout.addTab(tab);
    }

    // Configure the buttons shared by the tabs.
    mFab = (ImageView) findViewById(R.id.fab);
    mLeftButton = (Button) findViewById(R.id.left_button);
    mRightButton = (Button) findViewById(R.id.right_button);

    mFab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            getSelectedDeskClockFragment().onFabClick(mFab);
        }
    });
    mLeftButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            getSelectedDeskClockFragment().onLeftButtonClick(mLeftButton);
        }
    });
    mRightButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            getSelectedDeskClockFragment().onRightButtonClick(mRightButton);
        }
    });

    final long duration = UiDataModel.getUiDataModel().getShortAnimationDuration();

    final ValueAnimator hideFabAnimation = getScaleAnimator(mFab, 1f, 0f);
    final ValueAnimator showFabAnimation = getScaleAnimator(mFab, 0f, 1f);

    final ValueAnimator leftHideAnimation = getScaleAnimator(mLeftButton, 1f, 0f);
    final ValueAnimator rightHideAnimation = getScaleAnimator(mRightButton, 1f, 0f);
    final ValueAnimator leftShowAnimation = getScaleAnimator(mLeftButton, 0f, 1f);
    final ValueAnimator rightShowAnimation = getScaleAnimator(mRightButton, 0f, 1f);

    hideFabAnimation.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            getSelectedDeskClockFragment().onUpdateFab(mFab);
        }
    });

    leftHideAnimation.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            getSelectedDeskClockFragment().onUpdateFabButtons(mLeftButton, mRightButton);
        }
    });

    // Build the reusable animations that hide and show the fab and left/right buttons.
    // These may be used independently or be chained together.
    mHideAnimation.setDuration(duration).play(hideFabAnimation).with(leftHideAnimation)
            .with(rightHideAnimation);

    mShowAnimation.setDuration(duration).play(showFabAnimation).with(leftShowAnimation)
            .with(rightShowAnimation);

    // Build the reusable animation that hides and shows only the fab.
    mUpdateFabOnlyAnimation.setDuration(duration).play(showFabAnimation).after(hideFabAnimation);

    // Build the reusable animation that hides and shows only the buttons.
    mUpdateButtonsOnlyAnimation.setDuration(duration).play(leftShowAnimation).with(rightShowAnimation)
            .after(leftHideAnimation).after(rightHideAnimation);

    // Customize the view pager.
    mFragmentTabPagerAdapter = new FragmentTabPagerAdapter(this);
    mFragmentTabPager = (ViewPager) findViewById(R.id.desk_clock_pager);
    // Keep all four tabs to minimize jank.
    mFragmentTabPager.setOffscreenPageLimit(3);
    // Set Accessibility Delegate to null so view pager doesn't intercept movements and
    // prevent the fab from being selected.
    mFragmentTabPager.setAccessibilityDelegate(null);
    // Mirror changes made to the selected page of the view pager into UiDataModel.
    mFragmentTabPager.addOnPageChangeListener(new PageChangeWatcher());
    mFragmentTabPager.setAdapter(mFragmentTabPagerAdapter);

    // Mirror changes made to the selected tab into UiDataModel.
    mTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            UiDataModel.getUiDataModel().setSelectedTab((UiDataModel.Tab) tab.getTag());
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {
        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
        }
    });

    // Honor changes to the selected tab from outside entities.
    UiDataModel.getUiDataModel().addTabListener(mTabChangeWatcher);
}

From source file:com.jaydenxiao.androidfire.ui.zone.widget.ExpandableTextView.java

/**
 * //from w  ww.ja  va2 s.  co m
 * @param view
 */
@Override
public void onClick(View view) {
    if (mTvExpandCollapse.getVisibility() != View.VISIBLE) {
        return;
    }
    mCollapsed = !mCollapsed;
    ///?
    if (showExpandCollapseDrawable) {
        mTvExpandCollapse.setCompoundDrawablesWithIntrinsicBounds(null, null,
                mCollapsed ? mExpandDrawable : mCollapseDrawable, null);
    }
    mTvExpandCollapse.setText(
            mCollapsed ? getResources().getString(R.string.expand) : getResources().getString(R.string.shink));
    //???
    if (mCollapsedStatus != null) {
        mCollapsedStatus.put(mPosition, mCollapsed);
    }
    // /
    mAnimating = true;
    ValueAnimator valueAnimator;
    if (mCollapsed) {
        //            mTvContent.setMaxLines(mMaxCollapsedLines);
        valueAnimator = new ValueAnimator().ofInt(getHeight(), mCollapsedHeight);
    } else {
        valueAnimator = new ValueAnimator().ofInt(getHeight(),
                getHeight() + mTextHeightWithMaxLines - mTvContent.getHeight());
    }
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int animatedValue = (int) valueAnimator.getAnimatedValue();
            mTvContent.setMaxHeight(animatedValue - mMarginBetweenTxtAndBottom);
            getLayoutParams().height = animatedValue;
            requestLayout();
        }
    });
    valueAnimator.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animator) {

        }

        @Override
        public void onAnimationEnd(Animator animator) {
            // ??????
            /// clear the animation flag
            mAnimating = false;
            // notify the listener
            if (mListener != null) {
                mListener.onExpandStateChanged(mTvContent, !mCollapsed);
            }
        }

        @Override
        public void onAnimationCancel(Animator animator) {

        }

        @Override
        public void onAnimationRepeat(Animator animator) {

        }
    });
    valueAnimator.setDuration(mAnimationDuration);
    valueAnimator.start();
}

From source file:com.taobao.weex.ui.view.refresh.core.WXSwipeLayout.java

/**
 * Reset refresh state//from  www . j  a va 2  s .  c  om
 * @param headerViewHeight
 */
private void resetHeaderView(int headerViewHeight) {
    headerView.stopAnimation();
    headerView.setStartEndTrim(0, 0.75f);
    ValueAnimator animator = ValueAnimator.ofFloat(headerViewHeight, 0);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            LayoutParams lp = (LayoutParams) headerView.getLayoutParams();
            lp.height = (int) ((Float) animation.getAnimatedValue()).floatValue();
            headerView.setLayoutParams(lp);
            moveTargetView(lp.height);
        }
    });
    animator.addListener(new WXRefreshAnimatorListener() {
        @Override
        public void onAnimationEnd(Animator animation) {
            resetRefreshState();

        }
    });
    animator.setDuration(300);
    animator.start();
}

From source file:com.taobao.weex.ui.view.refresh.core.WXSwipeLayout.java

/**
 * Reset loadmore state//  ww w.  jav  a  2 s.  co  m
 * @param headerViewHeight
 */
private void resetFootView(int headerViewHeight) {
    footerView.stopAnimation();
    footerView.setStartEndTrim(0.5f, 1.25f);
    ValueAnimator animator = ValueAnimator.ofFloat(headerViewHeight, 0);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            LayoutParams lp = (LayoutParams) footerView.getLayoutParams();
            lp.height = (int) ((Float) animation.getAnimatedValue()).floatValue();
            footerView.setLayoutParams(lp);
            moveTargetView(-lp.height);
        }
    });
    animator.addListener(new WXRefreshAnimatorListener() {
        @Override
        public void onAnimationEnd(Animator animation) {
            resetLoadmoreState();

        }
    });
    animator.setDuration(300);
    animator.start();
}