List of usage examples for android.animation Animator setDuration
public abstract Animator setDuration(long duration);
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 */// w w w. j a v a2s .c o 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.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); }//from w w w . j av a2s . 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: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 ww w . ja 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: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// ww w .j a v a 2 s .co m */ @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:android.support.v17.leanback.app.OnboardingSupportFragment.java
private Animator createAnimator(View view, boolean fadeIn, int slideDirection, long startDelay) { boolean isLtr = getView().getLayoutDirection() == View.LAYOUT_DIRECTION_LTR; boolean slideRight = (isLtr && slideDirection == Gravity.END) || (!isLtr && slideDirection == Gravity.START) || slideDirection == Gravity.RIGHT; Animator fadeAnimator; Animator slideAnimator;//from w w w. j a v a2 s . c o m if (fadeIn) { fadeAnimator = ObjectAnimator.ofFloat(view, View.ALPHA, 0.0f, 1.0f); slideAnimator = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, slideRight ? sSlideDistance : -sSlideDistance, 0); fadeAnimator.setInterpolator(HEADER_APPEAR_INTERPOLATOR); slideAnimator.setInterpolator(HEADER_APPEAR_INTERPOLATOR); } else { fadeAnimator = ObjectAnimator.ofFloat(view, View.ALPHA, 1.0f, 0.0f); slideAnimator = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, 0, slideRight ? sSlideDistance : -sSlideDistance); fadeAnimator.setInterpolator(HEADER_DISAPPEAR_INTERPOLATOR); slideAnimator.setInterpolator(HEADER_DISAPPEAR_INTERPOLATOR); } fadeAnimator.setDuration(HEADER_ANIMATION_DURATION_MS); fadeAnimator.setTarget(view); slideAnimator.setDuration(HEADER_ANIMATION_DURATION_MS); slideAnimator.setTarget(view); AnimatorSet animator = new AnimatorSet(); animator.playTogether(fadeAnimator, slideAnimator); if (startDelay > 0) { animator.setStartDelay(startDelay); } return animator; }
From source file:com.android.launcher3.Folder.java
public void animateOpen() { if (!(getParent() instanceof DragLayer)) return;/*from w ww. j av a 2s . c om*/ 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.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 va2s.co 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:com.fairphone.fplauncher3.Folder.java
public void animateOpen() { if (!(getParent() instanceof DragLayer)) { return;/*from w w w . jav a 2 s . co 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(); } }
From source file:io.plaidapp.core.ui.transitions.ReflowText.java
/** * Create Animators to transition each run of text from start to end position and size. */// w ww . java2 s .c o m @NonNull private List<Animator> createRunAnimators(View view, ReflowData startData, ReflowData endData, Bitmap startText, Bitmap endText, List<Run> runs) { List<Animator> animators = new ArrayList<>(runs.size()); int dx = startData.bounds.left - endData.bounds.left; int dy = startData.bounds.top - endData.bounds.top; long startDelay = 0L; // move text closest to the destination first i.e. loop forward or backward over the runs boolean upward = startData.bounds.centerY() > endData.bounds.centerY(); boolean first = true; boolean lastRightward = true; LinearInterpolator linearInterpolator = new LinearInterpolator(); for (int i = upward ? 0 : runs.size() - 1; ((upward && i < runs.size()) || (!upward && i >= 0)); i += (upward ? 1 : -1)) { Run run = runs.get(i); // skip text runs which aren't visible in either state if (!run.startVisible && !run.endVisible) continue; // create & position the drawable which displays the run; add it to the overlay. SwitchDrawable drawable = new SwitchDrawable(startText, run.start, startData.textSize, endText, run.end, endData.textSize); drawable.setBounds(run.start.left + dx, run.start.top + dy, run.start.right + dx, run.start.bottom + dy); view.getOverlay().add(drawable); PropertyValuesHolder topLeft = PropertyValuesHolder.ofObject(SwitchDrawable.TOP_LEFT, null, getPathMotion().getPath(run.start.left + dx, run.start.top + dy, run.end.left, run.end.top)); PropertyValuesHolder width = PropertyValuesHolder.ofInt(SwitchDrawable.WIDTH, run.start.width(), run.end.width()); PropertyValuesHolder height = PropertyValuesHolder.ofInt(SwitchDrawable.HEIGHT, run.start.height(), run.end.height()); // the progress property drives the switching behaviour PropertyValuesHolder progress = PropertyValuesHolder.ofFloat(SwitchDrawable.PROGRESS, 0f, 1f); Animator runAnim = ObjectAnimator.ofPropertyValuesHolder(drawable, topLeft, width, height, progress); boolean rightward = run.start.centerX() + dx < run.end.centerX(); if ((run.startVisible && run.endVisible) && !first && rightward != lastRightward) { // increase the start delay (by a decreasing amount) for the next run // (if it's visible throughout) to stagger the movement and try to minimize overlaps startDelay += staggerDelay; staggerDelay *= STAGGER_DECAY; } lastRightward = rightward; first = false; runAnim.setStartDelay(startDelay); long animDuration = Math.max(minDuration, duration - (startDelay / 2)); runAnim.setDuration(animDuration); animators.add(runAnim); if (run.startVisible != run.endVisible) { // if run is appearing/disappearing then fade it in/out ObjectAnimator fade = ObjectAnimator.ofInt(drawable, SwitchDrawable.ALPHA, run.startVisible ? OPAQUE : TRANSPARENT, run.endVisible ? OPAQUE : TRANSPARENT); fade.setDuration((duration + startDelay) / 2); if (!run.startVisible) { drawable.setAlpha(TRANSPARENT); fade.setStartDelay((duration + startDelay) / 2); } else { fade.setStartDelay(startDelay); } animators.add(fade); } else { // slightly fade during transition to minimize movement ObjectAnimator fade = ObjectAnimator.ofInt(drawable, SwitchDrawable.ALPHA, OPAQUE, OPACITY_MID_TRANSITION, OPAQUE); fade.setStartDelay(startDelay); fade.setDuration(duration + startDelay); fade.setInterpolator(linearInterpolator); animators.add(fade); } } return animators; }
From source file:com.itsronald.widget.IndicatorDotPathView.java
@NonNull private Animator retreatCenterSegmentAnimator(final float toX, final float toY, final long animationDuration) { final float originalScale = 1, scaleX = 0, scaleY = 1; final Animator animator = scaleAnimator(centerSegment, originalScale, scaleX, scaleY); // Choose the corner of the view farthest from the destination location. final float originalPivotX = getPivotX(); final float originalPivotY = getPivotY(); final float pivotX = Math.max(0, Math.min(toX, centerSegment.getWidth())); final float pivotY = Math.max(0, Math.min(toY, centerSegment.getHeight())); animator.addListener(new AnimatorListenerAdapter() { @Override/*from ww w . j a v a 2 s . co m*/ public void onAnimationStart(Animator animation) { super.onAnimationStart(animation); centerSegment.setPivotX(pivotX); centerSegment.setPivotY(pivotY); } @Override public void onAnimationEnd(Animator animation) { // Reset values. centerSegment.setVisibility(INVISIBLE); centerSegment.setScaleX(originalScale); centerSegment.setScaleY(originalScale); centerSegment.setPivotX(originalPivotX); centerSegment.setPivotY(originalPivotY); } }); animator.setDuration(animationDuration); return animator; }