Example usage for android.animation AnimatorListenerAdapter AnimatorListenerAdapter

List of usage examples for android.animation AnimatorListenerAdapter AnimatorListenerAdapter

Introduction

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

Prototype

AnimatorListenerAdapter

Source Link

Usage

From source file:com.alexandrepiveteau.library.tutorial.TutorialActivity.java

private void handleCustomIcons(int position) {
    boolean hadPreviousPageCustomIcon = false;
    boolean hasCustomIcon = false;

    int previousPageIcon;
    final int currentPageIcon;

    if (mFragmentList.get(mPreviousPage) instanceof CustomAction) {
        hadPreviousPageCustomIcon = ((CustomAction) mFragmentList.get(mPreviousPage)).isEnabled();
    }//from www .ja  v a2s.  c  o  m

    if (hadPreviousPageCustomIcon) {
        previousPageIcon = ((CustomAction) mFragmentList.get(mPreviousPage)).getCustomActionIcon();
    } else {
        previousPageIcon = R.drawable.static_previous;
    }

    if (mFragmentList.get(position) instanceof CustomAction) {
        hasCustomIcon = ((CustomAction) mFragmentList.get(position)).isEnabled();
    }

    if (hasCustomIcon) {
        currentPageIcon = ((CustomAction) mFragmentList.get(position)).getCustomActionIcon();
    } else {
        currentPageIcon = R.drawable.static_previous;
    }

    if (currentPageIcon != previousPageIcon) {
        mImageButtonLeft.animate().alpha(0)
                .setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime))
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        super.onAnimationEnd(animation);
                        mImageButtonLeft.setImageResource(currentPageIcon);
                        mImageButtonLeft.animate().alpha(1f)
                                .setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime))
                                .setListener(null)//We clear all listeners
                                .start();
                    }
                }).start();
    }

    mPreviousPage = position;
}

From source file:com.fairphone.fplauncher3.Folder.java

private static Animator setupAlphaAnimator(final View v, final float startAlpha, final float endAlpha,
        final long duration, final long startDelay) {
    v.setAlpha(startAlpha);/*  w  w w.  j a va  2 s  .  c  o  m*/
    Animator animator = LauncherAnimUtils.ofFloat(v, "alpha", startAlpha, endAlpha);
    animator.setDuration(duration);
    animator.setStartDelay(startDelay);
    animator.setInterpolator(new LogDecelerateInterpolator(60, 0));
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            // in low power mode the animation doesn't play, so set the end value here
            v.setAlpha(endAlpha);
        }
    });

    return animator;
}

From source file:com.auratech.launcher.Folder.java

public void animateOpen() {
    positionAndSizeAsIcon();/*w  w  w . j ava  2 s  .  c  o m*/

    if (!(getParent() instanceof DragLayer))
        return;
    centerAboutIcon();
    PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1);
    PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
    PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
    final ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);

    oa.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
                    String.format(getContext().getString(R.string.folder_opened), mContent.getCountX(),
                            mContent.getCountY()));
            mState = STATE_ANIMATING;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mState = STATE_OPEN;
            setLayerType(LAYER_TYPE_NONE, null);

            // Only show cling if we are not in the middle of a drag - this would be quite jarring.
            if (!mDragController.isDragging()) {
                Cling cling = mLauncher.getLauncherClings().showFoldersCling();
                if (cling != null) {
                    cling.bringScrimToFront();
                    bringToFront();
                    cling.bringToFront();
                }
            }
            setFocusOnFirstChild();
        }
    });
    oa.setDuration(mExpandDuration);
    setLayerType(LAYER_TYPE_HARDWARE, null);
    oa.start();

    // Make sure the folder picks up the last drag move even if the finger doesn't move.
    if (mDragController.isDragging()) {
        mDragController.forceTouchMove();
    }
}

From source file:com.android.deskclock.timer.TimerFragment.java

/**
 * @param timerToRemove the timer to be removed during the animation
 *///from  ww w  .j  av  a2s  . c  om
private void animateTimerRemove(final Timer timerToRemove) {
    final Animator fadeOut = ObjectAnimator.ofFloat(mViewPager, ALPHA, 1, 0);
    fadeOut.setDuration(mShortAnimationDuration);
    fadeOut.setInterpolator(new DecelerateInterpolator());
    fadeOut.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            DataModel.getDataModel().removeTimer(timerToRemove);
            Events.sendTimerEvent(R.string.action_delete, R.string.label_deskclock);
        }
    });

    final Animator fadeIn = ObjectAnimator.ofFloat(mViewPager, ALPHA, 0, 1);
    fadeIn.setDuration(mShortAnimationDuration);
    fadeIn.setInterpolator(new AccelerateInterpolator());

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.play(fadeOut).before(fadeIn);
    animatorSet.start();
}

From source file:com.amagi82.kerbalspaceapp.MissionPlanner.java

/**
 * This method animates all other views in the ListView container (not including ignoreView) into their final positions. It is called
 * after ignoreView has been removed from the adapter, but before layout has been run. The approach here is to figure out where
 * everything is now, then allow layout to run, then figure out where everything is after layout, and then to run animations between all
 * of those start/end positions./* w  w  w. j  ava  2  s  .  co m*/
 */
private void animateRemoval(final ListView listview, View viewToRemove) {
    int firstVisiblePosition = listview.getFirstVisiblePosition();
    for (int i = 0; i < listview.getChildCount(); ++i) {
        View child = listview.getChildAt(i);
        if (child != viewToRemove) {
            int position = firstVisiblePosition + i;
            long itemId = mAdapter.getItemId(position);
            mItemIdTopMap.put(itemId, child.getTop());
        }
    }
    // Delete the item from the adapter
    int position = mListView.getPositionForView(viewToRemove);
    mAdapter.remove(mAdapter.getItem(position));
    mAdapter.notifyDataSetChanged();
    refreshDeltaV();

    final ViewTreeObserver observer = listview.getViewTreeObserver();
    observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            observer.removeOnPreDrawListener(this);
            boolean firstAnimation = true;
            int firstVisiblePosition = listview.getFirstVisiblePosition();
            for (int i = 0; i < listview.getChildCount(); ++i) {
                final View child = listview.getChildAt(i);
                int position = firstVisiblePosition + i;
                long itemId = mAdapter.getItemId(position);
                Integer startTop = mItemIdTopMap.get(itemId);
                int top = child.getTop();
                if (startTop != null) {
                    if (startTop != top) {
                        int delta = startTop - top;
                        child.setTranslationY(delta);
                        child.animate().setDuration(MOVE_DURATION).translationY(0);
                        if (firstAnimation) {
                            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                                child.animate().setListener(new AnimatorListenerAdapter() {
                                    @Override
                                    public void onAnimationEnd(Animator animation) {
                                        mBackgroundContainer.hideBackground();
                                        mSwiping = false;
                                        mListView.setEnabled(true);

                                    }
                                });
                            } else {
                                child.animate().withEndAction(new Runnable() {
                                    @Override
                                    public void run() {
                                        mBackgroundContainer.hideBackground();
                                        mSwiping = false;
                                        mListView.setEnabled(true);
                                    }
                                });
                                firstAnimation = false;
                            }
                        }
                    }
                } else {
                    // Animate new views along with the others. The catch is that they did not
                    // exist in the start state, so we must calculate their starting position
                    // based on neighboring views.
                    int childHeight = child.getHeight() + listview.getDividerHeight();
                    startTop = top + (i > 0 ? childHeight : -childHeight);
                    int delta = startTop - top;
                    child.setTranslationY(delta);
                    child.animate().setDuration(MOVE_DURATION).translationY(0);
                    if (firstAnimation) {
                        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                            child.animate().setListener(new AnimatorListenerAdapter() {
                                @Override
                                public void onAnimationEnd(Animator animation) {
                                    mBackgroundContainer.hideBackground();
                                    mSwiping = false;
                                    mListView.setEnabled(true);

                                }
                            });
                        } else {
                            child.animate().withEndAction(new Runnable() {
                                @Override
                                public void run() {
                                    mBackgroundContainer.hideBackground();
                                    mSwiping = false;
                                    mListView.setEnabled(true);
                                }
                            });
                            firstAnimation = false;
                        }
                    }
                }
            }
            mItemIdTopMap.clear();
            return true;
        }
    });

}

From source file:com.betterAlarm.deskclock.timer.TimerFragment.java

private Animator getScaleFooterButtonsAnimator(final boolean show) {
    final AnimatorSet animatorSet = new AnimatorSet();
    final Animator leftButtonAnimator = AnimatorUtils.getScaleAnimator(mLeftButton, show ? 0.0f : 1.0f,
            show ? 1.0f : 0.0f);/*  w w w.j av a 2s.  co  m*/
    final Animator rightButtonAnimator = AnimatorUtils.getScaleAnimator(mRightButton, show ? 0.0f : 1.0f,
            show ? 1.0f : 0.0f);
    final float fabStartScale = (show && mFab.getVisibility() == View.INVISIBLE) ? 0.0f : 1.0f;
    final Animator fabAnimator = AnimatorUtils.getScaleAnimator(mFab, fabStartScale, show ? 1.0f : 0.0f);
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mLeftButton.setVisibility(show ? View.VISIBLE : View.INVISIBLE);
            mRightButton.setVisibility(show ? View.VISIBLE : View.INVISIBLE);
            restoreScale(mLeftButton);
            restoreScale(mRightButton);
            restoreScale(mFab);
        }
    });
    // If not show, means transiting from timer view to setup view,
    // when the setup view starts to rotate, the footer buttons are already invisible,
    // so the scaling has to finish before the setup view starts rotating
    animatorSet.setDuration(show ? ROTATE_ANIM_DURATION_MILIS * 2 : ROTATE_ANIM_DURATION_MILIS);
    animatorSet.play(leftButtonAnimator).with(rightButtonAnimator).with(fabAnimator);
    return animatorSet;
}

From source file:com.mjw.android.swipe.SwipeListViewTouchListener.java

/**
 * Create choice animation//  w  w w  .  j a  v a 2s  . c  om
 * 
 * @param view
 *            affected view
 * @param position
 *            list position
 */
private void generateChoiceAnimate(final View view, final int position) {

    view.animate().translationX(0).setDuration(animationTime).setListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            swipeListView.resetScrolling();
            resetCell();
        }
    });
}

From source file:com.example.jonas.materialmockups.activities.ExhibitDetailsActivity.java

/**
 * Hides the audio toolbar.//from  ww  w.j a v a2  s.c  o m
 * @return true if the audio toolbar was hidden, false otherwise
 */
private boolean hideAudioToolbar() {
    if (mRevealView != null) {
        int cx = (mRevealView.getLeft() + mRevealView.getRight());
        int cy = mRevealView.getTop();
        int radius = Math.max(mRevealView.getWidth(), mRevealView.getHeight());

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {

            SupportAnimator animator = ViewAnimationUtils.createCircularReveal(mRevealView, cx, cy, 0, radius);
            animator.setInterpolator(new AccelerateDecelerateInterpolator());
            animator.setDuration(800);

            SupportAnimator animator_reverse = animator.reverse();
            animator_reverse.addListener(new SupportAnimator.AnimatorListener() {
                @Override
                public void onAnimationStart() {

                }

                @Override
                public void onAnimationEnd() {
                    mRevealView.setVisibility(View.INVISIBLE);
                    isAudioToolbarHidden = true;

                }

                @Override
                public void onAnimationCancel() {

                }

                @Override
                public void onAnimationRepeat() {

                }
            });
            animator_reverse.start();

        } else {
            Animator anim = android.view.ViewAnimationUtils.createCircularReveal(mRevealView, cx, cy, radius,
                    0);
            anim.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    mRevealView.setVisibility(View.INVISIBLE);
                    isAudioToolbarHidden = true;
                }
            });
            anim.start();

        }

        return true;
    }

    return false;
}

From source file:com.android.nobug.view.pattern.PatternView.java

private void startCellStateAnimationSw(final CellState cellState, final float startAlpha, final float endAlpha,
        final float startTranslationY, final float endTranslationY, final float startScale,
        final float endScale, long delay, long duration, Interpolator interpolator,
        final Runnable finishRunnable) {
    cellState.alpha = startAlpha;//from  w  ww  .  j  a v  a2  s  .  c o  m
    cellState.translationY = startTranslationY;
    cellState.radius = mDotSize / 2 * startScale;
    ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f);
    animator.setDuration(duration);
    animator.setStartDelay(delay);
    animator.setInterpolator(interpolator);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float t = (float) animation.getAnimatedValue();
            cellState.alpha = (1 - t) * startAlpha + t * endAlpha;
            cellState.translationY = (1 - t) * startTranslationY + t * endTranslationY;
            cellState.radius = mDotSize / 2 * ((1 - t) * startScale + t * endScale);
            invalidate();
        }
    });
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (finishRunnable != null) {
                finishRunnable.run();
            }
        }
    });
    animator.start();
}

From source file:com.hamzahrmalik.calculator2.Calculator.java

private void onResult(final String result) {
    // Calculate the values needed to perform the scale and translation
    // animations,
    // accounting for how the scale will affect the final position of the
    // text.//  w w  w  .j  a  va  2  s. c o  m
    final float resultScale = mFormulaEditText.getVariableTextSize(result) / mResultEditText.getTextSize();
    final float resultTranslationX = (1.0f - resultScale)
            * (mResultEditText.getWidth() / 2.0f - mResultEditText.getPaddingEnd());
    final float resultTranslationY = (1.0f - resultScale)
            * (mResultEditText.getHeight() / 2.0f - mResultEditText.getPaddingBottom())
            + (mFormulaEditText.getBottom() - mResultEditText.getBottom())
            + (mResultEditText.getPaddingBottom() - mFormulaEditText.getPaddingBottom());
    final float formulaTranslationY = -mFormulaEditText.getBottom();

    // Use a value animator to fade to the final text color over the course
    // of the animation.
    final int resultTextColor = mResultEditText.getCurrentTextColor();
    final int formulaTextColor = mFormulaEditText.getCurrentTextColor();
    final ValueAnimator textColorAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), resultTextColor,
            formulaTextColor);
    textColorAnimator.addUpdateListener(new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            /*
             * mResultEditText.setTextColor((int) valueAnimator
             * .getAnimatedValue());
             */
        }
    });

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(textColorAnimator,
            ObjectAnimator.ofFloat(mResultEditText, View.SCALE_X, resultScale),
            ObjectAnimator.ofFloat(mResultEditText, View.SCALE_Y, resultScale),
            ObjectAnimator.ofFloat(mResultEditText, View.TRANSLATION_X, resultTranslationX),
            ObjectAnimator.ofFloat(mResultEditText, View.TRANSLATION_Y, resultTranslationY),
            ObjectAnimator.ofFloat(mFormulaEditText, View.TRANSLATION_Y, formulaTranslationY));
    animatorSet.setDuration(getResources().getInteger(android.R.integer.config_longAnimTime));
    animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            mResultEditText.setText(result);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            // Reset all of the values modified during the animation.
            mResultEditText.setTextColor(resultTextColor);
            mResultEditText.setScaleX(1.0f);
            mResultEditText.setScaleY(1.0f);
            mResultEditText.setTranslationX(0.0f);
            mResultEditText.setTranslationY(0.0f);
            mFormulaEditText.setTranslationY(0.0f);

            // Finally update the formula to use the current result.
            mFormulaEditText.setText(result);
            setState(CalculatorState.RESULT);

            mCurrentAnimator = null;
        }
    });

    mCurrentAnimator = animatorSet;
    animatorSet.start();
}