List of usage examples for android.animation Animator start
public void start()
From source file:com.github.huajianjiang.expandablerecyclerview.sample.anim.CircularRevealItemAnimator.java
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) private void animateRemoveImpl(final RecyclerView.ViewHolder holder) { final View view = holder.itemView; // final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view); mRemoveAnimations.add(holder);//from w w w. j ava 2s . c om // get the center for the clipping circle int cx = (view.getLeft() + view.getRight()) / 2; int cy = view.getHeight() / 2; // get the initial radius for the clipping circle int initialRadius = view.getWidth(); // create the animation (the final radius is zero) final Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, initialRadius, 0); anim.setDuration(getRemoveDuration()); // make the view invisible when the animation is done anim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { dispatchAddStarting(holder); } @Override public void onAnimationEnd(Animator animation) { anim.removeListener(this); view.setVisibility(View.VISIBLE); dispatchRemoveFinished(holder); mRemoveAnimations.remove(holder); dispatchFinishedWhenDone(); } }); // start the animation anim.start(); // animation.setDuration(getRemoveDuration()) // .alpha(0).setListener(new CircularRevealItemAnimator.VpaListenerAdapter() { // @Override // public void onAnimationStart(View view) { // dispatchRemoveStarting(holder); // } // // @Override // public void onAnimationEnd(View view) { // animation.setListener(null); // ViewCompat.setAlpha(view, 1); // dispatchRemoveFinished(holder); // mRemoveAnimations.remove(holder); // dispatchFinishedWhenDone(); // } // }).start(); }
From source file:com.sinyuk.jianyimaterial.widgets.FloatingToolbar.java
@TargetApi(21) private void hideLollipopImpl() { int rootWidth = mRoot.getWidth(); float controlX; if (mFabOriginalX > rootWidth / 2f) { controlX = mFabOriginalX * 0.98f; } else {/* ww w. j a v a 2s .c o m*/ controlX = mFabOriginalX * 1.02f; } final Path path = new Path(); path.moveTo(mFab.getX(), mFab.getY()); final float x2 = controlX; final float y2 = getY(); path.quadTo(x2, y2, mFabOriginalX, mFabOriginalY + getTranslationY()); ObjectAnimator anim = ObjectAnimator.ofFloat(mFab, View.X, View.Y, path); anim.setInterpolator(new AccelerateDecelerateInterpolator()); anim.setDuration(FAB_UNMORPH_DURATION); anim.setStartDelay(FAB_UNMORPH_DELAY); anim.start(); /** * Animate FAB elevation back to 6dp */ anim = ObjectAnimator.ofFloat(mFab, View.TRANSLATION_Z, 0); anim.setInterpolator(new AccelerateDecelerateInterpolator()); anim.setDuration(FAB_UNMORPH_DURATION); anim.setStartDelay(FAB_UNMORPH_DELAY); anim.start(); /** * Restore alpha of FAB drawable */ Drawable drawable = mFab.getDrawable(); if (drawable != null) { anim = ObjectAnimator.ofPropertyValuesHolder(drawable, PropertyValuesHolder.ofInt("alpha", 255)); anim.setInterpolator(new AccelerateDecelerateInterpolator()); anim.setDuration(FAB_UNMORPH_DURATION); anim.setStartDelay(FAB_UNMORPH_DELAY); anim.start(); } Animator toolbarReveal = ViewAnimationUtils.createCircularReveal(this, getWidth() / 2, getHeight() / 2, (float) (Math.hypot(getWidth() / 2, getHeight() / 2)), (float) mFab.getWidth() / 2f); toolbarReveal.setTarget(this); toolbarReveal.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); setVisibility(View.INVISIBLE); mFab.setVisibility(View.VISIBLE); mMorphing = false; } }); toolbarReveal.setDuration(CIRCULAR_UNREVEAL_DURATION); toolbarReveal.setInterpolator(new AccelerateInterpolator()); toolbarReveal.setStartDelay(CIRCULAR_UNREVEAL_DELAY); toolbarReveal.start(); /** * Animate FloatingToolbar animation back to 6dp */ anim = ObjectAnimator.ofFloat(this, View.TRANSLATION_Z, 0); anim.setDuration(CIRCULAR_UNREVEAL_DURATION); anim.setStartDelay(CIRCULAR_UNREVEAL_DELAY); anim.start(); }
From source file:com.github.huajianjiang.expandablerecyclerview.sample.anim.CircularRevealItemAnimator.java
void animateAddImpl(final RecyclerView.ViewHolder holder) { Logger.e(TAG, "<<<animateAddImpl>>" + holder); final View view = holder.itemView; // final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view); mAddAnimations.add(holder);//www . ja va2s. com // get the center for the clipping circle int cx = (view.getLeft() + view.getRight()) / 2; int cy = view.getHeight() / 2; Logger.e(TAG, "cx=" + cx + ",cy=" + cy); // get the final radius for the clipping circle int finalRadius = Math.max(view.getWidth(), view.getHeight()); Logger.e(TAG, "width=" + view.getWidth() + ",height=" + view.getHeight() + ",finalRadius=" + finalRadius); // create the animator for this view (the start radius is zero) final Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius); anim.setDuration(getAddDuration()); anim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { dispatchAddStarting(holder); } @Override public void onAnimationCancel(Animator animation) { view.setVisibility(View.VISIBLE); } @Override public void onAnimationEnd(Animator animation) { anim.removeListener(this); dispatchAddFinished(holder); mAddAnimations.remove(holder); dispatchFinishedWhenDone(); } }); // make the view visible and start the animation view.setVisibility(View.VISIBLE); anim.start(); // animation.alpha(1).setDuration(getAddDuration()). // setListener(new CircularRevealItemAnimator.VpaListenerAdapter() { // @Override // public void onAnimationStart(View view) { // dispatchAddStarting(holder); // } // @Override // public void onAnimationCancel(View view) { // ViewCompat.setAlpha(view, 1); // } // // @Override // public void onAnimationEnd(View view) { // animation.setListener(null); // dispatchAddFinished(holder); // mAddAnimations.remove(holder); // dispatchFinishedWhenDone(); // } // }).start(); }
From source file:org.chromium.chrome.browser.widget.animation.FocusAnimator.java
private void startAnimator(final Runnable callback) { // Don't animate anything if the number of children changed. if (mInitialNumberOfChildren != mLayout.getChildCount()) { finishAnimation(callback);// w w w. j a v a 2 s. c o m return; } // Don't animate if children are already all in the correct places. boolean isAnimationNecessary = false; ArrayList<Integer> finalChildTops = calculateChildTops(); for (int i = 0; i < finalChildTops.size() && !isAnimationNecessary; i++) { isAnimationNecessary |= finalChildTops.get(i).compareTo(mInitialTops.get(i)) != 0; } if (!isAnimationNecessary) { finishAnimation(callback); return; } // Animate each child moving and changing size to match their final locations. ArrayList<Animator> animators = new ArrayList<Animator>(); ValueAnimator childAnimator = ValueAnimator.ofFloat(0f, 1f); animators.add(childAnimator); for (int i = 0; i < mLayout.getChildCount(); i++) { // The child is already where it should be. if (mInitialTops.get(i).compareTo(finalChildTops.get(i)) == 0 && mInitialTops.get(i + 1).compareTo(finalChildTops.get(i + 1)) == 0) { continue; } final View child = mLayout.getChildAt(i); final int translationDifference = mInitialTops.get(i) - finalChildTops.get(i); final int oldHeight = mInitialTops.get(i + 1) - mInitialTops.get(i); final int newHeight = finalChildTops.get(i + 1) - finalChildTops.get(i); // Translate the child to its new place while changing where its bottom is drawn to // animate the child changing height without causing another layout. childAnimator.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float progress = (Float) animation.getAnimatedValue(); child.setTranslationY(translationDifference * (1f - progress)); if (oldHeight != newHeight) { float animatedHeight = oldHeight * (1f - progress) + newHeight * progress; child.setBottom(child.getTop() + (int) animatedHeight); } } }); // Explicitly place the child in its final position in the end. childAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animator) { child.setTranslationY(0); child.setBottom(child.getTop() + newHeight); } }); } // Animate the height of the container itself changing. int oldContainerHeight = mInitialTops.get(mInitialTops.size() - 1); int newContainerHeight = finalChildTops.get(finalChildTops.size() - 1); ValueAnimator layoutAnimator = ValueAnimator.ofInt(oldContainerHeight, newContainerHeight); layoutAnimator.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { mLayout.setBottom(((Integer) animation.getAnimatedValue())); requestChildFocus(); } }); animators.add(layoutAnimator); // Set up and kick off the animation. AnimatorSet animator = new AnimatorSet(); animator.setDuration(ANIMATION_LENGTH_MS); animator.setInterpolator(new LinearOutSlowInInterpolator()); animator.playTogether(animators); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animator) { finishAnimation(callback); // Request a layout to put everything in the right final place. mLayout.requestLayout(); } }); animator.start(); }
From source file:com.songcode.materialnotes.ui.NoteEditActivity.java
private void animateRevealHide(final View targetview, View startView) { if (isActionInsertOrEdit()) { int cx = startView.getLeft() + (startView.getWidth() / 2); //middle of button int cy = startView.getTop() + (startView.getHeight() / 2); //middle of button int radius = (int) Math.sqrt(Math.pow(cx, 2) + Math.pow(cy, 2)); //hypotenuse to top left Animator anim = ViewAnimationUtils.createCircularReveal(targetview, cx, cy, radius, 0); anim.addListener(new AnimatorListenerAdapter() { @Override/* w w w . ja v a2s. c o m*/ public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); targetview.setVisibility(View.INVISIBLE); } }); //anim.setInterpolator(new AccelerateInterpolator()); anim.setDuration(ANIM_DURATION); anim.start(); Integer colorTo = getResources().getColor(R.color.primaryColor); Integer colorFrom = getResources().getColor(android.R.color.white); ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { targetview.setBackgroundColor((Integer) animator.getAnimatedValue()); } }); colorAnimation.setInterpolator(new AccelerateInterpolator(2)); colorAnimation.setDuration(ANIM_DURATION); colorAnimation.start(); } else if (isActionActionView()) { mAnimBackGroudView.animate().scaleX(1).scaleY(1).alpha(1).translationY(0).setDuration(ANIM_DURATION) .setInterpolator(new AccelerateInterpolator()).start(); mNoteEditor.animate().alpha(0).setDuration(100).start(); } }
From source file:bottombar.BottomBar.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void backgroundCircularRevealAnimation(View clickedView, final int newColor) { int centerX = (int) (ViewCompat.getX(clickedView) + (clickedView.getMeasuredWidth() / 2)); int yOffset = isTabletMode ? (int) ViewCompat.getY(clickedView) : 0; int centerY = yOffset + clickedView.getMeasuredHeight() / 2; int startRadius = 0; int finalRadius = isTabletMode ? outerContainer.getHeight() : outerContainer.getWidth(); Animator animator = ViewAnimationUtils.createCircularReveal(backgroundOverlay, centerX, centerY, startRadius, finalRadius);//ww w .j a v a 2 s .c o m if (isTabletMode) { animator.setDuration(500); } animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { onEnd(); } @Override public void onAnimationCancel(Animator animation) { onEnd(); } private void onEnd() { outerContainer.setBackgroundColor(newColor); backgroundOverlay.setVisibility(View.INVISIBLE); ViewCompat.setAlpha(backgroundOverlay, 1); } }); animator.start(); }
From source file:com.sinyuk.jianyimaterial.widgets.FloatingToolbar.java
@TargetApi(21) private void showLollipopImpl() { int rootWidth = mRoot.getWidth(); float endFabX; float controlX; if (mFabOriginalX > rootWidth / 2f) { endFabX = rootWidth / 2f + (mFabOriginalX - rootWidth / 2f) / 4f; controlX = mFabOriginalX * 0.98f; } else {/*from w ww. j ava2s . c o m*/ endFabX = rootWidth / 2f - (mFabOriginalX - rootWidth / 2f) / 4f; controlX = mFabOriginalX * 1.02f; } /** * Animate FAB movement */ final Path path = new Path(); path.moveTo(mFab.getX(), mFab.getY()); final float x2 = controlX; final float y2 = getY(); path.quadTo(x2, y2, endFabX, getY()); ObjectAnimator anim = ObjectAnimator.ofFloat(mFab, View.X, View.Y, path); anim.setInterpolator(new AccelerateDecelerateInterpolator()); anim.setDuration(FAB_MORPH_DURATION); anim.start(); /** * Fade FAB drawable */ Drawable drawable = mFab.getDrawable(); if (drawable != null) { anim = ObjectAnimator.ofPropertyValuesHolder(drawable, PropertyValuesHolder.ofInt("alpha", 0)); anim.setInterpolator(new AccelerateDecelerateInterpolator()); anim.setDuration((long) (FAB_MORPH_DURATION / 3f)); anim.start(); } /** * Animate FAB elevation to 8dp */ anim = ObjectAnimator.ofFloat(mFab, View.TRANSLATION_Z, dpToPixels(2)); anim.setInterpolator(new AccelerateDecelerateInterpolator()); anim.setDuration(FAB_MORPH_DURATION); anim.start(); /** * Create circular reveal */ Animator toolbarReveal = ViewAnimationUtils.createCircularReveal(this, getWidth() / 2, getHeight() / 2, (float) mFab.getWidth() / 2f, (float) (Math.hypot(getWidth() / 2, getHeight() / 2))); toolbarReveal.setDuration(CIRCULAR_REVEAL_DURATION); toolbarReveal.setTarget(this); toolbarReveal.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { super.onAnimationStart(animation); mFab.setVisibility(View.INVISIBLE); setVisibility(View.VISIBLE); } @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); mMorphing = false; } }); toolbarReveal.setInterpolator(new AccelerateInterpolator()); toolbarReveal.setStartDelay(CIRCULAR_REVEAL_DELAY); toolbarReveal.start(); /** * Animate FloatingToolbar elevation to 8dp */ anim = ObjectAnimator.ofFloat(this, View.TRANSLATION_Z, dpToPixels(2)); anim.setDuration(CIRCULAR_REVEAL_DURATION); anim.setStartDelay(CIRCULAR_REVEAL_DELAY); anim.start(); }
From source file:android.support.v17.leanback.app.OnboardingSupportFragment.java
private boolean startLogoAnimation() { Animator animator = null; if (mLogoResourceId != 0) { mLogoView.setVisibility(View.VISIBLE); mLogoView.setImageResource(mLogoResourceId); Animator inAnimator = AnimatorInflater.loadAnimator(getActivity(), R.animator.lb_onboarding_logo_enter); Animator outAnimator = AnimatorInflater.loadAnimator(getActivity(), R.animator.lb_onboarding_logo_exit); outAnimator.setStartDelay(LOGO_SPLASH_PAUSE_DURATION_MS); AnimatorSet logoAnimator = new AnimatorSet(); logoAnimator.playSequentially(inAnimator, outAnimator); logoAnimator.setTarget(mLogoView); animator = logoAnimator;//from w ww . j av a 2 s . c o m } else { animator = onCreateLogoAnimation(); } if (animator != null) { animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (getActivity() != null) { startEnterAnimation(); } } }); animator.start(); return true; } return false; }
From source file:com.rbware.github.androidcouchpotato.app.OnboardingSupportFragment.java
boolean startLogoAnimation() { Animator animator = null; if (mLogoResourceId != 0) { mLogoView.setVisibility(View.VISIBLE); mLogoView.setImageResource(mLogoResourceId); Animator inAnimator = AnimatorInflater.loadAnimator(getActivity(), R.animator.lb_onboarding_logo_enter); Animator outAnimator = AnimatorInflater.loadAnimator(getActivity(), R.animator.lb_onboarding_logo_exit); outAnimator.setStartDelay(LOGO_SPLASH_PAUSE_DURATION_MS); AnimatorSet logoAnimator = new AnimatorSet(); logoAnimator.playSequentially(inAnimator, outAnimator); logoAnimator.setTarget(mLogoView); animator = logoAnimator;/* w w w . ja v a 2 s . c o m*/ } else { animator = onCreateLogoAnimation(); } if (animator != null) { animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (getActivity() != null) { startEnterAnimation(); } } }); animator.start(); return true; } return false; }
From source file:ca.zadrox.dota2esportticker.ui.TeamDetailActivity.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void createCircularReveal() { mHeaderTeamLogo.setVisibility(View.VISIBLE); mHeaderTeamLogo.setImageBitmap(mTeam.logo); if (mHeaderBox.isAttachedToWindow()) { mHeaderTeamLogo.setTranslationY(-UIUtils.calculateActionBarSize(this) - mHeaderTeamLogo.getHeight()); mHeaderTeamLogo.animate().translationY(0).setDuration(100) .setInterpolator(new AccelerateDecelerateInterpolator()) .setListener(new Animator.AnimatorListener() { @Override/*from w ww.j a v a2s. c o m*/ public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { int cx = (mHeaderBox.getLeft() + mHeaderBox.getRight()) / 2; int cy = (mHeaderBox.getTop() + mHeaderBox.getBottom()) / 2; int finalRadius = Math.max(mHeaderBox.getWidth(), mHeaderBox.getHeight()); final Animator anim = ViewAnimationUtils.createCircularReveal(mHeaderBox, cx, cy, 0, finalRadius); anim.setDuration(250); anim.setInterpolator(new AccelerateDecelerateInterpolator()); anim.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { mHeaderTeamName.setAlpha(1); mHeaderTeamLogo.setImageBitmap(mTeam.logo); mHeaderBox.setBackgroundColor(mTeam.palette .getDarkVibrantColor(getResources().getColor(R.color.theme_primary))); } @Override public void onAnimationEnd(Animator animation) { } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); anim.start(); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }).start(); } else { mHeaderTeamName.setAlpha(1); mHeaderTeamLogo.setImageBitmap(mTeam.logo); mHeaderBox.setBackgroundColor( mTeam.palette.getDarkVibrantColor(getResources().getColor(R.color.theme_primary))); } }