List of usage examples for android.animation ValueAnimator setDuration
@Override public ValueAnimator setDuration(long duration)
From source file:com.commit451.inkpageindicator.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//from w w w . jav a2s . com public void onAnimationEnd(Animator animation) { resetState(); pageChanging = false; } }); moveSelected.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { // todo avoid autoboxing selectedDotX = (Float) valueAnimator.getAnimatedValue(); retreatAnimation.startIfNecessary(selectedDotX); ViewCompat.postInvalidateOnAnimation(InkPageIndicator.this); } }); 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.systemui.statusbar.phone.NotificationPanelView.java
private void flingSettings(float vel, boolean expand, final Runnable onFinishRunnable, boolean isClick) { float target = expand ? mQsMaxExpansionHeight : mQsMinExpansionHeight; if (target == mQsExpansionHeight) { mScrollYOverride = -1;//from www. ja v a 2s .c om if (onFinishRunnable != null) { onFinishRunnable.run(); } return; } boolean belowFalsingThreshold = isBelowFalsingThreshold(); if (belowFalsingThreshold) { vel = 0; } mScrollView.setBlockFlinging(true); ValueAnimator animator = ValueAnimator.ofFloat(mQsExpansionHeight, target); if (isClick) { animator.setInterpolator(mTouchResponseInterpolator); animator.setDuration(368); } else { mFlingAnimationUtils.apply(animator, mQsExpansionHeight, target, vel); } if (belowFalsingThreshold) { animator.setDuration(350); } animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { setQsExpansion((Float) animation.getAnimatedValue()); } }); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mScrollView.setBlockFlinging(false); mScrollYOverride = -1; mQsExpansionAnimator = null; if (onFinishRunnable != null) { onFinishRunnable.run(); } } }); animator.start(); mQsExpansionAnimator = animator; mQsAnimatorExpand = expand; }
From source file:com.xelitexirish.scammerbingo.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//from w w w. j a v a2 s .c o m public void onAnimationEnd(Animator animation) { resetState(); pageChanging = false; } }); moveSelected.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { // todo avoid autoboxing selectedDotX = (Float) valueAnimator.getAnimatedValue(); retreatAnimation.startIfNecessary(selectedDotX); ViewCompat.postInvalidateOnAnimation(InkPageIndicator.this); } }); 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.systemui.statusbar.phone.NotificationPanelView.java
private void animateKeyguardStatusBarOut() { ValueAnimator anim = ValueAnimator.ofFloat(mKeyguardStatusBar.getAlpha(), 0f); anim.addUpdateListener(mStatusBarAnimateAlphaListener); anim.setStartDelay(mStatusBar.isKeyguardFadingAway() ? mStatusBar.getKeyguardFadingAwayDelay() : 0); anim.setDuration(mStatusBar.isKeyguardFadingAway() ? mStatusBar.getKeyguardFadingAwayDuration() / 2 : StackStateAnimator.ANIMATION_DURATION_STANDARD); anim.setInterpolator(mDozeAnimationInterpolator); anim.addListener(new AnimatorListenerAdapter() { @Override//from w w w . j a v a2 s . c o m public void onAnimationEnd(Animator animation) { mAnimateKeyguardStatusBarInvisibleEndRunnable.run(); } }); anim.start(); }
From source file:cc.flydev.launcher.Page.java
public void onFlingToDelete(PointF vel) { final long startTime = AnimationUtils.currentAnimationTimeMillis(); // NOTE: Because it takes time for the first frame of animation to actually be // called and we expect the animation to be a continuation of the fling, we have // to account for the time that has elapsed since the fling finished. And since // we don't have a startDelay, we will always get call to update when we call // start() (which we want to ignore). final TimeInterpolator tInterpolator = new TimeInterpolator() { private int mCount = -1; private long mStartTime; private float mOffset; /* Anonymous inner class ctor */ { mStartTime = startTime;/*w w w .ja va 2 s .com*/ } @Override public float getInterpolation(float t) { if (mCount < 0) { mCount++; } else if (mCount == 0) { mOffset = Math.min(0.5f, (float) (AnimationUtils.currentAnimationTimeMillis() - mStartTime) / FLING_TO_DELETE_FADE_OUT_DURATION); mCount++; } return Math.min(1f, mOffset + t); } }; final Rect from = new Rect(); final View dragView = mDragView; from.left = (int) dragView.getTranslationX(); from.top = (int) dragView.getTranslationY(); AnimatorUpdateListener updateCb = new FlingAlongVectorAnimatorUpdateListener(dragView, vel, from, startTime, FLING_TO_DELETE_FRICTION); final Runnable onAnimationEndRunnable = createPostDeleteAnimationRunnable(dragView); // Create and start the animation ValueAnimator mDropAnim = new ValueAnimator(); mDropAnim.setInterpolator(tInterpolator); mDropAnim.setDuration(FLING_TO_DELETE_FADE_OUT_DURATION); mDropAnim.setFloatValues(0f, 1f); mDropAnim.addUpdateListener(updateCb); mDropAnim.addListener(new AnimatorListenerAdapter() { public void onAnimationEnd(Animator animation) { onAnimationEndRunnable.run(); } }); mDropAnim.start(); mDeferringForDelete = true; }
From source file:com.marlonjones.voidlauncher.CellLayout.java
public boolean animateChildToPosition(final View child, int cellX, int cellY, int duration, int delay, boolean permanent, boolean adjustOccupied) { ShortcutAndWidgetContainer clc = getShortcutsAndWidgets(); if (clc.indexOfChild(child) != -1) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final ItemInfo info = (ItemInfo) child.getTag(); // We cancel any existing animations if (mReorderAnimators.containsKey(lp)) { mReorderAnimators.get(lp).cancel(); mReorderAnimators.remove(lp); }//from w w w .jav a 2 s .c om final int oldX = lp.x; final int oldY = lp.y; if (adjustOccupied) { GridOccupancy occupied = permanent ? mOccupied : mTmpOccupied; occupied.markCells(lp.cellX, lp.cellY, lp.cellHSpan, lp.cellVSpan, false); occupied.markCells(cellX, cellY, lp.cellHSpan, lp.cellVSpan, true); } lp.isLockedToGrid = true; if (permanent) { lp.cellX = info.cellX = cellX; lp.cellY = info.cellY = cellY; } else { lp.tmpCellX = cellX; lp.tmpCellY = cellY; } clc.setupLp(lp); lp.isLockedToGrid = false; final int newX = lp.x; final int newY = lp.y; lp.x = oldX; lp.y = oldY; // Exit early if we're not actually moving the view if (oldX == newX && oldY == newY) { lp.isLockedToGrid = true; return true; } ValueAnimator va = LauncherAnimUtils.ofFloat(child, 0f, 1f); va.setDuration(duration); mReorderAnimators.put(lp, va); va.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float r = ((Float) animation.getAnimatedValue()).floatValue(); lp.x = (int) ((1 - r) * oldX + r * newX); lp.y = (int) ((1 - r) * oldY + r * newY); child.requestLayout(); } }); va.addListener(new AnimatorListenerAdapter() { boolean cancelled = false; public void onAnimationEnd(Animator animation) { // If the animation was cancelled, it means that another animation // has interrupted this one, and we don't want to lock the item into // place just yet. if (!cancelled) { lp.isLockedToGrid = true; child.requestLayout(); } if (mReorderAnimators.containsKey(lp)) { mReorderAnimators.remove(lp); } } public void onAnimationCancel(Animator animation) { cancelled = true; } }); va.setStartDelay(delay); va.start(); return true; } return false; }
From source file:saftyos.android.launcher3.Page.java
public void onFlingToDelete(PointF vel) { final long startTime = AnimationUtils.currentAnimationTimeMillis(); // NOTE: Because it takes time for the first frame of animation to actually be // called and we expect the animation to be a continuation of the fling, we have // to account for the time that has elapsed since the fling finished. And since // we don't have a startDelay, we will always get call to update when we call // start() (which we want to ignore). final TimeInterpolator tInterpolator = new TimeInterpolator() { private int mCount = -1; private long mStartTime; private float mOffset; /* Anonymous inner class ctor */ { mStartTime = startTime;//from ww w.j ava2s. c om } @Override public float getInterpolation(float t) { if (mCount < 0) { mCount++; } else if (mCount == 0) { mOffset = Math.min(0.5f, (float) (AnimationUtils.currentAnimationTimeMillis() - mStartTime) / FLING_TO_DELETE_FADE_OUT_DURATION); mCount++; } return Math.min(1f, mOffset + t); } }; final Rect from = new Rect(); final View dragView = mDragView; from.left = (int) dragView.getTranslationX(); from.top = (int) dragView.getTranslationY(); AnimatorUpdateListener updateCb = new FlingAlongVectorAnimatorUpdateListener(dragView, vel, from, startTime, FLING_TO_DELETE_FRICTION); final Runnable onAnimationEndRunnable = createPostDeleteAnimationRunnable(dragView); // Create and start the animation ValueAnimator mDropAnim = new ValueAnimator(); mDropAnim.setInterpolator(tInterpolator); mDropAnim.setDuration(FLING_TO_DELETE_FADE_OUT_DURATION); mDropAnim.setFloatValues(0f, 1f); mDropAnim.addUpdateListener(updateCb); mDropAnim.addListener(new AnimatorListenerAdapter() { public void onAnimationEnd(Animator animation) { onAnimationEndRunnable.run(); } }); mDropAnim.start(); mDeferringForDelete = true; }
From source file:com.filemanager.free.ui.views.Indicator.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/*from w w w. j a va2 s. c o m*/ public void onAnimationEnd(Animator animation) { resetState(); pageChanging = false; } }); moveSelected.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { // todo avoid autoboxing selectedDotX = (Float) valueAnimator.getAnimatedValue(); retreatAnimation.startIfNecessary(selectedDotX); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { postInvalidateOnAnimation(); } else { postInvalidate(); } } }); 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.heinrichreimersoftware.materialintro.view.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//from w w w . java2 s . c om public void onAnimationEnd(Animator animation) { resetState(); pageChanging = false; } }); moveSelected.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { selectedDotX = (Float) valueAnimator.getAnimatedValue(); retreatAnimation.startIfNecessary(selectedDotX); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { postInvalidateOnAnimation(); } else { postInvalidate(); } } }); 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.dish.browser.activity.BrowserActivity.java
private void changeToolbarBackground(Bitmap favicon) { Palette.from(favicon).generate(new Palette.PaletteAsyncListener() { @Override/* w w w . j ava 2 s.c o m*/ public void onGenerated(Palette palette) { // OR with opaque black to remove transparency glitches int color = 0xff000000 | palette.getVibrantColor(mActivity.getResources().getColor(R.color.primary_color)); int finalColor; // Lighten up the dark color if it is // too dark if (isColorTooDark(color)) { finalColor = mixTwoColors(mActivity.getResources().getColor(R.color.primary_color), color, 0.25f); } else { finalColor = color; } ValueAnimator anim = ValueAnimator.ofObject(new ArgbEvaluator(), mBackground.getColor(), finalColor); anim.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { int color = (Integer) animation.getAnimatedValue(); mBackground.setColor(color); getWindow().setBackgroundDrawable(mBackground); mToolbarLayout.setBackgroundColor(color); } }); anim.setDuration(300); anim.start(); } }); }