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.kytse.aria2remote.LoginFragment.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
private void showProgress(final boolean show) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime);

        mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
        mLoginFormView.animate().setDuration(shortAnimTime).alpha(show ? 0 : 1)
                .setListener(new AnimatorListenerAdapter() {
                    @Override//w w  w .  j  av a2  s . c  om
                    public void onAnimationEnd(Animator animation) {
                        mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
                    }
                });

        mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
        mProgressView.animate().setDuration(shortAnimTime).alpha(show ? 1 : 0)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
                    }
                });
    } else {
        mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
        mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
    }
}

From source file:com.example.ray.firstapp.bottombar.MiscUtils.java

/**
 * Animate a background color change. Uses Circular Reveal if supported,
 * otherwise crossfades the background color in.
 *
 * @param clickedView    the view that was clicked for calculating the start position
 *                       for the Circular Reveal.
 * @param backgroundView the currently showing background color.
 * @param bgOverlay      the overlay view for the new background color that will be
 *                       animated in./*  ww w .  j  a v  a2  s .c om*/
 * @param newColor       the new color.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected static void animateBGColorChange(View clickedView, final View backgroundView, final View bgOverlay,
        final int newColor) {
    int centerX = (int) (ViewCompat.getX(clickedView) + (clickedView.getMeasuredWidth() / 2));
    int centerY = clickedView.getMeasuredHeight() / 2;
    int finalRadius = backgroundView.getWidth();

    backgroundView.clearAnimation();
    bgOverlay.clearAnimation();

    Object animator;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (!bgOverlay.isAttachedToWindow()) {
            return;
        }

        animator = ViewAnimationUtils.createCircularReveal(bgOverlay, centerX, centerY, 0, finalRadius);
    } else {
        ViewCompat.setAlpha(bgOverlay, 0);
        animator = ViewCompat.animate(bgOverlay).alpha(1);
    }

    if (animator instanceof ViewPropertyAnimatorCompat) {
        ((ViewPropertyAnimatorCompat) animator).setListener(new ViewPropertyAnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(View view) {
                onCancel();
            }

            @Override
            public void onAnimationCancel(View view) {
                onCancel();
            }

            private void onCancel() {
                backgroundView.setBackgroundColor(newColor);
                bgOverlay.setVisibility(View.INVISIBLE);
                ViewCompat.setAlpha(bgOverlay, 1);
            }
        }).start();
    } else if (animator != null) {
        ((Animator) animator).addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                onCancel();
            }

            @Override
            public void onAnimationCancel(Animator animation) {
                onCancel();
            }

            private void onCancel() {
                backgroundView.setBackgroundColor(newColor);
                bgOverlay.setVisibility(View.INVISIBLE);
                ViewCompat.setAlpha(bgOverlay, 1);
            }
        });

        ((Animator) animator).start();
    }

    bgOverlay.setBackgroundColor(newColor);
    bgOverlay.setVisibility(View.VISIBLE);
}

From source file:android.example.com.animationdemos.CrossfadeActivity.java

/**
 * Cross-fades between {@link #mContentView} and {@link #mLoadingView}.
 *//*from ww  w  .  j av a2 s .c  om*/
private void showContentOrLoadingIndicator(boolean contentLoaded) {
    // Decide which view to hide and which to show.
    final View showView = contentLoaded ? mContentView : mLoadingView;
    final View hideView = contentLoaded ? mLoadingView : mContentView;
    // Set the "show" view to 0% opacity but visible, so that it is visible
    // (but fully transparent) during the animation.
    showView.setAlpha(0f);
    showView.setVisibility(View.VISIBLE);
    // Animate the "show" view to 100% opacity, and clear any animation listener set on
    // the view. Remember that listeners are not limited to the specific animation
    // describes in the chained method calls. Listeners are set on the
    // ViewPropertyAnimator object for the view, which persists across several
    // animations.
    showView.animate().alpha(1f).setDuration(mShortAnimationDuration).setListener(null);
    // Animate the "hide" view to 0% opacity. After the animation ends, set its visibility
    // to GONE as an optimization step (it won't participate in layout passes, etc.)
    hideView.animate().alpha(0f).setDuration(mShortAnimationDuration)
            .setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    hideView.setVisibility(View.GONE);
                }
            });
}

From source file:com.android.incallui.CircularRevealActivity.java

private void setupDecorView(final Point touchPoint, MaterialPalette palette) {
    final View view = getWindow().getDecorView();

    // The circle starts from an initial size of 0 so clip it such that it is invisible. When
    // the animation later starts, this clip will be clobbered by the circular reveal clip.
    // See ViewAnimationUtils.createCircularReveal.
    view.setOutlineProvider(new ViewOutlineProvider() {
        @Override//from   ww w  . j a va 2s .c  om
        public void getOutline(View view, Outline outline) {
            // Using (0, 0, 0, 0) will not work since the outline will simply be treated as
            // an empty outline.
            outline.setOval(-1, -1, 0, 0);
        }
    });
    view.setClipToOutline(true);

    if (palette != null) {
        view.findViewById(R.id.outgoing_call_animation_circle).setBackgroundColor(palette.mPrimaryColor);
        getWindow().setStatusBarColor(palette.mSecondaryColor);
    }

    view.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            final ViewTreeObserver vto = view.getViewTreeObserver();
            if (vto.isAlive()) {
                vto.removeOnPreDrawListener(this);
            }
            final Animator animator = getRevealAnimator(touchPoint);
            // Since this animator is a RenderNodeAnimator (native animator), add an arbitary
            // start delay to force the onAnimationStart callback to happen later on the UI
            // thread. Otherwise it would happen right away inside animator.start()
            animator.setStartDelay(5);
            animator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationStart(Animator animation) {
                    InCallPresenter.getInstance().onCircularRevealStarted(CircularRevealActivity.this);
                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    view.setClipToOutline(false);
                    super.onAnimationEnd(animation);
                }
            });
            animator.start();
            return false;
        }
    });
}

From source file:cn.androidy.materialdesignsample.animations.CrossfadeActivity.java

/**
 * Cross-fades between {@link #mContentView} and {@link #mLoadingView}.
 *//*w  w  w  .  j a  v a2  s.  c  o  m*/
private void showContentOrLoadingIndicator(boolean contentLoaded) {
    // Decide which view to hide and which to show.
    final View showView = contentLoaded ? mContentView : mLoadingView;
    final View hideView = contentLoaded ? mLoadingView : mContentView;

    // Set the "show" view to 0% opacity but visible, so that it is visible
    // (but fully transparent) during the animation.
    showView.setAlpha(0f);
    showView.setVisibility(View.VISIBLE);

    // Animate the "show" view to 100% opacity, and clear any animation listener set on
    // the view. Remember that listeners are not limited to the specific animation
    // describes in the chained method calls. Listeners are set on the
    // ViewPropertyAnimator object for the view, which persists across several
    // animations.
    showView.animate().alpha(1f).setDuration(mShortAnimationDuration).setListener(null);

    // Animate the "hide" view to 0% opacity. After the animation ends, set its visibility
    // to GONE as an optimization step (it won't participate in layout passes, etc.)
    hideView.animate().alpha(0f).setDuration(mShortAnimationDuration)
            .setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    hideView.setVisibility(View.GONE);
                }
            });
}

From source file:com.google.android.apps.muzei.TutorialFragment.java

@Override
public void onViewCreated(final View view, @Nullable final Bundle savedInstanceState) {
    view.findViewById(R.id.tutorial_icon_affordance).setOnClickListener(new View.OnClickListener() {
        @Override/*from  w  ww  .  j  a  va2  s . c  o m*/
        public void onClick(View view) {
            FirebaseAnalytics.getInstance(getContext()).logEvent(FirebaseAnalytics.Event.TUTORIAL_COMPLETE,
                    null);
            final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
            sp.edit().putBoolean(PREF_SEEN_TUTORIAL, true).apply();
        }
    });

    if (savedInstanceState == null) {
        float animateDistance = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100,
                getResources().getDisplayMetrics());
        View mainTextView = view.findViewById(R.id.tutorial_main_text);
        mainTextView.setAlpha(0);
        mainTextView.setTranslationY(-animateDistance / 5);
        View subTextView = view.findViewById(R.id.tutorial_sub_text);
        subTextView.setAlpha(0);
        subTextView.setTranslationY(-animateDistance / 5);
        final View affordanceView = view.findViewById(R.id.tutorial_icon_affordance);
        affordanceView.setAlpha(0);
        affordanceView.setTranslationY(animateDistance);
        View iconTextView = view.findViewById(R.id.tutorial_icon_text);
        iconTextView.setAlpha(0);
        iconTextView.setTranslationY(animateDistance);
        mAnimator = new AnimatorSet();
        mAnimator.setStartDelay(500);
        mAnimator.setDuration(250);
        mAnimator.playTogether(ObjectAnimator.ofFloat(mainTextView, View.ALPHA, 1f),
                ObjectAnimator.ofFloat(subTextView, View.ALPHA, 1f));
        mAnimator.start();
        mAnimator = new AnimatorSet();
        mAnimator.setStartDelay(2000);
        // Bug in older versions where set.setInterpolator didn't work
        Interpolator interpolator = new OvershootInterpolator();
        ObjectAnimator a1 = ObjectAnimator.ofFloat(affordanceView, View.TRANSLATION_Y, 0);
        ObjectAnimator a2 = ObjectAnimator.ofFloat(iconTextView, View.TRANSLATION_Y, 0);
        ObjectAnimator a3 = ObjectAnimator.ofFloat(mainTextView, View.TRANSLATION_Y, 0);
        ObjectAnimator a4 = ObjectAnimator.ofFloat(subTextView, View.TRANSLATION_Y, 0);
        a1.setInterpolator(interpolator);
        a2.setInterpolator(interpolator);
        a3.setInterpolator(interpolator);
        a4.setInterpolator(interpolator);
        mAnimator.setDuration(500).playTogether(ObjectAnimator.ofFloat(affordanceView, View.ALPHA, 1f),
                ObjectAnimator.ofFloat(iconTextView, View.ALPHA, 1f), a1, a2, a3, a4);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mAnimator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    if (isAdded()) {
                        ImageView emanateView = (ImageView) view.findViewById(R.id.tutorial_icon_emanate);
                        AnimatedVectorDrawable avd = (AnimatedVectorDrawable) getResources()
                                .getDrawable(R.drawable.avd_tutorial_icon_emanate, getContext().getTheme());
                        emanateView.setImageDrawable(avd);
                        avd.start();
                    }
                }
            });
        }
        mAnimator.start();
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ImageView emanateView = (ImageView) view.findViewById(R.id.tutorial_icon_emanate);
        AnimatedVectorDrawable avd = (AnimatedVectorDrawable) getResources()
                .getDrawable(R.drawable.avd_tutorial_icon_emanate, getContext().getTheme());
        emanateView.setImageDrawable(avd);
        avd.start();
    }
}

From source file:com.jaspervanriet.huntingthatproduct.Views.FeedContextMenuManager.java

private void performDismissAnimation() {
    contextMenuView.setPivotX(contextMenuView.getWidth() / 2);
    contextMenuView.setPivotY(contextMenuView.getHeight());
    contextMenuView.animate().scaleX(0.1f).scaleY(0.1f).setDuration(150)
            .setInterpolator(new AccelerateInterpolator()).setStartDelay(100)
            .setListener(new AnimatorListenerAdapter() {
                @Override//from   ww w . j  a  va 2s  . co m
                public void onAnimationEnd(Animator animation) {
                    if (contextMenuView != null) {
                        contextMenuView.dismiss();
                    }
                    isContextMenuDismissing = false;
                }
            });
}

From source file:com.google.samples.apps.ourstreets.fragment.StreetViewFragment.java

@Override
public void onBackPressed() {
    if (isRestored) {
        getFragmentManager().popBackStack();
    } else {//from www . ja  v a 2  s.c o m
        // Perform a circular conceal, then pop this fragment off the back stack.
        final FrameLayout view = ((FrameLayout) getView());
        //noinspection ConstantConditions
        Animator circularConceal = ViewUtils.createCircularConceal(mRevealCenter, mRevealWidth, view,
                INTERPOLATOR);
        circularConceal.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                view.setVisibility(View.GONE);
                getFragmentManager().popBackStack();
            }
        });
        circularConceal.start();
    }
}

From source file:com.microsoft.artcurator.ui.emaildetails.EmailDetailsFragment.java

@Override
public void onActionFailed(IOException e) {
    e.printStackTrace();/*from w w  w  . j av a2  s  .c  o m*/
    mButtonLayout.setVisibility(View.VISIBLE);
    mButtonLayout.animate().translationY(0).setListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            mScrollView.setLayoutParams(adjustMargins(Direction.UP));
        }
    });
}

From source file:com.android.clear.reminder.ItemAnimator.java

@Override
public boolean animateMove(final ViewHolder holder, int fromX, int fromY, int toX, int toY) {
    endAnimation(holder);/*  w w w  . j av a  2s . c om*/

    final int deltaX = toX - fromX;
    final int deltaY = toY - fromY;
    final long moveDuration = getMoveDuration();

    if (deltaX == 0 && deltaY == 0) {
        dispatchMoveFinished(holder);
        return false;
    }

    final View view = holder.itemView;
    final float prevTranslationX = view.getTranslationX();
    final float prevTranslationY = view.getTranslationY();
    view.setTranslationX(-deltaX);
    view.setTranslationY(-deltaY);

    final ObjectAnimator moveAnimator;
    if (deltaX != 0 && deltaY != 0) {
        final PropertyValuesHolder moveX = PropertyValuesHolder.ofFloat(TRANSLATION_X, 0f);
        final PropertyValuesHolder moveY = PropertyValuesHolder.ofFloat(TRANSLATION_Y, 0f);
        moveAnimator = ObjectAnimator.ofPropertyValuesHolder(holder.itemView, moveX, moveY);
    } else if (deltaX != 0) {
        final PropertyValuesHolder moveX = PropertyValuesHolder.ofFloat(TRANSLATION_X, 0f);
        moveAnimator = ObjectAnimator.ofPropertyValuesHolder(holder.itemView, moveX);
    } else {
        final PropertyValuesHolder moveY = PropertyValuesHolder.ofFloat(TRANSLATION_Y, 0f);
        moveAnimator = ObjectAnimator.ofPropertyValuesHolder(holder.itemView, moveY);
    }

    moveAnimator.setDuration(moveDuration);
    moveAnimator.setInterpolator(AnimatorUtils.INTERPOLATOR_FAST_OUT_SLOW_IN);
    moveAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animator) {
            dispatchMoveStarting(holder);
        }

        @Override
        public void onAnimationEnd(Animator animator) {
            animator.removeAllListeners();
            mAnimators.remove(holder);
            view.setTranslationX(prevTranslationX);
            view.setTranslationY(prevTranslationY);
            dispatchMoveFinished(holder);
        }
    });
    mMoveAnimatorsList.add(moveAnimator);
    mAnimators.put(holder, moveAnimator);

    return true;
}