List of usage examples for android.animation ValueAnimator addListener
public void addListener(AnimatorListener listener)
From source file:com.example.android.tryanimationt.TryAnimationFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mCardView = (CardView) view.findViewById(R.id.cardview); fab1st = (android.widget.ImageButton) view.findViewById(R.id.fabBt); fab2nd = (android.widget.ImageButton) view.findViewById(R.id.fabBt2); fab3rd = (android.widget.ImageButton) view.findViewById(R.id.fab3); footer = view.findViewById(R.id.footer); animButtons(fab1st, true, 2500, 0);// www. j av a2 s . c o m animButtons(fab2nd, true, 1000, 150); animButtons(fab3rd, true, 2000, 250); fab1st.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AnimatorSet animSet = new AnimatorSet(); ObjectAnimator anim2 = ObjectAnimator.ofFloat(fab1st, "rotationX", 0, 359); anim2.setDuration(1500); ObjectAnimator anim3 = ObjectAnimator.ofFloat(fab1st, "rotationY", 0, 359); anim3.setDuration(1500); ObjectAnimator animTrx = ObjectAnimator.ofFloat(fab1st, "translationX", 0, -20); animTrx.setDuration(2500); ObjectAnimator animTry = ObjectAnimator.ofFloat(fab1st, "translationY", 0, -20); animTry.setDuration(2500); animSet.setInterpolator(new BounceInterpolator()); animSet.playTogether(anim2, anim3, animTry, animTrx); animSet.start(); } }); fab1st.setOutlineProvider(new ViewOutlineProvider() { @Override public void getOutline(View view, Outline outline) { int size = getResources().getDimensionPixelSize(R.dimen.fab_size); outline.setOval(0, 0, size, size); outline.setRoundRect(0, 0, size, size, size / 2); } }); fab1st.setClipToOutline(true); final View vImage = view.findViewById(R.id.image); final View vCard = view.findViewById(R.id.cardview); final View vCardTextPart = view.findViewById(R.id.cardview_textpart2); final View vCardContentContainer = view.findViewById(R.id.cardContentContainer); vCard.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(), // Now we provide a list of Pair items which contain the view we can transitioning // from, and the name of the view it is transitioning to, in the launched activity android.support.v4.util.Pair.create(vImage, "photo_hero"), android.support.v4.util.Pair.create(vCardTextPart, "sharedSceneTrasintionText")); Intent intent = new Intent(getActivity(), sceneTransitionActivity.class); intent.putExtra("photo_hero", R.drawable.image1); ActivityCompat.startActivity(getActivity(), intent, options.toBundle()); } }); fab2nd.setOutlineProvider(new ViewOutlineProvider() { @Override public void getOutline(View view, Outline outline) { int size = getResources().getDimensionPixelSize(R.dimen.fab_size); outline.setOval(0, 0, size, size); outline.setRoundRect(0, 0, size, size, size / 2); } }); fab2nd.setClipToOutline(true); final AnimationDrawable[] animDrawables = new AnimationDrawable[2]; animDrawables[0] = (AnimationDrawable) getResources().getDrawable(R.drawable.anim_off_to_on); animDrawables[1] = (AnimationDrawable) getResources().getDrawable(R.drawable.anim_on_to_off); animDrawables[0].setOneShot(true); animDrawables[1].setOneShot(true); fab2nd.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final int fab2InconIndex = mAnimationStateIndex; mAnimationStateIndex = (mAnimationStateIndex + 1) % 2; /*****************************************************/ // animate the card //final Animation myRotation = AnimationUtils.loadAnimation(getActivity(), R.anim.rotate_anim); //mCardView.startAnimation(myRotation); int start; int end; if (mAnimationStateIndex == 0) { start = Color.rgb(0x71, 0xc3, 0xde); end = Color.rgb(0x68, 0xe8, 0xee); } else { start = Color.rgb(0x68, 0xe8, 0xee); end = Color.rgb(0x71, 0xc3, 0xde); } AnimatorSet animSet = new AnimatorSet(); ValueAnimator valueAnimator = ObjectAnimator.ofInt(vCardContentContainer, "backgroundColor", start, end); valueAnimator.setInterpolator(new BounceInterpolator()); valueAnimator.setDuration(2000); valueAnimator.setEvaluator(new ArgbEvaluator()); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { int animProgress = (Integer) animation.getAnimatedValue(); } }); valueAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mCardView.setRadius(8); //mCardView.setElevation(0); } }); float rotateStart, rotateEnd; float scaleXStart, scaleXEnd; float rotateXStart, rotateXEnd; float rotateYStart, rotateYEnd; float transitionXStart, transitionXEnd; float transitionYStart, transitionYEnd; if (mAnimationStateIndex == 0) { rotateStart = 0f; rotateEnd = 80f; scaleXStart = 1f; scaleXEnd = 0.66f; rotateXStart = 0f; rotateXEnd = 30f; rotateYStart = 0f; rotateYEnd = 30f; transitionYStart = 0f; transitionYEnd = -100f; transitionXStart = 0f; transitionXEnd = 100f; } else { rotateStart = 80f; rotateEnd = 0f; scaleXStart = 0.66f; scaleXEnd = 1; rotateXStart = 30; rotateXEnd = 0f; rotateYStart = 30f; rotateYEnd = 0f; transitionYStart = -100f; transitionYEnd = 0f; transitionXStart = 100f; transitionXEnd = 0f; } ObjectAnimator anim = ObjectAnimator.ofFloat(mCardView, "rotation", rotateStart, rotateEnd); anim.setDuration(2000); ObjectAnimator anim1 = ObjectAnimator.ofFloat(mCardView, "scaleX", scaleXStart, scaleXEnd); anim1.setDuration(2000); ObjectAnimator anim2 = ObjectAnimator.ofFloat(mCardView, "rotationX", rotateXStart, rotateXEnd); anim2.setDuration(2000); ObjectAnimator anim3 = ObjectAnimator.ofFloat(mCardView, "rotationY", rotateYStart, rotateYEnd); anim3.setDuration(2000); ObjectAnimator animTry = ObjectAnimator.ofFloat(mCardView, "translationY", transitionYStart, transitionYEnd); animTry.setDuration(2000); ObjectAnimator animTrx = ObjectAnimator.ofFloat(mCardView, "translationX", transitionXStart, transitionXEnd); animTrx.setDuration(2000); animSet.setInterpolator(new BounceInterpolator()); animSet.playTogether(valueAnimator, anim, anim2, anim3, anim1, animTry, animTrx); float controlX1, controlY1, controlX2, controlY2; if (mAnimationStateIndex == 0) { controlX1 = 0f; controlY1 = 0.25f; controlX2 = 1; controlY2 = 1; } else { controlX1 = 1; controlY1 = 1; controlX2 = 0.25f; controlY2 = 1; } PathInterpolator pathInterpolator = new PathInterpolator(controlX1, controlY1, controlX2, controlY2); animTrx.setInterpolator(pathInterpolator); animSet.start(); /*****************************************************/ // animate rotate white button RotateAnimation r = new RotateAnimation(0, 359, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); r.setDuration(2000); r.setFillAfter(true); r.setInterpolator(new BounceInterpolator()); fab2nd.startAnimation(r); // change 2nd button image fab2nd.setImageDrawable(animDrawables[fab2InconIndex]); animDrawables[fab2InconIndex].start(); /*****************************************************/ // animate changing 3rd button image fab3rd.setImageDrawable(animDrawables[mAnimationStateIndex]); animDrawables[mAnimationStateIndex].start(); /*****************************************************/ // using AnimatedStateListDrawable to animate the 1st button image by its state { Drawable drawable = getActivity().getResources().getDrawable(R.drawable.icon_anim); fab1st.setImageDrawable(drawable); final int[] STATE_CHECKED = new int[] { android.R.attr.state_checked }; final int[] STATE_UNCHECKED = new int[] {}; // set state fab1st.setImageState((mAnimationStateIndex != 0) ? STATE_UNCHECKED : STATE_CHECKED, false); drawable.jumpToCurrentState(); // change to state fab1st.setImageState((mAnimationStateIndex != 0) ? STATE_CHECKED : STATE_UNCHECKED, false); } } }); fab3rd.setOutlineProvider(new ViewOutlineProvider() { @Override public void getOutline(View view, Outline outline) { int size = getResources().getDimensionPixelSize(R.dimen.fab_size); outline.setOval(0, 0, size, size); outline.setRoundRect(0, 0, size, size, size / 2); } }); fab3rd.setClipToOutline(true); final CheckBox circleFadeout = (CheckBox) view.findViewById(R.id.circleFadeout); circleFadeout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (((CheckBox) v).isChecked()) { } } }); final ImageButton vLogoBt = fab3rd; vLogoBt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { animButtons(fab1st, false, 2000, 0); animButtons(fab2nd, false, 600, 150); animButtons(fab3rd, false, 1500, 250); Handler delayHandler = new Handler(); delayHandler.postDelayed(new Runnable() { @Override public void run() { Intent logoIntent = new Intent(getActivity(), LogoActivity.class); logoIntent.putExtra(LogoActivity.LOGO_VIEW_IMAGE_FADEOUT, (circleFadeout.isChecked() ? 1 : 0)); logoIntent.putExtra(LogoActivity.LOGO_VIEW_TRANSTION_TYPE, logoActivityTransitionType); startActivityForResult(logoIntent, mRequestCode, ActivityOptions.makeSceneTransitionAnimation(getActivity()).toBundle()); } }, 1000); // footer slide down slideView(footer, false); } }); mRadioGrp = (RadioGroup) view.findViewById(R.id.radioGroup); mRadioGrp.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { int selectedId = mRadioGrp.getCheckedRadioButtonId(); String transitionType = "using"; switch (selectedId) { case R.id.radioFade: logoActivityTransitionType = 0; transitionType = transitionType + " Fade"; break; case R.id.radioExplode: logoActivityTransitionType = 1; transitionType = transitionType + " Explode"; break; default: logoActivityTransitionType = 2; transitionType = transitionType + " Slide"; } mSwitcher.setText(transitionType + " transition"); } }); mSwitcher = (TextSwitcher) view.findViewById(R.id.textSwitcher); mSwitcher.setFactory(mFactory); Animation in = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_in_top); Animation out = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_out_top); mSwitcher.setInAnimation(in); mSwitcher.setOutAnimation(out); mSwitcher.setCurrentText("using Fade transition"); // footer slide up slideView(footer, true); }
From source file:com.shopify.buy.ui.ProductDetailsFragmentView.java
@Override public void setImageAreaSize(final boolean grow) { final int finalHeight = grow ? getHeight() : imageAreaHeight; // hide or show the checkout button if (grow && !imageAreaIsExpanded) { hideCheckoutButton(IMAGE_AREA_FEATURES_ANIMATION_DURATION); } else if (!grow && imageAreaIsExpanded) { showCheckoutButton(IMAGE_AREA_FEATURES_ANIMATION_DURATION); }// w w w . jav a 2s . co m // Animate the image changing size ValueAnimator anim = ValueAnimator.ofInt(imageAreaWrapper.getHeight(), finalHeight); anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { int val = (Integer) valueAnimator.getAnimatedValue(); ViewGroup.LayoutParams containerLayoutParams = imageAreaWrapper.getLayoutParams(); containerLayoutParams.height = val; imageAreaWrapper.setLayoutParams(containerLayoutParams); } }); anim.setDuration(IMAGE_AREA_FEATURES_ANIMATION_DURATION); // Disable touch handler for duration of image resizing imagePager.setOnTouchListener(null); anim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); // Re-enable the touch handle on the image imagePager.setOnTouchListener(imageAreaTouchHandler); if (grow) { onExpandImageArea(); } else { onCollapseImageArea(); } } }); anim.start(); }
From source file:com.hippo.widget.lockpattern.LockPatternView.java
private void startSizeAnimation(float start, float end, long duration, Interpolator interpolator, final CellState state, final Runnable endRunnable) { ValueAnimator valueAnimator = ValueAnimator.ofFloat(start, end); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override/* ww w . j ava2 s . com*/ public void onAnimationUpdate(ValueAnimator animation) { state.size = (float) animation.getAnimatedValue(); invalidate(); } }); if (endRunnable != null) { valueAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { endRunnable.run(); } }); } valueAnimator.setInterpolator(interpolator); valueAnimator.setDuration(duration); valueAnimator.start(); }
From source file:org.protocoderrunner.apprunner.api.PUI.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @ProtocoderScript//from www . ja v a2 s . co m @APIParam(params = { "View" }) public void unreveal(final View v) { // get the center for the clipping circle int cx = (v.getLeft() + v.getRight()) / 2; int cy = (v.getTop() + v.getBottom()) / 2; // get the initial radius for the clipping circle int initialRadius = v.getWidth(); // create the animation (the final radius is zero) ValueAnimator anim = (ValueAnimator) ViewAnimationUtils.createCircularReveal(v, cx, cy, initialRadius, 0); anim.setDuration(1000); // make the view invisible when the animation is done anim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); v.setVisibility(View.INVISIBLE); } }); // start the animation anim.start(); }
From source file:com.heinrichreimersoftware.materialintro.app.IntroActivity.java
private void smoothScrollPagerTo(final int position) { if (miPager.isFakeDragging()) return;/* w w w .ja v a2s. co m*/ ValueAnimator animator = ValueAnimator.ofFloat(miPager.getCurrentItem(), position); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (miPager.isFakeDragging()) miPager.endFakeDrag(); miPager.setCurrentItem(position); } @Override public void onAnimationCancel(Animator animation) { if (miPager.isFakeDragging()) miPager.endFakeDrag(); } }); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float position = (Float) animation.getAnimatedValue(); fakeDragToPosition(position); } private boolean fakeDragToPosition(float position) { // The following mimics the underlying calculations in ViewPager float scrollX = miPager.getScrollX(); int pagerWidth = miPager.getWidth(); int currentPosition = miPager.getCurrentItem(); if (position > currentPosition && Math.floor(position) != currentPosition && position % 1 != 0) { miPager.setCurrentItem((int) Math.floor(position), false); } else if (position < currentPosition && Math.ceil(position) != currentPosition && position % 1 != 0) { miPager.setCurrentItem((int) Math.ceil(position), false); } if (!miPager.isFakeDragging() && !miPager.beginFakeDrag()) return false; miPager.fakeDragBy(scrollX - pagerWidth * position); return true; } }); int distance = Math.abs(position - miPager.getCurrentItem()); animator.setInterpolator(pageScrollInterpolator); animator.setDuration(calculateScrollDuration(distance)); animator.start(); }
From source file:com.telenav.nodeflow.NodeFlowLayout.java
/** * perform closing animation for the specified node * * @param node node to be animated/* ww w. j a va 2s. com*/ */ private void animateDrillOut(final Node<?> node) { final Node<?> parent = node.getParent(); if (parent.getDepth() > 0) addView(_getHeaderView(node.getParent()), 0);//add parent if (nodeChangeListener != null && node.getParent().getDepth() > 0) nodeChangeListener.onParentNodeOpening(getChildAt(0), node.getParent()); for (int i = 0; i < node.getParent().getChildCount(); ++i) { if (i != node.getIndex()) addView(_getHeaderView(node.getParent().getChildAt(i)), i + (parent.getDepth() > 0 ? 1 : 0)); } final int newIndex = node.getIndex() + (parent.getDepth() > 0 ? 1 : 0); final int aux = parent.getChildCount() + (parent.getDepth() > 0 ? 1 : 0); ValueAnimator animator = ValueAnimator.ofFloat(1); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { for (int i = 0; i < aux; ++i) { if (i < newIndex) { getChildAt(i).setTranslationY(headerHeight * (-newIndex + i) + headerHeight * newIndex * ((Float) animation.getAnimatedValue())); } else if (i > newIndex) { getChildAt(i) .setTranslationY((getHeight() + headerHeight * (i - (newIndex + 1))) - ((getHeight() - (node.getIndex() + 1 + (parent.getDepth() > 0 ? 1 : 0)) * headerHeight) * ((Float) animation.getAnimatedValue()))); } else { getChildAt(newIndex) .setTranslationY(headerHeight * newIndex * ((Float) animation.getAnimatedValue())); } } } }); animator.addListener(new CustomAnimationListener() { @Override public void onAnimationEnd(Animator animator) { activeNode = parent; updateViews(node, false); } }); animator.setDuration(duration); animator.setInterpolator(new FastOutSlowInInterpolator()); animator.start(); animateDrillAlpha(newIndex + 1, aux, 1); }
From source file:com.awt.supark.LayoutHandler.java
public void smallButtonPressed(final View view, final MainActivity act) { if (!act.pullUp && !act.pullUpStarted) { // If it isn't already up act.pullUpStarted = true;/* w ww .j ava2 s . c o m*/ // Declaring animator ValueAnimator animation = ValueAnimator.ofFloat(1f, 0.17f); // ****** UI ELEMENTS FADING OUT ANIMATION ****** // Sets the animation properties animation.setDuration(act.layoutFadeOutDuration); animation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float value = (float) animation.getAnimatedValue(); // Fades out contentLinear and all buttons, except the one that is pressed act.contentLinear.setAlpha(value); if (view.getId() != R.id.buttonMap) { act.btnMap.setAlpha(value); } if (view.getId() != R.id.buttonCars) { act.btnCars.setAlpha(value); } if (view.getId() != R.id.buttonStatistics) { act.btnStatistics.setAlpha(value); } if (view.getId() != R.id.buttonEtc) { act.btnEtc.setAlpha(value); } } }); animation.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { // Sets the visibility of the other layout and contentlinear act.contentLinear.setVisibility(View.GONE); act.otherContent.setVisibility(View.VISIBLE); // ****** BUTTON PULL UP ANIMATION ****** // Declaring animator ValueAnimator nextAnimation = ValueAnimator.ofFloat(1f, 0f); // Sets the animation properties nextAnimation.setDuration(act.layoutPullUpDuration); nextAnimation.setInterpolator(new AccelerateDecelerateInterpolator()); nextAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float value = (float) animation.getAnimatedValue(); // Sets weight of the two layouts, this makes one smaller and the other bigger act.tableRowTopHalf .setLayoutParams(new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, value)); act.otherContent.setLayoutParams( new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1 - value)); } }); // ****** LAYOUT PULL UP ANIMATION ****** nextAnimation.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { act.otherContentHandler(view); // Takes care of including new views act.otherContent.startAnimation(act.anim_slide_up_fade_in); // Animates the new activity act.pullUp = true; // Changing the pull up status indicator act.pullUpStarted = false; } @Override public void onAnimationCancel(Animator animation) { act.pullUpStarted = false; act.otherContent.setVisibility(View.GONE); } @Override public void onAnimationRepeat(Animator animation) { } }); nextAnimation.start(); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); animation.start(); } else if (view.getId() == act.openedLayout) { act.pullDown(); // If there is a layout already pulled up we have to pull it down } else if (act.pullUp && (act.openedLayout != 0) && !act.pullUpStarted) { act.pullUpStarted = true; // To prevent more than one highlight // Changing highlight from previous to current button ValueAnimator animation = ValueAnimator.ofFloat(0.17f, 1f); animation.setDuration(act.smallButtonHighlightChangeDuration); animation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float value = (float) animation.getAnimatedValue(); act.findViewById(view.getId()).setAlpha(value); act.findViewById(act.openedLayout).setAlpha(1.17f - value); } }); animation.start(); // Fades out current layout act.otherContent.startAnimation(act.anim_fade_out); act.anim_fade_out.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { act.otherContentHandler(view); // Switches the layout to the new one act.otherContent.startAnimation(act.anim_slide_up_fade_in); // Fades in the new layout act.pullUpStarted = false; } @Override public void onAnimationRepeat(Animation animation) { } }); } }
From source file:io.plaidapp.about.ui.widget.InkPageIndicator.java
private ValueAnimator createMoveSelectedAnimator(final float moveTo, int was, int now, int steps) { // create the actual move animator ValueAnimator moveSelected = ValueAnimator.ofFloat(selectedDotX, moveTo); // also set up a pending retreat anim this starts when the move is 75% complete retreatAnimation = new PendingRetreatAnimator(was, now, steps, now > was ? new RightwardStartPredicate(moveTo - ((moveTo - selectedDotX) * 0.25f)) : new LeftwardStartPredicate(moveTo + ((selectedDotX - moveTo) * 0.25f))); retreatAnimation.addListener(new AnimatorListenerAdapter() { @Override/* www.j a v a2 s.c o m*/ public void onAnimationEnd(Animator animation) { resetState(); pageChanging = false; } }); moveSelected.addUpdateListener(valueAnimator -> { // todo avoid autoboxing selectedDotX = (Float) valueAnimator.getAnimatedValue(); retreatAnimation.startIfNecessary(selectedDotX); postInvalidateOnAnimation(); }); moveSelected.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { // set a flag so that we continue to draw the unselected dot in the target position // until the selected dot has finished moving into place selectedDotInPosition = false; } @Override public void onAnimationEnd(Animator animation) { // set a flag when anim finishes so that we don't draw both selected & unselected // page dots selectedDotInPosition = true; } }); // slightly delay the start to give the joins a chance to run // unless dot isn't in position yet then don't delay! moveSelected.setStartDelay(selectedDotInPosition ? animDuration / 4L : 0L); moveSelected.setDuration(animDuration * 3L / 4L); moveSelected.setInterpolator(interpolator); return moveSelected; }
From source file:com.android.settings.widget.DotsPageIndicator.java
private ValueAnimator createMoveSelectedAnimator(final float moveTo, int was, int now, int steps) { // create the actual move animator ValueAnimator moveSelected = ValueAnimator.ofFloat(selectedDotX, moveTo); // also set up a pending retreat anim this starts when the move is 75% complete retreatAnimation = new PendingRetreatAnimator(was, now, steps, now > was ? new RightwardStartPredicate(moveTo - ((moveTo - selectedDotX) * 0.25f)) : new LeftwardStartPredicate(moveTo + ((selectedDotX - moveTo) * 0.25f))); moveSelected.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override//from ww w.ja v a 2 s .c om public void onAnimationUpdate(ValueAnimator valueAnimator) { // todo avoid autoboxing selectedDotX = (Float) valueAnimator.getAnimatedValue(); retreatAnimation.startIfNecessary(selectedDotX); postInvalidateOnAnimation(); } }); moveSelected.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { // set a flag so that we continue to draw the unselected dot in the target position // until the selected dot has finished moving into place selectedDotInPosition = false; } @Override public void onAnimationEnd(Animator animation) { // set a flag when anim finishes so that we don't draw both selected & unselected // page dots selectedDotInPosition = true; } }); // slightly delay the start to give the joins a chance to run // unless dot isn't in position yet then don't delay! moveSelected.setStartDelay(selectedDotInPosition ? animDuration / 4L : 0L); moveSelected.setDuration(animDuration * 3L / 4L); moveSelected.setInterpolator(interpolator); return moveSelected; }
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);//from w w w .j av a 2s . c om 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(); }