List of usage examples for android.animation Animator setInterpolator
public abstract void setInterpolator(TimeInterpolator value);
From source file:com.taobao.weex.ui.action.GraphicActionAnimation.java
private void startAnimation(@NonNull WXSDKInstance instance, @Nullable WXComponent component) { if (component != null) { if (mAnimationBean != null) { component.setNeedLayoutOnAnimation(mAnimationBean.needLayout); }//w w w . jav a2 s . c o m if (component.getHostView() == null) { WXAnimationModule.AnimationHolder holder = new WXAnimationModule.AnimationHolder(mAnimationBean, callback); component.postAnimation(holder); } else { try { Animator animator = createAnimator(component.getHostView(), instance.getInstanceViewPortWidth()); if (animator != null) { Animator.AnimatorListener animatorCallback = createAnimatorListener(instance, callback); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2 && component.isLayerTypeEnabled()) { component.getHostView().setLayerType(View.LAYER_TYPE_HARDWARE, null); } Interpolator interpolator = createTimeInterpolator(); if (animatorCallback != null) { animator.addListener(animatorCallback); } if (interpolator != null) { animator.setInterpolator(interpolator); } component.getHostView().setCameraDistance(mAnimationBean.styles.getCameraDistance()); animator.setDuration(mAnimationBean.duration); animator.start(); } } catch (RuntimeException e) { WXLogUtils.e(TAG, WXLogUtils.getStackTrace(e)); } } } }
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:org.huxizhijian.hhcomicviewer.ui.entry.ComicDetailsActivity.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void animateRevealShow(View viewRoot) { //???//from ww w . j a v a 2 s .c o m int cx = (viewRoot.getLeft() + viewRoot.getRight()) / 2; int cy = (viewRoot.getTop() + viewRoot.getBottom()) / 2; //? int finalRadius = Math.max(viewRoot.getWidth(), viewRoot.getHeight()); Animator anim = ViewAnimationUtils.createCircularReveal(viewRoot, cx, cy, 0, finalRadius); viewRoot.setVisibility(View.VISIBLE); //?? anim.setDuration(getResources().getInteger(R.integer.anim_duration_medium));// anim.setInterpolator(new AccelerateInterpolator());//? ?? anim.start(); }
From source file:io.plaidapp.ui.DribbbleShot.java
/** * Animate in the title, description and author can't do this in a content transition as they * are within the ListView so do it manually. Also handle the FAB tanslation here so that it * plays nicely with #calculateFabPosition *//*from w ww .j ava 2 s . co m*/ private void enterAnimation(boolean isOrientationChange) { Interpolator interp = AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_slow_in); int offset = title.getHeight(); viewEnterAnimation(title, offset, interp); if (description.getVisibility() == View.VISIBLE) { offset *= 1.5f; viewEnterAnimation(description, offset, interp); } // animate the fab without touching the alpha as this is handled in the content transition offset *= 1.5f; float fabTransY = fab.getTranslationY(); fab.setTranslationY(fabTransY + offset); fab.animate().translationY(fabTransY).setDuration(600).setInterpolator(interp).start(); offset *= 1.5f; viewEnterAnimation(shotActions, offset, interp); offset *= 1.5f; viewEnterAnimation(playerName, offset, interp); viewEnterAnimation(playerAvatar, offset, interp); viewEnterAnimation(shotTimeAgo, offset, interp); back.animate().alpha(1f).setDuration(600).setInterpolator(interp).start(); if (isOrientationChange) { // we rely on the window enter content transition to show the fab. This isn't run on // orientation changes so manually show it. Animator showFab = ObjectAnimator.ofPropertyValuesHolder(fab, PropertyValuesHolder.ofFloat(View.ALPHA, 0f, 1f), PropertyValuesHolder.ofFloat(View.SCALE_X, 0f, 1f), PropertyValuesHolder.ofFloat(View.SCALE_Y, 0f, 1f)); showFab.setStartDelay(300L); showFab.setDuration(300L); showFab.setInterpolator( AnimationUtils.loadInterpolator(this, android.R.interpolator.linear_out_slow_in)); showFab.start(); } }
From source file:com.songcode.materialnotes.ui.NoteEditActivity.java
private void animateRevealShow(View targetview, View startView) { if (isActionInsertOrEdit()) { final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 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, 0, radius); targetview.setVisibility(View.VISIBLE); anim.setInterpolator(new DecelerateInterpolator()); anim.addListener(new Animator.AnimatorListener() { @Override/*from w ww.j a va 2s. co m*/ public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { mNoteEditor.requestFocus(); imm.showSoftInput(mNoteEditor, 0); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); anim.setDuration(ANIM_DURATION); anim.start(); } else if (isActionActionView()) { mAnimBackGroudView.animate().scaleX(.92f).scaleY(.92f).alpha(.6f).setDuration(ANIM_DURATION) .setInterpolator(new AccelerateInterpolator()).start(); mNoteEditor.animate().alpha(1).setStartDelay(400).setDuration(ANIM_DURATION); ViewCompat.setTransitionName(mAnimTargetView, "target_anim_view"); } }
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 {//from w w w . j a v a 2 s . com 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.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 ww w . j a v a 2 s . 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.transition.TransitionPort.java
/** * This is a utility method used by subclasses to handle standard parts of * setting up and running an Animator: it sets the {@link #getDuration() * duration} and the {@link #getStartDelay() startDelay}, starts the * animation, and, when the animator ends, calls {@link #end()}. * * @param animator The Animator to be run during this transition. * @hide//from w ww.j av a2 s.com */ @RestrictTo(GROUP_ID) protected void animate(Animator animator) { // TODO: maybe pass auto-end as a boolean parameter? if (animator == null) { end(); } else { if (getDuration() >= 0) { animator.setDuration(getDuration()); } if (getStartDelay() >= 0) { animator.setStartDelay(getStartDelay()); } if (getInterpolator() != null) { animator.setInterpolator(getInterpolator()); } animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { end(); animation.removeListener(this); } }); animator.start(); } }
From source file:com.android.launcher3.Folder.java
public void animateOpen() { if (!(getParent() instanceof DragLayer)) return;//from ww w. j a v a 2 s . co m Animator openFolderAnim = null; final Runnable onCompleteRunnable; if (!Utilities.isLmpOrAbove()) { positionAndSizeAsIcon(); 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.setDuration(mExpandDuration); openFolderAnim = oa; setLayerType(LAYER_TYPE_HARDWARE, null); onCompleteRunnable = new Runnable() { @Override public void run() { setLayerType(LAYER_TYPE_NONE, null); } }; } else { prepareReveal(); centerAboutIcon(); int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth(); int height = getFolderHeight(); float transX = -0.075f * (width / 2 - getPivotX()); float transY = -0.075f * (height / 2 - getPivotY()); setTranslationX(transX); setTranslationY(transY); PropertyValuesHolder tx = PropertyValuesHolder.ofFloat("translationX", transX, 0); PropertyValuesHolder ty = PropertyValuesHolder.ofFloat("translationY", transY, 0); int rx = (int) Math.max(Math.max(width - getPivotX(), 0), getPivotX()); int ry = (int) Math.max(Math.max(height - getPivotY(), 0), getPivotY()); float radius = (float) Math.sqrt(rx * rx + ry * ry); AnimatorSet anim = LauncherAnimUtils.createAnimatorSet(); Animator reveal = LauncherAnimUtils.createCircularReveal(this, (int) getPivotX(), (int) getPivotY(), 0, radius); reveal.setDuration(mMaterialExpandDuration); reveal.setInterpolator(new LogDecelerateInterpolator(100, 0)); mContent.setAlpha(0f); Animator iconsAlpha = LauncherAnimUtils.ofFloat(mContent, "alpha", 0f, 1f); iconsAlpha.setDuration(mMaterialExpandDuration); iconsAlpha.setStartDelay(mMaterialExpandStagger); iconsAlpha.setInterpolator(new AccelerateInterpolator(1.5f)); mFolderName.setAlpha(0f); Animator textAlpha = LauncherAnimUtils.ofFloat(mFolderName, "alpha", 0f, 1f); textAlpha.setDuration(mMaterialExpandDuration); textAlpha.setStartDelay(mMaterialExpandStagger); textAlpha.setInterpolator(new AccelerateInterpolator(1.5f)); Animator drift = LauncherAnimUtils.ofPropertyValuesHolder(this, tx, ty); drift.setDuration(mMaterialExpandDuration); drift.setStartDelay(mMaterialExpandStagger); drift.setInterpolator(new LogDecelerateInterpolator(60, 0)); anim.play(drift); anim.play(iconsAlpha); anim.play(textAlpha); anim.play(reveal); openFolderAnim = anim; mContent.setLayerType(LAYER_TYPE_HARDWARE, null); onCompleteRunnable = new Runnable() { @Override public void run() { mContent.setLayerType(LAYER_TYPE_NONE, null); } }; } openFolderAnim.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; if (onCompleteRunnable != null) { onCompleteRunnable.run(); } setFocusOnFirstChild(); } }); openFolderAnim.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.fairphone.fplauncher3.Folder.java
public void animateOpen() { if (!(getParent() instanceof DragLayer)) { return;// ww w . ja v a 2s . c o m } Animator openFolderAnim; final Runnable onCompleteRunnable; if (!Utilities.isLmpOrAbove()) { positionAndSizeAsIcon(); centerAboutIcon(); PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1f); PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f); PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f); final ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY); oa.setDuration(mExpandDuration); openFolderAnim = oa; setLayerType(LAYER_TYPE_HARDWARE, null); onCompleteRunnable = new Runnable() { @Override public void run() { setLayerType(LAYER_TYPE_NONE, null); } }; } else { prepareReveal(); centerAboutIcon(); int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth(); int height = getFolderHeight(); float transX = -0.075f * (width / 2 - getPivotX()); float transY = -0.075f * (height / 2 - getPivotY()); final float endTransX = 0; final float endTransY = 0; setTranslationX(transX); setTranslationY(transY); PropertyValuesHolder tx = PropertyValuesHolder.ofFloat("translationX", transX, endTransX); PropertyValuesHolder ty = PropertyValuesHolder.ofFloat("translationY", transY, endTransY); int rx = (int) Math.max(Math.max(width - getPivotX(), 0), getPivotX()); int ry = (int) Math.max(Math.max(height - getPivotY(), 0), getPivotY()); float radius = (float) Math.sqrt(rx * rx + ry * ry); AnimatorSet anim = LauncherAnimUtils.createAnimatorSet(); Animator reveal = LauncherAnimUtils.createCircularReveal(this, (int) getPivotX(), (int) getPivotY(), 0, radius); reveal.setDuration(mMaterialExpandDuration); reveal.setInterpolator(new LogDecelerateInterpolator(100, 0)); View[] alphaViewSet = new View[] { mContent, mFolderName }; for (View view : alphaViewSet) { Animator alphaAnimator = setupAlphaAnimator(view, 0f, 1f, mMaterialExpandDuration, mMaterialExpandStagger); anim.play(alphaAnimator); } /* mContent.setAlpha(0f); Animator iconsAlpha = LauncherAnimUtils.ofFloat(mContent, "alpha", 0f, 1f); iconsAlpha.setDuration(mMaterialExpandDuration); iconsAlpha.setStartDelay(mMaterialExpandStagger); iconsAlpha.setInterpolator(new AccelerateInterpolator(1.5f)); mFolderName.setAlpha(0f); Animator textAlpha = LauncherAnimUtils.ofFloat(mFolderName, "alpha", 0f, 1f); textAlpha.setDuration(mMaterialExpandDuration); textAlpha.setStartDelay(mMaterialExpandStagger); textAlpha.setInterpolator(new AccelerateInterpolator(1.5f));*/ Animator drift = LauncherAnimUtils.ofPropertyValuesHolder(this, tx, ty); drift.setDuration(mMaterialExpandDuration); drift.setStartDelay(mMaterialExpandStagger); drift.setInterpolator(new LogDecelerateInterpolator(60, 0)); drift.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { // in low power mode the animation doesn't play, so set the end value here Folder.this.setTranslationX(endTransX); Folder.this.setTranslationY(endTransY); } }); anim.play(drift); /* anim.play(iconsAlpha); anim.play(textAlpha);*/ anim.play(reveal); openFolderAnim = anim; mContent.setLayerType(LAYER_TYPE_HARDWARE, null); onCompleteRunnable = new Runnable() { @Override public void run() { mContent.setLayerType(LAYER_TYPE_NONE, null); } }; } openFolderAnim.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; if (onCompleteRunnable != null) { onCompleteRunnable.run(); } setFocusOnFirstChild(); } }); openFolderAnim.start(); // Make sure the folder picks up the last drag move even if the finger doesn't move. if (mDragController.isDragging()) { mDragController.forceTouchMove(); } }